diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index fa688b9c02..a14a3c0650 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -507,7 +507,7 @@ bool Converter::VisitMemberPointerType(clang::MemberPointerType *type) { if (type->isMemberFunctionPointer()) { llvm::report_fatal_error("pointers to member functions are not supported"); } - StrCat("isize"); + StrCat("DataMemberPointer"); return false; } @@ -638,7 +638,13 @@ void Converter::EmitHoistedDecls(clang::CompoundStmt *body) { void Converter::EmitHoistedDecl(clang::VarDecl *decl) { hoisted_decls_.insert(decl); if (ConvertVarDeclSkipInit(decl)) { - StrCat(token::kAssign, ConvertVarDefaultInit(decl), token::kSemiColon); + auto *record = decl->getType()->getAsRecordDecl(); + StrCat(token::kAssign, + record && IsUserDefinedDecl(record) && + !HasValueDefaultConstructor(record) + ? ConvertVarZeroInit(decl) + : ConvertVarDefaultInit(decl), + token::kSemiColon); } } @@ -936,56 +942,6 @@ void Converter::EmitScopedDestructor(const clang::VarDecl *decl) { GetNamedDeclAsString(decl))); } -bool Converter::RecordDerivesDefault(const clang::RecordDecl *decl) { - if (RecordNeedsDestruction(decl)) { - return false; - } - if (auto cxx_decl = clang::dyn_cast(decl)) { - if (GetUserDefinedDefaultConstructor(cxx_decl)) { - return false; - } - } - - for (auto f : decl->fields()) { - if (f->hasInClassInitializer() || !TypeDerivesDefault(f->getType())) { - return false; - } - } - - return true; -} - -bool Converter::TypeDerivesDefault(clang::QualType qual_type) { - // Rust only implements Default for arrays of up to 32 elements - if (auto *array_type = ctx_.getAsConstantArrayType(qual_type)) { - return array_type->getSize().ule(32) && - TypeDerivesDefault(array_type->getElementType()); - } - if (qual_type->isArrayType() || qual_type->isMemberPointerType()) { - return false; - } - - auto *cxx_record = qual_type->getAsCXXRecordDecl(); - if (IsStdDecl(cxx_record, "array") || IsStdDecl(cxx_record, "basic_string")) { - return false; - } - - // libc types do not implement Default - if (auto record = qual_type->getAsRecordDecl()) { - if (ctx_.getSourceManager().isInSystemHeader(record->getLocation()) && - qual_type.isPODType(ctx_)) { - return false; - } - } - - if (auto lambda = AsLambdaClass(qual_type); - lambda && lambda->captures().empty()) { - return false; - } - - return true; -} - bool Converter::IsPassThroughRule(clang::Expr *expr) { const auto *rule = RuleRegistry::GetExprRule(ctx_, expr); if (!rule || rule->body.size() != 1) { @@ -1547,6 +1503,11 @@ bool Converter::VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl) { void Converter::ConvertCXXConstructorBody(clang::CXXConstructorDecl *decl) { EmitFunctionPreamble(decl); + if (ConstructsDefaultValue(decl)) { + StrCat(std::format("{}(::default());", + GetConstructorWrite())); + return; + } EmitConstructorInit(decl); ConvertBodyStmts(decl->getBody()); } @@ -1577,16 +1538,7 @@ void Converter::EmitConstructorFieldInits(clang::CXXConstructorDecl *decl) { for (const auto *field : record_decl->fields()) { auto field_name = GetNamedDeclAsString(field); - const clang::CXXCtorInitializer *ctor_initializer = nullptr; - for (const auto *init : definition->inits()) { - if (init->isMemberInitializer() && init->getMember() == field) { - ctor_initializer = init; - break; - } - } - - auto *init = ctor_initializer ? ctor_initializer->getInit() - : field->getInClassInitializer(); + auto *init = GetFieldInitializer(definition, field); if (auto *construct = init ? GetPlacementInitializer(init) : nullptr) { ConstructInPlace(init, construct, GetFieldPlacementReceiver(field_name)); continue; @@ -4633,7 +4585,9 @@ void Converter::ConvertScalarInitList(clang::InitListExpr *expr) { void Converter::ConvertRecordInitList(clang::InitListExpr *expr, bool is_empty) { auto qual_type = expr->getType(); - if (is_empty) { + auto *cxx = qual_type->getAsCXXRecordDecl(); + if (is_empty && (!cxx || cxx->isUnion() || !IsUserDefinedDecl(cxx) || + cxx->hasTrivialDefaultConstructor())) { StrCat(GetDefaultAsString(qual_type)); return; } @@ -4768,7 +4722,7 @@ bool Converter::VisitCXXNullPtrLiteralExpr(clang::CXXNullPtrLiteralExpr *expr) { return false; } -void Converter::EmitNullPointer() { EmitFresh(token::kDefault); } +void Converter::EmitNullPointer() { EmitFresh("std::ptr::null_mut()"); } bool Converter::VisitVAArgExpr(clang::VAArgExpr *expr) { auto va_list_expr = expr->getSubExpr(); @@ -4804,6 +4758,21 @@ bool Converter::VisitCXXNewExpr(clang::CXXNewExpr *expr) { StrCat("Box::leak(Box::new("); Convert(init); StrCat("))"); + } else if (auto *construct = GetArrayNewElementConstruct(ctx_, expr)) { + PushBrace block(*this); + auto record_name = + GetRecordName(construct->getConstructor()->getParent()); + StrCat(std::format( + "let __n = ({0}) as usize; let __p: &mut [{1}] = " + "Box::leak((0..__n).map(|_| <{1}>::zero_init()).collect::>" + "());", + ToString(*expr->getArraySize()), record_name)); + StrCat("for __i in 0..__n"); + { + PushBrace loop(*this); + ConstructInPlace(construct, construct, "&raw mut __p[__i]"); + } + StrCat("__p"); } else { assert(expr->getArraySize().has_value()); auto array_size_as_string = ToString(*expr->getArraySize()); @@ -5117,9 +5086,10 @@ bool Converter::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) { return false; } - if (ctor->isDefaultConstructor() && - !(ctor->isUserProvided() && IsUserDefinedDecl(ctor)) && - !IsConvertibleDefaultConstructor(ctor)) { + if ((ctor->isDefaultConstructor() && + !(ctor->isUserProvided() && IsUserDefinedDecl(ctor)) && + !IsConvertibleDefaultConstructor(ctor)) || + (ConstructsDefaultValue(ctor) && in_place_.expr != expr)) { EmitFresh(GetDefaultAsString(expr->getType())); return false; } @@ -5317,6 +5287,10 @@ bool Converter::VisitImplicitValueInitExpr(clang::ImplicitValueInitExpr *expr) { } else if (elem_ty->isMemberDataPointerType()) { StrCat(std::format("[{}; {}]", GetDefaultAsString(elem_ty), arr_ty->getSize().getZExtValue())); + } else if (elem_ty->isRecordType()) { + StrCat(std::format("std::array::from_fn::<_, {}, _>(|_| {})", + arr_ty->getSize().getZExtValue(), + GetDefaultAsString(elem_ty))); } else { StrCat( std::format("std::array::from_fn::<_, {}, _>(|_| Default::default())", @@ -5509,7 +5483,7 @@ std::string Converter::GetDefaultAsString(clang::QualType qual_type) { } if (qual_type->isMemberDataPointerType()) { - return "-1_isize"; + return "DataMemberPointer::null()"; } if (qual_type->isPointerType()) { @@ -5521,10 +5495,17 @@ std::string Converter::GetDefaultAsString(clang::QualType qual_type) { : "std::ptr::null_mut()"; } - // A type without Default is constructed by its default constructor. if (auto *record = qual_type->getAsRecordDecl(); - record && RecordNeedsDestruction(record)) { - return std::format("<{}>::default_constructed()", + record && IsUserDefinedDecl(record)) { + auto *cxx = clang::dyn_cast(record); + ENSURE((!cxx || !cxx->hasDefaultConstructor() || + HasValueDefaultConstructor(cxx)) && + "a default constructor that uses this constructs into storage"); + if (HasValueDefaultConstructor(record)) { + return std::format("<{}>::default()", + ToString(qual_type.getUnqualifiedType())); + } + return std::format("{} {{ <{}>::zero_init() }}", keyword_unsafe_, ToString(qual_type.getUnqualifiedType())); } @@ -5554,6 +5535,11 @@ std::string Converter::ConvertVarDefaultInit(const clang::VarDecl *decl) { return GetDefaultAsString(decl->getType()); } +std::string Converter::ConvertVarZeroInit(const clang::VarDecl *decl) { + return std::format("unsafe {{ <{}>::zero_init() }}", + ToString(decl->getType())); +} + std::string Converter::GetOverloadedFunctionName(const clang::CXXMethodDecl *decl) { auto name = GetFunctionBaseName(decl); @@ -5631,10 +5617,6 @@ Converter::GetStructAttributes(const clang::RecordDecl *decl) { AddSpecialMemberDerives(decl, struct_attrs); - if (RecordDerivesDefault(decl)) { - struct_attrs.emplace_back("Default"); - } - return struct_attrs; } @@ -5708,15 +5690,6 @@ void Converter::ConvertUnsignedArithOperand(clang::Expr *expr, } void Converter::ConvertEqualsNullPtr(clang::Expr *expr) { - if (expr->getType()->isMemberPointerType()) { - PushParen outer(*this); - { - PushParen inner(*this); - Convert(expr); - } - EmitFresh("== -1_isize"); - return; - } StrCat('('); Convert(expr); EmitFresh(expr->getType()->isFunctionPointerType() ? ").is_none()" @@ -6246,8 +6219,7 @@ void Converter::AddSpecialMemberDerives(const clang::RecordDecl *decl, provided_trait->refcount.name); } }; - auto *cxx = clang::dyn_cast(decl); - bool trivial_default = !cxx || cxx->hasTrivialDefaultConstructor(); + bool trivial_default = IsTriviallyDefaultConstructible(decl); if (trivial_default) { attrs.emplace_back(GetCopyOrMoveTraitName(kTriviallyDefaultConstructible)); } @@ -6321,49 +6293,35 @@ bool Converter::RecordImplementsClone(const clang::RecordDecl *decl) { GetUserDefinedCopyConstructor(decl) != nullptr; } -void Converter::AddDefaultTraitForUnion(const clang::RecordDecl *decl) { - EmitDefaultImpl(decl, [&] { StrCat("unsafe { std::mem::zeroed() }"); }); -} - void Converter::AddDefaultTrait(const clang::RecordDecl *decl) { - if (auto *default_ctor = GetConvertedDefaultConstructor(decl); - default_ctor && !GetRecordTrait(default_ctor)) { + auto *default_ctor = GetConvertedDefaultConstructor(decl); + if (default_ctor && !GetRecordTrait(default_ctor)) { AddDefaultConstructibleTrait(clang::cast(decl), default_ctor); } - if (decl->isUnion()) { - AddDefaultTraitForUnion(decl); - return; - } - if (RecordDerivesDefault(decl) || RecordNeedsDestruction(decl)) { - return; - } - EmitDefaultImpl(decl, [&] { + if (default_ctor && !IsTriviallyDefaultConstructible(decl) && + HasValueDefaultConstructor(decl)) { + StrCat(keyword::kImpl, "Default for", GetRecordName(decl)); + PushBrace impl_brace(*this); + StrCat("fn default() -> Self"); + PushBrace fn_brace(*this); StrCat(keyword_unsafe_); PushBrace unsafe_brace(*this); - auto *cxx = clang::dyn_cast(decl); - if (cxx && !cxx->hasDefaultConstructor()) { - StrCat(std::format("<{}>::zero_init()", GetRecordName(decl))); - return; - } - if (auto *default_ctor = - cxx ? GetUserDefinedDefaultConstructor(cxx) : nullptr) { - Convert(MakeDefaultConstructExpr(cxx, default_ctor)); - } else { - EmitDefaultStructLiteral(decl); - } - }); + ConvertDefaultValue(clang::cast(decl), default_ctor); + } } -clang::CXXConstructExpr * -Converter::MakeDefaultConstructExpr(const clang::CXXRecordDecl *decl, - clang::CXXConstructorDecl *ctor) { - std::vector args; - for (auto *param : ctor->parameters()) { - args.push_back(clang::CXXDefaultArgExpr::Create(ctx_, param->getLocation(), - param, nullptr, ctor)); +void Converter::ConvertDefaultValue(const clang::CXXRecordDecl *decl, + const clang::CXXConstructorDecl *ctor) { + auto *definition = + clang::cast(ctor->getDefinition()); + StrCat(GetRecordName(decl)); + PushBrace brace(*this); + for (const auto *field : decl->fields()) { + StrCat(GetNamedDeclAsString(field), token::kColon); + ConvertFieldInit(field, GetFieldInitializer(definition, field)); + StrCat(token::kComma); } - return MakeConstructExpr(ctx_, ctx_.getCanonicalTagType(decl), ctor, args); } void Converter::AddDefaultConstructibleTrait(const clang::CXXRecordDecl *decl, @@ -6377,30 +6335,11 @@ void Converter::AddDefaultConstructibleTrait(const clang::CXXRecordDecl *decl, PushBrace fn_brace(*this); StrCat(keyword_unsafe_); PushBrace unsafe_brace(*this); - auto *construct = MakeDefaultConstructExpr(decl, ctor); + auto *construct = MakeDefaultConstructExpr(ctx_, decl, ctor); ConstructInPlace(construct, construct, spelling.receiver); } } -void Converter::EmitDefaultImpl(const clang::RecordDecl *decl, - llvm::function_ref body) { - StrCat(std::format("impl Default for {}", GetRecordName(decl))); - PushBrace impl_brace(*this); - StrCat("fn default() -> Self"); - PushBrace fn_brace(*this); - body(); -} - -void Converter::EmitDefaultStructLiteral(const clang::RecordDecl *decl) { - StrCat(GetRecordName(decl)); - PushBrace brace(*this); - for (auto *field : decl->fields()) { - StrCat(GetNamedDeclAsString(field), token::kColon); - ConvertFieldInit(field, field->getInClassInitializer()); - StrCat(token::kComma); - } -} - void Converter::ConvertFieldInit(const clang::FieldDecl *field, clang::Expr *init) { if (init) { @@ -6520,10 +6459,11 @@ std::string Converter::GetMemberPtrAsString(const clang::ValueDecl *member) { offsets.push_back(GetFieldOffsetAsString(field)); } if (offsets.empty()) { - return "0_isize"; + return "DataMemberPointer::from_offset(0)"; } if (offsets.size() == 1) { - return std::format("({} as isize)", offsets.front()); + return std::format("DataMemberPointer::from_offset({} as isize)", + offsets.front()); } std::string sum; for (const auto &offset : offsets) { @@ -6532,7 +6472,7 @@ std::string Converter::GetMemberPtrAsString(const clang::ValueDecl *member) { } sum += offset; } - return std::format("(({}) as isize)", sum); + return std::format("DataMemberPointer::from_offset(({}) as isize)", sum); } std::string Converter::GetFieldOffsetAsString(const clang::FieldDecl *field) { @@ -6569,8 +6509,8 @@ std::string Converter::ConvertMemberPtrObject(clang::BinaryOperator *expr) { std::string Converter::GetMemberOfObjectAsString(std::string object, std::string member, clang::QualType type) { - return std::format("{}.wrapping_byte_offset({}).cast::<{}>()", object, member, - ToString(type)); + return std::format("{}.wrapping_byte_offset(({}).offset()).cast::<{}>()", + object, member, ToString(type)); } void Converter::EmitDeref(std::string inner, clang::QualType pointee_type) { @@ -7538,7 +7478,11 @@ std::string Converter::ConvertGenericCall( } if (call.method == "default_constructed") { assert(call_args.empty() && "default_constructed takes no arguments"); - return GetUnboxedDefaultAsString(type); + auto *cxx = type->getAsCXXRecordDecl(); + if (!cxx || cxx->isUnion() || !IsUserDefinedDecl(cxx) || + cxx->hasTrivialDefaultConstructor()) { + return GetUnboxedDefaultAsString(type); + } } return std::format("<{}>::{}({})", GetUnboxedTypeAsString(type), call.method, diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 44dbc79de1..5b549b22b3 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -631,7 +631,7 @@ class Converter : public clang::RecursiveASTVisitor { // The value of expr, an integer constant expression. void EmitEvaluatedInt(clang::Expr *expr); - void EmitNullPointer(); + virtual void EmitNullPointer(); bool VisitCXXNoexceptExpr(clang::CXXNoexceptExpr *expr); @@ -925,6 +925,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual std::string ConvertVarDefaultInit(const clang::VarDecl *decl); + virtual std::string ConvertVarZeroInit(const clang::VarDecl *decl); + virtual std::string GetOverloadedFunctionName(const clang::CXXMethodDecl *decl); @@ -1023,6 +1025,9 @@ class Converter : public clang::RecursiveASTVisitor { virtual void AddDefaultTrait(const clang::RecordDecl *decl); + virtual void ConvertDefaultValue(const clang::CXXRecordDecl *decl, + const clang::CXXConstructorDecl *ctor); + // The CopyAssignable and MoveAssignable impls that call a copy assignment // operator that isn't their method (GetWrappedCopyAssignment). void AddAssignmentTraits(const clang::CXXRecordDecl *decl); @@ -1033,21 +1038,9 @@ class Converter : public clang::RecursiveASTVisitor { std::string GetCopyOrMoveSourceType(const RecordTrait &trait, std::string_view self = "Self") const; - virtual void AddDefaultTraitForUnion(const clang::RecordDecl *decl); - - clang::CXXConstructExpr * - MakeDefaultConstructExpr(const clang::CXXRecordDecl *decl, - clang::CXXConstructorDecl *ctor); - void AddDefaultConstructibleTrait(const clang::CXXRecordDecl *decl, clang::CXXConstructorDecl *ctor); - void EmitDefaultStructLiteral(const clang::RecordDecl *decl); - - // Emits `impl Default for decl`, whose default() returns what body emits. - void EmitDefaultImpl(const clang::RecordDecl *decl, - llvm::function_ref body); - virtual void EmitByteSizeAttr(const clang::RecordDecl *decl); virtual void @@ -1213,10 +1206,6 @@ class Converter : public clang::RecursiveASTVisitor { bool ExprMapsValueToPointer(const clang::CallExpr *expr) const; - virtual bool RecordDerivesDefault(const clang::RecordDecl *decl); - - virtual bool TypeDerivesDefault(clang::QualType qual_type); - bool RecordDerivesCopy(clang::QualType type); bool IsPassThroughRule(clang::Expr *expr); diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 88fc850a5f..d48b71add7 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -991,10 +991,10 @@ bool IsConvertibleCopyConstructor(const clang::CXXConstructorDecl *ctor) { } bool IsConvertibleDefaultConstructor(const clang::CXXConstructorDecl *ctor) { + auto *parent = ctor->getParent(); return ctor->isDefaultConstructor() && !ctor->isUserProvided() && - !ctor->isDeleted() && - IsConvertibleImplicitMemberParent(ctor->getParent()) && - !ctor->isTrivial(); + !ctor->isDeleted() && IsUserDefinedDecl(parent) && + !parent->isAbstract() && !ctor->isTrivial(); } // Whether moving a field of decl isn't a copy: the field is a record with a @@ -1383,7 +1383,8 @@ const clang::CXXConstructExpr *GetInPlaceConstruct(const clang::Expr *init) { if (ctor->isCopyOrMoveConstructor()) { return IsConvertibleCopyOrMoveConstructor(ctor) ? construct : nullptr; } - return ctor->isUserProvided() || IsConvertibleDefaultConstructor(ctor) + return (ctor->isUserProvided() || IsConvertibleDefaultConstructor(ctor)) && + !ConstructsDefaultValue(ctor) ? construct : nullptr; } @@ -2651,6 +2652,31 @@ clang::CXXConstructExpr *MakeConstructExpr(clang::ASTContext &ctx, clang::SourceRange()); } +clang::CXXConstructExpr * +MakeDefaultConstructExpr(clang::ASTContext &ctx, + const clang::CXXRecordDecl *decl, + clang::CXXConstructorDecl *ctor) { + std::vector args; + for (auto *param : ctor->parameters()) { + args.push_back(clang::CXXDefaultArgExpr::Create(ctx, param->getLocation(), + param, nullptr, ctor)); + } + return MakeConstructExpr(ctx, ctx.getCanonicalTagType(decl), ctor, args); +} + +clang::CXXConstructExpr *GetArrayNewElementConstruct(clang::ASTContext &ctx, + clang::CXXNewExpr *expr) { + auto *record = expr->getAllocatedType()->getAsCXXRecordDecl(); + auto *construct = + clang::dyn_cast_or_null(expr->getInitializer()); + if (!record || !construct || construct->getConstructor()->isTrivial()) { + return nullptr; + } + auto *element = + MakeDefaultConstructExpr(ctx, record, construct->getConstructor()); + return GetInPlaceConstruct(element) ? element : nullptr; +} + std::optional> GetTemplateArgs(clang::QualType qual_type, clang::Expr *expr) { if (auto ty = clang::dyn_cast(qual_type)) { @@ -2784,6 +2810,90 @@ bool RefersToPointer(const clang::Stmt *stmt) { return std::ranges::any_of(GetAllVars(stmt), IsPointerVar); } +bool IsTriviallyDefaultConstructible(const clang::RecordDecl *decl) { + auto *cxx = clang::dyn_cast(decl); + return !cxx || cxx->hasTrivialDefaultConstructor(); +} + +clang::Expr *GetFieldInitializer(const clang::CXXConstructorDecl *ctor, + const clang::FieldDecl *field) { + for (const auto *init : ctor->inits()) { + if (init->isMemberInitializer() && init->getMember() == field) { + return init->getInit(); + } + } + return field->getInClassInitializer(); +} + +static bool IsValueDefaultFieldInit(const clang::FieldDecl *field, + const clang::Expr *init) { + if (auto *default_init = clang::dyn_cast_or_null( + init ? init->IgnoreImplicit() : nullptr)) { + init = default_init->getExpr(); + } + if (init && ReferencesThis(init)) { + return false; + } + auto *record = + field->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl(); + if (!record || !IsUserDefinedDecl(record)) { + return true; + } + if (!HasValueDefaultConstructor(record)) { + return false; + } + if (!init) { + return true; + } + init = init->IgnoreImplicit(); + if (auto *construct = clang::dyn_cast(init)) { + return construct->getConstructor()->isDefaultConstructor() && + construct->getNumArgs() == 0; + } + if (auto *list = clang::dyn_cast(init)) { + return list->getNumInits() == 0; + } + return clang::isa(init); +} + +bool ConstructsDefaultValue(const clang::CXXConstructorDecl *ctor) { + auto *parent = ctor->getParent(); + if (!ctor->isDefaultConstructor() || !IsUserDefinedDecl(parent)) { + return false; + } + auto *default_ctor = GetConvertedDefaultConstructor(parent); + return default_ctor && + default_ctor->getCanonicalDecl() == ctor->getCanonicalDecl() && + HasValueDefaultConstructor(parent); +} + +bool HasValueDefaultConstructor(const clang::RecordDecl *decl) { + if (IsTriviallyDefaultConstructible(decl)) { + return true; + } + auto *cxx = clang::cast(decl); + auto *ctor = GetConvertedDefaultConstructor(cxx); + if (!ctor || ctor->getNumParams() != 0 || cxx->isPolymorphic() || + cxx->getNumBases() != 0) { + return false; + } + auto *definition = + clang::dyn_cast_or_null(ctor->getDefinition()); + if (!definition) { + return false; + } + if (auto *body = definition->getBody()) { + auto *compound = clang::dyn_cast(body); + if (!compound || !compound->body_empty()) { + return false; + } + } + return llvm::all_of(cxx->fields(), [&](const clang::FieldDecl *field) { + return IsValueDefaultFieldInit(field, + GetFieldInitializer(definition, field)); + }); +} + bool DefaultInitHasSideEffects(const clang::ASTContext &ctx, clang::QualType type) { auto *record = ctx.getBaseElementType(type)->getAsCXXRecordDecl(); diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 51b08bcb1c..f43938fbc9 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -559,6 +559,14 @@ clang::CXXConstructExpr *MakeConstructExpr(clang::ASTContext &ctx, clang::CXXConstructorDecl *ctor, llvm::ArrayRef args); +clang::CXXConstructExpr * +MakeDefaultConstructExpr(clang::ASTContext &ctx, + const clang::CXXRecordDecl *decl, + clang::CXXConstructorDecl *ctor); + +clang::CXXConstructExpr *GetArrayNewElementConstruct(clang::ASTContext &ctx, + clang::CXXNewExpr *expr); + std::optional> GetTemplateArgs(clang::QualType qual_type, clang::Expr *expr = nullptr); @@ -581,6 +589,15 @@ bool RefersToPointer(const clang::Stmt *stmt); bool DefaultInitHasSideEffects(const clang::ASTContext &ctx, clang::QualType type); +bool IsTriviallyDefaultConstructible(const clang::RecordDecl *decl); + +clang::Expr *GetFieldInitializer(const clang::CXXConstructorDecl *ctor, + const clang::FieldDecl *field); + +bool HasValueDefaultConstructor(const clang::RecordDecl *decl); + +bool ConstructsDefaultValue(const clang::CXXConstructorDecl *ctor); + bool ReferencesThis(const clang::Stmt *stmt); // Whether evaluating `stmt` reads a value from memory, e.g., a pointer. diff --git a/cpp2rust/converter/lex.h b/cpp2rust/converter/lex.h index 93b3b4a8d2..2868a742ff 100644 --- a/cpp2rust/converter/lex.h +++ b/cpp2rust/converter/lex.h @@ -63,7 +63,6 @@ inline constexpr const char kMut[] = "mut"; } // namespace keyword namespace token { -inline constexpr const char kDefault[] = "Default::default()"; inline constexpr const char kIgnoreRule[] = "libcc2rs::IgnoreRule"; } // namespace token } // namespace cpp2rust diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 3435b57a9b..56350bbd14 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -745,12 +745,14 @@ void ConverterRefCount::AddDefaultTrait(const clang::RecordDecl *decl) { Converter::AddDefaultTrait(decl); } -void ConverterRefCount::AddDefaultTraitForUnion(const clang::RecordDecl *decl) { - EmitDefaultImpl(decl, [&] { - StrCat(std::format("{} {{ __bytes: Box::from([0u8; {}]) }}", - GetRecordName(decl), - ctx_.getASTRecordLayout(decl).getSize().getQuantity())); - }); +void ConverterRefCount::ConvertDefaultValue( + const clang::CXXRecordDecl *decl, const clang::CXXConstructorDecl *ctor) { + PushConversionKind push(*this, ConversionKind::Unboxed); + Converter::ConvertDefaultValue(decl, ctor); +} + +void ConverterRefCount::EmitNullPointer() { + EmitFresh("Ptr::<()>::null().to_any()"); } void ConverterRefCount::EmitRustUnion(clang::RecordDecl *decl) { @@ -2024,6 +2026,20 @@ bool ConverterRefCount::VisitCXXNewExpr(clang::CXXNewExpr *expr) { PushConversionKind push(*this, ConversionKind::FullRefCount); Convert(init); StrCat(')'); + } else if (auto *construct = GetArrayNewElementConstruct(ctx_, expr)) { + PushBrace block(*this); + auto record_name = + GetRecordName(construct->getConstructor()->getParent()); + StrCat(std::format("let __n = ({0}) as usize; let __p = " + "Ptr::alloc_array((0..__n).map(|_| " + "<{1}>::zero_init()).collect::>());", + ToString(*expr->getArraySize()), record_name)); + StrCat("for __i in 0..__n"); + { + PushBrace loop(*this); + ConstructInPlace(construct, construct, "__p.offset(__i)"); + } + StrCat("__p"); } else { auto array_size_as_string = ToString(*expr->getArraySize()); auto alloc_type = expr->getAllocatedType(); @@ -2162,9 +2178,10 @@ bool ConverterRefCount::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) { return false; } - if (ctor->isDefaultConstructor() && - !(ctor->isUserProvided() && IsUserDefinedDecl(ctor)) && - !IsConvertibleDefaultConstructor(ctor)) { + if ((ctor->isDefaultConstructor() && + !(ctor->isUserProvided() && IsUserDefinedDecl(ctor)) && + !IsConvertibleDefaultConstructor(ctor)) || + (ConstructsDefaultValue(ctor) && in_place_.expr != expr)) { EmitFresh(GetDefaultAsString(expr->getType())); return false; } @@ -2180,6 +2197,12 @@ bool ConverterRefCount::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) { bool ConverterRefCount::VisitImplicitValueInitExpr( clang::ImplicitValueInitExpr *expr) { + if (auto *array_type = ctx_.getAsConstantArrayType(expr->getType()); + array_type && array_type->getElementType()->isArrayType()) { + PushConversionKind push(*this, ConversionKind::Pointee); + EmitFresh(GetDefaultAsString(expr->getType())); + return false; + } PushConversionKind push(*this, ConversionKind::Unboxed); if (ctx_.getAsConstantArrayType(expr->getType())) { StrCat("Box::new("); @@ -2285,7 +2308,7 @@ std::string ConverterRefCount::GetDefaultAsString(clang::QualType qual_type) { } if (qual_type->isMemberDataPointerType()) { - return BoxValue("-1_isize"); + return BoxValue("DataMemberPointer::null()"); } if (!qual_type->isPointerType()) { @@ -2315,6 +2338,11 @@ ConverterRefCount::ConvertVarDefaultInit(const clang::VarDecl *decl) { return GetDefaultAsString(decl->getType()); } +std::string ConverterRefCount::ConvertVarZeroInit(const clang::VarDecl *decl) { + PushConversionKind push(*this, VarConversionKind(decl)); + return std::format("<{}>::zero_init()", ToString(decl->getType())); +} + std::vector ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { std::vector attrs; @@ -2346,9 +2374,6 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { AddSpecialMemberDerives(decl, attrs); - if (RecordDerivesDefault(decl)) { - attrs.emplace_back("Default"); - } return attrs; } @@ -2357,11 +2382,6 @@ ConverterRefCount::GetRecordTraitSpelling(const RecordTrait &trait) const { return trait.refcount; } -bool ConverterRefCount::TypeDerivesDefault(clang::QualType qual_type) { - // Arrays are translated to Value>, whose Default is empty - return !qual_type->isArrayType() && Converter::TypeDerivesDefault(qual_type); -} - std::string ConverterRefCount::ConvertVarInitValue(clang::QualType qual_type, clang::Expr *expr) { if (auto lambda = clang::dyn_cast( diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index b65cd7cfbd..16d5c5e48a 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -81,7 +81,10 @@ class ConverterRefCount final : public Converter { void AddDefaultTrait(const clang::RecordDecl *decl) override; - void AddDefaultTraitForUnion(const clang::RecordDecl *decl) override; + void ConvertDefaultValue(const clang::CXXRecordDecl *decl, + const clang::CXXConstructorDecl *ctor) override; + + void EmitNullPointer() override; std::string GetSelfMaybeWithMut(const clang::CXXMethodDecl *decl) override; @@ -322,11 +325,11 @@ class ConverterRefCount final : public Converter { std::string ConvertVarDefaultInit(const clang::VarDecl *decl) override; + std::string ConvertVarZeroInit(const clang::VarDecl *decl) override; + std::vector GetStructAttributes(const clang::RecordDecl *decl) override; - bool TypeDerivesDefault(clang::QualType qual_type) override; - bool Convert(clang::QualType qual_type) override; bool Convert(clang::Expr *expr, diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index eec3c20f48..95ca28d50f 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -42,8 +42,21 @@ pub fn expand_trivially_default_constructible(input: TokenStream, is_unsafe: boo } else { quote!(::libcc2rs::TriviallyDefaultConstructible) }; - let marker: TokenStream = - quote!(impl #impl_generics #tr for #name #ty_generics #where_clause {}).into(); + let zero_init = if is_unsafe { + quote!(unsafe { ::zero_init() }) + } else { + quote!(::zero_init()) + }; + let marker: TokenStream = quote! { + impl #impl_generics #tr for #name #ty_generics #where_clause {} + + impl #impl_generics ::std::default::Default for #name #ty_generics #where_clause { + fn default() -> Self { + #zero_init + } + } + } + .into(); impls.extend(marker); impls } diff --git a/libcc2rs-macros/src/initialization.rs b/libcc2rs-macros/src/initialization.rs index 91381d7acf..60e7b602e8 100644 --- a/libcc2rs-macros/src/initialization.rs +++ b/libcc2rs-macros/src/initialization.rs @@ -59,10 +59,29 @@ pub fn expand_unsafe(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); let name = &input.ident; let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); + let value = match &input.data { + Data::Struct(data) => { + let value = quote!(::libcc2rs::ZeroInitializationUnsafe::zero_init()); + let values = std::iter::repeat_n(value, data.fields.len()); + let fields = match &data.fields { + Fields::Named(fields) => { + let idents = fields.named.iter().map(|field| &field.ident); + quote!({ #(#idents: #values,)* }) + } + Fields::Unnamed(fields) => { + let indices = (0..fields.unnamed.len()).map(Index::from); + quote!({ #(#indices: #values,)* }) + } + Fields::Unit => quote!({}), + }; + quote!(Self #fields) + } + _ => quote!(::std::mem::MaybeUninit::zeroed().assume_init()), + }; quote! { impl #impl_generics ::libcc2rs::ZeroInitializationUnsafe for #name #ty_generics #where_clause { unsafe fn zero_init() -> Self { - unsafe { ::std::mem::MaybeUninit::zeroed().assume_init() } + unsafe { #value } } } } diff --git a/libcc2rs/src/cmp.rs b/libcc2rs/src/cmp.rs index c6875abcf7..d400b7faed 100644 --- a/libcc2rs/src/cmp.rs +++ b/libcc2rs/src/cmp.rs @@ -242,7 +242,7 @@ macro_rules! impl_weakly_equality_comparable_with_unsafe { impl_weakly_equality_comparable_with!( <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, - Ptr, Option, + Ptr, Option, <> crate::DataMemberPointer, ); impl WeaklyEqualityComparableWith for Vec { @@ -282,7 +282,7 @@ where impl_weakly_equality_comparable_with_unsafe!( <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, - *mut T, *const T, Option, + *mut T, *const T, Option, <> crate::DataMemberPointer, ); impl WeaklyEqualityComparableWithUnsafe for Vec { diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index 2fcbe074f7..d547671e00 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -7,6 +7,7 @@ use crate::capture::{ use crate::conversion::{Constructor, ConstructorUnsafe}; use crate::fn_ptr::{FnPtr, FnSig}; use crate::initialization::ZeroInitialization; +use crate::member_ptr::DataMemberPointer; use crate::rc::{AsPointer, Ptr, Value}; use crate::reference::{Const, LvalueRef, LvalueRefUnsafe, RvalueRef, RvalueRefUnsafe}; use crate::reinterpret::ByteRepr; @@ -574,6 +575,13 @@ macro_rules! impl_default_by_zeroed { impl $crate::TriviallyDefaultConstructibleUnsafe for $ty {} + + impl $crate::ZeroInitializationUnsafe for $ty { + #[inline] + unsafe fn zero_init() -> Self { + unsafe { std::mem::zeroed() } + } + } )*}; } pub(crate) use impl_default_by_zeroed; @@ -654,6 +662,22 @@ impl ConstructorUnsafe<()> for FnPtr { } } +impl TriviallyDefaultConstructible for DataMemberPointer {} + +impl TriviallyDefaultConstructibleUnsafe for DataMemberPointer {} + +impl Constructor<()> for DataMemberPointer { + fn constructor(this: Ptr, _: ()) { + this.write(DataMemberPointer::null()); + } +} + +impl ConstructorUnsafe<()> for DataMemberPointer { + unsafe fn constructor(this: *mut Self, _: ()) { + unsafe { std::ptr::write(this, DataMemberPointer::null()) } + } +} + impl Constructor<()> for Box<[T]> { fn constructor(this: Ptr, _: ()) { let len = this.with(|elems| elems.len()); @@ -702,6 +726,7 @@ impl_trivial_copy_move!( f32, f64, AnyPtr, + DataMemberPointer, crate::VaArg, std::rc::Rc, ); diff --git a/libcc2rs/src/fn_ptr.rs b/libcc2rs/src/fn_ptr.rs index c149582224..45c2685667 100644 --- a/libcc2rs/src/fn_ptr.rs +++ b/libcc2rs/src/fn_ptr.rs @@ -514,6 +514,13 @@ impl crate::ZeroInitialization for FnPtr { } } +impl crate::ZeroInitializationUnsafe for FnPtr { + #[inline] + unsafe fn zero_init() -> Self { + FnPtr::null() + } +} + impl FnPtrArg for FnPtr { #[inline] fn to_repr(self) -> ArgRepr { diff --git a/libcc2rs/src/initialization.rs b/libcc2rs/src/initialization.rs index 926f4a0197..4590946f36 100644 --- a/libcc2rs/src/initialization.rs +++ b/libcc2rs/src/initialization.rs @@ -87,6 +87,13 @@ impl ZeroInitializatio } } +impl ZeroInitializationUnsafe for [T; N] { + #[inline] + unsafe fn zero_init() -> Self { + std::array::from_fn(|_| unsafe { T::zero_init() }) + } +} + impl ZeroInitializationUnsafe for *mut T { #[inline] unsafe fn zero_init() -> Self { diff --git a/libcc2rs/src/lib.rs b/libcc2rs/src/lib.rs index 171a021a11..5d95c4f44e 100644 --- a/libcc2rs/src/lib.rs +++ b/libcc2rs/src/lib.rs @@ -23,6 +23,7 @@ pub mod __field { } mod member_ptr; +pub use member_ptr::DataMemberPointer; mod cstr; pub use cstr::CChar; diff --git a/libcc2rs/src/member_ptr.rs b/libcc2rs/src/member_ptr.rs index 4c7f4347ca..db1382f43e 100644 --- a/libcc2rs/src/member_ptr.rs +++ b/libcc2rs/src/member_ptr.rs @@ -4,10 +4,80 @@ use std::any::TypeId; use crate::Record; +use crate::fn_ptr_arg::{ArgRepr, FnPtrArg}; +use crate::initialization::{ZeroInitialization, ZeroInitializationUnsafe}; use crate::rc::Ptr; use crate::reinterpret::ByteRepr; -const NULL: isize = -1; +#[derive(Clone, Copy, PartialEq, Eq)] +pub struct DataMemberPointer(isize); + +impl DataMemberPointer { + #[inline] + pub const fn null() -> Self { + DataMemberPointer(-1) + } + + #[inline] + pub const fn from_offset(offset: isize) -> Self { + DataMemberPointer(offset) + } + + #[inline] + pub fn is_null(self) -> bool { + self.0 == -1 + } + + #[inline] + pub fn offset(self) -> isize { + if self.is_null() { + panic!("ub: null member pointer"); + } + self.0 + } +} + +impl ByteRepr for DataMemberPointer { + #[inline] + fn byte_size() -> usize { + std::mem::size_of::() + } + #[inline] + fn to_bytes(&self, buf: &mut [u8]) { + buf.copy_from_slice(&self.0.to_ne_bytes()); + } + #[inline] + fn from_bytes(buf: &[u8]) -> Self { + let mut a = [0u8; std::mem::size_of::()]; + a.copy_from_slice(buf); + DataMemberPointer(isize::from_ne_bytes(a)) + } +} + +impl ZeroInitialization for DataMemberPointer { + #[inline] + fn zero_init() -> Self { + Self::null() + } +} + +impl ZeroInitializationUnsafe for DataMemberPointer { + #[inline] + unsafe fn zero_init() -> Self { + Self::null() + } +} + +impl FnPtrArg for DataMemberPointer { + #[inline] + fn to_repr(self) -> ArgRepr { + self.0.to_repr() + } + #[inline] + fn from_repr(r: ArgRepr) -> Self { + DataMemberPointer(isize::from_repr(r)) + } +} fn member_of(object: &C, offset: usize) -> &T { object @@ -25,11 +95,11 @@ fn member_of_mut(object: &mut C, offset: usize) -> &mut T impl Ptr { #[inline] - pub fn member(&self, member: isize) -> Ptr { - if member == NULL { + pub fn member(&self, member: DataMemberPointer) -> Ptr { + if member.is_null() { panic!("ub: null member pointer"); } - let offset = member as usize; + let offset = member.0 as usize; self.field_ptr_at( move |object| member_of(object, offset), move |object| member_of_mut(object, offset), diff --git a/rules/dirent/shim.rs b/rules/dirent/shim.rs index ae8f1cb6a1..e7fc0ece4b 100644 --- a/rules/dirent/shim.rs +++ b/rules/dirent/shim.rs @@ -26,18 +26,6 @@ pub struct Dirent { pub d_name: Box<[i8]>, } -impl Default for Dirent { - fn default() -> Self { - Self { - d_ino: 0, - d_off: 0, - d_reclen: 0, - d_type: 0, - d_name: vec![0i8; size_of_field!(::libc::dirent, d_name)].into_boxed_slice(), - } - } -} - impl Dirent { pub fn from_entry(ino: u64, name: &[u8], d_type: u8) -> Self { let mut de = Dirent { diff --git a/rules/ifaddrs/shim.rs b/rules/ifaddrs/shim.rs index f3f1c35480..7973888922 100644 --- a/rules/ifaddrs/shim.rs +++ b/rules/ifaddrs/shim.rs @@ -9,13 +9,7 @@ use crate::{ use std::mem::{offset_of, size_of}; #[derive( - Clone, - Default, - Record, - ByteRepr, - ZeroInitialization, - TriviallyDefaultConstructible, - TriviallyCopyable, + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, )] #[byte_size(size_of::<::libc::ifaddrs>())] pub struct Ifaddrs { diff --git a/rules/ip/shim.rs b/rules/ip/shim.rs index 782d43192e..38779b0967 100644 --- a/rules/ip/shim.rs +++ b/rules/ip/shim.rs @@ -5,13 +5,7 @@ use crate::TriviallyDefaultConstructible; use crate::{ByteRepr, Ptr, Record, TriviallyCopyable, ZeroInitialization}; #[derive( - Clone, - Default, - Record, - ByteRepr, - ZeroInitialization, - TriviallyDefaultConstructible, - TriviallyCopyable, + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, )] #[byte_size(4)] pub struct InAddr { @@ -36,14 +30,6 @@ impl In6Addr { } } -impl Default for In6Addr { - fn default() -> Self { - Self { - s6_addr: vec![0u8; 16].into_boxed_slice(), - } - } -} - impl ByteRepr for ::libc::in_addr {} impl ByteRepr for ::libc::in6_addr {} diff --git a/rules/netdb/shim.rs b/rules/netdb/shim.rs index 3462fee9af..d0708d6ab2 100644 --- a/rules/netdb/shim.rs +++ b/rules/netdb/shim.rs @@ -6,13 +6,7 @@ use crate::{ByteRepr, Ptr, Record, Sockaddr, TriviallyCopyable, ZeroInitializati use std::mem::{offset_of, size_of}; #[derive( - Clone, - Default, - Record, - ByteRepr, - ZeroInitialization, - TriviallyDefaultConstructible, - TriviallyCopyable, + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, )] #[byte_size(size_of::<::libc::addrinfo>())] pub struct Addrinfo { diff --git a/rules/poll/shim.rs b/rules/poll/shim.rs index 61d6e8569f..f5b4edf61d 100644 --- a/rules/poll/shim.rs +++ b/rules/poll/shim.rs @@ -6,13 +6,7 @@ use crate::{ByteRepr, Record, TriviallyCopyable, ZeroInitialization}; use std::mem::{offset_of, size_of}; #[derive( - Clone, - Default, - Record, - ByteRepr, - ZeroInitialization, - TriviallyDefaultConstructible, - TriviallyCopyable, + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, )] #[byte_size(size_of::<::libc::pollfd>())] pub struct Pollfd { diff --git a/rules/pwd/shim.rs b/rules/pwd/shim.rs index 05d22c24e1..1aef9de3c4 100644 --- a/rules/pwd/shim.rs +++ b/rules/pwd/shim.rs @@ -6,13 +6,7 @@ use crate::{ByteRepr, Ptr, Record, TriviallyCopyable, ZeroInitialization}; use std::mem::{offset_of, size_of}; #[derive( - Clone, - Default, - Record, - ByteRepr, - ZeroInitialization, - TriviallyDefaultConstructible, - TriviallyCopyable, + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, )] #[byte_size(size_of::<::libc::passwd>())] pub struct Passwd { diff --git a/rules/socket/shim.rs b/rules/socket/shim.rs index faed480f7c..dc6ad385c5 100644 --- a/rules/socket/shim.rs +++ b/rules/socket/shim.rs @@ -36,13 +36,7 @@ pub struct SockaddrIn { } #[derive( - Clone, - Default, - Record, - ByteRepr, - ZeroInitialization, - TriviallyDefaultConstructible, - TriviallyCopyable, + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, )] #[byte_size(28)] pub struct SockaddrIn6 { @@ -197,44 +191,6 @@ impl SockaddrIn6 { } } -impl Default for Sockaddr { - fn default() -> Self { - Self { - sa_family: 0, - sa_data: vec![0i8; 14].into_boxed_slice(), - } - } -} - -impl Default for SockaddrIn { - fn default() -> Self { - Self { - sin_family: 0, - sin_port: 0, - sin_addr: InAddr::default(), - sin_zero: vec![0u8; 8].into_boxed_slice(), - } - } -} - -impl Default for SockaddrUn { - fn default() -> Self { - Self { - sun_family: 0, - sun_path: vec![0i8; 108].into_boxed_slice(), - } - } -} - -impl Default for SockaddrStorage { - fn default() -> Self { - Self { - ss_family: 0, - __pad: vec![0u8; 126].into_boxed_slice(), - } - } -} - impl ByteRepr for ::libc::sockaddr {} impl ByteRepr for ::libc::sockaddr_in {} impl ByteRepr for ::libc::sockaddr_in6 {} diff --git a/rules/stat/shim.rs b/rules/stat/shim.rs index 2643e8ec7a..cfea6f90d1 100644 --- a/rules/stat/shim.rs +++ b/rules/stat/shim.rs @@ -5,9 +5,7 @@ use crate::TriviallyDefaultConstructible; use crate::{ByteRepr, Record, TriviallyCopyable, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive( - Clone, Default, Record, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, -)] +#[derive(Clone, Record, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable)] // The fields have the sizes of those of libc::stat only in x86-64 Linux. #[cfg_attr( all(target_os = "linux", target_arch = "x86_64"), diff --git a/rules/termios/shim.rs b/rules/termios/shim.rs index a5dfbc66cd..db114eb28f 100644 --- a/rules/termios/shim.rs +++ b/rules/termios/shim.rs @@ -31,21 +31,6 @@ pub struct Termios { pub c_ospeed: u32, } -impl Default for Termios { - fn default() -> Self { - Self { - c_iflag: 0, - c_oflag: 0, - c_cflag: 0, - c_lflag: 0, - c_line: 0, - c_cc: vec![0u8; 32].into_boxed_slice(), - c_ispeed: 0, - c_ospeed: 0, - } - } -} - impl Termios { #[allow(clippy::unnecessary_cast)] pub fn from_libc(t: &::libc::termios) -> Self { @@ -109,13 +94,7 @@ impl Termios { } #[derive( - Clone, - Default, - Record, - ByteRepr, - ZeroInitialization, - TriviallyDefaultConstructible, - TriviallyCopyable, + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, )] #[byte_size(size_of::<::libc::winsize>())] pub struct Winsize { diff --git a/rules/time/shim.rs b/rules/time/shim.rs index c30e468c1f..88a4bc392e 100644 --- a/rules/time/shim.rs +++ b/rules/time/shim.rs @@ -6,13 +6,7 @@ use crate::{ByteRepr, Ptr, Record, TriviallyCopyable, ZeroInitialization}; use std::mem::{offset_of, size_of}; #[derive( - Clone, - Default, - Record, - ByteRepr, - ZeroInitialization, - TriviallyDefaultConstructible, - TriviallyCopyable, + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, )] #[byte_size(size_of::<::libc::tm>())] pub struct Tm { @@ -75,13 +69,7 @@ impl Tm { } #[derive( - Clone, - Default, - Record, - ByteRepr, - ZeroInitialization, - TriviallyDefaultConstructible, - TriviallyCopyable, + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, )] #[byte_size(size_of::<::libc::timeval>())] pub struct Timeval { @@ -92,13 +80,7 @@ pub struct Timeval { } #[derive( - Clone, - Default, - Record, - ByteRepr, - ZeroInitialization, - TriviallyDefaultConstructible, - TriviallyCopyable, + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, )] #[byte_size(size_of::<::libc::timespec>())] pub struct Timespec { diff --git a/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs b/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs index ee2522bdfe..ce984b7f41 100644 --- a/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs +++ b/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(4)] pub struct widget { diff --git a/tests/multi-file/cross_tu_tag_collision/out/unsafe/cross_tu_tag_collision.rs b/tests/multi-file/cross_tu_tag_collision/out/unsafe/cross_tu_tag_collision.rs index a6566b5214..1d2874c29f 100644 --- a/tests/multi-file/cross_tu_tag_collision/out/unsafe/cross_tu_tag_collision.rs +++ b/tests/multi-file/cross_tu_tag_collision/out/unsafe/cross_tu_tag_collision.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct widget { pub id: i32, diff --git a/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs index bc4ba39164..f95187b346 100644 --- a/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs +++ b/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs @@ -34,11 +34,6 @@ impl S { field!(this, n).write(Box::new([(*x.borrow()), ((*x.borrow()) + 1)])); } } -impl Default for S { - fn default() -> Self { - { ::zero_init() } - } -} #[derive( Clone, Record, @@ -50,7 +45,6 @@ impl Default for S { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -67,7 +61,12 @@ impl T { return (((*this.upgrade().deref()).v.len()) as i32); } pub fn constructor_1(this: Ptr) { - field!(this, v).write(Vec::new()); + this.write(::default()); + } +} +impl Default for T { + fn default() -> Self { + { T { v: Vec::new() } } } } pub fn sum_0(s: Ptr) -> i32 { @@ -106,7 +105,7 @@ pub fn shuffle_1(mut x: i32) -> i32 { u.clone(), RvalueRef::bind(t.as_pointer()) )); - object!(w, T::constructor_1()); + let w: Value = Rc::new(RefCell::new(::default())); assign!(w = RvalueRef(u)); assert!( ((({ T::size(t.as_pointer(),) }) == 0) && (({ T::size(u.as_pointer(),) }) == 0)) diff --git a/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs index 736e2c672a..dc9da839f6 100644 --- a/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs +++ b/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs @@ -13,7 +13,6 @@ use std::rc::Rc; DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -41,7 +40,6 @@ impl S { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -55,7 +53,12 @@ impl T { return (((*this).v.len()) as i32); } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(Vec::new()); + this.write(::default()); + } +} +impl Default for T { + fn default() -> Self { + unsafe { T { v: Vec::new() } } } } pub unsafe fn sum_0(s: *const S) -> i32 { @@ -94,7 +97,7 @@ pub unsafe fn shuffle_1(mut x: i32) -> i32 { u, RvalueRefUnsafe::bind(&mut t) )); - object_unsafe!(w, T::constructor_1()); + let mut w: T = ::default(); assign_unsafe!(w = RvalueRefUnsafe(u)); assert!( (((unsafe { T::size(&raw const t,) }) == (0)) diff --git a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs index 1b1ac0deb3..a02d77c9aa 100644 --- a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs index 9b135af2e2..a886b2e72b 100644 --- a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs b/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs index 4f7fd71566..199b2d160c 100644 --- a/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs +++ b/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct container { diff --git a/tests/multi-file/opaque_forward_decl/out/unsafe/opaque_forward_decl.rs b/tests/multi-file/opaque_forward_decl/out/unsafe/opaque_forward_decl.rs index b5489afd25..bdc484dbe8 100644 --- a/tests/multi-file/opaque_forward_decl/out/unsafe/opaque_forward_decl.rs +++ b/tests/multi-file/opaque_forward_decl/out/unsafe/opaque_forward_decl.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct container { pub p: *mut opaque, diff --git a/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs b/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs index 10e90ff48d..1e4226c12e 100644 --- a/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs +++ b/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs @@ -31,9 +31,7 @@ impl S { return this.with(|__s| __s.v); } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[byte_size(4)] pub struct M { @@ -54,7 +52,6 @@ pub trait Base { FnPtrArg, DefaultInitializable, Copyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -74,7 +71,6 @@ impl Derived {} FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs b/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs index 51e50e971e..311b98cde1 100644 --- a/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs +++ b/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs @@ -29,9 +29,7 @@ impl S { } } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] pub struct M { pub v: i32, @@ -49,7 +47,6 @@ pub unsafe trait Base { ZeroInitializationUnsafe, DefaultInitializableUnsafe, CopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -66,7 +63,6 @@ impl Derived {} ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs index f23fc96578..1828a85db4 100644 --- a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs @@ -29,7 +29,7 @@ impl S_int_ { field!(this, x).write(v); } pub fn constructor_1(this: Ptr) { - field!(this, x).write(0); + this.write(::default()); } } impl Default for S_int_ { @@ -42,7 +42,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(p, S_int_::constructor_1()); + let p: Value = Rc::new(RefCell::new(::default())); ({ S_int_::set(p.as_pointer(), 3) }); assert!((({ f_0((p.as_pointer()),) }) == 3)); return 0; diff --git a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs index 4623ba404f..9dc09a3583 100644 --- a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs @@ -26,7 +26,7 @@ impl S_int_ { (*this).x = v; } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).x).write(0); + this.write(::default()); } } impl Default for S_int_ { @@ -41,7 +41,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(p, S_int_::constructor_1()); + let mut p: S_int_ = ::default(); (unsafe { S_int_::set(&raw mut p, 3) }); assert!(((unsafe { f_0((&mut p as *mut S_int_),) }) == (3))); return 0; diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index 66076fe075..58817dd82b 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs @@ -136,7 +136,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index 5949c7cd1a..f1986b8bc3 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs @@ -116,7 +116,6 @@ pub static mut shared_5: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index dc756f1f38..8b6b1ad6b1 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs @@ -102,7 +102,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -132,7 +131,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index 8752bcaa6e..b326994488 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs @@ -82,7 +82,6 @@ pub static mut member_4: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -110,7 +109,6 @@ pub static mut member_5: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index fda33c6c38..267c1438a1 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs @@ -200,7 +200,6 @@ fn main_0() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -245,7 +244,6 @@ pub fn b_count_local_15() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index fa90a916bb..bdb6ab28a6 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -173,7 +173,6 @@ unsafe fn main_0() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -213,7 +212,6 @@ pub unsafe fn b_count_local_15() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index ff87206292..3cb5b1142e 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs @@ -113,7 +113,6 @@ impl Destructible for AssertsDtorCountAtExit { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs index 347a2005ea..d99048ebe4 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs @@ -92,7 +92,6 @@ impl DestructibleUnsafe for AssertsDtorCountAtExit { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs index b8797e781b..c93bfcc621 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -53,13 +53,6 @@ impl anon_13 { this.reinterpret_cast() } } -impl Default for anon_13 { - fn default() -> Self { - anon_13 { - __bytes: Box::from([0u8; 4]), - } - } -} thread_local!( pub static anon_13: Value = Rc::new(RefCell::new(::default())); ); @@ -95,7 +88,7 @@ pub struct Record_19 { } impl Record_19 { pub fn constructor_1(this: Ptr) { - field!(this, id).write(100); + this.write(::default()); } } impl Default for Record_19 { @@ -110,8 +103,8 @@ pub fn test_21() { assert!((({ bump_18() }) == 2)); assert!((({ bump_in_b_22() }) == 51)); assert!((counter_17.with(|rc| *rc.borrow()) == 2)); - object!(record, Record_19::constructor_1()); - assert!(({ (*record.borrow()).id } == 100)); + let mut record: Record_19 = ::default(); + assert!((record.id == 100)); assert!((({ record_id_in_b_23() }) == 200)); assert!((depth_20.with(|rc| *rc.borrow()) == 3)); assert!((({ depth_in_b_24() }) == 4)); @@ -138,7 +131,6 @@ pub fn test_29() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -169,7 +161,6 @@ pub fn test_33() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -228,12 +219,12 @@ thread_local!( static count_48: Value = Rc::new(RefCell::new(1)); ); pub fn first_key_51() -> i32 { - object!(entry, Entry_52::constructor_1()); - return { (*entry.borrow()).key }; + let mut entry: Entry_52 = ::default(); + return entry.key; } pub fn second_key_plus_value_53() -> i32 { - object!(entry, Entry_54::constructor_1()); - return ({ (*entry.borrow()).key } + { (*entry.borrow()).value }); + let mut entry: Entry_54 = ::default(); + return (entry.key + entry.value); } pub fn test_55() { assert!((({ first_key_51() }) == 1)); @@ -260,7 +251,7 @@ pub struct Entry_52 { } impl Entry_52 { pub fn constructor_1(this: Ptr) { - field!(this, key).write(1); + this.write(::default()); } } impl Default for Entry_52 { @@ -290,8 +281,7 @@ pub struct Entry_54 { } impl Entry_54 { pub fn constructor_1(this: Ptr) { - field!(this, key).write(2); - field!(this, value).write(30); + this.write(::default()); } } impl Default for Entry_54 { @@ -382,13 +372,6 @@ impl anon_62 { this.reinterpret_cast() } } -impl Default for anon_62 { - fn default() -> Self { - anon_62 { - __bytes: Box::from([0u8; 4]), - } - } -} thread_local!( pub static anon_62: Value = Rc::new(RefCell::new(::default())); ); @@ -426,8 +409,7 @@ pub struct Record_65 { } impl Record_65 { pub fn constructor_1(this: Ptr) { - field!(this, id).write(200_i64); - field!(this, extra).write(1); + this.write(::default()); } } impl Default for Record_65 { @@ -447,8 +429,8 @@ pub fn bump_in_b_22() -> i32 { return ({ bump_64() }); } pub fn record_id_in_b_23() -> i32 { - object!(record, Record_65::constructor_1()); - return ({ (*record.borrow()).id } as i32); + let mut record: Record_65 = ::default(); + return (record.id as i32); } pub fn depth_in_b_24() -> i32 { return depth_66.with(|rc| *rc.borrow()); @@ -476,7 +458,6 @@ pub fn raise_30(mut by: i32) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -524,8 +505,8 @@ thread_local!( static count_70: Value = Rc::new(RefCell::new(0)); ); pub fn key_in_b_56() -> i32 { - object!(entry, Entry_71::constructor_1()); - return ({ (*entry.borrow()).key } as i32); + let mut entry: Entry_71 = ::default(); + return (entry.key as i32); } #[derive( Copy, @@ -547,7 +528,7 @@ pub struct Entry_71 { } impl Entry_71 { pub fn constructor_1(this: Ptr) { - field!(this, key).write(400_i64); + this.write(::default()); } } impl Default for Entry_71 { diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs index ec942e8e60..47cdeb836a 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -50,11 +50,6 @@ pub union anon_13 { pub whole: i32, pub fraction: f32, } -impl Default for anon_13 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} pub static mut anon_13: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { ::default() }); pub unsafe fn test_14() { @@ -84,7 +79,7 @@ pub struct Record_19 { } impl Record_19 { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).id).write(100); + this.write(::default()); } } impl Default for Record_19 { @@ -97,7 +92,7 @@ pub unsafe fn test_21() { assert!(((unsafe { bump_18() }) == (2))); assert!(((unsafe { bump_in_b_22() }) == (51))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut counter_17)) == (2))); - object_unsafe!(record, Record_19::constructor_1()); + let mut record: Record_19 = ::default(); assert!(((record.id) == (100))); assert!(((unsafe { record_id_in_b_23() }) == (200))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut depth_20)) == (3))); @@ -124,7 +119,6 @@ pub unsafe fn test_29() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -151,7 +145,6 @@ pub unsafe fn test_33() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -203,11 +196,11 @@ pub unsafe fn test_49() { static mut count_46: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); static mut count_48: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); pub unsafe fn first_key_51() -> i32 { - object_unsafe!(entry, Entry_52::constructor_1()); + let mut entry: Entry_52 = ::default(); return entry.key; } pub unsafe fn second_key_plus_value_53() -> i32 { - object_unsafe!(entry, Entry_54::constructor_1()); + let mut entry: Entry_54 = ::default(); return ((entry.key) + (entry.value)); } pub unsafe fn test_55() { @@ -232,7 +225,7 @@ pub struct Entry_52 { } impl Entry_52 { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).key).write(1); + this.write(::default()); } } impl Default for Entry_52 { @@ -258,8 +251,7 @@ pub struct Entry_54 { } impl Entry_54 { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).key).write(2); - (&raw mut (*this).value).write(30); + this.write(::default()); } } impl Default for Entry_54 { @@ -332,11 +324,6 @@ pub union anon_62 { pub whole: i32, pub fraction: f32, } -impl Default for anon_62 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} pub static mut anon_62: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { ::default() }); pub unsafe fn set_whole_in_b_15(mut value: i32) { @@ -367,8 +354,7 @@ pub struct Record_65 { } impl Record_65 { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).id).write(200_i64); - (&raw mut (*this).extra).write(1); + this.write(::default()); } } impl Default for Record_65 { @@ -386,7 +372,7 @@ pub unsafe fn bump_in_b_22() -> i32 { return (unsafe { bump_64() }); } pub unsafe fn record_id_in_b_23() -> i32 { - object_unsafe!(record, Record_65::constructor_1()); + let mut record: Record_65 = ::default(); return (record.id as i32); } pub unsafe fn depth_in_b_24() -> i32 { @@ -411,7 +397,6 @@ pub unsafe fn raise_30(mut by: i32) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -448,7 +433,7 @@ pub unsafe fn next_in_b_50() -> i32 { } static mut count_70: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub unsafe fn key_in_b_56() -> i32 { - object_unsafe!(entry, Entry_71::constructor_1()); + let mut entry: Entry_71 = ::default(); return (entry.key as i32); } #[repr(C)] @@ -468,7 +453,7 @@ pub struct Entry_71 { } impl Entry_71 { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).key).write(400_i64); + this.write(::default()); } } impl Default for Entry_71 { diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs index 166826eb34..ff32925db4 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs @@ -39,7 +39,7 @@ impl p1_member_hides_namespace_variable_HasBalance { return balance_0.with(|rc| *rc.borrow()); } pub fn constructor_1(this: Ptr) { - field!(this, balance).write(7); + this.write(::default()); } } impl Default for p1_member_hides_namespace_variable_HasBalance { @@ -48,10 +48,9 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { } } pub fn test_1() { - object!( - object, - p1_member_hides_namespace_variable_HasBalance::constructor_1() - ); + let object: Value = Rc::new(RefCell::new( + ::default(), + )); assert!( (({ p1_member_hides_namespace_variable_HasBalance::deposit(object.as_pointer(), 3,) }) == 10) @@ -89,7 +88,7 @@ pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { } impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub fn constructor_1(this: Ptr) { - field!(this, held).write(1); + this.write(::default()); } } impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { @@ -114,9 +113,8 @@ impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { } pub fn test_5() { assert!((total_4.with(|rc| *rc.borrow()) == 7)); - object!( - object, - p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::constructor_1() + let object: Value = Rc::new( + RefCell::new(::default()), ); assert!( (({ diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs index c20a931c54..767fedea51 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs index 2966ede095..6a610fc542 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs @@ -27,7 +27,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -105,20 +104,6 @@ impl p9_func_declared_before_function_body_RecordsConstructorName { ); } } -impl Default for p9_func_declared_before_function_body_RecordsConstructorName { - fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p9_func_declared_before_function_body_RecordsConstructorName::constructor_1( - __v.as_pointer(), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} pub fn plain_function_5() -> Ptr { return Ptr::::from_string_literal(b"plain_function"); } diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs index af1207012a..dbec0de591 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs @@ -54,7 +54,6 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -98,7 +97,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -141,13 +139,6 @@ impl anon_8 { this.reinterpret_cast() } } -impl Default for anon_8 { - fn default() -> Self { - anon_8 { - __bytes: Box::from([0u8; 8]), - } - } -} thread_local!( pub static anon_8: Value = Rc::new(RefCell::new(::default())); ); @@ -175,13 +166,6 @@ impl anon_9 { this.reinterpret_cast() } } -impl Default for anon_9 { - fn default() -> Self { - anon_9 { - __bytes: Box::from([0u8; 8]), - } - } -} #[derive( Clone, Record, @@ -191,7 +175,6 @@ impl Default for anon_9 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -259,13 +242,6 @@ impl anon_11 { this.reinterpret_cast() } } -impl Default for anon_11 { - fn default() -> Self { - anon_11 { - __bytes: Box::from([0u8; 8]), - } - } -} #[derive( Copy, Clone, @@ -300,8 +276,7 @@ impl p3_2_const_qualified_member_is_distinct_HasConstOverload { return 2; } pub fn constructor_1(this: Ptr) { - field!(this, plain_calls).write(0); - field!(this, const_calls).write(0); + this.write(::default()); } } impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { @@ -315,9 +290,8 @@ impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { } } pub fn test_12() { - object!( - object, - p3_2_const_qualified_member_is_distinct_HasConstOverload::constructor_1() + let object: Value = Rc::new( + RefCell::new(::default()), ); let view: Ptr = object.as_pointer(); assert!( @@ -371,7 +345,7 @@ impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverl return ((this.with(|__s| __s.base) + amount) + 100); } pub fn constructor_1(this: Ptr) { - field!(this, base).write(10); + this.write(::default()); } } impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { @@ -384,7 +358,11 @@ impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplici } } pub fn test_15() { - object!(object, p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1()); + let object: Value< + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload, + > = Rc::new(RefCell::new( + ::default(), + )); assert!( (({ p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::pick_1( @@ -395,16 +373,11 @@ pub fn test_15() { ); assert!((explicit_calls_13.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_14.with(|rc| *rc.borrow()) == 0)); - { - let __tmp_0: Value< - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload, - > = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - assert!( - (({ - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( { p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1(__tmp_0.as_pointer()) ; __tmp_0.as_pointer() } , 2 , ) - }) == 112) - ) - }; + assert!( + (({ + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( Rc::new(RefCell::new(::default() )).as_pointer() , 2 , ) + }) == 112) + ); assert!((explicit_calls_13.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_14.with(|rc| *rc.borrow()) == 1)); } @@ -424,7 +397,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -497,8 +469,7 @@ pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOv } impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { pub fn constructor_1(this: Ptr) { - field!(this, plain_calls).write(0); - field!(this, const_calls).write(0); + this.write(::default()); } pub fn get_1_int(this: Ptr, mut value: i32) -> i32 { field!(this, plain_calls).with_mut(|__v| { @@ -524,11 +495,11 @@ impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemp } } pub fn test_19() { - object!( - object, - p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::constructor_1( - ) - ); + let object: Value = + Rc::new(RefCell::new( + ::default( + ), + )); let view: Ptr = object.as_pointer(); assert!( @@ -568,7 +539,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -621,7 +591,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -641,7 +610,6 @@ pub fn shared_friend_24() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -686,7 +654,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -717,7 +684,6 @@ pub fn test_33() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs index d72be59edc..b42c194248 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs @@ -32,7 +32,7 @@ impl p1_member_hides_namespace_variable_HasBalance { return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)); } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).balance).write(7); + this.write(::default()); } } impl Default for p1_member_hides_namespace_variable_HasBalance { @@ -41,10 +41,8 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { } } pub unsafe fn test_1() { - object_unsafe!( - object, - p1_member_hides_namespace_variable_HasBalance::constructor_1() - ); + let mut object: p1_member_hides_namespace_variable_HasBalance = + ::default(); assert!( ((unsafe { p1_member_hides_namespace_variable_HasBalance::deposit(&raw mut object, 3,) }) == (10)) @@ -77,7 +75,7 @@ pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { } impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).held).write(1); + this.write(::default()); } } impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { @@ -99,10 +97,8 @@ impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { } pub unsafe fn test_5() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_4)) == (7))); - object_unsafe!( - object, - p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::constructor_1() - ); + let mut object: p1_out_of_class_definition_is_in_class_scope_HasStaticTotal = + ::default(); assert!( ((unsafe { p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::add(&raw mut object, 4) diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs index d3424bc960..4b9c2d9629 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs index 16559374a7..6effd98287 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs @@ -27,7 +27,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -103,20 +102,6 @@ impl p9_func_declared_before_function_body_RecordsConstructorName { assert!((((*this).name) == (c"RecordsConstructorName".as_ptr()))); } } -impl Default for p9_func_declared_before_function_body_RecordsConstructorName { - fn default() -> Self { - unsafe { - { - let mut __v: p9_func_declared_before_function_body_RecordsConstructorName = - ZeroInitializationUnsafe::zero_init(); - p9_func_declared_before_function_body_RecordsConstructorName::constructor_1( - &raw mut __v, - ); - __v - } - } - } -} pub unsafe fn plain_function_5() -> *const libc::c_char { return c"plain_function".as_ptr(); } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs index fd92c6ac36..237d1740ce 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs @@ -50,7 +50,6 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -89,7 +88,6 @@ pub static mut count_6: std::cell::LazyCell = std::cell::LazyCell::new(|| u ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -121,11 +119,6 @@ pub union anon_8 { pub namespace_count: i32, pub namespace_ratio: f64, } -impl Default for anon_8 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} pub static mut anon_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { ::default() }); #[repr(C)] @@ -142,11 +135,6 @@ pub union anon_9 { pub member_count: i32, pub member_ratio: f64, } -impl Default for anon_9 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -156,7 +144,6 @@ impl Default for anon_9 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -211,11 +198,6 @@ pub union anon_11 { pub block_count: i32, pub block_ratio: f64, } -impl Default for anon_11 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -242,8 +224,7 @@ impl p3_2_const_qualified_member_is_distinct_HasConstOverload { return 2; } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).plain_calls).write(0); - (&raw mut (*this).const_calls).write(0); + this.write(::default()); } } impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { @@ -257,10 +238,8 @@ impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { } } pub unsafe fn test_12() { - object_unsafe!( - object, - p3_2_const_qualified_member_is_distinct_HasConstOverload::constructor_1() - ); + let mut object: p3_2_const_qualified_member_is_distinct_HasConstOverload = + ::default(); let view: *const p3_2_const_qualified_member_is_distinct_HasConstOverload = &object; assert!( ((unsafe { @@ -309,7 +288,7 @@ impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverl return ((((*this).base) + (amount)) + (100)); } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).base).write(10); + this.write(::default()); } } impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { @@ -322,7 +301,8 @@ impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplici } } pub unsafe fn test_15() { - object_unsafe!(object, p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1()); + let mut object: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = + ::default(); assert!( ((unsafe { p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::pick_1( @@ -333,14 +313,11 @@ pub unsafe fn test_15() { ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut explicit_calls_13)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_14)) == (0))); - { - let mut __tmp_0: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = ZeroInitializationUnsafe::zero_init(); - assert!( - ((unsafe { - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1(&raw mut __tmp_0) ; & mut __tmp_0 } ) , 2 , ) - }) == (112)) - ) - }; + assert!( + ((unsafe { + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut ::default() , 2 , ) + }) == (112)) + ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut explicit_calls_13)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_14)) == (1))); } @@ -357,7 +334,6 @@ pub static mut rvalue_calls_17: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -417,8 +393,7 @@ pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOv } impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).plain_calls).write(0); - (&raw mut (*this).const_calls).write(0); + this.write(::default()); } pub unsafe fn get_1_int(this: *mut Self, mut value: i32) -> i32 { (*this).plain_calls.prefix_inc(); @@ -440,11 +415,8 @@ impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemp } } pub unsafe fn test_19() { - object_unsafe!( - object, - p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::constructor_1( - ) - ); + let mut object: p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload = + ::default(); let view: *const p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload = &object; assert!( @@ -481,7 +453,6 @@ pub static mut rvalue_calls_21: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -531,7 +502,6 @@ pub static mut friend_calls_23: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -549,7 +519,6 @@ pub unsafe fn shared_friend_24() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -589,7 +558,6 @@ pub static mut function_calls_31: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -617,7 +585,6 @@ pub unsafe fn test_33() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs index b55aea53a8..dfaee8a866 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs @@ -74,7 +74,6 @@ pub struct HoldsTracker { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -176,7 +175,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs index 47926e2396..13147e4933 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs @@ -71,7 +71,6 @@ pub struct HoldsTracker { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -177,7 +176,6 @@ pub static mut trivial_9: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/basic/basic.types/out/refcount/basic.types.general.rs b/tests/std/basic/basic.types/out/refcount/basic.types.general.rs index 62a94b610e..b9d5ac08c0 100644 --- a/tests/std/basic/basic.types/out/refcount/basic.types.general.rs +++ b/tests/std/basic/basic.types/out/refcount/basic.types.general.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -28,30 +27,38 @@ pub struct p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { pub second: i32, } pub fn test_0() { - let pm: Value = Rc::new(RefCell::new( - (offset_of_field!( + let pm: Value = Rc::new(RefCell::new(DataMemberPointer::from_offset( + offset_of_field!( p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, second - ) as isize), - )); + ) as isize, + ))); let bytes: Value> = Rc::new(RefCell::new((0..8).map(|_| 0_u8).collect::>())); { let mut __tmp_0 = { (bytes.decay()).to_any() }; - __tmp_0.memcpy(&(pm.as_pointer()).to_any(), ::std::mem::size_of::()); + __tmp_0.memcpy( + &(pm.as_pointer()).to_any(), + ::std::mem::size_of::(), + ); (__tmp_0).clone() }; - (*pm.borrow_mut()) = - (offset_of_field!(p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, first) as isize); + (*pm.borrow_mut()) = DataMemberPointer::from_offset(offset_of_field!( + p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, + first + ) as isize); { let mut __tmp_1 = { (pm.as_pointer()).to_any() }; - __tmp_1.memcpy(&(bytes.decay()).to_any(), ::std::mem::size_of::()); + __tmp_1.memcpy( + &(bytes.decay()).to_any(), + ::std::mem::size_of::(), + ); (__tmp_1).clone() }; assert!( ({ ((*pm.borrow()) - == (offset_of_field!( + == DataMemberPointer::from_offset(offset_of_field!( p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, second ) as isize)) @@ -64,23 +71,28 @@ pub fn test_0() { }, )); assert!(({ (((obj.as_pointer()).member::((*pm.borrow())).read()) == 4) })); - let null_pm: Value = Rc::new(RefCell::new(-1_isize)); + let null_pm: Value = Rc::new(RefCell::new(DataMemberPointer::null())); { let mut __tmp_2 = { (bytes.decay()).to_any() }; __tmp_2.memcpy( &(null_pm.as_pointer()).to_any(), - ::std::mem::size_of::(), + ::std::mem::size_of::(), ); (__tmp_2).clone() }; - (*null_pm.borrow_mut()) = - (offset_of_field!(p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, first) as isize); + (*null_pm.borrow_mut()) = DataMemberPointer::from_offset(offset_of_field!( + p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, + first + ) as isize); { let mut __tmp_3 = { (null_pm.as_pointer()).to_any() }; - __tmp_3.memcpy(&(bytes.decay()).to_any(), ::std::mem::size_of::()); + __tmp_3.memcpy( + &(bytes.decay()).to_any(), + ::std::mem::size_of::(), + ); (__tmp_3).clone() }; - assert!(({ ((*null_pm.borrow()) == -1_isize) })); + assert!(({ (*null_pm.borrow()).is_null() })); } #[derive( Copy, @@ -92,7 +104,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -104,14 +115,14 @@ pub struct p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts { pub second: i32, } pub fn test_1() { - let source: Value = Rc::new(RefCell::new( - (offset_of_field!( + let source: Value = Rc::new(RefCell::new(DataMemberPointer::from_offset( + offset_of_field!( p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts, second - ) as isize), - )); - let destination: Value = Rc::new(RefCell::new( - (offset_of_field!( + ) as isize, + ))); + let destination: Value = Rc::new(RefCell::new( + DataMemberPointer::from_offset(offset_of_field!( p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts, first ) as isize), @@ -120,7 +131,7 @@ pub fn test_1() { let mut __tmp_4 = { (destination.as_pointer()).to_any() }; __tmp_4.memcpy( &(source.as_pointer()).to_any(), - ::std::mem::size_of::(), + ::std::mem::size_of::(), ); (__tmp_4).clone() }; @@ -140,16 +151,16 @@ pub fn test_1() { == 4) }) ); - let null_source: Value = Rc::new(RefCell::new(-1_isize)); + let null_source: Value = Rc::new(RefCell::new(DataMemberPointer::null())); { let mut __tmp_5 = { (destination.as_pointer()).to_any() }; __tmp_5.memcpy( &(null_source.as_pointer()).to_any(), - ::std::mem::size_of::(), + ::std::mem::size_of::(), ); (__tmp_5).clone() }; - assert!(({ ((*destination.borrow()) == -1_isize) })); + assert!(({ (*destination.borrow()).is_null() })); } pub fn main() { __cpp2rust_init_globals(); diff --git a/tests/std/basic/basic.types/out/unsafe/basic.types.general.rs b/tests/std/basic/basic.types/out/unsafe/basic.types.general.rs index b7ff0e156e..e5b4d18f96 100644 --- a/tests/std/basic/basic.types/out/unsafe/basic.types.general.rs +++ b/tests/std/basic/basic.types/out/unsafe/basic.types.general.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -24,35 +23,45 @@ pub struct p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { pub second: i32, } pub unsafe fn test_0() { - let mut pm: isize = (::std::mem::offset_of!( + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, second ) as isize); let mut bytes: [u8; 8] = [0_u8; 8]; { let mut __tmp_0 = { (bytes.as_mut_ptr() as *mut ::libc::c_void) }; - let mut __tmp_1 = { ((&mut pm as *mut isize) as *const ::libc::c_void) }; - if ::std::mem::size_of::() != 0 { - ::std::ptr::copy_nonoverlapping(__tmp_1, __tmp_0, ::std::mem::size_of::()) + let mut __tmp_1 = { ((&mut pm as *mut DataMemberPointer) as *const ::libc::c_void) }; + if ::std::mem::size_of::() != 0 { + ::std::ptr::copy_nonoverlapping( + __tmp_1, + __tmp_0, + ::std::mem::size_of::(), + ) } __tmp_0 }; - pm = (::std::mem::offset_of!(p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, first) - as isize); + pm = DataMemberPointer::from_offset(::std::mem::offset_of!( + p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, + first + ) as isize); { - let mut __tmp_2 = { ((&mut pm as *mut isize) as *mut ::libc::c_void) }; + let mut __tmp_2 = { ((&mut pm as *mut DataMemberPointer) as *mut ::libc::c_void) }; let mut __tmp_3 = { (bytes.as_mut_ptr() as *const ::libc::c_void) }; - if ::std::mem::size_of::() != 0 { - ::std::ptr::copy_nonoverlapping(__tmp_3, __tmp_2, ::std::mem::size_of::()) + if ::std::mem::size_of::() != 0 { + ::std::ptr::copy_nonoverlapping( + __tmp_3, + __tmp_2, + ::std::mem::size_of::(), + ) } __tmp_2 }; assert!( ((pm) - == (::std::mem::offset_of!( + == (DataMemberPointer::from_offset(::std::mem::offset_of!( p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, second - ) as isize)) + ) as isize))) ); let mut obj: p2_pointer_to_data_member_bytes_round_trip_HasTwoInts = p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { @@ -61,30 +70,40 @@ pub unsafe fn test_0() { }; assert!( ((*(&mut obj as *mut p2_pointer_to_data_member_bytes_round_trip_HasTwoInts) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::()) == (4)) ); - let mut null_pm: isize = -1_isize; + let mut null_pm: DataMemberPointer = DataMemberPointer::null(); { let mut __tmp_4 = { (bytes.as_mut_ptr() as *mut ::libc::c_void) }; - let mut __tmp_5 = { ((&mut null_pm as *mut isize) as *const ::libc::c_void) }; - if ::std::mem::size_of::() != 0 { - ::std::ptr::copy_nonoverlapping(__tmp_5, __tmp_4, ::std::mem::size_of::()) + let mut __tmp_5 = { ((&mut null_pm as *mut DataMemberPointer) as *const ::libc::c_void) }; + if ::std::mem::size_of::() != 0 { + ::std::ptr::copy_nonoverlapping( + __tmp_5, + __tmp_4, + ::std::mem::size_of::(), + ) } __tmp_4 }; - null_pm = (::std::mem::offset_of!(p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, first) - as isize); + null_pm = DataMemberPointer::from_offset(::std::mem::offset_of!( + p2_pointer_to_data_member_bytes_round_trip_HasTwoInts, + first + ) as isize); { - let mut __tmp_6 = { ((&mut null_pm as *mut isize) as *mut ::libc::c_void) }; + let mut __tmp_6 = { ((&mut null_pm as *mut DataMemberPointer) as *mut ::libc::c_void) }; let mut __tmp_7 = { (bytes.as_mut_ptr() as *const ::libc::c_void) }; - if ::std::mem::size_of::() != 0 { - ::std::ptr::copy_nonoverlapping(__tmp_7, __tmp_6, ::std::mem::size_of::()) + if ::std::mem::size_of::() != 0 { + ::std::ptr::copy_nonoverlapping( + __tmp_7, + __tmp_6, + ::std::mem::size_of::(), + ) } __tmp_6 }; - assert!(((null_pm) == -1_isize)); + assert!((null_pm).is_null()); } #[repr(C)] #[derive( @@ -95,7 +114,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -104,19 +122,24 @@ pub struct p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts { pub second: i32, } pub unsafe fn test_1() { - let mut source: isize = (::std::mem::offset_of!( + let mut source: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts, second ) as isize); - let mut destination: isize = (::std::mem::offset_of!( - p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts, - first - ) as isize); + let mut destination: DataMemberPointer = + DataMemberPointer::from_offset(::std::mem::offset_of!( + p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts, + first + ) as isize); { - let mut __tmp_8 = { ((&mut destination as *mut isize) as *mut ::libc::c_void) }; - let mut __tmp_9 = { ((&mut source as *mut isize) as *const ::libc::c_void) }; - if ::std::mem::size_of::() != 0 { - ::std::ptr::copy_nonoverlapping(__tmp_9, __tmp_8, ::std::mem::size_of::()) + let mut __tmp_8 = { ((&mut destination as *mut DataMemberPointer) as *mut ::libc::c_void) }; + let mut __tmp_9 = { ((&mut source as *mut DataMemberPointer) as *const ::libc::c_void) }; + if ::std::mem::size_of::() != 0 { + ::std::ptr::copy_nonoverlapping( + __tmp_9, + __tmp_8, + ::std::mem::size_of::(), + ) } __tmp_8 }; @@ -128,20 +151,26 @@ pub unsafe fn test_1() { }; assert!( ((*(&mut obj as *mut p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts) - .wrapping_byte_offset(destination) + .wrapping_byte_offset((destination).offset()) .cast::()) == (4)) ); - let mut null_source: isize = -1_isize; + let mut null_source: DataMemberPointer = DataMemberPointer::null(); { - let mut __tmp_10 = { ((&mut destination as *mut isize) as *mut ::libc::c_void) }; - let mut __tmp_11 = { ((&mut null_source as *mut isize) as *const ::libc::c_void) }; - if ::std::mem::size_of::() != 0 { - ::std::ptr::copy_nonoverlapping(__tmp_11, __tmp_10, ::std::mem::size_of::()) + let mut __tmp_10 = + { ((&mut destination as *mut DataMemberPointer) as *mut ::libc::c_void) }; + let mut __tmp_11 = + { ((&mut null_source as *mut DataMemberPointer) as *const ::libc::c_void) }; + if ::std::mem::size_of::() != 0 { + ::std::ptr::copy_nonoverlapping( + __tmp_11, + __tmp_10, + ::std::mem::size_of::(), + ) } __tmp_10 }; - assert!(((destination) == -1_isize)); + assert!((destination).is_null()); } pub fn main() { unsafe { diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 4aa16c4365..9ded0a1d71 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -19,7 +19,6 @@ thread_local!( MoveConstructible, MoveAssignable, Swappable, - Default, )] #[memberwise(copy_assign)] #[derive(Conversions)] @@ -253,17 +252,21 @@ pub trait p4_1_pure_virtual_without_definition_HasPureVirtual { ZeroInitialization, VaArg, FnPtrArg, - DefaultInitializable, + Destructible, Copyable, - Default, Conversions, )] #[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} +impl p4_1_pure_virtual_without_definition_OverridesPureVirtual { + pub fn constructor_1(this: Ptr) {} +} pub fn test_11() { - let d: Value = Rc::new( - RefCell::new(::default()), + object!( + d, + p4_1_pure_virtual_without_definition_OverridesPureVirtual::constructor_1() ); let mut p: PtrDyn = (d.as_pointer()).to_dyn::(|w| w); @@ -381,7 +384,6 @@ thread_local!( MoveConstructible, MoveAssignable, Swappable, - Default, )] #[memberwise(copy_assign)] #[derive(Conversions)] @@ -660,18 +662,6 @@ impl p9_unused_copy_constructor_HasUndefinedCopyCtor { (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); } } -impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} pub fn read_30(object: Ptr) -> i32 { return object.with(|__s| __s.value); } @@ -708,20 +698,6 @@ impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); } } -impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1( - __v.as_pointer(), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} #[derive( Copy, Clone, @@ -732,7 +708,6 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { FnPtrArg, Destructible, Copyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 96d07ff20f..2d30428bf2 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -16,7 +16,6 @@ pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new( MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] @@ -206,16 +205,21 @@ pub unsafe trait p4_1_pure_virtual_without_definition_HasPureVirtual { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DefaultInitializableUnsafe, + DestructibleUnsafe, CopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} +impl p4_1_pure_virtual_without_definition_OverridesPureVirtual { + pub unsafe fn constructor_1(this: *mut Self) {} +} pub unsafe fn test_11() { - let mut d: p4_1_pure_virtual_without_definition_OverridesPureVirtual = - ::default(); + object_unsafe!( + d, + p4_1_pure_virtual_without_definition_OverridesPureVirtual::constructor_1() + ); let mut p: *mut dyn p4_1_pure_virtual_without_definition_HasPureVirtual = (&mut d as *mut p4_1_pure_virtual_without_definition_OverridesPureVirtual); (unsafe { (*p).f() }); @@ -333,7 +337,6 @@ pub static mut copies_18: std::cell::LazyCell = std::cell::LazyCell::new(|| MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] @@ -593,18 +596,6 @@ impl p9_unused_copy_constructor_HasUndefinedCopyCtor { (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)).prefix_inc(); } } -impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn default() -> Self { - unsafe { - { - let mut __v: p9_unused_copy_constructor_HasUndefinedCopyCtor = - ZeroInitializationUnsafe::zero_init(); - p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1(&raw mut __v); - __v - } - } - } -} pub unsafe fn read_30(object: *const p9_unused_copy_constructor_HasUndefinedCopyCtor) -> i32 { return (*object).value; } @@ -637,20 +628,6 @@ impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)).prefix_inc(); } } -impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn default() -> Self { - unsafe { - { - let mut __v: p9_unused_implicit_assignment_HasUndefinedCopyAssignment = - ZeroInitializationUnsafe::zero_init(); - p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1( - &raw mut __v, - ); - __v - } - } - } -} #[repr(C)] #[derive( Copy, @@ -660,7 +637,6 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/class/class.compare/out/refcount/class.spaceship.rs b/tests/std/class/class.compare/out/refcount/class.spaceship.rs index 222558373f..9ba14eb07f 100644 --- a/tests/std/class/class.compare/out/refcount/class.spaceship.rs +++ b/tests/std/class/class.compare/out/refcount/class.spaceship.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -127,7 +126,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -217,7 +215,6 @@ pub fn test_1() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(weak_ordering_from_user_operator_Fraction::operator_cmp)] @@ -342,7 +339,6 @@ pub fn test_2() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(partial_ordering_from_user_operator_Interval::operator_cmp)] diff --git a/tests/std/class/class.compare/out/unsafe/class.spaceship.rs b/tests/std/class/class.compare/out/unsafe/class.spaceship.rs index 38362beb7f..191925992f 100644 --- a/tests/std/class/class.compare/out/unsafe/class.spaceship.rs +++ b/tests/std/class/class.compare/out/unsafe/class.spaceship.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -127,7 +126,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -205,7 +203,6 @@ pub unsafe fn test_1() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(weak_ordering_from_user_operator_Fraction::operator_cmp)] @@ -315,7 +312,6 @@ pub unsafe fn test_2() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(partial_ordering_from_user_operator_Interval::operator_cmp)] diff --git a/tests/std/class/class.init/out/refcount/class.base.init.rs b/tests/std/class/class.init/out/refcount/class.base.init.rs index e684057e0f..bc65b3ca2f 100644 --- a/tests/std/class/class.init/out/refcount/class.base.init.rs +++ b/tests/std/class/class.init/out/refcount/class.base.init.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/class/class.init/out/unsafe/class.base.init.rs b/tests/std/class/class.init/out/unsafe/class.base.init.rs index 89a481c297..31ea050fe8 100644 --- a/tests/std/class/class.init/out/unsafe/class.base.init.rs +++ b/tests/std/class/class.init/out/unsafe/class.base.init.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs index 7d5e62eabe..c3ff30087b 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs @@ -25,7 +25,6 @@ impl p1_template_constructor_from_own_type_Probe { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -64,7 +63,6 @@ pub fn test_0() { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -173,7 +171,6 @@ pub fn test_1() { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -245,7 +242,6 @@ pub fn test_2() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -264,7 +260,6 @@ pub struct p2_explicit_constructor_and_conversion_function_Source { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs index 4c4224906a..49aba4337c 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -51,7 +50,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -132,7 +130,6 @@ pub fn test_1() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -171,7 +168,6 @@ pub fn test_2() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs index ec44ca2f4a..5fbd4828b1 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs @@ -24,7 +24,6 @@ impl p1_template_constructor_from_own_type_Probe { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -60,7 +59,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -133,7 +131,6 @@ pub unsafe fn test_1() { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -185,7 +182,6 @@ pub unsafe fn test_2() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -201,7 +197,6 @@ pub struct p2_explicit_constructor_and_conversion_function_Source { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs index 9aa229123c..746f9ae7c3 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -45,7 +44,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -109,7 +107,6 @@ pub unsafe fn test_1() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -141,7 +138,6 @@ pub unsafe fn test_2() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs index 6f462ee343..824508ccf4 100644 --- a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs @@ -6,9 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise)] #[memberwise(move_constructor)] #[derive(Conversions)] #[conversions(move)] diff --git a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs index d59560429f..20fbb6cc3e 100644 --- a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs @@ -7,9 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe)] #[memberwise(move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(move)] diff --git a/tests/std/class/class.mem/class.mem.general-unsupported.cpp b/tests/std/class/class.mem/class.mem.general-unsupported.cpp deleted file mode 100644 index d9ec9528f0..0000000000 --- a/tests/std/class/class.mem/class.mem.general-unsupported.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// no-compile: refcount, unsafe -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -#include - -// N4950 [class.mem.general]/7.5: a default member initializer within the -// member-specification of a class is a complete-class context. -namespace p7_5_default_member_initializer_names_later_member { -static int member_calls; - -int base = 100; -int scaled(int amount) { return amount * 1000; } - -struct HasLaterInitializerOperands { - int first = base + 1; - int second = scaled(first); - - static inline int base = 4; - int scaled(int amount) const { - ++member_calls; - return amount * 10; - } -}; - -void test() { - HasLaterInitializerOperands object; - assert(object.first == 5); - assert(object.second == 50); - assert(member_calls == 1); - assert(base == 100); -} -} // namespace p7_5_default_member_initializer_names_later_member - -int main() { - p7_5_default_member_initializer_names_later_member::test(); - return 0; -} diff --git a/tests/std/class/class.mem/class.mem.general.cpp b/tests/std/class/class.mem/class.mem.general.cpp index c4a31c54de..f3b318f21b 100644 --- a/tests/std/class/class.mem/class.mem.general.cpp +++ b/tests/std/class/class.mem/class.mem.general.cpp @@ -50,8 +50,37 @@ void test() { } } // namespace p7_2_default_argument_names_later_member +// N4950 [class.mem.general]/7.5: a default member initializer within the +// member-specification of a class is a complete-class context. +namespace p7_5_default_member_initializer_names_later_member { +static int member_calls; + +int base = 100; +int scaled(int amount) { return amount * 1000; } + +struct HasLaterInitializerOperands { + int first = base + 1; + int second = scaled(first); + + static inline int base = 4; + int scaled(int amount) const { + ++member_calls; + return amount * 10; + } +}; + +void test() { + HasLaterInitializerOperands object; + assert(object.first == 5); + assert(object.second == 50); + assert(member_calls == 1); + assert(base == 100); +} +} // namespace p7_5_default_member_initializer_names_later_member + int main() { p7_1_function_body_names_later_member::test(); p7_2_default_argument_names_later_member::test(); + p7_5_default_member_initializer_names_later_member::test(); return 0; } diff --git a/tests/std/class/class.mem/out/refcount/class.free.rs b/tests/std/class/class.mem/out/refcount/class.free.rs index b432d72898..9aec1f06e8 100644 --- a/tests/std/class/class.mem/out/refcount/class.free.rs +++ b/tests/std/class/class.mem/out/refcount/class.free.rs @@ -19,7 +19,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -69,7 +68,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/class/class.mem/out/refcount/class.mem.general.rs b/tests/std/class/class.mem/out/refcount/class.mem.general.rs index 977c66d683..c49d7dda38 100644 --- a/tests/std/class/class.mem/out/refcount/class.mem.general.rs +++ b/tests/std/class/class.mem/out/refcount/class.mem.general.rs @@ -45,7 +45,7 @@ impl p7_1_function_body_names_later_member_HasLaterMembers { return 2; } pub fn constructor_1(this: Ptr) { - field!(this, stock).write(9); + this.write(::default()); } } impl Default for p7_1_function_body_names_later_member_HasLaterMembers { @@ -54,9 +54,8 @@ impl Default for p7_1_function_body_names_later_member_HasLaterMembers { } } pub fn test_3() { - object!( - object, - p7_1_function_body_names_later_member_HasLaterMembers::constructor_1() + let object: Value = Rc::new( + RefCell::new(::default()), ); assert!( (({ @@ -98,7 +97,7 @@ impl p7_2_default_argument_names_later_member_HasLaterStaticStep { return this.with(|__s| __s.total); } pub fn constructor_1(this: Ptr) { - field!(this, total).write(1); + this.write(::default()); } } impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { @@ -107,9 +106,8 @@ impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { } } pub fn test_6() { - object!( - object, - p7_2_default_argument_names_later_member_HasLaterStaticStep::constructor_1() + let object: Value = Rc::new( + RefCell::new(::default()), ); assert!( (({ @@ -129,6 +127,55 @@ pub fn test_6() { ); assert!((step_4.with(|rc| *rc.borrow()) == 100)); } +thread_local!( + pub static member_calls_7: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static base_8: Value = Rc::new(RefCell::new(100)); +); +pub fn scaled_9(mut amount: i32) -> i32 { + return (amount * 1000); +} +thread_local!( + pub static base_10: Value = Rc::new(RefCell::new(4)); +); +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[byte_size(8)] +pub struct p7_5_default_member_initializer_names_later_member_HasLaterInitializerOperands { + #[offset(0)] + pub first: i32, + #[offset(4)] + pub second: i32, +} +impl p7_5_default_member_initializer_names_later_member_HasLaterInitializerOperands { + pub fn scaled(this: Ptr, mut amount: i32) -> i32 { + (*member_calls_7.with(Value::clone).borrow_mut()).prefix_inc(); + return (amount * 10); + } + pub fn constructor_1(this: Ptr) { + field!(this, first).write((base_10.with(|rc| *rc.borrow()) + 1)); + field!(this, second).write(( { p7_5_default_member_initializer_names_later_member_HasLaterInitializerOperands :: scaled ( this.clone() , this .with(|__s| __s . first ) , ) } ) ); + } +} +pub fn test_11() { + object!(object, p7_5_default_member_initializer_names_later_member_HasLaterInitializerOperands::constructor_1()); + assert!(({ (*object.borrow()).first } == 5)); + assert!(({ (*object.borrow()).second } == 50)); + assert!((member_calls_7.with(|rc| *rc.borrow()) == 1)); + assert!((base_8.with(|rc| *rc.borrow()) == 100)); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -136,10 +183,14 @@ pub fn main() { fn main_0() -> i32 { ({ test_3() }); ({ test_6() }); + ({ test_11() }); return 0; } pub fn __cpp2rust_init_globals() { let _ = stock_0.with(|_| ()); let _ = step_4.with(|_| ()); let _ = step_5.with(|_| ()); + let _ = member_calls_7.with(|_| ()); + let _ = base_8.with(|_| ()); + let _ = base_10.with(|_| ()); } diff --git a/tests/std/class/class.mem/out/unsafe/class.free.rs b/tests/std/class/class.mem/out/unsafe/class.free.rs index cc8588b0d2..67fe9f9ac2 100644 --- a/tests/std/class/class.mem/out/unsafe/class.free.rs +++ b/tests/std/class/class.mem/out/unsafe/class.free.rs @@ -16,7 +16,6 @@ pub static mut allocations_0: std::cell::LazyCell = std::cell::LazyCell::ne ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -61,7 +60,6 @@ pub static mut deallocations_2: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs index 5eace88cf7..6be6a953d6 100644 --- a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs +++ b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs @@ -40,7 +40,7 @@ impl p7_1_function_body_names_later_member_HasLaterMembers { return 2; } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).stock).write(9); + this.write(::default()); } } impl Default for p7_1_function_body_names_later_member_HasLaterMembers { @@ -49,10 +49,8 @@ impl Default for p7_1_function_body_names_later_member_HasLaterMembers { } } pub unsafe fn test_3() { - object_unsafe!( - object, - p7_1_function_body_names_later_member_HasLaterMembers::constructor_1() - ); + let mut object: p7_1_function_body_names_later_member_HasLaterMembers = + ::default(); assert!( ((unsafe { p7_1_function_body_names_later_member_HasLaterMembers::take(&raw mut object, 3) @@ -84,7 +82,7 @@ impl p7_2_default_argument_names_later_member_HasLaterStaticStep { return (*this).total; } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).total).write(1); + this.write(::default()); } } impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { @@ -93,10 +91,8 @@ impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { } } pub unsafe fn test_6() { - object_unsafe!( - object, - p7_2_default_argument_names_later_member_HasLaterStaticStep::constructor_1() - ); + let mut object: p7_2_default_argument_names_later_member_HasLaterStaticStep = + ::default(); assert!( ((unsafe { p7_2_default_argument_names_later_member_HasLaterStaticStep::advance( @@ -112,6 +108,47 @@ pub unsafe fn test_6() { ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut step_4)) == (100))); } +pub static mut member_calls_7: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut base_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); +pub unsafe fn scaled_9(mut amount: i32) -> i32 { + return ((amount) * (1000)); +} +pub static mut base_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +pub struct p7_5_default_member_initializer_names_later_member_HasLaterInitializerOperands { + pub first: i32, + pub second: i32, +} +impl p7_5_default_member_initializer_names_later_member_HasLaterInitializerOperands { + pub unsafe fn scaled(this: *const Self, mut amount: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut member_calls_7)).prefix_inc(); + return ((amount) * (10)); + } + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).first) + .write(((*std::cell::LazyCell::force_mut(&mut *&raw mut base_10)) + (1))); + (&raw mut (*this).second).write(( unsafe { let _amount: i32 = ( * this ) . first ; p7_5_default_member_initializer_names_later_member_HasLaterInitializerOperands :: scaled ( ( this ) .cast_const() , _amount , ) } ) ); + } +} +pub unsafe fn test_11() { + object_unsafe!(object, p7_5_default_member_initializer_names_later_member_HasLaterInitializerOperands::constructor_1()); + assert!(((object.first) == (5))); + assert!(((object.second) == (50))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut member_calls_7)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut base_8)) == (100))); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -121,10 +158,14 @@ pub fn main() { unsafe fn main_0() -> i32 { (unsafe { test_3() }); (unsafe { test_6() }); + (unsafe { test_11() }); return 0; } pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const stock_0); std::cell::LazyCell::force(&*&raw const step_4); std::cell::LazyCell::force(&*&raw const step_5); + std::cell::LazyCell::force(&*&raw const member_calls_7); + std::cell::LazyCell::force(&*&raw const base_8); + std::cell::LazyCell::force(&*&raw const base_10); } diff --git a/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs b/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs index 36685a983f..4235945156 100644 --- a/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs +++ b/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs @@ -19,7 +19,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -56,7 +55,6 @@ pub fn test_1() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -103,7 +101,6 @@ pub fn test_2() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs b/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs index ac877077aa..d88b51e186 100644 --- a/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs +++ b/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs @@ -25,7 +25,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -68,7 +67,6 @@ pub fn test_3() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -135,7 +133,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs b/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs index 232ae81cb3..7de7d66210 100644 --- a/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs +++ b/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs @@ -17,7 +17,6 @@ pub static mut not_equal_calls_0: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -44,7 +43,6 @@ pub unsafe fn test_1() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -87,7 +85,6 @@ pub unsafe fn test_2() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs b/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs index 4afcb87738..9d66c12fcd 100644 --- a/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs +++ b/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs @@ -21,7 +21,6 @@ pub static mut greater_equal_calls_2: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -62,7 +61,6 @@ pub unsafe fn test_3() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -128,7 +126,6 @@ pub static mut greater_calls_5: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs b/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs index 3d6901ad4e..0800a386c9 100644 --- a/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs +++ b/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -41,7 +40,6 @@ impl p1_constructible_from_Meters { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -98,14 +96,7 @@ pub fn test_0() { ); } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - DefaultInitializable, - Memberwise, - MoveAssignable, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, MoveAssignable, )] #[memberwise(copy_assign)] #[derive(Conversions)] diff --git a/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs b/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs index 08b66f6b78..a13b4bdda9 100644 --- a/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs +++ b/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -41,7 +40,6 @@ impl p1_convertible_to_Meters { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -66,7 +64,6 @@ impl p1_convertible_to_Celsius { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs b/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs index 8d18ed56ae..e702f8f311 100644 --- a/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs +++ b/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ impl p1_constructible_from_Meters { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -89,7 +87,6 @@ pub unsafe fn test_0() { DefaultInitializableUnsafe, MemberwiseUnsafe, MoveAssignableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] diff --git a/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs b/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs index 3a19952892..524ebbc817 100644 --- a/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs +++ b/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ impl p1_convertible_to_Meters { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -59,7 +57,6 @@ impl p1_convertible_to_Celsius { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs b/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs index 21121f5e06..e7459e2b50 100644 --- a/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs +++ b/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -80,7 +79,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs b/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs index 17cd966374..f6618863e2 100644 --- a/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs +++ b/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -65,7 +64,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general-p6.2-padding-bits.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general-p6.2-padding-bits.rs index 7331d89a7f..fa920d0aec 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general-p6.2-padding-bits.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general-p6.2-padding-bits.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ pub struct p6_2_zero_initialized_padding_Padded { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -58,7 +56,6 @@ pub struct p6_2_zero_initialized_padding_TailPadded { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs index 8cf6d61f92..7738362b99 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -44,37 +43,39 @@ pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { pub struct p6_1_zero_initialized_pointer_to_member_HoldsSelector { #[offset(0)] #[byte_size(8)] - pub selector: isize, -} -impl Default for p6_1_zero_initialized_pointer_to_member_HoldsSelector { - fn default() -> Self { - { p6_1_zero_initialized_pointer_to_member_HoldsSelector { selector: -1_isize } } - } + pub selector: DataMemberPointer, } thread_local!( - pub static static_pm_0: Value = Rc::new(RefCell::new(-1_isize)); + pub static static_pm_0: Value = + Rc::new(RefCell::new(DataMemberPointer::null())); ); pub fn test_1() { - assert!(((static_pm_0.with(|rc| *rc.borrow())) == -1_isize)); + assert!((static_pm_0.with(|rc| *rc.borrow())).is_null()); assert!( (static_pm_0.with(|rc| *rc.borrow()) - != (offset_of_field!(p6_1_zero_initialized_pointer_to_member_HasTwoInts, first) - as isize)) + != DataMemberPointer::from_offset(offset_of_field!( + p6_1_zero_initialized_pointer_to_member_HasTwoInts, + first + ) as isize)) ); - let mut value_initialized: isize = -1_isize; - assert!(((value_initialized) == -1_isize)); + let mut value_initialized: DataMemberPointer = DataMemberPointer::null(); + assert!((value_initialized).is_null()); assert!( (value_initialized - != (offset_of_field!(p6_1_zero_initialized_pointer_to_member_HasTwoInts, first) - as isize)) + != DataMemberPointer::from_offset(offset_of_field!( + p6_1_zero_initialized_pointer_to_member_HasTwoInts, + first + ) as isize)) ); let mut holder: p6_1_zero_initialized_pointer_to_member_HoldsSelector = ::default(); - assert!(((holder.selector) == -1_isize)); + assert!((holder.selector).is_null()); assert!( (holder.selector - != (offset_of_field!(p6_1_zero_initialized_pointer_to_member_HasTwoInts, first) - as isize)) + != DataMemberPointer::from_offset(offset_of_field!( + p6_1_zero_initialized_pointer_to_member_HasTwoInts, + first + ) as isize)) ); } pub type p6_1_zero_initialized_scalars_Color = i32; @@ -145,7 +146,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -187,20 +187,6 @@ pub struct p6_2_zero_initialized_class_Outer { #[array_len(2)] pub inners: Box<[p6_2_zero_initialized_class_Inner]>, } -impl Default for p6_2_zero_initialized_class_Outer { - fn default() -> Self { - { - p6_2_zero_initialized_class_Outer { - letter: 0_i8, - inner: ::default(), - numbers: (0..3).map(|_| 0_i32).collect::>(), - inners: (0..2) - .map(|_| ::default()) - .collect::>(), - } - } - } -} thread_local!( pub static static_outer_13: Value = Rc::new(RefCell::new(::default())); @@ -265,13 +251,6 @@ impl p6_3_zero_initialized_union_Number { this.reinterpret_cast() } } -impl Default for p6_3_zero_initialized_union_Number { - fn default() -> Self { - p6_3_zero_initialized_union_Number { - __bytes: Box::from([0u8; 8]), - } - } -} thread_local!( pub static static_number_16: Value = Rc::new(RefCell::new(::default())); @@ -296,7 +275,6 @@ pub fn test_17() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -425,8 +403,7 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { } impl p9_1_2_zero_then_default_initialized_WithDefaultMember { pub fn constructor_1(this: Ptr) { - field!(this, zeroed).write(0_i32); - field!(this, five).write(5); + this.write(::default()); } } impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { @@ -459,21 +436,12 @@ pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { } impl p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub fn constructor_1(this: Ptr) { - field!(this, untouched).write(0_i32); + this.write(::default()); } } impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1( - __v.as_pointer(), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { p9_1_2_zero_then_default_initialized_LeavesMemberAlone { untouched: 0_i32 } } } } #[derive( @@ -485,7 +453,6 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { VaArg, FnPtrArg, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -500,39 +467,35 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { } impl p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub fn constructor_1(this: Ptr) { - field!(this, number).write(0_i32); - p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1(field_ptr!( - this, member - )); + this.write(::default()); + } +} +impl Default for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + fn default() -> Self { + { + p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + number: 0_i32, + member: ::default(), + } + } } } pub fn test_22() { - object!( - value, - p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1() - ); - assert!(({ (*value.borrow()).zeroed } == 0)); - assert!(({ (*value.borrow()).five } == 5)); - let mut heap: Ptr = { - let __p = Ptr::alloc(::zero_init()); - p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1(__p.clone()); - __p - }; + let mut value: p9_1_2_zero_then_default_initialized_WithDefaultMember = + ::default(); + assert!((value.zeroed == 0)); + assert!((value.five == 5)); + let mut heap: Ptr = + Ptr::alloc(::default()); assert!((heap.with(|__s| __s.zeroed) == 0)); assert!((heap.with(|__s| __s.five) == 5)); heap.delete(); - object!( - holder, - p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1() - ); - assert!(({ (*holder.borrow()).number } == 0)); - assert!(({ (*holder.borrow()).member.untouched } == 0)); - let mut heap_holder: Ptr = { - let __p = - Ptr::alloc(::zero_init()); - p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1(__p.clone()); - __p - }; + let mut holder: p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = + ::default(); + assert!((holder.number == 0)); + assert!((holder.member.untouched == 0)); + let mut heap_holder: Ptr = + Ptr::alloc(::default()); assert!((heap_holder.with(|__s| __s.number) == 0)); assert!((heap_holder.with(|__s| __s.member.untouched) == 0)); heap_holder.delete(); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs index ab9b8c59fa..2b258e2d4e 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs @@ -24,7 +24,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general-p6.2-padding-bits.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general-p6.2-padding-bits.rs index f19f44d2d9..eef227dd5e 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general-p6.2-padding-bits.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general-p6.2-padding-bits.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct p6_2_zero_initialized_padding_Padded { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -49,7 +47,6 @@ pub struct p6_2_zero_initialized_padding_TailPadded { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs index 406fec871f..f29ba2819d 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -36,36 +35,37 @@ pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { )] #[conversions(copy, move)] pub struct p6_1_zero_initialized_pointer_to_member_HoldsSelector { - pub selector: isize, + pub selector: DataMemberPointer, } -impl Default for p6_1_zero_initialized_pointer_to_member_HoldsSelector { - fn default() -> Self { - unsafe { p6_1_zero_initialized_pointer_to_member_HoldsSelector { selector: -1_isize } } - } -} -pub static mut static_pm_0: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { -1_isize }); +pub static mut static_pm_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { DataMemberPointer::null() }); pub unsafe fn test_1() { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_pm_0)) == -1_isize)); + assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut static_pm_0)).is_null()); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_pm_0)) - != (::std::mem::offset_of!(p6_1_zero_initialized_pointer_to_member_HasTwoInts, first) - as isize)) + != (DataMemberPointer::from_offset(::std::mem::offset_of!( + p6_1_zero_initialized_pointer_to_member_HasTwoInts, + first + ) as isize))) ); - let mut value_initialized: isize = -1_isize; - assert!(((value_initialized) == -1_isize)); + let mut value_initialized: DataMemberPointer = DataMemberPointer::null(); + assert!((value_initialized).is_null()); assert!( ((value_initialized) - != (::std::mem::offset_of!(p6_1_zero_initialized_pointer_to_member_HasTwoInts, first) - as isize)) + != (DataMemberPointer::from_offset(::std::mem::offset_of!( + p6_1_zero_initialized_pointer_to_member_HasTwoInts, + first + ) as isize))) ); let mut holder: p6_1_zero_initialized_pointer_to_member_HoldsSelector = ::default(); - assert!(((holder.selector) == -1_isize)); + assert!((holder.selector).is_null()); assert!( ((holder.selector) - != (::std::mem::offset_of!(p6_1_zero_initialized_pointer_to_member_HasTwoInts, first) - as isize)) + != (DataMemberPointer::from_offset(::std::mem::offset_of!( + p6_1_zero_initialized_pointer_to_member_HasTwoInts, + first + ) as isize))) ); } pub type p6_1_zero_initialized_scalars_Color = i32; @@ -136,7 +136,6 @@ static mut counter_11: std::cell::LazyCell = std::cell::LazyCell::new(|| un ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -154,7 +153,6 @@ pub struct p6_2_zero_initialized_class_Inner { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -222,11 +220,6 @@ pub union p6_3_zero_initialized_union_Number { pub integer: i32, pub bytes: [libc::c_char; 8], } -impl Default for p6_3_zero_initialized_union_Number { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} pub static mut static_number_16: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { ::default() }); pub unsafe fn test_17() { @@ -244,7 +237,6 @@ pub unsafe fn test_17() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -354,8 +346,7 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { } impl p9_1_2_zero_then_default_initialized_WithDefaultMember { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).zeroed).write(0_i32); - (&raw mut (*this).five).write(5); + this.write(::default()); } } impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { @@ -385,19 +376,12 @@ pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { } impl p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).untouched).write(0_i32); + this.write(::default()); } } impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { fn default() -> Self { - unsafe { - { - let mut __v: p9_1_2_zero_then_default_initialized_LeavesMemberAlone = - ZeroInitializationUnsafe::zero_init(); - p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1(&raw mut __v); - __v - } - } + unsafe { p9_1_2_zero_then_default_initialized_LeavesMemberAlone { untouched: 0_i32 } } } } #[repr(C)] @@ -408,7 +392,6 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -419,26 +402,28 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { } impl p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).number).write(0_i32); - p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1( - &raw mut (*this).member, - ); + this.write(::default()); + } +} +impl Default for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + fn default() -> Self { + unsafe { + p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + number: 0_i32, + member: ::default(), + } + } } } pub unsafe fn test_22() { - object_unsafe!( - value, - p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1() - ); + let mut value: p9_1_2_zero_then_default_initialized_WithDefaultMember = + ::default(); assert!(((value.zeroed) == (0))); assert!(((value.five) == (5))); - let mut heap: *mut p9_1_2_zero_then_default_initialized_WithDefaultMember = { - let __p: *mut p9_1_2_zero_then_default_initialized_WithDefaultMember = Box::leak(Box::new( - ::zero_init(), - )); - p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1(__p); - __p - }; + let mut heap: *mut p9_1_2_zero_then_default_initialized_WithDefaultMember = (Box::leak( + Box::new(::default()), + ) + as *mut p9_1_2_zero_then_default_initialized_WithDefaultMember); assert!((((*heap).zeroed) == (0))); assert!((((*heap).five) == (5))); { @@ -447,19 +432,14 @@ pub unsafe fn test_22() { ::std::mem::drop(Box::from_raw(__p)) } }; - object_unsafe!( - holder, - p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1() - ); + let mut holder: p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = + ::default(); assert!(((holder.number) == (0))); assert!(((holder.member.untouched) == (0))); - let mut heap_holder: *mut p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = { - let __p: *mut p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = Box::leak( - Box::new(::zero_init()), - ); - p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1(__p); - __p - }; + let mut heap_holder: *mut p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = + (Box::leak(Box::new( + ::default(), + )) as *mut p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone); assert!((((*heap_holder).number) == (0))); assert!((((*heap_holder).member.untouched) == (0))); { diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs index fbdd2cce8f..d18a56bb40 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs @@ -23,7 +23,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.array.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.array.rs index 54ff35794d..95d88cc9f9 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.array.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.array.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -30,10 +29,19 @@ pub struct p6_array_of_pointers_to_data_members_HasThreeInts { pub third: i32, } pub fn test_0() { - let members: Value> = Rc::new(RefCell::new(Box::new([ - (offset_of_field!(p6_array_of_pointers_to_data_members_HasThreeInts, third) as isize), - (offset_of_field!(p6_array_of_pointers_to_data_members_HasThreeInts, first) as isize), - (offset_of_field!(p6_array_of_pointers_to_data_members_HasThreeInts, second) as isize), + let members: Value> = Rc::new(RefCell::new(Box::new([ + DataMemberPointer::from_offset(offset_of_field!( + p6_array_of_pointers_to_data_members_HasThreeInts, + third + ) as isize), + DataMemberPointer::from_offset(offset_of_field!( + p6_array_of_pointers_to_data_members_HasThreeInts, + first + ) as isize), + DataMemberPointer::from_offset(offset_of_field!( + p6_array_of_pointers_to_data_members_HasThreeInts, + second + ) as isize), ]))); let obj: Value = Rc::new(RefCell::new( p6_array_of_pointers_to_data_members_HasThreeInts { @@ -66,7 +74,7 @@ pub fn test_0() { == 5) }) ); - let mut element: Ptr = members.decay(); + let mut element: Ptr = members.decay(); assert!(({ element.offset((1) as isize) } == { (members.decay().offset(1)) })); assert!( (((obj.as_pointer()) @@ -78,8 +86,10 @@ pub fn test_0() { element.prefix_inc(); assert!(({ (element).clone() } == { (members.decay().offset(2)) })); assert!((((obj.as_pointer()).member::((element.read())).read()) == 5)); - (*members.borrow_mut())[(2) as usize] = - (offset_of_field!(p6_array_of_pointers_to_data_members_HasThreeInts, third) as isize); + (*members.borrow_mut())[(2) as usize] = DataMemberPointer::from_offset(offset_of_field!( + p6_array_of_pointers_to_data_members_HasThreeInts, + third + ) as isize); assert!((((obj.as_pointer()).member::((element.read())).read()) == 6)); } pub fn main() { diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs index bb0cbf37f5..35fa40799d 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs @@ -80,7 +80,7 @@ impl p9_static_member_hides_namespace_variable_HasStaticStep { return this.with(|__s| __s.total); } pub fn constructor_1(this: Ptr) { - field!(this, total).write(1); + this.write(::default()); } } impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { @@ -89,9 +89,8 @@ impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { } } pub fn test_11() { - object!( - object, - p9_static_member_hides_namespace_variable_HasStaticStep::constructor_1() + let object: Value = Rc::new( + RefCell::new(::default()), ); assert!( (({ @@ -159,21 +158,6 @@ impl Constructor<()> for p9_evaluated_each_time_called_Widget { } } } -impl Default for p9_evaluated_each_time_called_Widget { - fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p9_evaluated_each_time_called_Widget::constructor_1( - __v.as_pointer(), - ({ count_default_13() }), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} thread_local!( static base_15: Value = Rc::new(RefCell::new(10)); ); @@ -211,7 +195,7 @@ impl p9_evaluated_each_time_called_Account { base_15.with(|rc| *rc.borrow_mut() = value); } pub fn constructor_1(this: Ptr) { - field!(this, balance).write(0); + this.write(::default()); } } impl Default for p9_evaluated_each_time_called_Account { @@ -242,10 +226,9 @@ pub fn test_17() { assert!(({ (*b.borrow()).id } == 40)); assert!(({ (*c.borrow()).id } == 5)); assert!((defaults_evaluated_12.with(|rc| *rc.borrow()) == 5)); - object!( - account, - p9_evaluated_each_time_called_Account::constructor_1() - ); + let account: Value = Rc::new(RefCell::new( + ::default(), + )); assert!( (({ p9_evaluated_each_time_called_Account::deposit( @@ -282,7 +265,6 @@ pub fn add_18(mut a: i32, mut b: i32) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.mptr.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.mptr.rs index cdfc059fb1..c0caba7c8f 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.mptr.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.mptr.rs @@ -27,19 +27,11 @@ pub struct p2_pointer_to_array_member_HasIntArray { #[array_len(3)] pub elements: Box<[i32]>, } -impl Default for p2_pointer_to_array_member_HasIntArray { - fn default() -> Self { - { - p2_pointer_to_array_member_HasIntArray { - before: 0_i32, - elements: (0..3).map(|_| 0_i32).collect::>(), - } - } - } -} pub fn test_0() { - let mut pm: isize = - (offset_of_field!(p2_pointer_to_array_member_HasIntArray, elements) as isize); + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(offset_of_field!( + p2_pointer_to_array_member_HasIntArray, + elements + ) as isize); let obj: Value = Rc::new(RefCell::new(p2_pointer_to_array_member_HasIntArray { before: 1, @@ -61,7 +53,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -73,7 +64,10 @@ pub struct p2_pointer_to_data_member_HasTwoInts { pub second: i32, } pub fn test_1() { - let mut pm: isize = (offset_of_field!(p2_pointer_to_data_member_HasTwoInts, first) as isize); + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(offset_of_field!( + p2_pointer_to_data_member_HasTwoInts, + first + ) as isize); let obj: Value = Rc::new(RefCell::new(p2_pointer_to_data_member_HasTwoInts { first: 3, @@ -83,14 +77,17 @@ pub fn test_1() { (obj.as_pointer()).member::(pm).write(5); assert!(({ (*obj.borrow()).first } == 5)); assert!(({ (*obj.borrow()).second } == 4)); - pm = (offset_of_field!(p2_pointer_to_data_member_HasTwoInts, second) as isize); + pm = DataMemberPointer::from_offset(offset_of_field!( + p2_pointer_to_data_member_HasTwoInts, + second + ) as isize); assert!((((obj.as_pointer()).member::(pm).read()) == 4)); (obj.as_pointer()).member::(pm).write(6); assert!(({ (*obj.borrow()).first } == 5)); assert!(({ (*obj.borrow()).second } == 6)); } thread_local!( - pub static pm_2: Value = Rc::new(RefCell::new(-1_isize)); + pub static pm_2: Value = Rc::new(RefCell::new(DataMemberPointer::null())); ); #[derive( Copy, @@ -102,7 +99,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -114,9 +110,9 @@ pub struct p2_pointer_to_member_of_incomplete_class_CompletedLater { pub second: i32, } pub fn test_3() { - assert!(((pm_2.with(|rc| *rc.borrow())) == -1_isize)); + assert!((pm_2.with(|rc| *rc.borrow())).is_null()); pm_2.with(|rc| { - *rc.borrow_mut() = (offset_of_field!( + *rc.borrow_mut() = DataMemberPointer::from_offset(offset_of_field!( p2_pointer_to_member_of_incomplete_class_CompletedLater, second ) as isize) @@ -144,7 +140,6 @@ pub fn test_3() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -172,22 +167,17 @@ pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { pub struct p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector { #[offset(0)] #[byte_size(8)] - pub selector: isize, -} -impl Default for p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector { - fn default() -> Self { - { p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector { selector: -1_isize } } - } + pub selector: DataMemberPointer, } pub fn test_4() { - let mut pm: isize = (offset_of_field!( + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(offset_of_field!( p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector, selector ) as isize); let holder: Value = Rc::new(RefCell::new( p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector { - selector: (offset_of_field!( + selector: DataMemberPointer::from_offset(offset_of_field!( p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts, second ) as isize), @@ -201,16 +191,16 @@ pub fn test_4() { ); assert!( (((obj.as_pointer()) - .member::(((holder.as_pointer()).member::(pm).read())) + .member::(((holder.as_pointer()).member::(pm).read())) .read()) == 4) ); - (holder.as_pointer()).member::(pm).write( - (offset_of_field!( + (holder.as_pointer()) + .member::(pm) + .write(DataMemberPointer::from_offset(offset_of_field!( p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts, first - ) as isize), - ); + ) as isize)); assert!( (((obj.as_pointer()) .member::(({ (*holder.borrow()).selector })) diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.array.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.array.rs index 7fae15cd15..22c4036df9 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.array.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.array.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -25,11 +24,19 @@ pub struct p6_array_of_pointers_to_data_members_HasThreeInts { pub third: i32, } pub unsafe fn test_0() { - let mut members: [isize; 3] = [ - (::std::mem::offset_of!(p6_array_of_pointers_to_data_members_HasThreeInts, third) as isize), - (::std::mem::offset_of!(p6_array_of_pointers_to_data_members_HasThreeInts, first) as isize), - (::std::mem::offset_of!(p6_array_of_pointers_to_data_members_HasThreeInts, second) - as isize), + let mut members: [DataMemberPointer; 3] = [ + DataMemberPointer::from_offset(::std::mem::offset_of!( + p6_array_of_pointers_to_data_members_HasThreeInts, + third + ) as isize), + DataMemberPointer::from_offset(::std::mem::offset_of!( + p6_array_of_pointers_to_data_members_HasThreeInts, + first + ) as isize), + DataMemberPointer::from_offset(::std::mem::offset_of!( + p6_array_of_pointers_to_data_members_HasThreeInts, + second + ) as isize), ]; let mut obj: p6_array_of_pointers_to_data_members_HasThreeInts = p6_array_of_pointers_to_data_members_HasThreeInts { @@ -39,44 +46,48 @@ pub unsafe fn test_0() { }; assert!( ((*(&mut obj as *mut p6_array_of_pointers_to_data_members_HasThreeInts) - .wrapping_byte_offset(members[(0) as usize]) + .wrapping_byte_offset((members[(0) as usize]).offset()) .cast::()) == (6)) ); assert!( ((*(&mut obj as *mut p6_array_of_pointers_to_data_members_HasThreeInts) - .wrapping_byte_offset(members[(1) as usize]) + .wrapping_byte_offset((members[(1) as usize]).offset()) .cast::()) == (4)) ); assert!( ((*(&mut obj as *mut p6_array_of_pointers_to_data_members_HasThreeInts) - .wrapping_byte_offset(members[(2) as usize]) + .wrapping_byte_offset((members[(2) as usize]).offset()) .cast::()) == (5)) ); - let mut element: *mut isize = members.as_mut_ptr(); - assert!(((element.offset((1) as isize)) == (&mut members[(1) as usize] as *mut isize))); + let mut element: *mut DataMemberPointer = members.as_mut_ptr(); + assert!( + ((element.offset((1) as isize)) == (&mut members[(1) as usize] as *mut DataMemberPointer)) + ); assert!( ((*(&mut obj as *mut p6_array_of_pointers_to_data_members_HasThreeInts) - .wrapping_byte_offset((*element.offset((1) as isize))) + .wrapping_byte_offset((*element.offset((1) as isize)).offset()) .cast::()) == (4)) ); element.prefix_inc(); element.prefix_inc(); - assert!(((element) == (&mut members[(2) as usize] as *mut isize))); + assert!(((element) == (&mut members[(2) as usize] as *mut DataMemberPointer))); assert!( ((*(&mut obj as *mut p6_array_of_pointers_to_data_members_HasThreeInts) - .wrapping_byte_offset((*element)) + .wrapping_byte_offset((*element).offset()) .cast::()) == (5)) ); - members[(2) as usize] = - (::std::mem::offset_of!(p6_array_of_pointers_to_data_members_HasThreeInts, third) as isize); + members[(2) as usize] = DataMemberPointer::from_offset(::std::mem::offset_of!( + p6_array_of_pointers_to_data_members_HasThreeInts, + third + ) as isize); assert!( ((*(&mut obj as *mut p6_array_of_pointers_to_data_members_HasThreeInts) - .wrapping_byte_offset((*element)) + .wrapping_byte_offset((*element).offset()) .cast::()) == (6)) ); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs index dd4664c7a7..c742d6b71b 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs @@ -74,7 +74,7 @@ impl p9_static_member_hides_namespace_variable_HasStaticStep { return (*this).total; } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).total).write(1); + this.write(::default()); } } impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { @@ -83,10 +83,8 @@ impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { } } pub unsafe fn test_11() { - object_unsafe!( - object, - p9_static_member_hides_namespace_variable_HasStaticStep::constructor_1() - ); + let mut object: p9_static_member_hides_namespace_variable_HasStaticStep = + ::default(); assert!( ((unsafe { p9_static_member_hides_namespace_variable_HasStaticStep::advance( @@ -149,21 +147,6 @@ impl ConstructorUnsafe<()> for p9_evaluated_each_time_called_Widget { } } } -impl Default for p9_evaluated_each_time_called_Widget { - fn default() -> Self { - unsafe { - { - let mut __v: p9_evaluated_each_time_called_Widget = - ZeroInitializationUnsafe::zero_init(); - p9_evaluated_each_time_called_Widget::constructor_1( - &raw mut __v, - (unsafe { count_default_13() }), - ); - __v - } - } - } -} static mut base_15: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); pub type anon_16 = u32; pub const anon_16_kBonus: anon_16 = 5; @@ -194,7 +177,7 @@ impl p9_evaluated_each_time_called_Account { (*std::cell::LazyCell::force_mut(&mut *&raw mut base_15)) = value; } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).balance).write(0); + this.write(::default()); } } impl Default for p9_evaluated_each_time_called_Account { @@ -227,10 +210,8 @@ pub unsafe fn test_17() { assert!(((b.id) == (40))); assert!(((c.id) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut defaults_evaluated_12)) == (5))); - object_unsafe!( - account, - p9_evaluated_each_time_called_Account::constructor_1() - ); + let mut account: p9_evaluated_each_time_called_Account = + ::default(); assert!( ((unsafe { p9_evaluated_each_time_called_Account::deposit( @@ -272,7 +253,6 @@ pub unsafe fn add_18(mut a: i32, mut b: i32) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.mptr.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.mptr.rs index 2affbf260f..c80d3ed299 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.mptr.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.mptr.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -24,26 +23,28 @@ pub struct p2_pointer_to_array_member_HasIntArray { pub elements: [i32; 3], } pub unsafe fn test_0() { - let mut pm: isize = - (::std::mem::offset_of!(p2_pointer_to_array_member_HasIntArray, elements) as isize); + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( + p2_pointer_to_array_member_HasIntArray, + elements + ) as isize); let mut obj: p2_pointer_to_array_member_HasIntArray = p2_pointer_to_array_member_HasIntArray { before: 1, elements: [2, 3, 4], }; assert!( (((*(&mut obj as *mut p2_pointer_to_array_member_HasIntArray) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::<[i32; 3]>())[(0) as usize]) == (2)) ); assert!( (((*(&mut obj as *mut p2_pointer_to_array_member_HasIntArray) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::<[i32; 3]>())[(2) as usize]) == (4)) ); (*(&mut obj as *mut p2_pointer_to_array_member_HasIntArray) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::<[i32; 3]>())[(1) as usize] = 7; assert!(((obj.elements[(1) as usize]) == (7))); assert!(((obj.before) == (1))); @@ -57,7 +58,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -66,37 +66,43 @@ pub struct p2_pointer_to_data_member_HasTwoInts { pub second: i32, } pub unsafe fn test_1() { - let mut pm: isize = - (::std::mem::offset_of!(p2_pointer_to_data_member_HasTwoInts, first) as isize); + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( + p2_pointer_to_data_member_HasTwoInts, + first + ) as isize); let mut obj: p2_pointer_to_data_member_HasTwoInts = p2_pointer_to_data_member_HasTwoInts { first: 3, second: 4, }; assert!( ((*(&mut obj as *mut p2_pointer_to_data_member_HasTwoInts) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::()) == (3)) ); (*(&mut obj as *mut p2_pointer_to_data_member_HasTwoInts) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::()) = 5; assert!(((obj.first) == (5))); assert!(((obj.second) == (4))); - pm = (::std::mem::offset_of!(p2_pointer_to_data_member_HasTwoInts, second) as isize); + pm = DataMemberPointer::from_offset(::std::mem::offset_of!( + p2_pointer_to_data_member_HasTwoInts, + second + ) as isize); assert!( ((*(&mut obj as *mut p2_pointer_to_data_member_HasTwoInts) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::()) == (4)) ); (*(&mut obj as *mut p2_pointer_to_data_member_HasTwoInts) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::()) = 6; assert!(((obj.first) == (5))); assert!(((obj.second) == (6))); } -pub static mut pm_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { -1_isize }); +pub static mut pm_2: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { DataMemberPointer::null() }); #[repr(C)] #[derive( Copy, @@ -106,7 +112,6 @@ pub static mut pm_2: std::cell::LazyCell = std::cell::LazyCell::new(|| un ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -115,11 +120,12 @@ pub struct p2_pointer_to_member_of_incomplete_class_CompletedLater { pub second: i32, } pub unsafe fn test_3() { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut pm_2)) == -1_isize)); - (*std::cell::LazyCell::force_mut(&mut *&raw mut pm_2)) = (::std::mem::offset_of!( - p2_pointer_to_member_of_incomplete_class_CompletedLater, - second - ) as isize); + assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut pm_2)).is_null()); + (*std::cell::LazyCell::force_mut(&mut *&raw mut pm_2)) = + DataMemberPointer::from_offset(::std::mem::offset_of!( + p2_pointer_to_member_of_incomplete_class_CompletedLater, + second + ) as isize); let mut obj: p2_pointer_to_member_of_incomplete_class_CompletedLater = p2_pointer_to_member_of_incomplete_class_CompletedLater { first: 3, @@ -127,7 +133,7 @@ pub unsafe fn test_3() { }; assert!( ((*(&mut obj as *mut p2_pointer_to_member_of_incomplete_class_CompletedLater) - .wrapping_byte_offset((*std::cell::LazyCell::force_mut(&mut *&raw mut pm_2))) + .wrapping_byte_offset((*std::cell::LazyCell::force_mut(&mut *&raw mut pm_2)).offset()) .cast::()) == (4)) ); @@ -141,7 +147,6 @@ pub unsafe fn test_3() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -162,23 +167,16 @@ pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { )] #[conversions(copy, move)] pub struct p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector { - pub selector: isize, -} -impl Default for p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector { - fn default() -> Self { - unsafe { - p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector { selector: -1_isize } - } - } + pub selector: DataMemberPointer, } pub unsafe fn test_4() { - let mut pm: isize = (::std::mem::offset_of!( + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector, selector ) as isize); let mut holder: p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector = p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector { - selector: (::std::mem::offset_of!( + selector: DataMemberPointer::from_offset(::std::mem::offset_of!( p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts, second ) as isize), @@ -193,21 +191,22 @@ pub unsafe fn test_4() { .wrapping_byte_offset( (*(&mut holder as *mut p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector) - .wrapping_byte_offset(pm) - .cast::()) + .wrapping_byte_offset((pm).offset()) + .cast::()) + .offset() ) .cast::()) == (4)) ); (*(&mut holder as *mut p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector) - .wrapping_byte_offset(pm) - .cast::()) = (::std::mem::offset_of!( + .wrapping_byte_offset((pm).offset()) + .cast::()) = DataMemberPointer::from_offset(::std::mem::offset_of!( p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts, first ) as isize); assert!( ((*(&mut obj as *mut p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts) - .wrapping_byte_offset((holder.selector)) + .wrapping_byte_offset((holder.selector).offset()) .cast::()) == (3)) ); diff --git a/tests/std/expr/conv/out/refcount/conv.mem.rs b/tests/std/expr/conv/out/refcount/conv.mem.rs index 96610506cd..41db6d1855 100644 --- a/tests/std/expr/conv/out/refcount/conv.mem.rs +++ b/tests/std/expr/conv/out/refcount/conv.mem.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -28,11 +27,15 @@ pub struct p1_null_distinct_from_first_member_HasTwoInts { pub second: i32, } pub fn test_0() { - let mut null_pm: isize = -1_isize; - let mut first_pm: isize = - (offset_of_field!(p1_null_distinct_from_first_member_HasTwoInts, first) as isize); - let mut second_pm: isize = - (offset_of_field!(p1_null_distinct_from_first_member_HasTwoInts, second) as isize); + let mut null_pm: DataMemberPointer = DataMemberPointer::null(); + let mut first_pm: DataMemberPointer = DataMemberPointer::from_offset(offset_of_field!( + p1_null_distinct_from_first_member_HasTwoInts, + first + ) as isize); + let mut second_pm: DataMemberPointer = DataMemberPointer::from_offset(offset_of_field!( + p1_null_distinct_from_first_member_HasTwoInts, + second + ) as isize); assert!((first_pm != null_pm)); assert!((second_pm != null_pm)); } diff --git a/tests/std/expr/conv/out/unsafe/conv.mem.rs b/tests/std/expr/conv/out/unsafe/conv.mem.rs index 0bbbc0409d..de9aff27e7 100644 --- a/tests/std/expr/conv/out/unsafe/conv.mem.rs +++ b/tests/std/expr/conv/out/unsafe/conv.mem.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -24,11 +23,15 @@ pub struct p1_null_distinct_from_first_member_HasTwoInts { pub second: i32, } pub unsafe fn test_0() { - let mut null_pm: isize = -1_isize; - let mut first_pm: isize = - (::std::mem::offset_of!(p1_null_distinct_from_first_member_HasTwoInts, first) as isize); - let mut second_pm: isize = - (::std::mem::offset_of!(p1_null_distinct_from_first_member_HasTwoInts, second) as isize); + let mut null_pm: DataMemberPointer = DataMemberPointer::null(); + let mut first_pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( + p1_null_distinct_from_first_member_HasTwoInts, + first + ) as isize); + let mut second_pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( + p1_null_distinct_from_first_member_HasTwoInts, + second + ) as isize); assert!(((first_pm) != (null_pm))); assert!(((second_pm) != (null_pm))); } diff --git a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.const.cast.rs b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.const.cast.rs index 901ad5a232..b36c56ffc0 100644 --- a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.const.cast.rs +++ b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.const.cast.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast-p10-result-is-unspecified.rs b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast-p10-result-is-unspecified.rs index 867b80578c..152a98e7fd 100644 --- a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast-p10-result-is-unspecified.rs +++ b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast-p10-result-is-unspecified.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ pub struct HasTwoInts { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -53,7 +51,10 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let mut converted: isize = (offset_of_field!(HasTwoInts, second) as isize); - return ((converted == (offset_of_field!(AlsoHasTwoInts, second) as isize)) as i32); + let mut converted: DataMemberPointer = + DataMemberPointer::from_offset(offset_of_field!(HasTwoInts, second) as isize); + return ((converted + == DataMemberPointer::from_offset(offset_of_field!(AlsoHasTwoInts, second) as isize)) + as i32); } pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast.rs b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast.rs index 6cc22e6992..c39bf887af 100644 --- a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast.rs +++ b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast.rs @@ -26,7 +26,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -47,7 +46,6 @@ pub struct p10_null_converts_to_null_HasTwoInts { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -57,9 +55,9 @@ pub struct p10_null_converts_to_null_HasChar { pub character: i8, } pub fn test_1() { - let mut pm: isize = -1_isize; - let mut converted: isize = pm; - assert!(((converted) == -1_isize)); + let mut pm: DataMemberPointer = DataMemberPointer::null(); + let mut converted: DataMemberPointer = pm; + assert!((converted).is_null()); } #[derive( Copy, @@ -71,7 +69,6 @@ pub fn test_1() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -92,7 +89,6 @@ pub struct p10_2_data_member_round_trip_HasTwoInts { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -102,10 +98,18 @@ pub struct p10_2_data_member_round_trip_HasChar { pub character: i8, } pub fn test_2() { - let mut converted: isize = - (offset_of_field!(p10_2_data_member_round_trip_HasTwoInts, second) as isize); - let mut back: isize = converted; - assert!((back == (offset_of_field!(p10_2_data_member_round_trip_HasTwoInts, second) as isize))); + let mut converted: DataMemberPointer = DataMemberPointer::from_offset(offset_of_field!( + p10_2_data_member_round_trip_HasTwoInts, + second + ) as isize); + let mut back: DataMemberPointer = converted; + assert!( + (back + == DataMemberPointer::from_offset(offset_of_field!( + p10_2_data_member_round_trip_HasTwoInts, + second + ) as isize)) + ); let obj: Value = Rc::new(RefCell::new(p10_2_data_member_round_trip_HasTwoInts { first: 3, diff --git a/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.const.cast.rs b/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.const.cast.rs index 3da9d84c0f..06d8928d2e 100644 --- a/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.const.cast.rs +++ b/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.const.cast.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.reinterpret.cast-p10-result-is-unspecified.rs b/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.reinterpret.cast-p10-result-is-unspecified.rs index bd21165242..b411d748c4 100644 --- a/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.reinterpret.cast-p10-result-is-unspecified.rs +++ b/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.reinterpret.cast-p10-result-is-unspecified.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct HasTwoInts { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -47,7 +45,10 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut converted: isize = (::std::mem::offset_of!(HasTwoInts, second) as isize); - return (((converted) == (::std::mem::offset_of!(AlsoHasTwoInts, second) as isize)) as i32); + let mut converted: DataMemberPointer = + DataMemberPointer::from_offset(::std::mem::offset_of!(HasTwoInts, second) as isize); + return (((converted) + == (DataMemberPointer::from_offset(::std::mem::offset_of!(AlsoHasTwoInts, second) as isize))) + as i32); } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.reinterpret.cast.rs b/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.reinterpret.cast.rs index d682c1bf4f..02f5780cb6 100644 --- a/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.reinterpret.cast.rs +++ b/tests/std/expr/expr.compound/expr.post/out/unsafe/expr.reinterpret.cast.rs @@ -25,7 +25,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -42,7 +41,6 @@ pub struct p10_null_converts_to_null_HasTwoInts { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -50,9 +48,9 @@ pub struct p10_null_converts_to_null_HasChar { pub character: libc::c_char, } pub unsafe fn test_1() { - let mut pm: isize = -1_isize; - let mut converted: isize = pm; - assert!(((converted) == -1_isize)); + let mut pm: DataMemberPointer = DataMemberPointer::null(); + let mut converted: DataMemberPointer = pm; + assert!((converted).is_null()); } #[repr(C)] #[derive( @@ -63,7 +61,6 @@ pub unsafe fn test_1() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -80,7 +77,6 @@ pub struct p10_2_data_member_round_trip_HasTwoInts { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -88,12 +84,17 @@ pub struct p10_2_data_member_round_trip_HasChar { pub character: libc::c_char, } pub unsafe fn test_2() { - let mut converted: isize = - (::std::mem::offset_of!(p10_2_data_member_round_trip_HasTwoInts, second) as isize); - let mut back: isize = converted; + let mut converted: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( + p10_2_data_member_round_trip_HasTwoInts, + second + ) as isize); + let mut back: DataMemberPointer = converted; assert!( ((back) - == (::std::mem::offset_of!(p10_2_data_member_round_trip_HasTwoInts, second) as isize)) + == (DataMemberPointer::from_offset(::std::mem::offset_of!( + p10_2_data_member_round_trip_HasTwoInts, + second + ) as isize))) ); let mut obj: p10_2_data_member_round_trip_HasTwoInts = p10_2_data_member_round_trip_HasTwoInts { @@ -102,7 +103,7 @@ pub unsafe fn test_2() { }; assert!( ((*(&mut obj as *mut p10_2_data_member_round_trip_HasTwoInts) - .wrapping_byte_offset(back) + .wrapping_byte_offset((back).offset()) .cast::()) == (4)) ); diff --git a/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.pre.incr.rs b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.pre.incr.rs index 70f4d9a972..2b11e64b3b 100644 --- a/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.pre.incr.rs +++ b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.pre.incr.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs index ed8f449014..666f30bff7 100644 --- a/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs +++ b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs @@ -22,7 +22,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -53,7 +52,6 @@ pub fn test_2() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -100,7 +98,6 @@ pub fn test_3() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.pre.incr.rs b/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.pre.incr.rs index 1f0d5fc05e..3d5cd58576 100644 --- a/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.pre.incr.rs +++ b/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.pre.incr.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs b/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs index 020ce0f383..5f03040f76 100644 --- a/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs +++ b/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs @@ -17,7 +17,6 @@ pub static mut calls_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -47,7 +46,6 @@ pub unsafe fn test_2() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -84,7 +82,6 @@ pub unsafe fn test_3() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/expr/expr.compound/out/refcount/expr.cond.rs b/tests/std/expr/expr.compound/out/refcount/expr.cond.rs index 1b589f0934..b8b3a34af4 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.cond.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.cond.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -27,11 +26,14 @@ pub struct p7_4_pointer_to_member_and_null_HasTwoInts { #[offset(4)] pub second: i32, } -pub fn second_or_null_0(mut choose_second: bool) -> isize { +pub fn second_or_null_0(mut choose_second: bool) -> DataMemberPointer { return if choose_second { - (offset_of_field!(p7_4_pointer_to_member_and_null_HasTwoInts, second) as isize) + DataMemberPointer::from_offset(offset_of_field!( + p7_4_pointer_to_member_and_null_HasTwoInts, + second + ) as isize) } else { - -1_isize + DataMemberPointer::null() }; } pub fn test_1() { @@ -40,10 +42,13 @@ pub fn test_1() { first: 3, second: 4, })); - assert!((({ second_or_null_0(false,) }) == -1_isize)); + assert!(({ second_or_null_0(false,) }).is_null()); assert!( (({ second_or_null_0(true,) }) - == (offset_of_field!(p7_4_pointer_to_member_and_null_HasTwoInts, second) as isize)) + == DataMemberPointer::from_offset(offset_of_field!( + p7_4_pointer_to_member_and_null_HasTwoInts, + second + ) as isize)) ); assert!( (((obj.as_pointer()) diff --git a/tests/std/expr/expr.compound/out/refcount/expr.eq.rs b/tests/std/expr/expr.compound/out/refcount/expr.eq.rs index 3116ba3f69..ecb22ae67b 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.eq.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.eq.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -28,8 +27,8 @@ pub struct p4_1_both_null_HasTwoInts { pub second: i32, } pub fn test_0() { - let mut first_null: isize = -1_isize; - let mut second_null: isize = -1_isize; + let mut first_null: DataMemberPointer = DataMemberPointer::null(); + let mut second_null: DataMemberPointer = DataMemberPointer::null(); assert!((first_null == second_null)); assert!(!(first_null != second_null)); } @@ -43,7 +42,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -55,8 +53,9 @@ pub struct p4_2_one_null_HasTwoInts { pub second: i32, } pub fn test_1() { - let mut null_pm: isize = -1_isize; - let mut first_pm: isize = (offset_of_field!(p4_2_one_null_HasTwoInts, first) as isize); + let mut null_pm: DataMemberPointer = DataMemberPointer::null(); + let mut first_pm: DataMemberPointer = + DataMemberPointer::from_offset(offset_of_field!(p4_2_one_null_HasTwoInts, first) as isize); assert!((first_pm != null_pm)); assert!(!(first_pm == null_pm)); assert!((null_pm != first_pm)); @@ -86,16 +85,9 @@ impl p4_5_members_of_same_union_HasTwoIntMembers { this.reinterpret_cast() } } -impl Default for p4_5_members_of_same_union_HasTwoIntMembers { - fn default() -> Self { - p4_5_members_of_same_union_HasTwoIntMembers { - __bytes: Box::from([0u8; 4]), - } - } -} pub fn test_2() { - let mut first_pm: isize = 0_isize; - let mut second_pm: isize = 0_isize; + let mut first_pm: DataMemberPointer = DataMemberPointer::from_offset(0); + let mut second_pm: DataMemberPointer = DataMemberPointer::from_offset(0); assert!((first_pm == second_pm)); assert!(!(first_pm != second_pm)); } @@ -109,7 +101,6 @@ pub fn test_2() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -121,9 +112,18 @@ pub struct p4_6_data_members_HasTwoInts { pub second: i32, } pub fn test_3() { - let mut first_pm: isize = (offset_of_field!(p4_6_data_members_HasTwoInts, first) as isize); - let mut also_first_pm: isize = (offset_of_field!(p4_6_data_members_HasTwoInts, first) as isize); - let mut second_pm: isize = (offset_of_field!(p4_6_data_members_HasTwoInts, second) as isize); + let mut first_pm: DataMemberPointer = DataMemberPointer::from_offset(offset_of_field!( + p4_6_data_members_HasTwoInts, + first + ) as isize); + let mut also_first_pm: DataMemberPointer = DataMemberPointer::from_offset(offset_of_field!( + p4_6_data_members_HasTwoInts, + first + ) as isize); + let mut second_pm: DataMemberPointer = DataMemberPointer::from_offset(offset_of_field!( + p4_6_data_members_HasTwoInts, + second + ) as isize); assert!((first_pm == also_first_pm)); assert!(!(first_pm != also_first_pm)); assert!((first_pm != second_pm)); diff --git a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper-p6-null-pointer-to-data-member.rs b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper-p6-null-pointer-to-data-member.rs index 0a5c201024..feecf3d38e 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper-p6-null-pointer-to-data-member.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper-p6-null-pointer-to-data-member.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -32,7 +31,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let mut pm: isize = -1_isize; + let mut pm: DataMemberPointer = DataMemberPointer::null(); let obj: Value = Rc::new(RefCell::new(HasTwoInts { first: 3, second: 4, diff --git a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs index 2856256e52..49ac296e45 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -28,7 +27,8 @@ pub struct p3_arrow_star_HasTwoInts { pub second: i32, } pub fn test_0() { - let mut pm: isize = (offset_of_field!(p3_arrow_star_HasTwoInts, second) as isize); + let mut pm: DataMemberPointer = + DataMemberPointer::from_offset(offset_of_field!(p3_arrow_star_HasTwoInts, second) as isize); let obj: Value = Rc::new(RefCell::new(p3_arrow_star_HasTwoInts { first: 3, second: 4, @@ -50,7 +50,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -79,11 +78,14 @@ pub fn select_object_5() -> Ptr { }); return object_4.with(|v| v.as_pointer()); } -pub fn select_member_6() -> isize { +pub fn select_member_6() -> DataMemberPointer { member_stamp_3.with(|rc| { *rc.borrow_mut() = { (*(*sequence_1.with(Value::clone).borrow_mut()).prefix_inc()) } }); - return (offset_of_field!(p4_object_expression_sequenced_first_HasValue, value) as isize); + return DataMemberPointer::from_offset(offset_of_field!( + p4_object_expression_sequenced_first_HasValue, + value + ) as isize); } pub fn test_7() { assert!( @@ -105,7 +107,6 @@ pub fn test_7() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -117,8 +118,10 @@ pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { pub second: i32, } pub fn test_8() { - let mut pm: isize = - (offset_of_field!(p6_data_member_of_lvalue_is_lvalue_HasTwoInts, second) as isize); + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(offset_of_field!( + p6_data_member_of_lvalue_is_lvalue_HasTwoInts, + second + ) as isize); let obj: Value = Rc::new(RefCell::new( p6_data_member_of_lvalue_is_lvalue_HasTwoInts { first: 3, @@ -144,7 +147,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, Destructible, - Default, Conversions, )] #[conversions(copy, move)] @@ -176,7 +178,6 @@ impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { TriviallyDefaultConstructible, Destructible, Memberwise, - Default, )] #[memberwise(copy_constructor, move_constructor)] #[derive(Conversions)] @@ -189,8 +190,10 @@ pub struct p6_data_member_of_rvalue_is_xvalue_HoldsCounted { } impl p6_data_member_of_rvalue_is_xvalue_HoldsCounted {} pub fn test_11() { - let mut pm: isize = - (offset_of_field!(p6_data_member_of_rvalue_is_xvalue_HoldsCounted, member) as isize); + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(offset_of_field!( + p6_data_member_of_rvalue_is_xvalue_HoldsCounted, + member + ) as isize); let holder: Value = Rc::new(RefCell::new( ::default(), )); diff --git a/tests/std/expr/expr.compound/out/unsafe/expr.cond.rs b/tests/std/expr/expr.compound/out/unsafe/expr.cond.rs index eb160580db..cdf55f1735 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.cond.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.cond.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -23,11 +22,14 @@ pub struct p7_4_pointer_to_member_and_null_HasTwoInts { pub first: i32, pub second: i32, } -pub unsafe fn second_or_null_0(mut choose_second: bool) -> isize { +pub unsafe fn second_or_null_0(mut choose_second: bool) -> DataMemberPointer { return if choose_second { - (::std::mem::offset_of!(p7_4_pointer_to_member_and_null_HasTwoInts, second) as isize) + DataMemberPointer::from_offset(::std::mem::offset_of!( + p7_4_pointer_to_member_and_null_HasTwoInts, + second + ) as isize) } else { - -1_isize + DataMemberPointer::null() }; } pub unsafe fn test_1() { @@ -36,15 +38,17 @@ pub unsafe fn test_1() { first: 3, second: 4, }; - assert!(((unsafe { second_or_null_0(false,) }) == -1_isize)); + assert!((unsafe { second_or_null_0(false,) }).is_null()); assert!( ((unsafe { second_or_null_0(true,) }) - == (::std::mem::offset_of!(p7_4_pointer_to_member_and_null_HasTwoInts, second) - as isize)) + == (DataMemberPointer::from_offset(::std::mem::offset_of!( + p7_4_pointer_to_member_and_null_HasTwoInts, + second + ) as isize))) ); assert!( ((*(&mut obj as *mut p7_4_pointer_to_member_and_null_HasTwoInts) - .wrapping_byte_offset((unsafe { second_or_null_0(true,) })) + .wrapping_byte_offset((unsafe { second_or_null_0(true,) }).offset()) .cast::()) == (4)) ); diff --git a/tests/std/expr/expr.compound/out/unsafe/expr.eq.rs b/tests/std/expr/expr.compound/out/unsafe/expr.eq.rs index 4d1a9f2eab..017ae97c03 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.eq.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.eq.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -24,8 +23,8 @@ pub struct p4_1_both_null_HasTwoInts { pub second: i32, } pub unsafe fn test_0() { - let mut first_null: isize = -1_isize; - let mut second_null: isize = -1_isize; + let mut first_null: DataMemberPointer = DataMemberPointer::null(); + let mut second_null: DataMemberPointer = DataMemberPointer::null(); assert!(((first_null) == (second_null))); assert!(!((first_null) != (second_null))); } @@ -38,7 +37,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -47,8 +45,11 @@ pub struct p4_2_one_null_HasTwoInts { pub second: i32, } pub unsafe fn test_1() { - let mut null_pm: isize = -1_isize; - let mut first_pm: isize = (::std::mem::offset_of!(p4_2_one_null_HasTwoInts, first) as isize); + let mut null_pm: DataMemberPointer = DataMemberPointer::null(); + let mut first_pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( + p4_2_one_null_HasTwoInts, + first + ) as isize); assert!(((first_pm) != (null_pm))); assert!(!((first_pm) == (null_pm))); assert!(((null_pm) != (first_pm))); @@ -68,14 +69,9 @@ pub union p4_5_members_of_same_union_HasTwoIntMembers { pub first: i32, pub second: i32, } -impl Default for p4_5_members_of_same_union_HasTwoIntMembers { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} pub unsafe fn test_2() { - let mut first_pm: isize = 0_isize; - let mut second_pm: isize = 0_isize; + let mut first_pm: DataMemberPointer = DataMemberPointer::from_offset(0); + let mut second_pm: DataMemberPointer = DataMemberPointer::from_offset(0); assert!(((first_pm) == (second_pm))); assert!(!((first_pm) != (second_pm))); } @@ -88,7 +84,6 @@ pub unsafe fn test_2() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -97,12 +92,17 @@ pub struct p4_6_data_members_HasTwoInts { pub second: i32, } pub unsafe fn test_3() { - let mut first_pm: isize = - (::std::mem::offset_of!(p4_6_data_members_HasTwoInts, first) as isize); - let mut also_first_pm: isize = - (::std::mem::offset_of!(p4_6_data_members_HasTwoInts, first) as isize); - let mut second_pm: isize = - (::std::mem::offset_of!(p4_6_data_members_HasTwoInts, second) as isize); + let mut first_pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( + p4_6_data_members_HasTwoInts, + first + ) as isize); + let mut also_first_pm: DataMemberPointer = DataMemberPointer::from_offset( + ::std::mem::offset_of!(p4_6_data_members_HasTwoInts, first) as isize, + ); + let mut second_pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( + p4_6_data_members_HasTwoInts, + second + ) as isize); assert!(((first_pm) == (also_first_pm))); assert!(!((first_pm) != (also_first_pm))); assert!(((first_pm) != (second_pm))); diff --git a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper-p6-null-pointer-to-data-member.rs b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper-p6-null-pointer-to-data-member.rs index 0d1cf85134..5a1e2282c9 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper-p6-null-pointer-to-data-member.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper-p6-null-pointer-to-data-member.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -30,13 +29,13 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut pm: isize = -1_isize; + let mut pm: DataMemberPointer = DataMemberPointer::null(); let mut obj: HasTwoInts = HasTwoInts { first: 3, second: 4, }; return (*(&mut obj as *mut HasTwoInts) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::()); } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs index a39ed60c79..9839cf4287 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -24,20 +23,23 @@ pub struct p3_arrow_star_HasTwoInts { pub second: i32, } pub unsafe fn test_0() { - let mut pm: isize = (::std::mem::offset_of!(p3_arrow_star_HasTwoInts, second) as isize); + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( + p3_arrow_star_HasTwoInts, + second + ) as isize); let mut obj: p3_arrow_star_HasTwoInts = p3_arrow_star_HasTwoInts { first: 3, second: 4, }; let mut p: *mut p3_arrow_star_HasTwoInts = (&mut obj as *mut p3_arrow_star_HasTwoInts); - assert!(((*(p).wrapping_byte_offset(pm).cast::()) == (4))); - (*(p).wrapping_byte_offset(pm).cast::()) = 5; + assert!(((*(p).wrapping_byte_offset((pm).offset()).cast::()) == (4))); + (*(p).wrapping_byte_offset((pm).offset()).cast::()) = 5; assert!(((obj.second) == (5))); assert!(((obj.first) == (3))); assert!( - ((&mut (*(p).wrapping_byte_offset(pm).cast::()) as *mut i32) + ((&mut (*(p).wrapping_byte_offset((pm).offset()).cast::()) as *mut i32) == (&mut (*(&mut (*p) as *mut p3_arrow_star_HasTwoInts) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::()) as *mut i32)) ); } @@ -50,7 +52,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -71,15 +72,18 @@ pub unsafe fn select_object_5() -> *mut p4_object_expression_sequenced_first_Has (*(*std::cell::LazyCell::force_mut(&mut *&raw mut sequence_1)).prefix_inc()); return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut object_4)); } -pub unsafe fn select_member_6() -> isize { +pub unsafe fn select_member_6() -> DataMemberPointer { (*std::cell::LazyCell::force_mut(&mut *&raw mut member_stamp_3)) = (*(*std::cell::LazyCell::force_mut(&mut *&raw mut sequence_1)).prefix_inc()); - return (::std::mem::offset_of!(p4_object_expression_sequenced_first_HasValue, value) as isize); + return DataMemberPointer::from_offset(::std::mem::offset_of!( + p4_object_expression_sequenced_first_HasValue, + value + ) as isize); } pub unsafe fn test_7() { assert!( ((*(unsafe { select_object_5() }) - .wrapping_byte_offset((unsafe { select_member_6() })) + .wrapping_byte_offset((unsafe { select_member_6() }).offset()) .cast::()) == (7)) ); @@ -95,7 +99,6 @@ pub unsafe fn test_7() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -104,8 +107,10 @@ pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { pub second: i32, } pub unsafe fn test_8() { - let mut pm: isize = - (::std::mem::offset_of!(p6_data_member_of_lvalue_is_lvalue_HasTwoInts, second) as isize); + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( + p6_data_member_of_lvalue_is_lvalue_HasTwoInts, + second + ) as isize); let mut obj: p6_data_member_of_lvalue_is_lvalue_HasTwoInts = p6_data_member_of_lvalue_is_lvalue_HasTwoInts { first: 3, @@ -113,12 +118,12 @@ pub unsafe fn test_8() { }; assert!( ((&mut (*(&mut obj as *mut p6_data_member_of_lvalue_is_lvalue_HasTwoInts) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::()) as *mut i32) == (&mut obj.second as *mut i32)) ); let ref_: *mut i32 = &mut (*(&mut obj as *mut p6_data_member_of_lvalue_is_lvalue_HasTwoInts) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::()); (*ref_) = 5; assert!(((obj.second) == (5))); @@ -132,7 +137,6 @@ pub static mut moveCount_10: std::cell::LazyCell = std::cell::LazyCell::new ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -162,7 +166,6 @@ impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, MemberwiseUnsafe, - Default, )] #[memberwise(copy_constructor, move_constructor)] #[derive(ConversionsUnsafe)] @@ -172,8 +175,10 @@ pub struct p6_data_member_of_rvalue_is_xvalue_HoldsCounted { } impl p6_data_member_of_rvalue_is_xvalue_HoldsCounted {} pub unsafe fn test_11() { - let mut pm: isize = - (::std::mem::offset_of!(p6_data_member_of_rvalue_is_xvalue_HoldsCounted, member) as isize); + let mut pm: DataMemberPointer = DataMemberPointer::from_offset(::std::mem::offset_of!( + p6_data_member_of_rvalue_is_xvalue_HoldsCounted, + member + ) as isize); let mut holder: p6_data_member_of_rvalue_is_xvalue_HoldsCounted = ::default(); object_unsafe!( @@ -181,7 +186,7 @@ pub unsafe fn test_11() { p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_2( LvalueRefUnsafe::bind( &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::()) ) ) @@ -193,7 +198,7 @@ pub unsafe fn test_11() { p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_3( RvalueRefUnsafe::bind( &mut (*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) - .wrapping_byte_offset(pm) + .wrapping_byte_offset((pm).offset()) .cast::()) ) ) diff --git a/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs b/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs index aa155229ac..d386f9b67f 100644 --- a/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs +++ b/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs @@ -35,11 +35,6 @@ impl p1_default_member_initializer_names_object_Holder { assert!(({ this.with(|__s| __s.self_.clone()).with(|__s| __s.value) } == { value })); } } -impl Default for p1_default_member_initializer_names_object_Holder { - fn default() -> Self { - { ::zero_init() } - } -} pub fn test_0() { object!( holder, @@ -56,7 +51,6 @@ pub fn test_0() { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -96,7 +90,6 @@ pub fn test_1() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs b/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs index 23e5e94649..ea1e769108 100644 --- a/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs +++ b/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs @@ -31,11 +31,6 @@ impl p1_default_member_initializer_names_object_Holder { assert!((((*(*this).self_).value) == (value))); } } -impl Default for p1_default_member_initializer_names_object_Holder { - fn default() -> Self { - unsafe { ::zero_init() } - } -} pub unsafe fn test_0() { object_unsafe!( holder, @@ -52,7 +47,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -86,7 +80,6 @@ pub unsafe fn test_1() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs index 76311ce8ab..f7d9c44ae8 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -42,7 +41,7 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { } impl p16_rebind_member_Alloc_std_pair_const_int__int__ { pub fn constructor_1(this: Ptr) { - field!(this, id).write(0); + this.write(::default()); } } impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { @@ -83,7 +82,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs index 82820a63f9..8f7a7efc5a 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -37,7 +36,7 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { } impl p16_rebind_member_Alloc_std_pair_const_int__int__ { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).id).write(0); + this.write(::default()); } } impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { @@ -78,7 +77,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs b/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs index b59ba33b07..a8152aabb4 100644 --- a/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs +++ b/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs @@ -19,7 +19,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -180,7 +179,6 @@ pub fn test_1() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -209,7 +207,6 @@ impl LessThanComparable for table29_other_operator_shapes_Weight { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -236,7 +233,6 @@ impl LessThanComparable for table29_other_operator_shapes_Height { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(table29_other_operator_shapes_Depth::operator_cmp)] @@ -341,7 +337,6 @@ pub fn test_2() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs b/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs index e20798e882..bf33731e76 100644 --- a/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs +++ b/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs @@ -16,7 +16,6 @@ pub static mut less_calls_0: std::cell::LazyCell = std::cell::LazyCell::new ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -138,7 +137,6 @@ pub unsafe fn test_1() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -167,7 +165,6 @@ impl LessThanComparableUnsafe for table29_other_operator_shapes_Weight { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -191,7 +188,6 @@ impl LessThanComparableUnsafe for table29_other_operator_shapes_Height { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(table29_other_operator_shapes_Depth::operator_cmp)] @@ -283,7 +279,6 @@ pub unsafe fn test_2() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/support/cmp/out/refcount/cmp.concept.rs b/tests/std/support/cmp/out/refcount/cmp.concept.rs index c974b14ce7..2684f92516 100644 --- a/tests/std/support/cmp/out/refcount/cmp.concept.rs +++ b/tests/std/support/cmp/out/refcount/cmp.concept.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -112,7 +111,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -176,7 +174,6 @@ pub fn test_2() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -239,7 +236,6 @@ pub fn test_3() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(p1_three_way_without_equality_Rank::operator_cmp)] diff --git a/tests/std/support/cmp/out/unsafe/cmp.concept.rs b/tests/std/support/cmp/out/unsafe/cmp.concept.rs index 126c5aa0a9..63022eecaf 100644 --- a/tests/std/support/cmp/out/unsafe/cmp.concept.rs +++ b/tests/std/support/cmp/out/unsafe/cmp.concept.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -101,7 +100,6 @@ pub static mut three_way_calls_1: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -168,7 +166,6 @@ pub unsafe fn test_2() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -223,7 +220,6 @@ pub unsafe fn test_3() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(p1_three_way_without_equality_Rank::operator_cmp)] diff --git a/tests/std/temp/out/refcount/temp.type.rs b/tests/std/temp/out/refcount/temp.type.rs index 4664d4c625..bb9314d582 100644 --- a/tests/std/temp/out/refcount/temp.type.rs +++ b/tests/std/temp/out/refcount/temp.type.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -40,7 +39,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -60,7 +58,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -80,7 +77,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/temp/out/unsafe/temp.type.rs b/tests/std/temp/out/unsafe/temp.type.rs index 38d9fb7e60..f0f1e7164c 100644 --- a/tests/std/temp/out/unsafe/temp.type.rs +++ b/tests/std/temp/out/unsafe/temp.type.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -33,7 +32,6 @@ pub static mut count_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -49,7 +47,6 @@ pub static mut count_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -65,7 +62,6 @@ pub static mut count_2: std::cell::LazyCell = std::cell::LazyCell::new(|| u ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs index a5ab8c271b..3303a0e133 100644 --- a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs @@ -27,7 +27,7 @@ pub struct p2_reference_does_not_instantiate_Member { } impl p2_reference_does_not_instantiate_Member { pub fn constructor_1(this: Ptr) { - field!(this, value).write(1); + this.write(::default()); } pub fn constructor_2( this: Ptr, @@ -42,7 +42,7 @@ impl Default for p2_reference_does_not_instantiate_Member { { p2_reference_does_not_instantiate_Member { value: 1 } } } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise)] #[memberwise(move_constructor)] #[derive(Conversions)] #[conversions(move)] @@ -55,17 +55,24 @@ pub struct p2_reference_does_not_instantiate_Holder { } impl p2_reference_does_not_instantiate_Holder { pub fn constructor_1(this: Ptr) { - p2_reference_does_not_instantiate_Member::constructor_1(field_ptr!(this, member)); + this.write(::default()); + } +} +impl Default for p2_reference_does_not_instantiate_Holder { + fn default() -> Self { + { + p2_reference_does_not_instantiate_Holder { + member: ::default(), + } + } } } pub fn test_0() { - object!( - holder, - p2_reference_does_not_instantiate_Holder::constructor_1() - ); - assert!(({ (*holder.borrow()).member.value } == 1)); - (*holder.borrow_mut()).member.value = 3; - assert!(({ (*holder.borrow()).member.value } == 3)); + let mut holder: p2_reference_does_not_instantiate_Holder = + ::default(); + assert!((holder.member.value == 1)); + holder.member.value = 3; + assert!((holder.member.value == 3)); } pub fn main() { __cpp2rust_init_globals(); diff --git a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs index 2c251655b9..476d662ac8 100644 --- a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs @@ -24,7 +24,7 @@ pub struct p2_reference_does_not_instantiate_Member { } impl p2_reference_does_not_instantiate_Member { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).value).write(1); + this.write(::default()); } pub unsafe fn constructor_2( this: *mut Self, @@ -40,7 +40,7 @@ impl Default for p2_reference_does_not_instantiate_Member { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe)] #[memberwise(move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(move)] @@ -50,14 +50,21 @@ pub struct p2_reference_does_not_instantiate_Holder { } impl p2_reference_does_not_instantiate_Holder { pub unsafe fn constructor_1(this: *mut Self) { - p2_reference_does_not_instantiate_Member::constructor_1(&raw mut (*this).member); + this.write(::default()); + } +} +impl Default for p2_reference_does_not_instantiate_Holder { + fn default() -> Self { + unsafe { + p2_reference_does_not_instantiate_Holder { + member: ::default(), + } + } } } pub unsafe fn test_0() { - object_unsafe!( - holder, - p2_reference_does_not_instantiate_Holder::constructor_1() - ); + let mut holder: p2_reference_does_not_instantiate_Holder = + ::default(); assert!(((holder.member.value) == (1))); holder.member.value = 3; assert!(((holder.member.value) == (3))); diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 956068cc7e..f2c5bcdff9 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -14,9 +14,7 @@ pub fn test_0() { lvalue.write(2); assert!(({ ((*value.borrow()) == 2) })); } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] @@ -56,20 +54,6 @@ impl p6_forward_like_Holder { p6_forward_like_Movable::constructor_1(field_ptr!(this, member), 1); } } -impl Default for p6_forward_like_Holder { - fn default() -> Self { - { - p6_forward_like_Holder { - member: { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p6_forward_like_Movable::constructor_1(__v.as_pointer(), 1); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }, - } - } - } -} pub fn take_1(__return: Ptr, self_: Ptr) { p6_forward_like_Movable::constructor_2( __return.clone(), @@ -95,9 +79,7 @@ pub fn test_3() { })); assert!(({ (*moved.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 0)); } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, RvalueRef)] @@ -186,11 +168,6 @@ impl p10_forward_in_template_A { field!(other, value).write(0); } } -impl Default for p10_forward_in_template_A { - fn default() -> Self { - { ::zero_init() } - } -} pub fn make_5(__return: Ptr, source: Ptr) { p10_forward_in_template_A::constructor_2(__return.clone(), LvalueRef::bind((source).clone())); return; @@ -218,9 +195,7 @@ pub fn test_7() { ); assert!(({ (*a.borrow()).value } == 0)); } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] @@ -247,9 +222,7 @@ impl p11_move_if_noexcept_NoexceptMove { field!(other, value).write(0); } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index b72d0f16fb..1d78a46303 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -22,7 +22,6 @@ pub fn test_0() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -59,9 +58,7 @@ pub fn test_1() { ); assert!(({ (*element.borrow()).x } == 5) && ({ (*element.borrow()).y } == 6)); } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, RvalueRef)] diff --git a/tests/std/utilities/utility/out/refcount/utility.as.const.rs b/tests/std/utilities/utility/out/refcount/utility.as.const.rs index 8a788a26cf..db6ce05fc9 100644 --- a/tests/std/utilities/utility/out/refcount/utility.as.const.rs +++ b/tests/std/utilities/utility/out/refcount/utility.as.const.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index 2a8a93039b..7c9a50edfb 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -15,9 +15,7 @@ pub unsafe fn test_0() { assert!(((value) == (2))); } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] @@ -56,19 +54,6 @@ impl p6_forward_like_Holder { p6_forward_like_Movable::constructor_1(&raw mut (*this).member, 1); } } -impl Default for p6_forward_like_Holder { - fn default() -> Self { - unsafe { - p6_forward_like_Holder { - member: { - let mut __v: p6_forward_like_Movable = ZeroInitializationUnsafe::zero_init(); - p6_forward_like_Movable::constructor_1(&raw mut __v, 1); - __v - }, - } - } - } -} pub unsafe fn take_1(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { p6_forward_like_Movable::constructor_2(__return, LvalueRefUnsafe::bind(&(*self_).member)); return; @@ -89,9 +74,7 @@ pub unsafe fn test_3() { assert!(((moved.value) == (1)) && ((holder.member.value) == (0))); } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, RvalueRefUnsafe)] @@ -178,11 +161,6 @@ impl p10_forward_in_template_A { (*other).value = 0; } } -impl Default for p10_forward_in_template_A { - fn default() -> Self { - unsafe { ::zero_init() } - } -} pub unsafe fn make_5( __return: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A, @@ -211,9 +189,7 @@ pub unsafe fn test_7() { assert!(((a.value) == (0))); } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] @@ -242,9 +218,7 @@ impl p11_move_if_noexcept_NoexceptMove { } } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index caa94a1e5e..2828cebf6f 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -21,7 +21,6 @@ pub unsafe fn test_0() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -50,9 +49,7 @@ pub unsafe fn test_1() { assert!(((element.x) == (5)) && ((element.y) == (6))); } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, RvalueRefUnsafe)] diff --git a/tests/std/utilities/utility/out/unsafe/utility.as.const.rs b/tests/std/utilities/utility/out/unsafe/utility.as.const.rs index d70473ad09..b838244f86 100644 --- a/tests/std/utilities/utility/out/unsafe/utility.as.const.rs +++ b/tests/std/utilities/utility/out/unsafe/utility.as.const.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/ub/out/refcount/ctor_ref_member.rs b/tests/ub/out/refcount/ctor_ref_member.rs index 576aa62fed..a6aa3f1b1a 100644 --- a/tests/ub/out/refcount/ctor_ref_member.rs +++ b/tests/ub/out/refcount/ctor_ref_member.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/ub/out/refcount/self_referencing_initializer.rs b/tests/ub/out/refcount/self_referencing_initializer.rs index c41ddd2eae..4820a231ab 100644 --- a/tests/ub/out/refcount/self_referencing_initializer.rs +++ b/tests/ub/out/refcount/self_referencing_initializer.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/ub/out/refcount/ub6.rs b/tests/ub/out/refcount/ub6.rs index 502c6d37e5..d62fcfc833 100644 --- a/tests/ub/out/refcount/ub6.rs +++ b/tests/ub/out/refcount/ub6.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/ub/out/unsafe/ctor_ref_member.rs b/tests/ub/out/unsafe/ctor_ref_member.rs index f63545f21a..ff5159542e 100644 --- a/tests/ub/out/unsafe/ctor_ref_member.rs +++ b/tests/ub/out/unsafe/ctor_ref_member.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/ub/out/unsafe/self_referencing_initializer.rs b/tests/ub/out/unsafe/self_referencing_initializer.rs index 54d99126f4..c3e6a08ba0 100644 --- a/tests/ub/out/unsafe/self_referencing_initializer.rs +++ b/tests/ub/out/unsafe/self_referencing_initializer.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/ub/out/unsafe/ub6.rs b/tests/ub/out/unsafe/ub6.rs index 8578975d3d..397e9cc9a0 100644 --- a/tests/ub/out/unsafe/ub6.rs +++ b/tests/ub/out/unsafe/ub6.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/05_new.rs b/tests/unit/out/refcount/05_new.rs index 9719605c62..0105521efb 100644 --- a/tests/unit/out/refcount/05_new.rs +++ b/tests/unit/out/refcount/05_new.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct A {} FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index 2aab41cbe5..184ffb30a2 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -36,7 +35,6 @@ pub struct GraphNode { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -74,7 +72,7 @@ pub struct Partial { } impl Partial { pub fn constructor_1(this: Ptr) { - field!(this, p).write(Ptr::::null()); + this.write(::default()); } pub fn constructor_2(this: Ptr, q: Pointer) { let mut q = q.as_pointer(); @@ -100,7 +98,6 @@ impl Default for Partial { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -116,7 +113,6 @@ impl Declared {} FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -142,8 +138,8 @@ fn main_0() -> i32 { if ({ { (*it.borrow()).p.clone() } } != { arr.decay() }) { return 1; } - object!(def, Partial::constructor_1()); - if !(({ (*def.borrow()).p.clone() }).is_null()) { + let mut def: Partial = ::default(); + if !((def.p).is_null()) { return 1; } let mut s: S = S { diff --git a/tests/unit/out/refcount/addr_of_global.rs b/tests/unit/out/refcount/addr_of_global.rs index 7c3f0b1230..7c2e181937 100644 --- a/tests/unit/out/refcount/addr_of_global.rs +++ b/tests/unit/out/refcount/addr_of_global.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -34,7 +33,6 @@ pub struct Inner { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/anonymous-struct.rs b/tests/unit/out/refcount/anonymous-struct.rs index e3de675ff5..4662b44c8c 100644 --- a/tests/unit/out/refcount/anonymous-struct.rs +++ b/tests/unit/out/refcount/anonymous-struct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ pub struct Outer_Named { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -58,7 +56,6 @@ pub struct anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -79,7 +76,6 @@ pub struct anon_1 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -100,7 +96,6 @@ pub struct anon_2 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -119,7 +114,6 @@ pub struct anon_4 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -138,7 +132,6 @@ pub struct anon_5 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -163,7 +156,6 @@ pub struct anon_3 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -240,7 +232,6 @@ fn main_0() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/anonymous-struct_c.rs b/tests/unit/out/refcount/anonymous-struct_c.rs index 1edb3cd3f0..205dc692a2 100644 --- a/tests/unit/out/refcount/anonymous-struct_c.rs +++ b/tests/unit/out/refcount/anonymous-struct_c.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct Named { @@ -35,7 +34,6 @@ pub struct Named { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct anon_0 { @@ -54,7 +52,6 @@ pub struct anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct anon_1 { @@ -73,7 +70,6 @@ pub struct anon_1 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct anon_2 { @@ -92,7 +88,6 @@ pub struct anon_2 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(4)] pub struct anon_4 { @@ -109,7 +104,6 @@ pub struct anon_4 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(4)] pub struct anon_5 { @@ -126,7 +120,6 @@ pub struct anon_5 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(12)] pub struct anon_3 { @@ -149,7 +142,6 @@ pub struct anon_3 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(44)] pub struct Outer { @@ -230,7 +222,6 @@ fn main_0() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct anon_6 { diff --git a/tests/unit/out/refcount/anonymous_enum.rs b/tests/unit/out/refcount/anonymous_enum.rs index 722900ac17..7a5036af33 100644 --- a/tests/unit/out/refcount/anonymous_enum.rs +++ b/tests/unit/out/refcount/anonymous_enum.rs @@ -22,7 +22,6 @@ pub const anon_1_SECOND_B: anon_1 = 1; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -47,7 +46,6 @@ pub const anon_2_FIELD_B: anon_2 = 1; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/anonymous_enum_c.rs b/tests/unit/out/refcount/anonymous_enum_c.rs index c348d852a2..312473f380 100644 --- a/tests/unit/out/refcount/anonymous_enum_c.rs +++ b/tests/unit/out/refcount/anonymous_enum_c.rs @@ -22,7 +22,6 @@ pub const anon_1_SECOND_B: anon_1 = 1; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(4)] pub struct S { @@ -45,7 +44,6 @@ pub const anon_2_FIELD_B: anon_2 = 1; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct WithAnonField { diff --git a/tests/unit/out/refcount/any.rs b/tests/unit/out/refcount/any.rs index 84ba9fcf17..39f458fdce 100644 --- a/tests/unit/out/refcount/any.rs +++ b/tests/unit/out/refcount/any.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/array_const_init.rs b/tests/unit/out/refcount/array_const_init.rs index 4e1c28e929..1b2d88afc6 100644 --- a/tests/unit/out/refcount/array_const_init.rs +++ b/tests/unit/out/refcount/array_const_init.rs @@ -29,17 +29,6 @@ pub struct S { #[array_len(4)] pub buf: Box<[i8]>, } -impl Default for S { - fn default() -> Self { - { - S { - head: 0_i32, - tail: (0..3).map(|_| 0_i32).collect::>(), - buf: (0..4).map(|_| 0_i8).collect::>(), - } - } - } -} thread_local!( pub static s_0: Value = Rc::new(RefCell::new(S { head: 5, @@ -57,7 +46,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct P { diff --git a/tests/unit/out/refcount/array_field_addr.rs b/tests/unit/out/refcount/array_field_addr.rs index 0beecd6e81..b39e396e06 100644 --- a/tests/unit/out/refcount/array_field_addr.rs +++ b/tests/unit/out/refcount/array_field_addr.rs @@ -27,17 +27,6 @@ pub struct S { #[offset(8)] pub after: i32, } -impl Default for S { - fn default() -> Self { - { - S { - before: 0_i32, - mask: (0..4).map(|_| 0_u8).collect::>(), - after: 0_i32, - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index 4eae87808a..5edbf45cc2 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -32,15 +32,14 @@ pub struct NonCopy { } impl NonCopy { pub fn constructor_1(this: Ptr) { - field!(this, data).write(Vec::new()); - field!(this, tag).write(0); + this.write(::default()); } } impl Default for NonCopy { fn default() -> Self { { NonCopy { - data: Default::default(), + data: Vec::new(), tag: 0, } } @@ -51,13 +50,11 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let arr: Value> = Rc::new(RefCell::new(Box::new( - std::array::from_fn::<_, 3, _>(|_| { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - NonCopy::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }), - ))); + let arr: Value> = Rc::new(RefCell::new( + (0..3) + .map(|_| ::default()) + .collect::>(), + )); (*arr.borrow_mut())[(0) as usize].tag = 7; ({ let __tmp_0: Value = Rc::new(RefCell::new(42)); diff --git a/tests/unit/out/refcount/array_reference.rs b/tests/unit/out/refcount/array_reference.rs index cf494f4667..b664bf4f14 100644 --- a/tests/unit/out/refcount/array_reference.rs +++ b/tests/unit/out/refcount/array_reference.rs @@ -69,7 +69,6 @@ pub fn pick_10(s: Ptr) -> Ptr { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/as_const.rs b/tests/unit/out/refcount/as_const.rs index d777f68105..b23dc27a0b 100644 --- a/tests/unit/out/refcount/as_const.rs +++ b/tests/unit/out/refcount/as_const.rs @@ -19,7 +19,6 @@ pub const Overload_kConstOverload: Overload = 2; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/assign_rhs_first.rs b/tests/unit/out/refcount/assign_rhs_first.rs index f96301dad8..3338db6ea3 100644 --- a/tests/unit/out/refcount/assign_rhs_first.rs +++ b/tests/unit/out/refcount/assign_rhs_first.rs @@ -24,7 +24,6 @@ pub fn advance_1() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index bbd2ca8fbe..c1c818ecd7 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -819,7 +819,6 @@ pub fn test_reference_members_9() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -838,7 +837,6 @@ pub struct Slot_6 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -857,7 +855,6 @@ pub struct Slot_8 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -934,7 +931,6 @@ pub fn test_pointer_elements_11() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -980,7 +976,6 @@ pub fn test_reference_pointer_13() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -1090,7 +1085,6 @@ pub fn test_reference_subfields_18() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -1108,7 +1102,6 @@ pub struct Index_16 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -1128,7 +1121,6 @@ pub struct Slot_17 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -1146,7 +1138,6 @@ pub struct Index_19 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -1201,7 +1192,6 @@ pub fn observe_24(mut assigned: i32, mut stored: Ptr) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -1220,7 +1210,6 @@ pub struct GlobalRecord_Inner { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -1478,7 +1467,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -1496,7 +1484,6 @@ pub struct Record_32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -1520,7 +1507,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -1778,7 +1764,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -2151,7 +2136,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -2394,7 +2378,6 @@ pub fn test_stable_containers_58() { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -2408,7 +2391,12 @@ pub struct Counts_59 { } impl Counts_59 { pub fn constructor_1(this: Ptr) { - field!(this, counts).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Counts_59 { + fn default() -> Self { + { Counts_59 { counts: Vec::new() } } } } #[derive( @@ -2421,7 +2409,6 @@ impl Counts_59 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -2745,7 +2732,6 @@ fn main_0() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -2775,16 +2761,6 @@ pub struct Owner_63 { #[offset(8)] pub index: i32, } -impl Default for Owner_63 { - fn default() -> Self { - { - Owner_63 { - values: (0..2).map(|_| 0_i32).collect::>(), - index: 0_i32, - } - } - } -} pub fn __cpp2rust_init_globals() { let _ = global_22.with(|_| ()); let _ = global_record_25.with(|_| ()); diff --git a/tests/unit/out/refcount/bounded_struct_ptr.rs b/tests/unit/out/refcount/bounded_struct_ptr.rs index 5ddee4f361..ea2dc97338 100644 --- a/tests/unit/out/refcount/bounded_struct_ptr.rs +++ b/tests/unit/out/refcount/bounded_struct_ptr.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/bst.rs b/tests/unit/out/refcount/bst.rs index 318586c3f3..2c863ff4ee 100644 --- a/tests/unit/out/refcount/bst.rs +++ b/tests/unit/out/refcount/bst.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/c_struct.rs b/tests/unit/out/refcount/c_struct.rs index e1370c5c1b..e97f918020 100644 --- a/tests/unit/out/refcount/c_struct.rs +++ b/tests/unit/out/refcount/c_struct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct Point { @@ -35,7 +34,6 @@ pub struct Point { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct Line { @@ -55,7 +53,6 @@ pub struct Line { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct Node { @@ -79,7 +76,6 @@ pub const Color_BLUE: Color = 2; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct Inner { @@ -98,7 +94,6 @@ pub struct Inner { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct Container { diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index 831c3621ea..84383a3fbb 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -20,7 +20,6 @@ pub const E_C: E = 2; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -41,7 +40,6 @@ pub struct Pair { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -76,19 +74,6 @@ pub struct Grid { #[array_len(2, 3)] pub cells: Box<[Box<[i32]>]>, } -impl Default for Grid { - fn default() -> Self { - { - Grid { - h: 0_i32, - row: (0..3).map(|_| 0_i32).collect::>(), - cells: (0..2) - .map(|_| (0..3).map(|_| 0_i32).collect::>()) - .collect::]>>(), - } - } - } -} #[derive( Clone, Record, @@ -100,7 +85,6 @@ impl Default for Grid { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -116,8 +100,17 @@ pub struct Bag { } impl Bag { pub fn constructor_1(this: Ptr) { - field!(this, n).write(0_i32); - field!(this, items).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Bag { + fn default() -> Self { + { + Bag { + n: 0_i32, + items: Vec::new(), + } + } } } pub fn adjacent_arrays_0() { @@ -389,7 +382,7 @@ pub fn nested_5() { assert!(({ ((*m.borrow())[(1) as usize][(1) as usize] == 42) })); assert!(({ (pm).clone() } == { (m.decay().offset(1).decay().offset(1)) })); assert!(({ (pm).clone() } < { (m.decay().offset(2).decay().offset(0)) })); - object!(b, Bag::constructor_1()); + let b: Value = Rc::new(RefCell::new(::default())); if 4_usize > (*b.borrow()).items.capacity() as usize { let len_0 = (*b.borrow()).items.len(); (*b.borrow_mut()) diff --git a/tests/unit/out/refcount/cast_array_to_pointer_decay.rs b/tests/unit/out/refcount/cast_array_to_pointer_decay.rs index 2be7893600..4272e0b922 100644 --- a/tests/unit/out/refcount/cast_array_to_pointer_decay.rs +++ b/tests/unit/out/refcount/cast_array_to_pointer_decay.rs @@ -35,15 +35,6 @@ pub struct Row { #[array_len(3)] pub a: Box<[i32]>, } -impl Default for Row { - fn default() -> Self { - { - Row { - a: (0..3).map(|_| 0_i32).collect::>(), - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/class.rs b/tests/unit/out/refcount/class.rs index 01d48a3621..ffecfaf4e1 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -60,7 +59,6 @@ impl Pair { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -89,7 +87,6 @@ impl Route { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -118,7 +115,6 @@ impl Counter { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/class_template_lazy_member.rs b/tests/unit/out/refcount/class_template_lazy_member.rs index 541685d7cb..1401a90068 100644 --- a/tests/unit/out/refcount/class_template_lazy_member.rs +++ b/tests/unit/out/refcount/class_template_lazy_member.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -35,7 +34,6 @@ pub struct Point { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -59,7 +57,6 @@ impl Box_int_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -84,7 +81,6 @@ impl Box_Point_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -108,7 +104,6 @@ impl Deduced_int_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index 69d4095d39..d94ff07b64 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -17,7 +17,6 @@ use std::rc::{Rc, Weak}; Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -50,7 +49,12 @@ impl MyContainer_int_ { CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); } pub fn constructor_1(this: Ptr) { - field!(this, vec_).write(Vec::new()); + this.write(::default()); + } +} +impl Default for MyContainer_int_ { + fn default() -> Self { + { MyContainer_int_ { vec_: Vec::new() } } } } #[derive( @@ -64,7 +68,6 @@ impl MyContainer_int_ { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -97,7 +100,12 @@ impl MyContainer_char_ { CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); } pub fn constructor_1(this: Ptr) { - field!(this, vec_).write(Vec::new()); + this.write(::default()); + } +} +impl Default for MyContainer_char_ { + fn default() -> Self { + { MyContainer_char_ { vec_: Vec::new() } } } } #[derive( @@ -111,7 +119,6 @@ impl MyContainer_char_ { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -144,7 +151,12 @@ impl MyContainer_float_ { CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); } pub fn constructor_1(this: Ptr) { - field!(this, vec_).write(Vec::new()); + this.write(::default()); + } +} +impl Default for MyContainer_float_ { + fn default() -> Self { + { MyContainer_float_ { vec_: Vec::new() } } } } #[derive( @@ -157,7 +169,6 @@ impl MyContainer_float_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -184,7 +195,6 @@ impl Boxed_short_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -211,7 +221,6 @@ impl Boxed_int_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -238,7 +247,6 @@ impl Boxed_long_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -264,7 +272,6 @@ impl Outer_int__Inner_int_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -291,7 +298,6 @@ impl Outer_int_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -317,7 +323,6 @@ impl Outer_long__Inner_int_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -343,7 +348,6 @@ impl Outer_long__Inner_char_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -370,7 +374,6 @@ impl Outer_long_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -418,7 +421,7 @@ fn main_0() -> i32 { assert!((({ Boxed_long_::twice(10_i64,) }) == 20_i64)); let bl: Value = Rc::new(RefCell::new(Boxed_long_ { value: 7_i64 })); assert!((({ Boxed_long_::plus(bl.as_pointer(), 1_i64,) }) == 8_i64)); - object!(imc, MyContainer_int_::constructor_1()); + let imc: Value = Rc::new(RefCell::new(::default())); assert!(({ MyContainer_int_::empty(imc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(1)); @@ -430,7 +433,7 @@ fn main_0() -> i32 { ); ({ MyContainer_int_::pop_back(imc.as_pointer()) }); assert!(({ MyContainer_int_::empty(imc.as_pointer(),) })); - object!(cmc, MyContainer_char_::constructor_1()); + let cmc: Value = Rc::new(RefCell::new(::default())); assert!(({ MyContainer_char_::empty(cmc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(('a' as i8))); @@ -443,7 +446,7 @@ fn main_0() -> i32 { ); ({ MyContainer_char_::pop_back(cmc.as_pointer()) }); assert!(({ MyContainer_char_::empty(cmc.as_pointer(),) })); - object!(fmc, MyContainer_float_::constructor_1()); + let fmc: Value = Rc::new(RefCell::new(::default())); assert!(({ MyContainer_float_::empty(fmc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new((1_f64 as f32))); diff --git a/tests/unit/out/refcount/clone_vs_move.rs b/tests/unit/out/refcount/clone_vs_move.rs index 01f08719fe..717560622a 100644 --- a/tests/unit/out/refcount/clone_vs_move.rs +++ b/tests/unit/out/refcount/clone_vs_move.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -55,19 +54,6 @@ pub struct Foo { #[byte_size(4)] pub bar: Bar, } -impl Default for Foo { - fn default() -> Self { - { - Foo { - x: 0_i32, - y: >::default(), - z: Ptr::::null(), - a: (0..3).map(|_| 0_i32).collect::>(), - bar: ::default(), - } - } - } -} #[derive( Clone, Record, @@ -77,7 +63,6 @@ impl Default for Foo { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/comma_operator.rs b/tests/unit/out/refcount/comma_operator.rs index c4bf0369ef..fb28c255c7 100644 --- a/tests/unit/out/refcount/comma_operator.rs +++ b/tests/unit/out/refcount/comma_operator.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/complex_function.rs b/tests/unit/out/refcount/complex_function.rs index cdaf1ef018..9c4025350c 100644 --- a/tests/unit/out/refcount/complex_function.rs +++ b/tests/unit/out/refcount/complex_function.rs @@ -25,7 +25,6 @@ pub fn bar_2(x: Ptr) -> Ptr { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -43,7 +42,6 @@ pub struct X1 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -67,7 +65,6 @@ impl X2 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -91,7 +88,6 @@ impl X3 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/compound_assign_paren.rs b/tests/unit/out/refcount/compound_assign_paren.rs index bcb31b9e27..d622676b69 100644 --- a/tests/unit/out/refcount/compound_assign_paren.rs +++ b/tests/unit/out/refcount/compound_assign_paren.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/concepts.rs b/tests/unit/out/refcount/concepts.rs index 4d2bb260fd..d48cb8f20d 100644 --- a/tests/unit/out/refcount/concepts.rs +++ b/tests/unit/out/refcount/concepts.rs @@ -21,7 +21,6 @@ const _: () = assert!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/constexpr_function.rs b/tests/unit/out/refcount/constexpr_function.rs index 3f53ea24b1..260195be5b 100644 --- a/tests/unit/out/refcount/constexpr_function.rs +++ b/tests/unit/out/refcount/constexpr_function.rs @@ -31,7 +31,6 @@ pub fn half_3(mut x: f64) -> f64 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -73,7 +72,6 @@ pub fn imm_7(mut b: bool) -> bool { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/constructor.rs b/tests/unit/out/refcount/constructor.rs index 7fbe88c197..c16ea8f306 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -93,17 +93,6 @@ impl Point { }; } } -impl Default for Point { - fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Point::constructor_3(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index c4bb6c21e0..06174883e0 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -19,7 +19,6 @@ use std::rc::{Rc, Weak}; CopyAssignable, MoveAssignable, Swappable, - Default, )] #[memberwise(move_constructor)] #[derive(Conversions)] diff --git a/tests/unit/out/refcount/container_field_addr.rs b/tests/unit/out/refcount/container_field_addr.rs index c4cac46cc0..0dbcef6bb7 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -17,7 +17,6 @@ use std::rc::{Rc, Weak}; Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -33,8 +32,17 @@ pub struct S { } impl S { pub fn constructor_1(this: Ptr) { - field!(this, tag).write(0_i32); - field!(this, v).write(Vec::new()); + this.write(::default()); + } +} +impl Default for S { + fn default() -> Self { + { + S { + tag: 0_i32, + v: Vec::new(), + } + } } } pub fn add_0(mut v: Ptr>, k: i32) { @@ -61,14 +69,10 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(local, S::constructor_1()); + let local: Value = Rc::new(RefCell::new(::default())); (*local.borrow_mut()).tag = 7; ({ run_1((local.as_pointer())) }); - let mut heap: Ptr = { - let __p = Ptr::alloc(::zero_init()); - S::constructor_1(__p.clone()); - __p - }; + let mut heap: Ptr = Ptr::alloc(::default()); field!(heap, tag).write(7); ({ run_1((heap).clone()) }); heap.delete(); diff --git a/tests/unit/out/refcount/conversion_operator_same_translation.rs b/tests/unit/out/refcount/conversion_operator_same_translation.rs index 95557778f6..65d8f965ec 100644 --- a/tests/unit/out/refcount/conversion_operator_same_translation.rs +++ b/tests/unit/out/refcount/conversion_operator_same_translation.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -45,7 +44,6 @@ impl S { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index 4f00ada430..577cd0ef3d 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -18,7 +18,6 @@ thread_local!( MoveConstructible, MoveAssignable, Swappable, - Default, Conversions, )] #[conversions(copy)] @@ -74,7 +73,7 @@ pub struct NonConstAssign { } impl NonConstAssign { pub fn constructor_1(this: Ptr) { - field!(this, mark).write(0); + this.write(::default()); } pub fn operator_assign_2(this: Ptr, o: Ptr) -> Ptr { field!(this, mark).write((o.with(|__s| __s.mark) + 1)); @@ -87,14 +86,7 @@ impl NonConstAssign { } impl Default for NonConstAssign { fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - NonConstAssign::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { NonConstAssign { mark: 0 } } } } #[derive( @@ -119,7 +111,7 @@ pub struct RefQualified { } impl RefQualified { pub fn constructor_1(this: Ptr) { - field!(this, mark).write(0); + this.write(::default()); } } impl CopyAssignable for RefQualified { @@ -131,14 +123,7 @@ impl CopyAssignable for RefQualified { } impl Default for RefQualified { fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - RefQualified::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { RefQualified { mark: 0 } } } } #[derive( @@ -158,18 +143,6 @@ pub struct Holder { pub arr: Box<[Partial]>, } impl Holder {} -impl Default for Holder { - fn default() -> Self { - { - Holder { - p: ::default(), - arr: (0..2) - .map(|_| ::default()) - .collect::>(), - } - } - } -} thread_local!( pub static copies_1: Value = Rc::new(RefCell::new(0)); ); @@ -183,7 +156,6 @@ thread_local!( MoveConstructible, MoveAssignable, Swappable, - Default, )] #[memberwise(copy_assign)] #[derive(Conversions)] @@ -222,18 +194,6 @@ pub struct HasCopyCounted { pub arr: Box<[CopyCounted]>, } impl HasCopyCounted {} -impl Default for HasCopyCounted { - fn default() -> Self { - { - HasCopyCounted { - c: ::default(), - arr: (0..2) - .map(|_| ::default()) - .collect::>(), - } - } - } -} #[derive( Clone, Record, @@ -244,7 +204,6 @@ impl Default for HasCopyCounted { Destructible, CopyConstructible, Movable, - Default, Conversions, )] #[conversions(copy)] @@ -257,7 +216,7 @@ pub struct ExplicitOperatorCall { } impl ExplicitOperatorCall { pub fn constructor_1(this: Ptr) { - field!(this, w).write(Vec::new()); + this.write(::default()); } } impl CopyAssignable for ExplicitOperatorCall { @@ -274,6 +233,11 @@ impl CopyAssignable for ExplicitOperatorCall { return (this).clone(); } } +impl Default for ExplicitOperatorCall { + fn default() -> Self { + { ExplicitOperatorCall { w: Vec::new() } } + } +} thread_local!( pub static swap_copies_2: Value = Rc::new(RefCell::new(0)); ); @@ -285,7 +249,6 @@ thread_local!( DefaultInitializable, MoveConstructible, Swappable, - Default, Conversions, )] #[conversions(copy)] @@ -334,14 +297,7 @@ impl MoveAssignable for Swapped { } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - DefaultInitializable, - Memberwise, - Swappable, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -376,7 +332,7 @@ pub struct VoidAssign { } impl VoidAssign { pub fn constructor_1(this: Ptr) { - field!(this, x).write(0); + this.write(::default()); } pub fn copy_assign(this: Ptr, o: Ptr) { field!(this, x).write((o.with(|__s| __s.x) + 5)); @@ -396,13 +352,7 @@ impl MoveAssignable for VoidAssign { } impl Default for VoidAssign { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - VoidAssign::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { VoidAssign { x: 0 } } } } #[derive( @@ -417,7 +367,6 @@ impl Default for VoidAssign { Memberwise, CopyConstructible, Movable, - Default, )] #[memberwise(copy_assign)] #[derive(Conversions)] @@ -431,7 +380,16 @@ pub struct HoldsVoidAssign { } impl HoldsVoidAssign { pub fn constructor_1(this: Ptr) { - VoidAssign::constructor_1(field_ptr!(this, v)); + this.write(::default()); + } +} +impl Default for HoldsVoidAssign { + fn default() -> Self { + { + HoldsVoidAssign { + v: ::default(), + } + } } } pub fn main() { @@ -491,16 +449,16 @@ fn main_0() -> i32 { && (array_elem!(h.as_pointer(), arr, 1).with(|__s| __s.keep) == 60) ); assert!((assigns_0.with(|rc| *rc.borrow()) == 8)); - object!(n, NonConstAssign::constructor_1()); - object!(n1, NonConstAssign::constructor_1()); - object!(n2, NonConstAssign::constructor_1()); - object!(cn, NonConstAssign::constructor_1()); + let n: Value = Rc::new(RefCell::new(::default())); + let n1: Value = Rc::new(RefCell::new(::default())); + let n2: Value = Rc::new(RefCell::new(::default())); + let cn: Value = Rc::new(RefCell::new(::default())); NonConstAssign::operator_assign_2(n1.as_pointer(), n.as_pointer()); NonConstAssign::operator_assign_3(n2.as_pointer(), cn.as_pointer()); assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); - object!(r, RefQualified::constructor_1()); - object!(r1, RefQualified::constructor_1()); + let r: Value = Rc::new(RefCell::new(::default())); + let r1: Value = Rc::new(RefCell::new(::default())); assign!(r1 = r); assert!(({ (*r1.borrow()).mark } == 1)); let h2: Value = Rc::new(RefCell::new(Holder { @@ -582,8 +540,8 @@ fn main_0() -> i32 { && (array_elem!(hc1.as_pointer(), arr, 1).with(|__s| __s.v) == 6) ); assert!((copies_1.with(|rc| *rc.borrow()) == 0)); - object!(e1, ExplicitOperatorCall::constructor_1()); - object!(e2, ExplicitOperatorCall::constructor_1()); + let e1: Value = Rc::new(RefCell::new(::default())); + let e2: Value = Rc::new(RefCell::new(::default())); ({ let __tmp_1: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( @@ -623,8 +581,8 @@ fn main_0() -> i32 { })); assign!(hs1 = hs2); assert!(({ (*hs1.borrow()).s.v } == 4) && (swap_copies_2.with(|rc| *rc.borrow()) == 2)); - object!(hv1, HoldsVoidAssign::constructor_1()); - object!(hv2, HoldsVoidAssign::constructor_1()); + let hv1: Value = Rc::new(RefCell::new(::default())); + let hv2: Value = Rc::new(RefCell::new(::default())); assign!(hv1 = hv2); assert!(({ (*hv1.borrow()).v.x } == 5)); return 0; diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 36d2db9828..5d006bf4fc 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -19,7 +19,6 @@ thread_local!( MoveConstructible, MoveAssignable, Swappable, - Default, )] #[memberwise(copy_assign)] #[derive(Conversions)] @@ -65,7 +64,7 @@ pub struct NonConst { } impl NonConst { pub fn constructor_1(this: Ptr) { - field!(this, mark).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, o: LvalueRef) { let o = o.as_pointer(); @@ -78,13 +77,7 @@ impl NonConst { } impl Default for NonConst { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - NonConst::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { NonConst { mark: 0 } } } } #[derive( @@ -97,7 +90,6 @@ impl Default for NonConst { MoveConstructible, MoveAssignable, Swappable, - Default, )] #[memberwise(copy_assign)] #[derive(Conversions)] @@ -136,21 +128,7 @@ pub struct Holder { pub arr: Box<[Counted]>, } impl Holder {} -impl Default for Holder { - fn default() -> Self { - { - Holder { - c: ::default(), - arr: (0..2) - .map(|_| ::default()) - .collect::>(), - } - } - } -} -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise)] #[memberwise(move_constructor)] #[derive(Conversions)] #[conversions(copy, move)] @@ -170,9 +148,7 @@ impl Box_int_ { field!(this, val).write(o.with(|__s| __s.val)); } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise)] #[memberwise(copy_constructor, move_constructor)] #[derive(Conversions)] #[conversions(copy, move)] @@ -193,7 +169,6 @@ impl Owner {} MoveConstructible, MoveAssignable, Swappable, - Default, )] #[memberwise(copy_assign)] #[derive(Conversions)] @@ -237,7 +212,7 @@ pub struct Tracked { } impl Tracked { pub fn constructor_1(this: Ptr) { - field!(this, copied_from).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); @@ -299,17 +274,6 @@ impl SelfPtr { field!(this, self_).write((this).clone()); } } -impl Default for SelfPtr { - fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - SelfPtr::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} #[derive( Copy, Clone, @@ -320,7 +284,6 @@ impl Default for SelfPtr { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -342,17 +305,6 @@ impl Derived { Counted::constructor_1(field_ptr!(this, c), 20); } } -impl Default for Derived { - fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Derived::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -441,20 +393,20 @@ fn main_0() -> i32 { ); assert!(({ (*ol2.borrow()).v } == 105)); assert!((copies_0.with(|rc| *rc.borrow()) == 12)); - object!(n, NonConst::constructor_1()); + let n: Value = Rc::new(RefCell::new(::default())); object!(n1, NonConst::constructor_2(LvalueRef::bind(n.as_pointer()))); - object!(cn, NonConst::constructor_1()); + let cn: Value = Rc::new(RefCell::new(::default())); object!( n2, NonConst::constructor_3(LvalueRef::bind(cn.as_pointer())) ); assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); - object!(t1, Tracked::constructor_1()); + let t1: Value = Rc::new(RefCell::new(::default())); object!(t2, Tracked::constructor_2(LvalueRef::bind(t1.as_pointer()))); assign!(t2 = t1); assert!(({ (*t1.borrow()).copied_from } == 2)); - object!(ct, Tracked::constructor_1()); + let ct: Value = Rc::new(RefCell::new(::default())); object!(t3, Tracked::constructor_2(LvalueRef::bind(ct.as_pointer()))); ({ touch_1((ct.as_pointer())) }); assert!(({ (*ct.borrow()).copied_from } == 2)); diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index 99e7082ee2..c272d44ffd 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -88,17 +87,6 @@ pub struct Implicit { #[array_len(2)] pub arr: Box<[i32]>, } -impl Default for Implicit { - fn default() -> Self { - { - Implicit { - v: 0_i32, - inner: ::default(), - arr: (0..2).map(|_| 0_i32).collect::>(), - } - } - } -} #[derive( Copy, Clone, @@ -111,7 +99,6 @@ impl Default for Implicit { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(copy_assign)] #[derive(Conversions)] @@ -142,14 +129,7 @@ impl MoveAssignable for DefaultCopyUserMove { } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - DefaultInitializable, - Memberwise, - Swappable, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] @@ -219,11 +199,6 @@ impl Buffer { ); } } -impl Default for Buffer { - fn default() -> Self { - { ::zero_init() } - } -} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] @@ -246,17 +221,14 @@ pub struct Owner { } impl Owner { pub fn constructor_1(this: Ptr) { - field!(this, data).write(Vec::new()); - field!(this, n).write(0_i32); - field!(this, arr).write((0..2).map(|_| 0_i32).collect::>()); - field!(this, p).write(None); + this.write(::default()); } } impl Default for Owner { fn default() -> Self { { Owner { - data: Default::default(), + data: Vec::new(), n: 0_i32, arr: (0..2).map(|_| 0_i32).collect::>(), p: None, @@ -275,7 +247,6 @@ impl Default for Owner { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -289,7 +260,12 @@ pub struct Copyable { } impl Copyable { pub fn constructor_1(this: Ptr) { - field!(this, data).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Copyable { + fn default() -> Self { + { Copyable { data: Vec::new() } } } } #[derive( @@ -335,7 +311,7 @@ pub struct SeesThis { } impl SeesThis { pub fn constructor_1(this: Ptr) { - field!(this, self_).write(Ptr::::null()); + this.write(::default()); } } impl CopyAssignable for SeesThis { @@ -361,7 +337,7 @@ impl Default for SeesThis { } } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise)] #[memberwise(copy_assign, move_assign)] #[derive(Conversions)] #[constructor(constructor_1)] @@ -376,8 +352,17 @@ pub struct HasSeesThis { } impl HasSeesThis { pub fn constructor_1(this: Ptr) { - SeesThis::constructor_1(field_ptr!(this, s)); - field!(this, v).write(Vec::new()); + this.write(::default()); + } +} +impl Default for HasSeesThis { + fn default() -> Self { + { + HasSeesThis { + s: ::default(), + v: Vec::new(), + } + } } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] @@ -393,8 +378,7 @@ pub struct Counted_int_ { } impl Counted_int_ { pub fn constructor_1(this: Ptr) { - field!(this, v).write(0_i32); - field!(this, moves).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); @@ -415,9 +399,7 @@ impl Default for Counted_int_ { { Counted_int_ { v: 0_i32, moves: 0 } } } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] @@ -433,8 +415,17 @@ pub struct HasCounted { } impl HasCounted { pub fn constructor_1(this: Ptr) { - Counted_int_::constructor_1(field_ptr!(this, c)); - field!(this, w).write(Vec::new()); + this.write(::default()); + } +} +impl Default for HasCounted { + fn default() -> Self { + { + HasCounted { + c: ::default(), + w: Vec::new(), + } + } } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] @@ -483,21 +474,7 @@ impl MoveAssignable for CtorSeesThis { return (this).clone(); } } -impl Default for CtorSeesThis { - fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - CtorSeesThis::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(Conversions)] #[conversions(copy, move)] @@ -537,18 +514,6 @@ impl InitsCtorSeesThis { CtorSeesThis::constructor_2(field_ptr!(this, y), 2); } } -impl Default for InitsCtorSeesThis { - fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - InitsCtorSeesThis::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} #[derive( Record, ByteRepr, @@ -590,18 +555,6 @@ impl Constructor<()> for OutOfLineDefaulted { } } } -impl Default for OutOfLineDefaulted { - fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - OutOfLineDefaulted::construct(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} impl OutOfLineDefaulted {} impl OutOfLineDefaulted {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] @@ -619,9 +572,7 @@ pub struct OutOfLineAssign { } impl OutOfLineAssign { pub fn constructor_1(this: Ptr) { - SeesThis::constructor_1(field_ptr!(this, s)); - field!(this, v).write(1); - field!(this, w).write(Vec::new()); + this.write(::default()); } } impl Default for OutOfLineAssign { @@ -630,7 +581,7 @@ impl Default for OutOfLineAssign { OutOfLineAssign { s: ::default(), v: 1, - w: Default::default(), + w: Vec::new(), } } } @@ -815,7 +766,7 @@ fn main_0() -> i32 { && ((*bufs.borrow())[0_usize].data.is_empty()) }) ); - object!(o1, Owner::constructor_1()); + let o1: Value = Rc::new(RefCell::new(::default())); ({ let __tmp_3: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( @@ -843,7 +794,7 @@ fn main_0() -> i32 { && (({ (*o1.borrow()).p.clone() }.as_pointer()).is_null()) }) ); - object!(o3, Owner::constructor_1()); + let o3: Value = Rc::new(RefCell::new(::default())); assign!(o3 = RvalueRef(o2)); assert!( ((({ (*o3.borrow()).n } == 5) @@ -869,7 +820,7 @@ fn main_0() -> i32 { }); assert!(({ (c2.data.len() == 2_usize) && ((*c3.borrow()).data.len() == 2_usize) })); assert!(({ (*c1.borrow()).data.is_empty() })); - object!(c4, Copyable::constructor_1()); + let c4: Value = Rc::new(RefCell::new(::default())); assign!(c4 = RvalueRef(c3)); assert!( ({ @@ -898,14 +849,14 @@ fn main_0() -> i32 { && (({ (*h3.borrow()).p.clone() }.as_pointer().read()) == 9)) && (({ (*h2.borrow()).p.clone() }.as_pointer()).is_null()) ); - object!(t1, HasSeesThis::constructor_1()); - object!(t2, HasSeesThis::constructor_1()); - object!(t3, HasSeesThis::constructor_1()); + let t1: Value = Rc::new(RefCell::new(::default())); + let t2: Value = Rc::new(RefCell::new(::default())); + let t3: Value = Rc::new(RefCell::new(::default())); assign!(t2 = RvalueRef(t1)); assert!(({ { (*t2.borrow()).s.self_.clone() } } == { (field_ptr!(t2.as_pointer(), s)) })); assign!(t3 = t2); assert!(({ { (*t3.borrow()).s.self_.clone() } } == { (field_ptr!(t3.as_pointer(), s)) })); - object!(k1, HasCounted::constructor_1()); + let k1: Value = Rc::new(RefCell::new(::default())); object!(k2, HasCounted, |k2| { ::move_constructor( k2.clone(), @@ -913,7 +864,7 @@ fn main_0() -> i32 { ) }); assert!(({ (*k2.borrow()).c.moves } == 1)); - object!(k3, HasCounted::constructor_1()); + let k3: Value = Rc::new(RefCell::new(::default())); assign!(k3 = RvalueRef(k2)); assert!(({ (*k3.borrow()).c.moves } == 2)); { @@ -981,9 +932,9 @@ fn main_0() -> i32 { ({ (*o2.borrow()).v } == 2) && ({ { (*o2.borrow()).x.self_.clone() } } == { (field_ptr!(o2.as_pointer(), x)) }) ); - object!(a1, OutOfLineAssign::constructor_1()); - object!(a2, OutOfLineAssign::constructor_1()); - object!(a3, OutOfLineAssign::constructor_1()); + let a1: Value = Rc::new(RefCell::new(::default())); + let a2: Value = Rc::new(RefCell::new(::default())); + let a3: Value = Rc::new(RefCell::new(::default())); (*a1.borrow_mut()).v = 3; ({ let __tmp_4: Value = Rc::new(RefCell::new(4)); diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index 3779e7dc33..95f7c873e6 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -7,14 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - DefaultInitializable, - Swappable, - Default, - Conversions, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Swappable, Conversions, )] #[conversions(move)] #[constructor(constructor_1, i32)] @@ -53,7 +46,7 @@ pub struct PrivateCopy { } impl PrivateCopy { pub fn constructor_2(this: Ptr) { - field!(this, v).write(0); + this.write(::default()); } pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); @@ -71,14 +64,7 @@ impl MoveAssignable for PrivateCopy { } impl Default for PrivateCopy { fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - PrivateCopy::constructor_2(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { PrivateCopy { v: 0 } } } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] @@ -90,29 +76,16 @@ pub struct Immovable { } impl Immovable { pub fn constructor_1(this: Ptr) { - field!(this, v).write(0); + this.write(::default()); } } impl Default for Immovable { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Immovable::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { Immovable { v: 0 } } } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - DefaultInitializable, - Memberwise, - Swappable, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] @@ -126,9 +99,7 @@ pub struct Container { pub tag: i32, } impl Container {} -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] @@ -141,7 +112,12 @@ pub struct VecHolder { } impl VecHolder { pub fn constructor_1(this: Ptr) { - field!(this, items).write(Vec::new()); + this.write(::default()); + } +} +impl Default for VecHolder { + fn default() -> Self { + { VecHolder { items: Vec::new() } } } } pub fn bump_0(mut p: Ptr) { @@ -162,7 +138,7 @@ fn main_0() -> i32 { assert!(({ (*a.borrow()).v } == 1) && ({ (*b.borrow()).v } == 0)); ({ bump_0((a.as_pointer())) }); assert!(({ (*a.borrow()).v } == 2)); - object!(p, PrivateCopy::constructor_2()); + let p: Value = Rc::new(RefCell::new(::default())); (*p.borrow_mut()).v = 3; object!( q, @@ -171,7 +147,7 @@ fn main_0() -> i32 { assert!(({ (*q.borrow()).v } == 3) && ({ (*p.borrow()).v } == 0)); assign!(p = RvalueRef(q)); assert!(({ (*p.borrow()).v } == 3) && ({ (*q.borrow()).v } == 0)); - object!(im, Immovable::constructor_1()); + let im: Value = Rc::new(RefCell::new(::default())); (*im.borrow_mut()).v = 4; ({ bump_ref_1(im.as_pointer()) }); let mut pim: Ptr = (im.as_pointer()); @@ -194,7 +170,7 @@ fn main_0() -> i32 { (({ (*d.borrow()).inner.v } == 6) && ({ (*d.borrow()).tag } == 7)) && ({ (*c.borrow()).inner.v } == 0) ); - object!(h, VecHolder::constructor_1()); + let h: Value = Rc::new(RefCell::new(::default())); object!(h2, VecHolder, |h2| { ::move_constructor( h2.clone(), diff --git a/tests/unit/out/refcount/default.rs b/tests/unit/out/refcount/default.rs index 6f657c55a8..356c6c8ac4 100644 --- a/tests/unit/out/refcount/default.rs +++ b/tests/unit/out/refcount/default.rs @@ -37,23 +37,6 @@ pub struct Pointers { #[offset(136)] pub x5: i32, } -impl Default for Pointers { - fn default() -> Self { - { - Pointers { - x1: Ptr::::null(), - x2: Ptr::::null(), - x3: (0..5) - .map(|_| Ptr::::null()) - .collect::]>>(), - x4: (0..10) - .map(|_| Ptr::::null()) - .collect::]>>(), - x5: 0_i32, - } - } - } -} #[derive( Clone, Record, @@ -84,22 +67,6 @@ pub struct SmallArrays { #[array_len(2)] pub p: Box<[Pointers]>, } -impl Default for SmallArrays { - fn default() -> Self { - { - SmallArrays { - a: (0..32).map(|_| 0_i32).collect::>(), - f: FnPtr:: i32>::null(), - fs: (0..2) - .map(|_| FnPtr:: i32>::null()) - .collect:: i32>]>>(), - p: (0..2) - .map(|_| ::default()) - .collect::>(), - } - } - } -} #[derive( Clone, Record, @@ -119,15 +86,6 @@ pub struct BigArray { #[array_len(33)] pub a: Box<[i32]>, } -impl Default for BigArray { - fn default() -> Self { - { - BigArray { - a: (0..33).map(|_| 0_i32).collect::>(), - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/default_function_arguments.rs b/tests/unit/out/refcount/default_function_arguments.rs index ed9a024b22..d457ab43e1 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -42,17 +42,6 @@ impl Constructor<()> for Bar { } } } -impl Default for Bar { - fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Bar::constructor_1(__v.as_pointer(), 1); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} thread_local!( pub static counter_2: Value = Rc::new(RefCell::new(0)); ); @@ -91,7 +80,6 @@ pub fn first_9(r: Ptr) -> i32 { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/default_in_statics.rs b/tests/unit/out/refcount/default_in_statics.rs index 53c1045bd0..185016d08c 100644 --- a/tests/unit/out/refcount/default_in_statics.rs +++ b/tests/unit/out/refcount/default_in_statics.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -66,24 +65,6 @@ pub struct Outer { #[byte_size(8)] pub fn_: FnPtr i32>, } -impl Default for Outer { - fn default() -> Self { - { - Outer { - p1: Ptr::::null(), - p2: Ptr::::null(), - arr: (0..3) - .map(|_| Ptr::::null()) - .collect::]>>(), - cp: Ptr::::null(), - pp: Ptr::>::null(), - inner: ::default(), - x: 0_i32, - fn_: FnPtr:: i32>::null(), - } - } - } -} #[derive( Clone, Record, @@ -93,7 +74,6 @@ impl Default for Outer { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index bc17b6fa88..0d391fe2dc 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -314,48 +314,46 @@ pub fn main() { } fn main_0() -> i32 { { - let s: Value = Rc::new(RefCell::new(::default_constructed())); + let s: Value = Rc::new(RefCell::new(::default())); let _dtor_s = std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 1)); { - let s: Value = Rc::new(RefCell::new(::default_constructed())); + let s: Value = Rc::new(RefCell::new(::default())); let _dtor_s = std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 2)); { - let d: Value = Rc::new(RefCell::new(::default_constructed())); + let d: Value = Rc::new(RefCell::new(::default())); let _dtor_d = std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 3)); { - let o: Value = Rc::new(RefCell::new(::default_constructed())); + let o: Value = Rc::new(RefCell::new(::default())); let _dtor_o = std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 4)); { - let am: Value = Rc::new(RefCell::new(::default_constructed())); + let am: Value = Rc::new(RefCell::new(::default())); let _dtor_am = std::mem::DropGuard::new(am.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 7)); { - let e: Value = Rc::new(RefCell::new(::default_constructed())); + let e: Value = Rc::new(RefCell::new(::default())); let _dtor_e = std::mem::DropGuard::new(e.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 8)); { - let tc: Value = - Rc::new(RefCell::new(::default_constructed())); + let tc: Value = Rc::new(RefCell::new(::default())); let _dtor_tc = std::mem::DropGuard::new(tc.clone(), |__p| Destructible::destroy(__p.as_pointer())); - let ti: Value = - Rc::new(RefCell::new(::default_constructed())); + let ti: Value = Rc::new(RefCell::new(::default())); let _dtor_ti = std::mem::DropGuard::new(ti.clone(), |__p| Destructible::destroy(__p.as_pointer())); } @@ -402,7 +400,7 @@ fn main_0() -> i32 { ); let mut before: i32 = global_0.with(|rc| *rc.borrow()); { - let cs: Value = Rc::new(RefCell::new(::default_constructed())); + let cs: Value = Rc::new(RefCell::new(::default())); let _dtor_cs = std::mem::DropGuard::new(cs.clone(), |__p| Destructible::destroy(__p.as_pointer())); } diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index b791c8fdae..7e0a5bcf76 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -57,7 +57,6 @@ pub fn with_default_3(s: ParameterObject) -> i32 { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/doubly_linked_list.rs b/tests/unit/out/refcount/doubly_linked_list.rs index e9a847d3d9..cc694aa3f0 100644 --- a/tests/unit/out/refcount/doubly_linked_list.rs +++ b/tests/unit/out/refcount/doubly_linked_list.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/enum_default_in_static.rs b/tests/unit/out/refcount/enum_default_in_static.rs index d0d934c149..237491803b 100644 --- a/tests/unit/out/refcount/enum_default_in_static.rs +++ b/tests/unit/out/refcount/enum_default_in_static.rs @@ -20,7 +20,6 @@ pub const Mode_MODE_TWO: Mode = 2; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct Config { diff --git a/tests/unit/out/refcount/enum_int_interop.rs b/tests/unit/out/refcount/enum_int_interop.rs index 3c053eb092..cbf68c4a4c 100644 --- a/tests/unit/out/refcount/enum_int_interop.rs +++ b/tests/unit/out/refcount/enum_int_interop.rs @@ -28,7 +28,6 @@ pub const Tag_TAG_TWO: Tag = 2; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/enum_int_interop_c.rs b/tests/unit/out/refcount/enum_int_interop_c.rs index d56a7cf2be..ff2f49e8bc 100644 --- a/tests/unit/out/refcount/enum_int_interop_c.rs +++ b/tests/unit/out/refcount/enum_int_interop_c.rs @@ -28,7 +28,6 @@ pub const Tag_enum_TAG_TWO: Tag_enum = 2; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct Entry { diff --git a/tests/unit/out/refcount/enum_underlying_type.rs b/tests/unit/out/refcount/enum_underlying_type.rs index 2db50121d3..9858a32841 100644 --- a/tests/unit/out/refcount/enum_underlying_type.rs +++ b/tests/unit/out/refcount/enum_underlying_type.rs @@ -45,7 +45,7 @@ pub struct HoldsEmpty { } impl HoldsEmpty { pub fn constructor_1(this: Ptr) { - field!(this, e).write(::default()); + this.write(::default()); } } impl Default for HoldsEmpty { @@ -88,10 +88,10 @@ fn main_0() -> i32 { let mut sc: Scoped = Scoped_NEG; assert!(((sc as i32) == -2_i32)); assert!((((Scoped_POS as i8) as i32) == 2)); - object!(he, HoldsEmpty::constructor_1()); - assert!(!({ (*he.borrow()).e })); + let mut he: HoldsEmpty = ::default(); + assert!(!(he.e)); let mut ev: Empty = ::default(); - assert!(((ev as i32) == ({ (*he.borrow()).e } as i32))); + assert!(((ev as i32) == (he.e as i32))); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/exprs.rs b/tests/unit/out/refcount/exprs.rs index bfc3ccee0f..2b85506ce6 100644 --- a/tests/unit/out/refcount/exprs.rs +++ b/tests/unit/out/refcount/exprs.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -34,7 +33,6 @@ pub struct X { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/fft.rs b/tests/unit/out/refcount/fft.rs index e83258f355..18888cd669 100644 --- a/tests/unit/out/refcount/fft.rs +++ b/tests/unit/out/refcount/fft.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/field_aliasing.rs b/tests/unit/out/refcount/field_aliasing.rs index 7e17c2ef68..6ebf970f2e 100644 --- a/tests/unit/out/refcount/field_aliasing.rs +++ b/tests/unit/out/refcount/field_aliasing.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct In { @@ -49,18 +48,6 @@ pub struct S { #[array_len(4)] pub arr: Box<[i32]>, } -impl Default for S { - fn default() -> Self { - { - S { - in_: ::default(), - total: 0_i32, - n: 0_i32, - arr: (0..4).map(|_| 0_i32).collect::>(), - } - } - } -} #[derive( Clone, Record, @@ -70,7 +57,6 @@ impl Default for S { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct Node { diff --git a/tests/unit/out/refcount/field_array_elem_ptr.rs b/tests/unit/out/refcount/field_array_elem_ptr.rs index 586d4d520c..2ff59f3454 100644 --- a/tests/unit/out/refcount/field_array_elem_ptr.rs +++ b/tests/unit/out/refcount/field_array_elem_ptr.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -54,18 +53,6 @@ pub struct Shape { #[offset(44)] pub tail: i32, } -impl Default for Shape { - fn default() -> Self { - { - Shape { - id: 0_i32, - coords: (0..4).map(|_| 0_i32).collect::>(), - points: (0..3).map(|_| ::default()).collect::>(), - tail: 0_i32, - } - } - } -} pub fn sum_0(mut p: Ptr, mut n: i32) -> i32 { let mut s: i32 = 0; { diff --git a/tests/unit/out/refcount/field_method_receiver.rs b/tests/unit/out/refcount/field_method_receiver.rs index b2f2329ea7..b0b5df617d 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -81,14 +80,7 @@ impl S { ({ Counter::add(field_ptr!(this, c), this.with(|__s| __s.tag)) }); } pub fn constructor_1(this: Ptr) { - field!(this, tag).write(0_i32); - field!(this, c).write(::default()); - field!(this, arr).write( - (0..2) - .map(|_| ::default()) - .collect::>(), - ); - field!(this, v).write(Vec::new()); + this.write(::default()); } } impl Default for S { @@ -100,7 +92,7 @@ impl Default for S { arr: (0..2) .map(|_| ::default()) .collect::>(), - v: Default::default(), + v: Vec::new(), } } } @@ -144,10 +136,20 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let local: Value = Rc::new(RefCell::new(::default())); + let local: Value = Rc::new(RefCell::new(S { + tag: 0_i32, + c: ::default(), + arr: Box::new([::default(); 2]), + v: Vec::new(), + })); (*local.borrow_mut()).tag = 1; ({ run_0((local.as_pointer())) }); - let mut heap: Ptr = Ptr::alloc(::default()); + let mut heap: Ptr = Ptr::alloc(S { + tag: 0_i32, + c: ::default(), + arr: Box::new([::default(); 2]), + v: Vec::new(), + }); field!(heap, tag).write(1); ({ run_0((heap).clone()) }); heap.delete(); diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index b4007c4652..014efefc6e 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -27,16 +27,6 @@ pub struct Inner { #[array_len(8)] pub name: Box<[i8]>, } -impl Default for Inner { - fn default() -> Self { - { - Inner { - a: 0_i32, - name: (0..8).map(|_| 0_i8).collect::>(), - } - } - } -} #[derive( Copy, Clone, @@ -47,7 +37,6 @@ impl Default for Inner { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -110,12 +99,7 @@ impl Outer { }); } pub fn constructor_1(this: Ptr) { - field!(this, x).write(0_i32); - field!(this, inner).write(::default()); - field!(this, items).write((0..3).map(|_| ::default()).collect::>()); - field!(this, v).write(Vec::new()); - field!(this, cursor).write(Ptr::::null()); - field!(this, buf).write((0..4).map(|_| 0_i32).collect::>()); + this.write(::default()); } } impl Default for Outer { @@ -125,7 +109,7 @@ impl Default for Outer { x: 0_i32, inner: ::default(), items: (0..3).map(|_| ::default()).collect::>(), - v: Default::default(), + v: Vec::new(), cursor: Ptr::::null(), buf: (0..4).map(|_| 0_i32).collect::>(), } @@ -144,7 +128,14 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let o: Value = Rc::new(RefCell::new(::default())); + let o: Value = Rc::new(RefCell::new(Outer { + x: 0_i32, + inner: ::default(), + items: Box::new([::default(), ::default(), ::default()]), + v: Vec::new(), + cursor: Ptr::::null(), + buf: Box::new([0; 4]), + })); (*o.borrow_mut()).x = 1; let mut px: Ptr = (field_ptr!(o.as_pointer(), x)); px.write(2); diff --git a/tests/unit/out/refcount/field_pointers_malloced_struct.rs b/tests/unit/out/refcount/field_pointers_malloced_struct.rs index 6fd9214c78..ab042a58f2 100644 --- a/tests/unit/out/refcount/field_pointers_malloced_struct.rs +++ b/tests/unit/out/refcount/field_pointers_malloced_struct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/field_reinterpret_write_through.rs b/tests/unit/out/refcount/field_reinterpret_write_through.rs index d4a33fd864..6e3a110374 100644 --- a/tests/unit/out/refcount/field_reinterpret_write_through.rs +++ b/tests/unit/out/refcount/field_reinterpret_write_through.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct In { @@ -53,19 +52,6 @@ pub struct S { #[offset(32)] pub tail: i64, } -impl Default for S { - fn default() -> Self { - { - S { - x: 0_i32, - in_: ::default(), - bytes: (0..4).map(|_| 0_u8).collect::>(), - arr: (0..3).map(|_| 0_i32).collect::>(), - tail: 0_i64, - } - } - } -} pub fn set_bytes_0(mut p: Ptr, mut n: usize, mut v: u8) { { let mut i: usize = 0_usize; diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index f665062c8d..f41771e569 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/first_field_ptr_covers_struct.rs b/tests/unit/out/refcount/first_field_ptr_covers_struct.rs index dedbeb550e..a42e743bc5 100644 --- a/tests/unit/out/refcount/first_field_ptr_covers_struct.rs +++ b/tests/unit/out/refcount/first_field_ptr_covers_struct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(4)] pub struct In { @@ -35,7 +34,6 @@ pub struct In { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(12)] pub struct S { diff --git a/tests/unit/out/refcount/first_member_downcast.rs b/tests/unit/out/refcount/first_member_downcast.rs index 2ae2ba0ab5..3291c5a1f7 100644 --- a/tests/unit/out/refcount/first_member_downcast.rs +++ b/tests/unit/out/refcount/first_member_downcast.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(4)] pub struct base { @@ -33,7 +32,6 @@ pub struct base { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct derived { diff --git a/tests/unit/out/refcount/flex_array_member_incomplete.rs b/tests/unit/out/refcount/flex_array_member_incomplete.rs index 9cc982b938..a4a54cfc17 100644 --- a/tests/unit/out/refcount/flex_array_member_incomplete.rs +++ b/tests/unit/out/refcount/flex_array_member_incomplete.rs @@ -25,16 +25,6 @@ pub struct F { #[array_len(0)] pub tail: Box<[i8]>, } -impl Default for F { - fn default() -> Self { - { - F { - n: 0_i32, - tail: Box::<[i8]>::default(), - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/flex_array_member_sibling_write.rs b/tests/unit/out/refcount/flex_array_member_sibling_write.rs index 6e100bd2cf..383410e180 100644 --- a/tests/unit/out/refcount/flex_array_member_sibling_write.rs +++ b/tests/unit/out/refcount/flex_array_member_sibling_write.rs @@ -25,16 +25,6 @@ pub struct S { #[array_len(1)] pub name: Box<[i8]>, } -impl Default for S { - fn default() -> Self { - { - S { - n: 0_i32, - name: (0..1).map(|_| 0_i8).collect::>(), - } - } - } -} #[derive( Copy, Clone, @@ -45,7 +35,6 @@ impl Default for S { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct E { @@ -75,17 +64,6 @@ pub struct T { #[array_len(1)] pub a: Box<[E]>, } -impl Default for T { - fn default() -> Self { - { - T { - n: 0_i32, - cap: 0_i32, - a: (0..1).map(|_| ::default()).collect::>(), - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/fn_ptr.rs b/tests/unit/out/refcount/fn_ptr.rs index de9aea0872..3c35d262d7 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -37,7 +37,6 @@ pub fn identity_hash_6(mut v: bool) -> usize { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/fn_ptr_cast.rs b/tests/unit/out/refcount/fn_ptr_cast.rs index 6c7a6e4834..631cb00da5 100644 --- a/tests/unit/out/refcount/fn_ptr_cast.rs +++ b/tests/unit/out/refcount/fn_ptr_cast.rs @@ -33,7 +33,6 @@ pub fn test_double_cast_2() { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/fn_ptr_stable_sort.rs b/tests/unit/out/refcount/fn_ptr_stable_sort.rs index 7e8ac3b925..c62a4de769 100644 --- a/tests/unit/out/refcount/fn_ptr_stable_sort.rs +++ b/tests/unit/out/refcount/fn_ptr_stable_sort.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index 22c991bf97..5dee5fe351 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -43,7 +42,6 @@ pub fn negate_1(mut x: i32) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -60,9 +58,7 @@ impl S { return (x + 3); } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, RvalueRef)] diff --git a/tests/unit/out/refcount/fn_ptr_typedef_cast.rs b/tests/unit/out/refcount/fn_ptr_typedef_cast.rs index ee141633e2..a22e5d3b7c 100644 --- a/tests/unit/out/refcount/fn_ptr_typedef_cast.rs +++ b/tests/unit/out/refcount/fn_ptr_typedef_cast.rs @@ -28,7 +28,6 @@ pub fn via_size_t_return_3(mut b: u64) -> usize { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct pair { diff --git a/tests/unit/out/refcount/fn_ptr_vtable.rs b/tests/unit/out/refcount/fn_ptr_vtable.rs index 3c29459b04..3b1db6e92e 100644 --- a/tests/unit/out/refcount/fn_ptr_vtable.rs +++ b/tests/unit/out/refcount/fn_ptr_vtable.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/fn_ref.rs b/tests/unit/out/refcount/fn_ref.rs index d73522be9b..d0b70b3994 100644 --- a/tests/unit/out/refcount/fn_ref.rs +++ b/tests/unit/out/refcount/fn_ref.rs @@ -30,7 +30,6 @@ pub fn call_forwarded_4(f: FnPtr i32>, mut x: i32) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index ab3ac134d4..13540da7cc 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -17,7 +17,6 @@ use std::rc::{Rc, Weak}; Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -33,8 +32,17 @@ pub struct S { } impl S { pub fn constructor_1(this: Ptr) { - field!(this, v).write(Vec::new()); - field!(this, a).write(0_i32); + this.write(::default()); + } +} +impl Default for S { + fn default() -> Self { + { + S { + v: Vec::new(), + a: 0_i32, + } + } } } pub fn main() { @@ -42,7 +50,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S::constructor_1()); + let s: Value = Rc::new(RefCell::new(::default())); ({ let __tmp_0: Value = Rc::new(RefCell::new(1)); MoveConstructible::push_moved( diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index 9102d7ef1b..d47055eed8 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -9,9 +9,7 @@ use std::rc::{Rc, Weak}; pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] @@ -63,9 +61,7 @@ impl Holder { Tracked::constructor_3(field_ptr!(this, t), RvalueRef::bind((x).clone())); } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise)] #[memberwise(copy_constructor, move_constructor)] #[derive(Conversions)] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index 75903e0673..3e04412069 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -9,9 +9,7 @@ use std::rc::{Rc, Weak}; pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index 3d55c011d1..cfb9a45fcb 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -11,9 +11,7 @@ pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index 83247cb240..1769f0d4d9 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -11,9 +11,7 @@ pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] @@ -103,9 +101,7 @@ impl Pair { Tracked::constructor_3(field_ptr!(this, b), RvalueRef::bind((y).clone())); } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise)] #[memberwise(copy_constructor, move_constructor)] #[derive(Conversions)] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index b2098a0d9d..ef3b10911f 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -25,7 +25,6 @@ pub fn scaled_2(v: Ptr, mut k: f64) -> f64 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -47,7 +46,6 @@ pub fn get_3(w: Ptr) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -69,7 +67,6 @@ pub fn get_4(w: Ptr) -> i64 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -88,7 +85,6 @@ pub struct W_long_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/function_overloading.rs b/tests/unit/out/refcount/function_overloading.rs index 60a3a5951d..424003af47 100644 --- a/tests/unit/out/refcount/function_overloading.rs +++ b/tests/unit/out/refcount/function_overloading.rs @@ -31,7 +31,6 @@ pub fn bar_4(x: Ptr) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/global_call_temporaries.rs b/tests/unit/out/refcount/global_call_temporaries.rs index 91d788b618..ccd29a7917 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -113,7 +113,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/global_init_side_effect.rs b/tests/unit/out/refcount/global_init_side_effect.rs index f1f34df9ee..ab093d44c9 100644 --- a/tests/unit/out/refcount/global_init_side_effect.rs +++ b/tests/unit/out/refcount/global_init_side_effect.rs @@ -19,7 +19,6 @@ thread_local!( FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index 3e989d0e15..2adf0bdd3a 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -53,7 +53,7 @@ pub struct Ctor { } impl Ctor { pub fn constructor_1(this: Ptr) { - field!(this, v).write(({ next_0() })); + this.write(::default()); } pub fn constructor_2(this: Ptr, mut x: i32) { field!(this, v).write(x); @@ -61,21 +61,11 @@ impl Ctor { } impl Default for Ctor { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Ctor::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { Ctor { v: ({ next_0() }) } } } } thread_local!( - pub static default_ctor_7: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Ctor::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + pub static default_ctor_7: Value = Rc::new(RefCell::new(::default())); ); thread_local!( pub static arg_ctor_8: Value = Rc::new(RefCell::new({ @@ -108,7 +98,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -150,7 +139,7 @@ pub struct Singleton { } impl Singleton { pub fn constructor_1(this: Ptr) { - field!(this, hits).write(0); + this.write(::default()); } pub fn instance() -> Ptr { return s_15.with(|v| v.as_pointer()); @@ -158,21 +147,11 @@ impl Singleton { } impl Default for Singleton { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Singleton::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { Singleton { hits: 0 } } } } thread_local!( - static s_15: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Singleton::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + static s_15: Value = Rc::new(RefCell::new(::default())); ); pub fn main() { __cpp2rust_init_globals(); diff --git a/tests/unit/out/refcount/global_pointers.rs b/tests/unit/out/refcount/global_pointers.rs index 72794e1869..bf5cfd24b0 100644 --- a/tests/unit/out/refcount/global_pointers.rs +++ b/tests/unit/out/refcount/global_pointers.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/global_without_initializer.rs b/tests/unit/out/refcount/global_without_initializer.rs index 5368ea07f3..9581a3fb13 100644 --- a/tests/unit/out/refcount/global_without_initializer.rs +++ b/tests/unit/out/refcount/global_without_initializer.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/goto_aggregate_default.rs b/tests/unit/out/refcount/goto_aggregate_default.rs index e42b37f3b9..4fd037fb82 100644 --- a/tests/unit/out/refcount/goto_aggregate_default.rs +++ b/tests/unit/out/refcount/goto_aggregate_default.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct Point { diff --git a/tests/unit/out/refcount/goto_cleanup.rs b/tests/unit/out/refcount/goto_cleanup.rs index 72d277e6a2..297f4de95c 100644 --- a/tests/unit/out/refcount/goto_cleanup.rs +++ b/tests/unit/out/refcount/goto_cleanup.rs @@ -85,7 +85,6 @@ pub fn from_switch_2(mut n: i32) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct wrapper { diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index 22b3208ef7..a93a19a1ab 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -58,9 +57,7 @@ pub fn Swap_0(a: Ptr, b: Ptr) { right: (t.right).clone(), }); } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] @@ -240,11 +237,20 @@ impl MinHeap { } } pub fn constructor_1(this: Ptr) { - field!(this, size).write(0_i32); - field!(this, capacity).write(0_i32); - field!(this, arr).write(None); - field!(this, next).write(0_i32); - field!(this, alloc).write(None); + this.write(::default()); + } +} +impl Default for MinHeap { + fn default() -> Self { + { + MinHeap { + size: 0_i32, + capacity: 0_i32, + arr: None, + next: 0_i32, + alloc: None, + } + } } } pub fn AllocMinHeap_1(mut capacity: i32) -> Option> { diff --git a/tests/unit/out/refcount/immutable-deref-on-func-call.rs b/tests/unit/out/refcount/immutable-deref-on-func-call.rs index b5e695214e..1a06b317de 100644 --- a/tests/unit/out/refcount/immutable-deref-on-func-call.rs +++ b/tests/unit/out/refcount/immutable-deref-on-func-call.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index f30d5b13c8..b1b3b5551b 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -17,7 +17,6 @@ use std::rc::{Rc, Weak}; Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -31,7 +30,12 @@ pub struct Holder { } impl Holder { pub fn constructor_1(this: Ptr) { - field!(this, v).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Holder { + fn default() -> Self { + { Holder { v: Vec::new() } } } } pub fn write_through_0(mut p: Ptr) { @@ -54,7 +58,7 @@ fn main_0() -> i32 { let mut p: Ptr> = (v.as_pointer()); let mut a: i32 = (index!(p, 0_usize).read()); index!(p, 1_usize).write(30); - object!(h, Holder::constructor_1()); + let h: Value = Rc::new(RefCell::new(::default())); ({ let __tmp_2: Value = Rc::new(RefCell::new(40)); MoveConstructible::push_moved( diff --git a/tests/unit/out/refcount/in_class_field_initializer.rs b/tests/unit/out/refcount/in_class_field_initializer.rs index a4404eedc0..41bafafe18 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.rs @@ -28,8 +28,7 @@ pub struct Inner { } impl Inner { pub fn constructor_1(this: Ptr) { - field!(this, x).write(3); - field!(this, y).write(4); + this.write(::default()); } } impl Default for Inner { @@ -67,20 +66,8 @@ impl S { pub fn constructor_1(this: Ptr) { field!(this, a).write(1); field!(this, b).write(2_i8); - field!(this, c).write(::default()); - Inner::constructor_1(field_ptr!(this, d)); - } -} -impl Default for S { - fn default() -> Self { - { - S { - a: 1, - b: 2_i8, - c: ::default(), - d: ::default(), - } - } + field!(this, c).write(Inner { x: 3, y: 4 }); + field!(this, d).write(::default()); } } #[derive( @@ -110,11 +97,6 @@ impl Boxed_int_ { field!(this, tag).write(t); } } -impl Default for Boxed_int_ { - fn default() -> Self { - { ::zero_init() } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/init.rs b/tests/unit/out/refcount/init.rs index 89b82c13f4..b95c246b56 100644 --- a/tests/unit/out/refcount/init.rs +++ b/tests/unit/out/refcount/init.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/init_list.rs b/tests/unit/out/refcount/init_list.rs index 0e4e1e348d..0d74dc458b 100644 --- a/tests/unit/out/refcount/init_list.rs +++ b/tests/unit/out/refcount/init_list.rs @@ -19,7 +19,6 @@ pub fn f_0(list: Vec) { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -58,15 +57,6 @@ impl Holder { field!(this, p).write(Pair { a: 0, b: 0 }); } } -impl Default for Holder { - fn default() -> Self { - { - Holder { - p: Pair { a: 0, b: 0 }, - } - } - } -} pub fn sum_1(p: Ptr) -> i32 { return ({ p.with(|__s| __s.a) } + { p.with(|__s| __s.b) }); } @@ -90,7 +80,7 @@ pub struct Seven { } impl Seven { pub fn constructor_1(this: Ptr) { - field!(this, v).write(7); + this.write(::default()); } } impl Default for Seven { @@ -115,7 +105,7 @@ fn main_0() -> i32 { Holder::operator_assign_1(h.as_pointer(), p.as_pointer()); assert!(({ (*h.borrow()).p.a } == 1) && ({ (*h.borrow()).p.b } == 2)); assert!((({ sum_1(p.as_pointer(),) }) == 3)); - let mut sevens: [Seven; 4] = [::default(); 4]; + let mut sevens: [Seven; 4] = [Seven { v: 7 }; 4]; { let mut i: i32 = 0; 'loop_: while (i < 4) { diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 2fe567d0e7..e5d44f3ca6 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -36,9 +36,7 @@ pub struct Elem { } impl Elem { pub fn constructor_1(this: Ptr) { - field!(this, id).write(0_i32); - field!(this, hist).write((0..4).map(|_| 0_i32).collect::>()); - field!(this, coeffs).write(Vec::new()); + this.write(::default()); } } impl Default for Elem { @@ -47,7 +45,7 @@ impl Default for Elem { Elem { id: 0_i32, hist: (0..4).map(|_| 0_i32).collect::>(), - coeffs: Default::default(), + coeffs: Vec::new(), } } } @@ -89,17 +87,7 @@ pub struct State { } impl State { pub fn constructor_1(this: Ptr) { - field!(this, count).write(0_i32); - field!(this, grid).write( - (0..2) - .map(|_| (0..3).map(|_| 0_i32).collect::>()) - .collect::]>>(), - ); - field!(this, arr).write(Box::<[i32]>::from(std::array::from_fn::<_, 3, _>(|_| { - 0_i32 - }))); - field!(this, elems).write(Vec::new()); - field!(this, rows).write(Vec::new()); + this.write(::default()); } } impl Default for State { @@ -111,8 +99,8 @@ impl Default for State { .map(|_| (0..3).map(|_| 0_i32).collect::>()) .collect::]>>(), arr: Box::<[i32]>::from(std::array::from_fn::<_, 3, _>(|_| 0_i32)), - elems: Default::default(), - rows: Default::default(), + elems: Vec::new(), + rows: Vec::new(), } } } @@ -149,7 +137,8 @@ pub fn fill_1(mut s: Ptr) { } } elem!(field_ref!(s, arr).decay(), 1_usize).write(7); - field!(s, elems).with_mut(|__v: &mut Vec| __v.resize_with(3_usize, || ::default())); + field!(s, elems) + .with_mut(|__v: &mut Vec| __v.resize_with(3_usize, || ::default_constructed())); { let mut i: i32 = 0; 'loop_: while (i < 3) { @@ -200,7 +189,7 @@ pub struct Counted { } impl Counted { pub fn constructor_1(this: Ptr) { - field!(this, v).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); @@ -241,7 +230,15 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let s: Value = Rc::new(RefCell::new(::default())); + let s: Value = Rc::new(RefCell::new(State { + count: 0_i32, + grid: (0..2) + .map(|_| (0..3).map(|_| 0_i32).collect::>()) + .collect::]>>(), + arr: Box::<[i32]>::from(std::array::from_fn::<_, 3, _>(|_| 0_i32)), + elems: Vec::new(), + rows: Vec::new(), + })); ({ fill_1((s.as_pointer())) }); assert!( ({ @@ -341,8 +338,9 @@ fn main_0() -> i32 { && ((index!(field!(vec_elem!(p, elems, 3_usize), hist), 0).read()) == 100) }) ); - let elems: Value> = - Rc::new(RefCell::new(Vec::from_fn(2_usize, |_| ::default()))); + let elems: Value> = Rc::new(RefCell::new(Vec::from_fn(2_usize, |_| { + ::default_constructed() + }))); let mut first: Ptr = (elems.decay().offset(0_usize)); (*elems.borrow_mut())[1_usize] .coeffs @@ -376,7 +374,15 @@ fn main_0() -> i32 { ((elem!(field_ref!(moved.as_pointer(), arr).decay(), 1_usize).read()) == 7) && ((elem!(field_ref!(t.as_pointer(), arr).decay(), 1_usize).read()) == 7) ); - let assigned: Value = Rc::new(RefCell::new(::default())); + let assigned: Value = Rc::new(RefCell::new(State { + count: 0_i32, + grid: (0..2) + .map(|_| (0..3).map(|_| 0_i32).collect::>()) + .collect::]>>(), + arr: Box::<[i32]>::from(std::array::from_fn::<_, 3, _>(|_| 0_i32)), + elems: Vec::new(), + rows: Vec::new(), + })); assign!(assigned = RvalueRef(moved)); assert!( ({ @@ -405,7 +411,7 @@ fn main_0() -> i32 { 3, _, >(|_| { - ::default() + ::default_constructed() })))); (*ca.borrow_mut())[1_usize].v = 5; let cb: Value> = Rc::new(RefCell::new({ diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index 0c2b885a5c..e524ba4cb9 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -112,9 +111,7 @@ pub fn quicksort_1(arr: Ptr>>>, mut start: i32, mut end ({ quicksort_1((arr).clone(), start, (p - 1)) }); ({ quicksort_1((arr).clone(), (p + 1), end) }); } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] @@ -233,14 +230,21 @@ impl DisjointSet { } } pub fn constructor_1(this: Ptr) { - field!(this, rank).write(None); - field!(this, parent).write(None); - field!(this, n).write(0_i32); + this.write(::default()); } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +impl Default for DisjointSet { + fn default() -> Self { + { + DisjointSet { + rank: None, + parent: None, + n: 0_i32, + } + } + } +} +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] @@ -257,9 +261,18 @@ pub struct Graph { } impl Graph { pub fn constructor_1(this: Ptr) { - field!(this, edges).write(None); - field!(this, V).write(0_i32); - field!(this, E).write(0_i32); + this.write(::default()); + } +} +impl Default for Graph { + fn default() -> Self { + { + Graph { + edges: None, + V: 0_i32, + E: 0_i32, + } + } } } pub fn MSTKruskal_2(graph: Ptr) -> f64 { diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index 55c942e682..a967cd5079 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -81,20 +81,6 @@ impl Holder__lambda_at_lambda_as_field_cpp_39_12__ { return ({ (*this.upgrade().deref()).f.call(x) }); } } -impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { - fn default() -> Self { - { - Holder__lambda_at_lambda_as_field_cpp_39_12__ { - f: FnPtr:: i32>::new(|mut x: i32| -> i32 { - { - return (x + 1); - } - }), - calls: 0_i32, - } - } - } -} #[derive( Clone, Record, @@ -104,7 +90,6 @@ impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -148,11 +133,6 @@ impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { field!(this, moves).write((o.with(|__s| __s.moves) + 1)); } } -impl Default for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn default() -> Self { - { ::zero_init() } - } -} pub fn wrap_0(fn_: FnPtr i32>) -> FnPtr i32> { let fn_: Value i32>> = Rc::new(RefCell::new(fn_)); return lambda!( diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 8fc8d569db..f163582bc1 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -20,8 +20,7 @@ pub struct Counted { } impl Counted { pub fn constructor_1(this: Ptr) { - field!(this, copies).write(0); - field!(this, moves).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); @@ -37,10 +36,9 @@ impl Counted { impl Default for Counted { fn default() -> Self { { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Counted::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() + Counted { + copies: 0, + moves: 0, } } } @@ -56,7 +54,9 @@ thread_local!( #[byte_size(1)] pub struct Dropped {} impl Dropped { - pub fn constructor_1(this: Ptr) {} + pub fn constructor_1(this: Ptr) { + this.write(::default()); + } pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); } @@ -69,12 +69,17 @@ impl Destructible for Dropped { (*drops_0.with(Value::clone).borrow_mut()).postfix_inc(); } } +impl Default for Dropped { + fn default() -> Self { + { Dropped {} } + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(c, Counted::constructor_1()); + let c: Value = Rc::new(RefCell::new(::default())); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let c: Value = Rc::new(RefCell::new({ @@ -121,13 +126,11 @@ fn main_0() -> i32 { .with(|__s| __s.copies) }; assert!((returned == 2)); - let arr: Value> = Rc::new(RefCell::new(Box::new( - std::array::from_fn::<_, 2, _>(|_| { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Counted::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }), - ))); + let arr: Value> = Rc::new(RefCell::new( + (0..2) + .map(|_| ::default()) + .collect::>(), + )); let a: Value i32>> = Rc::new(RefCell::new(lambda!( { let arr: Value> = Rc::new(RefCell::new(Box::new( @@ -156,12 +159,7 @@ fn main_0() -> i32 { { let m: Value> = Rc::new(RefCell::new(lambda!( { - let d: Value = Rc::new(RefCell::new({ - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Dropped::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let d: Value = Rc::new(RefCell::new(::default())); }, || {} ))); @@ -175,12 +173,7 @@ fn main_0() -> i32 { { let k: Value> = Rc::new(RefCell::new(lambda!( { - let d: Value = Rc::new(RefCell::new({ - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Dropped::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let d: Value = Rc::new(RefCell::new(::default())); }, || {} ))); @@ -194,12 +187,7 @@ fn main_0() -> i32 { { let inner: Value> = Rc::new(RefCell::new(lambda!( { - let d: Value = Rc::new(RefCell::new({ - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Dropped::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let d: Value = Rc::new(RefCell::new(::default())); }, || {} ))); diff --git a/tests/unit/out/refcount/lambda_capture_ref.rs b/tests/unit/out/refcount/lambda_capture_ref.rs index 6a13250210..97d230b176 100644 --- a/tests/unit/out/refcount/lambda_capture_ref.rs +++ b/tests/unit/out/refcount/lambda_capture_ref.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/lambda_capture_star_this.rs b/tests/unit/out/refcount/lambda_capture_star_this.rs index 5f0cc56787..8402f8fe78 100644 --- a/tests/unit/out/refcount/lambda_capture_star_this.rs +++ b/tests/unit/out/refcount/lambda_capture_star_this.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/lambda_capture_this.rs b/tests/unit/out/refcount/lambda_capture_this.rs index 44e5c89ccd..c559455ffa 100644 --- a/tests/unit/out/refcount/lambda_capture_this.rs +++ b/tests/unit/out/refcount/lambda_capture_this.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/lambda_capture_value.rs b/tests/unit/out/refcount/lambda_capture_value.rs index b0a6c97a82..3a348bd34c 100644 --- a/tests/unit/out/refcount/lambda_capture_value.rs +++ b/tests/unit/out/refcount/lambda_capture_value.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/lambda_decltype_type.rs b/tests/unit/out/refcount/lambda_decltype_type.rs index 8ff9412094..20d6eb10da 100644 --- a/tests/unit/out/refcount/lambda_decltype_type.rs +++ b/tests/unit/out/refcount/lambda_decltype_type.rs @@ -40,15 +40,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { field!(this, size).with_mut(|__v| __v.postfix_inc()); } pub fn constructor_1(this: Ptr) { - field!(this, items).write((0..4).map(|_| 0_i32).collect::>()); - field!(this, size).write(0); - field!(this, cmp).write(FnPtr:: bool>::new( - |mut a: i32, mut b: i32| -> bool { - { - return (a > b); - } - }, - )); + this.write(::default()); } } impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { @@ -100,15 +92,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { field!(this, size).with_mut(|__v| __v.postfix_inc()); } pub fn constructor_1(this: Ptr) { - field!(this, items).write((0..4).map(|_| 0_i32).collect::>()); - field!(this, size).write(0); - field!(this, cmp).write(FnPtr:: bool>::new( - |mut a: i32, mut b: i32| -> bool { - { - return (a < b); - } - }, - )); + this.write(::default()); } } impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { @@ -139,20 +123,18 @@ fn main_0() -> i32 { } }, ))); - object!( - desc, - Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::constructor_1() - ); + let desc: Value = Rc::new(RefCell::new( + ::default(), + )); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 2) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 7) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 4) }); assert!(((array_elem!(desc.as_pointer(), items, 0).read()) == 7)); assert!(((array_elem!(desc.as_pointer(), items, 1).read()) == 4)); assert!(((array_elem!(desc.as_pointer(), items, 2).read()) == 2)); - object!( - asc, - Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::constructor_1() - ); + let asc: Value = Rc::new(RefCell::new( + ::default(), + )); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 2) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 7) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 4) }); diff --git a/tests/unit/out/refcount/lambda_generic_explicit_args.rs b/tests/unit/out/refcount/lambda_generic_explicit_args.rs index 5d81e380fc..f3c5bb8648 100644 --- a/tests/unit/out/refcount/lambda_generic_explicit_args.rs +++ b/tests/unit/out/refcount/lambda_generic_explicit_args.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/lambda_immediate_init.rs b/tests/unit/out/refcount/lambda_immediate_init.rs index 45d71a6fd0..1a242de822 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -31,17 +31,7 @@ pub struct S { } impl S { pub fn constructor_1(this: Ptr) { - field!(this, j).write(10); - field!(this, k).write( - (({ - FnPtr:: i32>::new(|| -> i32 { - { - return 3; - } - }) - .call() - }) + 1), - ); + this.write(::default()); } } impl Default for S { @@ -103,8 +93,8 @@ fn main_0() -> i32 { }) == 237) ); assert!((({ pick_0(1,) }) == 1)); - object!(s, S::constructor_1()); - assert!(({ (*s.borrow()).k } == 4)); + let mut s: S = ::default(); + assert!((s.k == 4)); assert!((g_1.with(|rc| *rc.borrow()) == 10)); let a: Value = Rc::new(RefCell::new(2)); let mut c: i32 = ({ diff --git a/tests/unit/out/refcount/lambda_nested.rs b/tests/unit/out/refcount/lambda_nested.rs index c10784772e..50183168d1 100644 --- a/tests/unit/out/refcount/lambda_nested.rs +++ b/tests/unit/out/refcount/lambda_nested.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/lambda_static_local.rs b/tests/unit/out/refcount/lambda_static_local.rs index 32edd6b930..e2ab3f0fed 100644 --- a/tests/unit/out/refcount/lambda_static_local.rs +++ b/tests/unit/out/refcount/lambda_static_local.rs @@ -88,7 +88,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index cbe1a2dcb5..b2df0db18e 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -34,10 +34,7 @@ pub struct UserDefined { } impl UserDefined { pub fn constructor_1(this: Ptr) { - field!(this, a).write(Box::<[i32]>::from(std::array::from_fn::<_, 1, _>(|_| { - 0_i32 - }))); - field!(this, v).write(Vec::new()); + this.write(::default()); } } impl Default for UserDefined { @@ -45,7 +42,7 @@ impl Default for UserDefined { { UserDefined { a: Box::<[i32]>::from(std::array::from_fn::<_, 1, _>(|_| 0_i32)), - v: Default::default(), + v: Vec::new(), } } } @@ -68,15 +65,6 @@ pub struct FieldIsLibcType { #[byte_size(16)] pub addr: libcc2rs::Sockaddr, } -impl Default for FieldIsLibcType { - fn default() -> Self { - { - FieldIsLibcType { - addr: Default::default(), - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -102,7 +90,7 @@ fn main_0() -> i32 { let st: Value = Rc::new(RefCell::new(Default::default())); (*st.borrow_mut()).st_size = (1024 as ::libc::off_t); assert!(({ (*st.borrow()).st_size } == (1024 as ::libc::off_t))); - object!(ud, UserDefined::constructor_1()); + let ud: Value = Rc::new(RefCell::new(::default())); elem!(field_ref!(ud.as_pointer(), a).decay(), 0_usize).write(3); assert!(((elem!(field_ref!(ud.as_pointer(), a).decay(), 0_usize).read()) == 3)); assert!(({ ((*ud.borrow()).v.len() == 0_usize) })); diff --git a/tests/unit/out/refcount/linked_list.rs b/tests/unit/out/refcount/linked_list.rs index 14eb33d736..bc50932410 100644 --- a/tests/unit/out/refcount/linked_list.rs +++ b/tests/unit/out/refcount/linked_list.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/local_anon_struct_collision.rs b/tests/unit/out/refcount/local_anon_struct_collision.rs index 54d8b3a425..72b6b3bdbd 100644 --- a/tests/unit/out/refcount/local_anon_struct_collision.rs +++ b/tests/unit/out/refcount/local_anon_struct_collision.rs @@ -22,7 +22,6 @@ pub fn first_0() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct anon_1 { @@ -47,7 +46,6 @@ pub fn second_2() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct anon_3 { diff --git a/tests/unit/out/refcount/local_record_template.rs b/tests/unit/out/refcount/local_record_template.rs index 2b72bcbf2f..f9764429ec 100644 --- a/tests/unit/out/refcount/local_record_template.rs +++ b/tests/unit/out/refcount/local_record_template.rs @@ -39,7 +39,6 @@ pub fn wrap_10(mut v: i64) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -58,7 +57,6 @@ pub struct Local_5 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -81,7 +79,6 @@ pub fn other_11() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -115,7 +112,6 @@ fn main_0() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index d4c16f8bde..c72268722a 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -38,8 +38,7 @@ pub struct Point { } impl Point { pub fn constructor_1(this: Ptr) { - field!(this, x).write(0); - field!(this, y).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, mut x: i32, mut y: i32) { field!(this, x).write(x); @@ -48,13 +47,7 @@ impl Point { } impl Default for Point { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Point::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { Point { x: 0, y: 0 } } } } pub fn main() { @@ -847,7 +840,7 @@ fn main_0() -> i32 { (*points.borrow_mut()).subscript_move( __tmp_65, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -862,7 +855,7 @@ fn main_0() -> i32 { (*points.borrow_mut()).subscript_move( __tmp_66, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -895,7 +888,7 @@ fn main_0() -> i32 { (*points.borrow_mut()).subscript_move( __tmp_68, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -910,7 +903,7 @@ fn main_0() -> i32 { (*points.borrow_mut()).subscript_move( __tmp_69, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index c8c3306cea..b228f0378c 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -15,9 +15,7 @@ thread_local!( thread_local!( pub static made_2: Value = Rc::new(RefCell::new(0)); ); -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index 9140286dc0..de80a5991a 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -19,7 +19,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -59,17 +58,6 @@ impl Mapped { (*default_constructions_0.with(Value::clone).borrow_mut()).prefix_inc(); } } -impl Default for Mapped { - fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Mapped::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -93,8 +81,10 @@ fn main_0() -> i32 { != 0 }; let distinct: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - let a: Ptr = - ({ (*distinct.borrow_mut()).subscript(distinct_a.as_pointer(), || ::default()) }); + let a: Ptr = ({ + (*distinct.borrow_mut()) + .subscript(distinct_a.as_pointer(), || ::default_constructed()) + }); field!(a, value).write(11); let a_it: Value, Value)>> = Rc::new(RefCell::new(distinct.as_pointer().with( @@ -104,8 +94,10 @@ fn main_0() -> i32 { .1 .as_pointer()); ok = { ((ok as i32) & ((default_constructions_0.with(|rc| *rc.borrow()) == 1) as i32)) != 0 }; - let b: Ptr = - ({ (*distinct.borrow_mut()).subscript(distinct_b.as_pointer(), || ::default()) }); + let b: Ptr = ({ + (*distinct.borrow_mut()) + .subscript(distinct_b.as_pointer(), || ::default_constructed()) + }); field!(b, value).write(22); let b_it: Value, Value)>> = Rc::new(RefCell::new(distinct.as_pointer().with( @@ -235,7 +227,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(Map::new())); let mut before_equivalent: i32 = default_constructions_0.with(|rc| *rc.borrow()); let first: Ptr = ({ - (*equivalent.borrow_mut()).subscript(equivalent_a.as_pointer(), || ::default()) + (*equivalent.borrow_mut()).subscript(equivalent_a.as_pointer(), || { + ::default_constructed() + }) }); field!(first, value).write(31); let first_it: Value, Value)>> = @@ -252,7 +246,9 @@ fn main_0() -> i32 { != 0 }; let second: Ptr = ({ - (*equivalent.borrow_mut()).subscript(equivalent_b.as_pointer(), || ::default()) + (*equivalent.borrow_mut()).subscript(equivalent_b.as_pointer(), || { + ::default_constructed() + }) }); let mut reused: bool = (default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 1)); @@ -359,8 +355,10 @@ fn main_0() -> i32 { order: 4, identity: 10, })); - let later: Ptr = - ({ (*equivalent.borrow_mut()).subscript(later_key.as_pointer(), || ::default()) }); + let later: Ptr = ({ + (*equivalent.borrow_mut()) + .subscript(later_key.as_pointer(), || ::default_constructed()) + }); field!(later, value).write(41); ok = { ((ok as i32) @@ -415,8 +413,10 @@ fn main_0() -> i32 { })); let mut before_matching: i32 = default_constructions_0.with(|rc| *rc.borrow()); let matching: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - let matched: Ptr = - ({ (*matching.borrow_mut()).subscript(matching_a.as_pointer(), || ::default()) }); + let matched: Ptr = ({ + (*matching.borrow_mut()) + .subscript(matching_a.as_pointer(), || ::default_constructed()) + }); field!(matched, value).write(51); let matched_it: Value, Value)>> = Rc::new(RefCell::new(matching.as_pointer().with( @@ -431,8 +431,10 @@ fn main_0() -> i32 { & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32)) != 0 }; - let matched_again: Ptr = - ({ (*matching.borrow_mut()).subscript(matching_b.as_pointer(), || ::default()) }); + let matched_again: Ptr = ({ + (*matching.borrow_mut()) + .subscript(matching_b.as_pointer(), || ::default_constructed()) + }); ok = { ((ok as i32) & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32)) @@ -468,8 +470,10 @@ fn main_0() -> i32 { as i32)) != 0 }; - let other: Ptr = - ({ (*matching.borrow_mut()).subscript(matching_c.as_pointer(), || ::default()) }); + let other: Ptr = ({ + (*matching.borrow_mut()) + .subscript(matching_c.as_pointer(), || ::default_constructed()) + }); field!(other, value).write(61); ok = { ((ok as i32) diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 9d4c95638a..bf6fd867e1 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -31,7 +31,7 @@ pub struct Item { } impl Item { pub fn constructor_1(this: Ptr) { - field!(this, value).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, mut value: i32) { field!(this, value).write(value); @@ -51,13 +51,7 @@ impl Item { } impl Default for Item { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Item::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { Item { value: 0 } } } } pub fn argument_4(item: Ptr) -> Ptr { @@ -85,7 +79,7 @@ pub struct RefItem { } impl RefItem { pub fn constructor_1(this: Ptr) { - field!(this, value).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, counter: LvalueRef, mut amount: i32) { let counter = counter.as_pointer(); @@ -100,13 +94,7 @@ impl RefItem { } impl Default for RefItem { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - RefItem::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { RefItem { value: 0 } } } } pub fn reference_5(counter: Ptr) -> Ptr { diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index 9ee23c4dd4..c544e2e8b5 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -33,7 +33,7 @@ pub struct Item { } impl Item { pub fn constructor_1(this: Ptr) { - field!(this, value).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, counter: LvalueRef, mut amount: i32) { let counter = counter.as_pointer(); @@ -48,13 +48,7 @@ impl Item { } impl Default for Item { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Item::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { Item { value: 0 } } } } pub fn receiver_2( @@ -91,27 +85,8 @@ impl Temporary { (*temporary_calls_4.with(Value::clone).borrow_mut()).prefix_inc(); } } -impl Default for Temporary { - fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Temporary::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} #[derive( - Clone, - Record, - ByteRepr, - ZeroInitialization, - VaArg, - FnPtrArg, - TriviallyCopyable, - Default, - Conversions, + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] #[conversions(copy, move)] #[constructor(constructor_1)] @@ -153,11 +128,7 @@ pub struct Owner { } impl Owner { pub fn constructor_1(this: Ptr) { - field!(this, ptr).write(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Temporary::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })))); + this.write(::default()); } pub fn value(this: Ptr) -> Ptr { return field_ptr!(this.with(|__s| __s.ptr.clone()).as_pointer(), n); @@ -166,10 +137,13 @@ impl Owner { impl Default for Owner { fn default() -> Self { { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Owner::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() + Owner { + ptr: Some(Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))), } } } @@ -183,7 +157,7 @@ pub struct Noncopy { } impl Noncopy { pub fn constructor_1(this: Ptr) { - field!(this, n).write(5); + this.write(::default()); } } impl Default for Noncopy { @@ -205,7 +179,7 @@ pub struct Held { } impl Held { pub fn constructor_1(this: Ptr) { - field!(this, ptr).write(Ptr::::null()); + this.write(::default()); } pub fn constructor_2(this: Ptr, n: LvalueRef>) { let n = n.as_pointer(); @@ -218,10 +192,8 @@ impl Held { impl Default for Held { fn default() -> Self { { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Held::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() + Held { + ptr: Ptr::::null(), } } } @@ -1302,7 +1274,9 @@ fn main_0() -> i32 { field!( ({ (*selected.borrow_mut()) - .subscript(k.as_pointer(), || ::default()) + .subscript(k.as_pointer(), || { + ::default_constructed() + }) }), value ) @@ -1798,7 +1772,9 @@ fn main_0() -> i32 { }; value = (({ (*references.borrow_mut()) - .subscript(key.as_pointer(), || ::default()) + .subscript(key.as_pointer(), || { + ::default_constructed() + }) }) .with(|__s| __s.ptr.clone()) .read()) @@ -1910,7 +1886,9 @@ fn main_0() -> i32 { value = (elem!( ({ (*arrays.borrow_mut()) - .subscript(key.as_pointer(), || ::default()) + .subscript(key.as_pointer(), || { + ::default_constructed() + }) }) .with(|__s| __s.ptr.clone()), 1 @@ -2311,7 +2289,9 @@ fn main_0() -> i32 { }; value = (({ (*references.borrow_mut()) - .subscript(key.as_pointer(), || ::default()) + .subscript(key.as_pointer(), || { + ::default_constructed() + }) }) .with(|__s| __s.ptr.clone()) .read()) @@ -2332,12 +2312,11 @@ fn main_0() -> i32 { let owners: Value, Value)>> = Rc::new(RefCell::new(Map::new())); { - let __tmp_109: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); + let __tmp_109: Value; { match (({ Owner::value({ - Owner::constructor_1(__tmp_109.as_pointer()); + __tmp_109 = Rc::new(RefCell::new(::default())); __tmp_109.as_pointer() }) }),) @@ -2377,8 +2356,9 @@ fn main_0() -> i32 { } }; value = (({ - (*owners.borrow_mut()) - .subscript(key.as_pointer(), || ::default()) + (*owners.borrow_mut()).subscript(key.as_pointer(), || { + ::default_constructed() + }) }) .with(|__s| __s.ptr.clone()) .read()) @@ -2413,11 +2393,9 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new({ let __tmp_111: Value>>; match ({ - __tmp_111 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Noncopy::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }))))); + __tmp_111 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( + ::default(), + ))))); __tmp_111.as_pointer() },) { @@ -2453,11 +2431,9 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new({ let __tmp_113: Value>>; match ({ - __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Noncopy::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }))))); + __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( + ::default(), + ))))); __tmp_113.as_pointer() },) { diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index 754e499b86..a1e7e29170 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -30,7 +30,6 @@ pub fn pick_3(mut i: i32) -> Ptr { MoveConstructible, MoveAssignable, Swappable, - Default, )] #[memberwise(copy_assign)] #[derive(Conversions)] diff --git a/tests/unit/out/refcount/memcpy_struct_bytes.rs b/tests/unit/out/refcount/memcpy_struct_bytes.rs index f4bfdf8820..cb7b6f9be8 100644 --- a/tests/unit/out/refcount/memcpy_struct_bytes.rs +++ b/tests/unit/out/refcount/memcpy_struct_bytes.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct point { diff --git a/tests/unit/out/refcount/memcpy_struct_layouts.rs b/tests/unit/out/refcount/memcpy_struct_layouts.rs index 79f7c8cd1a..113c244176 100644 --- a/tests/unit/out/refcount/memcpy_struct_layouts.rs +++ b/tests/unit/out/refcount/memcpy_struct_layouts.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct packed { @@ -39,7 +38,6 @@ pub struct packed { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(12)] pub struct reordered { @@ -60,7 +58,6 @@ pub struct reordered { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct tail { @@ -79,7 +76,6 @@ pub struct tail { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(24)] pub struct nested { @@ -108,16 +104,6 @@ pub struct array { #[offset(4)] pub x: i32, } -impl Default for array { - fn default() -> Self { - { - array { - name: (0..3).map(|_| 0_i8).collect::>(), - x: 0_i32, - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/memcpy_struct_struct.rs b/tests/unit/out/refcount/memcpy_struct_struct.rs index 9481df496d..448a83e2bf 100644 --- a/tests/unit/out/refcount/memcpy_struct_struct.rs +++ b/tests/unit/out/refcount/memcpy_struct_struct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/memset_struct_tail.rs b/tests/unit/out/refcount/memset_struct_tail.rs index 9debd268ff..f869742279 100644 --- a/tests/unit/out/refcount/memset_struct_tail.rs +++ b/tests/unit/out/refcount/memset_struct_tail.rs @@ -31,19 +31,6 @@ pub struct S { #[offset(24)] pub last: i32, } -impl Default for S { - fn default() -> Self { - { - S { - keep: 0_i32, - a: 0_i32, - b: 0_i64, - c: (0..5).map(|_| 0_i8).collect::>(), - last: 0_i32, - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index b091e740be..9bcaaf667e 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -7,14 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - DefaultInitializable, - Swappable, - Default, - Conversions, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Swappable, Conversions, )] #[conversions(move)] #[constructor(constructor_1, i32)] @@ -54,7 +47,7 @@ pub struct ConstMoveAssign { } impl ConstMoveAssign { pub fn constructor_1(this: Ptr) { - field!(this, mark).write(0); + this.write(::default()); } pub fn operator_assign_2(this: Ptr, o: Ptr) -> Ptr { field!(this, mark).write((o.with(|__s| __s.mark) + 1)); @@ -67,14 +60,7 @@ impl ConstMoveAssign { } impl Default for ConstMoveAssign { fn default() -> Self { - { - { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - ConstMoveAssign::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { ConstMoveAssign { mark: 0 } } } } pub fn make_0(__return: Ptr, mut v: i32) { @@ -131,10 +117,10 @@ fn main_0() -> i32 { assign!(*vec_.decay().offset(0_usize) = RvalueRef(d)); assert!(({ (*vec_.borrow())[0_usize].v } == 8)); assert!(({ (*d.borrow()).v } == 0)); - object!(m, ConstMoveAssign::constructor_1()); - object!(m1, ConstMoveAssign::constructor_1()); - object!(m2, ConstMoveAssign::constructor_1()); - object!(cm, ConstMoveAssign::constructor_1()); + let m: Value = Rc::new(RefCell::new(::default())); + let m1: Value = Rc::new(RefCell::new(::default())); + let m2: Value = Rc::new(RefCell::new(::default())); + let cm: Value = Rc::new(RefCell::new(::default())); ConstMoveAssign::operator_assign_2(m1.as_pointer(), m.as_pointer()); ConstMoveAssign::operator_assign_3(m2.as_pointer(), cm.as_pointer()); assert!(({ (*m1.borrow()).mark } == 1)); diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index d1b1faf1c4..b815204354 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -6,9 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(move)] #[constructor(constructor_1, i32)] #[constructor(constructor_3, RvalueRef)] @@ -39,7 +37,7 @@ pub struct ConstMove { } impl ConstMove { pub fn constructor_1(this: Ptr) { - field!(this, mark).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); @@ -52,18 +50,10 @@ impl ConstMove { } impl Default for ConstMove { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - ConstMove::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { ConstMove { mark: 0 } } } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] @@ -97,9 +87,7 @@ impl ThrowingMove { field!(o, v).write(0); } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] @@ -189,12 +177,12 @@ fn main_0() -> i32 { MoveConstructible::push_moved(&vec_.as_pointer(), f.as_pointer()); assert!(({ (*vec_.borrow())[0_usize].v } == 7) && ({ (*vec_.borrow())[1_usize].v } == 8)); assert!(({ (*f.borrow()).v } == 0)); - object!(m, ConstMove::constructor_1()); + let m: Value = Rc::new(RefCell::new(::default())); object!( m1, ConstMove::constructor_2(RvalueRef::bind(m.as_pointer())) ); - object!(cm, ConstMove::constructor_1()); + let cm: Value = Rc::new(RefCell::new(::default())); object!( m2, ConstMove::constructor_3(RvalueRef::bind(cm.as_pointer())) diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index a3f1965027..ba6056f2f2 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -6,9 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] diff --git a/tests/unit/out/refcount/nested_structs.rs b/tests/unit/out/refcount/nested_structs.rs index ba856f8057..f1b873d673 100644 --- a/tests/unit/out/refcount/nested_structs.rs +++ b/tests/unit/out/refcount/nested_structs.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -35,7 +34,6 @@ pub struct Level0_Level1_1_Level2_1_Level3_1 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -56,7 +54,6 @@ pub struct Level0_Level1_1_Level2_1_Level3_2 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -75,7 +72,6 @@ pub struct Level0_Level1_1_Level2_1 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -94,7 +90,6 @@ pub struct Level0_Level1_1 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -115,7 +110,6 @@ pub struct Level0_Level1_2 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/new.rs b/tests/unit/out/refcount/new.rs index 70b58d0ede..ffceefaded 100644 --- a/tests/unit/out/refcount/new.rs +++ b/tests/unit/out/refcount/new.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/new_bst.rs b/tests/unit/out/refcount/new_bst.rs index 912c97f12f..641a161204 100644 --- a/tests/unit/out/refcount/new_bst.rs +++ b/tests/unit/out/refcount/new_bst.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/new_struct.rs b/tests/unit/out/refcount/new_struct.rs index 500d0aa66f..b25e2d9da2 100644 --- a/tests/unit/out/refcount/new_struct.rs +++ b/tests/unit/out/refcount/new_struct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ pub struct Pair { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/nttp_distinct_specializations.rs b/tests/unit/out/refcount/nttp_distinct_specializations.rs index 0aff173c99..b3c2c6a327 100644 --- a/tests/unit/out/refcount/nttp_distinct_specializations.rs +++ b/tests/unit/out/refcount/nttp_distinct_specializations.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -42,7 +41,6 @@ impl S_2_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -66,7 +64,6 @@ impl S_1_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/offsetof.rs b/tests/unit/out/refcount/offsetof.rs index a3be2b5e09..d4ef992d55 100644 --- a/tests/unit/out/refcount/offsetof.rs +++ b/tests/unit/out/refcount/offsetof.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -50,16 +49,6 @@ pub struct Frame { #[array_len(64)] pub body: Box<[i8]>, } -impl Default for Frame { - fn default() -> Self { - { - Frame { - tag: 0_u16, - body: (0..64).map(|_| 0_i8).collect::>(), - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/opaque_forward_decl.rs b/tests/unit/out/refcount/opaque_forward_decl.rs index c253a00c35..a10e21a25a 100644 --- a/tests/unit/out/refcount/opaque_forward_decl.rs +++ b/tests/unit/out/refcount/opaque_forward_decl.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct container { diff --git a/tests/unit/out/refcount/opaque_record_copy.rs b/tests/unit/out/refcount/opaque_record_copy.rs index dd60c43296..6e058b2071 100644 --- a/tests/unit/out/refcount/opaque_record_copy.rs +++ b/tests/unit/out/refcount/opaque_record_copy.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct Probe {} FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/opaque_then_defined.rs b/tests/unit/out/refcount/opaque_then_defined.rs index 6d8dc545f9..c3a2d644b9 100644 --- a/tests/unit/out/refcount/opaque_then_defined.rs +++ b/tests/unit/out/refcount/opaque_then_defined.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct list { @@ -34,7 +33,6 @@ pub struct list { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct node { diff --git a/tests/unit/out/refcount/operator_arithmetic_free.rs b/tests/unit/out/refcount/operator_arithmetic_free.rs index fbfe6b0329..2e55f348ab 100644 --- a/tests/unit/out/refcount/operator_arithmetic_free.rs +++ b/tests/unit/out/refcount/operator_arithmetic_free.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_arithmetic_member.rs b/tests/unit/out/refcount/operator_arithmetic_member.rs index 8b8915f4cb..4e345c2220 100644 --- a/tests/unit/out/refcount/operator_arithmetic_member.rs +++ b/tests/unit/out/refcount/operator_arithmetic_member.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_bitwise_free.rs b/tests/unit/out/refcount/operator_bitwise_free.rs index 27a0128cfa..3581534ced 100644 --- a/tests/unit/out/refcount/operator_bitwise_free.rs +++ b/tests/unit/out/refcount/operator_bitwise_free.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_bitwise_member.rs b/tests/unit/out/refcount/operator_bitwise_member.rs index b2177ac0fb..8c74256471 100644 --- a/tests/unit/out/refcount/operator_bitwise_member.rs +++ b/tests/unit/out/refcount/operator_bitwise_member.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index 5a2c77a088..d4d1a4cd70 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ pub struct Eq { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -89,7 +87,6 @@ impl LessThanComparable for Cmp { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -130,7 +127,6 @@ impl LessThanComparable for Both { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(OrdOnly::operator_cmp)] @@ -170,7 +166,6 @@ impl LessThanComparable for OrdOnly { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -211,7 +206,6 @@ impl LessThanComparable for Inner { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -263,7 +257,6 @@ impl LessThanComparable for Outer { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -301,7 +294,6 @@ impl LessThanComparable for Secondary { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index 8601f21645..8ff3420b92 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -46,7 +45,6 @@ pub fn operator_lt_1(mut a: i32, b: Ptr) -> bool { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index acadd8cc62..7183aa9e73 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_comparison_mixed.rs b/tests/unit/out/refcount/operator_comparison_mixed.rs index 76333aa36a..d5387bb116 100644 --- a/tests/unit/out/refcount/operator_comparison_mixed.rs +++ b/tests/unit/out/refcount/operator_comparison_mixed.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index fe5d82ba36..6549c0c2f9 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -58,7 +57,6 @@ pub fn operator_ge_3(mut a: X, mut b: X) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -77,7 +75,6 @@ pub struct Result { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -103,7 +100,6 @@ impl Custom { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -148,7 +144,6 @@ impl LessThanComparable for Mixed { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -177,7 +172,6 @@ impl MyBool { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -209,14 +203,7 @@ pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { }; } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - DefaultInitializable, - Memberwise, - MoveAssignable, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, MoveAssignable, )] #[memberwise(copy_assign)] #[derive(Conversions)] @@ -252,7 +239,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index 100f191845..751ca2a5a5 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -11,9 +11,7 @@ impl LessThanComparable for S { return ({ x.with(|__s| __s.data_) } < { y.with(|__s| __s.data_) }); } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise)] #[memberwise(move_constructor)] #[derive(Conversions)] #[conversions(move)] diff --git a/tests/unit/out/refcount/operator_compound_assignment_free.rs b/tests/unit/out/refcount/operator_compound_assignment_free.rs index a41d9466f0..7c124fdb86 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_free.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_free.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_compound_assignment_member.rs b/tests/unit/out/refcount/operator_compound_assignment_member.rs index 752e0a4e1f..cd34f85903 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_member.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_member.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index 73a37d4914..19e620358c 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -52,7 +51,6 @@ impl ThreeWayComparable for DefaultedOrd { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -88,7 +86,6 @@ pub fn operator_add_0(x: Ptr, y: Ptr) -> Inline { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -107,7 +104,6 @@ pub struct Inline { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -131,7 +127,6 @@ impl LessThanComparable for Tmpl_int_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -150,7 +145,6 @@ pub struct Tmpl_int_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -169,7 +163,6 @@ pub struct Tmpl_long_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_less_than.rs b/tests/unit/out/refcount/operator_less_than.rs index 92681a1bd6..aa43806a99 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_logical_free.rs b/tests/unit/out/refcount/operator_logical_free.rs index aadf9531f8..4a29c615eb 100644 --- a/tests/unit/out/refcount/operator_logical_free.rs +++ b/tests/unit/out/refcount/operator_logical_free.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_logical_member.rs b/tests/unit/out/refcount/operator_logical_member.rs index cbb4b85656..ecf83a281e 100644 --- a/tests/unit/out/refcount/operator_logical_member.rs +++ b/tests/unit/out/refcount/operator_logical_member.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_member_pointer_free.rs b/tests/unit/out/refcount/operator_member_pointer_free.rs index ddd80ba8d8..c360ee46ca 100644 --- a/tests/unit/out/refcount/operator_member_pointer_free.rs +++ b/tests/unit/out/refcount/operator_member_pointer_free.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -47,16 +46,6 @@ pub struct S { #[byte_size(4)] pub inner: Inner, } -impl Default for S { - fn default() -> Self { - { - S { - data: (0..3).map(|_| 0_i32).collect::>(), - inner: ::default(), - } - } - } -} pub fn operator_deref_0(s: Ptr) -> Ptr { return field_ptr!(s, inner); } diff --git a/tests/unit/out/refcount/operator_member_pointer_member.rs b/tests/unit/out/refcount/operator_member_pointer_member.rs index abb506ed45..4b53598c39 100644 --- a/tests/unit/out/refcount/operator_member_pointer_member.rs +++ b/tests/unit/out/refcount/operator_member_pointer_member.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -35,7 +34,6 @@ pub struct Inner { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -88,16 +86,6 @@ impl S { return (array_field_ptr!(this, data).offset((0) as isize)); } } -impl Default for S { - fn default() -> Self { - { - S { - data: (0..3).map(|_| 0_i32).collect::>(), - inner: ::default(), - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/operator_other_free.rs b/tests/unit/out/refcount/operator_other_free.rs index 1dc7af38ef..9117cfd15b 100644 --- a/tests/unit/out/refcount/operator_other_free.rs +++ b/tests/unit/out/refcount/operator_other_free.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_other_member.rs b/tests/unit/out/refcount/operator_other_member.rs index e933c0b1ef..65ba54a398 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_member.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ impl Static { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_overloads.rs b/tests/unit/out/refcount/operator_overloads.rs index b74cfdd244..8ec5b71855 100644 --- a/tests/unit/out/refcount/operator_overloads.rs +++ b/tests/unit/out/refcount/operator_overloads.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_qualifiers.rs b/tests/unit/out/refcount/operator_qualifiers.rs index 93b109eb64..9294e15ffc 100644 --- a/tests/unit/out/refcount/operator_qualifiers.rs +++ b/tests/unit/out/refcount/operator_qualifiers.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 3174e5eb07..6f8bf3ae8f 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 1d662beb1d..1aff2b6578 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -40,7 +39,6 @@ impl LessThanComparable for Lt { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -59,7 +57,6 @@ pub struct Eq { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] @@ -94,7 +91,6 @@ impl LessThanComparable for Cmp { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -118,7 +114,6 @@ impl LessThanComparable for Free { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/overload_mangling.rs b/tests/unit/out/refcount/overload_mangling.rs index cba600c702..1217324453 100644 --- a/tests/unit/out/refcount/overload_mangling.rs +++ b/tests/unit/out/refcount/overload_mangling.rs @@ -29,7 +29,6 @@ pub fn twice_2(mut n: i32) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -59,7 +58,6 @@ impl Access_S_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -155,7 +153,6 @@ impl S { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index bf4a93e669..b8c53a1a82 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -41,7 +40,6 @@ impl Celsius { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -66,7 +64,6 @@ impl Meters { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -92,7 +89,6 @@ impl Label { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -127,7 +123,6 @@ impl Owner { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -172,17 +167,6 @@ impl Constructor<()> for Fallback { } } } -impl Default for Fallback { - fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Fallback::constructor_1(__v.as_pointer(), -1_i32); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} #[derive( Copy, Clone, @@ -193,7 +177,6 @@ impl Default for Fallback { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -212,7 +195,6 @@ pub struct Counter { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -245,7 +227,6 @@ impl Tag { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -265,7 +246,6 @@ pub struct Tag { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/pod.rs b/tests/unit/out/refcount/pod.rs index 7cea2fe3a6..bf825d73b7 100644 --- a/tests/unit/out/refcount/pod.rs +++ b/tests/unit/out/refcount/pod.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/pointer_array.rs b/tests/unit/out/refcount/pointer_array.rs index b70895f7b6..d69d7c59e8 100644 --- a/tests/unit/out/refcount/pointer_array.rs +++ b/tests/unit/out/refcount/pointer_array.rs @@ -25,17 +25,6 @@ pub struct StackArray { #[array_len(3)] pub arr: Box<[Ptr]>, } -impl Default for StackArray { - fn default() -> Self { - { - StackArray { - arr: (0..3) - .map(|_| Ptr::::null()) - .collect::]>>(), - } - } - } -} pub fn IncrementAll_0(s: Ptr) { { let mut i: i32 = 0; diff --git a/tests/unit/out/refcount/pointers.rs b/tests/unit/out/refcount/pointers.rs index fbb28b42b8..e6b8af35f4 100644 --- a/tests/unit/out/refcount/pointers.rs +++ b/tests/unit/out/refcount/pointers.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/polymorphism.rs b/tests/unit/out/refcount/polymorphism.rs index 74467e5cd4..faf82ceef0 100644 --- a/tests/unit/out/refcount/polymorphism.rs +++ b/tests/unit/out/refcount/polymorphism.rs @@ -17,14 +17,17 @@ pub trait Animal { ZeroInitialization, VaArg, FnPtrArg, - DefaultInitializable, + Destructible, Copyable, - Default, Conversions, )] #[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Dog {} +impl Dog { + pub fn constructor_1(this: Ptr) {} +} #[derive( Copy, Clone, @@ -33,28 +36,29 @@ pub struct Dog {} ZeroInitialization, VaArg, FnPtrArg, - DefaultInitializable, + Destructible, Copyable, - Default, Conversions, )] #[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Cat {} impl Cat { fn meow(this: Ptr) -> bool { return true; } + pub fn constructor_1(this: Ptr) {} } pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let dog: Value = Rc::new(RefCell::new(::default())); + object!(dog, Dog::constructor_1()); let mut animal: PtrDyn = (dog.as_pointer()).to_dyn::(|w| w); let mut eat1: bool = ({ (*animal.upgrade().deref()).bark() }); - let cat: Value = Rc::new(RefCell::new(::default())); + object!(cat, Cat::constructor_1()); animal = (cat.as_pointer()).to_dyn::(|w| w); let mut eat2: bool = ({ (*animal.upgrade().deref()).bark() }); assert!((eat1) && (!(eat2))); diff --git a/tests/unit/out/refcount/ptr_cast_init.rs b/tests/unit/out/refcount/ptr_cast_init.rs index 87969f89ab..c98a17ab58 100644 --- a/tests/unit/out/refcount/ptr_cast_init.rs +++ b/tests/unit/out/refcount/ptr_cast_init.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct header { @@ -35,7 +34,6 @@ pub struct header { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(4)] pub struct view { diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index 3a5e4706fa..9f732d4b3f 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -34,7 +33,6 @@ pub struct Chunk { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -58,7 +56,6 @@ pub struct Writer { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -75,8 +72,17 @@ pub struct JPEGData { } impl JPEGData { pub fn constructor_1(this: Ptr) { - field!(this, com_data).write(Vec::new()); - field!(this, app_data).write(Vec::new()); + this.write(::default()); + } +} +impl Default for JPEGData { + fn default() -> Self { + { + JPEGData { + com_data: Vec::new(), + app_data: Vec::new(), + } + } } } pub fn push_param_0(mut dest: Ptr>>) { @@ -181,8 +187,7 @@ pub struct Pair { } impl Pair { pub fn constructor_1(this: Ptr) { - field!(this, first).write(-1_i32); - field!(this, second).write(-1_i32); + this.write(::default()); } pub fn constructor_2(this: Ptr, mut a: i32) { field!(this, first).write(a); @@ -196,23 +201,16 @@ impl Pair { impl Default for Pair { fn default() -> Self { { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Pair::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() + Pair { + first: -1_i32, + second: -1_i32, } } } } pub fn emplace_ctor_args_7(mut pairs: Ptr>) { { - pairs.with_mut(|__v: &mut Vec| { - __v.push({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Pair::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) - }); + pairs.with_mut(|__v: &mut Vec| __v.push(::default())); }; { let mut __tmp_4 = { @@ -247,13 +245,7 @@ pub fn emplace_deque_8(mut queue: Ptr>) { queue.with_mut(|__v: &mut Vec| __v.push(__tmp_6)); }; { - queue.with_mut(|__v: &mut Vec| { - __v.push({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Pair::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) - }); + queue.with_mut(|__v: &mut Vec| __v.push(::default())); }; } pub fn emplace_scalar_9(mut values: Ptr>, x: i32) { @@ -382,15 +374,14 @@ pub struct Bytes { } impl Bytes { pub fn constructor_1(this: Ptr) { - field!(this, v).write(Vec::new()); - field!(this, b).write((0..3).map(|_| 0_u8).collect::>()); + this.write(::default()); } } impl Default for Bytes { fn default() -> Self { { Bytes { - v: Default::default(), + v: Vec::new(), b: (0..3).map(|_| 0_u8).collect::>(), } } @@ -441,16 +432,6 @@ pub struct Plain { #[array_len(2)] pub b: Box<[f64]>, } -impl Default for Plain { - fn default() -> Self { - { - Plain { - a: 0_i32, - b: (0..2).map(|_| 0_f64).collect::>(), - } - } - } -} pub fn emplace_plain_15(mut v: Ptr>) { let p: Value = Rc::new(RefCell::new(Plain { a: 1, @@ -474,7 +455,6 @@ thread_local!( FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -541,7 +521,7 @@ fn main_0() -> i32 { ({ push_param_0((vecs.as_pointer())) }); assert!(({ ((*vecs.borrow()).len() == 1_usize) })); assert!(({ (*vecs.decay().offset(0_usize).upgrade().deref()).is_empty() })); - object!(jpg, JPEGData::constructor_1()); + let jpg: Value = Rc::new(RefCell::new(::default())); ({ push_local_from_field_1((jpg.as_pointer()), true) }); assert!(({ ((*jpg.borrow()).com_data.len() == 1_usize) })); assert!( diff --git a/tests/unit/out/refcount/random.rs b/tests/unit/out/refcount/random.rs index 3b97b9b0e4..0f223cb7d3 100644 --- a/tests/unit/out/refcount/random.rs +++ b/tests/unit/out/refcount/random.rs @@ -64,23 +64,6 @@ impl Pair { return (field_ptr!(this, x)); } } -impl Default for Pair { - fn default() -> Self { - { - Pair { - x: 0_i32, - y: 0_i32, - a: (0..5).map(|_| 0_i32).collect::>(), - r: >::default(), - p: Ptr::::null(), - pair: Ptr::::null(), - ap: (0..2) - .map(|_| Ptr::::null()) - .collect::]>>(), - } - } - } -} pub fn zero_0() -> i32 { return 0; } @@ -94,7 +77,6 @@ pub fn zero_0() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/reference_wrapper.rs b/tests/unit/out/refcount/reference_wrapper.rs index f2a8101f4d..8b7d2c3972 100644 --- a/tests/unit/out/refcount/reference_wrapper.rs +++ b/tests/unit/out/refcount/reference_wrapper.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/references.rs b/tests/unit/out/refcount/references.rs index 9210cd9bbb..f2db39fe22 100644 --- a/tests/unit/out/refcount/references.rs +++ b/tests/unit/out/refcount/references.rs @@ -29,17 +29,6 @@ pub struct Pair { #[array_len(2)] pub arr: Box<[i32]>, } -impl Default for Pair { - fn default() -> Self { - { - Pair { - x: 0_i32, - y: 0_i32, - arr: (0..2).map(|_| 0_i32).collect::>(), - } - } - } -} #[derive( Clone, Record, @@ -49,7 +38,6 @@ impl Default for Pair { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/refs_as_args.rs b/tests/unit/out/refcount/refs_as_args.rs index df7af17bdb..268f115eed 100644 --- a/tests/unit/out/refcount/refs_as_args.rs +++ b/tests/unit/out/refcount/refs_as_args.rs @@ -40,7 +40,6 @@ pub fn more_refs_0(x1: i32, x2: i32, r1: Ptr, r2: Ptr) { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs b/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs index f78e16c444..07a4d606c9 100644 --- a/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs +++ b/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -48,16 +47,6 @@ pub struct W { #[array_len(3)] pub arr: Box<[S]>, } -impl Default for W { - fn default() -> Self { - { - W { - h: 0_i32, - arr: (0..3).map(|_| ::default()).collect::>(), - } - } - } -} #[derive( Clone, Record, @@ -80,18 +69,6 @@ pub struct P { #[array_len(3)] pub arr: Box<[Ptr]>, } -impl Default for P { - fn default() -> Self { - { - P { - a: Ptr::::null(), - arr: (0..3) - .map(|_| Ptr::::null()) - .collect::]>>(), - } - } - } -} pub fn typed_0() { let w: Value = Rc::new(RefCell::new(::default())); let mut p: Ptr = (array_field_ptr!(w.as_pointer(), arr).offset((2) as isize)); diff --git a/tests/unit/out/refcount/reinterpret_cast_struct.rs b/tests/unit/out/refcount/reinterpret_cast_struct.rs index 2b7528881e..717fa4a749 100644 --- a/tests/unit/out/refcount/reinterpret_cast_struct.rs +++ b/tests/unit/out/refcount/reinterpret_cast_struct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs b/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs index abd2f86917..3940cda984 100644 --- a/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs +++ b/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ pub struct Point { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/reserved_keywords.rs b/tests/unit/out/refcount/reserved_keywords.rs index 34f8f95b8a..b53a8d68d9 100644 --- a/tests/unit/out/refcount/reserved_keywords.rs +++ b/tests/unit/out/refcount/reserved_keywords.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -109,7 +108,6 @@ pub struct S { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -128,7 +126,6 @@ pub struct type_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/return_move.rs b/tests/unit/out/refcount/return_move.rs index 7800c9a920..1c32a27ffa 100644 --- a/tests/unit/out/refcount/return_move.rs +++ b/tests/unit/out/refcount/return_move.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -36,7 +35,6 @@ pub struct node { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/rvalue_rule_arg_move.rs b/tests/unit/out/refcount/rvalue_rule_arg_move.rs index f431b93143..1baf02ffdd 100644 --- a/tests/unit/out/refcount/rvalue_rule_arg_move.rs +++ b/tests/unit/out/refcount/rvalue_rule_arg_move.rs @@ -13,14 +13,7 @@ thread_local!( pub static moves_1: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - DefaultInitializable, - Memberwise, - Swappable, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(copy_assign, move_assign)] #[derive(Conversions)] diff --git a/tests/unit/out/refcount/rvalue_struct.rs b/tests/unit/out/refcount/rvalue_struct.rs index 4ee92b4ff3..ece376ec2b 100644 --- a/tests/unit/out/refcount/rvalue_struct.rs +++ b/tests/unit/out/refcount/rvalue_struct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs b/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs index e0f14181ad..4f020a93a0 100644 --- a/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs +++ b/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/self_referencing_initializer.rs b/tests/unit/out/refcount/self_referencing_initializer.rs index e240f356e6..d7290198a4 100644 --- a/tests/unit/out/refcount/self_referencing_initializer.rs +++ b/tests/unit/out/refcount/self_referencing_initializer.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -34,7 +33,6 @@ pub struct list_head { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -61,8 +59,7 @@ pub struct node_with_defaults { } impl node_with_defaults { pub fn constructor_1(this: Ptr) { - field!(this, next).write(Ptr::::null()); - field!(this, value).write(3); + this.write(::default()); } } impl Default for node_with_defaults { diff --git a/tests/unit/out/refcount/size_t_static_member.rs b/tests/unit/out/refcount/size_t_static_member.rs index 2f0c828ffc..bcd6e2fad5 100644 --- a/tests/unit/out/refcount/size_t_static_member.rs +++ b/tests/unit/out/refcount/size_t_static_member.rs @@ -19,7 +19,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -38,7 +37,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/size_t_template_param.rs b/tests/unit/out/refcount/size_t_template_param.rs index 2e2ac9adeb..559c614ea6 100644 --- a/tests/unit/out/refcount/size_t_template_param.rs +++ b/tests/unit/out/refcount/size_t_template_param.rs @@ -20,7 +20,6 @@ pub fn array_ref_0(a: Ptr) -> u64 { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -46,7 +45,6 @@ impl PtrCtor_unsigned_long_ { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index a9e08862ee..ae0a85157c 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -22,7 +22,7 @@ pub struct Tracked { } impl Tracked { pub fn constructor_1(this: Ptr) { - field!(this, v).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, mut v: i32) { field!(this, v).write(v); @@ -54,13 +54,7 @@ impl MoveAssignable for Tracked { } impl Default for Tracked { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Tracked::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { Tracked { v: 0 } } } } impl LessThanComparable for Tracked { @@ -72,14 +66,7 @@ pub fn greater_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) }); } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - DefaultInitializable, - Memberwise, - Swappable, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] @@ -100,9 +87,7 @@ impl LessThanComparable for MoveOnly { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(Conversions)] #[conversions(copy, move)] @@ -115,7 +100,12 @@ pub struct Bag { } impl Bag { pub fn constructor_1(this: Ptr) { - field!(this, items).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Bag { + fn default() -> Self { + { Bag { items: Vec::new() } } } } impl LessThanComparable for Bag { @@ -306,13 +296,9 @@ fn main_0() -> i32 { && ({ (*vec_.borrow())[3_usize].v } == 2) ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - let bags: Value> = Rc::new(RefCell::new(Box::new(std::array::from_fn::<_, 3, _>( - |_| { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Bag::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }, - )))); + let bags: Value> = Rc::new(RefCell::new( + (0..3).map(|_| ::default()).collect::>(), + )); { let mut __tmp_9 = { { @@ -358,8 +344,9 @@ fn main_0() -> i32 { }) ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - let bag_vec: Value> = - Rc::new(RefCell::new(Vec::from_fn(3_usize, |_| ::default()))); + let bag_vec: Value> = Rc::new(RefCell::new(Vec::from_fn(3_usize, |_| { + ::default_constructed() + }))); match ( field_ref!(bag_vec.decay().offset(1_usize), items).as_pointer(), { diff --git a/tests/unit/out/refcount/static_local.rs b/tests/unit/out/refcount/static_local.rs index 2f46b5c455..90dd5d28a9 100644 --- a/tests/unit/out/refcount/static_local.rs +++ b/tests/unit/out/refcount/static_local.rs @@ -43,7 +43,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/static_var_in_class.rs b/tests/unit/out/refcount/static_var_in_class.rs index d3ecaa4ac6..70a3d61951 100644 --- a/tests/unit/out/refcount/static_var_in_class.rs +++ b/tests/unit/out/refcount/static_var_in_class.rs @@ -19,7 +19,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -45,7 +44,6 @@ pub const anon_3_kValue: anon_3 = 3; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/stdcopy.rs b/tests/unit/out/refcount/stdcopy.rs index 3a312a4201..ec7716c910 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/strdup.rs b/tests/unit/out/refcount/strdup.rs index 1135a0239a..52dd6928b1 100644 --- a/tests/unit/out/refcount/strdup.rs +++ b/tests/unit/out/refcount/strdup.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct record { diff --git a/tests/unit/out/refcount/string_literal_ptr_init.rs b/tests/unit/out/refcount/string_literal_ptr_init.rs index faecbb65d5..d2ac54626b 100644 --- a/tests/unit/out/refcount/string_literal_ptr_init.rs +++ b/tests/unit/out/refcount/string_literal_ptr_init.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(24)] pub struct label { diff --git a/tests/unit/out/refcount/string_substr.rs b/tests/unit/out/refcount/string_substr.rs index 3218503167..292654acf7 100644 --- a/tests/unit/out/refcount/string_substr.rs +++ b/tests/unit/out/refcount/string_substr.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/struct_2d_array_field.rs b/tests/unit/out/refcount/struct_2d_array_field.rs index 8ac998a96b..23e005d3e3 100644 --- a/tests/unit/out/refcount/struct_2d_array_field.rs +++ b/tests/unit/out/refcount/struct_2d_array_field.rs @@ -25,18 +25,6 @@ pub struct table { #[offset(32)] pub count: usize, } -impl Default for table { - fn default() -> Self { - { - table { - rows: (0..3) - .map(|_| (0..10).map(|_| 0_i8).collect::>()) - .collect::]>>(), - count: 0_usize, - } - } - } -} thread_local!( pub static T1_0: Value = Rc::new(RefCell::new(table { rows: Box::new([ diff --git a/tests/unit/out/refcount/struct_ctor.rs b/tests/unit/out/refcount/struct_ctor.rs index efeff6d618..471de057ec 100644 --- a/tests/unit/out/refcount/struct_ctor.rs +++ b/tests/unit/out/refcount/struct_ctor.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -59,7 +58,6 @@ pub fn foo_0(x: Ptr) -> Ptr { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -102,17 +100,6 @@ impl Ptr_ { Value_::constructor_1(field_ptr!(this, v2), 22); } } -impl Default for Ptr_ { - fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Ptr_::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/struct_default_ctor.rs b/tests/unit/out/refcount/struct_default_ctor.rs index cbe377b96f..7ddc45785b 100644 --- a/tests/unit/out/refcount/struct_default_ctor.rs +++ b/tests/unit/out/refcount/struct_default_ctor.rs @@ -28,19 +28,12 @@ pub struct S { } impl S { pub fn constructor_1(this: Ptr) { - field!(this, a).write(11); - field!(this, b).write(true); + this.write(::default()); } } impl Default for S { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { S { a: 11, b: true } } } } #[derive( @@ -52,7 +45,6 @@ impl Default for S { VaArg, FnPtrArg, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -76,11 +68,7 @@ pub struct Holder { } impl Holder { pub fn constructor_1(this: Ptr) { - field!(this, items).write(Box::new(std::array::from_fn::<_, 2, _>(|_| { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }))); + this.write(::default()); } } impl Default for Holder { @@ -115,7 +103,7 @@ pub struct FromStatic { } impl FromStatic { pub fn constructor_1(this: Ptr) { - field!(this, v).write(kInit_0.with(|rc| *rc.borrow())); + this.write(::default()); } } impl Default for FromStatic { @@ -134,9 +122,9 @@ pub fn main() { fn main_0() -> i32 { let mut d: Ptr = Ptr::::null(); assert!((d).is_null()); - object!(s, S::constructor_1()); - assert!(({ (*s.borrow()).a } == 11)); - assert!((({ (*s.borrow()).b } as i32) == (true as i32))); + let mut s: S = ::default(); + assert!((s.a == 11)); + assert!(((s.b as i32) == (true as i32))); let mut h: Ptr = Ptr::alloc_array( (0..1_usize) .map(|_| ::default()) diff --git a/tests/unit/out/refcount/struct_member_array_adjacency.rs b/tests/unit/out/refcount/struct_member_array_adjacency.rs index 62c22118f0..5696afc7ff 100644 --- a/tests/unit/out/refcount/struct_member_array_adjacency.rs +++ b/tests/unit/out/refcount/struct_member_array_adjacency.rs @@ -27,16 +27,6 @@ pub struct pair { #[array_len(4)] pub b: Box<[i32]>, } -impl Default for pair { - fn default() -> Self { - { - pair { - a: (0..4).map(|_| 0_i32).collect::>(), - b: (0..4).map(|_| 0_i32).collect::>(), - } - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/struct_ptr.rs b/tests/unit/out/refcount/struct_ptr.rs index e82556be4d..96c99b3380 100644 --- a/tests/unit/out/refcount/struct_ptr.rs +++ b/tests/unit/out/refcount/struct_ptr.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/structured_binding_copy_ctor.rs b/tests/unit/out/refcount/structured_binding_copy_ctor.rs index b015c29c02..f8d15e7f00 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -19,7 +19,6 @@ thread_local!( MoveConstructible, MoveAssignable, Swappable, - Default, )] #[memberwise(copy_assign)] #[derive(Conversions)] diff --git a/tests/unit/out/refcount/structured_binding_element_ctor.rs b/tests/unit/out/refcount/structured_binding_element_ctor.rs index 2c555331a3..7f786fcf51 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -12,9 +12,7 @@ thread_local!( thread_local!( pub static moves_1: Value = Rc::new(RefCell::new(0)); ); -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRef>)] @@ -40,9 +38,7 @@ impl Elem { (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise)] #[memberwise(copy_constructor, move_constructor)] #[derive(Conversions)] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/structured_binding_move_ctor.rs b/tests/unit/out/refcount/structured_binding_move_ctor.rs index f284322384..22c1eb228b 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -12,9 +12,7 @@ thread_local!( thread_local!( pub static moves_1: Value = Rc::new(RefCell::new(0)); ); -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] #[conversions(copy, move)] #[constructor(constructor_1, i32, i32)] #[constructor(constructor_2, LvalueRef>)] @@ -57,7 +55,6 @@ impl Movable { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -81,8 +78,17 @@ impl Holder { return; } pub fn constructor_1(this: Ptr) { - field!(this, xs).write(Vec::new()); - field!(this, ys).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Holder { + fn default() -> Self { + { + Holder { + xs: Vec::new(), + ys: Vec::new(), + } + } } } pub fn main() { diff --git a/tests/unit/out/refcount/structured_binding_range_for.rs b/tests/unit/out/refcount/structured_binding_range_for.rs index 4f6e53e1d6..470bdfedaa 100644 --- a/tests/unit/out/refcount/structured_binding_range_for.rs +++ b/tests/unit/out/refcount/structured_binding_range_for.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/structured_binding_ref.rs b/tests/unit/out/refcount/structured_binding_ref.rs index 420c71dd97..f672fbebac 100644 --- a/tests/unit/out/refcount/structured_binding_ref.rs +++ b/tests/unit/out/refcount/structured_binding_ref.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/structured_binding_trivial.rs b/tests/unit/out/refcount/structured_binding_trivial.rs index 9cd943158c..2c6333c92c 100644 --- a/tests/unit/out/refcount/structured_binding_trivial.rs +++ b/tests/unit/out/refcount/structured_binding_trivial.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 841a656559..1c4d184823 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -22,7 +22,7 @@ pub struct Tracked { } impl Tracked { pub fn constructor_1(this: Ptr) { - field!(this, v).write(0); + this.write(::default()); } pub fn constructor_2(this: Ptr, mut v: i32) { field!(this, v).write(v); @@ -54,18 +54,10 @@ impl MoveAssignable for Tracked { } impl Default for Tracked { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Tracked::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { Tracked { v: 0 } } } } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(Conversions)] #[conversions(copy, move)] @@ -81,8 +73,17 @@ pub struct Pair { } impl Pair { pub fn constructor_1(this: Ptr) { - Tracked::constructor_1(field_ptr!(this, x)); - Tracked::constructor_1(field_ptr!(this, y)); + this.write(::default()); + } +} +impl Default for Pair { + fn default() -> Self { + { + Pair { + x: ::default(), + y: ::default(), + } + } } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] @@ -103,16 +104,7 @@ pub struct Arrays { } impl Arrays { pub fn constructor_1(this: Ptr) { - field!(this, a).write(Box::new(std::array::from_fn::<_, 2, _>(|_| { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Tracked::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }))); - field!(this, b).write(Box::new(std::array::from_fn::<_, 2, _>(|_| { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Tracked::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }))); + this.write(::default()); } } impl Default for Arrays { @@ -289,9 +281,7 @@ pub fn swapped_once_6() -> bool { }); return ok; } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] @@ -304,7 +294,12 @@ pub struct Owner { } impl Owner { pub fn constructor_1(this: Ptr) { - field!(this, p).write(None); + this.write(::default()); + } +} +impl Default for Owner { + fn default() -> Self { + { Owner { p: None } } } } pub fn main() { @@ -328,7 +323,7 @@ fn main_0() -> i32 { (*m1.borrow_mut()).subscript_move( __tmp_0, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -345,7 +340,7 @@ fn main_0() -> i32 { (*m1.borrow_mut()).subscript_move( __tmp_1, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -363,7 +358,7 @@ fn main_0() -> i32 { (*m2.borrow_mut()).subscript_move( __tmp_2, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -378,7 +373,7 @@ fn main_0() -> i32 { (*m1.borrow_mut()).subscript_move( __tmp_3, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -389,7 +384,7 @@ fn main_0() -> i32 { (*m1.borrow_mut()).subscript_move( __tmp_4, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -402,7 +397,7 @@ fn main_0() -> i32 { (*m1.borrow_mut()).subscript_move( __tmp_5, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -415,7 +410,7 @@ fn main_0() -> i32 { (*m1.borrow_mut()).subscript_move( __tmp_6, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -433,7 +428,7 @@ fn main_0() -> i32 { (*m1.borrow_mut()).subscript_move( __tmp_7, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -449,7 +444,7 @@ fn main_0() -> i32 { (*m2.borrow_mut()).subscript_move( __tmp_8, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -462,7 +457,7 @@ fn main_0() -> i32 { (*m2.borrow_mut()).subscript_move( __tmp_9, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -579,7 +574,7 @@ fn main_0() -> i32 { && ({ (*pairs.borrow())[(1) as usize].y.v } == 8) ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - object!(arrays, Arrays::constructor_1()); + let arrays: Value = Rc::new(RefCell::new(::default())); field!(array_elem!(arrays.as_pointer(), a, 0), v).write(1); field!(array_elem!(arrays.as_pointer(), b, 1), v).write(2); Swappable::swap( @@ -665,7 +660,7 @@ fn main_0() -> i32 { (*maps.borrow_mut())[(0) as usize].subscript_move( __tmp_18, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -682,7 +677,7 @@ fn main_0() -> i32 { (*maps.borrow_mut())[(1) as usize].subscript_move( __tmp_19, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -698,7 +693,7 @@ fn main_0() -> i32 { (*maps.borrow_mut())[(0) as usize].subscript_move( __tmp_20, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } @@ -714,7 +709,7 @@ fn main_0() -> i32 { (*maps.borrow_mut())[(1) as usize].subscript_move( __tmp_21, |__k| cpp_move!(__k), - || ::default(), + || ::default_constructed(), ) }) } diff --git a/tests/unit/out/refcount/tag_vs_identifier_collision.rs b/tests/unit/out/refcount/tag_vs_identifier_collision.rs index f86e8dbb0a..5feb2cd74c 100644 --- a/tests/unit/out/refcount/tag_vs_identifier_collision.rs +++ b/tests/unit/out/refcount/tag_vs_identifier_collision.rs @@ -20,7 +20,6 @@ pub const widget_enum_MODE_DONE: widget_enum = 2; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct widget { @@ -39,7 +38,6 @@ pub struct widget { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct point_struct { @@ -72,13 +70,6 @@ impl point { this.reinterpret_cast() } } -impl Default for point { - fn default() -> Self { - point { - __bytes: Box::from([0u8; 4]), - } - } -} #[derive( VaArg, FnPtrArg, @@ -103,13 +94,6 @@ impl slot_union { this.reinterpret_cast() } } -impl Default for slot_union { - fn default() -> Self { - slot_union { - __bytes: Box::from([0u8; 4]), - } - } -} pub type slot = u32; pub const slot_SLOT_A: slot = 0; pub const slot_SLOT_B: slot = 1; @@ -123,7 +107,6 @@ pub const slot_SLOT_B: slot = 1; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(4)] pub struct Inner { @@ -140,7 +123,6 @@ pub struct Inner { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(4)] pub struct Outer { @@ -158,7 +140,6 @@ pub struct Outer { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(4)] pub struct Inner_struct { diff --git a/tests/unit/out/refcount/template_default_arg.rs b/tests/unit/out/refcount/template_default_arg.rs index c326db0757..09dbfcd621 100644 --- a/tests/unit/out/refcount/template_default_arg.rs +++ b/tests/unit/out/refcount/template_default_arg.rs @@ -27,7 +27,7 @@ pub struct A { } impl A { pub fn constructor_1(this: Ptr) { - field!(this, v).write(1); + this.write(::default()); } pub fn constructor_2(this: Ptr, mut v: i32) { field!(this, v).write(v); @@ -35,13 +35,7 @@ impl A { } impl Default for A { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - A::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { A { v: 1 } } } } #[derive( @@ -64,18 +58,12 @@ pub struct B { } impl B { pub fn constructor_1(this: Ptr) { - field!(this, v).write(2); + this.write(::default()); } } impl Default for B { fn default() -> Self { - { - { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - B::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } - } + { B { v: 2 } } } } #[derive( @@ -88,7 +76,6 @@ impl Default for B { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -125,7 +112,6 @@ pub fn always_given_3(mut x: NoDefault) -> i32 { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -148,15 +134,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - assert!( - (({ - used_0({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - A::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) - }) == 1) - ); + assert!((({ used_0(::default(),) }) == 1)); assert!( (({ used_0({ @@ -166,15 +144,7 @@ fn main_0() -> i32 { }) }) == 5) ); - assert!( - (({ - used_1({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - B::constructor_1(__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) - }) == 2) - ); + assert!((({ used_1(::default(),) }) == 2)); assert!( (({ scaled_2( diff --git a/tests/unit/out/refcount/template_static_member.rs b/tests/unit/out/refcount/template_static_member.rs index 4a3e57b40f..f9b6071881 100644 --- a/tests/unit/out/refcount/template_static_member.rs +++ b/tests/unit/out/refcount/template_static_member.rs @@ -19,7 +19,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -38,7 +37,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -57,7 +55,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -79,7 +76,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -101,7 +97,6 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index ab371a0ab0..4a217d6546 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -17,7 +17,6 @@ use std::rc::{Rc, Weak}; Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -31,7 +30,12 @@ pub struct Inner { } impl Inner { pub fn constructor_1(this: Ptr) { - field!(this, values).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Inner { + fn default() -> Self { + { Inner { values: Vec::new() } } } } #[derive( @@ -65,16 +69,14 @@ pub struct Outer { } impl Outer { pub fn constructor_1(this: Ptr) { - field!(this, values).write(Vec::new()); - Inner::constructor_1(field_ptr!(this, inner)); - field!(this, name).write((0..8).map(|_| 0_i8).collect::>()); + this.write(::default()); } } impl Default for Outer { fn default() -> Self { { Outer { - values: Default::default(), + values: Vec::new(), inner: ::default(), name: (0..8).map(|_| 0_i8).collect::>(), } diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index b908d68d41..2b52f4ad4c 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -17,7 +17,6 @@ use std::rc::{Rc, Weak}; Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -31,7 +30,12 @@ pub struct Outer { } impl Outer { pub fn constructor_1(this: Ptr) { - field!(this, values).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Outer { + fn default() -> Self { + { Outer { values: Vec::new() } } } } pub fn make_0(__return: Ptr) { @@ -50,7 +54,6 @@ pub fn make_0(__return: Ptr) { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index d528835867..4792103db8 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -17,7 +17,6 @@ use std::rc::{Rc, Weak}; Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -31,7 +30,12 @@ pub struct Inner { } impl Inner { pub fn constructor_1(this: Ptr) { - field!(this, values).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Inner { + fn default() -> Self { + { Inner { values: Vec::new() } } } } #[derive( @@ -45,7 +49,6 @@ impl Inner { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -62,8 +65,17 @@ pub struct Outer { } impl Outer { pub fn constructor_1(this: Ptr) { - field!(this, values).write(Vec::new()); - Inner::constructor_1(field_ptr!(this, inner)); + this.write(::default()); + } +} +impl Default for Outer { + fn default() -> Self { + { + Outer { + values: Vec::new(), + inner: ::default(), + } + } } } pub fn make_0(__return: Ptr) { diff --git a/tests/unit/out/refcount/this.rs b/tests/unit/out/refcount/this.rs index cf648bb3b7..c8a8e84ea2 100644 --- a/tests/unit/out/refcount/this.rs +++ b/tests/unit/out/refcount/this.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -125,7 +124,6 @@ pub fn bump_0(mut p: Ptr) { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index c9e1dd91e9..4f9b561f6e 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -38,7 +37,6 @@ pub struct Outer_RunInfo { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -52,7 +50,12 @@ pub struct Outer { } impl Outer { pub fn constructor_1(this: Ptr) { - field!(this, runs).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Outer { + fn default() -> Self { + { Outer { runs: Vec::new() } } } } pub fn main() { @@ -60,7 +63,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(o, Outer::constructor_1()); + let o: Value = Rc::new(RefCell::new(::default())); let info: Value = Rc::new(RefCell::new(::default())); (*info.borrow_mut()).block_idx = 1; (*info.borrow_mut()).num_extra_zero_runs = 2; diff --git a/tests/unit/out/refcount/types.rs b/tests/unit/out/refcount/types.rs index 6eda079e67..cbdb728a66 100644 --- a/tests/unit/out/refcount/types.rs +++ b/tests/unit/out/refcount/types.rs @@ -36,7 +36,7 @@ fn main_0() -> i32 { let mut xc8: u8 = 66_u8; let mut xc16: u16 = 67_u16; let mut xc32: u32 = 68_u32; - let xnp: Value = Rc::new(RefCell::new(Default::default())); + let xnp: Value = Rc::new(RefCell::new(Ptr::<()>::null().to_any())); assert!( ((((((((((((xu8 as i32) + (xu16 as i32)) as u32).wrapping_add(xu32)) as u64) .wrapping_add(xu64)) diff --git a/tests/unit/out/refcount/unary_expr_or_type_trait.rs b/tests/unit/out/refcount/unary_expr_or_type_trait.rs index 113098923a..f738c39685 100644 --- a/tests/unit/out/refcount/unary_expr_or_type_trait.rs +++ b/tests/unit/out/refcount/unary_expr_or_type_trait.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/unboxed_locals.rs b/tests/unit/out/refcount/unboxed_locals.rs index 2430ac05fb..64c2fc9413 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -24,7 +24,6 @@ pub fn inc_1(r: Ptr) { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -75,19 +74,20 @@ pub trait Shape { ZeroInitialization, VaArg, FnPtrArg, - DefaultInitializable, + Destructible, Copyable, Conversions, )] #[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(16)] pub struct Square { #[offset(8)] pub side: i32, } -impl Default for Square { - fn default() -> Self { - { Square { side: 2 } } +impl Square { + pub fn constructor_1(this: Ptr) { + field!(this, side).write(2); } } pub fn main() { @@ -204,7 +204,7 @@ fn main_0() -> i32 { )); ({ set_0(data.decay(), 8) }); assert!(({ (*data.borrow())[0_usize] } == 8)); - let square: Value = Rc::new(RefCell::new(::default())); + object!(square, Square::constructor_1()); let mut shape: PtrDyn = (square.as_pointer()).to_dyn::(|w| w); assert!((({ (*shape.upgrade().deref_mut()).scale(3,) }) == 6)); return 0; diff --git a/tests/unit/out/refcount/unboxed_records.rs b/tests/unit/out/refcount/unboxed_records.rs index 9bc761e053..0473770956 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -57,19 +56,6 @@ pub struct Cookie { #[array_len(4)] pub arr: Box<[i32]>, } -impl Default for Cookie { - fn default() -> Self { - { - Cookie { - x: 0_i32, - data: Ptr::::null(), - in_: Ptr::::null(), - inner: ::default(), - arr: (0..4).map(|_| 0_i32).collect::>(), - } - } - } -} #[derive( Copy, Clone, @@ -95,7 +81,7 @@ impl Counter { }); } pub fn constructor_1(this: Ptr) { - field!(this, n).write(0); + this.write(::default()); } } impl Default for Counter { @@ -162,7 +148,7 @@ fn main_0() -> i32 { let field_addr: Value = Rc::new(RefCell::new(Inner { a: 0, b: 0 })); ({ set_0((field_ptr!(field_addr.as_pointer(), b)), 7) }); assert!(({ (*field_addr.borrow()).b } == 7)); - object!(counter, Counter::constructor_1()); + let counter: Value = Rc::new(RefCell::new(::default())); ({ Counter::inc(counter.as_pointer()) }); assert!(({ (*counter.borrow()).n } == 1)); return 0; diff --git a/tests/unit/out/refcount/union_addrof_external.rs b/tests/unit/out/refcount/union_addrof_external.rs index 6987c6e70c..52319db37c 100644 --- a/tests/unit/out/refcount/union_addrof_external.rs +++ b/tests/unit/out/refcount/union_addrof_external.rs @@ -29,18 +29,6 @@ pub struct record { #[array_len(8)] pub pad: Box<[i8]>, } -impl Default for record { - fn default() -> Self { - { - record { - code: 0_u16, - lo: 0_u16, - hi: 0_u32, - pad: (0..8).map(|_| 0_i8).collect::>(), - } - } - } -} #[derive( VaArg, FnPtrArg, @@ -65,13 +53,6 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 128]), - } - } -} #[derive( Clone, Record, @@ -81,7 +62,6 @@ impl Default for anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(128)] pub struct Container { diff --git a/tests/unit/out/refcount/union_basic.rs b/tests/unit/out/refcount/union_basic.rs index 0dc7a5de49..cfe40992d1 100644 --- a/tests/unit/out/refcount/union_basic.rs +++ b/tests/unit/out/refcount/union_basic.rs @@ -30,13 +30,6 @@ impl basic { this.reinterpret_cast() } } -impl Default for basic { - fn default() -> Self { - basic { - __bytes: Box::from([0u8; 4]), - } - } -} #[derive( VaArg, FnPtrArg, @@ -54,13 +47,6 @@ pub struct empty { __bytes: Box<[u8]>, } impl empty {} -impl Default for empty { - fn default() -> Self { - empty { - __bytes: Box::from([0u8; 1]), - } - } -} #[derive( VaArg, FnPtrArg, @@ -85,13 +71,6 @@ impl underscores { this.reinterpret_cast() } } -impl Default for underscores { - fn default() -> Self { - underscores { - __bytes: Box::from([0u8; 8]), - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -171,11 +150,4 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 4]), - } - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/union_cross_arm_cast.rs b/tests/unit/out/refcount/union_cross_arm_cast.rs index d4871fa382..121b82898e 100644 --- a/tests/unit/out/refcount/union_cross_arm_cast.rs +++ b/tests/unit/out/refcount/union_cross_arm_cast.rs @@ -25,16 +25,6 @@ pub struct shape_a { #[array_len(14)] pub pad: Box<[i8]>, } -impl Default for shape_a { - fn default() -> Self { - { - shape_a { - code: 0_u16, - pad: (0..14).map(|_| 0_i8).collect::>(), - } - } - } -} #[derive( Clone, Record, @@ -60,19 +50,6 @@ pub struct shape_b { #[offset(24)] pub tail: u32, } -impl Default for shape_b { - fn default() -> Self { - { - shape_b { - code: 0_u16, - lo: 0_u16, - mid: 0_u32, - fill: (0..16).map(|_| 0_u8).collect::>(), - tail: 0_u32, - } - } - } -} #[derive( VaArg, FnPtrArg, @@ -100,13 +77,6 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 64]), - } - } -} #[derive( Clone, Record, @@ -116,7 +86,6 @@ impl Default for anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(68)] pub struct Container { diff --git a/tests/unit/out/refcount/union_field_alignment.rs b/tests/unit/out/refcount/union_field_alignment.rs index f2f47c1f1b..81b3469150 100644 --- a/tests/unit/out/refcount/union_field_alignment.rs +++ b/tests/unit/out/refcount/union_field_alignment.rs @@ -30,13 +30,6 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 8]), - } - } -} #[derive( Clone, Record, @@ -46,7 +39,6 @@ impl Default for anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct node { diff --git a/tests/unit/out/refcount/union_flex_array_member.rs b/tests/unit/out/refcount/union_flex_array_member.rs index 0cc7bfa269..cd225ef3b0 100644 --- a/tests/unit/out/refcount/union_flex_array_member.rs +++ b/tests/unit/out/refcount/union_flex_array_member.rs @@ -30,13 +30,6 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 8]), - } - } -} #[derive( Clone, Record, @@ -46,7 +39,6 @@ impl Default for anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(24)] pub struct node { diff --git a/tests/unit/out/refcount/union_memset_memcpy.rs b/tests/unit/out/refcount/union_memset_memcpy.rs index 74c3826b41..3e0ead3de8 100644 --- a/tests/unit/out/refcount/union_memset_memcpy.rs +++ b/tests/unit/out/refcount/union_memset_memcpy.rs @@ -25,16 +25,6 @@ pub struct shape_a { #[array_len(14)] pub pad: Box<[i8]>, } -impl Default for shape_a { - fn default() -> Self { - { - shape_a { - code: 0_u16, - pad: (0..14).map(|_| 0_i8).collect::>(), - } - } - } -} #[derive( Clone, Record, @@ -58,18 +48,6 @@ pub struct shape_b { #[array_len(8)] pub fill: Box<[i8]>, } -impl Default for shape_b { - fn default() -> Self { - { - shape_b { - code: 0_u16, - lo: 0_u16, - hi: 0_u32, - fill: (0..8).map(|_| 0_i8).collect::>(), - } - } - } -} #[derive( VaArg, FnPtrArg, @@ -97,13 +75,6 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 256]), - } - } -} #[derive( Clone, Record, @@ -113,7 +84,6 @@ impl Default for anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(256)] pub struct Container { diff --git a/tests/unit/out/refcount/union_nested.rs b/tests/unit/out/refcount/union_nested.rs index 85282bf7c9..02109bcd0d 100644 --- a/tests/unit/out/refcount/union_nested.rs +++ b/tests/unit/out/refcount/union_nested.rs @@ -25,16 +25,6 @@ pub struct record { #[array_len(14)] pub pad: Box<[i8]>, } -impl Default for record { - fn default() -> Self { - { - record { - code: 0_u16, - pad: (0..14).map(|_| 0_i8).collect::>(), - } - } - } -} #[derive( VaArg, FnPtrArg, @@ -59,13 +49,6 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 128]), - } - } -} #[derive( Clone, Record, @@ -75,7 +58,6 @@ impl Default for anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(128)] pub struct inner { @@ -107,13 +89,6 @@ impl anon_1 { this.reinterpret_cast() } } -impl Default for anon_1 { - fn default() -> Self { - anon_1 { - __bytes: Box::from([0u8; 128]), - } - } -} #[derive( Clone, Record, @@ -123,7 +98,6 @@ impl Default for anon_1 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(144)] pub struct Outer { diff --git a/tests/unit/out/refcount/union_pointer_pun_address.rs b/tests/unit/out/refcount/union_pointer_pun_address.rs index 69aea799ce..1956fff003 100644 --- a/tests/unit/out/refcount/union_pointer_pun_address.rs +++ b/tests/unit/out/refcount/union_pointer_pun_address.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(4)] pub struct node_a { @@ -32,7 +31,6 @@ pub struct node_a { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct node_b { @@ -79,11 +77,4 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 8]), - } - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/union_pointer_pun_writethrough.rs b/tests/unit/out/refcount/union_pointer_pun_writethrough.rs index c256754f30..f73852ebbc 100644 --- a/tests/unit/out/refcount/union_pointer_pun_writethrough.rs +++ b/tests/unit/out/refcount/union_pointer_pun_writethrough.rs @@ -42,11 +42,4 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 8]), - } - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/union_struct_dual_use.rs b/tests/unit/out/refcount/union_struct_dual_use.rs index 734892b9fe..660d5bbd93 100644 --- a/tests/unit/out/refcount/union_struct_dual_use.rs +++ b/tests/unit/out/refcount/union_struct_dual_use.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct Inner { @@ -52,13 +51,6 @@ impl anon_1 { this.reinterpret_cast() } } -impl Default for anon_1 { - fn default() -> Self { - anon_1 { - __bytes: Box::from([0u8; 16]), - } - } -} #[derive( Clone, Record, @@ -68,7 +60,6 @@ impl Default for anon_1 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct Outer { diff --git a/tests/unit/out/refcount/union_tagged_many_arms.rs b/tests/unit/out/refcount/union_tagged_many_arms.rs index 83cc27c144..c78f508927 100644 --- a/tests/unit/out/refcount/union_tagged_many_arms.rs +++ b/tests/unit/out/refcount/union_tagged_many_arms.rs @@ -45,13 +45,6 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 8]), - } - } -} #[derive( Clone, Record, @@ -61,7 +54,6 @@ impl Default for anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct Slot { diff --git a/tests/unit/out/refcount/union_tagged_simple.rs b/tests/unit/out/refcount/union_tagged_simple.rs index 8ecd6d388a..5c5aa3e294 100644 --- a/tests/unit/out/refcount/union_tagged_simple.rs +++ b/tests/unit/out/refcount/union_tagged_simple.rs @@ -33,13 +33,6 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 8]), - } - } -} #[derive( Clone, Record, @@ -49,7 +42,6 @@ impl Default for anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(24)] pub struct Event { diff --git a/tests/unit/out/refcount/union_tagged_struct_arms.rs b/tests/unit/out/refcount/union_tagged_struct_arms.rs index 38b2f15ac3..d018cb0f4d 100644 --- a/tests/unit/out/refcount/union_tagged_struct_arms.rs +++ b/tests/unit/out/refcount/union_tagged_struct_arms.rs @@ -19,7 +19,6 @@ pub const Choice_enum_C_INTEGERS: Choice_enum = 3; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(24)] pub struct anon_1 { @@ -41,7 +40,6 @@ pub struct anon_1 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct anon_2 { @@ -64,7 +62,6 @@ pub struct anon_2 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(40)] pub struct anon_3 { @@ -106,13 +103,6 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 40]), - } - } -} #[derive( Clone, Record, @@ -122,7 +112,6 @@ impl Default for anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(48)] pub struct Branch { diff --git a/tests/unit/out/refcount/union_void_ptr_sized_deref.rs b/tests/unit/out/refcount/union_void_ptr_sized_deref.rs index 4193557584..5b9806a2ca 100644 --- a/tests/unit/out/refcount/union_void_ptr_sized_deref.rs +++ b/tests/unit/out/refcount/union_void_ptr_sized_deref.rs @@ -40,13 +40,6 @@ impl anon_0 { this.reinterpret_cast() } } -impl Default for anon_0 { - fn default() -> Self { - anon_0 { - __bytes: Box::from([0u8; 8]), - } - } -} #[derive( Clone, Record, @@ -56,7 +49,6 @@ impl Default for anon_0 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct Sink { diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index b8555ff7db..873eeec91b 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -6,9 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] @@ -28,7 +26,12 @@ impl SafePointer { }); } pub fn constructor_1(this: Ptr) { - field!(this, ptr).write(None); + this.write(::default()); + } +} +impl Default for SafePointer { + fn default() -> Self { + { SafePointer { ptr: None } } } } #[derive( @@ -41,7 +44,6 @@ impl SafePointer { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/unique_ptr_const_deref.rs b/tests/unit/out/refcount/unique_ptr_const_deref.rs index af51ec923f..0854af109a 100644 --- a/tests/unit/out/refcount/unique_ptr_const_deref.rs +++ b/tests/unit/out/refcount/unique_ptr_const_deref.rs @@ -6,9 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] @@ -21,7 +19,12 @@ pub struct Holder { } impl Holder { pub fn constructor_1(this: Ptr) { - field!(this, val).write(None); + this.write(::default()); + } +} +impl Default for Holder { + fn default() -> Self { + { Holder { val: None } } } } pub fn read_val_0(mut h: Ptr) -> i32 { @@ -35,7 +38,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(h, Holder::constructor_1()); + let h: Value = Rc::new(RefCell::new(::default())); { (*h.borrow_mut()).val = Some(Rc::new(RefCell::new(10))).take(); }; diff --git a/tests/unit/out/refcount/unique_ptr_field_reset.rs b/tests/unit/out/refcount/unique_ptr_field_reset.rs index 6a752b9461..10f27499dc 100644 --- a/tests/unit/out/refcount/unique_ptr_field_reset.rs +++ b/tests/unit/out/refcount/unique_ptr_field_reset.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -25,9 +24,7 @@ pub struct Data { #[offset(0)] pub v: i32, } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] @@ -45,8 +42,17 @@ impl Holder { field_ptr!(this, data).write(p.to_owned_opt()); } pub fn constructor_1(this: Ptr) { - field!(this, data).write(None); - field!(this, n).write(0_i32); + this.write(::default()); + } +} +impl Default for Holder { + fn default() -> Self { + { + Holder { + data: None, + n: 0_i32, + } + } } } thread_local!( @@ -65,7 +71,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(h, Holder::constructor_1()); + let h: Value = Rc::new(RefCell::new(::default())); (*h.borrow_mut()).n = 1; let mut hp: Ptr = (h.as_pointer()); field_ptr!(hp, data).write(Ptr::alloc(Data { v: 3 }).to_owned_opt()); diff --git a/tests/unit/out/refcount/unique_ptr_nested.rs b/tests/unit/out/refcount/unique_ptr_nested.rs index 1935680037..e9f7f6fde2 100644 --- a/tests/unit/out/refcount/unique_ptr_nested.rs +++ b/tests/unit/out/refcount/unique_ptr_nested.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -27,9 +26,7 @@ pub struct Inner { #[offset(4)] pub y: i32, } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] @@ -42,7 +39,12 @@ pub struct Outer { } impl Outer { pub fn constructor_1(this: Ptr) { - field!(this, inner).write(None); + this.write(::default()); + } +} +impl Default for Outer { + fn default() -> Self { + { Outer { inner: None } } } } pub fn main() { diff --git a/tests/unit/out/refcount/unique_ptr_struct.rs b/tests/unit/out/refcount/unique_ptr_struct.rs index 25ab325abf..cddf8ae352 100644 --- a/tests/unit/out/refcount/unique_ptr_struct.rs +++ b/tests/unit/out/refcount/unique_ptr_struct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/va_arg_mixed_types.rs b/tests/unit/out/refcount/va_arg_mixed_types.rs index 15514399be..e6aa650efb 100644 --- a/tests/unit/out/refcount/va_arg_mixed_types.rs +++ b/tests/unit/out/refcount/va_arg_mixed_types.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct pair { diff --git a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs index b3b8484a2f..c9aa3482f4 100644 --- a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct node { diff --git a/tests/unit/out/refcount/va_arg_struct_ctx.rs b/tests/unit/out/refcount/va_arg_struct_ctx.rs index bff2e8b664..df67927634 100644 --- a/tests/unit/out/refcount/va_arg_struct_ctx.rs +++ b/tests/unit/out/refcount/va_arg_struct_ctx.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(8)] pub struct context { @@ -58,13 +57,6 @@ impl value { this.reinterpret_cast() } } -impl Default for value { - fn default() -> Self { - value { - __bytes: Box::from([0u8; 8]), - } - } -} pub fn pick_1(use_long: i32, __args: Box<[VaArg]>) -> i64 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let use_long: Value = Rc::new(RefCell::new(use_long)); diff --git a/tests/unit/out/refcount/va_arg_void_ptr.rs b/tests/unit/out/refcount/va_arg_void_ptr.rs index f852755b22..b8830ddff5 100644 --- a/tests/unit/out/refcount/va_arg_void_ptr.rs +++ b/tests/unit/out/refcount/va_arg_void_ptr.rs @@ -15,7 +15,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, )] #[byte_size(16)] pub struct registry { diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index fc4a2b93e2..1441301b03 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -84,7 +84,6 @@ pub fn sum_ptr_2(n: i32, __args: Box<[VaArg]>) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 7d9809b4eb..51acda23b6 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ pub fn copy_0(mut copy_vector: Vec) {} Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -54,8 +52,17 @@ pub struct Foo { } impl Foo { pub fn constructor_1(this: Ptr) { - field!(this, a).write(Vec::new()); - field!(this, b).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Foo { + fn default() -> Self { + { + Foo { + a: Vec::new(), + b: Vec::new(), + } + } } } #[derive( @@ -68,7 +75,6 @@ impl Foo { FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -558,7 +564,7 @@ fn main_0() -> i32 { && ({ (*v11.borrow())[2_usize] } == 3) }) ); - object!(foo, Foo::constructor_1()); + let foo: Value = Rc::new(RefCell::new(::default())); ({ let __tmp_22: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index 258b666ca4..8a8f94734b 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, DefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -41,7 +40,6 @@ impl Degrees { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index 1b9a9a024e..f0205013c5 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -43,7 +42,6 @@ impl Point { Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -60,8 +58,17 @@ pub struct Holder { } impl Holder { pub fn constructor_1(this: Ptr) { - field!(this, values).write(Vec::new()); - field!(this, points).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Holder { + fn default() -> Self { + { + Holder { + values: Vec::new(), + points: Vec::new(), + } + } } } pub fn push_and_index_0(v: Ptr>) -> i32 { @@ -120,7 +127,7 @@ fn main_0() -> i32 { p.write(9); assert!(({ (*v.borrow())[2_usize] } == 9)); assert!((({ sum_ref_1(v.as_pointer(),) }) == ((((3 + 0) + 9) + 42) + 5))); - object!(h, Holder::constructor_1()); + let h: Value = Rc::new(RefCell::new(::default())); (*h.borrow_mut()).values.resize_with(2_usize, || 0_i32); vec_elem!(h.as_pointer(), values, 1_usize).write(6); ({ diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index a3c027a626..3d4e4ddfd8 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -16,7 +16,6 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -40,7 +39,6 @@ impl TestAllocator_int_ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 65c08c7ed9..3c929d5552 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -18,7 +18,6 @@ pub fn unused_param_0(mut x: i32) {} Memberwise, CopyConstructible, Swappable, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] @@ -32,7 +31,12 @@ pub struct NonTrivial { } impl NonTrivial { pub fn constructor_1(this: Ptr) { - field!(this, data).write(Vec::new()); + this.write(::default()); + } +} +impl Default for NonTrivial { + fn default() -> Self { + { NonTrivial { data: Vec::new() } } } } pub fn unused_ref_param_1(x: Ptr) {} @@ -54,7 +58,6 @@ pub fn bump_and_return_4() -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, - Default, Conversions, )] #[conversions(copy, move)] @@ -63,9 +66,7 @@ pub struct Holder { #[offset(0)] pub field: i32, } -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] @@ -78,7 +79,12 @@ pub struct NonCopyable { } impl NonCopyable { pub fn constructor_1(this: Ptr) { - field!(this, value).write(None); + this.write(::default()); + } +} +impl Default for NonCopyable { + fn default() -> Self { + { NonCopyable { value: None } } } } pub fn unused_noncopyable_param_5(x: Ptr) {} @@ -129,7 +135,7 @@ fn main_0() -> i32 { let mut arr: [i32; 3] = [1, 2, 3]; let h: Value = Rc::new(RefCell::new(Holder { field: 17 })); let mut hp: Ptr = (h.as_pointer()); - object!(nt, NonTrivial::constructor_1()); + let nt: Value = Rc::new(RefCell::new(::default())); ({ unused_ref_param_1(nt.as_pointer()) }); ({ unused_ptr_param_2((nt.as_pointer())) }); let g: Value = Rc::new(RefCell::new(NonCopyable { diff --git a/tests/unit/out/unsafe/05_new.rs b/tests/unit/out/unsafe/05_new.rs index 15c795f57f..3499c17df3 100644 --- a/tests/unit/out/unsafe/05_new.rs +++ b/tests/unit/out/unsafe/05_new.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -29,7 +28,6 @@ pub struct A {} ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/10_struct.rs b/tests/unit/out/unsafe/10_struct.rs index 3a1746e7b8..ed3b7198d9 100644 --- a/tests/unit/out/unsafe/10_struct.rs +++ b/tests/unit/out/unsafe/10_struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct GraphNode { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -70,7 +68,7 @@ pub struct Partial { } impl Partial { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).p).write(std::ptr::null_mut()); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, q: PointerUnsafe) { let mut q = (q.as_ptr() as *mut i32); @@ -95,7 +93,6 @@ impl Default for Partial { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -110,7 +107,6 @@ impl Declared {} ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -137,7 +133,7 @@ unsafe fn main_0() -> i32 { if ((it.p) != (arr.as_mut_ptr())) { return 1; } - object_unsafe!(def, Partial::constructor_1()); + let mut def: Partial = ::default(); if !((def.p).is_null()) { return 1; } diff --git a/tests/unit/out/unsafe/addr_of_global.rs b/tests/unit/out/unsafe/addr_of_global.rs index 7a6ba57664..3a959bc6be 100644 --- a/tests/unit/out/unsafe/addr_of_global.rs +++ b/tests/unit/out/unsafe/addr_of_global.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -31,7 +30,6 @@ pub struct Inner { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/anonymous-struct.rs b/tests/unit/out/unsafe/anonymous-struct.rs index d5e0bb02e4..d2197cec3a 100644 --- a/tests/unit/out/unsafe/anonymous-struct.rs +++ b/tests/unit/out/unsafe/anonymous-struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct Outer_Named { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -49,7 +47,6 @@ pub struct anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -66,7 +63,6 @@ pub struct anon_1 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -83,7 +79,6 @@ pub struct anon_2 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -99,7 +94,6 @@ pub struct anon_4 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -115,7 +109,6 @@ pub struct anon_5 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -133,7 +126,6 @@ pub struct anon_3 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -200,7 +192,6 @@ unsafe fn main_0() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/anonymous-struct_c.rs b/tests/unit/out/unsafe/anonymous-struct_c.rs index b0a56bd075..4d264d67cb 100644 --- a/tests/unit/out/unsafe/anonymous-struct_c.rs +++ b/tests/unit/out/unsafe/anonymous-struct_c.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Named { pub a: i32, @@ -30,7 +29,6 @@ pub struct Named { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_0 { pub c: i32, @@ -45,7 +43,6 @@ pub struct anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_1 { pub g: i32, @@ -60,7 +57,6 @@ pub struct anon_1 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_2 { pub e: i32, @@ -75,7 +71,6 @@ pub struct anon_2 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_4 { pub j: i32, @@ -89,7 +84,6 @@ pub struct anon_4 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_5 { pub k: i32, @@ -103,7 +97,6 @@ pub struct anon_5 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_3 { pub i: i32, @@ -119,7 +112,6 @@ pub struct anon_3 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Outer { pub named: Named, @@ -190,7 +182,6 @@ unsafe fn main_0() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_6 { pub x: i32, diff --git a/tests/unit/out/unsafe/anonymous_enum.rs b/tests/unit/out/unsafe/anonymous_enum.rs index 8f10b7516a..a591273c9f 100644 --- a/tests/unit/out/unsafe/anonymous_enum.rs +++ b/tests/unit/out/unsafe/anonymous_enum.rs @@ -21,7 +21,6 @@ pub const anon_1_SECOND_B: anon_1 = 1; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -43,7 +42,6 @@ pub const anon_2_FIELD_B: anon_2 = 1; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/anonymous_enum_c.rs b/tests/unit/out/unsafe/anonymous_enum_c.rs index 74794bce29..e5af35ceb3 100644 --- a/tests/unit/out/unsafe/anonymous_enum_c.rs +++ b/tests/unit/out/unsafe/anonymous_enum_c.rs @@ -21,7 +21,6 @@ pub const anon_1_SECOND_B: anon_1 = 1; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct S { pub a: i32, @@ -41,7 +40,6 @@ pub const anon_2_FIELD_B: anon_2 = 1; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct WithAnonField { pub a: i32, diff --git a/tests/unit/out/unsafe/any.rs b/tests/unit/out/unsafe/any.rs index 6aa4d696a0..1e20735408 100644 --- a/tests/unit/out/unsafe/any.rs +++ b/tests/unit/out/unsafe/any.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/array_const_init.rs b/tests/unit/out/unsafe/array_const_init.rs index 4c1845c3e7..2ff1123949 100644 --- a/tests/unit/out/unsafe/array_const_init.rs +++ b/tests/unit/out/unsafe/array_const_init.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct S { pub head: i32, @@ -38,7 +37,6 @@ pub static mut s_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct P { pub x: i32, diff --git a/tests/unit/out/unsafe/array_field_addr.rs b/tests/unit/out/unsafe/array_field_addr.rs index 268f5269a2..4bd44772cf 100644 --- a/tests/unit/out/unsafe/array_field_addr.rs +++ b/tests/unit/out/unsafe/array_field_addr.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct S { pub before: i32, diff --git a/tests/unit/out/unsafe/array_of_noncopy_struct.rs b/tests/unit/out/unsafe/array_of_noncopy_struct.rs index 2525d2f09d..37fbbc9653 100644 --- a/tests/unit/out/unsafe/array_of_noncopy_struct.rs +++ b/tests/unit/out/unsafe/array_of_noncopy_struct.rs @@ -27,15 +27,14 @@ pub struct NonCopy { } impl NonCopy { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).data).write(Vec::new()); - (&raw mut (*this).tag).write(0); + this.write(::default()); } } impl Default for NonCopy { fn default() -> Self { unsafe { NonCopy { - data: Default::default(), + data: Vec::new(), tag: 0, } } @@ -48,11 +47,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut arr: [NonCopy; 3] = std::array::from_fn::<_, 3, _>(|_| { - let mut __v: NonCopy = ZeroInitializationUnsafe::zero_init(); - NonCopy::constructor_1(&raw mut __v); - __v - }); + let mut arr: [NonCopy; 3] = std::array::from_fn::<_, 3, _>(|_| ::default()); arr[(0) as usize].tag = 7; { let mut __tmp_0: i32 = 42; diff --git a/tests/unit/out/unsafe/array_reference.rs b/tests/unit/out/unsafe/array_reference.rs index c68b203715..4a6ddb347a 100644 --- a/tests/unit/out/unsafe/array_reference.rs +++ b/tests/unit/out/unsafe/array_reference.rs @@ -65,7 +65,6 @@ pub unsafe fn pick_10(s: *const [libc::c_char; 5]) -> *const [libc::c_char; 5] { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/as_const.rs b/tests/unit/out/unsafe/as_const.rs index 4e5e74334d..3ea0014cf4 100644 --- a/tests/unit/out/unsafe/as_const.rs +++ b/tests/unit/out/unsafe/as_const.rs @@ -18,7 +18,6 @@ pub const Overload_kConstOverload: Overload = 2; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/assign_rhs_first.rs b/tests/unit/out/unsafe/assign_rhs_first.rs index d0f7762a62..08c425ead7 100644 --- a/tests/unit/out/unsafe/assign_rhs_first.rs +++ b/tests/unit/out/unsafe/assign_rhs_first.rs @@ -21,7 +21,6 @@ pub unsafe fn advance_1() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index ebf3f25628..d39ad47781 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -844,7 +844,6 @@ pub unsafe fn test_reference_members_9() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -860,7 +859,6 @@ pub struct Slot_6 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -876,7 +874,6 @@ pub struct Slot_8 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -936,7 +933,6 @@ pub unsafe fn test_pointer_elements_11() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -973,7 +969,6 @@ pub unsafe fn test_reference_pointer_13() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -1057,7 +1052,6 @@ pub unsafe fn test_reference_subfields_18() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -1073,7 +1067,6 @@ pub struct Index_16 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -1089,7 +1082,6 @@ pub struct Slot_17 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -1105,7 +1097,6 @@ pub struct Index_19 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -1156,7 +1147,6 @@ pub unsafe fn observe_24(mut assigned: i32, mut stored: *const i32) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -1172,7 +1162,6 @@ pub struct GlobalRecord_Inner { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -1449,7 +1438,6 @@ static mut flag_31: std::cell::LazyCell = std::cell::LazyCell::new(|| unsa ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -1465,7 +1453,6 @@ pub struct Record_32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -1483,7 +1470,6 @@ pub static mut selected_values_34: std::cell::LazyCell<[u32; 3]> = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -1713,7 +1699,6 @@ pub static mut global_rows_46: std::cell::LazyCell<[[u32; 2]; 2]> = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -1983,7 +1968,6 @@ pub static mut scoped_pointers_53: std::cell::LazyCell<[*mut u32; 1]> = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -2159,7 +2143,6 @@ pub unsafe fn test_stable_containers_58() { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -2170,7 +2153,12 @@ pub struct Counts_59 { } impl Counts_59 { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).counts).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Counts_59 { + fn default() -> Self { + unsafe { Counts_59 { counts: Vec::new() } } } } #[repr(C)] @@ -2182,7 +2170,6 @@ impl Counts_59 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -2495,7 +2482,6 @@ unsafe fn main_0() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -2511,7 +2497,6 @@ pub struct Index_62 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/bounded_struct_ptr.rs b/tests/unit/out/unsafe/bounded_struct_ptr.rs index 55e6c1e43b..3f9a117c97 100644 --- a/tests/unit/out/unsafe/bounded_struct_ptr.rs +++ b/tests/unit/out/unsafe/bounded_struct_ptr.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/bst.rs b/tests/unit/out/unsafe/bst.rs index 37605e38a8..b7ad903f49 100644 --- a/tests/unit/out/unsafe/bst.rs +++ b/tests/unit/out/unsafe/bst.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/c_struct.rs b/tests/unit/out/unsafe/c_struct.rs index 00cfcdd988..3766c56432 100644 --- a/tests/unit/out/unsafe/c_struct.rs +++ b/tests/unit/out/unsafe/c_struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Point { pub x: i32, @@ -30,7 +29,6 @@ pub struct Point { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Line { pub start: Point, @@ -45,7 +43,6 @@ pub struct Line { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Node { pub value: i32, @@ -64,7 +61,6 @@ pub const Color_BLUE: Color = 2; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Inner { pub a: i32, @@ -79,7 +75,6 @@ pub struct Inner { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Container { pub inner: Inner, diff --git a/tests/unit/out/unsafe/cast.rs b/tests/unit/out/unsafe/cast.rs index 49f7e8d1f1..4bc3dca4f2 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -19,7 +19,6 @@ pub const E_C: E = 2; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -36,7 +35,6 @@ pub struct Pair { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -52,7 +50,6 @@ pub struct Wide { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -71,7 +68,6 @@ pub struct Grid { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -83,8 +79,17 @@ pub struct Bag { } impl Bag { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).n).write(0_i32); - (&raw mut (*this).items).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Bag { + fn default() -> Self { + unsafe { + Bag { + n: 0_i32, + items: Vec::new(), + } + } } } pub unsafe fn adjacent_arrays_0() { @@ -329,7 +334,7 @@ pub unsafe fn nested_5() { assert!(((m[(1) as usize][(1) as usize]) == (42))); assert!(((pm) == (&mut m[(1) as usize][(1) as usize] as *mut i32))); assert!(((pm) < (&mut m[(2) as usize][(0) as usize] as *mut i32))); - object_unsafe!(b, Bag::constructor_1()); + let mut b: Bag = ::default(); if 4_usize > b.items.capacity() as usize { let len_0 = b.items.len(); b.items.reserve_exact(4_usize - len_0 as usize); diff --git a/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs b/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs index 8af40a1171..8fbe0cc808 100644 --- a/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs +++ b/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs @@ -25,7 +25,6 @@ pub unsafe fn strlen_1(mut s: *mut libc::c_char) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index fd2a3eea1b..06ee0106c8 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -61,7 +60,6 @@ impl Pair { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -85,7 +83,6 @@ impl Route { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -108,7 +105,6 @@ impl Counter { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/class_template_lazy_member.rs b/tests/unit/out/unsafe/class_template_lazy_member.rs index 489f9a4684..8387666a64 100644 --- a/tests/unit/out/unsafe/class_template_lazy_member.rs +++ b/tests/unit/out/unsafe/class_template_lazy_member.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -31,7 +30,6 @@ pub struct Point { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -52,7 +50,6 @@ impl Box_int_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -73,7 +70,6 @@ impl Box_Point_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -94,7 +90,6 @@ impl Deduced_int_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/class_templates.rs b/tests/unit/out/unsafe/class_templates.rs index f8e23d09af..200252f974 100644 --- a/tests/unit/out/unsafe/class_templates.rs +++ b/tests/unit/out/unsafe/class_templates.rs @@ -16,7 +16,6 @@ use std::rc::Rc; MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -46,7 +45,12 @@ impl MyContainer_int_ { (*this).vec_.push_copied(item); } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).vec_).write(Vec::new()); + this.write(::default()); + } +} +impl Default for MyContainer_int_ { + fn default() -> Self { + unsafe { MyContainer_int_ { vec_: Vec::new() } } } } #[repr(C)] @@ -59,7 +63,6 @@ impl MyContainer_int_ { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -89,7 +92,12 @@ impl MyContainer_char_ { (*this).vec_.push_copied(item); } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).vec_).write(Vec::new()); + this.write(::default()); + } +} +impl Default for MyContainer_char_ { + fn default() -> Self { + unsafe { MyContainer_char_ { vec_: Vec::new() } } } } #[repr(C)] @@ -102,7 +110,6 @@ impl MyContainer_char_ { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -132,7 +139,12 @@ impl MyContainer_float_ { (*this).vec_.push_copied(item); } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).vec_).write(Vec::new()); + this.write(::default()); + } +} +impl Default for MyContainer_float_ { + fn default() -> Self { + unsafe { MyContainer_float_ { vec_: Vec::new() } } } } #[repr(C)] @@ -144,7 +156,6 @@ impl MyContainer_float_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -168,7 +179,6 @@ impl Boxed_short_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -192,7 +202,6 @@ impl Boxed_int_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -216,7 +225,6 @@ impl Boxed_long_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -238,7 +246,6 @@ impl Outer_int__Inner_int_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -259,7 +266,6 @@ impl Outer_int_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -281,7 +287,6 @@ impl Outer_long__Inner_int_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -303,7 +308,6 @@ impl Outer_long__Inner_char_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -324,7 +328,6 @@ impl Outer_long_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -371,7 +374,7 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { Boxed_long_::twice(10_i64,) }) == (20_i64))); let mut bl: Boxed_long_ = Boxed_long_ { value: 7_i64 }; assert!(((unsafe { Boxed_long_::plus(&raw const bl, 1_i64,) }) == (8_i64))); - object_unsafe!(imc, MyContainer_int_::constructor_1()); + let mut imc: MyContainer_int_ = ::default(); assert!((unsafe { MyContainer_int_::empty(&raw const imc,) })); (unsafe { let mut _item: i32 = 1; @@ -383,7 +386,7 @@ unsafe fn main_0() -> i32 { ); (unsafe { MyContainer_int_::pop_back(&raw mut imc) }); assert!((unsafe { MyContainer_int_::empty(&raw const imc,) })); - object_unsafe!(cmc, MyContainer_char_::constructor_1()); + let mut cmc: MyContainer_char_ = ::default(); assert!((unsafe { MyContainer_char_::empty(&raw const cmc,) })); (unsafe { let mut _item: libc::c_char = ('a' as libc::c_char); @@ -396,7 +399,7 @@ unsafe fn main_0() -> i32 { ); (unsafe { MyContainer_char_::pop_back(&raw mut cmc) }); assert!((unsafe { MyContainer_char_::empty(&raw const cmc,) })); - object_unsafe!(fmc, MyContainer_float_::constructor_1()); + let mut fmc: MyContainer_float_ = ::default(); assert!((unsafe { MyContainer_float_::empty(&raw const fmc,) })); (unsafe { let mut _item: f32 = (1_f64 as f32); diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index 5f4a43f0d3..300b816b88 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -31,7 +30,6 @@ pub struct Bar { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -51,7 +49,6 @@ pub struct Foo { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/comma_operator.rs b/tests/unit/out/unsafe/comma_operator.rs index e45b678f5b..b4d8389b70 100644 --- a/tests/unit/out/unsafe/comma_operator.rs +++ b/tests/unit/out/unsafe/comma_operator.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/complex_function.rs b/tests/unit/out/unsafe/complex_function.rs index e7fd5acef1..d46677eb19 100644 --- a/tests/unit/out/unsafe/complex_function.rs +++ b/tests/unit/out/unsafe/complex_function.rs @@ -24,7 +24,6 @@ pub unsafe fn bar_2(x: *mut i32) -> *mut i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -40,7 +39,6 @@ pub struct X1 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -61,7 +59,6 @@ impl X2 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -82,7 +79,6 @@ impl X3 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/compound_assign_paren.rs b/tests/unit/out/unsafe/compound_assign_paren.rs index f7fb2d99ac..e30222c16b 100644 --- a/tests/unit/out/unsafe/compound_assign_paren.rs +++ b/tests/unit/out/unsafe/compound_assign_paren.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/concepts.rs b/tests/unit/out/unsafe/concepts.rs index 1a49420df5..bb4c65f2b7 100644 --- a/tests/unit/out/unsafe/concepts.rs +++ b/tests/unit/out/unsafe/concepts.rs @@ -20,7 +20,6 @@ const _: () = assert!( ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/constexpr_function.rs b/tests/unit/out/unsafe/constexpr_function.rs index e3ad223505..e023810b37 100644 --- a/tests/unit/out/unsafe/constexpr_function.rs +++ b/tests/unit/out/unsafe/constexpr_function.rs @@ -30,7 +30,6 @@ pub unsafe fn half_3(mut x: f64) -> f64 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -68,7 +67,6 @@ pub unsafe fn imm_7(mut b: bool) -> bool { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/constructor.rs b/tests/unit/out/unsafe/constructor.rs index 9e158e1fb5..e33f82f0d6 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -78,17 +78,6 @@ impl Point { (*this).x += 100; } } -impl Default for Point { - fn default() -> Self { - unsafe { - { - let mut __v: Point = ZeroInitializationUnsafe::zero_init(); - Point::constructor_3(&raw mut __v); - __v - } - } - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/container_element_receiver.rs b/tests/unit/out/unsafe/container_element_receiver.rs index c7b686a2e7..740df5a93c 100644 --- a/tests/unit/out/unsafe/container_element_receiver.rs +++ b/tests/unit/out/unsafe/container_element_receiver.rs @@ -18,7 +18,6 @@ use std::rc::Rc; CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor)] #[derive(ConversionsUnsafe)] diff --git a/tests/unit/out/unsafe/container_field_addr.rs b/tests/unit/out/unsafe/container_field_addr.rs index 8d7181e194..9184fdca7f 100644 --- a/tests/unit/out/unsafe/container_field_addr.rs +++ b/tests/unit/out/unsafe/container_field_addr.rs @@ -16,7 +16,6 @@ use std::rc::Rc; MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -28,8 +27,17 @@ pub struct S { } impl S { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).tag).write(0_i32); - (&raw mut (*this).v).write(Vec::new()); + this.write(::default()); + } +} +impl Default for S { + fn default() -> Self { + unsafe { + S { + tag: 0_i32, + v: Vec::new(), + } + } } } pub unsafe fn add_0(mut v: *mut Vec, mut k: i32) { @@ -58,14 +66,10 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(local, S::constructor_1()); + let mut local: S = ::default(); local.tag = 7; (unsafe { run_1((&mut local as *mut S)) }); - let mut heap: *mut S = { - let __p: *mut S = Box::leak(Box::new(::zero_init())); - S::constructor_1(__p); - __p - }; + let mut heap: *mut S = (Box::leak(Box::new(::default())) as *mut S); (*heap).tag = 7; (unsafe { run_1(heap) }); { diff --git a/tests/unit/out/unsafe/conversion_operator_same_translation.rs b/tests/unit/out/unsafe/conversion_operator_same_translation.rs index 4c1a73b75e..5055a3c4f4 100644 --- a/tests/unit/out/unsafe/conversion_operator_same_translation.rs +++ b/tests/unit/out/unsafe/conversion_operator_same_translation.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -41,7 +40,6 @@ impl S { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 405d122f4c..debf6b87bf 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -15,7 +15,6 @@ pub static mut assigns_0: std::cell::LazyCell = std::cell::LazyCell::new(|| MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy)] @@ -65,7 +64,7 @@ pub struct NonConstAssign { } impl NonConstAssign { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).mark).write(0); + this.write(::default()); } pub unsafe fn operator_assign_2( this: *mut Self, @@ -84,13 +83,7 @@ impl NonConstAssign { } impl Default for NonConstAssign { fn default() -> Self { - unsafe { - { - let mut __v: NonConstAssign = ZeroInitializationUnsafe::zero_init(); - NonConstAssign::constructor_1(&raw mut __v); - __v - } - } + unsafe { NonConstAssign { mark: 0 } } } } #[repr(C)] @@ -112,7 +105,7 @@ pub struct RefQualified { } impl RefQualified { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).mark).write(0); + this.write(::default()); } } impl CopyAssignableUnsafe for RefQualified { @@ -127,13 +120,7 @@ impl CopyAssignableUnsafe for RefQualified { } impl Default for RefQualified { fn default() -> Self { - unsafe { - { - let mut __v: RefQualified = ZeroInitializationUnsafe::zero_init(); - RefQualified::constructor_1(&raw mut __v); - __v - } - } + unsafe { RefQualified { mark: 0 } } } } #[repr(C)] @@ -143,7 +130,6 @@ impl Default for RefQualified { DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -163,7 +149,6 @@ pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] @@ -190,7 +175,6 @@ impl CopyCounted { DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] #[derive(ConversionsUnsafe)] @@ -209,7 +193,6 @@ impl HasCopyCounted {} DestructibleUnsafe, CopyConstructibleUnsafe, MovableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy)] @@ -219,7 +202,7 @@ pub struct ExplicitOperatorCall { } impl ExplicitOperatorCall { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).w).write(Vec::new()); + this.write(::default()); } } impl CopyAssignableUnsafe for ExplicitOperatorCall { @@ -234,6 +217,11 @@ impl CopyAssignableUnsafe for ExplicitOperatorCall { return &mut (*this); } } +impl Default for ExplicitOperatorCall { + fn default() -> Self { + unsafe { ExplicitOperatorCall { w: Vec::new() } } + } +} pub static mut swap_copies_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( @@ -242,7 +230,6 @@ pub static mut swap_copies_2: std::cell::LazyCell = std::cell::LazyCell::ne DefaultInitializableUnsafe, MoveConstructibleUnsafe, SwappableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy)] @@ -297,7 +284,6 @@ impl MoveAssignableUnsafe for Swapped { DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -326,7 +312,7 @@ pub struct VoidAssign { } impl VoidAssign { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).x).write(0); + this.write(::default()); } pub unsafe fn copy_assign(this: *mut Self, o: *const VoidAssign) { (*this).x = (((*o).x) + (5)); @@ -346,13 +332,7 @@ impl MoveAssignableUnsafe for VoidAssign { } impl Default for VoidAssign { fn default() -> Self { - unsafe { - { - let mut __v: VoidAssign = ZeroInitializationUnsafe::zero_init(); - VoidAssign::constructor_1(&raw mut __v); - __v - } - } + unsafe { VoidAssign { x: 0 } } } } #[repr(C)] @@ -366,7 +346,6 @@ impl Default for VoidAssign { MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] @@ -377,7 +356,16 @@ pub struct HoldsVoidAssign { } impl HoldsVoidAssign { pub unsafe fn constructor_1(this: *mut Self) { - VoidAssign::constructor_1(&raw mut (*this).v); + this.write(::default()); + } +} +impl Default for HoldsVoidAssign { + fn default() -> Self { + unsafe { + HoldsVoidAssign { + v: ::default(), + } + } } } pub fn main() { @@ -439,16 +427,16 @@ unsafe fn main_0() -> i32 { assert!(((h.p.v) == (2)) && ((h.p.keep) == (40))); assert!(((h.arr[(1) as usize].v) == (2)) && ((h.arr[(1) as usize].keep) == (60))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (8))); - object_unsafe!(n, NonConstAssign::constructor_1()); - object_unsafe!(n1, NonConstAssign::constructor_1()); - object_unsafe!(n2, NonConstAssign::constructor_1()); - object_unsafe!(cn, NonConstAssign::constructor_1()); + let mut n: NonConstAssign = ::default(); + let mut n1: NonConstAssign = ::default(); + let mut n2: NonConstAssign = ::default(); + let cn: NonConstAssign = ::default(); (unsafe { NonConstAssign::operator_assign_2(&raw mut n1, &mut n) }); (unsafe { NonConstAssign::operator_assign_3(&raw mut n2, &cn) }); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); - object_unsafe!(r, RefQualified::constructor_1()); - object_unsafe!(r1, RefQualified::constructor_1()); + let mut r: RefQualified = ::default(); + let mut r1: RefQualified = ::default(); assign_unsafe!(r1 = r); assert!(((r1.mark) == (1))); let mut h2: Holder = Holder { @@ -522,8 +510,8 @@ unsafe fn main_0() -> i32 { && ((hc1.arr[(1) as usize].v) == (6)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (0))); - object_unsafe!(e1, ExplicitOperatorCall::constructor_1()); - object_unsafe!(e2, ExplicitOperatorCall::constructor_1()); + let mut e1: ExplicitOperatorCall = ::default(); + let mut e2: ExplicitOperatorCall = ::default(); { let mut __tmp_0: i32 = 5; e1.w.push_moved(&mut __tmp_0) @@ -562,8 +550,8 @@ unsafe fn main_0() -> i32 { ((hs1.s.v) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut swap_copies_2)) == (2)) ); - object_unsafe!(hv1, HoldsVoidAssign::constructor_1()); - object_unsafe!(hv2, HoldsVoidAssign::constructor_1()); + let mut hv1: HoldsVoidAssign = ::default(); + let mut hv2: HoldsVoidAssign = ::default(); assign_unsafe!(hv1 = hv2); assert!(((hv1.v.x) == (5))); return 0; diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index e3052cb205..33325125a8 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -16,7 +16,6 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] @@ -57,7 +56,7 @@ pub struct NonConst { } impl NonConst { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).mark).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe) { let o = (o.as_ptr() as *mut NonConst); @@ -70,13 +69,7 @@ impl NonConst { } impl Default for NonConst { fn default() -> Self { - unsafe { - { - let mut __v: NonConst = ZeroInitializationUnsafe::zero_init(); - NonConst::constructor_1(&raw mut __v); - __v - } - } + unsafe { NonConst { mark: 0 } } } } #[repr(C)] @@ -88,7 +81,6 @@ impl Default for NonConst { MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] @@ -115,7 +107,6 @@ impl Ignored { DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] #[derive(ConversionsUnsafe)] @@ -126,9 +117,7 @@ pub struct Holder { } impl Holder {} #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe)] #[memberwise(move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(copy, move)] @@ -147,9 +136,7 @@ impl Box_int_ { } } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe)] #[memberwise(copy_constructor, move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(copy, move)] @@ -166,7 +153,6 @@ impl Owner {} MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] @@ -205,7 +191,7 @@ pub struct Tracked { } impl Tracked { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).copied_from).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Tracked); @@ -259,17 +245,6 @@ impl SelfPtr { (&raw mut (*this).self_).write(this); } } -impl Default for SelfPtr { - fn default() -> Self { - unsafe { - { - let mut __v: SelfPtr = ZeroInitializationUnsafe::zero_init(); - SelfPtr::constructor_1(&raw mut __v); - __v - } - } - } -} #[repr(C)] #[derive( Copy, @@ -279,7 +254,6 @@ impl Default for SelfPtr { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -300,17 +274,6 @@ impl Derived { Counted::constructor_1(&raw mut (*this).c, 20); } } -impl Default for Derived { - fn default() -> Self { - unsafe { - { - let mut __v: Derived = ZeroInitializationUnsafe::zero_init(); - Derived::constructor_1(&raw mut __v); - __v - } - } - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -392,17 +355,17 @@ unsafe fn main_0() -> i32 { object_unsafe!(ol2, OutOfLine::constructor_2(LvalueRefUnsafe::bind(&ol1))); assert!(((ol2.v) == (105))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (12))); - object_unsafe!(n, NonConst::constructor_1()); + let mut n: NonConst = ::default(); object_unsafe!(n1, NonConst::constructor_2(LvalueRefUnsafe::bind(&mut n))); - object_unsafe!(cn, NonConst::constructor_1()); + let cn: NonConst = ::default(); object_unsafe!(n2, NonConst::constructor_3(LvalueRefUnsafe::bind(&cn))); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); - object_unsafe!(t1, Tracked::constructor_1()); + let mut t1: Tracked = ::default(); object_unsafe!(t2, Tracked::constructor_2(LvalueRefUnsafe::bind(&t1))); assign_unsafe!(t2 = t1); assert!(((t1.copied_from) == (2))); - object_unsafe!(ct, Tracked::constructor_1()); + let ct: Tracked = ::default(); object_unsafe!(t3, Tracked::constructor_2(LvalueRefUnsafe::bind(&ct))); (unsafe { touch_1((&ct as *const Tracked)) }); assert!(((ct.copied_from) == (2))); diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index c7a1b84532..ccd8b7f86f 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -62,7 +61,6 @@ impl DestructibleUnsafe for Explicit { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -82,7 +80,6 @@ pub struct Implicit { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] @@ -120,7 +117,6 @@ impl MoveAssignableUnsafe for DefaultCopyUserMove { DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -156,7 +152,6 @@ impl CopyAssignableUnsafe for UserCopyDefaultMove { DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -181,12 +176,7 @@ impl Buffer { } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -200,10 +190,19 @@ pub struct Owner { } impl Owner { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).data).write(Vec::new()); - (&raw mut (*this).n).write(0_i32); - (&raw mut (*this).arr).write([0_i32; 2]); - (&raw mut (*this).p).write(None); + this.write(::default()); + } +} +impl Default for Owner { + fn default() -> Self { + unsafe { + Owner { + data: Vec::new(), + n: 0_i32, + arr: [0_i32; 2], + p: None, + } + } } } #[repr(C)] @@ -216,7 +215,6 @@ impl Owner { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -227,7 +225,12 @@ pub struct Copyable { } impl Copyable { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).data).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Copyable { + fn default() -> Self { + unsafe { Copyable { data: Vec::new() } } } } #[repr(C)] @@ -268,7 +271,7 @@ pub struct SeesThis { } impl SeesThis { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).self_).write(std::ptr::null_mut()); + this.write(::default()); } } impl CopyAssignableUnsafe for SeesThis { @@ -295,7 +298,7 @@ impl Default for SeesThis { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe)] #[memberwise(copy_assign, move_assign)] #[derive(ConversionsUnsafe)] #[constructor(constructor_1)] @@ -305,8 +308,17 @@ pub struct HasSeesThis { } impl HasSeesThis { pub unsafe fn constructor_1(this: *mut Self) { - SeesThis::constructor_1(&raw mut (*this).s); - (&raw mut (*this).v).write(Vec::new()); + this.write(::default()); + } +} +impl Default for HasSeesThis { + fn default() -> Self { + unsafe { + HasSeesThis { + s: ::default(), + v: Vec::new(), + } + } } } #[repr(C)] @@ -322,8 +334,7 @@ pub struct Counted_int_ { } impl Counted_int_ { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(0_i32); - (&raw mut (*this).moves).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Counted_int_); @@ -346,12 +357,7 @@ impl Default for Counted_int_ { } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -363,8 +369,17 @@ pub struct HasCounted { } impl HasCounted { pub unsafe fn constructor_1(this: *mut Self) { - Counted_int_::constructor_1(&raw mut (*this).c); - (&raw mut (*this).w).write(Vec::new()); + this.write(::default()); + } +} +impl Default for HasCounted { + fn default() -> Self { + unsafe { + HasCounted { + c: ::default(), + w: Vec::new(), + } + } } } #[repr(C)] @@ -418,25 +433,9 @@ impl MoveAssignableUnsafe for CtorSeesThis { return &mut (*this); } } -impl Default for CtorSeesThis { - fn default() -> Self { - unsafe { - { - let mut __v: CtorSeesThis = ZeroInitializationUnsafe::zero_init(); - CtorSeesThis::constructor_1(&raw mut __v); - __v - } - } - } -} #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -470,17 +469,6 @@ impl InitsCtorSeesThis { CtorSeesThis::constructor_2(&raw mut (*this).y, 2); } } -impl Default for InitsCtorSeesThis { - fn default() -> Self { - unsafe { - { - let mut __v: InitsCtorSeesThis = ZeroInitializationUnsafe::zero_init(); - InitsCtorSeesThis::constructor_1(&raw mut __v); - __v - } - } - } -} #[repr(C)] #[derive( FnPtrArg, @@ -517,17 +505,6 @@ impl ConstructorUnsafe<()> for OutOfLineDefaulted { } } } -impl Default for OutOfLineDefaulted { - fn default() -> Self { - unsafe { - { - let mut __v: OutOfLineDefaulted = ZeroInitializationUnsafe::zero_init(); - OutOfLineDefaulted::construct(&raw mut __v); - __v - } - } - } -} impl OutOfLineDefaulted {} impl OutOfLineDefaulted {} #[repr(C)] @@ -540,9 +517,7 @@ pub struct OutOfLineAssign { } impl OutOfLineAssign { pub unsafe fn constructor_1(this: *mut Self) { - SeesThis::constructor_1(&raw mut (*this).s); - (&raw mut (*this).v).write(1); - (&raw mut (*this).w).write(Vec::new()); + this.write(::default()); } } impl Default for OutOfLineAssign { @@ -551,7 +526,7 @@ impl Default for OutOfLineAssign { OutOfLineAssign { s: ::default(), v: 1, - w: Default::default(), + w: Vec::new(), } } } @@ -715,7 +690,7 @@ unsafe fn main_0() -> i32 { (((bufs[(1_usize)].n) == (3)) && ((bufs[(1_usize)].data.len()) == (3_usize))) && (bufs[(0_usize)].data.is_empty()) ); - object_unsafe!(o1, Owner::constructor_1()); + let mut o1: Owner = ::default(); { let mut __tmp_2: i32 = 5; o1.data.push_moved(&mut __tmp_2) @@ -750,7 +725,7 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - object_unsafe!(o3, Owner::constructor_1()); + let mut o3: Owner = ::default(); assign_unsafe!(o3 = RvalueRefUnsafe(o2)); assert!( ((((o3.n) == (5)) && ((o3.data[(0_usize)]) == (5))) && ((o3.arr[(0) as usize]) == (5))) @@ -777,7 +752,7 @@ unsafe fn main_0() -> i32 { }); assert!(((c2.data.len()) == (2_usize)) && ((c3.data.len()) == (2_usize))); assert!(c1.data.is_empty()); - object_unsafe!(c4, Copyable::constructor_1()); + let mut c4: Copyable = ::default(); assign_unsafe!(c4 = RvalueRefUnsafe(c3)); assert!(((c4.data[(1_usize)]) == (2)) && (c3.data.is_empty())); object_unsafe!(h1, Holder::constructor_1(4)); @@ -820,14 +795,14 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - object_unsafe!(t1, HasSeesThis::constructor_1()); - object_unsafe!(t2, HasSeesThis::constructor_1()); - object_unsafe!(t3, HasSeesThis::constructor_1()); + let mut t1: HasSeesThis = ::default(); + let mut t2: HasSeesThis = ::default(); + let mut t3: HasSeesThis = ::default(); assign_unsafe!(t2 = RvalueRefUnsafe(t1)); assert!(((t2.s.self_) == (&mut t2.s as *mut SeesThis))); assign_unsafe!(t3 = t2); assert!(((t3.s.self_) == (&mut t3.s as *mut SeesThis))); - object_unsafe!(k1, HasCounted::constructor_1()); + let mut k1: HasCounted = ::default(); object_unsafe!(k2, HasCounted, |k2| { ::move_constructor( k2, @@ -835,7 +810,7 @@ unsafe fn main_0() -> i32 { ) }); assert!(((k2.c.moves) == (1))); - object_unsafe!(k3, HasCounted::constructor_1()); + let mut k3: HasCounted = ::default(); assign_unsafe!(k3 = RvalueRefUnsafe(k2)); assert!(((k3.c.moves) == (2))); { @@ -888,9 +863,9 @@ unsafe fn main_0() -> i32 { OutOfLineDefaulted::constructor_2(LvalueRefUnsafe::bind(&o1)) ); assert!(((o2.v) == (2)) && ((o2.x.self_) == (&mut o2.x as *mut CtorSeesThis))); - object_unsafe!(a1, OutOfLineAssign::constructor_1()); - object_unsafe!(a2, OutOfLineAssign::constructor_1()); - object_unsafe!(a3, OutOfLineAssign::constructor_1()); + let mut a1: OutOfLineAssign = ::default(); + let mut a2: OutOfLineAssign = ::default(); + let mut a3: OutOfLineAssign = ::default(); a1.v = 3; { let mut __tmp_5: i32 = 4; diff --git a/tests/unit/out/unsafe/copy_move_deleted.rs b/tests/unit/out/unsafe/copy_move_deleted.rs index 3824cb5879..b7ea293982 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.rs @@ -12,7 +12,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultInitializableUnsafe, SwappableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(move)] @@ -51,7 +50,7 @@ pub struct PrivateCopy { } impl PrivateCopy { pub unsafe fn constructor_2(this: *mut Self) { - (&raw mut (*this).v).write(0); + this.write(::default()); } pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut PrivateCopy); @@ -69,13 +68,7 @@ impl MoveAssignableUnsafe for PrivateCopy { } impl Default for PrivateCopy { fn default() -> Self { - unsafe { - { - let mut __v: PrivateCopy = ZeroInitializationUnsafe::zero_init(); - PrivateCopy::constructor_2(&raw mut __v); - __v - } - } + unsafe { PrivateCopy { v: 0 } } } } #[repr(C)] @@ -86,18 +79,12 @@ pub struct Immovable { } impl Immovable { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(0); + this.write(::default()); } } impl Default for Immovable { fn default() -> Self { - unsafe { - { - let mut __v: Immovable = ZeroInitializationUnsafe::zero_init(); - Immovable::constructor_1(&raw mut __v); - __v - } - } + unsafe { Immovable { v: 0 } } } } #[repr(C)] @@ -107,7 +94,6 @@ impl Default for Immovable { DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -119,12 +105,7 @@ pub struct Container { impl Container {} #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -135,7 +116,12 @@ pub struct VecHolder { } impl VecHolder { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).items).write(Vec::new()); + this.write(::default()); + } +} +impl Default for VecHolder { + fn default() -> Self { + unsafe { VecHolder { items: Vec::new() } } } } pub unsafe fn bump_0(mut p: *mut NoCopy) { @@ -158,13 +144,13 @@ unsafe fn main_0() -> i32 { assert!(((a.v) == (1)) && ((b.v) == (0))); (unsafe { bump_0((&mut a as *mut NoCopy)) }); assert!(((a.v) == (2))); - object_unsafe!(p, PrivateCopy::constructor_2()); + let mut p: PrivateCopy = ::default(); p.v = 3; object_unsafe!(q, PrivateCopy::constructor_3(RvalueRefUnsafe::bind(&mut p))); assert!(((q.v) == (3)) && ((p.v) == (0))); assign_unsafe!(p = RvalueRefUnsafe(q)); assert!(((p.v) == (3)) && ((q.v) == (0))); - object_unsafe!(im, Immovable::constructor_1()); + let mut im: Immovable = ::default(); im.v = 4; (unsafe { bump_ref_1(&mut im) }); let mut pim: *mut Immovable = (&mut im as *mut Immovable); @@ -181,7 +167,7 @@ unsafe fn main_0() -> i32 { ::move_constructor(d, RvalueRefUnsafe::bind(&mut c)) }); assert!((((d.inner.v) == (6)) && ((d.tag) == (7))) && ((c.inner.v) == (0))); - object_unsafe!(h, VecHolder::constructor_1()); + let mut h: VecHolder = ::default(); object_unsafe!(h2, VecHolder, |h2| { ::move_constructor(h2, RvalueRefUnsafe::bind(&mut h)) }); diff --git a/tests/unit/out/unsafe/default.rs b/tests/unit/out/unsafe/default.rs index 961b1b4023..08b5c205e2 100644 --- a/tests/unit/out/unsafe/default.rs +++ b/tests/unit/out/unsafe/default.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -35,7 +34,6 @@ pub struct Pointers { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -60,11 +58,6 @@ pub struct SmallArrays { pub struct BigArray { pub a: [i32; 33], } -impl Default for BigArray { - fn default() -> Self { - unsafe { BigArray { a: [0_i32; 33] } } - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/default_function_arguments.rs b/tests/unit/out/unsafe/default_function_arguments.rs index 23bb7e5c10..0a459aa2dd 100644 --- a/tests/unit/out/unsafe/default_function_arguments.rs +++ b/tests/unit/out/unsafe/default_function_arguments.rs @@ -39,17 +39,6 @@ impl ConstructorUnsafe<()> for Bar { } } } -impl Default for Bar { - fn default() -> Self { - unsafe { - { - let mut __v: Bar = ZeroInitializationUnsafe::zero_init(); - Bar::constructor_1(&raw mut __v, 1); - __v - } - } - } -} pub static mut counter_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub unsafe fn next_3() -> i32 { return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut counter_2)).prefix_inc()); @@ -85,7 +74,6 @@ pub unsafe fn first_9(r: *mut [i32; 3]) -> i32 { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/default_in_statics.rs b/tests/unit/out/unsafe/default_in_statics.rs index 0f0c778393..a21bf7b055 100644 --- a/tests/unit/out/unsafe/default_in_statics.rs +++ b/tests/unit/out/unsafe/default_in_statics.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct Inner { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -55,7 +53,6 @@ pub struct Outer { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index c4907e839b..0635be1661 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -259,53 +259,53 @@ pub fn main() { } unsafe fn main_0() -> i32 { { - let mut s: S = ::default_constructed(); + let mut s: S = ::default(); let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (1))); { - let mut s: S = ::default_constructed(); + let mut s: S = ::default(); let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (2))); { - let mut d: Defaulted = ::default_constructed(); + let mut d: Defaulted = ::default(); let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (3))); { - let mut o: Outer = ::default_constructed(); + let mut o: Outer = ::default(); let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (4))); { - let mut am: ArrayMember = ::default_constructed(); + let mut am: ArrayMember = ::default(); let _dtor_am = std::mem::DropGuard::new(&raw mut am, |__p| unsafe { DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (7))); { - let mut e: EmptyBody = ::default_constructed(); + let mut e: EmptyBody = ::default(); let _dtor_e = std::mem::DropGuard::new(&raw mut e, |__p| unsafe { DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (8))); { - let mut tc: Templated_char_ = ::default_constructed(); + let mut tc: Templated_char_ = ::default(); let _dtor_tc = std::mem::DropGuard::new(&raw mut tc, |__p| unsafe { DestructibleUnsafe::destroy(__p) }); - let mut ti: Templated_int_ = ::default_constructed(); + let mut ti: Templated_int_ = ::default(); let _dtor_ti = std::mem::DropGuard::new(&raw mut ti, |__p| unsafe { DestructibleUnsafe::destroy(__p) }); @@ -341,7 +341,7 @@ unsafe fn main_0() -> i32 { assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut order_1))[(2) as usize]) == (1))); let mut before: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)); { - let mut cs: S = ::default_constructed(); + let mut cs: S = ::default(); let _dtor_cs = std::mem::DropGuard::new(&raw mut cs, |__p| unsafe { DestructibleUnsafe::destroy(__p) }); diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index b0e4935fc0..7e177303dc 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -49,7 +49,6 @@ pub unsafe fn with_default_3(s: ParameterObjectUnsafe) -> i32 { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/doubly_linked_list.rs b/tests/unit/out/unsafe/doubly_linked_list.rs index fca0f3445f..dbcb10f225 100644 --- a/tests/unit/out/unsafe/doubly_linked_list.rs +++ b/tests/unit/out/unsafe/doubly_linked_list.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/enum_default_in_static.rs b/tests/unit/out/unsafe/enum_default_in_static.rs index 4b5e366821..b15584db38 100644 --- a/tests/unit/out/unsafe/enum_default_in_static.rs +++ b/tests/unit/out/unsafe/enum_default_in_static.rs @@ -19,7 +19,6 @@ pub const Mode_MODE_TWO: Mode = 2; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Config { pub count: i32, diff --git a/tests/unit/out/unsafe/enum_int_interop.rs b/tests/unit/out/unsafe/enum_int_interop.rs index c94e18bbda..931ad902eb 100644 --- a/tests/unit/out/unsafe/enum_int_interop.rs +++ b/tests/unit/out/unsafe/enum_int_interop.rs @@ -28,7 +28,6 @@ pub const Tag_TAG_TWO: Tag = 2; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/enum_int_interop_c.rs b/tests/unit/out/unsafe/enum_int_interop_c.rs index c2b02f1435..b16b323dc2 100644 --- a/tests/unit/out/unsafe/enum_int_interop_c.rs +++ b/tests/unit/out/unsafe/enum_int_interop_c.rs @@ -28,7 +28,6 @@ pub const Tag_enum_TAG_TWO: Tag_enum = 2; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Entry { pub name: *const libc::c_char, diff --git a/tests/unit/out/unsafe/enum_underlying_type.rs b/tests/unit/out/unsafe/enum_underlying_type.rs index 2cb2f2a65f..2725230001 100644 --- a/tests/unit/out/unsafe/enum_underlying_type.rs +++ b/tests/unit/out/unsafe/enum_underlying_type.rs @@ -42,7 +42,7 @@ pub struct HoldsEmpty { } impl HoldsEmpty { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).e).write(false); + this.write(::default()); } } impl Default for HoldsEmpty { @@ -83,7 +83,7 @@ unsafe fn main_0() -> i32 { let mut sc: Scoped = Scoped_NEG; assert!(((sc as i32) == (-2_i32))); assert!((((Scoped_POS as i8) as i32) == (2))); - object_unsafe!(he, HoldsEmpty::constructor_1()); + let mut he: HoldsEmpty = ::default(); assert!(!(he.e)); let mut ev: Empty = false; assert!(((ev as i32) == (he.e as i32))); diff --git a/tests/unit/out/unsafe/exprs.rs b/tests/unit/out/unsafe/exprs.rs index c2a6006a8d..6c150b258f 100644 --- a/tests/unit/out/unsafe/exprs.rs +++ b/tests/unit/out/unsafe/exprs.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -31,7 +30,6 @@ pub struct X { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/fft.rs b/tests/unit/out/unsafe/fft.rs index c472658993..0ce83224dc 100644 --- a/tests/unit/out/unsafe/fft.rs +++ b/tests/unit/out/unsafe/fft.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/field_aliasing.rs b/tests/unit/out/unsafe/field_aliasing.rs index 5f3bd26f5a..6be843be4f 100644 --- a/tests/unit/out/unsafe/field_aliasing.rs +++ b/tests/unit/out/unsafe/field_aliasing.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct In { pub x: i32, @@ -30,7 +29,6 @@ pub struct In { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct S { pub in_: In, @@ -47,7 +45,6 @@ pub struct S { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Node { pub x: i32, diff --git a/tests/unit/out/unsafe/field_array_elem_ptr.rs b/tests/unit/out/unsafe/field_array_elem_ptr.rs index 2a770876c4..fdac884c13 100644 --- a/tests/unit/out/unsafe/field_array_elem_ptr.rs +++ b/tests/unit/out/unsafe/field_array_elem_ptr.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct Point { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/field_method_receiver.rs b/tests/unit/out/unsafe/field_method_receiver.rs index c3d8cccdc3..45ddcdc514 100644 --- a/tests/unit/out/unsafe/field_method_receiver.rs +++ b/tests/unit/out/unsafe/field_method_receiver.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -47,7 +46,6 @@ impl Counter { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -67,10 +65,19 @@ impl S { }); } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).tag).write(0_i32); - (&raw mut (*this).c).write(::default()); - (&raw mut (*this).arr).write([::default(); 2]); - (&raw mut (*this).v).write(Vec::new()); + this.write(::default()); + } +} +impl Default for S { + fn default() -> Self { + unsafe { + S { + tag: 0_i32, + c: ::default(), + arr: [::default(); 2], + v: Vec::new(), + } + } } } pub unsafe fn run_0(mut o: *mut S) { @@ -109,10 +116,20 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut local: S = ::default(); + let mut local: S = S { + tag: 0_i32, + c: ::default(), + arr: [::default(); 2], + v: Vec::new(), + }; local.tag = 1; (unsafe { run_0((&mut local as *mut S)) }); - let mut heap: *mut S = (Box::leak(Box::new(::default())) as *mut S); + let mut heap: *mut S = (Box::leak(Box::new(S { + tag: 0_i32, + c: ::default(), + arr: [::default(); 2], + v: Vec::new(), + })) as *mut S); (*heap).tag = 1; (unsafe { run_0(heap) }); { diff --git a/tests/unit/out/unsafe/field_pointers.rs b/tests/unit/out/unsafe/field_pointers.rs index f501b40dac..7baaac7f9b 100644 --- a/tests/unit/out/unsafe/field_pointers.rs +++ b/tests/unit/out/unsafe/field_pointers.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct Inner { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -50,7 +48,6 @@ pub struct Header { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -78,12 +75,21 @@ impl Outer { }; } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).x).write(0_i32); - (&raw mut (*this).inner).write(::default()); - (&raw mut (*this).items).write([::default(); 3]); - (&raw mut (*this).v).write(Vec::new()); - (&raw mut (*this).cursor).write(std::ptr::null_mut()); - (&raw mut (*this).buf).write([0_i32; 4]); + this.write(::default()); + } +} +impl Default for Outer { + fn default() -> Self { + unsafe { + Outer { + x: 0_i32, + inner: ::default(), + items: [::default(); 3], + v: Vec::new(), + cursor: std::ptr::null_mut(), + buf: [0_i32; 4], + } + } } } pub unsafe fn set_0(mut p: *mut i32, mut value: i32) { @@ -100,7 +106,14 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut o: Outer = ::default(); + let mut o: Outer = Outer { + x: 0_i32, + inner: ::default(), + items: [::default(); 3], + v: Vec::new(), + cursor: std::ptr::null_mut(), + buf: [0; 4], + }; o.x = 1; let mut px: *mut i32 = (&mut o.x as *mut i32); (*px) = 2; diff --git a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs index 691ef1594b..e33de41ac7 100644 --- a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs +++ b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/field_reinterpret_write_through.rs b/tests/unit/out/unsafe/field_reinterpret_write_through.rs index 8e75578838..81b32af630 100644 --- a/tests/unit/out/unsafe/field_reinterpret_write_through.rs +++ b/tests/unit/out/unsafe/field_reinterpret_write_through.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct In { pub a: i16, @@ -30,7 +29,6 @@ pub struct In { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct S { pub x: i32, diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index c673c84678..f88ea19c79 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs b/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs index 0c54613d31..92b77b7d29 100644 --- a/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs +++ b/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct In { pub a: i16, @@ -30,7 +29,6 @@ pub struct In { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct S { pub x: i32, diff --git a/tests/unit/out/unsafe/first_member_downcast.rs b/tests/unit/out/unsafe/first_member_downcast.rs index d3f4ab0bee..f48b8a4b2d 100644 --- a/tests/unit/out/unsafe/first_member_downcast.rs +++ b/tests/unit/out/unsafe/first_member_downcast.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct base { pub kind: i32, @@ -29,7 +28,6 @@ pub struct base { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct derived { pub head: base, diff --git a/tests/unit/out/unsafe/flex_array_member_incomplete.rs b/tests/unit/out/unsafe/flex_array_member_incomplete.rs index 8750661ff8..995b104bdb 100644 --- a/tests/unit/out/unsafe/flex_array_member_incomplete.rs +++ b/tests/unit/out/unsafe/flex_array_member_incomplete.rs @@ -20,11 +20,6 @@ pub struct F { pub n: i32, pub tail: [libc::c_char; 0], } -impl Default for F { - fn default() -> Self { - unsafe { F { n: 0_i32, tail: [] } } - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/flex_array_member_sibling_write.rs b/tests/unit/out/unsafe/flex_array_member_sibling_write.rs index 752bdf1574..a5526cc771 100644 --- a/tests/unit/out/unsafe/flex_array_member_sibling_write.rs +++ b/tests/unit/out/unsafe/flex_array_member_sibling_write.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct S { pub n: i32, @@ -30,7 +29,6 @@ pub struct S { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct E { pub id: i32, @@ -45,7 +43,6 @@ pub struct E { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct T { pub n: i32, diff --git a/tests/unit/out/unsafe/fn_ptr.rs b/tests/unit/out/unsafe/fn_ptr.rs index 5e494ad054..29fa1807d8 100644 --- a/tests/unit/out/unsafe/fn_ptr.rs +++ b/tests/unit/out/unsafe/fn_ptr.rs @@ -40,7 +40,6 @@ pub unsafe fn identity_hash_6(mut v: bool) -> usize { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/fn_ptr_cast.rs b/tests/unit/out/unsafe/fn_ptr_cast.rs index b223df991e..bec520da14 100644 --- a/tests/unit/out/unsafe/fn_ptr_cast.rs +++ b/tests/unit/out/unsafe/fn_ptr_cast.rs @@ -38,7 +38,6 @@ pub unsafe fn test_double_cast_2() { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs index e2bac77010..a27d6aeab7 100644 --- a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs +++ b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index 8ebe5a40f9..6eb296eacf 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -38,7 +37,6 @@ pub unsafe fn negate_1(mut x: i32) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -55,9 +53,7 @@ impl S { } } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, RvalueRefUnsafe)] diff --git a/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs b/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs index f9c0c8fd7e..456bd89bc2 100644 --- a/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs +++ b/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs @@ -27,7 +27,6 @@ pub unsafe fn via_size_t_return_3(mut b: u64) -> usize { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct pair { pub a: i32, diff --git a/tests/unit/out/unsafe/fn_ptr_vtable.rs b/tests/unit/out/unsafe/fn_ptr_vtable.rs index 28abdff5b6..c4e1dc111a 100644 --- a/tests/unit/out/unsafe/fn_ptr_vtable.rs +++ b/tests/unit/out/unsafe/fn_ptr_vtable.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/fn_ref.rs b/tests/unit/out/unsafe/fn_ref.rs index 272e78474b..bd0e201392 100644 --- a/tests/unit/out/unsafe/fn_ref.rs +++ b/tests/unit/out/unsafe/fn_ref.rs @@ -30,7 +30,6 @@ pub unsafe fn call_forwarded_4(f: Option i32>, mut x: i32) -> ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs index 4a89daab57..9b11cd3154 100644 --- a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs @@ -16,7 +16,6 @@ use std::rc::Rc; MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -28,8 +27,17 @@ pub struct S { } impl S { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(Vec::new()); - (&raw mut (*this).a).write(0_i32); + this.write(::default()); + } +} +impl Default for S { + fn default() -> Self { + unsafe { + S { + v: Vec::new(), + a: 0_i32, + } + } } } pub fn main() { @@ -39,7 +47,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S::constructor_1()); + let mut s: S = ::default(); { let mut __tmp_0: i32 = 1; s.v.push_moved(&mut __tmp_0) diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index a43ba113a2..a8a39022d4 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -10,9 +10,7 @@ pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] @@ -61,9 +59,7 @@ impl Holder { } } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe)] #[memberwise(copy_constructor, move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/forward_decltype.rs b/tests/unit/out/unsafe/forward_decltype.rs index 7111d34853..a2b236d09f 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -10,9 +10,7 @@ pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index a49ede2127..6831204be4 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -12,9 +12,7 @@ pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index 21a28f6080..0c53b41866 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -12,9 +12,7 @@ pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] @@ -103,9 +101,7 @@ impl Pair { } } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe)] #[memberwise(copy_constructor, move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/friend.rs b/tests/unit/out/unsafe/friend.rs index 1572274b47..ff74143f1e 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -24,7 +24,6 @@ pub unsafe fn scaled_2(v: *const V, mut k: f64) -> f64 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -43,7 +42,6 @@ pub unsafe fn get_3(w: *const W_int_) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -62,7 +60,6 @@ pub unsafe fn get_4(w: *const W_long_) -> i64 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -78,7 +75,6 @@ pub struct W_long_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/function_overloading.rs b/tests/unit/out/unsafe/function_overloading.rs index b1a5f87c1f..23c2ea787f 100644 --- a/tests/unit/out/unsafe/function_overloading.rs +++ b/tests/unit/out/unsafe/function_overloading.rs @@ -30,7 +30,6 @@ pub unsafe fn bar_4(x: *mut i32) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/global_call_temporaries.rs b/tests/unit/out/unsafe/global_call_temporaries.rs index 901f1d1e13..4055512f1d 100644 --- a/tests/unit/out/unsafe/global_call_temporaries.rs +++ b/tests/unit/out/unsafe/global_call_temporaries.rs @@ -97,7 +97,6 @@ pub static mut call_assigned_6: std::cell::LazyCell = std::cell::LazyCell:: ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/global_init_side_effect.rs b/tests/unit/out/unsafe/global_init_side_effect.rs index 037d1c716c..9695de6b02 100644 --- a/tests/unit/out/unsafe/global_init_side_effect.rs +++ b/tests/unit/out/unsafe/global_init_side_effect.rs @@ -16,7 +16,6 @@ pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/global_non_const_init.rs b/tests/unit/out/unsafe/global_non_const_init.rs index 610423735b..44a0780f32 100644 --- a/tests/unit/out/unsafe/global_non_const_init.rs +++ b/tests/unit/out/unsafe/global_non_const_init.rs @@ -45,7 +45,7 @@ pub struct Ctor { } impl Ctor { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write((unsafe { next_0() })); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, mut x: i32) { (&raw mut (*this).v).write(x); @@ -54,21 +54,14 @@ impl Ctor { impl Default for Ctor { fn default() -> Self { unsafe { - { - let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); - Ctor::constructor_1(&raw mut __v); - __v + Ctor { + v: (unsafe { next_0() }), } } } } -pub static mut default_ctor_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { - { - let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); - Ctor::constructor_1(&raw mut __v); - __v - } -}); +pub static mut default_ctor_7: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { ::default() }); pub static mut arg_ctor_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); @@ -100,7 +93,6 @@ pub static mut inline_member_11: std::cell::LazyCell = std::cell::LazyCell ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -137,7 +129,7 @@ pub struct Singleton { } impl Singleton { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).hits).write(0); + this.write(::default()); } pub unsafe fn instance() -> *mut Singleton { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut s_15)); @@ -145,22 +137,11 @@ impl Singleton { } impl Default for Singleton { fn default() -> Self { - unsafe { - { - let mut __v: Singleton = ZeroInitializationUnsafe::zero_init(); - Singleton::constructor_1(&raw mut __v); - __v - } - } + unsafe { Singleton { hits: 0 } } } } -static mut s_15: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { - { - let mut __v: Singleton = ZeroInitializationUnsafe::zero_init(); - Singleton::constructor_1(&raw mut __v); - __v - } -}); +static mut s_15: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { ::default() }); pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/global_pointers.rs b/tests/unit/out/unsafe/global_pointers.rs index a6ab209fd5..c5a48603f6 100644 --- a/tests/unit/out/unsafe/global_pointers.rs +++ b/tests/unit/out/unsafe/global_pointers.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/global_without_initializer.rs b/tests/unit/out/unsafe/global_without_initializer.rs index bea625254b..02819118c0 100644 --- a/tests/unit/out/unsafe/global_without_initializer.rs +++ b/tests/unit/out/unsafe/global_without_initializer.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/goto_aggregate_default.rs b/tests/unit/out/unsafe/goto_aggregate_default.rs index dae9dd1997..47d35880e3 100644 --- a/tests/unit/out/unsafe/goto_aggregate_default.rs +++ b/tests/unit/out/unsafe/goto_aggregate_default.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Point { pub x: i32, diff --git a/tests/unit/out/unsafe/goto_cleanup.rs b/tests/unit/out/unsafe/goto_cleanup.rs index 17ac7a507a..77d335380f 100644 --- a/tests/unit/out/unsafe/goto_cleanup.rs +++ b/tests/unit/out/unsafe/goto_cleanup.rs @@ -85,7 +85,6 @@ pub unsafe fn from_switch_2(mut n: i32) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct wrapper { pub item: *mut i32, diff --git a/tests/unit/out/unsafe/huffman.rs b/tests/unit/out/unsafe/huffman.rs index cb7efdb49b..d83a24c073 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -52,12 +51,7 @@ pub unsafe fn Swap_0(a: *mut MinHeapNode, b: *mut MinHeapNode) { } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -261,11 +255,20 @@ impl MinHeap { } } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).size).write(0_i32); - (&raw mut (*this).capacity).write(0_i32); - (&raw mut (*this).arr).write(None); - (&raw mut (*this).next).write(0_i32); - (&raw mut (*this).alloc).write(None); + this.write(::default()); + } +} +impl Default for MinHeap { + fn default() -> Self { + unsafe { + MinHeap { + size: 0_i32, + capacity: 0_i32, + arr: None, + next: 0_i32, + alloc: None, + } + } } } pub unsafe fn AllocMinHeap_1(mut capacity: i32) -> Option> { diff --git a/tests/unit/out/unsafe/immutable-deref-on-func-call.rs b/tests/unit/out/unsafe/immutable-deref-on-func-call.rs index 8ab42f850f..732d42fcb5 100644 --- a/tests/unit/out/unsafe/immutable-deref-on-func-call.rs +++ b/tests/unit/out/unsafe/immutable-deref-on-func-call.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/implicit_autoref.rs b/tests/unit/out/unsafe/implicit_autoref.rs index f064c49e32..25ee0cd4ce 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -16,7 +16,6 @@ use std::rc::Rc; MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -27,7 +26,12 @@ pub struct Holder { } impl Holder { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Holder { + fn default() -> Self { + unsafe { Holder { v: Vec::new() } } } } pub unsafe fn write_through_0(mut p: *mut i32) { @@ -52,7 +56,7 @@ unsafe fn main_0() -> i32 { let mut p: *mut Vec = (&mut v as *mut Vec); let mut a: i32 = (&mut (*p))[(0_usize)]; (&mut (*p))[(1_usize)] = 30; - object_unsafe!(h, Holder::constructor_1()); + let mut h: Holder = ::default(); { let mut __tmp_2: i32 = 40; h.v.push_moved(&mut __tmp_2) diff --git a/tests/unit/out/unsafe/in_class_field_initializer.rs b/tests/unit/out/unsafe/in_class_field_initializer.rs index 2f0295ed62..925bf52be8 100644 --- a/tests/unit/out/unsafe/in_class_field_initializer.rs +++ b/tests/unit/out/unsafe/in_class_field_initializer.rs @@ -24,8 +24,7 @@ pub struct Inner { } impl Inner { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).x).write(3); - (&raw mut (*this).y).write(4); + this.write(::default()); } } impl Default for Inner { @@ -55,20 +54,8 @@ impl S { pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).a).write(1); (&raw mut (*this).b).write((2 as libc::c_char)); - (&raw mut (*this).c).write(::default()); - Inner::constructor_1(&raw mut (*this).d); - } -} -impl Default for S { - fn default() -> Self { - unsafe { - S { - a: 1, - b: (2 as libc::c_char), - c: ::default(), - d: ::default(), - } - } + (&raw mut (*this).c).write(Inner { x: 3, y: 4 }); + (&raw mut (*this).d).write(::default()); } } #[repr(C)] @@ -94,11 +81,6 @@ impl Boxed_int_ { (&raw mut (*this).tag).write(t); } } -impl Default for Boxed_int_ { - fn default() -> Self { - unsafe { ::zero_init() } - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/init.rs b/tests/unit/out/unsafe/init.rs index 0f36941bdf..0f00969d13 100644 --- a/tests/unit/out/unsafe/init.rs +++ b/tests/unit/out/unsafe/init.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/init_list.rs b/tests/unit/out/unsafe/init_list.rs index 1d8f5874e8..5420cb4f0c 100644 --- a/tests/unit/out/unsafe/init_list.rs +++ b/tests/unit/out/unsafe/init_list.rs @@ -16,7 +16,6 @@ pub unsafe fn f_0(mut list: Vec) {} ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -48,15 +47,6 @@ impl Holder { (&raw mut (*this).p).write(Pair { a: 0, b: 0 }); } } -impl Default for Holder { - fn default() -> Self { - unsafe { - Holder { - p: Pair { a: 0, b: 0 }, - } - } - } -} pub unsafe fn sum_1(p: *const Pair) -> i32 { return (((*p).a) + ((*p).b)); } @@ -77,7 +67,7 @@ pub struct Seven { } impl Seven { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(7); + this.write(::default()); } } impl Default for Seven { @@ -104,7 +94,7 @@ unsafe fn main_0() -> i32 { (unsafe { Holder::operator_assign_1(&raw mut h, &mut p) }); assert!(((h.p.a) == (1)) && ((h.p.b) == (2))); assert!(((unsafe { sum_1(&p,) }) == (3))); - let mut sevens: [Seven; 4] = [::default(); 4]; + let mut sevens: [Seven; 4] = [Seven { v: 7 }; 4]; { let mut i: i32 = 0; 'loop_: while ((i) < (4)) { diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index 19128f8439..b18384d559 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -16,7 +16,6 @@ use std::rc::Rc; MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -29,9 +28,18 @@ pub struct Elem { } impl Elem { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).id).write(0_i32); - (&raw mut (*this).hist).write([0_i32; 4]); - (&raw mut (*this).coeffs).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Elem { + fn default() -> Self { + unsafe { + Elem { + id: 0_i32, + hist: [0_i32; 4], + coeffs: Vec::new(), + } + } } } #[repr(C)] @@ -58,11 +66,7 @@ pub struct State { } impl State { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).count).write(0_i32); - (&raw mut (*this).grid).write([[0_i32; 3]; 2]); - (&raw mut (*this).arr).write(std::array::from_fn::<_, 3, _>(|_| 0_i32)); - (&raw mut (*this).elems).write(Vec::new()); - (&raw mut (*this).rows).write(Vec::new()); + this.write(::default()); } } impl Default for State { @@ -72,8 +76,8 @@ impl Default for State { count: 0_i32, grid: [[0_i32; 3]; 2], arr: std::array::from_fn::<_, 3, _>(|_| 0_i32), - elems: Default::default(), - rows: Default::default(), + elems: Vec::new(), + rows: Vec::new(), } } } @@ -110,7 +114,8 @@ pub unsafe fn fill_1(mut s: *mut State) { } } (&mut (*s)).arr[(1_usize)] = 7; - (*s).elems.resize_with(3_usize, || ::default()); + (*s).elems + .resize_with(3_usize, || ::default_constructed()); { let mut i: i32 = 0; 'loop_: while ((i) < (3)) { @@ -156,7 +161,7 @@ pub struct Counted { } impl Counted { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Counted); @@ -199,7 +204,13 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut s: State = ::default(); + let mut s: State = State { + count: 0_i32, + grid: std::array::from_fn::<_, 2, _>(|_| Default::default()), + arr: std::array::from_fn::<_, 3, _>(|_| 0_i32), + elems: Vec::new(), + rows: Vec::new(), + }; (unsafe { fill_1((&mut s as *mut State)) }); assert!( ((s.grid[(1) as usize][(2) as usize]) == (5)) @@ -253,7 +264,7 @@ unsafe fn main_0() -> i32 { (((*p).elems.len()) == (4_usize)) && (((&mut (*p)).elems[(3_usize)].hist[(0) as usize]) == (100)) ); - let mut elems: Vec = Vec::from_fn(2_usize, |_| ::default()); + let mut elems: Vec = Vec::from_fn(2_usize, |_| ::default_constructed()); let mut first: *mut Elem = (&mut elems[(0_usize)] as *mut Elem); elems[(1_usize)].coeffs.resize_with(2_usize, || 0_i16); elems[(1_usize)].coeffs[(1_usize)] = 4_i16; @@ -270,7 +281,13 @@ unsafe fn main_0() -> i32 { ); assert!((((moved.elems.len()) == (4_usize)) && (t.elems.is_empty())) && (t.rows.is_empty())); assert!(((moved.arr[(1_usize)]) == (7)) && ((t.arr[(1_usize)]) == (7))); - let mut assigned: State = ::default(); + let mut assigned: State = State { + count: 0_i32, + grid: std::array::from_fn::<_, 2, _>(|_| Default::default()), + arr: std::array::from_fn::<_, 3, _>(|_| 0_i32), + elems: Vec::new(), + rows: Vec::new(), + }; assign_unsafe!(assigned = RvalueRefUnsafe(moved)); assert!( ((assigned.grid[(0) as usize][(0) as usize]) == (100)) @@ -280,7 +297,7 @@ unsafe fn main_0() -> i32 { ((assigned.elems[(2_usize)].coeffs[(1_usize)] as i32) == (7)) && (moved.elems.is_empty()) ); assert!(((assigned.arr[(1_usize)]) == (7)) && ((moved.arr[(1_usize)]) == (7))); - let mut ca: [Counted; 3] = std::array::from_fn::<_, 3, _>(|_| ::default()); + let mut ca: [Counted; 3] = std::array::from_fn::<_, 3, _>(|_| ::default_constructed()); ca[(1_usize)].v = 5; let mut cb: [Counted; 3] = std::array::from_fn(|__i| move_constructed_unsafe(&raw mut ca[__i])); assert!( diff --git a/tests/unit/out/unsafe/kruskal.rs b/tests/unit/out/unsafe/kruskal.rs index 7028ca1939..d2b2761e30 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -176,12 +175,7 @@ pub unsafe fn quicksort_1(arr: *mut Option>, mut start: i32, mut end } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -297,19 +291,23 @@ impl DisjointSet { } } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).rank).write(None); - (&raw mut (*this).parent).write(None); - (&raw mut (*this).n).write(0_i32); + this.write(::default()); + } +} +impl Default for DisjointSet { + fn default() -> Self { + unsafe { + DisjointSet { + rank: None, + parent: None, + n: 0_i32, + } + } } } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -322,9 +320,18 @@ pub struct Graph { } impl Graph { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).edges).write(None); - (&raw mut (*this).V).write(0_i32); - (&raw mut (*this).E).write(0_i32); + this.write(::default()); + } +} +impl Default for Graph { + fn default() -> Self { + unsafe { + Graph { + edges: None, + V: 0_i32, + E: 0_i32, + } + } } } pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index cd0356b6f9..80ec74c5bc 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -68,20 +68,6 @@ impl Holder__lambda_at_lambda_as_field_cpp_39_12__ { return (unsafe { (*this).f.call(x) }); } } -impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { - fn default() -> Self { - unsafe { - Holder__lambda_at_lambda_as_field_cpp_39_12__ { - f: FnPtr:: i32>::new(|mut x: i32| -> i32 { - unsafe { - return ((x) + (1)); - } - }), - calls: 0_i32, - } - } - } -} #[repr(C)] #[derive( Clone, @@ -90,7 +76,6 @@ impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -126,11 +111,6 @@ impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { (&raw mut (*this).moves).write((((*o).moves) + (1))); } } -impl Default for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn default() -> Self { - unsafe { ::zero_init() } - } -} pub unsafe fn wrap_0(mut fn_: FnPtr i32>) -> FnPtr i32> { return lambda_unsafe!( { diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index a3d0d20e44..f411bf5785 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -18,8 +18,7 @@ pub struct Counted { } impl Counted { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).copies).write(0); - (&raw mut (*this).moves).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Counted); @@ -35,10 +34,9 @@ impl Counted { impl Default for Counted { fn default() -> Self { unsafe { - { - let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); - Counted::constructor_1(&raw mut __v); - __v + Counted { + copies: 0, + moves: 0, } } } @@ -52,7 +50,9 @@ pub static mut drops_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u #[constructor(constructor_3, RvalueRefUnsafe)] pub struct Dropped {} impl Dropped { - pub unsafe fn constructor_1(this: *mut Self) {} + pub unsafe fn constructor_1(this: *mut Self) { + this.write(::default()); + } pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const Dropped); } @@ -65,6 +65,11 @@ impl DestructibleUnsafe for Dropped { (*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)).postfix_inc(); } } +impl Default for Dropped { + fn default() -> Self { + unsafe { Dropped {} } + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -72,7 +77,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(c, Counted::constructor_1()); + let mut c: Counted = ::default(); let mut f: FnPtr i32> = lambda_unsafe!( { let c: Counted = { @@ -115,11 +120,7 @@ unsafe fn main_0() -> i32 { .copies }; assert!(((returned) == (2))); - let mut arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|_| { - let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); - Counted::constructor_1(&raw mut __v); - __v - }); + let mut arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|_| ::default()); let mut a: FnPtr i32> = lambda_unsafe!( { let arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|__i: usize| { @@ -140,11 +141,7 @@ unsafe fn main_0() -> i32 { { let mut m: FnPtr = lambda_unsafe!( { - let d: Dropped = { - let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); - Dropped::constructor_1(&raw mut __v); - __v - }; + let d: Dropped = ::default(); }, || {} ); @@ -160,11 +157,7 @@ unsafe fn main_0() -> i32 { { let mut k: FnPtr = lambda_unsafe!( { - let d: Dropped = { - let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); - Dropped::constructor_1(&raw mut __v); - __v - }; + let d: Dropped = ::default(); }, || {} ); @@ -180,11 +173,7 @@ unsafe fn main_0() -> i32 { { let mut inner: FnPtr = lambda_unsafe!( { - let d: Dropped = { - let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); - Dropped::constructor_1(&raw mut __v); - __v - }; + let d: Dropped = ::default(); }, || {} ); diff --git a/tests/unit/out/unsafe/lambda_capture_ref.rs b/tests/unit/out/unsafe/lambda_capture_ref.rs index 70a8492246..c6922c0f2f 100644 --- a/tests/unit/out/unsafe/lambda_capture_ref.rs +++ b/tests/unit/out/unsafe/lambda_capture_ref.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/lambda_capture_star_this.rs b/tests/unit/out/unsafe/lambda_capture_star_this.rs index d2de505594..a693b3d88f 100644 --- a/tests/unit/out/unsafe/lambda_capture_star_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_star_this.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/lambda_capture_this.rs b/tests/unit/out/unsafe/lambda_capture_this.rs index 25e3fc0593..0a8524052e 100644 --- a/tests/unit/out/unsafe/lambda_capture_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_this.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/lambda_capture_value.rs b/tests/unit/out/unsafe/lambda_capture_value.rs index 3f53a18ed6..d3faefb8f6 100644 --- a/tests/unit/out/unsafe/lambda_capture_value.rs +++ b/tests/unit/out/unsafe/lambda_capture_value.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/lambda_decltype_type.rs b/tests/unit/out/unsafe/lambda_decltype_type.rs index 359658656c..ecad63ae1c 100644 --- a/tests/unit/out/unsafe/lambda_decltype_type.rs +++ b/tests/unit/out/unsafe/lambda_decltype_type.rs @@ -33,15 +33,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { (*this).size.postfix_inc(); } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).items).write([0_i32; 4]); - (&raw mut (*this).size).write(0); - (&raw mut (*this).cmp).write(FnPtr:: bool>::new( - |mut a: i32, mut b: i32| -> bool { - unsafe { - return ((a) > (b)); - } - }, - )); + this.write(::default()); } } impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { @@ -86,15 +78,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { (*this).size.postfix_inc(); } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).items).write([0_i32; 4]); - (&raw mut (*this).size).write(0); - (&raw mut (*this).cmp).write(FnPtr:: bool>::new( - |mut a: i32, mut b: i32| -> bool { - unsafe { - return ((a) < (b)); - } - }, - )); + this.write(::default()); } } impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { @@ -125,20 +109,16 @@ unsafe fn main_0() -> i32 { return ((a) > (b)); } }); - object_unsafe!( - desc, - Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::constructor_1() - ); + let mut desc: Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ = + ::default(); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 2) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 7) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 4) }); assert!(((desc.items[(0) as usize]) == (7))); assert!(((desc.items[(1) as usize]) == (4))); assert!(((desc.items[(2) as usize]) == (2))); - object_unsafe!( - asc, - Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::constructor_1() - ); + let mut asc: Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ = + ::default(); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 2) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 7) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 4) }); diff --git a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs b/tests/unit/out/unsafe/lambda_generic_explicit_args.rs index d7dd2a6d11..28bf439972 100644 --- a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs +++ b/tests/unit/out/unsafe/lambda_generic_explicit_args.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/lambda_immediate_init.rs b/tests/unit/out/unsafe/lambda_immediate_init.rs index b938db43ce..b07f5c53f9 100644 --- a/tests/unit/out/unsafe/lambda_immediate_init.rs +++ b/tests/unit/out/unsafe/lambda_immediate_init.rs @@ -27,17 +27,7 @@ pub struct S { } impl S { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).j).write(10); - (&raw mut (*this).k).write( - ((unsafe { - FnPtr:: i32>::new(|| -> i32 { - unsafe { - return 3; - } - }) - .call() - }) + (1)), - ); + this.write(::default()); } } impl Default for S { @@ -99,7 +89,7 @@ unsafe fn main_0() -> i32 { }) == (237)) ); assert!(((unsafe { pick_0(1,) }) == (1))); - object_unsafe!(s, S::constructor_1()); + let mut s: S = ::default(); assert!(((s.k) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut g_1)) == (10))); let mut a: i32 = 2; diff --git a/tests/unit/out/unsafe/lambda_nested.rs b/tests/unit/out/unsafe/lambda_nested.rs index 9a276cf17e..e0197eccc5 100644 --- a/tests/unit/out/unsafe/lambda_nested.rs +++ b/tests/unit/out/unsafe/lambda_nested.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/lambda_static_local.rs b/tests/unit/out/unsafe/lambda_static_local.rs index 08d48ccff2..073cdb7c4a 100644 --- a/tests/unit/out/unsafe/lambda_static_local.rs +++ b/tests/unit/out/unsafe/lambda_static_local.rs @@ -76,7 +76,6 @@ static mut calls_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsaf ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/libc_struct_without_default.rs b/tests/unit/out/unsafe/libc_struct_without_default.rs index eee5baa317..10e25eb6f0 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -27,8 +27,7 @@ pub struct UserDefined { } impl UserDefined { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).a).write(std::array::from_fn::<_, 1, _>(|_| 0_i32)); - (&raw mut (*this).v).write(Vec::new()); + this.write(::default()); } } impl Default for UserDefined { @@ -36,7 +35,7 @@ impl Default for UserDefined { unsafe { UserDefined { a: std::array::from_fn::<_, 1, _>(|_| 0_i32), - v: Default::default(), + v: Vec::new(), } } } @@ -56,15 +55,6 @@ impl Default for UserDefined { pub struct FieldIsLibcType { pub addr: libc::sockaddr, } -impl Default for FieldIsLibcType { - fn default() -> Self { - unsafe { - FieldIsLibcType { - addr: std::mem::zeroed(), - } - } - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -92,7 +82,7 @@ unsafe fn main_0() -> i32 { let mut st: ::libc::stat = std::mem::zeroed(); st.st_size = (1024 as ::libc::off_t); assert!(((st.st_size) == (1024 as ::libc::off_t))); - object_unsafe!(ud, UserDefined::constructor_1()); + let mut ud: UserDefined = ::default(); ud.a[(0_usize)] = 3; assert!(((ud.a[(0_usize)]) == (3))); assert!(((ud.v.len()) == (0_usize))); diff --git a/tests/unit/out/unsafe/linked_list.rs b/tests/unit/out/unsafe/linked_list.rs index b5e917018d..e4d8abdea5 100644 --- a/tests/unit/out/unsafe/linked_list.rs +++ b/tests/unit/out/unsafe/linked_list.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/local_anon_struct_collision.rs b/tests/unit/out/unsafe/local_anon_struct_collision.rs index 6bc09413c4..68bde68f1c 100644 --- a/tests/unit/out/unsafe/local_anon_struct_collision.rs +++ b/tests/unit/out/unsafe/local_anon_struct_collision.rs @@ -21,7 +21,6 @@ pub unsafe fn first_0() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_1 { pub x: i32, @@ -42,7 +41,6 @@ pub unsafe fn second_2() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_3 { pub a: i64, diff --git a/tests/unit/out/unsafe/local_record_template.rs b/tests/unit/out/unsafe/local_record_template.rs index 3c54b068d8..65b51ff32e 100644 --- a/tests/unit/out/unsafe/local_record_template.rs +++ b/tests/unit/out/unsafe/local_record_template.rs @@ -38,7 +38,6 @@ pub unsafe fn wrap_10(mut v: i64) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -54,7 +53,6 @@ pub struct Local_5 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -74,7 +72,6 @@ pub unsafe fn other_11() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -106,7 +103,6 @@ unsafe fn main_0() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index e7a22f483a..c826947ba9 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -34,8 +34,7 @@ pub struct Point { } impl Point { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).x).write(0); - (&raw mut (*this).y).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, mut x: i32, mut y: i32) { (&raw mut (*this).x).write(x); @@ -44,13 +43,7 @@ impl Point { } impl Default for Point { fn default() -> Self { - unsafe { - { - let mut __v: Point = ZeroInitializationUnsafe::zero_init(); - Point::constructor_1(&raw mut __v); - __v - } - } + unsafe { Point { x: 0, y: 0 } } } } pub fn main() { @@ -498,7 +491,7 @@ unsafe fn main_0() -> i32 { (*points.subscript_move( &mut __tmp_31, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) .x }) == (3)) @@ -512,7 +505,7 @@ unsafe fn main_0() -> i32 { (*points.subscript_move( &mut __tmp_32, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) .y }) == (4)) @@ -531,7 +524,7 @@ unsafe fn main_0() -> i32 { (*points.subscript_move( &mut __tmp_33, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) .x }) == (5)) @@ -545,7 +538,7 @@ unsafe fn main_0() -> i32 { (*points.subscript_move( &mut __tmp_34, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) .y }) == (6)) diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 716f383024..7f79eedc9b 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -10,9 +10,7 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut made_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index fe4f9c4623..cbf8688d82 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -17,7 +17,6 @@ pub static mut default_constructions_0: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -51,17 +50,6 @@ impl Mapped { (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)).prefix_inc(); } } -impl Default for Mapped { - fn default() -> Self { - unsafe { - { - let mut __v: Mapped = ZeroInitializationUnsafe::zero_init(); - Mapped::constructor_1(&raw mut __v); - __v - } - } - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -85,7 +73,8 @@ unsafe fn main_0() -> i32 { }) as i32)) != 0; let mut distinct: UnsafeMap = UnsafeMap::new(); - let a: *mut Mapped = &mut (*distinct.subscript(&distinct_a, || ::default())); + let a: *mut Mapped = + &mut (*distinct.subscript(&distinct_a, || ::default_constructed())); (*a).value = 11; let mut a_it: UnsafeBidirectionalIterator<(Key, Mapped)> = distinct.find(&distinct_a); let mut a_value: *mut Mapped = (&mut (*a_it.iter_deref()).1 as *mut Mapped); @@ -93,7 +82,8 @@ unsafe fn main_0() -> i32 { & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (1)) as i32)) != 0; - let b: *mut Mapped = &mut (*distinct.subscript(&distinct_b, || ::default())); + let b: *mut Mapped = + &mut (*distinct.subscript(&distinct_b, || ::default_constructed())); (*b).value = 22; let mut b_it: UnsafeBidirectionalIterator<(Key, Mapped)> = distinct.find(&distinct_b); ok = ((ok as i32) @@ -152,7 +142,8 @@ unsafe fn main_0() -> i32 { let mut equivalent: UnsafeMap = UnsafeMap::new(); let before_equivalent: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)); - let first: *mut Mapped = &mut (*equivalent.subscript(&equivalent_a, || ::default())); + let first: *mut Mapped = + &mut (*equivalent.subscript(&equivalent_a, || ::default_constructed())); (*first).value = 31; let mut first_it: UnsafeBidirectionalIterator<(Key, Mapped)> = equivalent.find(&equivalent_a); let mut first_value: *mut Mapped = (&mut (*first_it.iter_deref()).1 as *mut Mapped); @@ -160,7 +151,8 @@ unsafe fn main_0() -> i32 { & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == ((before_equivalent) + (1))) as i32)) != 0; - let second: *mut Mapped = &mut (*equivalent.subscript(&equivalent_b, || ::default())); + let second: *mut Mapped = + &mut (*equivalent.subscript(&equivalent_b, || ::default_constructed())); let reused: bool = ((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == ((before_equivalent) + (1))); ok = ((ok as i32) & (reused as i32)) != 0; @@ -210,7 +202,8 @@ unsafe fn main_0() -> i32 { order: 4, identity: 10, }; - let later: *mut Mapped = &mut (*equivalent.subscript(&later_key, || ::default())); + let later: *mut Mapped = + &mut (*equivalent.subscript(&later_key, || ::default_constructed())); (*later).value = 41; ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) @@ -244,7 +237,8 @@ unsafe fn main_0() -> i32 { let before_matching: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)); let mut matching: UnsafeMap = UnsafeMap::new(); - let matched: *mut Mapped = &mut (*matching.subscript(&matching_a, || ::default())); + let matched: *mut Mapped = + &mut (*matching.subscript(&matching_a, || ::default_constructed())); (*matched).value = 51; let mut matched_it: UnsafeBidirectionalIterator<(Key, Mapped)> = matching.find(&matching_a); let mut matched_value: *mut Mapped = (&mut (*matched_it.iter_deref()).1 as *mut Mapped); @@ -253,7 +247,7 @@ unsafe fn main_0() -> i32 { == ((before_matching) + (1))) as i32)) != 0; let matched_again: *mut Mapped = - &mut (*matching.subscript(&matching_b, || ::default())); + &mut (*matching.subscript(&matching_b, || ::default_constructed())); ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == ((before_matching) + (1))) as i32)) @@ -268,7 +262,8 @@ unsafe fn main_0() -> i32 { & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) != 0; ok = ((ok as i32) & ((((*matched_it.iter_deref()).1.value) == (51)) as i32)) != 0; - let other: *mut Mapped = &mut (*matching.subscript(&matching_c, || ::default())); + let other: *mut Mapped = + &mut (*matching.subscript(&matching_c, || ::default_constructed())); (*other).value = 61; ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 8e174ec643..0af4fb439c 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -22,7 +22,7 @@ pub struct Item { } impl Item { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).value).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); @@ -42,13 +42,7 @@ impl Item { } impl Default for Item { fn default() -> Self { - unsafe { - { - let mut __v: Item = ZeroInitializationUnsafe::zero_init(); - Item::constructor_1(&raw mut __v); - __v - } - } + unsafe { Item { value: 0 } } } } pub unsafe fn argument_4(item: *mut Item) -> *mut Item { @@ -73,7 +67,7 @@ pub struct RefItem { } impl RefItem { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).value).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, counter: LvalueRefUnsafe, mut amount: i32) { let counter = (counter.as_ptr() as *mut i32); @@ -86,13 +80,7 @@ impl RefItem { } impl Default for RefItem { fn default() -> Self { - unsafe { - { - let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); - RefItem::constructor_1(&raw mut __v); - __v - } - } + unsafe { RefItem { value: 0 } } } } pub unsafe fn reference_5(counter: *mut i32) -> *mut i32 { diff --git a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs index 96e0eacc66..c17bb86ebc 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -26,7 +26,7 @@ pub struct Item { } impl Item { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).value).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, counter: LvalueRefUnsafe, mut amount: i32) { let counter = (counter.as_ptr() as *mut i32); @@ -39,13 +39,7 @@ impl Item { } impl Default for Item { fn default() -> Self { - unsafe { - { - let mut __v: Item = ZeroInitializationUnsafe::zero_init(); - Item::constructor_1(&raw mut __v); - __v - } - } + unsafe { Item { value: 0 } } } } pub unsafe fn receiver_2(m: *mut UnsafeMap) -> *mut UnsafeMap { @@ -81,17 +75,6 @@ impl Temporary { (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)).prefix_inc(); } } -impl Default for Temporary { - fn default() -> Self { - unsafe { - { - let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); - Temporary::constructor_1(&raw mut __v); - __v - } - } - } -} #[repr(C)] #[derive( Copy, @@ -100,7 +83,6 @@ impl Default for Temporary { FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -140,11 +122,7 @@ pub struct Owner { } impl Owner { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).ptr).write(Some(Box::new({ - let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); - Temporary::constructor_1(&raw mut __v); - __v - }))); + this.write(::default()); } pub unsafe fn value(this: *mut Self) -> *const i32 { return &(*(*this).ptr.as_deref().map_or(::std::ptr::null_mut(), |v| { @@ -156,10 +134,12 @@ impl Owner { impl Default for Owner { fn default() -> Self { unsafe { - { - let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); - Owner::constructor_1(&raw mut __v); - __v + Owner { + ptr: Some(Box::new({ + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); + __v + })), } } } @@ -172,7 +152,7 @@ pub struct Noncopy { } impl Noncopy { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).n).write(5); + this.write(::default()); } } impl Default for Noncopy { @@ -198,7 +178,7 @@ pub struct Held { } impl Held { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).ptr).write(std::ptr::null()); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, n: LvalueRefUnsafe>) { let n = (n.as_ptr() as *const i32); @@ -211,10 +191,8 @@ impl Held { impl Default for Held { fn default() -> Self { unsafe { - { - let mut __v: Held = ZeroInitializationUnsafe::zero_init(); - Held::constructor_1(&raw mut __v); - __v + Held { + ptr: std::ptr::null(), } } } @@ -739,7 +717,8 @@ unsafe fn main_0() -> i32 { keys.as_ptr().offset((3_i64) as isize), ) { let mut k: i32 = (*k); - (*selected.subscript(&k, || ::default())).value = 42; + (*selected.subscript(&k, || ::default_constructed())) + .value = 42; } } let mut a: i32 = 0; @@ -1005,8 +984,9 @@ unsafe fn main_0() -> i32 { __v }), }; - value = - (*(*references.subscript(&key, || ::default())).ptr) + value = (*(*references + .subscript(&key, || ::default_constructed())) + .ptr) } }; assert!( @@ -1062,9 +1042,10 @@ unsafe fn main_0() -> i32 { __v }), }; - value = (*(*arrays.subscript(&key, || ::default())) - .ptr - .offset((1) as isize)) + value = (*(*arrays + .subscript(&key, || ::default_constructed())) + .ptr + .offset((1) as isize)) } }; assert!( @@ -1309,8 +1290,9 @@ unsafe fn main_0() -> i32 { __v }), }; - value = - (*(*references.subscript(&key, || ::default())).ptr) + value = (*(*references + .subscript(&key, || ::default_constructed())) + .ptr) } }; assert!( @@ -1329,12 +1311,12 @@ unsafe fn main_0() -> i32 { ); let mut owners: UnsafeMap = UnsafeMap::new(); { - let mut __tmp_101: Owner = ZeroInitializationUnsafe::zero_init(); + let mut __tmp_101: Owner; { match (((unsafe { Owner::value( &mut (*{ - Owner::constructor_1(&raw mut __tmp_101); + __tmp_101 = ::default(); &mut __tmp_101 }), ) @@ -1350,7 +1332,9 @@ unsafe fn main_0() -> i32 { __v }), }; - value = (*(*owners.subscript(&key, || ::default())).ptr) + value = (*(*owners + .subscript(&key, || ::default_constructed())) + .ptr) } }; assert!(((value) == (5))); @@ -1369,11 +1353,7 @@ unsafe fn main_0() -> i32 { ) = { let mut __tmp_103: Option>; match (({ - __tmp_103 = Some(Box::new({ - let mut __v: Noncopy = ZeroInitializationUnsafe::zero_init(); - Noncopy::constructor_1(&raw mut __v); - __v - })); + __tmp_103 = Some(Box::new(::default())); &mut __tmp_103 } as *mut Option>),) { @@ -1386,11 +1366,7 @@ unsafe fn main_0() -> i32 { ) = { let mut __tmp_105: Option>; match (({ - __tmp_105 = Some(Box::new({ - let mut __v: Noncopy = ZeroInitializationUnsafe::zero_init(); - Noncopy::constructor_1(&raw mut __v); - __v - })); + __tmp_105 = Some(Box::new(::default())); &mut __tmp_105 } as *mut Option>),) { diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 52daa3f512..2618adf3db 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -25,7 +25,6 @@ pub unsafe fn pick_3(mut i: i32) -> *mut i32 { MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] diff --git a/tests/unit/out/unsafe/memcpy_struct_bytes.rs b/tests/unit/out/unsafe/memcpy_struct_bytes.rs index 2009639c7e..48854dadf5 100644 --- a/tests/unit/out/unsafe/memcpy_struct_bytes.rs +++ b/tests/unit/out/unsafe/memcpy_struct_bytes.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct point { pub x: i32, diff --git a/tests/unit/out/unsafe/memcpy_struct_layouts.rs b/tests/unit/out/unsafe/memcpy_struct_layouts.rs index a5b4b4e426..f2176c68df 100644 --- a/tests/unit/out/unsafe/memcpy_struct_layouts.rs +++ b/tests/unit/out/unsafe/memcpy_struct_layouts.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct packed { pub a: i32, @@ -32,7 +31,6 @@ pub struct packed { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct reordered { pub a: libc::c_char, @@ -48,7 +46,6 @@ pub struct reordered { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct tail { pub a: libc::c_char, @@ -63,7 +60,6 @@ pub struct tail { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct nested { pub t: tail, @@ -78,7 +74,6 @@ pub struct nested { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct array { pub name: [libc::c_char; 3], diff --git a/tests/unit/out/unsafe/memcpy_struct_struct.rs b/tests/unit/out/unsafe/memcpy_struct_struct.rs index e2a8ed6756..d2bebd14c3 100644 --- a/tests/unit/out/unsafe/memcpy_struct_struct.rs +++ b/tests/unit/out/unsafe/memcpy_struct_struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/memset_struct_tail.rs b/tests/unit/out/unsafe/memset_struct_tail.rs index cd756001e9..2146fa0efe 100644 --- a/tests/unit/out/unsafe/memset_struct_tail.rs +++ b/tests/unit/out/unsafe/memset_struct_tail.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct S { pub keep: i32, diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index 215170a416..3c417be76a 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -12,7 +12,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultInitializableUnsafe, SwappableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(move)] @@ -50,7 +49,7 @@ pub struct ConstMoveAssign { } impl ConstMoveAssign { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).mark).write(0); + this.write(::default()); } pub unsafe fn operator_assign_2( this: *mut Self, @@ -69,13 +68,7 @@ impl ConstMoveAssign { } impl Default for ConstMoveAssign { fn default() -> Self { - unsafe { - { - let mut __v: ConstMoveAssign = ZeroInitializationUnsafe::zero_init(); - ConstMoveAssign::constructor_1(&raw mut __v); - __v - } - } + unsafe { ConstMoveAssign { mark: 0 } } } } pub unsafe fn make_0(__return: *mut MoveOnly, mut v: i32) { @@ -135,10 +128,10 @@ unsafe fn main_0() -> i32 { assign_unsafe!(vec_[(0_usize)] = RvalueRefUnsafe(d)); assert!(((vec_[(0_usize)].v) == (8))); assert!(((d.v) == (0))); - object_unsafe!(m, ConstMoveAssign::constructor_1()); - object_unsafe!(m1, ConstMoveAssign::constructor_1()); - object_unsafe!(m2, ConstMoveAssign::constructor_1()); - object_unsafe!(cm, ConstMoveAssign::constructor_1()); + let mut m: ConstMoveAssign = ::default(); + let mut m1: ConstMoveAssign = ::default(); + let mut m2: ConstMoveAssign = ::default(); + let cm: ConstMoveAssign = ::default(); (unsafe { ConstMoveAssign::operator_assign_2(&raw mut m1, &mut m) }); (unsafe { ConstMoveAssign::operator_assign_3(&raw mut m2, &cm) }); assert!(((m1.mark) == (1))); diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index 560f78c913..12dbfed85f 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -7,9 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(move)] #[constructor(constructor_1, i32)] #[constructor(constructor_3, RvalueRefUnsafe)] @@ -37,7 +35,7 @@ pub struct ConstMove { } impl ConstMove { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).mark).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut ConstMove); @@ -50,19 +48,11 @@ impl ConstMove { } impl Default for ConstMove { fn default() -> Self { - unsafe { - { - let mut __v: ConstMove = ZeroInitializationUnsafe::zero_init(); - ConstMove::constructor_1(&raw mut __v); - __v - } - } + unsafe { ConstMove { mark: 0 } } } } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] @@ -93,9 +83,7 @@ impl ThrowingMove { } } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] @@ -183,9 +171,9 @@ unsafe fn main_0() -> i32 { vec_.push_moved(&mut f); assert!(((vec_[(0_usize)].v) == (7)) && ((vec_[(1_usize)].v) == (8))); assert!(((f.v) == (0))); - object_unsafe!(m, ConstMove::constructor_1()); + let mut m: ConstMove = ::default(); object_unsafe!(m1, ConstMove::constructor_2(RvalueRefUnsafe::bind(&mut m))); - object_unsafe!(cm, ConstMove::constructor_1()); + let cm: ConstMove = ::default(); object_unsafe!(m2, ConstMove::constructor_3(RvalueRefUnsafe::bind(&cm))); assert!(((m1.mark) == (1))); assert!(((m2.mark) == (10))); diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index bf79529233..33d1658373 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -7,9 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] diff --git a/tests/unit/out/unsafe/nested_structs.rs b/tests/unit/out/unsafe/nested_structs.rs index bfb1764e3f..2c5ecf6797 100644 --- a/tests/unit/out/unsafe/nested_structs.rs +++ b/tests/unit/out/unsafe/nested_structs.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -31,7 +30,6 @@ pub struct Level0_Level1_1_Level2_1_Level3_1 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -48,7 +46,6 @@ pub struct Level0_Level1_1_Level2_1_Level3_2 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -64,7 +61,6 @@ pub struct Level0_Level1_1_Level2_1 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -80,7 +76,6 @@ pub struct Level0_Level1_1 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -97,7 +92,6 @@ pub struct Level0_Level1_2 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/new.rs b/tests/unit/out/unsafe/new.rs index 374d0c37ce..054a7b3e63 100644 --- a/tests/unit/out/unsafe/new.rs +++ b/tests/unit/out/unsafe/new.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/new_bst.rs b/tests/unit/out/unsafe/new_bst.rs index 7837ddd131..8ed40091be 100644 --- a/tests/unit/out/unsafe/new_bst.rs +++ b/tests/unit/out/unsafe/new_bst.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/new_struct.rs b/tests/unit/out/unsafe/new_struct.rs index 0ffe4e02f1..ba8b132cca 100644 --- a/tests/unit/out/unsafe/new_struct.rs +++ b/tests/unit/out/unsafe/new_struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct Pair { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/nttp_distinct_specializations.rs b/tests/unit/out/unsafe/nttp_distinct_specializations.rs index 2e455c7a70..1683763153 100644 --- a/tests/unit/out/unsafe/nttp_distinct_specializations.rs +++ b/tests/unit/out/unsafe/nttp_distinct_specializations.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ impl S_2_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -58,7 +56,6 @@ impl S_1_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/offsetof.rs b/tests/unit/out/unsafe/offsetof.rs index 034870dd88..79d9559235 100644 --- a/tests/unit/out/unsafe/offsetof.rs +++ b/tests/unit/out/unsafe/offsetof.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -40,16 +39,6 @@ pub struct Frame { pub tag: u16, pub body: [libc::c_char; 64], } -impl Default for Frame { - fn default() -> Self { - unsafe { - Frame { - tag: 0_u16, - body: [(0 as libc::c_char); 64], - } - } - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/opaque_forward_decl.rs b/tests/unit/out/unsafe/opaque_forward_decl.rs index 54d591d405..e4bc807b8f 100644 --- a/tests/unit/out/unsafe/opaque_forward_decl.rs +++ b/tests/unit/out/unsafe/opaque_forward_decl.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct container { pub p: *mut opaque, diff --git a/tests/unit/out/unsafe/opaque_record_copy.rs b/tests/unit/out/unsafe/opaque_record_copy.rs index 6c3042bf02..d85b67666a 100644 --- a/tests/unit/out/unsafe/opaque_record_copy.rs +++ b/tests/unit/out/unsafe/opaque_record_copy.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -29,7 +28,6 @@ pub struct Probe {} ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/opaque_then_defined.rs b/tests/unit/out/unsafe/opaque_then_defined.rs index fabebaf001..3d1f41b5ab 100644 --- a/tests/unit/out/unsafe/opaque_then_defined.rs +++ b/tests/unit/out/unsafe/opaque_then_defined.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct list { pub head: *mut node, @@ -30,7 +29,6 @@ pub struct list { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct node { pub value: i32, diff --git a/tests/unit/out/unsafe/operator_arithmetic_free.rs b/tests/unit/out/unsafe/operator_arithmetic_free.rs index 7a9dccd758..2a1b5d3aed 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_free.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_free.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_arithmetic_member.rs b/tests/unit/out/unsafe/operator_arithmetic_member.rs index 681ebd8169..4b9247476a 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_member.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_member.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_bitwise_free.rs b/tests/unit/out/unsafe/operator_bitwise_free.rs index 57a7d648ba..c8e80316eb 100644 --- a/tests/unit/out/unsafe/operator_bitwise_free.rs +++ b/tests/unit/out/unsafe/operator_bitwise_free.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_bitwise_member.rs b/tests/unit/out/unsafe/operator_bitwise_member.rs index 351eaa5d27..f223eb45b4 100644 --- a/tests/unit/out/unsafe/operator_bitwise_member.rs +++ b/tests/unit/out/unsafe/operator_bitwise_member.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index 94ba85e9ea..d523c202be 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct Eq { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -76,7 +74,6 @@ impl LessThanComparableUnsafe for Cmp { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -112,7 +109,6 @@ impl LessThanComparableUnsafe for Both { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(OrdOnly::operator_cmp)] @@ -147,7 +143,6 @@ impl LessThanComparableUnsafe for OrdOnly { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -183,7 +178,6 @@ impl LessThanComparableUnsafe for Inner { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -229,7 +223,6 @@ impl LessThanComparableUnsafe for Outer { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -265,7 +258,6 @@ impl LessThanComparableUnsafe for Secondary { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] diff --git a/tests/unit/out/unsafe/operator_comparison_free.rs b/tests/unit/out/unsafe/operator_comparison_free.rs index 3f29909619..f082324a16 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -42,7 +41,6 @@ pub unsafe fn operator_lt_1(mut a: i32, b: *const S) -> bool { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_comparison_member.rs b/tests/unit/out/unsafe/operator_comparison_member.rs index 4e3b54c8b4..5ec1353c02 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_comparison_mixed.rs b/tests/unit/out/unsafe/operator_comparison_mixed.rs index a19dca88fe..2a46635877 100644 --- a/tests/unit/out/unsafe/operator_comparison_mixed.rs +++ b/tests/unit/out/unsafe/operator_comparison_mixed.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index d267606bf5..53e1ba94a8 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -54,7 +53,6 @@ pub unsafe fn operator_ge_3(mut a: X, mut b: X) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -70,7 +68,6 @@ pub struct Result { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -93,7 +90,6 @@ impl Custom { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -127,7 +123,6 @@ impl LessThanComparableUnsafe for Mixed { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -153,7 +148,6 @@ impl MyBool { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -189,7 +183,6 @@ pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { DefaultInitializableUnsafe, MemberwiseUnsafe, MoveAssignableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] @@ -222,7 +215,6 @@ pub static mut ref_true_8: std::cell::LazyCell = std::cell::LazyCell::n ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index d2172b3b03..ea0637ac01 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -12,9 +12,7 @@ impl LessThanComparableUnsafe for S { } } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe)] #[memberwise(move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(move)] diff --git a/tests/unit/out/unsafe/operator_compound_assignment_free.rs b/tests/unit/out/unsafe/operator_compound_assignment_free.rs index d07f94df86..a180bde94e 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_free.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_free.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_compound_assignment_member.rs b/tests/unit/out/unsafe/operator_compound_assignment_member.rs index bd8b89492b..a8eaf7dd0f 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_member.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_member.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_friend.rs b/tests/unit/out/unsafe/operator_friend.rs index 1d43aabf16..62e33bc3a1 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -48,7 +47,6 @@ impl ThreeWayComparableUnsafe for DefaultedOrd { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -81,7 +79,6 @@ pub unsafe fn operator_add_0(x: *const Inline, y: *const Inline) -> Inline { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -97,7 +94,6 @@ pub struct Inline { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -118,7 +114,6 @@ impl LessThanComparableUnsafe for Tmpl_int_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -134,7 +129,6 @@ pub struct Tmpl_int_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -150,7 +144,6 @@ pub struct Tmpl_long_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_less_than.rs b/tests/unit/out/unsafe/operator_less_than.rs index a80f6bd106..0c9faafe39 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_logical_free.rs b/tests/unit/out/unsafe/operator_logical_free.rs index 440d7d9a09..57fa6d30e5 100644 --- a/tests/unit/out/unsafe/operator_logical_free.rs +++ b/tests/unit/out/unsafe/operator_logical_free.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_logical_member.rs b/tests/unit/out/unsafe/operator_logical_member.rs index 5de075709d..5aab222b25 100644 --- a/tests/unit/out/unsafe/operator_logical_member.rs +++ b/tests/unit/out/unsafe/operator_logical_member.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_member_pointer_free.rs b/tests/unit/out/unsafe/operator_member_pointer_free.rs index 9daac8ade1..5912bae537 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_free.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_free.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -31,7 +30,6 @@ pub struct Inner { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_member_pointer_member.rs b/tests/unit/out/unsafe/operator_member_pointer_member.rs index c44182e765..6245e1e08c 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_member.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_member.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -31,7 +30,6 @@ pub struct Inner { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -52,7 +50,6 @@ pub static mut table_0: std::cell::LazyCell<[i32; 3]> = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_other_free.rs b/tests/unit/out/unsafe/operator_other_free.rs index 05b8c9c5da..d622a21ef3 100644 --- a/tests/unit/out/unsafe/operator_other_free.rs +++ b/tests/unit/out/unsafe/operator_other_free.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_other_member.rs b/tests/unit/out/unsafe/operator_other_member.rs index d14ee5c86c..a65549e356 100644 --- a/tests/unit/out/unsafe/operator_other_member.rs +++ b/tests/unit/out/unsafe/operator_other_member.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -34,7 +33,6 @@ impl Static { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_overloads.rs b/tests/unit/out/unsafe/operator_overloads.rs index 1f690397e0..8255e5a0f5 100644 --- a/tests/unit/out/unsafe/operator_overloads.rs +++ b/tests/unit/out/unsafe/operator_overloads.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_qualifiers.rs b/tests/unit/out/unsafe/operator_qualifiers.rs index a177054c4d..d4c3c20670 100644 --- a/tests/unit/out/unsafe/operator_qualifiers.rs +++ b/tests/unit/out/unsafe/operator_qualifiers.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index adab99e390..9e82a997b0 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index befbfad472..9cbdbfd17a 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -36,7 +35,6 @@ impl LessThanComparableUnsafe for Lt { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -52,7 +50,6 @@ pub struct Eq { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] @@ -81,7 +78,6 @@ impl LessThanComparableUnsafe for Cmp { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -102,7 +98,6 @@ impl LessThanComparableUnsafe for Free { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/overload_mangling.rs b/tests/unit/out/unsafe/overload_mangling.rs index 005bf039cc..b3d099e8aa 100644 --- a/tests/unit/out/unsafe/overload_mangling.rs +++ b/tests/unit/out/unsafe/overload_mangling.rs @@ -24,7 +24,6 @@ pub unsafe fn twice_2(mut n: i32) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -52,7 +51,6 @@ impl Access_S_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -149,7 +147,6 @@ impl S { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/pair_converting_construction.rs b/tests/unit/out/unsafe/pair_converting_construction.rs index 2674a4d16b..2a4597e250 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ impl Celsius { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -59,7 +57,6 @@ impl Meters { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -82,7 +79,6 @@ impl Label { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -113,7 +109,6 @@ impl Owner { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -153,17 +148,6 @@ impl ConstructorUnsafe<()> for Fallback { } } } -impl Default for Fallback { - fn default() -> Self { - unsafe { - { - let mut __v: Fallback = ZeroInitializationUnsafe::zero_init(); - Fallback::constructor_1(&raw mut __v, -1_i32); - __v - } - } - } -} #[repr(C)] #[derive( Copy, @@ -173,7 +157,6 @@ impl Default for Fallback { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -189,7 +172,6 @@ pub struct Counter { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -219,7 +201,6 @@ impl Tag { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -236,7 +217,6 @@ pub struct Tag { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/pod.rs b/tests/unit/out/unsafe/pod.rs index 3f28ae3ae9..dabf5105b6 100644 --- a/tests/unit/out/unsafe/pod.rs +++ b/tests/unit/out/unsafe/pod.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/pointer_array.rs b/tests/unit/out/unsafe/pointer_array.rs index 8d3ed9a99f..e3196b4309 100644 --- a/tests/unit/out/unsafe/pointer_array.rs +++ b/tests/unit/out/unsafe/pointer_array.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/pointers.rs b/tests/unit/out/unsafe/pointers.rs index 658a98e4d9..dae0b184dc 100644 --- a/tests/unit/out/unsafe/pointers.rs +++ b/tests/unit/out/unsafe/pointers.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/polymorphism.rs b/tests/unit/out/unsafe/polymorphism.rs index 571b2aac32..451c36ed86 100644 --- a/tests/unit/out/unsafe/polymorphism.rs +++ b/tests/unit/out/unsafe/polymorphism.rs @@ -16,13 +16,16 @@ pub unsafe trait Animal { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DefaultInitializableUnsafe, + DestructibleUnsafe, CopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Dog {} +impl Dog { + pub unsafe fn constructor_1(this: *mut Self) {} +} #[repr(C)] #[derive( Copy, @@ -30,17 +33,18 @@ pub struct Dog {} VaArg, FnPtrArg, ZeroInitializationUnsafe, - DefaultInitializableUnsafe, + DestructibleUnsafe, CopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Cat {} impl Cat { unsafe fn meow(this: *const Self) -> bool { return true; } + pub unsafe fn constructor_1(this: *mut Self) {} } pub fn main() { unsafe { @@ -49,10 +53,10 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut dog: Dog = ::default(); + object_unsafe!(dog, Dog::constructor_1()); let mut animal: *mut dyn Animal = (&mut dog as *mut Dog); let mut eat1: bool = (unsafe { (*(animal).cast_const()).bark() }); - let mut cat: Cat = ::default(); + object_unsafe!(cat, Cat::constructor_1()); animal = (&mut cat as *mut Cat); let mut eat2: bool = (unsafe { (*(animal).cast_const()).bark() }); assert!((eat1) && (!(eat2))); diff --git a/tests/unit/out/unsafe/ptr_cast_init.rs b/tests/unit/out/unsafe/ptr_cast_init.rs index 2d789809c0..89dd6b4858 100644 --- a/tests/unit/out/unsafe/ptr_cast_init.rs +++ b/tests/unit/out/unsafe/ptr_cast_init.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct header { pub tag: i32, @@ -30,7 +29,6 @@ pub struct header { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct view { pub tag: i32, diff --git a/tests/unit/out/unsafe/push_emplace_back.rs b/tests/unit/out/unsafe/push_emplace_back.rs index 3c4e44ba37..0f4fa3952f 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -31,7 +30,6 @@ pub struct Chunk { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -49,7 +47,6 @@ pub struct Writer { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -61,8 +58,17 @@ pub struct JPEGData { } impl JPEGData { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).com_data).write(Vec::new()); - (&raw mut (*this).app_data).write(Vec::new()); + this.write(::default()); + } +} +impl Default for JPEGData { + fn default() -> Self { + unsafe { + JPEGData { + com_data: Vec::new(), + app_data: Vec::new(), + } + } } } pub unsafe fn push_param_0(mut dest: *mut Vec>) { @@ -151,8 +157,7 @@ pub struct Pair { } impl Pair { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).first).write(-1_i32); - (&raw mut (*this).second).write(-1_i32); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, mut a: i32) { (&raw mut (*this).first).write(a); @@ -166,20 +171,15 @@ impl Pair { impl Default for Pair { fn default() -> Self { unsafe { - { - let mut __v: Pair = ZeroInitializationUnsafe::zero_init(); - Pair::constructor_1(&raw mut __v); - __v + Pair { + first: -1_i32, + second: -1_i32, } } } } pub unsafe fn emplace_ctor_args_7(mut pairs: *mut Vec) { - (*pairs).push_mut({ - let mut __v: Pair = ZeroInitializationUnsafe::zero_init(); - Pair::constructor_1(&raw mut __v); - __v - }); + (*pairs).push_mut(::default()); (*pairs).push_mut({ let mut __v: Pair = ZeroInitializationUnsafe::zero_init(); Pair::constructor_2(&raw mut __v, 3); @@ -197,11 +197,7 @@ pub unsafe fn emplace_deque_8(mut queue: *mut Vec) { Pair::constructor_3(&raw mut __v, 6, 7); __v }); - (*queue).push_mut({ - let mut __v: Pair = ZeroInitializationUnsafe::zero_init(); - Pair::constructor_1(&raw mut __v); - __v - }); + (*queue).push_mut(::default()); } pub unsafe fn emplace_scalar_9(mut values: *mut Vec, mut x: i32) { (*values).push_mut(0_i64); @@ -254,7 +250,6 @@ pub unsafe fn emplace_ref_self_read_13(values: *mut Vec) -> *mut i64 { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -266,8 +261,17 @@ pub struct Bytes { } impl Bytes { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(Vec::new()); - (&raw mut (*this).b).write([0_u8; 3]); + this.write(::default()); + } +} +impl Default for Bytes { + fn default() -> Self { + unsafe { + Bytes { + v: Vec::new(), + b: [0_u8; 3], + } + } } } pub unsafe fn emplace_from_element_14(mut v: *mut Vec>) { @@ -296,7 +300,6 @@ pub unsafe fn emplace_from_element_14(mut v: *mut Vec>) { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -322,7 +325,6 @@ pub static mut all_counted_16: std::cell::LazyCell<*mut Vec> = ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -374,7 +376,7 @@ unsafe fn main_0() -> i32 { (unsafe { push_param_0((&mut vecs as *mut Vec>)) }); assert!(((vecs.len()) == (1_usize))); assert!(vecs[(0_usize)].is_empty()); - object_unsafe!(jpg, JPEGData::constructor_1()); + let mut jpg: JPEGData = ::default(); (unsafe { push_local_from_field_1((&mut jpg as *mut JPEGData), true) }); assert!(((jpg.com_data.len()) == (1_usize))); assert!(((jpg.com_data[(0_usize)].len()) == (3_usize))); diff --git a/tests/unit/out/unsafe/random.rs b/tests/unit/out/unsafe/random.rs index 24f6193f2b..f89e2b1649 100644 --- a/tests/unit/out/unsafe/random.rs +++ b/tests/unit/out/unsafe/random.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -60,7 +59,6 @@ pub unsafe fn zero_0() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/reference_wrapper.rs b/tests/unit/out/unsafe/reference_wrapper.rs index d020e1cb30..6dd364dcbf 100644 --- a/tests/unit/out/unsafe/reference_wrapper.rs +++ b/tests/unit/out/unsafe/reference_wrapper.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/references.rs b/tests/unit/out/unsafe/references.rs index 87af1b0b6e..2016e04ad8 100644 --- a/tests/unit/out/unsafe/references.rs +++ b/tests/unit/out/unsafe/references.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -33,7 +32,6 @@ pub struct Pair { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/refs_as_args.rs b/tests/unit/out/unsafe/refs_as_args.rs index 6a7f10b69d..d14d66629c 100644 --- a/tests/unit/out/unsafe/refs_as_args.rs +++ b/tests/unit/out/unsafe/refs_as_args.rs @@ -26,7 +26,6 @@ pub unsafe fn more_refs_0(mut x1: i32, mut x2: i32, r1: *mut i32, r2: *const i32 ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs b/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs index 8dd5192d0d..f77b1f973d 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct S { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -49,7 +47,6 @@ pub struct W { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/reinterpret_cast_struct.rs b/tests/unit/out/unsafe/reinterpret_cast_struct.rs index e8be11c742..f4fc41080d 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_struct.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/reinterpret_cast_struct_to_struct.rs b/tests/unit/out/unsafe/reinterpret_cast_struct_to_struct.rs index 1f470f8072..5953c7701f 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_struct_to_struct.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_struct_to_struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct Point { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/reserved_keywords.rs b/tests/unit/out/unsafe/reserved_keywords.rs index d1e0ee0a77..3a0063c213 100644 --- a/tests/unit/out/unsafe/reserved_keywords.rs +++ b/tests/unit/out/unsafe/reserved_keywords.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -68,7 +67,6 @@ pub struct S { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -84,7 +82,6 @@ pub struct type_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/return_move.rs b/tests/unit/out/unsafe/return_move.rs index 7aa61bf3dc..63ac26572d 100644 --- a/tests/unit/out/unsafe/return_move.rs +++ b/tests/unit/out/unsafe/return_move.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct node { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs index 5432d79c1e..676fe806fa 100644 --- a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs +++ b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs @@ -15,7 +15,6 @@ pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_assign, move_assign)] #[derive(ConversionsUnsafe)] diff --git a/tests/unit/out/unsafe/rvalue_struct.rs b/tests/unit/out/unsafe/rvalue_struct.rs index c786ba21a5..1c0303f9b3 100644 --- a/tests/unit/out/unsafe/rvalue_struct.rs +++ b/tests/unit/out/unsafe/rvalue_struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs b/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs index 20ff4e81c4..3af7775911 100644 --- a/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs +++ b/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/self_referencing_initializer.rs b/tests/unit/out/unsafe/self_referencing_initializer.rs index 30d5c979ec..3390f42ad0 100644 --- a/tests/unit/out/unsafe/self_referencing_initializer.rs +++ b/tests/unit/out/unsafe/self_referencing_initializer.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -31,7 +30,6 @@ pub struct list_head { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -57,8 +55,7 @@ pub struct node_with_defaults { } impl node_with_defaults { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).next).write(std::ptr::null_mut()); - (&raw mut (*this).value).write(3); + this.write(::default()); } } impl Default for node_with_defaults { diff --git a/tests/unit/out/unsafe/size_t_static_member.rs b/tests/unit/out/unsafe/size_t_static_member.rs index 9a0d31b545..03afbad331 100644 --- a/tests/unit/out/unsafe/size_t_static_member.rs +++ b/tests/unit/out/unsafe/size_t_static_member.rs @@ -16,7 +16,6 @@ pub static mut c_0: std::cell::LazyCell = std::cell::LazyCell::new(|| uns ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub static mut table_size_1: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/size_t_template_param.rs b/tests/unit/out/unsafe/size_t_template_param.rs index 07f6e47a40..41ec08a671 100644 --- a/tests/unit/out/unsafe/size_t_template_param.rs +++ b/tests/unit/out/unsafe/size_t_template_param.rs @@ -19,7 +19,6 @@ pub unsafe fn array_ref_0(a: *mut [u64; 3]) -> u64 { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -42,7 +41,6 @@ impl PtrCtor_unsigned_long_ { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index c58ce47980..802a94c03b 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -21,7 +21,7 @@ pub struct Tracked { } impl Tracked { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); @@ -53,13 +53,7 @@ impl MoveAssignableUnsafe for Tracked { } impl Default for Tracked { fn default() -> Self { - unsafe { - { - let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); - Tracked::constructor_1(&raw mut __v); - __v - } - } + unsafe { Tracked { v: 0 } } } } impl LessThanComparableUnsafe for Tracked { @@ -77,7 +71,6 @@ pub unsafe fn greater_1(a: *const Tracked, b: *const Tracked) -> bool { DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -98,12 +91,7 @@ impl LessThanComparableUnsafe for MoveOnly { } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -114,7 +102,12 @@ pub struct Bag { } impl Bag { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).items).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Bag { + fn default() -> Self { + unsafe { Bag { items: Vec::new() } } } } impl LessThanComparableUnsafe for Bag { @@ -341,11 +334,7 @@ unsafe fn main_0() -> i32 { && ((vec_[(3_usize)].v) == (2)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); - let mut bags: [Bag; 3] = std::array::from_fn::<_, 3, _>(|_| { - let mut __v: Bag = ZeroInitializationUnsafe::zero_init(); - Bag::constructor_1(&raw mut __v); - __v - }); + let mut bags: [Bag; 3] = std::array::from_fn::<_, 3, _>(|_| ::default()); bags[(0) as usize].items.push_mut({ let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); Tracked::constructor_2(&raw mut __v, 1); @@ -392,7 +381,7 @@ unsafe fn main_0() -> i32 { && ((bags[(2) as usize].items.len()) == (2_usize)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); - let mut bag_vec: Vec = Vec::from_fn(3_usize, |_| ::default()); + let mut bag_vec: Vec = Vec::from_fn(3_usize, |_| ::default_constructed()); bag_vec[(1_usize)].items.push_mut({ let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); Tracked::constructor_2(&raw mut __v, 4); diff --git a/tests/unit/out/unsafe/static_local.rs b/tests/unit/out/unsafe/static_local.rs index 07433d91ea..695416d24e 100644 --- a/tests/unit/out/unsafe/static_local.rs +++ b/tests/unit/out/unsafe/static_local.rs @@ -30,7 +30,6 @@ static mut x_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/static_var_in_class.rs b/tests/unit/out/unsafe/static_var_in_class.rs index 61b816275e..ca8a058c54 100644 --- a/tests/unit/out/unsafe/static_var_in_class.rs +++ b/tests/unit/out/unsafe/static_var_in_class.rs @@ -16,7 +16,6 @@ static mut inner_const_0: std::cell::LazyCell = std::cell::LazyCell::new(|| ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -38,7 +37,6 @@ pub const anon_3_kValue: anon_3 = 3; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/stdcopy.rs b/tests/unit/out/unsafe/stdcopy.rs index 7ca1020bed..64859e7d79 100644 --- a/tests/unit/out/unsafe/stdcopy.rs +++ b/tests/unit/out/unsafe/stdcopy.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/strdup.rs b/tests/unit/out/unsafe/strdup.rs index 6956bfcdf4..3de03852d5 100644 --- a/tests/unit/out/unsafe/strdup.rs +++ b/tests/unit/out/unsafe/strdup.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct record { pub name: *mut libc::c_char, diff --git a/tests/unit/out/unsafe/string_literal_ptr_init.rs b/tests/unit/out/unsafe/string_literal_ptr_init.rs index 2e80d468b6..5baf27c2eb 100644 --- a/tests/unit/out/unsafe/string_literal_ptr_init.rs +++ b/tests/unit/out/unsafe/string_literal_ptr_init.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct label { pub name: *const libc::c_char, diff --git a/tests/unit/out/unsafe/string_substr.rs b/tests/unit/out/unsafe/string_substr.rs index b8ddb79023..051ab0c50e 100644 --- a/tests/unit/out/unsafe/string_substr.rs +++ b/tests/unit/out/unsafe/string_substr.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/struct_2d_array_field.rs b/tests/unit/out/unsafe/struct_2d_array_field.rs index 029a03a6c9..1a9a185392 100644 --- a/tests/unit/out/unsafe/struct_2d_array_field.rs +++ b/tests/unit/out/unsafe/struct_2d_array_field.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct table { pub rows: [[libc::c_char; 10]; 3], diff --git a/tests/unit/out/unsafe/struct_ctor.rs b/tests/unit/out/unsafe/struct_ctor.rs index 0cf44f6ffe..2c2857b3e7 100644 --- a/tests/unit/out/unsafe/struct_ctor.rs +++ b/tests/unit/out/unsafe/struct_ctor.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -50,7 +49,6 @@ pub unsafe fn foo_0(x: *mut i32) -> *mut i32 { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -85,17 +83,6 @@ impl Ptr_ { Value_::constructor_1(&raw mut (*this).v2, 22); } } -impl Default for Ptr_ { - fn default() -> Self { - unsafe { - { - let mut __v: Ptr_ = ZeroInitializationUnsafe::zero_init(); - Ptr_::constructor_1(&raw mut __v); - __v - } - } - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/struct_default_ctor.rs b/tests/unit/out/unsafe/struct_default_ctor.rs index d6b88c62e6..4b69a6f999 100644 --- a/tests/unit/out/unsafe/struct_default_ctor.rs +++ b/tests/unit/out/unsafe/struct_default_ctor.rs @@ -24,19 +24,12 @@ pub struct S { } impl S { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).a).write(11); - (&raw mut (*this).b).write(true); + this.write(::default()); } } impl Default for S { fn default() -> Self { - unsafe { - { - let mut __v: S = ZeroInitializationUnsafe::zero_init(); - S::constructor_1(&raw mut __v); - __v - } - } + unsafe { S { a: 11, b: true } } } } #[repr(C)] @@ -47,7 +40,6 @@ impl Default for S { FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -63,7 +55,6 @@ impl Declared {} FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -73,11 +64,16 @@ pub struct Holder { } impl Holder { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).items).write(std::array::from_fn::<_, 2, _>(|_| { - let mut __v: S = ZeroInitializationUnsafe::zero_init(); - S::constructor_1(&raw mut __v); - __v - })); + this.write(::default()); + } +} +impl Default for Holder { + fn default() -> Self { + unsafe { + Holder { + items: [::default(); 2], + } + } } } pub static mut kInit_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); @@ -98,7 +94,7 @@ pub struct FromStatic { } impl FromStatic { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write((*std::cell::LazyCell::force_mut(&mut *&raw mut kInit_0))); + this.write(::default()); } } impl Default for FromStatic { @@ -119,7 +115,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut d: *mut Declared = std::ptr::null_mut(); assert!((d).is_null()); - object_unsafe!(s, S::constructor_1()); + let mut s: S = ::default(); assert!(((s.a) == (11))); assert!(((s.b as i32) == (true as i32))); let mut h: *mut Holder = Box::leak( diff --git a/tests/unit/out/unsafe/struct_member_array_adjacency.rs b/tests/unit/out/unsafe/struct_member_array_adjacency.rs index 6f27ef0fe8..96f67cdaad 100644 --- a/tests/unit/out/unsafe/struct_member_array_adjacency.rs +++ b/tests/unit/out/unsafe/struct_member_array_adjacency.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct pair { pub a: [i32; 4], diff --git a/tests/unit/out/unsafe/struct_ptr.rs b/tests/unit/out/unsafe/struct_ptr.rs index dd8bc8ee8d..94f40894c1 100644 --- a/tests/unit/out/unsafe/struct_ptr.rs +++ b/tests/unit/out/unsafe/struct_ptr.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs index afb7188eb3..199292d250 100644 --- a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs @@ -16,7 +16,6 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, - Default, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] diff --git a/tests/unit/out/unsafe/structured_binding_element_ctor.rs b/tests/unit/out/unsafe/structured_binding_element_ctor.rs index 9c88a0824e..b791bae633 100644 --- a/tests/unit/out/unsafe/structured_binding_element_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_element_ctor.rs @@ -9,9 +9,7 @@ use std::rc::Rc; pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] @@ -36,9 +34,7 @@ impl Elem { } } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe)] #[memberwise(copy_constructor, move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/structured_binding_move_ctor.rs b/tests/unit/out/unsafe/structured_binding_move_ctor.rs index 5a2cc0cf9f..d9a943d9b1 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -9,9 +9,7 @@ use std::rc::Rc; pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] #[conversions(copy, move)] #[constructor(constructor_1, i32, i32)] #[constructor(constructor_2, LvalueRefUnsafe>)] @@ -50,7 +48,6 @@ impl Movable { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -69,8 +66,17 @@ impl Holder { return; } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).xs).write(Vec::new()); - (&raw mut (*this).ys).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Holder { + fn default() -> Self { + unsafe { + Holder { + xs: Vec::new(), + ys: Vec::new(), + } + } } } pub fn main() { diff --git a/tests/unit/out/unsafe/structured_binding_range_for.rs b/tests/unit/out/unsafe/structured_binding_range_for.rs index 5b26cd7cef..a1b27f67f1 100644 --- a/tests/unit/out/unsafe/structured_binding_range_for.rs +++ b/tests/unit/out/unsafe/structured_binding_range_for.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/structured_binding_ref.rs b/tests/unit/out/unsafe/structured_binding_ref.rs index 24101cca1f..39240ff760 100644 --- a/tests/unit/out/unsafe/structured_binding_ref.rs +++ b/tests/unit/out/unsafe/structured_binding_ref.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/structured_binding_trivial.rs b/tests/unit/out/unsafe/structured_binding_trivial.rs index 1c53d5aa8e..634ea0f74d 100644 --- a/tests/unit/out/unsafe/structured_binding_trivial.rs +++ b/tests/unit/out/unsafe/structured_binding_trivial.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index 37acfaaf99..2320a6e415 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -21,7 +21,7 @@ pub struct Tracked { } impl Tracked { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(0); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); @@ -53,23 +53,12 @@ impl MoveAssignableUnsafe for Tracked { } impl Default for Tracked { fn default() -> Self { - unsafe { - { - let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); - Tracked::constructor_1(&raw mut __v); - __v - } - } + unsafe { Tracked { v: 0 } } } } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -81,18 +70,22 @@ pub struct Pair { } impl Pair { pub unsafe fn constructor_1(this: *mut Self) { - Tracked::constructor_1(&raw mut (*this).x); - Tracked::constructor_1(&raw mut (*this).y); + this.write(::default()); + } +} +impl Default for Pair { + fn default() -> Self { + unsafe { + Pair { + x: ::default(), + y: ::default(), + } + } } } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -104,16 +97,17 @@ pub struct Arrays { } impl Arrays { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).a).write(std::array::from_fn::<_, 2, _>(|_| { - let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); - Tracked::constructor_1(&raw mut __v); - __v - })); - (&raw mut (*this).b).write(std::array::from_fn::<_, 2, _>(|_| { - let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); - Tracked::constructor_1(&raw mut __v); - __v - })); + this.write(::default()); + } +} +impl Default for Arrays { + fn default() -> Self { + unsafe { + Arrays { + a: std::array::from_fn::<_, 2, _>(|_| ::default()), + b: std::array::from_fn::<_, 2, _>(|_| ::default()), + } + } } } pub static mut copy_only_copies_1: std::cell::LazyCell = @@ -266,12 +260,7 @@ pub unsafe fn swapped_once_6() -> bool { } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -282,7 +271,12 @@ pub struct Owner { } impl Owner { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).p).write(None); + this.write(::default()); + } +} +impl Default for Owner { + fn default() -> Self { + unsafe { Owner { p: None } } } } pub fn main() { @@ -313,7 +307,7 @@ unsafe fn main_0() -> i32 { &raw mut (*m1.subscript_move( &mut __tmp_0, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) }) = RvalueRefUnsafe(_o) ) @@ -330,7 +324,7 @@ unsafe fn main_0() -> i32 { &raw mut (*m1.subscript_move( &mut __tmp_1, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) }) = RvalueRefUnsafe(_o) ) @@ -348,7 +342,7 @@ unsafe fn main_0() -> i32 { &raw mut (*m2.subscript_move( &mut __tmp_2, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) }) = RvalueRefUnsafe(_o) ) @@ -364,7 +358,7 @@ unsafe fn main_0() -> i32 { &mut (*m1.subscript_move( &mut __tmp_3, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) }; let __b: *mut _ = { @@ -372,7 +366,7 @@ unsafe fn main_0() -> i32 { &mut (*m1.subscript_move( &mut __tmp_4, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) }; SwappableUnsafe::swap(&mut *__a, __b) @@ -386,7 +380,7 @@ unsafe fn main_0() -> i32 { (*m1.subscript_move( &mut __tmp_5, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) .v }) == (20)) @@ -397,7 +391,7 @@ unsafe fn main_0() -> i32 { (*m1.subscript_move( &mut __tmp_6, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) .v }) == (10)) @@ -418,7 +412,7 @@ unsafe fn main_0() -> i32 { (*m1.subscript_move( &mut __tmp_7, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) .v }) == (30)) @@ -433,7 +427,7 @@ unsafe fn main_0() -> i32 { (*m2.subscript_move( &mut __tmp_8, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) .v }) == (20)) @@ -445,7 +439,7 @@ unsafe fn main_0() -> i32 { (*m2.subscript_move( &mut __tmp_9, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) .v }) == (10)) @@ -564,7 +558,7 @@ unsafe fn main_0() -> i32 { }; assert!(((pairs[(0) as usize].x.v) == (7)) && ((pairs[(1) as usize].y.v) == (8))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); - object_unsafe!(arrays, Arrays::constructor_1()); + let mut arrays: Arrays = ::default(); arrays.a[(0) as usize].v = 1; arrays.b[(1) as usize].v = 2; { @@ -622,7 +616,7 @@ unsafe fn main_0() -> i32 { &raw mut (*maps[(0) as usize].subscript_move( &mut __tmp_10, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) }) = RvalueRefUnsafe(_o) ) @@ -639,7 +633,7 @@ unsafe fn main_0() -> i32 { &raw mut (*maps[(1) as usize].subscript_move( &mut __tmp_11, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) }) = RvalueRefUnsafe(_o) ) @@ -659,7 +653,7 @@ unsafe fn main_0() -> i32 { (*maps[(0) as usize].subscript_move( &mut __tmp_12, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) .v }) == (2)) @@ -674,7 +668,7 @@ unsafe fn main_0() -> i32 { (*maps[(1) as usize].subscript_move( &mut __tmp_13, |__k| cpp_move_unsafe!(__k), - || ::default(), + || ::default_constructed(), )) .v }) == (1)) diff --git a/tests/unit/out/unsafe/tag_vs_identifier_collision.rs b/tests/unit/out/unsafe/tag_vs_identifier_collision.rs index 4519752d15..bf9f975ce4 100644 --- a/tests/unit/out/unsafe/tag_vs_identifier_collision.rs +++ b/tests/unit/out/unsafe/tag_vs_identifier_collision.rs @@ -19,7 +19,6 @@ pub const widget_enum_MODE_DONE: widget_enum = 2; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct widget { pub id: i32, @@ -34,7 +33,6 @@ pub struct widget { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct point_struct { pub x: i32, @@ -54,11 +52,6 @@ pub union point { pub whole: i32, pub half: i16, } -impl Default for point { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -73,11 +66,6 @@ pub union slot_union { pub i: i32, pub u: u32, } -impl Default for slot_union { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} pub type slot = u32; pub const slot_SLOT_A: slot = 0; pub const slot_SLOT_B: slot = 1; @@ -90,7 +78,6 @@ pub const slot_SLOT_B: slot = 1; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Inner { pub tag_field: i32, @@ -104,7 +91,6 @@ pub struct Inner { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Outer { pub field: Inner, @@ -118,7 +104,6 @@ pub struct Outer { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Inner_struct { pub typedef_field: i32, diff --git a/tests/unit/out/unsafe/template_default_arg.rs b/tests/unit/out/unsafe/template_default_arg.rs index 592373cf79..abf55d4574 100644 --- a/tests/unit/out/unsafe/template_default_arg.rs +++ b/tests/unit/out/unsafe/template_default_arg.rs @@ -24,7 +24,7 @@ pub struct A { } impl A { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(1); + this.write(::default()); } pub unsafe fn constructor_2(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); @@ -32,13 +32,7 @@ impl A { } impl Default for A { fn default() -> Self { - unsafe { - { - let mut __v: A = ZeroInitializationUnsafe::zero_init(); - A::constructor_1(&raw mut __v); - __v - } - } + unsafe { A { v: 1 } } } } #[repr(C)] @@ -58,18 +52,12 @@ pub struct B { } impl B { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).v).write(2); + this.write(::default()); } } impl Default for B { fn default() -> Self { - unsafe { - { - let mut __v: B = ZeroInitializationUnsafe::zero_init(); - B::constructor_1(&raw mut __v); - __v - } - } + unsafe { B { v: 2 } } } } #[repr(C)] @@ -81,7 +69,6 @@ impl Default for B { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -115,7 +102,6 @@ pub unsafe fn always_given_3(mut x: NoDefault) -> i32 { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -138,15 +124,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - assert!( - ((unsafe { - used_0({ - let mut __v: A = ZeroInitializationUnsafe::zero_init(); - A::constructor_1(&raw mut __v); - __v - }) - }) == (1)) - ); + assert!(((unsafe { used_0(::default(),) }) == (1))); assert!( ((unsafe { used_0({ @@ -156,15 +134,7 @@ unsafe fn main_0() -> i32 { }) }) == (5)) ); - assert!( - ((unsafe { - used_1({ - let mut __v: B = ZeroInitializationUnsafe::zero_init(); - B::constructor_1(&raw mut __v); - __v - }) - }) == (2)) - ); + assert!(((unsafe { used_1(::default(),) }) == (2))); assert!( ((unsafe { scaled_2( diff --git a/tests/unit/out/unsafe/template_static_member.rs b/tests/unit/out/unsafe/template_static_member.rs index c873d53a4f..61ebe0a7e0 100644 --- a/tests/unit/out/unsafe/template_static_member.rs +++ b/tests/unit/out/unsafe/template_static_member.rs @@ -16,7 +16,6 @@ pub static mut s_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsaf ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub static mut s_1: std::cell::LazyCell = ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -47,7 +45,6 @@ pub static mut s_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsaf ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -63,7 +60,6 @@ pub static mut hi_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsa ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -80,7 +76,6 @@ pub static mut hi_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsa ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/temporary_field_addr.rs b/tests/unit/out/unsafe/temporary_field_addr.rs index b8206f7d9c..e6f04946fc 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -16,7 +16,6 @@ use std::rc::Rc; MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -27,7 +26,12 @@ pub struct Inner { } impl Inner { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).values).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Inner { + fn default() -> Self { + unsafe { Inner { values: Vec::new() } } } } #[repr(C)] @@ -40,7 +44,6 @@ impl Inner { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -53,9 +56,18 @@ pub struct Outer { } impl Outer { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).values).write(Vec::new()); - Inner::constructor_1(&raw mut (*this).inner); - (&raw mut (*this).name).write([(0 as libc::c_char); 8]); + this.write(::default()); + } +} +impl Default for Outer { + fn default() -> Self { + unsafe { + Outer { + values: Vec::new(), + inner: ::default(), + name: [(0 as libc::c_char); 8], + } + } } } pub unsafe fn make_0(__return: *mut Outer, calls: *mut i32) { diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index ca5082b431..822b0f0192 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -16,7 +16,6 @@ use std::rc::Rc; MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -27,7 +26,12 @@ pub struct Outer { } impl Outer { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).values).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Outer { + fn default() -> Self { + unsafe { Outer { values: Vec::new() } } } } pub unsafe fn make_0(__return: *mut Outer) { @@ -45,7 +49,6 @@ pub unsafe fn make_0(__return: *mut Outer) { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index f23edc40f5..c317df027d 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -16,7 +16,6 @@ use std::rc::Rc; MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -27,7 +26,12 @@ pub struct Inner { } impl Inner { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).values).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Inner { + fn default() -> Self { + unsafe { Inner { values: Vec::new() } } } } #[repr(C)] @@ -40,7 +44,6 @@ impl Inner { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -52,8 +55,17 @@ pub struct Outer { } impl Outer { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).values).write(Vec::new()); - Inner::constructor_1(&raw mut (*this).inner); + this.write(::default()); + } +} +impl Default for Outer { + fn default() -> Self { + unsafe { + Outer { + values: Vec::new(), + inner: ::default(), + } + } } } pub unsafe fn make_0(__return: *mut Outer) { diff --git a/tests/unit/out/unsafe/this.rs b/tests/unit/out/unsafe/this.rs index 471e7670b3..ced63adb1a 100644 --- a/tests/unit/out/unsafe/this.rs +++ b/tests/unit/out/unsafe/this.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -124,7 +123,6 @@ pub unsafe fn bump_0(mut p: *mut S) { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/typedef-anon-struct.rs b/tests/unit/out/unsafe/typedef-anon-struct.rs index 111a77f22b..7b7b668509 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -33,7 +32,6 @@ pub struct Outer_RunInfo { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -44,7 +42,12 @@ pub struct Outer { } impl Outer { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).runs).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Outer { + fn default() -> Self { + unsafe { Outer { runs: Vec::new() } } } } pub fn main() { @@ -54,7 +57,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(o, Outer::constructor_1()); + let mut o: Outer = ::default(); let mut info: Outer_RunInfo = ::default(); info.block_idx = 1; info.num_extra_zero_runs = 2; diff --git a/tests/unit/out/unsafe/types.rs b/tests/unit/out/unsafe/types.rs index db83187b82..bcbdaea4be 100644 --- a/tests/unit/out/unsafe/types.rs +++ b/tests/unit/out/unsafe/types.rs @@ -41,7 +41,7 @@ unsafe fn main_0() -> i32 { let mut xc8: u8 = 66_u8; let mut xc16: u16 = 67_u16; let mut xc32: u32 = 68_u32; - let mut xnp: *mut ::libc::c_void = Default::default(); + let mut xnp: *mut ::libc::c_void = std::ptr::null_mut(); assert!( (((((((((((((xu8 as i32) + (xu16 as i32)) as u32).wrapping_add(xu32)) as u64) .wrapping_add(xu64)) diff --git a/tests/unit/out/unsafe/unary_expr_or_type_trait.rs b/tests/unit/out/unsafe/unary_expr_or_type_trait.rs index be0622e922..c38d4e22a3 100644 --- a/tests/unit/out/unsafe/unary_expr_or_type_trait.rs +++ b/tests/unit/out/unsafe/unary_expr_or_type_trait.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/unboxed_locals.rs b/tests/unit/out/unsafe/unboxed_locals.rs index 748a99e85b..3563fb6fb8 100644 --- a/tests/unit/out/unsafe/unboxed_locals.rs +++ b/tests/unit/out/unsafe/unboxed_locals.rs @@ -21,7 +21,6 @@ pub unsafe fn inc_1(r: *mut i32) { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -68,17 +67,18 @@ pub unsafe trait Shape { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DefaultInitializableUnsafe, + DestructibleUnsafe, CopyableUnsafe, ConversionsUnsafe, )] #[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Square { pub side: i32, } -impl Default for Square { - fn default() -> Self { - unsafe { Square { side: 2 } } +impl Square { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).side).write(2); } } pub fn main() { @@ -186,7 +186,7 @@ unsafe fn main_0() -> i32 { let mut data: Vec = Vec::from_fn(2_usize, |_| copy_constructed_unsafe(&mut 0)); (unsafe { set_0(data.as_mut_ptr(), 8) }); assert!(((data[(0_usize)]) == (8))); - let mut square: Square = ::default(); + object_unsafe!(square, Square::constructor_1()); let mut shape: *mut dyn Shape = (&mut square as *mut Square); assert!(((unsafe { (*shape).scale(3,) }) == (6))); return 0; diff --git a/tests/unit/out/unsafe/unboxed_records.rs b/tests/unit/out/unsafe/unboxed_records.rs index ad4045ab72..b68e66589d 100644 --- a/tests/unit/out/unsafe/unboxed_records.rs +++ b/tests/unit/out/unsafe/unboxed_records.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -32,7 +31,6 @@ pub struct Inner { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -63,7 +61,7 @@ impl Counter { (*this).n.prefix_inc(); } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).n).write(0); + this.write(::default()); } } impl Default for Counter { @@ -133,7 +131,7 @@ unsafe fn main_0() -> i32 { let mut field_addr: Inner = Inner { a: 0, b: 0 }; (unsafe { set_0((&mut field_addr.b as *mut i32), 7) }); assert!(((field_addr.b) == (7))); - object_unsafe!(counter, Counter::constructor_1()); + let mut counter: Counter = ::default(); (unsafe { Counter::inc(&raw mut counter) }); assert!(((counter.n) == (1))); return 0; diff --git a/tests/unit/out/unsafe/union_addrof_external.rs b/tests/unit/out/unsafe/union_addrof_external.rs index 074e9570c5..b0143bbcc1 100644 --- a/tests/unit/out/unsafe/union_addrof_external.rs +++ b/tests/unit/out/unsafe/union_addrof_external.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct record { pub code: u16, @@ -37,11 +36,6 @@ pub union anon_0 { pub h: record, pub raw_: [libc::c_char; 128], } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -51,7 +45,6 @@ impl Default for anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Container { pub view: anon_0, diff --git a/tests/unit/out/unsafe/union_basic.rs b/tests/unit/out/unsafe/union_basic.rs index 3db1c405cc..a81ef0c5fc 100644 --- a/tests/unit/out/unsafe/union_basic.rs +++ b/tests/unit/out/unsafe/union_basic.rs @@ -20,11 +20,6 @@ pub union basic { pub i: i32, pub f: f32, } -impl Default for basic { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -38,11 +33,6 @@ impl Default for basic { pub union empty { __empty: u8, } -impl Default for empty { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -57,11 +47,6 @@ pub union underscores { pub __: i32, pub ___: f64, } -impl Default for underscores { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -128,9 +113,4 @@ pub union anon_0 { pub ai: i32, pub af: f32, } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/union_cross_arm_cast.rs b/tests/unit/out/unsafe/union_cross_arm_cast.rs index 4c6f8cb4ab..caf353a767 100644 --- a/tests/unit/out/unsafe/union_cross_arm_cast.rs +++ b/tests/unit/out/unsafe/union_cross_arm_cast.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct shape_a { pub code: u16, @@ -30,7 +29,6 @@ pub struct shape_a { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct shape_b { pub code: u16, @@ -54,11 +52,6 @@ pub union anon_0 { pub b: shape_b, pub raw_: [libc::c_char; 64], } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -68,7 +61,6 @@ impl Default for anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Container { pub len: u32, diff --git a/tests/unit/out/unsafe/union_field_alignment.rs b/tests/unit/out/unsafe/union_field_alignment.rs index 770621d105..716524aa50 100644 --- a/tests/unit/out/unsafe/union_field_alignment.rs +++ b/tests/unit/out/unsafe/union_field_alignment.rs @@ -20,11 +20,6 @@ pub union anon_0 { pub bytes: [u8; 1], pub aligner: *mut ::libc::c_void, } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -34,7 +29,6 @@ impl Default for anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct node { pub next: *mut node, diff --git a/tests/unit/out/unsafe/union_flex_array_member.rs b/tests/unit/out/unsafe/union_flex_array_member.rs index 5dd0cae24b..69ec9b71a1 100644 --- a/tests/unit/out/unsafe/union_flex_array_member.rs +++ b/tests/unit/out/unsafe/union_flex_array_member.rs @@ -20,11 +20,6 @@ pub union anon_0 { pub bytes: [u8; 1], pub aligner: *mut ::libc::c_void, } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -34,7 +29,6 @@ impl Default for anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct node { pub len: usize, diff --git a/tests/unit/out/unsafe/union_memset_memcpy.rs b/tests/unit/out/unsafe/union_memset_memcpy.rs index 002f4c8e92..c2c505deac 100644 --- a/tests/unit/out/unsafe/union_memset_memcpy.rs +++ b/tests/unit/out/unsafe/union_memset_memcpy.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct shape_a { pub code: u16, @@ -30,7 +29,6 @@ pub struct shape_a { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct shape_b { pub code: u16, @@ -53,11 +51,6 @@ pub union anon_0 { pub b: shape_b, pub raw_: [libc::c_char; 256], } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -67,7 +60,6 @@ impl Default for anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Container { pub view: anon_0, diff --git a/tests/unit/out/unsafe/union_nested.rs b/tests/unit/out/unsafe/union_nested.rs index d01e16aaf6..263962e6f2 100644 --- a/tests/unit/out/unsafe/union_nested.rs +++ b/tests/unit/out/unsafe/union_nested.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct record { pub code: u16, @@ -35,11 +34,6 @@ pub union anon_0 { pub h: record, pub raw_: [libc::c_char; 128], } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -49,7 +43,6 @@ impl Default for anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct inner { pub view: anon_0, @@ -68,11 +61,6 @@ pub union anon_1 { pub h: record, pub nested: inner, } -impl Default for anon_1 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -82,7 +70,6 @@ impl Default for anon_1 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Outer { pub kind: i32, diff --git a/tests/unit/out/unsafe/union_pointer_pun_address.rs b/tests/unit/out/unsafe/union_pointer_pun_address.rs index 800d16877e..e72b0ad653 100644 --- a/tests/unit/out/unsafe/union_pointer_pun_address.rs +++ b/tests/unit/out/unsafe/union_pointer_pun_address.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct node_a { pub n: i32, @@ -29,7 +28,6 @@ pub struct node_a { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct node_b { pub data: *mut ::libc::c_void, @@ -63,9 +61,4 @@ pub union anon_0 { pub to_a: *mut node_a, pub to_b: *mut node_b, } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs b/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs index abf73be7db..22d954cc58 100644 --- a/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs +++ b/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs @@ -34,9 +34,4 @@ pub union anon_0 { pub as_unsigned: *mut u64, pub as_signed: *mut i64, } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/union_struct_dual_use.rs b/tests/unit/out/unsafe/union_struct_dual_use.rs index eb77ee61b0..8470abf224 100644 --- a/tests/unit/out/unsafe/union_struct_dual_use.rs +++ b/tests/unit/out/unsafe/union_struct_dual_use.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Inner { pub a: i32, @@ -38,11 +37,6 @@ pub union anon_1 { pub inner: Inner, pub raw_: [libc::c_char; 16], } -impl Default for anon_1 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -52,7 +46,6 @@ impl Default for anon_1 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Outer { pub u: anon_1, diff --git a/tests/unit/out/unsafe/union_tagged_many_arms.rs b/tests/unit/out/unsafe/union_tagged_many_arms.rs index 2b2c7abcde..49fdbd7443 100644 --- a/tests/unit/out/unsafe/union_tagged_many_arms.rs +++ b/tests/unit/out/unsafe/union_tagged_many_arms.rs @@ -29,11 +29,6 @@ pub union anon_0 { pub unsigned_n: u64, pub f: f64, } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -43,7 +38,6 @@ impl Default for anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Slot { pub tag: Tag_enum, diff --git a/tests/unit/out/unsafe/union_tagged_simple.rs b/tests/unit/out/unsafe/union_tagged_simple.rs index 0797efcf2a..f75ecf15b5 100644 --- a/tests/unit/out/unsafe/union_tagged_simple.rs +++ b/tests/unit/out/unsafe/union_tagged_simple.rs @@ -23,11 +23,6 @@ pub union anon_0 { pub obj: *mut ::libc::c_void, pub code: i32, } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -37,7 +32,6 @@ impl Default for anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Event { pub kind: Kind_enum, diff --git a/tests/unit/out/unsafe/union_tagged_struct_arms.rs b/tests/unit/out/unsafe/union_tagged_struct_arms.rs index 50de080c50..beb1ad2c73 100644 --- a/tests/unit/out/unsafe/union_tagged_struct_arms.rs +++ b/tests/unit/out/unsafe/union_tagged_struct_arms.rs @@ -19,7 +19,6 @@ pub const Choice_enum_C_INTEGERS: Choice_enum = 3; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_1 { pub items: *mut *mut libc::c_char, @@ -35,7 +34,6 @@ pub struct anon_1 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_2 { pub lo: i32, @@ -52,7 +50,6 @@ pub struct anon_2 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct anon_3 { pub lo: i64, @@ -76,11 +73,6 @@ pub union anon_0 { pub letters: anon_2, pub integers: anon_3, } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -90,7 +82,6 @@ impl Default for anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Branch { pub choice: Choice_enum, diff --git a/tests/unit/out/unsafe/union_void_ptr_sized_deref.rs b/tests/unit/out/unsafe/union_void_ptr_sized_deref.rs index 404e5b9cb3..be006923f8 100644 --- a/tests/unit/out/unsafe/union_void_ptr_sized_deref.rs +++ b/tests/unit/out/unsafe/union_void_ptr_sized_deref.rs @@ -26,11 +26,6 @@ pub union anon_0 { pub signed_n: i64, pub f: f64, } -impl Default for anon_0 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} #[repr(C)] #[derive( Copy, @@ -40,7 +35,6 @@ impl Default for anon_0 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct Sink { pub width: Width_enum, diff --git a/tests/unit/out/unsafe/unique_ptr.rs b/tests/unit/out/unsafe/unique_ptr.rs index 45b54ebaa8..21e7b88e24 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -8,12 +8,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -31,7 +26,12 @@ impl SafePointer { .prefix_inc(); } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).ptr).write(None); + this.write(::default()); + } +} +impl Default for SafePointer { + fn default() -> Self { + unsafe { SafePointer { ptr: None } } } } #[repr(C)] @@ -43,7 +43,6 @@ impl SafePointer { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/unique_ptr_const_deref.rs b/tests/unit/out/unsafe/unique_ptr_const_deref.rs index f8dd9749e8..f7555921bd 100644 --- a/tests/unit/out/unsafe/unique_ptr_const_deref.rs +++ b/tests/unit/out/unsafe/unique_ptr_const_deref.rs @@ -8,12 +8,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -24,7 +19,12 @@ pub struct Holder { } impl Holder { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).val).write(None); + this.write(::default()); + } +} +impl Default for Holder { + fn default() -> Self { + unsafe { Holder { val: None } } } } pub unsafe fn read_val_0(mut h: *const Holder) -> i32 { @@ -46,7 +46,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(h, Holder::constructor_1()); + let mut h: Holder = ::default(); { h.val = Some(Box::new(10)).take(); }; diff --git a/tests/unit/out/unsafe/unique_ptr_field_reset.rs b/tests/unit/out/unsafe/unique_ptr_field_reset.rs index 794691a49b..0c223ae1fc 100644 --- a/tests/unit/out/unsafe/unique_ptr_field_reset.rs +++ b/tests/unit/out/unsafe/unique_ptr_field_reset.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -24,12 +23,7 @@ pub struct Data { } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -48,8 +42,17 @@ impl Holder { }; } pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).data).write(None); - (&raw mut (*this).n).write(0_i32); + this.write(::default()); + } +} +impl Default for Holder { + fn default() -> Self { + unsafe { + Holder { + data: None, + n: 0_i32, + } + } } } pub static mut trace_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); @@ -70,7 +73,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(h, Holder::constructor_1()); + let mut h: Holder = ::default(); h.n = 1; let mut hp: *mut Holder = (&mut h as *mut Holder); { diff --git a/tests/unit/out/unsafe/unique_ptr_nested.rs b/tests/unit/out/unsafe/unique_ptr_nested.rs index a0dddc0a8d..5e8d972288 100644 --- a/tests/unit/out/unsafe/unique_ptr_nested.rs +++ b/tests/unit/out/unsafe/unique_ptr_nested.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -25,12 +24,7 @@ pub struct Inner { } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -41,7 +35,12 @@ pub struct Outer { } impl Outer { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).inner).write(None); + this.write(::default()); + } +} +impl Default for Outer { + fn default() -> Self { + unsafe { Outer { inner: None } } } } pub fn main() { diff --git a/tests/unit/out/unsafe/unique_ptr_struct.rs b/tests/unit/out/unsafe/unique_ptr_struct.rs index 78047726f7..357d982fc1 100644 --- a/tests/unit/out/unsafe/unique_ptr_struct.rs +++ b/tests/unit/out/unsafe/unique_ptr_struct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/va_arg_mixed_types.rs b/tests/unit/out/unsafe/va_arg_mixed_types.rs index a49854d2a7..3cf303e10d 100644 --- a/tests/unit/out/unsafe/va_arg_mixed_types.rs +++ b/tests/unit/out/unsafe/va_arg_mixed_types.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct pair { pub a: i32, diff --git a/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs b/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs index ca56031b25..a32cd9ad4d 100644 --- a/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct node { pub data: i32, diff --git a/tests/unit/out/unsafe/va_arg_struct_ctx.rs b/tests/unit/out/unsafe/va_arg_struct_ctx.rs index 234eabf4d5..24885426f9 100644 --- a/tests/unit/out/unsafe/va_arg_struct_ctx.rs +++ b/tests/unit/out/unsafe/va_arg_struct_ctx.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct context { pub verbose: i32, @@ -46,11 +45,6 @@ pub union value { pub i: i32, pub l: i64, } -impl Default for value { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} pub unsafe fn pick_1(mut use_long: i32, __args: Box<[VaArg]>) -> i64 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); diff --git a/tests/unit/out/unsafe/va_arg_void_ptr.rs b/tests/unit/out/unsafe/va_arg_void_ptr.rs index 02d10525e7..0896c98dc8 100644 --- a/tests/unit/out/unsafe/va_arg_void_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_void_ptr.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, )] pub struct registry { pub slot: *mut ::libc::c_void, diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs index 7011b782b9..e71f574aed 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -75,7 +75,6 @@ pub unsafe fn sum_ptr_2(mut n: i32, __args: Box<[VaArg]>) -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index 44560dac26..af58aec23d 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -33,7 +32,6 @@ pub unsafe fn copy_0(mut copy_vector: Vec) {} MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -45,8 +43,17 @@ pub struct Foo { } impl Foo { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).a).write(Vec::new()); - (&raw mut (*this).b).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Foo { + fn default() -> Self { + unsafe { + Foo { + a: Vec::new(), + b: Vec::new(), + } + } } } #[repr(C)] @@ -58,7 +65,6 @@ impl Foo { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -428,7 +434,7 @@ unsafe fn main_0() -> i32 { ((((v10.len()) == (1_usize)) && ((v10[(0_usize)]) == (4))) && ((v11.len()) == (3_usize))) && ((v11[(2_usize)]) == (3)) ); - object_unsafe!(foo, Foo::constructor_1()); + let mut foo: Foo = ::default(); { let mut __tmp_15: i32 = 5; foo.a.push_moved(&mut __tmp_15) diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index 202b307dc7..8e8a5fae5f 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -37,7 +36,6 @@ impl Degrees { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/vector_subscript_direct.rs b/tests/unit/out/unsafe/vector_subscript_direct.rs index 05d58cc823..4f82a1000b 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -38,7 +37,6 @@ impl Point { MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -50,8 +48,17 @@ pub struct Holder { } impl Holder { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).values).write(Vec::new()); - (&raw mut (*this).points).write(Vec::new()); + this.write(::default()); + } +} +impl Default for Holder { + fn default() -> Self { + unsafe { + Holder { + values: Vec::new(), + points: Vec::new(), + } + } } } pub unsafe fn push_and_index_0(v: *mut Vec) -> i32 { @@ -114,7 +121,7 @@ unsafe fn main_0() -> i32 { (*p) = 9; assert!(((v[(2_usize)]) == (9))); assert!(((unsafe { sum_ref_1(&v,) }) == (((((3) + (0)) + (9)) + (42)) + (5)))); - object_unsafe!(h, Holder::constructor_1()); + let mut h: Holder = ::default(); h.values.resize_with(2_usize, || 0_i32); h.values[(1_usize)] = 6; { diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index 1ba3b4e042..a75c324c55 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -15,7 +15,6 @@ use std::rc::Rc; ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -46,7 +45,6 @@ impl TestAllocator_int_ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] diff --git a/tests/unit/out/unsafe/void_cast.rs b/tests/unit/out/unsafe/void_cast.rs index 73b2c93ee8..41bb55cc60 100644 --- a/tests/unit/out/unsafe/void_cast.rs +++ b/tests/unit/out/unsafe/void_cast.rs @@ -17,7 +17,6 @@ pub unsafe fn unused_param_0(mut x: i32) {} MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, - Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] @@ -28,7 +27,12 @@ pub struct NonTrivial { } impl NonTrivial { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).data).write(Vec::new()); + this.write(::default()); + } +} +impl Default for NonTrivial { + fn default() -> Self { + unsafe { NonTrivial { data: Vec::new() } } } } pub unsafe fn unused_ref_param_1(x: *const NonTrivial) {} @@ -48,7 +52,6 @@ pub unsafe fn bump_and_return_4() -> i32 { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, - Default, ConversionsUnsafe, )] #[conversions(copy, move)] @@ -57,12 +60,7 @@ pub struct Holder { } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - DestructibleUnsafe, - MemberwiseUnsafe, - SwappableUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] @@ -73,7 +71,12 @@ pub struct NonCopyable { } impl NonCopyable { pub unsafe fn constructor_1(this: *mut Self) { - (&raw mut (*this).value).write(None); + this.write(::default()); + } +} +impl Default for NonCopyable { + fn default() -> Self { + unsafe { NonCopyable { value: None } } } } pub unsafe fn unused_noncopyable_param_5(x: *const NonCopyable) {} @@ -126,7 +129,7 @@ unsafe fn main_0() -> i32 { let mut arr: [i32; 3] = [1, 2, 3]; let mut h: Holder = Holder { field: 17 }; let mut hp: *mut Holder = (&mut h as *mut Holder); - object_unsafe!(nt, NonTrivial::constructor_1()); + let mut nt: NonTrivial = ::default(); (unsafe { unused_ref_param_1(&nt) }); (unsafe { unused_ptr_param_2((&mut nt as *mut NonTrivial).cast_const()) }); let mut g: NonCopyable = NonCopyable {