diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 06ed04af8c..a24a19ee77 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -73,12 +73,11 @@ void Converter::EmitUndefinedRecordTraits(Model model, std::string &out) { if (converted_record_traits_.contains({record, name})) { continue; } + const auto &spelling = is_unsafe ? trait->unsafe : trait->refcount; out += std::format( "impl {} for {} {{ {} {{ unreachable!(\"{}::{} is never defined\") " "}} }}\n", - is_unsafe ? trait->unsafe_name : trait->name, record, - is_unsafe ? trait->unsafe_signature : trait->signature, record, - trait->method); + spelling.name, record, spelling.signature, record, trait->method); } } } @@ -88,16 +87,16 @@ void Converter::DeclareRecordTraits(const clang::CXXRecordDecl *decl) { for (auto *method : decl->methods()) { if (auto *trait = GetRecordTrait(method); trait && !IsDerivedCopyOrMove(method)) { - traits.emplace(trait->name, trait); + traits.emplace(trait->refcount.name, trait); } } - if (traits.contains(kCopyConstructible.name) && + if (traits.contains(kCopyConstructible.refcount.name) && !decl->hasUserDeclaredMoveConstructor()) { - traits.emplace(kMoveConstructible.name, &kMoveConstructible); + traits.emplace(kMoveConstructible.refcount.name, &kMoveConstructible); } - if (traits.contains(kCopyAssignable.name) && + if (traits.contains(kCopyAssignable.refcount.name) && !decl->hasUserDeclaredMoveAssignment()) { - traits.emplace(kMoveAssignable.name, &kMoveAssignable); + traits.emplace(kMoveAssignable.refcount.name, &kMoveAssignable); } } @@ -1098,7 +1097,7 @@ void Converter::ConvertCopyOrMoveTraitImpl(clang::CXXMethodDecl *method, return; } converted_record_traits_.emplace(GetRecordName(method->getParent()), - trait.name); + trait.refcount.name); StrCat(keyword::kImpl, GetCopyOrMoveTraitName(trait), "for", GetRecordName(method->getParent())); PushBrace brace(*this); @@ -2663,8 +2662,13 @@ std::string Converter::GetUFCSName(const clang::CXXMethodDecl *method) const { return GetRecordName(method->getParent()); } +const RecordTraitSpelling & +Converter::GetRecordTraitSpelling(const RecordTrait &trait) const { + return trait.unsafe; +} + const char *Converter::GetCopyOrMoveTraitName(const RecordTrait &trait) const { - return trait.unsafe_name; + return GetRecordTraitSpelling(trait).name; } void Converter::ConvertUserOperatorCall(clang::CXXOperatorCallExpr *expr) { @@ -5248,10 +5252,7 @@ Converter::GetStructAttributes(const clang::RecordDecl *decl) { if (decl->isUnion()) { std::vector union_attrs = { "Copy", "Clone", "FnPtrArg", "VaArg", "ZeroInitializationUnsafe"}; - if (!RecordDerivesTriviallyCopyable(decl)) { - union_attrs.emplace_back("DestructibleUnsafe"); - } - AddCopyAndMoveDerives(decl, union_attrs); + AddSpecialMemberDerives(decl, union_attrs); return union_attrs; } @@ -5275,12 +5276,7 @@ Converter::GetStructAttributes(const clang::RecordDecl *decl) { struct_attrs.emplace_back("CppFromUnsafe"); } - if (!ImplementsRecordTrait(decl, kDestructible) && - !RecordDerivesTriviallyCopyable(decl)) { - struct_attrs.emplace_back("DestructibleUnsafe"); - } - - AddCopyAndMoveDerives(decl, struct_attrs); + AddSpecialMemberDerives(decl, struct_attrs); if (RecordDerivesDefault(decl)) { struct_attrs.emplace_back("Default"); @@ -5802,8 +5798,8 @@ void Converter::AddCloneTrait(const clang::RecordDecl *decl) { TakePlacementValue())); } -void Converter::AddCopyAndMoveDerives(const clang::RecordDecl *decl, - std::vector &attrs) { +void Converter::AddSpecialMemberDerives(const clang::RecordDecl *decl, + std::vector &attrs) { auto implements = [&](const RecordTrait *trait) { return ImplementsRecordTrait(decl, *trait); }; @@ -5812,9 +5808,26 @@ void Converter::AddCopyAndMoveDerives(const clang::RecordDecl *decl, attrs.emplace_back(GetCopyOrMoveTraitName(trait)); for (const auto *provided_trait : provided) { converted_record_traits_.emplace(GetRecordName(decl), - provided_trait->name); + provided_trait->refcount.name); } }; + auto *cxx = clang::dyn_cast(decl); + bool trivial_default = !cxx || cxx->hasTrivialDefaultConstructor(); + if (trivial_default) { + attrs.emplace_back(GetCopyOrMoveTraitName(kTriviallyDefaultConstructible)); + } + bool derives_default = !trivial_default && + !implements(&kDefaultConstructible) && + !GetConvertedDefaultConstructor(decl); + bool derives_destructible = + !implements(&kDestructible) && !RecordDerivesTriviallyCopyable(decl); + if (derives_default && derives_destructible) { + attrs.emplace_back(GetCopyOrMoveTraitName(kDefaultInitializable)); + } else if (derives_default) { + attrs.emplace_back(GetCopyOrMoveTraitName(kDefaultConstructible)); + } else if (derives_destructible) { + attrs.emplace_back(GetCopyOrMoveTraitName(kDestructible)); + } if (!GetDerivedCopyOrMoves(decl).empty()) { attrs.emplace_back(GetCopyOrMoveTraitName(kMemberwise)); } @@ -5879,6 +5892,11 @@ void Converter::AddDefaultTraitForUnion(const clang::RecordDecl *decl) { } void Converter::AddDefaultTrait(const clang::RecordDecl *decl) { + if (auto *default_ctor = GetConvertedDefaultConstructor(decl); + default_ctor && !GetRecordTrait(default_ctor)) { + AddDefaultConstructibleTrait(clang::cast(decl), + default_ctor); + } if (decl->isUnion()) { AddDefaultTraitForUnion(decl); return; @@ -5896,19 +5914,37 @@ void Converter::AddDefaultTrait(const clang::RecordDecl *decl) { } if (auto *default_ctor = cxx ? GetUserDefinedDefaultConstructor(cxx) : nullptr) { - std::vector args; - for (auto *param : default_ctor->parameters()) { - args.push_back(clang::CXXDefaultArgExpr::Create( - ctx_, param->getLocation(), param, nullptr, default_ctor)); - } - Convert(MakeConstructExpr(ctx_, ctx_.getCanonicalTagType(decl), - default_ctor, args)); + Convert(MakeDefaultConstructExpr(cxx, default_ctor)); } else { EmitDefaultStructLiteral(decl); } }); } +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)); + } + return MakeConstructExpr(ctx_, ctx_.getCanonicalTagType(decl), ctor, args); +} + +void Converter::AddDefaultConstructibleTrait(const clang::CXXRecordDecl *decl, + clang::CXXConstructorDecl *ctor) { + const auto &spelling = GetRecordTraitSpelling(kDefaultConstructible); + StrCat(keyword::kImpl, spelling.name, "for", GetRecordName(decl)); + PushBrace impl_brace(*this); + StrCat(spelling.signature); + PushBrace fn_brace(*this); + StrCat(keyword_unsafe_); + PushBrace unsafe_brace(*this); + auto *construct = MakeDefaultConstructExpr(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))); @@ -6849,8 +6885,8 @@ std::string Converter::ConvertGenericCall( assert(expr && "unbound generic outside an expression rule"); type = RuleRegistry::GetGenericType(ctx_, expr, call.generic); } - if (call.method == "default") { - assert(call_args.empty() && "default takes no arguments"); + if (call.method == "default_constructed") { + assert(call_args.empty() && "default_constructed takes no arguments"); return GetUnboxedDefaultAsString(type); } if (call.method == "cpp_from" || call.method == "cpp_from_move") { diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 6f76693a61..de99a7cf8b 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -381,10 +381,13 @@ class Converter : public clang::RecursiveASTVisitor { virtual const char *GetConversionTraitName() const; - virtual const char *GetCopyOrMoveTraitName(const RecordTrait &trait) const; + virtual const RecordTraitSpelling & + GetRecordTraitSpelling(const RecordTrait &trait) const; - void AddCopyAndMoveDerives(const clang::RecordDecl *decl, - std::vector &attrs); + const char *GetCopyOrMoveTraitName(const RecordTrait &trait) const; + + void AddSpecialMemberDerives(const clang::RecordDecl *decl, + std::vector &attrs); virtual std::string DerefPtrExpr(std::string_view ptr_expr, clang::QualType pointee_type); @@ -970,6 +973,13 @@ class Converter : public clang::RecursiveASTVisitor { 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. diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 260006725e..49599ff6a1 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -578,6 +578,9 @@ const char *GetCopyOrMoveName(const clang::CXXMethodDecl *method) { if (ctor->isMoveConstructor()) { return "move_from"; } + if (ctor->isDefaultConstructor() && ctor->getNumParams() == 0) { + return "default_constructor"; + } return nullptr; } if (method->isCopyAssignmentOperator()) { @@ -606,8 +609,12 @@ static bool IsTranslatedCopyAssignment(const clang::CXXMethodDecl *method); static bool IsTranslatedMoveAssignment(const clang::CXXMethodDecl *method); -static bool IsTranslatedCopyOrMove(const clang::CXXMethodDecl *method) { +static bool IsTranslatedSpecialMember(const clang::CXXMethodDecl *method) { if (auto *ctor = clang::dyn_cast(method)) { + if (ctor->isDefaultConstructor()) { + return !ctor->getParent()->isUnion() && + IsConvertibleDefaultConstructor(ctor); + } return IsConvertibleCopyOrMoveConstructor(ctor); } return method->isCopyAssignmentOperator() @@ -633,13 +640,16 @@ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { const char *name = GetCopyOrMoveName(method); if (!name || method->isDeleted() || method->isVirtual() || !CanUseCopyOrMoveName(method, name) || - (!IsUserWrittenMember(method) && !IsTranslatedCopyOrMove(method))) { + (!IsUserWrittenMember(method) && !IsTranslatedSpecialMember(method))) { return nullptr; } auto *ctor = clang::dyn_cast(method); if (!ctor && !method->getReturnType()->isLValueReferenceType()) { return nullptr; } + if (ctor && ctor->isDefaultConstructor()) { + return &kDefaultConstructible; + } auto param = method->getParamDecl(0)->getType(); bool is_copy = ctor ? ctor->isCopyConstructor() : method->isCopyAssignmentOperator(); @@ -654,6 +664,10 @@ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { } bool IsDerivedCopyOrMove(const clang::CXXMethodDecl *method) { + if (auto *ctor = clang::dyn_cast(method); + ctor && ctor->isDefaultConstructor()) { + return false; + } return !method->isUserProvided() && GetRecordTrait(method); } @@ -708,35 +722,11 @@ bool IsConvertibleCopyConstructor(const clang::CXXConstructorDecl *ctor) { HasFieldWithCopyConstructor(ctor->getParent())); } -// Whether default-initializing a field of decl runs a translated constructor, -// which receives the field in place. -static bool HasFieldWithDefaultConstructor(const clang::CXXRecordDecl *decl) { - for (const auto *field : decl->fields()) { - if (auto *init = field->getInClassInitializer()) { - if (GetPlacementInitializer(init)) { - return true; - } - continue; - } - auto *record = field->getType()->getAsCXXRecordDecl(); - if (!record || !record->hasDefinition() || !IsUserDefinedDecl(record) || - record->isLambda()) { - continue; - } - if (record->hasUserProvidedDefaultConstructor() || - (IsConvertibleImplicitMemberParent(record) && - HasFieldWithDefaultConstructor(record))) { - return true; - } - } - return false; -} - bool IsConvertibleDefaultConstructor(const clang::CXXConstructorDecl *ctor) { return ctor->isDefaultConstructor() && !ctor->isUserProvided() && !ctor->isDeleted() && IsConvertibleImplicitMemberParent(ctor->getParent()) && - HasFieldWithDefaultConstructor(ctor->getParent()); + !ctor->isTrivial(); } // Whether moving a field of decl isn't a copy: the field is a record with a @@ -1248,6 +1238,23 @@ GetUserDefinedDefaultConstructor(const clang::CXXRecordDecl *decl) { return nullptr; } +clang::CXXConstructorDecl * +GetConvertedDefaultConstructor(const clang::RecordDecl *decl) { + auto *cxx = clang::dyn_cast(decl); + if (!cxx || cxx->isUnion()) { + return nullptr; + } + if (auto *ctor = GetUserDefinedDefaultConstructor(cxx)) { + return ctor; + } + for (auto *ctor : cxx->ctors()) { + if (IsConvertibleDefaultConstructor(ctor)) { + return ctor; + } + } + return nullptr; +} + bool HasUsableDefaultArg(const clang::ParmVarDecl *param) { return param->hasDefaultArg() && !param->hasUninstantiatedDefaultArg(); } diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 6213a38288..0632105b69 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -105,45 +105,72 @@ const char *GetCopyOrMoveName(const clang::CXXMethodDecl *method); bool CanUseCopyOrMoveName(const clang::CXXMethodDecl *decl, const std::string &name); -struct RecordTrait { +struct RecordTraitSpelling { const char *name; - const char *unsafe_name; + const char *signature = nullptr; + const char *receiver = nullptr; +}; + +struct RecordTrait { const char *method; - const char *signature; - const char *unsafe_signature; + RecordTraitSpelling refcount; + RecordTraitSpelling unsafe; }; +inline constexpr RecordTrait kDefaultConstructible{ + "default_constructor", + {"DefaultConstructible", "fn default_constructor(this: &Ptr)", + "this"}, + {"DefaultConstructibleUnsafe", "unsafe fn default_constructor(&mut self)", + "&mut *self"}}; inline constexpr RecordTrait kCopyConstructible{ - "CopyConstructible", "CopyConstructibleUnsafe", "copy_constructor", - "fn copy_constructor(_: &Ptr, _: Ptr)", - "unsafe fn copy_constructor(&mut self, _: *const Self)"}; + "copy_constructor", + {"CopyConstructible", "fn copy_constructor(this: &Ptr, _: Ptr)", + "this"}, + {"CopyConstructibleUnsafe", + "unsafe fn copy_constructor(&mut self, _: *const Self)", "&mut *self"}}; inline constexpr RecordTrait kMoveConstructible{ - "MoveConstructible", "MoveConstructibleUnsafe", "move_constructor", - "fn move_constructor(_: &Ptr, _: Ptr)", - "unsafe fn move_constructor(&mut self, _: *mut Self)"}; + "move_constructor", + {"MoveConstructible", "fn move_constructor(this: &Ptr, _: Ptr)", + "this"}, + {"MoveConstructibleUnsafe", + "unsafe fn move_constructor(&mut self, _: *mut Self)", "&mut *self"}}; inline constexpr RecordTrait kCopyAssignable{ - "CopyAssignable", "CopyAssignableUnsafe", "copy_assign", - "fn copy_assign(_: &Ptr, _: Ptr) -> Ptr", - "unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self"}; + "copy_assign", + {"CopyAssignable", + "fn copy_assign(this: &Ptr, _: Ptr) -> Ptr", "this"}, + {"CopyAssignableUnsafe", + "unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self", + "&mut *self"}}; inline constexpr RecordTrait kMoveAssignable{ - "MoveAssignable", "MoveAssignableUnsafe", "move_assign", - "fn move_assign(_: &Ptr, _: Ptr) -> Ptr", - "unsafe fn move_assign(&mut self, _: *mut Self) -> *mut Self"}; + "move_assign", + {"MoveAssignable", + "fn move_assign(this: &Ptr, _: Ptr) -> Ptr", "this"}, + {"MoveAssignableUnsafe", + "unsafe fn move_assign(&mut self, _: *mut Self) -> *mut Self", + "&mut *self"}}; inline constexpr RecordTrait kSwappable{ - "Swappable", "SwappableUnsafe", "swap", - "fn swap(_: &Ptr, _: Ptr)", - "unsafe fn swap(&mut self, _: *mut Self)"}; + "swap", + {"Swappable", "fn swap(this: &Ptr, _: Ptr)", "this"}, + {"SwappableUnsafe", "unsafe fn swap(&mut self, _: *mut Self)", + "&mut *self"}}; inline constexpr RecordTrait kDestructible{ - "Destructible", "DestructibleUnsafe", "destroy", - "fn destroy(_: &Ptr)", "unsafe fn destroy(&mut self)"}; -inline constexpr RecordTrait kMovable{"Movable", "MovableUnsafe", nullptr, - nullptr, nullptr}; -inline constexpr RecordTrait kCopyable{"Copyable", "CopyableUnsafe", nullptr, - nullptr, nullptr}; + "destroy", + {"Destructible", "fn destroy(this: &Ptr)", "this"}, + {"DestructibleUnsafe", "unsafe fn destroy(&mut self)", "&mut *self"}}; +inline constexpr RecordTrait kTriviallyDefaultConstructible{ + nullptr, + {"TriviallyDefaultConstructible"}, + {"TriviallyDefaultConstructibleUnsafe"}}; +inline constexpr RecordTrait kDefaultInitializable{ + nullptr, {"DefaultInitializable"}, {"DefaultInitializableUnsafe"}}; +inline constexpr RecordTrait kMovable{nullptr, {"Movable"}, {"MovableUnsafe"}}; +inline constexpr RecordTrait kCopyable{ + nullptr, {"Copyable"}, {"CopyableUnsafe"}}; inline constexpr RecordTrait kTriviallyCopyable{ - "TriviallyCopyable", "TriviallyCopyableUnsafe", nullptr, nullptr, nullptr}; -inline constexpr RecordTrait kMemberwise{"Memberwise", "MemberwiseUnsafe", - nullptr, nullptr, nullptr}; + nullptr, {"TriviallyCopyable"}, {"TriviallyCopyableUnsafe"}}; +inline constexpr RecordTrait kMemberwise{ + nullptr, {"Memberwise"}, {"MemberwiseUnsafe"}}; const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method); @@ -163,7 +190,7 @@ bool IsConvertibleCopyOrMoveConstructor(const clang::CXXConstructorDecl *ctor); bool IsConvertibleCopyConstructor(const clang::CXXConstructorDecl *ctor); // Whether ctor is a defaulted default constructor that is translated, as it -// default-initializes a field with a translated constructor, in place. +// is not trivial. bool IsConvertibleDefaultConstructor(const clang::CXXConstructorDecl *ctor); bool IsDefaultedMoveConstructor(const clang::CXXConstructorDecl *ctor); @@ -277,6 +304,9 @@ unsigned GetCtorIndex(clang::CXXConstructorDecl *ctor); clang::CXXConstructorDecl * GetUserDefinedDefaultConstructor(const clang::CXXRecordDecl *decl); +clang::CXXConstructorDecl * +GetConvertedDefaultConstructor(const clang::RecordDecl *decl); + bool HasUsableDefaultArg(const clang::ParmVarDecl *param); std::string GetFileName(const clang::Decl *decl); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 4e339e06a7..f5b59f4463 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -2357,10 +2357,7 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { if (decl->isUnion()) { std::vector union_attrs = {"VaArg", "FnPtrArg"}; - if (!RecordDerivesTriviallyCopyable(decl)) { - union_attrs.emplace_back("Destructible"); - } - AddCopyAndMoveDerives(decl, union_attrs); + AddSpecialMemberDerives(decl, union_attrs); return union_attrs; } @@ -2387,12 +2384,7 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { attrs.emplace_back("CppFrom"); } - if (!ImplementsRecordTrait(decl, kDestructible) && - !RecordDerivesTriviallyCopyable(decl)) { - attrs.emplace_back("Destructible"); - } - - AddCopyAndMoveDerives(decl, attrs); + AddSpecialMemberDerives(decl, attrs); if (RecordDerivesDefault(decl)) { attrs.emplace_back("Default"); @@ -2404,9 +2396,9 @@ const char *ConverterRefCount::GetConversionTraitName() const { return "CppFrom"; } -const char * -ConverterRefCount::GetCopyOrMoveTraitName(const RecordTrait &trait) const { - return trait.name; +const RecordTraitSpelling & +ConverterRefCount::GetRecordTraitSpelling(const RecordTrait &trait) const { + return trait.refcount; } bool ConverterRefCount::TypeDerivesDefault(clang::QualType qual_type) { diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 0ad31c5959..39eac342a4 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -542,7 +542,8 @@ class ConverterRefCount final : public Converter { const char *GetConversionTraitName() const override; - const char *GetCopyOrMoveTraitName(const RecordTrait &trait) const override; + const RecordTraitSpelling & + GetRecordTraitSpelling(const RecordTrait &trait) const override; bool IsBoxedType(clang::QualType type); bool IsVecType(clang::QualType type); diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index f2d1f9ea95..5c438d0c37 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -32,6 +32,51 @@ pub fn expand_movable(input: TokenStream, is_unsafe: bool) -> TokenStream { quote!(#(#impls)* #swap).into() } +pub fn expand_trivially_default_constructible(input: TokenStream, is_unsafe: bool) -> TokenStream { + let mut impls = expand_default_constructible(input.clone(), is_unsafe); + 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 tr = if is_unsafe { + quote!(::libcc2rs::TriviallyDefaultConstructibleUnsafe) + } else { + quote!(::libcc2rs::TriviallyDefaultConstructible) + }; + let marker: TokenStream = + quote!(impl #impl_generics #tr for #name #ty_generics #where_clause {}).into(); + impls.extend(marker); + impls +} + +pub fn expand_default_constructible(input: TokenStream, is_unsafe: bool) -> 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(); + if is_unsafe { + quote! { + impl #impl_generics ::libcc2rs::DefaultConstructibleUnsafe for #name #ty_generics #where_clause { + unsafe fn default_constructor(&mut self) { + unsafe { + ::std::ptr::write( + self, + ::zero_init(), + ) + } + } + } + } + } else { + quote! { + impl #impl_generics ::libcc2rs::DefaultConstructible for #name #ty_generics #where_clause { + fn default_constructor(this: &::libcc2rs::Ptr) { + this.write(::zero_init()); + } + } + } + } + .into() +} + pub fn expand_swappable(input: TokenStream, is_unsafe: bool) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); impl_swap(&input, is_unsafe).into() diff --git a/libcc2rs-macros/src/lib.rs b/libcc2rs-macros/src/lib.rs index ca0513fd73..997db20c39 100644 --- a/libcc2rs-macros/src/lib.rs +++ b/libcc2rs-macros/src/lib.rs @@ -175,6 +175,16 @@ pub fn derive_zero_initialization_unsafe(input: TokenStream) -> TokenStream { initialization::expand_unsafe(input) } +#[proc_macro_derive(DefaultConstructible)] +pub fn derive_default_constructible(input: TokenStream) -> TokenStream { + constructor::expand_default_constructible(input, false) +} + +#[proc_macro_derive(DefaultConstructibleUnsafe)] +pub fn derive_default_constructible_unsafe(input: TokenStream) -> TokenStream { + constructor::expand_default_constructible(input, true) +} + #[proc_macro_derive(CopyConstructible)] pub fn derive_copy_constructible(input: TokenStream) -> TokenStream { constructor::expand(input, "copy", false, false) @@ -283,6 +293,30 @@ pub fn derive_memberwise_unsafe(input: TokenStream) -> TokenStream { // Implements the C++ implicit destructor of S, which destroys the fields with a // destroy attribute, in reverse declaration order. +#[proc_macro_derive(TriviallyDefaultConstructible)] +pub fn derive_trivially_default_constructible(input: TokenStream) -> TokenStream { + constructor::expand_trivially_default_constructible(input, false) +} + +#[proc_macro_derive(TriviallyDefaultConstructibleUnsafe)] +pub fn derive_trivially_default_constructible_unsafe(input: TokenStream) -> TokenStream { + constructor::expand_trivially_default_constructible(input, true) +} + +#[proc_macro_derive(DefaultInitializable, attributes(destroy))] +pub fn derive_default_initializable(input: TokenStream) -> TokenStream { + let mut impls = constructor::expand_default_constructible(input.clone(), false); + impls.extend(destructor::expand(input, false)); + impls +} + +#[proc_macro_derive(DefaultInitializableUnsafe, attributes(destroy))] +pub fn derive_default_initializable_unsafe(input: TokenStream) -> TokenStream { + let mut impls = constructor::expand_default_constructible(input.clone(), true); + impls.extend(destructor::expand(input, true)); + impls +} + #[proc_macro_derive(Destructible, attributes(destroy))] pub fn derive_destructible(input: TokenStream) -> TokenStream { destructor::expand(input, false) diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index c62805e4c6..2cd83f6811 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -6,10 +6,24 @@ use crate::capture::{ }; use crate::fn_ptr::{FnPtr, FnSig}; use crate::initialization::ZeroInitialization; -use crate::rc::Ptr; +use crate::rc::{AsPointer, Ptr, Value}; use crate::reinterpret::ByteRepr; use crate::void::AnyPtr; +pub trait DefaultConstructible: Sized { + fn default_constructor(this: &Ptr); + + // TODO: remove default_constructed. + fn default_constructed() -> Self + where + Self: ZeroInitialization, + { + let dst: Value = std::rc::Rc::new(std::cell::RefCell::new(Self::zero_init())); + Self::default_constructor(&AsPointer::::as_pointer(&dst)); + std::rc::Rc::try_unwrap(dst).ok().unwrap().into_inner() + } +} + pub trait MoveConstructible: Sized { fn move_constructor(this: &Ptr, src: Ptr); } @@ -42,6 +56,12 @@ pub trait Swappable: Sized { fn swap(this: &Ptr, other: Ptr); } +pub trait TriviallyDefaultConstructible: DefaultConstructible {} + +pub trait DefaultInitializable: DefaultConstructible + Destructible {} + +impl DefaultInitializable for T {} + pub trait Movable: MoveConstructible + MoveAssignable + Swappable + Destructible {} impl Movable for T {} @@ -69,6 +89,24 @@ impl< { } +pub trait DefaultConstructibleUnsafe { + /// # Safety + /// `self` must be valid for writes. + unsafe fn default_constructor(&mut self); + + // TODO: remove default_constructed. + fn default_constructed() -> Self + where + Self: Sized, + { + let mut dst = std::mem::MaybeUninit::::zeroed(); + unsafe { + (*dst.as_mut_ptr()).default_constructor(); + dst.assume_init() + } + } +} + pub trait MoveConstructibleUnsafe { /// # Safety /// `src` must point to a live value. @@ -115,6 +153,12 @@ pub trait SwappableUnsafe { unsafe fn swap(&mut self, other: *mut Self); } +pub trait TriviallyDefaultConstructibleUnsafe: DefaultConstructibleUnsafe {} + +pub trait DefaultInitializableUnsafe: DefaultConstructibleUnsafe + DestructibleUnsafe {} + +impl DefaultInitializableUnsafe for T {} + pub trait MovableUnsafe: MoveConstructibleUnsafe + MoveAssignableUnsafe + SwappableUnsafe + DestructibleUnsafe { @@ -399,6 +443,123 @@ macro_rules! impl_move_by_take { } pub(crate) use impl_move_by_take; +macro_rules! impl_default_by_zeroed { + ($($ty:ty),* $(,)?) => {$( + impl $crate::DefaultConstructibleUnsafe for $ty { + unsafe fn default_constructor(&mut self) { + unsafe { std::ptr::write(self, std::mem::zeroed()) } + } + } + + impl $crate::TriviallyDefaultConstructibleUnsafe for $ty {} + )*}; +} +pub(crate) use impl_default_by_zeroed; + +macro_rules! impl_trivially_default_constructible { + ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( + impl<$($param),*> DefaultConstructible for $ty + where + $ty: Default + ByteRepr, + { + fn default_constructor(this: &Ptr) { + this.write(Self::default()); + } + } + + impl<$($param),*> TriviallyDefaultConstructible for $ty where $ty: Default + ByteRepr {} + + impl<$($param),*> DefaultConstructibleUnsafe for $ty + where + $ty: Default, + { + unsafe fn default_constructor(&mut self) { + unsafe { std::ptr::write(self, Self::default()) } + } + } + + impl<$($param),*> TriviallyDefaultConstructibleUnsafe for $ty where $ty: Default {} + )*}; +} + +impl_trivially_default_constructible!( + <> (), + <> bool, + <> i8, + <> u8, + <> i16, + <> u16, + <> i32, + <> u32, + <> i64, + <> u64, + <> i128, + <> u128, + <> isize, + <> usize, + <> f32, + <> f64, + <> AnyPtr, + Ptr, +); + +impl TriviallyDefaultConstructible for FnPtr {} + +impl TriviallyDefaultConstructibleUnsafe for FnPtr {} + +impl TriviallyDefaultConstructible for Box<[T]> {} + +impl TriviallyDefaultConstructibleUnsafe + for [T; N] +{ +} + +impl TriviallyDefaultConstructibleUnsafe for *mut T {} + +impl TriviallyDefaultConstructibleUnsafe for *const T {} + +impl DefaultConstructible for FnPtr { + fn default_constructor(this: &Ptr) { + this.with_mut(|dst| *dst = ::zero_init()); + } +} + +impl DefaultConstructibleUnsafe for FnPtr { + unsafe fn default_constructor(&mut self) { + unsafe { std::ptr::write(self, ::zero_init()) } + } +} + +impl DefaultConstructible for Box<[T]> { + fn default_constructor(this: &Ptr) { + let len = this.with(|elems| elems.len()); + let dst = this.decay(); + for i in 0..len { + T::default_constructor(&dst.offset(i)); + } + } +} + +impl DefaultConstructibleUnsafe for [T; N] { + unsafe fn default_constructor(&mut self) { + for elem in self.iter_mut() { + unsafe { elem.default_constructor() } + } + } +} + +impl DefaultConstructibleUnsafe for *mut T { + unsafe fn default_constructor(&mut self) { + unsafe { std::ptr::write(self, std::ptr::null_mut()) } + } +} + +impl DefaultConstructibleUnsafe for *const T { + unsafe fn default_constructor(&mut self) { + unsafe { std::ptr::write(self, std::ptr::null()) } + } +} + impl_trivial_copy_move!( (), bool, diff --git a/libcc2rs/src/lib.rs b/libcc2rs/src/lib.rs index 165c836eae..ab6a3ee08f 100644 --- a/libcc2rs/src/lib.rs +++ b/libcc2rs/src/lib.rs @@ -49,12 +49,13 @@ pub use capture::{ mod constructor; pub use constructor::{ CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, Copyable, - CopyableUnsafe, Movable, MovableUnsafe, MoveAssignable, MoveAssignableUnsafe, + CopyableUnsafe, DefaultConstructible, DefaultConstructibleUnsafe, DefaultInitializable, + DefaultInitializableUnsafe, Movable, MovableUnsafe, MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, Swappable, SwappableUnsafe, TriviallyCopyAssignable, TriviallyCopyAssignableUnsafe, TriviallyCopyConstructible, TriviallyCopyConstructibleUnsafe, TriviallyCopyable, TriviallyCopyableUnsafe, - TriviallyMoveAssignable, TriviallyMoveAssignableUnsafe, TriviallyMoveConstructible, - TriviallyMoveConstructibleUnsafe, + TriviallyDefaultConstructible, TriviallyDefaultConstructibleUnsafe, TriviallyMoveAssignable, + TriviallyMoveAssignableUnsafe, TriviallyMoveConstructible, TriviallyMoveConstructibleUnsafe, }; mod cmp; @@ -67,7 +68,9 @@ mod initialization; pub use initialization::{ZeroInitialization, ZeroInitializationUnsafe}; mod swap; -pub use swap::{copy_constructed, swap_by_move, swap_by_move_unsafe}; +pub use swap::{ + copy_constructed, move_constructed, move_constructed_unsafe, swap_by_move, swap_by_move_unsafe, +}; // Used by cpp_move! and cpp_move_unsafe!. #[doc(hidden)] pub mod __swap { @@ -119,9 +122,11 @@ pub use format::*; pub use libcc2rs_macros::{ ByteRepr, CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, - Copyable, CopyableUnsafe, CppFrom, CppFromUnsafe, Destructible, DestructibleUnsafe, FnPtrArg, - Memberwise, MemberwiseUnsafe, Movable, MovableUnsafe, MoveAssignable, MoveAssignableUnsafe, - MoveConstructible, MoveConstructibleUnsafe, Record, Swappable, SwappableUnsafe, - TriviallyCopyable, TriviallyCopyableUnsafe, VaArg, ZeroInitialization, + Copyable, CopyableUnsafe, CppFrom, CppFromUnsafe, DefaultConstructible, + DefaultConstructibleUnsafe, DefaultInitializable, DefaultInitializableUnsafe, Destructible, + DestructibleUnsafe, FnPtrArg, Memberwise, MemberwiseUnsafe, Movable, MovableUnsafe, + MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, Record, + Swappable, SwappableUnsafe, TriviallyCopyable, TriviallyCopyableUnsafe, + TriviallyDefaultConstructible, TriviallyDefaultConstructibleUnsafe, VaArg, ZeroInitialization, ZeroInitializationUnsafe, goto, goto_block, lambda, lambda_unsafe, switch, }; diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index 5a73a257f4..3ea7c2c178 100644 --- a/libcc2rs/src/swap.rs +++ b/libcc2rs/src/swap.rs @@ -48,7 +48,7 @@ pub fn pointer(value: &Value) -> Ptr { as AsPointer>::as_pointer(value) } -fn move_constructed(src: &Ptr) -> T { +pub fn move_constructed(src: &Ptr) -> T { let dst: Value = Rc::new(RefCell::new(T::zero_init())); T::move_constructor(&pointer(&dst), src.clone()); Rc::try_unwrap(dst).ok().unwrap().into_inner() @@ -68,7 +68,7 @@ unsafe fn copy_constructed_unsafe(src: *const T) -> } } -unsafe fn move_constructed_unsafe(src: *mut T) -> T { +pub unsafe fn move_constructed_unsafe(src: *mut T) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { (*dst.as_mut_ptr()).move_constructor(src); diff --git a/rule-preprocessor/src/semantic.rs b/rule-preprocessor/src/semantic.rs index b704e0969c..6ed6611a00 100644 --- a/rule-preprocessor/src/semantic.rs +++ b/rule-preprocessor/src/semantic.rs @@ -523,7 +523,7 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> { } } rustc_hir::ExprKind::Call(callee, args) => { - if self.is_std_mem_take(expr) && args.len() == 1 { + if self.is_take(expr) && args.len() == 1 { self.visit_expr(&args[0], Access::Take); } else { self.visit_expr(callee, context); @@ -556,9 +556,23 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> { self.fn_ir .resolve_next_param(¶m, &mut self.visited, |p| { if p.access == Access::Unknown { - p.access = Access::Borrow; + p.access = if context == Access::Take { + Access::Take + } else { + Access::Borrow + }; } }); + if context == Access::Take + && let Some(info) = self + .fn_ir + .params + .as_mut() + .and_then(|params| params.get_mut(¶m)) + { + info.is_refcount_pointer = false; + info.is_reference = true; + } return; } self.visit_expr(inner, Access::Borrow); @@ -717,12 +731,14 @@ impl<'a, 'tcx> AstVisitor<'a, 'tcx> { } } - fn is_std_mem_take(&self, expr: &rustc_hir::Expr<'tcx>) -> bool { + fn is_take(&self, expr: &rustc_hir::Expr<'tcx>) -> bool { if let rustc_hir::ExprKind::Call(callee, _) = &expr.kind && let rustc_middle::ty::TyKind::FnDef(def_id, _) = self.tcx.typeck(expr.hir_id.owner).expr_ty(callee).kind() { - return self.tcx.def_path_str(*def_id) == "std::mem::take"; + let name = self.tcx.item_name(*def_id); + return ["move_constructed", "move_constructed_unsafe"].contains(&name.as_str()) + && self.tcx.crate_name(def_id.krate).as_str() == "libcc2rs"; } false } diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index 36570d2c9c..6eab5b34a9 100644 --- a/rule-preprocessor/src/syntactic.rs +++ b/rule-preprocessor/src/syntactic.rs @@ -309,9 +309,14 @@ impl<'a> FragmentCtx<'a> { if param.is_mut_ref && self.text_buf.ends_with('*') { self.text_buf.pop(); } - if param.is_mut_ref && self.text_buf.ends_with("std::mem::take(&mut ") { - self.text_buf - .truncate(self.text_buf.len() - "std::mem::take(&mut ".len()); + let take = if param.is_refcount_pointer { + "move_constructed(&" + } else { + "move_constructed_unsafe(&mut " + }; + if (param.is_refcount_pointer || param.is_mut_ref) && self.text_buf.ends_with(take) + { + self.text_buf.truncate(self.text_buf.len() - take.len()); self.pending_close_parens += 1; access = Access::Unknown; } diff --git a/rules/array/tgt_refcount.rs b/rules/array/tgt_refcount.rs index cb30bfcc2c..c327c5edcf 100644 --- a/rules/array/tgt_refcount.rs +++ b/rules/array/tgt_refcount.rs @@ -5,8 +5,8 @@ use libcc2rs::*; use std::cell::RefCell; use std::rc::Rc; -fn t1() -> Box<[T1]> { - Box::<[T1]>::from(std::array::from_fn::<_, T2, _>(|_| ::default())) +fn t1() -> Box<[T1]> { + Box::<[T1]>::from(std::array::from_fn::<_, T2, _>(|_| ::default_constructed())) } fn t4() -> Ptr { diff --git a/rules/array/tgt_unsafe.rs b/rules/array/tgt_unsafe.rs index 8d01c78699..53838aadd7 100644 --- a/rules/array/tgt_unsafe.rs +++ b/rules/array/tgt_unsafe.rs @@ -3,8 +3,8 @@ use libcc2rs::*; -fn t1() -> [T1; T2] { - std::array::from_fn::<_, T2, _>(|_| ::default()) +fn t1() -> [T1; T2] { + std::array::from_fn::<_, T2, _>(|_| ::default_constructed()) } fn t2() -> usize { diff --git a/rules/deque/tgt_refcount.rs b/rules/deque/tgt_refcount.rs index 223923720a..63f4bfb2ca 100644 --- a/rules/deque/tgt_refcount.rs +++ b/rules/deque/tgt_refcount.rs @@ -27,8 +27,11 @@ fn f10(a0: &mut Vec, a1: Vec) -> &mut Vec { a0 } -fn f11<'a, T1>(a0: &'a mut Vec, a1: &mut Vec) -> &'a mut Vec { - *a0 = std::mem::take(&mut *a1); +fn f11<'a, T1>(a0: &'a mut Vec, a1: Ptr>) -> &'a mut Vec +where + Vec: MoveConstructible + ZeroInitialization, +{ + *a0 = move_constructed(&a1); a0 } @@ -37,3 +40,14 @@ fn f12(a0: &mut Vec, init: T1) -> &mut T1 { let __n = a0.len() - 1; &mut a0[__n] } + +fn f4(a0: &mut Vec, a1: Ptr) { + a0.push(move_constructed(&a1)) +} + +fn f9(a0: Ptr>) -> Vec +where + Vec: MoveConstructible + ZeroInitialization, +{ + move_constructed(&a0) +} diff --git a/rules/deque/tgt_unsafe.rs b/rules/deque/tgt_unsafe.rs index e3448c6ae1..985cc9de7f 100644 --- a/rules/deque/tgt_unsafe.rs +++ b/rules/deque/tgt_unsafe.rs @@ -38,8 +38,8 @@ fn f3(a0: Vec) -> bool { a0.is_empty() } -fn f4(a0: &mut Vec, a1: &mut T1) { - a0.push(std::mem::take(&mut *a1)) +unsafe fn f4(a0: &mut Vec, a1: &mut T1) { + a0.push(move_constructed_unsafe(&mut *a1)) } fn f5(a0: &mut Vec) -> T1 { @@ -54,8 +54,8 @@ fn f8(a0: Vec) -> Vec { a0.clone() } -fn f9(a0: &mut Vec) -> Vec { - std::mem::take(&mut *a0) +unsafe fn f9(a0: &mut Vec) -> Vec { + move_constructed_unsafe(&mut *a0) } fn f10(a0: &mut Vec, a1: Vec) -> &mut Vec { @@ -63,8 +63,8 @@ fn f10(a0: &mut Vec, a1: Vec) -> &mut Vec { a0 } -fn f11<'a, T1>(a0: &'a mut Vec, a1: &mut Vec) -> &'a mut Vec { - *a0 = std::mem::take(&mut *a1); +unsafe fn f11<'a, T1>(a0: &'a mut Vec, a1: &mut Vec) -> &'a mut Vec { + *a0 = move_constructed_unsafe(&mut *a1); a0 } diff --git a/rules/dirent/shim.rs b/rules/dirent/shim.rs index 02c56e203b..ae8f1cb6a1 100644 --- a/rules/dirent/shim.rs +++ b/rules/dirent/shim.rs @@ -1,11 +1,14 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::TriviallyDefaultConstructible; use crate::{ByteRepr, Record, TriviallyCopyable, ZeroInitialization, size_of_field}; use std::cell::Cell; use std::mem::{offset_of, size_of}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, +)] #[byte_size(size_of::<::libc::dirent>())] pub struct Dirent { #[offset(offset_of!(::libc::dirent, d_ino))] @@ -87,3 +90,5 @@ impl ByteRepr for CDir {} impl ByteRepr for ::libc::dirent {} crate::constructor::impl_trivial_copy_move!(::libc::dirent,); + +crate::constructor::impl_default_by_zeroed!(::libc::dirent,); diff --git a/rules/ifaddrs/shim.rs b/rules/ifaddrs/shim.rs index 72bb389b4d..f3f1c35480 100644 --- a/rules/ifaddrs/shim.rs +++ b/rules/ifaddrs/shim.rs @@ -1,13 +1,22 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::TriviallyDefaultConstructible; use crate::{ ByteRepr, Ptr, Record, Sockaddr, SockaddrIn, SockaddrIn6, SockaddrStorage, TriviallyCopyable, ZeroInitialization, }; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, + Default, + Record, + ByteRepr, + ZeroInitialization, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(size_of::<::libc::ifaddrs>())] pub struct Ifaddrs { #[offset(offset_of!(::libc::ifaddrs, ifa_next))] @@ -59,3 +68,5 @@ impl Ifaddrs { impl ByteRepr for ::libc::ifaddrs {} crate::constructor::impl_trivial_copy_move!(::libc::ifaddrs,); + +crate::constructor::impl_default_by_zeroed!(::libc::ifaddrs,); diff --git a/rules/ip/shim.rs b/rules/ip/shim.rs index 0ddbf861b2..782d43192e 100644 --- a/rules/ip/shim.rs +++ b/rules/ip/shim.rs @@ -1,16 +1,27 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::TriviallyDefaultConstructible; use crate::{ByteRepr, Ptr, Record, TriviallyCopyable, ZeroInitialization}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, + Default, + Record, + ByteRepr, + ZeroInitialization, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(4)] pub struct InAddr { #[offset(0)] pub s_addr: u32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, +)] #[byte_size(16)] pub struct In6Addr { #[offset(0)] @@ -37,3 +48,5 @@ impl ByteRepr for ::libc::in_addr {} impl ByteRepr for ::libc::in6_addr {} crate::constructor::impl_trivial_copy_move!(::libc::in_addr, ::libc::in6_addr,); + +crate::constructor::impl_default_by_zeroed!(::libc::in_addr, ::libc::in6_addr,); diff --git a/rules/map/tgt_refcount.rs b/rules/map/tgt_refcount.rs index 71cfde537b..8369c3d9b6 100644 --- a/rules/map/tgt_refcount.rs +++ b/rules/map/tgt_refcount.rs @@ -9,11 +9,11 @@ fn t1() -> Map, Value)> { Map::new() } -fn f1( +fn f1( a0: &mut Map, Value)>, a1: Ptr, ) -> Ptr { - a0.subscript(a1, || T2::default()) + a0.subscript(a1, || ::default_constructed()) } fn f2(a0: Map, Value)>) -> usize { @@ -39,11 +39,11 @@ fn f7(a0: &mut Map, Value)>, a1: P a0.get(&a1).expect("out of range!").borrow().1.as_pointer() } -fn f8( +fn f8( a0: &mut Map, Value)>, a1: Ptr, ) -> Ptr { - a0.subscript_move(a1, |__k| cpp_move!(__k), || T2::default()) + a0.subscript_move(a1, |__k| cpp_move!(__k), || ::default_constructed()) } fn f9(a0: Ptr, Value)>>) -> BidirectionalIterator<(Value, Value)> { @@ -74,8 +74,11 @@ fn f24(a0: Ptr, Value)>>) -> Ma a0.with_mut(|__m: &mut Map, Value)>| std::mem::take(__m)) } -fn f25<'a, T1: 'static, T2: 'static>(a0: &'a mut Map, Value)>, a1: &mut Map, Value)>) -> &'a mut Map, Value)> { - *a0 = std::mem::take(&mut *a1); +fn f25<'a, T1: 'static, T2: 'static>(a0: &'a mut Map, Value)>, a1: Ptr, Value)>>) -> &'a mut Map, Value)> +where + Map, Value)>: MoveConstructible + ZeroInitialization, +{ + *a0 = move_constructed(&a1); a0 } diff --git a/rules/map/tgt_unsafe.rs b/rules/map/tgt_unsafe.rs index 186941ce1e..831307bddc 100644 --- a/rules/map/tgt_unsafe.rs +++ b/rules/map/tgt_unsafe.rs @@ -19,8 +19,8 @@ fn t6() -> T2 { unimplemented!() } -unsafe fn f1(a0: &mut UnsafeMap, a1: T1) -> &mut T2 { - &mut (*a0.subscript(&a1, || T2::default())) +unsafe fn f1(a0: &mut UnsafeMap, a1: T1) -> &mut T2 { + &mut (*a0.subscript(&a1, || ::default_constructed())) } fn f2(a0: UnsafeMap) -> usize { @@ -43,8 +43,8 @@ unsafe fn f7(a0: &mut UnsafeMap, a1: T1) -> *const T2 &raw const (*a0.get(&a1).expect("out of range!")).1 } -unsafe fn f8(a0: &mut UnsafeMap, a1: *mut T1) -> &mut T2 { - &mut (*a0.subscript_move(a1, |__k| cpp_move_unsafe!(__k), || T2::default())) +unsafe fn f8(a0: &mut UnsafeMap, a1: *mut T1) -> &mut T2 { + &mut (*a0.subscript_move(a1, |__k| cpp_move_unsafe!(__k), || ::default_constructed())) } fn f9(a0: UnsafeMap) -> UnsafeBidirectionalIterator<(T1, T2)> { @@ -71,12 +71,12 @@ fn f17(a0: UnsafeMap, a1: T1) -> UnsafeBidirectionalI a0.find(&a1) } -fn f24(a0: &mut UnsafeMap) -> UnsafeMap { - std::mem::take(&mut *a0) +unsafe fn f24(a0: &mut UnsafeMap) -> UnsafeMap { + move_constructed_unsafe(&mut *a0) } -fn f25<'a, T1, T2>(a0: &'a mut UnsafeMap, a1: &mut UnsafeMap) -> &'a mut UnsafeMap { - *a0 = std::mem::take(&mut *a1); +unsafe fn f25<'a, T1, T2>(a0: &'a mut UnsafeMap, a1: &mut UnsafeMap) -> &'a mut UnsafeMap { + *a0 = move_constructed_unsafe(&mut *a1); a0 } diff --git a/rules/netdb/shim.rs b/rules/netdb/shim.rs index 9759114ae9..3462fee9af 100644 --- a/rules/netdb/shim.rs +++ b/rules/netdb/shim.rs @@ -1,10 +1,19 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::TriviallyDefaultConstructible; use crate::{ByteRepr, Ptr, Record, Sockaddr, TriviallyCopyable, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, + Default, + Record, + ByteRepr, + ZeroInitialization, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(size_of::<::libc::addrinfo>())] pub struct Addrinfo { #[offset(offset_of!(::libc::addrinfo, ai_flags))] @@ -28,3 +37,5 @@ pub struct Addrinfo { impl ByteRepr for ::libc::addrinfo {} crate::constructor::impl_trivial_copy_move!(::libc::addrinfo,); + +crate::constructor::impl_default_by_zeroed!(::libc::addrinfo,); diff --git a/rules/pair/tgt_refcount.rs b/rules/pair/tgt_refcount.rs index addff8790b..17f6a0ab32 100644 --- a/rules/pair/tgt_refcount.rs +++ b/rules/pair/tgt_refcount.rs @@ -5,10 +5,10 @@ use libcc2rs::*; use std::cell::RefCell; use std::rc::Rc; -fn t1() -> (Value, Value) { +fn t1() -> (Value, Value) { ( - Rc::new(RefCell::new(T1::default())), - Rc::new(RefCell::new(T2::default())), + Rc::new(RefCell::new(::default_constructed())), + Rc::new(RefCell::new(::default_constructed())), ) } diff --git a/rules/pair/tgt_unsafe.rs b/rules/pair/tgt_unsafe.rs index 4f17c158b6..1714c8379f 100644 --- a/rules/pair/tgt_unsafe.rs +++ b/rules/pair/tgt_unsafe.rs @@ -3,8 +3,8 @@ use libcc2rs::*; -fn t1() -> (T1, T2) { - <(T1, T2)>::default() +fn t1() -> (T1, T2) { + (::default_constructed(), ::default_constructed()) } fn t2() -> T1 { @@ -37,8 +37,11 @@ fn f13(a0: &mut (T1, T2), a1: (T1, T2)) -> &mut (T1, T2) { a0 } -fn f14<'a, T1: Default, T2: Default>(a0: &'a mut (T1, T2), a1: &mut (T1, T2)) -> &'a mut (T1, T2) { - *a0 = std::mem::take(&mut *a1); +unsafe fn f14<'a, T1, T2>(a0: &'a mut (T1, T2), a1: &mut (T1, T2)) -> &'a mut (T1, T2) +where + (T1, T2): MoveConstructibleUnsafe, +{ + *a0 = move_constructed_unsafe(&mut *a1); a0 } diff --git a/rules/poll/shim.rs b/rules/poll/shim.rs index e3fd49fee5..61d6e8569f 100644 --- a/rules/poll/shim.rs +++ b/rules/poll/shim.rs @@ -1,10 +1,19 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::TriviallyDefaultConstructible; use crate::{ByteRepr, Record, TriviallyCopyable, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, + Default, + Record, + ByteRepr, + ZeroInitialization, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(size_of::<::libc::pollfd>())] pub struct Pollfd { #[offset(offset_of!(::libc::pollfd, fd))] @@ -18,3 +27,5 @@ pub struct Pollfd { impl ByteRepr for ::libc::pollfd {} crate::constructor::impl_trivial_copy_move!(::libc::pollfd,); + +crate::constructor::impl_default_by_zeroed!(::libc::pollfd,); diff --git a/rules/pwd/shim.rs b/rules/pwd/shim.rs index ce42470db6..05d22c24e1 100644 --- a/rules/pwd/shim.rs +++ b/rules/pwd/shim.rs @@ -1,10 +1,19 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::TriviallyDefaultConstructible; use crate::{ByteRepr, Ptr, Record, TriviallyCopyable, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, + Default, + Record, + ByteRepr, + ZeroInitialization, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(size_of::<::libc::passwd>())] pub struct Passwd { #[offset(offset_of!(::libc::passwd, pw_name))] @@ -53,3 +62,5 @@ impl Passwd { impl ByteRepr for ::libc::passwd {} crate::constructor::impl_trivial_copy_move!(::libc::passwd,); + +crate::constructor::impl_default_by_zeroed!(::libc::passwd,); diff --git a/rules/socket/shim.rs b/rules/socket/shim.rs index d88e067aa7..faed480f7c 100644 --- a/rules/socket/shim.rs +++ b/rules/socket/shim.rs @@ -1,10 +1,13 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::TriviallyDefaultConstructible; use crate::{ByteRepr, CChar, In6Addr, InAddr, Ptr, Record, TriviallyCopyable, ZeroInitialization}; // The fields are at the offsets of the byte representation below. -#[derive(Clone, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, +)] #[byte_size(16)] pub struct Sockaddr { #[offset(0)] @@ -15,7 +18,9 @@ pub struct Sockaddr { pub sa_data: Box<[i8]>, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, +)] #[byte_size(16)] pub struct SockaddrIn { #[offset(0)] @@ -30,7 +35,15 @@ pub struct SockaddrIn { pub sin_zero: Box<[u8]>, } -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, + Default, + Record, + ByteRepr, + ZeroInitialization, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(28)] pub struct SockaddrIn6 { #[offset(0)] @@ -45,7 +58,9 @@ pub struct SockaddrIn6 { pub sin6_scope_id: u32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, +)] #[byte_size(110)] pub struct SockaddrUn { #[offset(0)] @@ -56,7 +71,9 @@ pub struct SockaddrUn { pub sun_path: Box<[i8]>, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, +)] #[byte_size(128)] pub struct SockaddrStorage { #[offset(0)] @@ -76,11 +93,12 @@ impl SockaddrIn { sin_addr: InAddr { s_addr: l.sin_addr.s_addr, }, - sin_zero: l.sin_zero - .iter() - .map(|&b| b as u8) - .collect::>() - .into_boxed_slice(), + sin_zero: l + .sin_zero + .iter() + .map(|&b| b as u8) + .collect::>() + .into_boxed_slice(), } } @@ -405,3 +423,11 @@ crate::constructor::impl_trivial_copy_move!( ::libc::sockaddr_un, ::libc::sockaddr_storage, ); + +crate::constructor::impl_default_by_zeroed!( + ::libc::sockaddr, + ::libc::sockaddr_in, + ::libc::sockaddr_in6, + ::libc::sockaddr_un, + ::libc::sockaddr_storage, +); diff --git a/rules/stat/shim.rs b/rules/stat/shim.rs index e56c9642cc..2643e8ec7a 100644 --- a/rules/stat/shim.rs +++ b/rules/stat/shim.rs @@ -1,10 +1,13 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::TriviallyDefaultConstructible; use crate::{ByteRepr, Record, TriviallyCopyable, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, Default, 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"), @@ -71,3 +74,5 @@ impl ByteRepr for Stat { impl ByteRepr for ::libc::stat {} crate::constructor::impl_trivial_copy_move!(::libc::stat,); + +crate::constructor::impl_default_by_zeroed!(::libc::stat,); diff --git a/rules/string/tgt_refcount.rs b/rules/string/tgt_refcount.rs index 783649934b..84cb208d85 100644 --- a/rules/string/tgt_refcount.rs +++ b/rules/string/tgt_refcount.rs @@ -178,8 +178,8 @@ fn f27(a0: Vec) -> Vec { a0 } -fn f28(a0: &mut Vec) -> Vec { - std::mem::take(&mut *a0) +fn f28(a0: Ptr>) -> Vec { + move_constructed(&a0) } fn f29(a0: &mut Vec, a1: Vec) -> &mut Vec { @@ -187,8 +187,8 @@ fn f29(a0: &mut Vec, a1: Vec) -> &mut Vec { a0 } -fn f30<'a>(a0: &'a mut Vec, a1: &mut Vec) -> &'a mut Vec { - *a0 = std::mem::take(&mut *a1); +fn f30<'a>(a0: &'a mut Vec, a1: Ptr>) -> &'a mut Vec { + *a0 = move_constructed(&a1); a0 } diff --git a/rules/string/tgt_unsafe.rs b/rules/string/tgt_unsafe.rs index 18a3c1cb65..14e5fded85 100644 --- a/rules/string/tgt_unsafe.rs +++ b/rules/string/tgt_unsafe.rs @@ -182,8 +182,8 @@ fn f27(a0: Vec) -> Vec { a0.clone() } -fn f28(a0: &mut Vec) -> Vec { - std::mem::take(&mut *a0) +unsafe fn f28(a0: &mut Vec) -> Vec { + move_constructed_unsafe(&mut *a0) } fn f29(a0: &mut Vec, a1: Vec) -> &mut Vec { @@ -191,8 +191,8 @@ fn f29(a0: &mut Vec, a1: Vec) -> &mut Vec(a0: &'a mut Vec, a1: &mut Vec) -> &'a mut Vec { - *a0 = std::mem::take(&mut *a1); +unsafe fn f30<'a>(a0: &'a mut Vec, a1: &mut Vec) -> &'a mut Vec { + *a0 = move_constructed_unsafe(&mut *a1); a0 } diff --git a/rules/termios/shim.rs b/rules/termios/shim.rs index e6d0c1bb5c..a5dfbc66cd 100644 --- a/rules/termios/shim.rs +++ b/rules/termios/shim.rs @@ -1,10 +1,13 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::TriviallyDefaultConstructible; use crate::{ByteRepr, Record, TriviallyCopyable, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, TriviallyDefaultConstructible, TriviallyCopyable, +)] #[byte_size(size_of::<::libc::termios>())] pub struct Termios { #[offset(offset_of!(::libc::termios, c_iflag))] @@ -105,7 +108,15 @@ impl Termios { } } -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, + Default, + Record, + ByteRepr, + ZeroInitialization, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(size_of::<::libc::winsize>())] pub struct Winsize { #[offset(offset_of!(::libc::winsize, ws_row))] diff --git a/rules/time/shim.rs b/rules/time/shim.rs index b0093f7db8..c30e468c1f 100644 --- a/rules/time/shim.rs +++ b/rules/time/shim.rs @@ -1,10 +1,19 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::TriviallyDefaultConstructible; use crate::{ByteRepr, Ptr, Record, TriviallyCopyable, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, + Default, + Record, + ByteRepr, + ZeroInitialization, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(size_of::<::libc::tm>())] pub struct Tm { #[offset(offset_of!(::libc::tm, tm_sec))] @@ -65,7 +74,15 @@ impl Tm { } } -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, + Default, + Record, + ByteRepr, + ZeroInitialization, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(size_of::<::libc::timeval>())] pub struct Timeval { #[offset(offset_of!(::libc::timeval, tv_sec))] @@ -74,7 +91,15 @@ pub struct Timeval { pub tv_usec: i64, } -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, TriviallyCopyable)] +#[derive( + Clone, + Default, + Record, + ByteRepr, + ZeroInitialization, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(size_of::<::libc::timespec>())] pub struct Timespec { #[offset(offset_of!(::libc::timespec, tv_sec))] @@ -88,3 +113,5 @@ impl ByteRepr for ::libc::timeval {} impl ByteRepr for ::libc::timespec {} crate::constructor::impl_trivial_copy_move!(::libc::tm, ::libc::timeval, ::libc::timespec,); + +crate::constructor::impl_default_by_zeroed!(::libc::tm, ::libc::timeval, ::libc::timespec,); diff --git a/rules/unique_ptr/tgt_refcount.rs b/rules/unique_ptr/tgt_refcount.rs index 4b17f09b39..6fae9f658f 100644 --- a/rules/unique_ptr/tgt_refcount.rs +++ b/rules/unique_ptr/tgt_refcount.rs @@ -21,9 +21,9 @@ fn t4() -> Ptr { Ptr::null() } -fn f1, T2: Default>(a0: usize) -> Option>> { +fn f1, T2: DefaultConstructible + ZeroInitialization>(a0: usize) -> Option>> { Some(Rc::new(RefCell::new( - (0..a0).map(|_| ::default()).collect::>(), + (0..a0).map(|_| ::default_constructed()).collect::>(), ))) } diff --git a/rules/unique_ptr/tgt_unsafe.rs b/rules/unique_ptr/tgt_unsafe.rs index f159de037d..5c965faa6a 100644 --- a/rules/unique_ptr/tgt_unsafe.rs +++ b/rules/unique_ptr/tgt_unsafe.rs @@ -19,8 +19,8 @@ fn t4() -> *mut T1 { ::std::ptr::null_mut() } -fn f1, T2: Default>(a0: usize) -> Option> { - Some((0..a0).map(|_| ::default()).collect::>()) +fn f1, T2: DefaultConstructibleUnsafe>(a0: usize) -> Option> { + Some((0..a0).map(|_| ::default_constructed()).collect::>()) } fn f2(a0: &mut Option>) -> *mut T1 { a0.as_deref_mut() @@ -32,7 +32,7 @@ unsafe fn f3(a0: *mut T1) -> Option> { unsafe fn f4(a0: *mut T1) -> Option> { Some(Box::from_raw(a0)) } -unsafe fn f5(a0: &mut Option>, a1: *mut T1) { +unsafe fn f5(a0: &mut Option>, a1: *mut T1) { let _a0: *mut T1 = a1; *a0 = if _a0.is_null() { None @@ -60,7 +60,7 @@ fn f16(a0: &mut Option>) { *a0 = None } -fn f10() -> Option> { +fn f10() -> Option> { None } diff --git a/rules/vector/tgt_refcount.rs b/rules/vector/tgt_refcount.rs index 12753f7ad3..fe73c784f7 100644 --- a/rules/vector/tgt_refcount.rs +++ b/rules/vector/tgt_refcount.rs @@ -58,6 +58,12 @@ fn f72(a0: Ptr) -> RandomAccessIterator { a0.begin() } +fn f73(a0: &mut Vec, a1: Ptr) { + let __a1 = move_constructed(&a1); + a0.push(__a1) +} + + fn f76(a0: Ptr) -> RandomAccessIterator { a0.end() } @@ -129,8 +135,11 @@ fn f101 + ByteRepr, T2, T3: CppInputIterator, T4: ByteRepr>( a1 } -fn f103<'a, T1>(a0: &'a mut Vec, a1: &mut Vec) -> &'a mut Vec { - *a0 = std::mem::take(&mut *a1); +fn f103<'a, T1>(a0: &'a mut Vec, a1: Ptr>) -> &'a mut Vec +where + Vec: MoveConstructible + ZeroInitialization, +{ + *a0 = move_constructed(&a1); a0 } @@ -179,3 +188,10 @@ fn f114(a0: &mut Vec, init: T1) -> &mut T1 { let __n = a0.len() - 1; &mut a0[__n] } + +fn f108(a0: Ptr>) -> Vec +where + Vec: MoveConstructible + ZeroInitialization, +{ + move_constructed(&a0) +} diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index d96b2af328..4a637944e8 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -81,8 +81,8 @@ fn f66(a0: &mut Vec, a1: usize) -> &mut T1 { &mut a0[a1] } -fn f67(a0: usize) -> Vec { - Vec::from_fn(a0, |_| ::default()) +fn f67(a0: usize) -> Vec { + Vec::from_fn(a0, |_| ::default_constructed()) } fn f68(a0: &mut Vec) -> &mut T1 { @@ -109,13 +109,13 @@ fn f72(a0: &mut Vec) -> UnsafeRandomAccessIterator { a0.begin() } -fn f73(a0: &mut Vec, a1: &mut T1) { - let __a1 = std::mem::take(&mut *a1); +unsafe fn f73(a0: &mut Vec, a1: &mut T1) { + let __a1 = move_constructed_unsafe(&mut *a1); a0.push(__a1) } -fn f74(a0: &mut Vec, a1: usize) { - a0.resize_with(a1, || ::default()) +fn f74(a0: &mut Vec, a1: usize) { + a0.resize_with(a1, || ::default_constructed()) } fn f75(a0: &mut Vec) { @@ -132,7 +132,7 @@ fn f77(a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: T1) -> Unsa UnsafeRandomAccessIterator::Vec(a0.insert_mut(pos, a2)) } -fn f78(a0: usize, a1: T1) -> Vec { +fn f78(a0: usize, a1: T1) -> Vec { vec![a1; a0] } @@ -203,12 +203,12 @@ unsafe fn f101, T2, T3: UnsafeCppInputIterator, T4>( UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr().add(__off)) } -fn f102(a0: &mut Vec, a1: usize, a2: T1) { +fn f102(a0: &mut Vec, a1: usize, a2: T1) { a0.resize(a1, a2) } -fn f103<'a, T1: Clone>(a0: &'a mut Vec, a1: &mut Vec) -> &'a mut Vec { - *a0 = std::mem::take(&mut *a1); +unsafe fn f103<'a, T1: Clone>(a0: &'a mut Vec, a1: &mut Vec) -> &'a mut Vec { + *a0 = move_constructed_unsafe(&mut *a1); a0 } @@ -225,8 +225,8 @@ fn f106(a0: &mut Vec) { a0.shrink_to_fit() } -fn f108(a0: &mut Vec) -> Vec { - std::mem::take(&mut *a0) +unsafe fn f108(a0: &mut Vec) -> Vec { + move_constructed_unsafe(&mut *a0) } fn f110(a0: Vec) -> Vec { 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 70ce781b92..ee2522bdfe 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 @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 81ce74dc03..a6566b5214 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 21ff4464c1..8862c1b4e3 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 @@ -7,7 +7,14 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Memberwise, Swappable, + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + CppFrom, + DefaultInitializable, + Memberwise, + Swappable, )] #[memberwise(move_constructor, move_assign)] #[cpp_from(i32, construct, value)] @@ -46,6 +53,11 @@ pub struct T { #[byte_size(24)] pub v: Vec, } +impl DefaultConstructible for T { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(Vec::new()); + } +} pub fn sum_0(s: Ptr) -> i32 { return ({ ({ (((*s.upgrade().deref()).v.len()) as i32) } + { (array_elem!(s, n, 0).read()) }) @@ -79,7 +91,8 @@ pub fn shuffle_1(mut x: i32) -> i32 { let t: Value = Rc::new(RefCell::new(T { v: Vec::from([1]) })); let u: Value = Rc::new(RefCell::new(::zero_init())); MoveConstructible::move_constructor(&u.as_pointer(), { t.as_pointer() }); - let w: Value = Rc::new(RefCell::new(::default())); + let w: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&w.as_pointer()); ({ MoveAssignable::move_assign(&w.as_pointer(), u.as_pointer()) }); assert!( ((({ TImpl::size(&t.as_pointer(),) }) == 0) && (({ TImpl::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 fc9d2f15e6..dab76eb690 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 @@ -11,7 +11,7 @@ use std::rc::Rc; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, @@ -49,6 +49,11 @@ impl T { return ((self.v.len()) as i32); } } +impl DefaultConstructibleUnsafe for T { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write(Vec::new()); + } +} pub unsafe fn sum_0(s: *const S) -> i32 { return (((((*s).v.len()) as i32) + ((*s).n[(0) as usize])) + ((*s).n[(1) as usize])); } @@ -82,7 +87,8 @@ pub unsafe fn shuffle_1(mut x: i32) -> i32 { let mut t: T = T { v: Vec::from([1]) }; let mut u: T = ::zero_init(); MoveConstructibleUnsafe::move_constructor(&mut u, { &mut t }); - let mut w: T = ::default(); + let mut w: T = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut w); (unsafe { MoveAssignableUnsafe::move_assign(&mut w, &mut u) }); assert!( (((unsafe { T::size(&t,) }) == (0)) && ((unsafe { T::size(&u,) }) == (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 5a6904297e..8a185bce62 100644 --- a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct S { 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 a4b028e173..f48036273a 100644 --- a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub a: i32, 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 f9cfd7c604..8bc86701b3 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 @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 9b0aa0cf07..20929d6c0c 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 ec2e9aa614..94cae20caf 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 @@ -13,6 +13,7 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, + DefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -24,7 +25,7 @@ pub struct S { #[offset(0)] pub v: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default)] #[byte_size(4)] pub struct M { #[offset(0)] @@ -41,7 +42,7 @@ pub trait Base { ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Copyable, Default, )] @@ -51,7 +52,16 @@ pub struct Derived { pub factor: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { 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 1b9a4ef84b..98ba6c01cb 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 @@ -12,6 +12,7 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -27,7 +28,7 @@ impl S { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default)] pub struct M { pub v: i32, } @@ -42,7 +43,7 @@ pub unsafe trait Base { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyableUnsafe, Default, )] @@ -52,7 +53,14 @@ pub struct Derived { impl Derived {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub first: i32, 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 0c6a4af038..00463deb12 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 @@ -12,6 +12,11 @@ pub struct S_int_ { #[offset(0)] pub x: i32, } +impl DefaultConstructible for S_int_ { + fn default_constructor(this: &Ptr) { + field!((*this), x).write(0); + } +} impl Default for S_int_ { fn default() -> Self { { S_int_ { x: 0 } } @@ -22,7 +27,8 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let p: Value = Rc::new(RefCell::new(::default())); + let p: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&p.as_pointer()); ({ S_int_Impl::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 cfa1a21e68..19760378df 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 @@ -16,6 +16,11 @@ impl S_int_ { self.x = v; } } +impl DefaultConstructibleUnsafe for S_int_ { + unsafe fn default_constructor(&mut self) { + (&raw mut self.x).write(0); + } +} impl Default for S_int_ { fn default() -> Self { unsafe { S_int_ { x: 0 } } @@ -28,7 +33,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut p: S_int_ = ::default(); + let mut p: S_int_ = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut p); (unsafe { S_int_::set(&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 f1e0b0a9ac..c574946d93 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 @@ -45,6 +45,12 @@ impl LifetimeTracked { }); } } +impl DefaultConstructible for LifetimeTracked { + fn default_constructor(this: &Ptr) { + field!((*this), uses).write(0); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CopyConstructible for LifetimeTracked { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), uses).write(0); @@ -72,7 +78,7 @@ impl Default for LifetimeTracked { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -85,6 +91,7 @@ impl Default for LifetimeTracked { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -114,7 +121,7 @@ thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -124,7 +131,16 @@ thread_local!( }; ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct HasInlineMembers {} @@ -137,7 +153,7 @@ thread_local!( static local_6: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -173,14 +189,9 @@ pub fn b_instance_address_9() -> Ptr { return ({ HasInlineMembers::instance() }); } pub trait LifetimeTrackedImpl { - fn construct(&self); fn use_(&self); } impl LifetimeTrackedImpl for Ptr { - fn construct(&self) { - field!((*self), uses).write(0); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); 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 4acf156250..71f4a8cafa 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 @@ -29,15 +29,17 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn construct(&mut self) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - } pub unsafe fn use_(&self) { (*(&raw const self.uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for LifetimeTracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.uses).write(0); + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + } +} impl CopyConstructibleUnsafe for LifetimeTracked { unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); @@ -63,7 +65,7 @@ impl Default for LifetimeTracked { unsafe { { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -75,6 +77,7 @@ impl Default for LifetimeTracked { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -104,7 +107,7 @@ pub static mut shared_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -115,7 +118,14 @@ pub static mut shared_5: std::cell::LazyCell = }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct HasInlineMembers {} impl HasInlineMembers { @@ -127,7 +137,7 @@ static mut local_6: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 cb1d7b0b33..f2de6e7436 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 @@ -45,6 +45,12 @@ impl LifetimeTracked { }); } } +impl DefaultConstructible for LifetimeTracked { + fn default_constructor(this: &Ptr) { + field!((*this), uses).write(0); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CopyConstructible for LifetimeTracked { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), uses).write(0); @@ -72,7 +78,7 @@ impl Default for LifetimeTracked { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -82,7 +88,7 @@ thread_local!( pub static member_4: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -92,7 +98,16 @@ thread_local!( }; ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct HasStaticMember_int_ {} @@ -100,7 +115,7 @@ thread_local!( pub static member_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -110,7 +125,16 @@ thread_local!( }; ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct HasStaticMember_long_ {} @@ -139,14 +163,9 @@ pub fn b_int_address_8() -> Ptr { return (member_4.with(|v| v.as_pointer())); } pub trait LifetimeTrackedImpl { - fn construct(&self); fn use_(&self); } impl LifetimeTrackedImpl for Ptr { - fn construct(&self) { - field!((*self), uses).write(0); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); 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 4f9c613945..e41e758cca 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 @@ -29,15 +29,17 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn construct(&mut self) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - } pub unsafe fn use_(&self) { (*(&raw const self.uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for LifetimeTracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.uses).write(0); + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + } +} impl CopyConstructibleUnsafe for LifetimeTracked { unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); @@ -63,7 +65,7 @@ impl Default for LifetimeTracked { unsafe { { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -74,7 +76,7 @@ pub static mut member_4: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -85,7 +87,14 @@ pub static mut member_4: std::cell::LazyCell = }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct HasStaticMember_int_ {} pub static mut member_5: std::cell::LazyCell = @@ -93,7 +102,7 @@ pub static mut member_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -104,7 +113,14 @@ pub static mut member_5: std::cell::LazyCell = }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct HasStaticMember_long_ {} pub fn main() { 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 9f01a7d5fd..427f6afbf0 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 @@ -45,6 +45,12 @@ impl LifetimeTracked { }); } } +impl DefaultConstructible for LifetimeTracked { + fn default_constructor(this: &Ptr) { + field!((*this), uses).write(0); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CopyConstructible for LifetimeTracked { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), uses).write(0); @@ -72,7 +78,7 @@ impl Default for LifetimeTracked { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -85,6 +91,7 @@ impl Default for LifetimeTracked { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -114,7 +121,7 @@ thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -130,7 +137,7 @@ thread_local!( static t_8: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -146,7 +153,7 @@ thread_local!( static t_11: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -186,7 +193,16 @@ fn main_0() -> i32 { return 0; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct S_14 {} @@ -197,7 +213,7 @@ thread_local!( static t_19: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -219,19 +235,23 @@ pub fn b_count_local_15() -> i32 { return ({ count_18() }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct S_21 {} pub trait LifetimeTrackedImpl { - fn construct(&self); fn use_(&self); } impl LifetimeTrackedImpl for Ptr { - fn construct(&self) { - field!((*self), uses).write(0); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); 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 6be3fc1d68..dcc91dae91 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 @@ -29,15 +29,17 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn construct(&mut self) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - } pub unsafe fn use_(&self) { (*(&raw const self.uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for LifetimeTracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.uses).write(0); + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + } +} impl CopyConstructibleUnsafe for LifetimeTracked { unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); @@ -63,7 +65,7 @@ impl Default for LifetimeTracked { unsafe { { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -75,6 +77,7 @@ impl Default for LifetimeTracked { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -102,7 +105,7 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -116,7 +119,7 @@ static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -130,7 +133,7 @@ static mut t_11: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -172,7 +175,14 @@ unsafe fn main_0() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S_14 {} pub unsafe fn count_18() -> i32 { @@ -182,7 +192,7 @@ static mut t_19: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -203,7 +213,14 @@ pub unsafe fn b_count_local_15() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S_21 {} pub unsafe fn __cpp2rust_init_globals() { diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs index 21dd819328..502db9b23e 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs @@ -45,6 +45,12 @@ impl LifetimeTracked { }); } } +impl DefaultConstructible for LifetimeTracked { + fn default_constructor(this: &Ptr) { + field!((*this), uses).write(0); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CopyConstructible for LifetimeTracked { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), uses).write(0); @@ -72,7 +78,7 @@ impl Default for LifetimeTracked { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -85,6 +91,7 @@ impl Default for LifetimeTracked { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -108,7 +115,7 @@ thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -149,14 +156,9 @@ pub fn b_address_8() -> Ptr { return ({ instance_4() }); } pub trait LifetimeTrackedImpl { - fn construct(&self); fn use_(&self); } impl LifetimeTrackedImpl for Ptr { - fn construct(&self) { - field!((*self), uses).write(0); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs index 5b69c600e5..cf503f4fb2 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs @@ -29,15 +29,17 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn construct(&mut self) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - } pub unsafe fn use_(&self) { (*(&raw const self.uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for LifetimeTracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.uses).write(0); + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + } +} impl CopyConstructibleUnsafe for LifetimeTracked { unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); @@ -63,7 +65,7 @@ impl Default for LifetimeTracked { unsafe { { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -75,6 +77,7 @@ impl Default for LifetimeTracked { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -96,7 +99,7 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index 2325ffd6e3..c30fc358da 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs @@ -45,6 +45,12 @@ impl LifetimeTracked { }); } } +impl DefaultConstructible for LifetimeTracked { + fn default_constructor(this: &Ptr) { + field!((*this), uses).write(0); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CopyConstructible for LifetimeTracked { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), uses).write(0); @@ -72,7 +78,7 @@ impl Default for LifetimeTracked { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -85,6 +91,7 @@ impl Default for LifetimeTracked { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -114,7 +121,7 @@ thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -144,14 +151,9 @@ pub fn b_address_7() -> Ptr { return (shared_5.with(|v| v.as_pointer())); } pub trait LifetimeTrackedImpl { - fn construct(&self); fn use_(&self); } impl LifetimeTrackedImpl for Ptr { - fn construct(&self) { - field!((*self), uses).write(0); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index b7906a551a..310dc7de43 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs @@ -29,15 +29,17 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn construct(&mut self) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - } pub unsafe fn use_(&self) { (*(&raw const self.uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for LifetimeTracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.uses).write(0); + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + } +} impl CopyConstructibleUnsafe for LifetimeTracked { unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); @@ -63,7 +65,7 @@ impl Default for LifetimeTracked { unsafe { { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -75,6 +77,7 @@ impl Default for LifetimeTracked { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -104,7 +107,7 @@ pub static mut shared_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 a443bd6e03..6e95dfe962 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 @@ -45,6 +45,12 @@ impl LifetimeTracked { }); } } +impl DefaultConstructible for LifetimeTracked { + fn default_constructor(this: &Ptr) { + field!((*this), uses).write(0); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CopyConstructible for LifetimeTracked { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), uses).write(0); @@ -72,7 +78,7 @@ impl Default for LifetimeTracked { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -85,6 +91,7 @@ impl Default for LifetimeTracked { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -102,7 +109,16 @@ impl Destructible for AssertsDtorCountAtExit { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct X {} @@ -110,7 +126,7 @@ thread_local!( static local_4: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -164,14 +180,9 @@ pub fn b_call_6() { }); } pub trait LifetimeTrackedImpl { - fn construct(&self); fn use_(&self); } impl LifetimeTrackedImpl for Ptr { - fn construct(&self) { - field!((*self), uses).write(0); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); 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 bac67f99e0..590b59ddc4 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 @@ -29,15 +29,17 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn construct(&mut self) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - } pub unsafe fn use_(&self) { (*(&raw const self.uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for LifetimeTracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.uses).write(0); + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + } +} impl CopyConstructibleUnsafe for LifetimeTracked { unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); @@ -63,7 +65,7 @@ impl Default for LifetimeTracked { unsafe { { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -75,6 +77,7 @@ impl Default for LifetimeTracked { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -91,7 +94,14 @@ impl DestructibleUnsafe for AssertsDtorCountAtExit { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct X {} impl X { @@ -119,7 +129,7 @@ static mut local_4: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index 1f3ed0b777..aa37b1cd93 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs @@ -45,6 +45,12 @@ impl LifetimeTracked { }); } } +impl DefaultConstructible for LifetimeTracked { + fn default_constructor(this: &Ptr) { + field!((*this), uses).write(0); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CopyConstructible for LifetimeTracked { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), uses).write(0); @@ -72,7 +78,7 @@ impl Default for LifetimeTracked { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -85,6 +91,7 @@ impl Default for LifetimeTracked { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -119,7 +126,7 @@ thread_local!( static local_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -155,14 +162,9 @@ pub fn b_call_7() { ({ f_4(true, FnPtr::::null()) }); } pub trait LifetimeTrackedImpl { - fn construct(&self); fn use_(&self); } impl LifetimeTrackedImpl for Ptr { - fn construct(&self) { - field!((*self), uses).write(0); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index 6e9beddd62..bc16418ba6 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs @@ -29,15 +29,17 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn construct(&mut self) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - } pub unsafe fn use_(&self) { (*(&raw const self.uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for LifetimeTracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.uses).write(0); + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + } +} impl CopyConstructibleUnsafe for LifetimeTracked { unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); @@ -63,7 +65,7 @@ impl Default for LifetimeTracked { unsafe { { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -75,6 +77,7 @@ impl Default for LifetimeTracked { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -111,7 +114,7 @@ static mut local_5: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 1b51239747..1ca48344f3 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -29,7 +29,15 @@ pub fn test_11() { assert!((ceiling_10.with(|rc| *rc.borrow()) == 40)); assert!(((ceiling_10.with(|v| v.as_pointer())) == ({ ceiling_address_in_b_12() }))); } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(4)] pub struct anon_13 { #[offset(0)] @@ -73,6 +81,11 @@ pub struct Record_19 { #[offset(0)] pub id: i32, } +impl DefaultConstructible for Record_19 { + fn default_constructor(this: &Ptr) { + field!((*this), id).write(100); + } +} impl Default for Record_19 { fn default() -> Self { { Record_19 { id: 100 } } @@ -85,8 +98,9 @@ pub fn test_21() { assert!((({ bump_18() }) == 2)); assert!((({ bump_in_b_22() }) == 51)); assert!((counter_17.with(|rc| *rc.borrow()) == 2)); - let mut record: Record_19 = ::default(); - assert!((record.id == 100)); + let record: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&record.as_pointer()); + assert!(({ (*record.borrow()).id } == 100)); assert!((({ record_id_in_b_23() }) == 200)); assert!((depth_20.with(|rc| *rc.borrow()) == 3)); assert!((({ depth_in_b_24() }) == 4)); @@ -104,7 +118,16 @@ pub fn test_29() { assert!((({ raise_30(1,) }) == 11)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Tally_31 {} @@ -118,7 +141,16 @@ pub fn test_33() { assert!((total_32.with(|rc| *rc.borrow()) == 11)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p5_members_of_class_with_external_linkage_Ledger {} @@ -175,12 +207,14 @@ thread_local!( static count_48: Value = Rc::new(RefCell::new(1)); ); pub fn first_key_51() -> i32 { - let mut entry: Entry_52 = ::default(); - return entry.key; + let entry: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&entry.as_pointer()); + return { (*entry.borrow()).key }; } pub fn second_key_plus_value_53() -> i32 { - let mut entry: Entry_54 = ::default(); - return (entry.key + entry.value); + let entry: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&entry.as_pointer()); + return ({ (*entry.borrow()).key } + { (*entry.borrow()).value }); } pub fn test_55() { assert!((({ first_key_51() }) == 1)); @@ -193,6 +227,11 @@ pub struct Entry_52 { #[offset(0)] pub key: i32, } +impl DefaultConstructible for Entry_52 { + fn default_constructor(this: &Ptr) { + field!((*this), key).write(1); + } +} impl Default for Entry_52 { fn default() -> Self { { Entry_52 { key: 1 } } @@ -206,6 +245,12 @@ pub struct Entry_54 { #[offset(4)] pub value: i32, } +impl DefaultConstructible for Entry_54 { + fn default_constructor(this: &Ptr) { + field!((*this), key).write(2); + field!((*this), value).write(30); + } +} impl Default for Entry_54 { fn default() -> Self { { Entry_54 { key: 2, value: 30 } } @@ -270,7 +315,15 @@ thread_local!( pub fn ceiling_address_in_b_12() -> Ptr { return (ceiling_10.with(|v| v.as_pointer())); } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(4)] pub struct anon_62 { #[offset(0)] @@ -316,6 +369,12 @@ pub struct Record_65 { #[offset(8)] pub extra: i32, } +impl DefaultConstructible for Record_65 { + fn default_constructor(this: &Ptr) { + field!((*this), id).write(200_i64); + field!((*this), extra).write(1); + } +} impl Default for Record_65 { fn default() -> Self { { @@ -333,8 +392,9 @@ pub fn bump_in_b_22() -> i32 { return ({ bump_64() }); } pub fn record_id_in_b_23() -> i32 { - let mut record: Record_65 = ::default(); - return (record.id as i32); + let record: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&record.as_pointer()); + return ({ (*record.borrow()).id } as i32); } pub fn depth_in_b_24() -> i32 { return depth_66.with(|rc| *rc.borrow()); @@ -353,7 +413,16 @@ pub fn raise_30(mut by: i32) -> i32 { return level_28.with(|rc| *rc.borrow()); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Tally_67 {} @@ -393,8 +462,9 @@ thread_local!( static count_70: Value = Rc::new(RefCell::new(0)); ); pub fn key_in_b_56() -> i32 { - let mut entry: Entry_71 = ::default(); - return (entry.key as i32); + let entry: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&entry.as_pointer()); + return ({ (*entry.borrow()).key } as i32); } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] #[byte_size(8)] @@ -402,6 +472,11 @@ pub struct Entry_71 { #[offset(0)] pub key: i64, } +impl DefaultConstructible for Entry_71 { + fn default_constructor(this: &Ptr) { + field!((*this), key).write(400_i64); + } +} impl Default for Entry_71 { fn default() -> Self { { Entry_71 { key: 400_i64 } } 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 bc7bda2b28..ad2f9a1d64 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -37,7 +37,15 @@ pub unsafe fn test_11() { ); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_13 { pub whole: i32, pub fraction: f32, @@ -64,6 +72,11 @@ pub unsafe fn bump_18() -> i32 { pub struct Record_19 { pub id: i32, } +impl DefaultConstructibleUnsafe for Record_19 { + unsafe fn default_constructor(&mut self) { + (&raw mut self.id).write(100); + } +} impl Default for Record_19 { fn default() -> Self { unsafe { Record_19 { id: 100 } } @@ -74,7 +87,8 @@ 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))); - let mut record: Record_19 = ::default(); + let mut record: Record_19 = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut record); assert!(((record.id) == (100))); assert!(((unsafe { record_id_in_b_23() }) == (200))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut depth_20)) == (3))); @@ -94,7 +108,14 @@ pub unsafe fn test_29() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Tally_31 {} impl Tally_31 { @@ -112,7 +133,14 @@ pub unsafe fn test_33() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p5_members_of_class_with_external_linkage_Ledger {} pub unsafe fn test_36() { @@ -162,11 +190,13 @@ 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 { - let mut entry: Entry_52 = ::default(); + let mut entry: Entry_52 = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut entry); return entry.key; } pub unsafe fn second_key_plus_value_53() -> i32 { - let mut entry: Entry_54 = ::default(); + let mut entry: Entry_54 = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut entry); return ((entry.key) + (entry.value)); } pub unsafe fn test_55() { @@ -179,6 +209,11 @@ pub unsafe fn test_55() { pub struct Entry_52 { pub key: i32, } +impl DefaultConstructibleUnsafe for Entry_52 { + unsafe fn default_constructor(&mut self) { + (&raw mut self.key).write(1); + } +} impl Default for Entry_52 { fn default() -> Self { unsafe { Entry_52 { key: 1 } } @@ -190,6 +225,12 @@ pub struct Entry_54 { pub key: i32, pub value: i32, } +impl DefaultConstructibleUnsafe for Entry_54 { + unsafe fn default_constructor(&mut self) { + (&raw mut self.key).write(2); + (&raw mut self.value).write(30); + } +} impl Default for Entry_54 { fn default() -> Self { unsafe { Entry_54 { key: 2, value: 30 } } @@ -247,7 +288,15 @@ pub unsafe fn ceiling_address_in_b_12() -> *const i32 { return (&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut ceiling_10)) as *const i32); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_62 { pub whole: i32, pub fraction: f32, @@ -275,6 +324,12 @@ pub struct Record_65 { pub id: i64, pub extra: i32, } +impl DefaultConstructibleUnsafe for Record_65 { + unsafe fn default_constructor(&mut self) { + (&raw mut self.id).write(200_i64); + (&raw mut self.extra).write(1); + } +} impl Default for Record_65 { fn default() -> Self { unsafe { @@ -290,7 +345,8 @@ pub unsafe fn bump_in_b_22() -> i32 { return (unsafe { bump_64() }); } pub unsafe fn record_id_in_b_23() -> i32 { - let mut record: Record_65 = ::default(); + let mut record: Record_65 = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut record); return (record.id as i32); } pub unsafe fn depth_in_b_24() -> i32 { @@ -308,7 +364,14 @@ pub unsafe fn raise_30(mut by: i32) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Tally_67 {} impl Tally_67 { @@ -343,7 +406,8 @@ 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 { - let mut entry: Entry_71 = ::default(); + let mut entry: Entry_71 = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut entry); return (entry.key as i32); } #[repr(C)] @@ -351,6 +415,11 @@ pub unsafe fn key_in_b_56() -> i32 { pub struct Entry_71 { pub key: i64, } +impl DefaultConstructibleUnsafe for Entry_71 { + unsafe fn default_constructor(&mut self) { + (&raw mut self.key).write(400_i64); + } +} impl Default for Entry_71 { fn default() -> Self { unsafe { Entry_71 { key: 400_i64 } } diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs index 5bad7e7bfd..23daff9bf5 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs @@ -45,6 +45,12 @@ impl LifetimeTracked { }); } } +impl DefaultConstructible for LifetimeTracked { + fn default_constructor(this: &Ptr) { + field!((*this), uses).write(0); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CopyConstructible for LifetimeTracked { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), uses).write(0); @@ -72,7 +78,7 @@ impl Default for LifetimeTracked { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -94,6 +100,7 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -177,7 +184,7 @@ pub fn test_8() { pub fn test_9() { ({ LifetimeTracked::reset() }); let scoped: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&scoped.as_pointer()); + DefaultConstructible::default_constructor(&scoped.as_pointer()); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); @@ -188,7 +195,7 @@ pub fn test_9() { 'for_body: { let scoped: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&scoped.as_pointer()); + DefaultConstructible::default_constructor(&scoped.as_pointer()); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); @@ -200,7 +207,7 @@ pub fn test_9() { assert!((dtorCount_2.with(|rc| *rc.borrow()) == 3)); if (ctorCount_0.with(|rc| *rc.borrow()) == 4) { let scoped: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&scoped.as_pointer()); + DefaultConstructible::default_constructor(&scoped.as_pointer()); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); @@ -210,7 +217,7 @@ pub fn test_9() { if (ctorCount_0.with(|rc| *rc.borrow()) == 0) { } else { let scoped: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&scoped.as_pointer()); + DefaultConstructible::default_constructor(&scoped.as_pointer()); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); @@ -243,13 +250,13 @@ pub fn test_10() { pub fn test_11() { ({ LifetimeTracked::reset() }); let tracked: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&tracked.as_pointer()); + DefaultConstructible::default_constructor(&tracked.as_pointer()); let _dtor_tracked = std::mem::DropGuard::new(tracked.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); { let tracked: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&tracked.as_pointer()); + DefaultConstructible::default_constructor(&tracked.as_pointer()); let _dtor_tracked = std::mem::DropGuard::new(tracked.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); @@ -339,14 +346,9 @@ fn main_0() -> i32 { return 0; } pub trait LifetimeTrackedImpl { - fn construct(&self); fn use_(&self); } impl LifetimeTrackedImpl for Ptr { - fn construct(&self) { - field!((*self), uses).write(0); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); 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 d0dd2aadb7..0d4692d5d3 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 @@ -15,6 +15,11 @@ pub struct p1_member_hides_namespace_variable_HasBalance { #[offset(0)] pub balance: i32, } +impl DefaultConstructible for p1_member_hides_namespace_variable_HasBalance { + fn default_constructor(this: &Ptr) { + field!((*this), balance).write(7); + } +} impl Default for p1_member_hides_namespace_variable_HasBalance { fn default() -> Self { { p1_member_hides_namespace_variable_HasBalance { balance: 7 } } @@ -22,8 +27,9 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { } pub fn test_1() { let object: Value = Rc::new(RefCell::new( - ::default(), + ::zero_init(), )); + DefaultConstructible::default_constructor(&object.as_pointer()); assert!( (({ p1_member_hides_namespace_variable_HasBalanceImpl::deposit(&object.as_pointer(), 3) @@ -51,6 +57,11 @@ pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { #[offset(0)] pub held: i32, } +impl DefaultConstructible for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + fn default_constructor(this: &Ptr) { + field!((*this), held).write(1); + } +} impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { fn default() -> Self { { p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { held: 1 } } @@ -65,8 +76,9 @@ thread_local!( pub fn test_5() { assert!((total_4.with(|rc| *rc.borrow()) == 7)); let object: Value = Rc::new( - RefCell::new(::default()), + RefCell::new(::zero_init()), ); + DefaultConstructible::default_constructor(&object.as_pointer()); assert!( (({ p1_out_of_class_definition_is_in_class_scope_HasStaticTotalImpl::add( 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 c8ba3af145..078329d176 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 @@ -15,6 +15,7 @@ use std::rc::{Rc, Weak}; VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] 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 50d4f24248..f44d02b17f 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 @@ -19,7 +19,15 @@ pub fn test_0() { assert!((level == 5)); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct p1_own_address_in_initializer_SelfLinked { @@ -82,6 +90,15 @@ pub struct p9_func_declared_before_function_body_RecordsConstructorName { #[byte_size(8)] pub name: Ptr, } +impl DefaultConstructible for p9_func_declared_before_function_body_RecordsConstructorName { + fn default_constructor(this: &Ptr) { + field!((*this), name).write(Ptr::::from_string_literal(b"RecordsConstructorName")); + assert!( + ((*this).with(|__s| __s.name.clone()) + == Ptr::::from_string_literal(b"RecordsConstructorName")) + ); + } +} impl Default for p9_func_declared_before_function_body_RecordsConstructorName { fn default() -> Self { { @@ -90,9 +107,7 @@ impl Default for p9_func_declared_before_function_body_RecordsConstructorName { Rc::new(RefCell::new( ::zero_init(), )); - p9_func_declared_before_function_body_RecordsConstructorNameImpl::construct( - &__v.as_pointer(), - ); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -123,9 +138,7 @@ pub fn test_6() { let object: Value = Rc::new( RefCell::new(::zero_init()), ); - p9_func_declared_before_function_body_RecordsConstructorNameImpl::construct( - &object.as_pointer(), - ); + DefaultConstructible::default_constructor(&object.as_pointer()); assert!( ({ let mut __it1 = { (*object.borrow()).name.clone() }.to_c_string_iterator(); @@ -198,18 +211,4 @@ fn main_0() -> i32 { ({ test_7() }); return 0; } -pub trait p9_func_declared_before_function_body_RecordsConstructorNameImpl { - fn construct(&self); -} -impl p9_func_declared_before_function_body_RecordsConstructorNameImpl - for Ptr -{ - fn construct(&self) { - field!((*self), name).write(Ptr::::from_string_literal(b"RecordsConstructorName")); - assert!( - ((*self).with(|__s| __s.name.clone()) - == Ptr::::from_string_literal(b"RecordsConstructorName")) - ); - } -} pub fn __cpp2rust_init_globals() {} 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 0aecd9eb4b..7cf3f9d9eb 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 @@ -45,7 +45,16 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small: pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size = 8; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} @@ -75,7 +84,16 @@ thread_local!( pub static count_6: Value = Rc::new(RefCell::new(0)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p2_12_class_name_in_own_scope_HasStaticCounter {} @@ -92,7 +110,15 @@ pub fn test_7() { count_6.with(|rc| *rc.borrow_mut() = 6); assert!((count_6.with(|rc| *rc.borrow()) == 6)); } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct anon_8 { #[offset(0)] @@ -118,7 +144,15 @@ impl Default for anon_8 { thread_local!( pub static anon_8: Value = Rc::new(RefCell::new(::default())); ); -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct anon_9 { #[offset(0)] @@ -142,7 +176,15 @@ impl Default for anon_9 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { @@ -179,7 +221,15 @@ pub fn test_10() { anon_11::block_ratio(anon_11.as_pointer()).write(0.75_f64); assert!(((anon_11::block_ratio(anon_11.as_pointer()).read()) == 0.75_f64)); } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct anon_11 { #[offset(0)] @@ -210,6 +260,12 @@ pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { #[offset(4)] pub const_calls: i32, } +impl DefaultConstructible for p3_2_const_qualified_member_is_distinct_HasConstOverload { + fn default_constructor(this: &Ptr) { + field!((*this), plain_calls).write(0); + field!((*this), const_calls).write(0); + } +} impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { fn default() -> Self { { @@ -222,8 +278,9 @@ impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { } pub fn test_12() { let object: Value = Rc::new( - RefCell::new(::default()), + RefCell::new(::zero_init()), ); + DefaultConstructible::default_constructor(&object.as_pointer()); let view: Ptr = object.as_pointer(); assert!( (({ @@ -252,6 +309,13 @@ pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjec #[offset(0)] pub base: i32, } +impl DefaultConstructible + for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload +{ + fn default_constructor(this: &Ptr) { + field!((*this), base).write(10); + } +} impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { fn default() -> Self { { @@ -265,8 +329,10 @@ pub fn test_15() { let object: Value< p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload, > = Rc::new(RefCell::new( - ::default(), + ::zero_init( + ), )); + DefaultConstructible::default_constructor(&object.as_pointer()); assert!( (({ as p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl>::pick_1 ( object .as_pointer() , 1 , ) @@ -274,11 +340,14 @@ pub fn test_15() { ); assert!((explicit_calls_13.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_14.with(|rc| *rc.borrow()) == 0)); - assert!( - (({ - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl :: pick_2 ( &Rc::new(RefCell::new(::default() )).as_pointer() , 2 , ) - }) == 112) - ); + { + let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + assert!( + (({ + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl :: pick_2 ( &{ DefaultConstructible :: default_constructor ( &__tmp_0.as_pointer() , ) ; __tmp_0.as_pointer() } , 2 , ) + }) == 112) + ) + }; assert!((explicit_calls_13.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_14.with(|rc| *rc.borrow()) == 1)); } @@ -289,7 +358,16 @@ thread_local!( pub static rvalue_calls_17: Value = Rc::new(RefCell::new(0)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} @@ -336,6 +414,14 @@ pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOv #[offset(4)] pub const_calls: i32, } +impl DefaultConstructible + for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload +{ + fn default_constructor(this: &Ptr) { + field!((*this), plain_calls).write(0); + field!((*this), const_calls).write(0); + } +} impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { fn default() -> Self { { @@ -347,11 +433,8 @@ impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemp } } pub fn test_19() { - let object: Value = - Rc::new(RefCell::new( - ::default( - ), - )); + let object: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&object.as_pointer()); let view: Ptr = object.as_pointer(); assert!( @@ -376,7 +459,16 @@ thread_local!( pub static rvalue_calls_21: Value = Rc::new(RefCell::new(0)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} @@ -408,7 +500,16 @@ thread_local!( pub static friend_calls_23: Value = Rc::new(RefCell::new(0_i32)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DeclaresFriend {} @@ -417,7 +518,16 @@ pub fn shared_friend_24() -> i32 { return 7; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DefinesFriend {} @@ -451,7 +561,16 @@ thread_local!( pub static function_calls_31: Value = Rc::new(RefCell::new(0_i32)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct p4_2_class_and_function_share_name_Reading { @@ -471,7 +590,16 @@ pub fn test_33() { assert!((function_calls_31.with(|rc| *rc.borrow()) == 1)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct p4_2_class_and_variable_share_name_Limit { diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs index eba6486995..e0483e2eb1 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs @@ -29,15 +29,17 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn construct(&mut self) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - } pub unsafe fn use_(&self) { (*(&raw const self.uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for LifetimeTracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.uses).write(0); + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + } +} impl CopyConstructibleUnsafe for LifetimeTracked { unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); @@ -63,7 +65,7 @@ impl Default for LifetimeTracked { unsafe { { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -80,6 +82,7 @@ pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new( VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -158,7 +161,7 @@ pub unsafe fn test_8() { pub unsafe fn test_9() { (unsafe { LifetimeTracked::reset() }); let mut scoped: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut scoped); + DefaultConstructibleUnsafe::default_constructor(&mut scoped); let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); @@ -168,7 +171,7 @@ pub unsafe fn test_9() { 'loop_: while ((index) < (3)) { 'for_body: { let mut scoped: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut scoped); + DefaultConstructibleUnsafe::default_constructor(&mut scoped); let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); @@ -180,7 +183,7 @@ pub unsafe fn test_9() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (3))); if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4)) { let mut scoped: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut scoped); + DefaultConstructibleUnsafe::default_constructor(&mut scoped); let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); @@ -190,7 +193,7 @@ pub unsafe fn test_9() { if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0)) { } else { let mut scoped: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut scoped); + DefaultConstructibleUnsafe::default_constructor(&mut scoped); let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); @@ -219,13 +222,13 @@ pub unsafe fn test_10() { pub unsafe fn test_11() { (unsafe { LifetimeTracked::reset() }); let mut tracked: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut tracked); + DefaultConstructibleUnsafe::default_constructor(&mut tracked); let _dtor_tracked = std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); { let mut tracked: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut tracked); + DefaultConstructibleUnsafe::default_constructor(&mut tracked); let _dtor_tracked = std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); 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 fe8350df27..a5dd7660f9 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 @@ -22,6 +22,11 @@ impl p1_member_hides_namespace_variable_HasBalance { return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)); } } +impl DefaultConstructibleUnsafe for p1_member_hides_namespace_variable_HasBalance { + unsafe fn default_constructor(&mut self) { + (&raw mut self.balance).write(7); + } +} impl Default for p1_member_hides_namespace_variable_HasBalance { fn default() -> Self { unsafe { p1_member_hides_namespace_variable_HasBalance { balance: 7 } } @@ -29,7 +34,8 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { } pub unsafe fn test_1() { let mut object: p1_member_hides_namespace_variable_HasBalance = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut object); assert!( ((unsafe { p1_member_hides_namespace_variable_HasBalance::deposit(&mut object, 3,) }) == (10)) @@ -50,6 +56,11 @@ pub static mut initial_2: std::cell::LazyCell = std::cell::LazyCell::new(|| pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub held: i32, } +impl DefaultConstructibleUnsafe for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + unsafe fn default_constructor(&mut self) { + (&raw mut self.held).write(1); + } +} impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { fn default() -> Self { unsafe { p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { held: 1 } } @@ -70,7 +81,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))); let mut object: p1_out_of_class_definition_is_in_class_scope_HasStaticTotal = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut object); assert!( ((unsafe { p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::add(&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 539106be6d..b2090157bf 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 @@ -14,6 +14,7 @@ use std::rc::Rc; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] 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 3bfb70a4e9..9e3a02c949 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 @@ -20,7 +20,14 @@ pub unsafe fn test_0() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p1_own_address_in_initializer_SelfLinked { pub next: *mut p1_own_address_in_initializer_SelfLinked, @@ -78,8 +85,8 @@ pub const anon_4_above: anon_4 = 14; pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: *const libc::c_char, } -impl p9_func_declared_before_function_body_RecordsConstructorName { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for p9_func_declared_before_function_body_RecordsConstructorName { + unsafe fn default_constructor(&mut self) { (&raw mut self.name).write(c"RecordsConstructorName".as_ptr()); assert!(((self.name) == (c"RecordsConstructorName".as_ptr()))); } @@ -90,7 +97,7 @@ impl Default for p9_func_declared_before_function_body_RecordsConstructorName { { let mut __v: p9_func_declared_before_function_body_RecordsConstructorName = ::zero_init(); - p9_func_declared_before_function_body_RecordsConstructorName::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -104,7 +111,7 @@ pub unsafe fn test_6() { assert!(((unsafe { plain_function_5() }) == (unsafe { plain_function_5() }))); let mut object: p9_func_declared_before_function_body_RecordsConstructorName = ::zero_init(); - p9_func_declared_before_function_body_RecordsConstructorName::construct(&mut object); + DefaultConstructibleUnsafe::default_constructor(&mut object); assert!(((libc::strcmp(object.name, c"RecordsConstructorName".as_ptr())) == (0))); let mut enclosing: *const libc::c_char = c"test".as_ptr(); let mut lambda: FnPtr *const libc::c_char> = 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 e1c5504da8..0108b148e2 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 @@ -43,7 +43,14 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size = 8; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum { @@ -72,7 +79,14 @@ pub unsafe fn test_5() { pub static mut count_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_12_class_name_in_own_scope_HasStaticCounter {} impl p2_12_class_name_in_own_scope_HasStaticCounter { @@ -89,7 +103,15 @@ pub unsafe fn test_7() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_6)) == (6))); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_8 { pub namespace_count: i32, pub namespace_ratio: f64, @@ -102,7 +124,15 @@ impl Default for anon_8 { pub static mut anon_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { ::default() }); #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_9 { pub member_count: i32, pub member_ratio: f64, @@ -114,7 +144,14 @@ impl Default for anon_9 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { pub tag: i32, @@ -152,7 +189,15 @@ pub unsafe fn test_10() { assert!(((anon_11.block_ratio) == (0.75_f64))); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_11 { pub block_count: i32, pub block_ratio: f64, @@ -178,6 +223,12 @@ impl p3_2_const_qualified_member_is_distinct_HasConstOverload { return 2; } } +impl DefaultConstructibleUnsafe for p3_2_const_qualified_member_is_distinct_HasConstOverload { + unsafe fn default_constructor(&mut self) { + (&raw mut self.plain_calls).write(0); + (&raw mut self.const_calls).write(0); + } +} impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { fn default() -> Self { unsafe { @@ -190,7 +241,8 @@ impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { } pub unsafe fn test_12() { let mut object: p3_2_const_qualified_member_is_distinct_HasConstOverload = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut object); let view: *const p3_2_const_qualified_member_is_distinct_HasConstOverload = &object; assert!( ((unsafe { @@ -228,6 +280,13 @@ impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverl return (((self.base) + (amount)) + (100)); } } +impl DefaultConstructibleUnsafe + for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload +{ + unsafe fn default_constructor(&mut self) { + (&raw mut self.base).write(10); + } +} impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { fn default() -> Self { unsafe { @@ -239,7 +298,9 @@ impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplici } pub unsafe fn test_15() { let mut object: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = - ::default(); + ::zero_init( + ); + DefaultConstructibleUnsafe::default_constructor(&mut object); assert!( ((unsafe { p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::pick_1( @@ -250,11 +311,14 @@ 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))); - assert!( - ((unsafe { - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut ::default() , 2 , ) - }) == (112)) - ); + { + let mut __tmp_0: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = ::zero_init(); + assert!( + ((unsafe { + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ DefaultConstructibleUnsafe :: default_constructor ( &mut __tmp_0 , ) ; & mut __tmp_0 } ) , 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))); } @@ -264,7 +328,14 @@ pub static mut rvalue_calls_17: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads { @@ -320,6 +391,14 @@ impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload return ((value) + (2)); } } +impl DefaultConstructibleUnsafe + for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload +{ + unsafe fn default_constructor(&mut self) { + (&raw mut self.plain_calls).write(0); + (&raw mut self.const_calls).write(0); + } +} impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { fn default() -> Self { unsafe { @@ -332,7 +411,8 @@ impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemp } pub unsafe fn test_19() { let mut object: p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut object); let view: *const p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload = &object; assert!( @@ -362,7 +442,14 @@ pub static mut rvalue_calls_21: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} impl p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads { @@ -403,7 +490,14 @@ pub static mut friend_calls_23: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p4_friend_definition_defines_earlier_friend_declaration_DeclaresFriend {} pub unsafe fn shared_friend_24() -> i32 { @@ -412,7 +506,14 @@ pub unsafe fn shared_friend_24() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p4_friend_definition_defines_earlier_friend_declaration_DefinesFriend {} pub unsafe fn test_25() { @@ -443,7 +544,14 @@ pub static mut function_calls_31: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p4_2_class_and_function_share_name_Reading { pub value: i32, @@ -462,7 +570,14 @@ pub unsafe fn test_33() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p4_2_class_and_variable_share_name_Limit { pub value: i32, diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs index 51361a8071..087ead97f1 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs @@ -13,6 +13,7 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, + DefaultConstructible, Memberwise, CopyConstructible, Movable, 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 09852599a6..10c2f86bad 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 @@ -13,6 +13,7 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, + DefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -36,7 +37,7 @@ impl Destructible for Tracker { ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Memberwise, CopyConstructible, MoveConstructible, @@ -52,7 +53,16 @@ pub struct HoldsTracker { pub member: Tracker, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct TriviallyDestructible { @@ -142,7 +152,16 @@ thread_local!( Rc::new(RefCell::new(TriviallyDestructible { value: 6 })); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p3_reverse_completion_order_WithStaticMember {} diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs index 813791e127..8aaf462ed0 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs @@ -12,6 +12,7 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, 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 b1b60eb5ef..186f0cfd46 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 @@ -12,6 +12,7 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -41,7 +42,7 @@ impl DestructibleUnsafe for Tracker { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MoveConstructibleUnsafe, @@ -55,7 +56,14 @@ pub struct HoldsTracker { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct TriviallyDestructible { pub value: i32, @@ -147,7 +155,14 @@ pub static mut trivial_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { TriviallyDestructible { value: 6 } }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p3_reverse_completion_order_WithStaticMember {} pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 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 c5524401a6..f3ae2ec709 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 @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { @@ -72,7 +81,16 @@ pub fn test_0() { assert!(({ ((*null_pm.borrow()) == -1_isize) })); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts { 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 ad9e65e93e..0f4f424119 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { pub first: i32, @@ -79,7 +86,14 @@ pub unsafe fn test_0() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts { pub first: i32, diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index ab4ef21e25..1e9576d87b 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -16,7 +16,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, Movable, Default, @@ -87,6 +87,12 @@ impl LifetimeTracked { }); } } +impl DefaultConstructible for LifetimeTracked { + fn default_constructor(this: &Ptr) { + field!((*this), uses).write(0); + (*ctorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CopyConstructible for LifetimeTracked { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), uses).write(0); @@ -114,7 +120,7 @@ impl Default for LifetimeTracked { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -261,7 +267,7 @@ pub trait p4_1_pure_virtual_without_definition_HasPureVirtual { ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Copyable, Default, )] @@ -280,7 +286,7 @@ thread_local!( pub static global_12: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -304,7 +310,7 @@ pub fn test_13() { pub fn test_14() { ({ LifetimeTracked::reset() }); let t: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&t.as_pointer()); + DefaultConstructible::default_constructor(&t.as_pointer()); let _dtor_t = std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let r: Ptr = t.as_pointer(); @@ -385,7 +391,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, Movable, Default, @@ -474,6 +480,12 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[destroy] pub b: LifetimeTracked, } +impl DefaultConstructible for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + fn default_constructor(this: &Ptr) { + DefaultConstructible::default_constructor(&field_ptr!(this, a)); + DefaultConstructible::default_constructor(&field_ptr!(this, b)); + } +} pub fn test_20() { ({ LifetimeTracked::reset() }); let p: Value = Rc::new(RefCell::new( @@ -481,13 +493,13 @@ pub fn test_20() { a: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, b: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, }, @@ -528,6 +540,12 @@ pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(4)] pub n: i32, } +impl DefaultConstructible for p7_member_access_captures_this_HasMemberUsedInLambda { + fn default_constructor(this: &Ptr) { + DefaultConstructible::default_constructor(&field_ptr!(this, x)); + field!((*this), n).write(1); + } +} impl Default for p7_member_access_captures_this_HasMemberUsedInLambda { fn default() -> Self { { @@ -543,7 +561,7 @@ pub fn test_22() { let c: Value = Rc::new(RefCell::new( ::zero_init(), )); - p7_member_access_captures_this_HasMemberUsedInLambdaImpl::construct_1(&c.as_pointer()); + DefaultConstructible::default_constructor(&c.as_pointer()); let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let f: Value i32>> = Rc::new(RefCell::new( @@ -578,12 +596,17 @@ pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, } +impl DefaultConstructible for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + fn default_constructor(this: &Ptr) { + DefaultConstructible::default_constructor(&field_ptr!(this, x)); + } +} pub fn test_23() { ({ LifetimeTracked::reset() }); let c: Value = Rc::new( RefCell::new(::zero_init()), ); - p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl::construct_1(&c.as_pointer()); + DefaultConstructible::default_constructor(&c.as_pointer()); let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let f: Value usize>> = Rc::new(RefCell::new( @@ -632,6 +655,11 @@ thread_local!( #[memberwise(copy_assign)] #[byte_size(1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} +impl DefaultConstructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + fn default_constructor(this: &Ptr) { + (*t_ctors_27.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl Default for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { fn default() -> Self { { @@ -640,9 +668,7 @@ impl Default for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { Rc::new(RefCell::new( ::zero_init(), )); - p9_destructor_not_potentially_invoked_HasUndefinedDestructorImpl::construct( - &__v.as_pointer(), - ); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -652,7 +678,7 @@ pub fn test_28() { let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - p9_destructor_not_potentially_invoked_HasUndefinedDestructorImpl::construct(&__p); + DefaultConstructible::default_constructor(&__p); __p }; assert!(!((p).is_null())); @@ -677,6 +703,12 @@ pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { #[offset(0)] pub value: i32, } +impl DefaultConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { + fn default_constructor(this: &Ptr) { + field!((*this), value).write(3); + (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { fn default() -> Self { { @@ -684,7 +716,7 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - p9_unused_copy_constructor_HasUndefinedCopyCtorImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -697,7 +729,7 @@ pub fn test_31() { let a: Value = Rc::new(RefCell::new( ::zero_init(), )); - p9_unused_copy_constructor_HasUndefinedCopyCtorImpl::construct(&a.as_pointer()); + DefaultConstructible::default_constructor(&a.as_pointer()); assert!((({ read_30(a.as_pointer(),) }) == 3)); assert!((ctor_calls_29.with(|rc| *rc.borrow()) == 1)); } @@ -718,6 +750,11 @@ thread_local!( )] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} +impl DefaultConstructible for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + fn default_constructor(this: &Ptr) { + (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { fn default() -> Self { { @@ -726,9 +763,7 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { Rc::new(RefCell::new( ::zero_init(), )); - p9_unused_implicit_assignment_HasUndefinedCopyAssignmentImpl::construct( - &__v.as_pointer(), - ); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -756,21 +791,22 @@ pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { #[byte_size(1)] pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } +impl DefaultConstructible for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { + fn default_constructor(this: &Ptr) { + DefaultConstructible::default_constructor(&field_ptr!(this, m)); + } +} pub fn test_33() { let a: Value = Rc::new(RefCell::new( ::zero_init(), )); - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignmentImpl::construct_1( - &a.as_pointer(), - ); + DefaultConstructible::default_constructor(&a.as_pointer()); let b: Value = Rc::new(RefCell::new( ::zero_init(), )); - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignmentImpl::construct_1( - &b.as_pointer(), - ); + DefaultConstructible::default_constructor(&b.as_pointer()); assert!((m_ctors_32.with(|rc| *rc.borrow()) == 2)); } thread_local!( @@ -905,21 +941,21 @@ impl p4_1_pure_virtual_without_definition_HasPureVirtual } } impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - fn destroy(_: &Ptr) { + fn destroy(this: &Ptr) { unreachable!( "p9_destructor_not_potentially_invoked_HasUndefinedDestructor::destroy is never defined" ) } } impl CopyConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn copy_constructor(_: &Ptr, _: Ptr) { + fn copy_constructor(this: &Ptr, _: Ptr) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } impl CopyAssignable for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn copy_assign(_: &Ptr, _: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, _: Ptr) -> Ptr { unreachable!( "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" ) @@ -934,14 +970,9 @@ impl HasConstexprCtorImpl for Ptr { } } pub trait LifetimeTrackedImpl { - fn construct(&self); fn use_(&self); } impl LifetimeTrackedImpl for Ptr { - fn construct(&self) { - field!((*self), uses).write(0); - (*ctorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); @@ -960,20 +991,8 @@ impl p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl field!((*self), scratch).write(0); } } -pub trait p6_unevaluated_binding_needs_no_capture_HasTwoMembersImpl { - fn construct_1(&self); -} -impl p6_unevaluated_binding_needs_no_capture_HasTwoMembersImpl - for Ptr -{ - fn construct_1(&self) { - LifetimeTrackedImpl::construct(&field_ptr!(self, a)); - LifetimeTrackedImpl::construct(&field_ptr!(self, b)); - } -} pub trait p7_member_access_captures_this_HasMemberUsedInLambdaImpl { fn makeLambda(&self) -> FnPtr i32>; - fn construct_1(&self); } impl p7_member_access_captures_this_HasMemberUsedInLambdaImpl for Ptr @@ -990,14 +1009,9 @@ impl p7_member_access_captures_this_HasMemberUsedInLambdaImpl } ); } - fn construct_1(&self) { - LifetimeTrackedImpl::construct(&field_ptr!(self, x)); - field!((*self), n).write(1); - } } pub trait p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl { fn sizer(&self) -> FnPtr usize>; - fn construct_1(&self); } impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl for Ptr @@ -1009,52 +1023,6 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl } }); } - fn construct_1(&self) { - LifetimeTrackedImpl::construct(&field_ptr!(self, x)); - } -} -pub trait p9_destructor_not_potentially_invoked_HasUndefinedDestructorImpl { - fn construct(&self); -} -impl p9_destructor_not_potentially_invoked_HasUndefinedDestructorImpl - for Ptr -{ - fn construct(&self) { - (*t_ctors_27.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p9_unused_copy_constructor_HasUndefinedCopyCtorImpl { - fn construct(&self); -} -impl p9_unused_copy_constructor_HasUndefinedCopyCtorImpl - for Ptr -{ - fn construct(&self) { - field!((*self), value).write(3); - (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignmentImpl { - fn construct_1(&self); -} -impl p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignmentImpl - for Ptr -{ - fn construct_1(&self) { - p9_unused_implicit_assignment_HasUndefinedCopyAssignmentImpl::construct(&field_ptr!( - self, m - )); - } -} -pub trait p9_unused_implicit_assignment_HasUndefinedCopyAssignmentImpl { - fn construct(&self); -} -impl p9_unused_implicit_assignment_HasUndefinedCopyAssignmentImpl - for Ptr -{ - fn construct(&self) { - (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); - } } pub fn __cpp2rust_init_globals() { let _ = copyCount_0.with(|_| ()); diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index b244e81774..686c763bae 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -13,7 +13,7 @@ pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new( FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MovableUnsafe, Default, @@ -69,15 +69,17 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) }; } - pub unsafe fn construct(&mut self) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)).prefix_inc(); - } pub unsafe fn use_(&self) { (*(&raw const self.uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for LifetimeTracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.uses).write(0); + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)).prefix_inc(); + } +} impl CopyConstructibleUnsafe for LifetimeTracked { unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); @@ -103,7 +105,7 @@ impl Default for LifetimeTracked { unsafe { { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -227,7 +229,7 @@ pub unsafe trait p4_1_pure_virtual_without_definition_HasPureVirtual { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyableUnsafe, Default, )] @@ -245,7 +247,7 @@ pub static mut global_12: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -273,7 +275,7 @@ pub unsafe fn test_13() { pub unsafe fn test_14() { (unsafe { LifetimeTracked::reset() }); let mut t: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut t); + DefaultConstructibleUnsafe::default_constructor(&mut t); let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); @@ -350,7 +352,7 @@ pub static mut copies_18: std::cell::LazyCell = std::cell::LazyCell::new(|| FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MovableUnsafe, Default, @@ -430,10 +432,10 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[destroy] pub b: LifetimeTracked, } -impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - pub unsafe fn construct_1(&mut self) { - LifetimeTracked::construct(&mut self.a); - LifetimeTracked::construct(&mut self.b); +impl DefaultConstructibleUnsafe for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + unsafe fn default_constructor(&mut self) { + DefaultConstructibleUnsafe::default_constructor(&mut self.a); + DefaultConstructibleUnsafe::default_constructor(&mut self.b); } } pub unsafe fn test_20() { @@ -442,12 +444,12 @@ pub unsafe fn test_20() { p6_unevaluated_binding_needs_no_capture_HasTwoMembers { a: { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }, b: { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }, }; @@ -495,8 +497,10 @@ impl p7_member_access_captures_this_HasMemberUsedInLambda { } ); } - pub unsafe fn construct_1(&mut self) { - LifetimeTracked::construct(&mut self.x); +} +impl DefaultConstructibleUnsafe for p7_member_access_captures_this_HasMemberUsedInLambda { + unsafe fn default_constructor(&mut self) { + DefaultConstructibleUnsafe::default_constructor(&mut self.x); (&raw mut self.n).write(1); } } @@ -514,7 +518,7 @@ pub unsafe fn test_22() { (unsafe { LifetimeTracked::reset() }); let mut c: p7_member_access_captures_this_HasMemberUsedInLambda = ::zero_init(); - p7_member_access_captures_this_HasMemberUsedInLambda::construct_1(&mut c); + DefaultConstructibleUnsafe::default_constructor(&mut c); let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); @@ -553,15 +557,17 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } }); } - pub unsafe fn construct_1(&mut self) { - LifetimeTracked::construct(&mut self.x); +} +impl DefaultConstructibleUnsafe for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + unsafe fn default_constructor(&mut self) { + DefaultConstructibleUnsafe::default_constructor(&mut self.x); } } pub unsafe fn test_23() { (unsafe { LifetimeTracked::reset() }); let mut c: p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda = ::zero_init(); - p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::construct_1(&mut c); + DefaultConstructibleUnsafe::default_constructor(&mut c); let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); @@ -605,8 +611,8 @@ pub static mut t_ctors_27: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} -impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + unsafe fn default_constructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)).prefix_inc(); } } @@ -616,7 +622,7 @@ impl Default for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { { let mut __v: p9_destructor_not_potentially_invoked_HasUndefinedDestructor = ::zero_init(); - p9_destructor_not_potentially_invoked_HasUndefinedDestructor::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -627,7 +633,7 @@ pub unsafe fn test_28() { let __p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = Box::leak( Box::new(::zero_init()), ); - p9_destructor_not_potentially_invoked_HasUndefinedDestructor::construct(&mut *__p); + DefaultConstructibleUnsafe::default_constructor(&mut *__p); __p }; assert!(!((p).is_null())); @@ -648,8 +654,8 @@ pub static mut ctor_calls_29: std::cell::LazyCell = pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } -impl p9_unused_copy_constructor_HasUndefinedCopyCtor { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { + unsafe fn default_constructor(&mut self) { (&raw mut self.value).write(3); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)).prefix_inc(); } @@ -660,7 +666,7 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { { let mut __v: p9_unused_copy_constructor_HasUndefinedCopyCtor = ::zero_init(); - p9_unused_copy_constructor_HasUndefinedCopyCtor::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -672,7 +678,7 @@ pub unsafe fn read_30(object: *const p9_unused_copy_constructor_HasUndefinedCopy pub unsafe fn test_31() { let mut a: p9_unused_copy_constructor_HasUndefinedCopyCtor = ::zero_init(); - p9_unused_copy_constructor_HasUndefinedCopyCtor::construct(&mut a); + DefaultConstructibleUnsafe::default_constructor(&mut a); assert!(((unsafe { read_30(&a,) }) == (3))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)) == (1))); } @@ -689,8 +695,8 @@ pub static mut m_ctors_32: std::cell::LazyCell = std::cell::LazyCell::new(| MovableUnsafe, )] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} -impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + unsafe fn default_constructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)).prefix_inc(); } } @@ -700,7 +706,7 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { { let mut __v: p9_unused_implicit_assignment_HasUndefinedCopyAssignment = ::zero_init(); - p9_unused_implicit_assignment_HasUndefinedCopyAssignment::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -724,18 +730,20 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } -impl p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { - pub unsafe fn construct_1(&mut self) { - p9_unused_implicit_assignment_HasUndefinedCopyAssignment::construct(&mut self.m); +impl DefaultConstructibleUnsafe + for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment +{ + unsafe fn default_constructor(&mut self) { + DefaultConstructibleUnsafe::default_constructor(&mut self.m); } } pub unsafe fn test_33() { let mut a: p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment = ::zero_init(); - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::construct_1(&mut a); + DefaultConstructibleUnsafe::default_constructor(&mut a); let mut b: p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment = ::zero_init(); - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::construct_1(&mut b); + DefaultConstructibleUnsafe::default_constructor(&mut b); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)) == (2))); } pub static mut else_runs_34: std::cell::LazyCell = 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 4bbd0595b0..46af7099a6 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 @@ -15,6 +15,7 @@ use std::rc::{Rc, Weak}; VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] 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 6d9d473641..549325885a 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 @@ -14,6 +14,7 @@ use std::rc::Rc; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] 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 7c57795151..4ac43d08f9 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 @@ -15,6 +15,7 @@ use std::rc::{Rc, Weak}; VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] 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 a342e525ff..23cb1a23dc 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 @@ -15,6 +15,7 @@ use std::rc::{Rc, Weak}; VaArg, FnPtrArg, CppFrom, + TriviallyDefaultConstructible, TriviallyCopyable, Default, )] 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 69d9479e89..603547e872 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 @@ -19,6 +19,7 @@ impl p1_template_constructor_from_own_type_Probe { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] 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 2593310235..0688a1be3f 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 @@ -14,6 +14,7 @@ use std::rc::Rc; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] 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 b191ca0178..a2968b2631 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 @@ -7,7 +7,14 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Memberwise, Default, + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + CppFrom, + DefaultInitializable, + Memberwise, + Default, )] #[memberwise(move_constructor)] #[cpp_from(i32, construct, value)] 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 984ab8f9a1..46bb3a153f 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 @@ -8,7 +8,12 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, MemberwiseUnsafe, Default, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DefaultInitializableUnsafe, + MemberwiseUnsafe, + Default, )] #[memberwise(move_constructor)] #[cpp_from(i32, construct, value)] 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 a146bd27b8..472b787e90 100644 --- a/tests/std/class/class.mem/out/refcount/class.free.rs +++ b/tests/std/class/class.mem/out/refcount/class.free.rs @@ -10,7 +10,16 @@ thread_local!( pub static allocations_0: Value = Rc::new(RefCell::new(0)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p1_allocation_function_is_static_Allocates {} @@ -49,7 +58,16 @@ thread_local!( pub static deallocations_2: Value = Rc::new(RefCell::new(0)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p3_deallocation_function_is_static_Deallocates {} 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 410c047517..11ed85587e 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 @@ -20,6 +20,11 @@ pub struct p7_1_function_body_names_later_member_HasLaterMembers { #[offset(0)] pub stock: i32, } +impl DefaultConstructible for p7_1_function_body_names_later_member_HasLaterMembers { + fn default_constructor(this: &Ptr) { + field!((*this), stock).write(9); + } +} impl Default for p7_1_function_body_names_later_member_HasLaterMembers { fn default() -> Self { { p7_1_function_body_names_later_member_HasLaterMembers { stock: 9 } } @@ -27,8 +32,9 @@ impl Default for p7_1_function_body_names_later_member_HasLaterMembers { } pub fn test_3() { let object: Value = Rc::new( - RefCell::new(::default()), + RefCell::new(::zero_init()), ); + DefaultConstructible::default_constructor(&object.as_pointer()); assert!( (({ p7_1_function_body_names_later_member_HasLaterMembersImpl::take(&object.as_pointer(), 3) @@ -49,6 +55,11 @@ pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { #[offset(0)] pub total: i32, } +impl DefaultConstructible for p7_2_default_argument_names_later_member_HasLaterStaticStep { + fn default_constructor(this: &Ptr) { + field!((*this), total).write(1); + } +} impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { fn default() -> Self { { p7_2_default_argument_names_later_member_HasLaterStaticStep { total: 1 } } @@ -56,8 +67,9 @@ impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { } pub fn test_6() { let object: Value = Rc::new( - RefCell::new(::default()), + RefCell::new(::zero_init()), ); + DefaultConstructible::default_constructor(&object.as_pointer()); assert!( (({ p7_2_default_argument_names_later_member_HasLaterStaticStepImpl::advance( 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 100772f4b3..108af2684c 100644 --- a/tests/std/class/class.mem/out/unsafe/class.free.rs +++ b/tests/std/class/class.mem/out/unsafe/class.free.rs @@ -9,7 +9,14 @@ use std::rc::Rc; pub static mut allocations_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p1_allocation_function_is_static_Allocates {} impl p1_allocation_function_is_static_Allocates { @@ -45,7 +52,14 @@ pub static mut deallocations_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p3_deallocation_function_is_static_Deallocates {} impl p3_deallocation_function_is_static_Deallocates { 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 caab392d1f..ad96fdd5ac 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 @@ -28,6 +28,11 @@ impl p7_1_function_body_names_later_member_HasLaterMembers { return 2; } } +impl DefaultConstructibleUnsafe for p7_1_function_body_names_later_member_HasLaterMembers { + unsafe fn default_constructor(&mut self) { + (&raw mut self.stock).write(9); + } +} impl Default for p7_1_function_body_names_later_member_HasLaterMembers { fn default() -> Self { unsafe { p7_1_function_body_names_later_member_HasLaterMembers { stock: 9 } } @@ -35,7 +40,8 @@ impl Default for p7_1_function_body_names_later_member_HasLaterMembers { } pub unsafe fn test_3() { let mut object: p7_1_function_body_names_later_member_HasLaterMembers = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut object); assert!( ((unsafe { p7_1_function_body_names_later_member_HasLaterMembers::take(&mut object, 3,) }) == (38)) @@ -56,6 +62,11 @@ impl p7_2_default_argument_names_later_member_HasLaterStaticStep { return self.total; } } +impl DefaultConstructibleUnsafe for p7_2_default_argument_names_later_member_HasLaterStaticStep { + unsafe fn default_constructor(&mut self) { + (&raw mut self.total).write(1); + } +} impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { fn default() -> Self { unsafe { p7_2_default_argument_names_later_member_HasLaterStaticStep { total: 1 } } @@ -63,7 +74,8 @@ impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { } pub unsafe fn test_6() { let mut object: p7_2_default_argument_names_later_member_HasLaterStaticStep = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut object); assert!( ((unsafe { p7_2_default_argument_names_later_member_HasLaterStaticStep::advance( 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 2a5d03885c..401c73ca69 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 @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p6_2_zero_initialized_padding_Padded { @@ -17,7 +26,16 @@ pub struct p6_2_zero_initialized_padding_Padded { pub number: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p6_2_zero_initialized_padding_TailPadded { @@ -27,7 +45,16 @@ pub struct p6_2_zero_initialized_padding_TailPadded { pub letter: i8, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct p6_2_zero_initialized_padding_HoldsPadded { 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 d93c00cb5b..23313f5b3e 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 @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { @@ -16,7 +25,17 @@ pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(8)] pub struct p6_1_zero_initialized_pointer_to_member_HoldsSelector { #[offset(0)] @@ -114,7 +133,15 @@ thread_local!( static counter_11: Value = Rc::new(RefCell::new(0_i32)); ); #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(24)] pub struct p6_2_zero_initialized_class_Inner { @@ -126,7 +153,16 @@ pub struct p6_2_zero_initialized_class_Inner { #[byte_size(8)] pub pointer: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(96)] pub struct p6_2_zero_initialized_class_Outer { #[offset(0)] @@ -197,7 +233,15 @@ pub fn test_15() { ({ check_14((heap_outer).clone()) }); heap_outer.delete(); } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct p6_3_zero_initialized_union_Number { #[offset(0)] @@ -235,7 +279,16 @@ pub fn test_17() { assert!(((p6_3_zero_initialized_union_Number::integer(value_number.as_pointer()).read()) == 0)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p6_4_zero_initialized_array_Pair { @@ -348,6 +401,12 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { #[offset(4)] pub five: i32, } +impl DefaultConstructible for p9_1_2_zero_then_default_initialized_WithDefaultMember { + fn default_constructor(this: &Ptr) { + field!((*this), zeroed).write(0_i32); + field!((*this), five).write(5); + } +} impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { fn default() -> Self { { @@ -364,6 +423,11 @@ pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { #[offset(0)] pub untouched: i32, } +impl DefaultConstructible for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + fn default_constructor(this: &Ptr) { + field!((*this), untouched).write(0_i32); + } +} impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { fn default() -> Self { { @@ -372,9 +436,7 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { Rc::new(RefCell::new( ::zero_init(), )); - p9_1_2_zero_then_default_initialized_LeavesMemberAloneImpl::construct( - &__v.as_pointer(), - ); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -391,28 +453,37 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { #[byte_size(4)] pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } +impl DefaultConstructible for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + fn default_constructor(this: &Ptr) { + field!((*this), number).write(0_i32); + DefaultConstructible::default_constructor(&field_ptr!(this, member)); + } +} pub fn test_22() { - 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()); + let value: Value = Rc::new( + RefCell::new(::zero_init()), + ); + DefaultConstructible::default_constructor(&value.as_pointer()); + assert!(({ (*value.borrow()).zeroed } == 0)); + assert!(({ (*value.borrow()).five } == 5)); + let mut heap: Ptr = { + let __p = Ptr::alloc(::zero_init()); + DefaultConstructible::default_constructor(&__p); + __p + }; assert!((heap.with(|__s| __s.zeroed) == 0)); assert!((heap.with(|__s| __s.five) == 5)); heap.delete(); let holder: Value = Rc::new( RefCell::new(::zero_init()), ); - p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAloneImpl::construct_1( - &holder.as_pointer(), - ); + DefaultConstructible::default_constructor(&holder.as_pointer()); 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_HoldsLeavesMemberAloneImpl::construct_1(&__p); + DefaultConstructible::default_constructor(&__p); __p }; assert!((heap_holder.with(|__s| __s.number) == 0)); @@ -432,29 +503,6 @@ fn main_0() -> i32 { ({ test_22() }); return 0; } -pub trait p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAloneImpl { - fn construct_1(&self); -} -impl p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAloneImpl - for Ptr -{ - fn construct_1(&self) { - field!((*self), number).write(0_i32); - p9_1_2_zero_then_default_initialized_LeavesMemberAloneImpl::construct(&field_ptr!( - self, member - )); - } -} -pub trait p9_1_2_zero_then_default_initialized_LeavesMemberAloneImpl { - fn construct(&self); -} -impl p9_1_2_zero_then_default_initialized_LeavesMemberAloneImpl - for Ptr -{ - fn construct(&self) { - field!((*self), untouched).write(0_i32); - } -} pub fn __cpp2rust_init_globals() { let _ = static_pm_0.with(|_| ()); let _ = static_int_2.with(|_| ()); 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 b929604cbe..b57498b6cc 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p6_2_zero_initialized_padding_Padded { pub letter: libc::c_char, @@ -16,7 +23,14 @@ pub struct p6_2_zero_initialized_padding_Padded { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p6_2_zero_initialized_padding_TailPadded { pub number: i32, @@ -24,7 +38,14 @@ pub struct p6_2_zero_initialized_padding_TailPadded { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p6_2_zero_initialized_padding_HoldsPadded { pub letter: libc::c_char, 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 2f81b8a6b5..af85deebce 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 @@ -8,14 +8,29 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { pub first: i32, pub second: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub struct p6_1_zero_initialized_pointer_to_member_HoldsSelector { pub selector: isize, } @@ -110,7 +125,14 @@ pub unsafe fn test_12() { static mut counter_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p6_2_zero_initialized_class_Inner { pub number: i32, @@ -119,7 +141,14 @@ pub struct p6_2_zero_initialized_class_Inner { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p6_2_zero_initialized_class_Outer { pub letter: libc::c_char, @@ -172,7 +201,15 @@ pub unsafe fn test_15() { }; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union p6_3_zero_initialized_union_Number { pub integer: i32, pub bytes: [libc::c_char; 8], @@ -192,7 +229,14 @@ pub unsafe fn test_17() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p6_4_zero_initialized_array_Pair { pub first: i32, @@ -288,6 +332,12 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { pub zeroed: i32, pub five: i32, } +impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_WithDefaultMember { + unsafe fn default_constructor(&mut self) { + (&raw mut self.zeroed).write(0_i32); + (&raw mut self.five).write(5); + } +} impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { fn default() -> Self { unsafe { @@ -303,8 +353,8 @@ impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } -impl p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + unsafe fn default_constructor(&mut self) { (&raw mut self.untouched).write(0_i32); } } @@ -314,7 +364,7 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { { let mut __v: p9_1_2_zero_then_default_initialized_LeavesMemberAlone = ::zero_init(); - p9_1_2_zero_then_default_initialized_LeavesMemberAlone::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -328,21 +378,25 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub number: i32, pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } -impl p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { - pub unsafe fn construct_1(&mut self) { +impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + unsafe fn default_constructor(&mut self) { (&raw mut self.number).write(0_i32); - p9_1_2_zero_then_default_initialized_LeavesMemberAlone::construct(&mut self.member); + DefaultConstructibleUnsafe::default_constructor(&mut self.member); } } pub unsafe fn test_22() { let mut value: p9_1_2_zero_then_default_initialized_WithDefaultMember = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut value); assert!(((value.zeroed) == (0))); assert!(((value.five) == (5))); - 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); + 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(), + )); + DefaultConstructibleUnsafe::default_constructor(&mut *__p); + __p + }; assert!((((*heap).zeroed) == (0))); assert!((((*heap).five) == (5))); { @@ -353,14 +407,14 @@ pub unsafe fn test_22() { }; let mut holder: p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = ::zero_init(); - p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::construct_1(&mut holder); + DefaultConstructibleUnsafe::default_constructor(&mut holder); 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::construct_1(&mut *__p); + DefaultConstructibleUnsafe::default_constructor(&mut *__p); __p }; assert!((((*heap_holder).number) == (0))); 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 9c6861d953..a250ad10a8 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 @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(12)] pub struct p6_array_of_pointers_to_data_members_HasThreeInts { 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 3c3fa06825..e91210744e 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 @@ -60,6 +60,11 @@ pub struct p9_static_member_hides_namespace_variable_HasStaticStep { #[offset(0)] pub total: i32, } +impl DefaultConstructible for p9_static_member_hides_namespace_variable_HasStaticStep { + fn default_constructor(this: &Ptr) { + field!((*this), total).write(1); + } +} impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { fn default() -> Self { { p9_static_member_hides_namespace_variable_HasStaticStep { total: 1 } } @@ -67,8 +72,9 @@ impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { } pub fn test_11() { let object: Value = Rc::new( - RefCell::new(::default()), + RefCell::new(::zero_init()), ); + DefaultConstructible::default_constructor(&object.as_pointer()); assert!( (({ p9_static_member_hides_namespace_variable_HasStaticStepImpl::advance( @@ -114,6 +120,13 @@ pub struct p9_evaluated_each_time_called_Widget { #[offset(0)] pub id: i32, } +impl DefaultConstructible for p9_evaluated_each_time_called_Widget { + fn default_constructor(this: &Ptr) { + { + p9_evaluated_each_time_called_WidgetImpl::construct(this, { ({ count_default_13() }) }); + } + } +} impl Default for p9_evaluated_each_time_called_Widget { fn default() -> Self { { @@ -148,6 +161,11 @@ impl p9_evaluated_each_time_called_Account { base_15.with(|rc| *rc.borrow_mut() = value); } } +impl DefaultConstructible for p9_evaluated_each_time_called_Account { + fn default_constructor(this: &Ptr) { + field!((*this), balance).write(0); + } +} impl Default for p9_evaluated_each_time_called_Account { fn default() -> Self { { p9_evaluated_each_time_called_Account { balance: 0 } } @@ -184,8 +202,9 @@ pub fn test_17() { assert!(({ (*c.borrow()).id } == 5)); assert!((defaults_evaluated_12.with(|rc| *rc.borrow()) == 5)); let account: Value = Rc::new(RefCell::new( - ::default(), + ::zero_init(), )); + DefaultConstructible::default_constructor(&account.as_pointer()); assert!( (({ p9_evaluated_each_time_called_AccountImpl::deposit( @@ -215,7 +234,16 @@ pub fn add_18(mut a: i32, mut b: i32) -> i32 { return (a + b); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p9_not_part_of_the_type_Scale {} 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 271a27fe01..79fd5f7165 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 @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct p2_pointer_to_array_member_HasIntArray { #[offset(0)] @@ -41,7 +50,16 @@ pub fn test_0() { assert!(({ (*obj.borrow()).before } == 1)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p2_pointer_to_data_member_HasTwoInts { @@ -71,7 +89,16 @@ thread_local!( pub static pm_2: Value = Rc::new(RefCell::new(-1_isize)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p2_pointer_to_member_of_incomplete_class_CompletedLater { @@ -102,7 +129,16 @@ pub fn test_3() { ); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { @@ -111,7 +147,17 @@ pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(8)] pub struct p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector { #[offset(0)] 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 85b7ec1a0c..b59c1fc2be 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p6_array_of_pointers_to_data_members_HasThreeInts { pub first: i32, 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 36b4738747..d0b9de3511 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 @@ -64,6 +64,11 @@ impl p9_static_member_hides_namespace_variable_HasStaticStep { return self.total; } } +impl DefaultConstructibleUnsafe for p9_static_member_hides_namespace_variable_HasStaticStep { + unsafe fn default_constructor(&mut self) { + (&raw mut self.total).write(1); + } +} impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { fn default() -> Self { unsafe { p9_static_member_hides_namespace_variable_HasStaticStep { total: 1 } } @@ -71,7 +76,8 @@ impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { } pub unsafe fn test_11() { let mut object: p9_static_member_hides_namespace_variable_HasStaticStep = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut object); assert!( ((unsafe { p9_static_member_hides_namespace_variable_HasStaticStep::advance( @@ -117,6 +123,15 @@ impl p9_evaluated_each_time_called_Widget { (&raw mut self.id).write(id); } } +impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Widget { + unsafe fn default_constructor(&mut self) { + unsafe { + p9_evaluated_each_time_called_Widget::construct(&mut *self, { + (unsafe { count_default_13() }) + }); + } + } +} impl Default for p9_evaluated_each_time_called_Widget { fn default() -> Self { unsafe { @@ -151,6 +166,11 @@ impl p9_evaluated_each_time_called_Account { (*std::cell::LazyCell::force_mut(&mut *&raw mut base_15)) = value; } } +impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Account { + unsafe fn default_constructor(&mut self) { + (&raw mut self.balance).write(0); + } +} impl Default for p9_evaluated_each_time_called_Account { fn default() -> Self { unsafe { p9_evaluated_each_time_called_Account { balance: 0 } } @@ -182,7 +202,8 @@ pub unsafe fn test_17() { assert!(((c.id) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut defaults_evaluated_12)) == (5))); let mut account: p9_evaluated_each_time_called_Account = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut account); assert!( ((unsafe { p9_evaluated_each_time_called_Account::deposit( @@ -217,7 +238,14 @@ pub unsafe fn add_18(mut a: i32, mut b: i32) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p9_not_part_of_the_type_Scale {} impl p9_not_part_of_the_type_Scale { 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 18c61cc2fe..090bcf4650 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_pointer_to_array_member_HasIntArray { pub before: i32, @@ -41,7 +48,14 @@ pub unsafe fn test_0() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_pointer_to_data_member_HasTwoInts { pub first: i32, @@ -81,7 +95,14 @@ pub unsafe fn test_1() { pub static mut pm_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { -1_isize }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_pointer_to_member_of_incomplete_class_CompletedLater { pub first: i32, @@ -107,14 +128,29 @@ pub unsafe fn test_3() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { pub first: i32, pub second: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub struct p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector { pub selector: isize, } diff --git a/tests/std/expr/conv/out/refcount/conv.mem.rs b/tests/std/expr/conv/out/refcount/conv.mem.rs index 202d47048e..0fe2dfc94d 100644 --- a/tests/std/expr/conv/out/refcount/conv.mem.rs +++ b/tests/std/expr/conv/out/refcount/conv.mem.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p1_null_distinct_from_first_member_HasTwoInts { diff --git a/tests/std/expr/conv/out/unsafe/conv.mem.rs b/tests/std/expr/conv/out/unsafe/conv.mem.rs index d3311733de..ebb8082d3c 100644 --- a/tests/std/expr/conv/out/unsafe/conv.mem.rs +++ b/tests/std/expr/conv/out/unsafe/conv.mem.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p1_null_distinct_from_first_member_HasTwoInts { pub first: i32, 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 fa51d3ea05..9a71c9350c 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 @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct p4_reference_const_cast_Pair { 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 0ab850df8b..21674a4b82 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 @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct HasTwoInts { @@ -17,7 +26,16 @@ pub struct HasTwoInts { pub second: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct AlsoHasTwoInts { 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 c65e529aba..07fc493b87 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 @@ -17,7 +17,16 @@ pub fn test_0() { assert!((((converted.read()).read()) == 7)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p10_null_converts_to_null_HasTwoInts { @@ -27,7 +36,16 @@ pub struct p10_null_converts_to_null_HasTwoInts { pub second: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p10_null_converts_to_null_HasChar { @@ -40,7 +58,16 @@ pub fn test_1() { assert!(((converted) == -1_isize)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p10_2_data_member_round_trip_HasTwoInts { @@ -50,7 +77,16 @@ pub struct p10_2_data_member_round_trip_HasTwoInts { pub second: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p10_2_data_member_round_trip_HasChar { 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 d72d679fb2..258b55e89f 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p4_reference_const_cast_Pair { pub x: i32, 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 65184ac4c7..ea41a007c1 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct HasTwoInts { pub first: i32, @@ -16,7 +23,14 @@ pub struct HasTwoInts { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct AlsoHasTwoInts { pub first: i32, 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 0e85f5b1d4..b6e8f87d23 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 @@ -18,7 +18,14 @@ pub unsafe fn test_0() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p10_null_converts_to_null_HasTwoInts { pub first: i32, @@ -26,7 +33,14 @@ pub struct p10_null_converts_to_null_HasTwoInts { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p10_null_converts_to_null_HasChar { pub character: libc::c_char, @@ -38,7 +52,14 @@ pub unsafe fn test_1() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p10_2_data_member_round_trip_HasTwoInts { pub first: i32, @@ -46,7 +67,14 @@ pub struct p10_2_data_member_round_trip_HasTwoInts { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p10_2_data_member_round_trip_HasChar { pub character: libc::c_char, 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 b078a4b6ef..6a56774ca1 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 @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct p1_result_is_updated_operand_Counter { 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 13231d9f2f..f47f6c147a 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 @@ -13,7 +13,16 @@ thread_local!( pub static calls_1: Value = Rc::new(RefCell::new(0)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p3_2_static_member_is_ordinary_pointer_HasStaticMembers {} @@ -33,7 +42,16 @@ pub fn test_2() { assert!((calls_1.with(|rc| *rc.borrow()) == 1)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { @@ -51,7 +69,16 @@ pub fn test_3() { assert!((({ function_pointer.call(object.as_pointer(), 1,) }) == 6)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { 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 4744f7e936..92dd5b993d 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p1_result_is_updated_operand_Counter { pub n: i32, 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 d79d26d005..d6ab330b13 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 @@ -10,7 +10,14 @@ pub static mut shared_0: std::cell::LazyCell = std::cell::LazyCell::new(|| pub static mut calls_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p3_2_static_member_is_ordinary_pointer_HasStaticMembers {} impl p3_2_static_member_is_ordinary_pointer_HasStaticMembers { @@ -31,7 +38,14 @@ pub unsafe fn test_2() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { pub base: i32, @@ -59,7 +73,14 @@ pub unsafe fn test_3() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { pub value: i32, 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 8dec3dac8e..947947aa82 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.cond.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.cond.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p7_4_pointer_to_member_and_null_HasTwoInts { 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 e6c1918807..0b27916dfc 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.eq.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.eq.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p4_1_both_null_HasTwoInts { @@ -23,7 +32,16 @@ pub fn test_0() { assert!(!(first_null != second_null)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p4_2_one_null_HasTwoInts { @@ -40,7 +58,15 @@ pub fn test_1() { assert!((null_pm != first_pm)); assert!(!(null_pm == first_pm)); } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(4)] pub struct p4_5_members_of_same_union_HasTwoIntMembers { #[offset(0)] @@ -70,7 +96,16 @@ pub fn test_2() { assert!(!(first_pm != second_pm)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p4_6_data_members_HasTwoInts { 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 6b5d7fe003..f17758846e 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 @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct HasTwoInts { 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 0b63569205..e6f7aebe5f 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 @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p3_arrow_star_HasTwoInts { @@ -30,7 +39,16 @@ pub fn test_0() { assert!((((p).member::(pm)) == ((p).member::(pm)))); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct p4_object_expression_sequenced_first_HasValue { @@ -74,7 +92,16 @@ pub fn test_7() { assert!((member_stamp_3.with(|rc| *rc.borrow()) == 2)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { @@ -110,6 +137,7 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Destructible, CopyAssignable, MoveAssignable, @@ -153,6 +181,7 @@ impl Clone for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Destructible, Memberwise, CopyAssignable, 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 4663247295..7b98a029f5 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.cond.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.cond.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p7_4_pointer_to_member_and_null_HasTwoInts { pub first: i32, 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 9bd05e74e7..07b22b6a6d 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.eq.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.eq.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p4_1_both_null_HasTwoInts { pub first: i32, @@ -22,7 +29,14 @@ pub unsafe fn test_0() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p4_2_one_null_HasTwoInts { pub first: i32, @@ -37,7 +51,15 @@ pub unsafe fn test_1() { assert!(!((null_pm) == (first_pm))); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union p4_5_members_of_same_union_HasTwoIntMembers { pub first: i32, pub second: i32, @@ -55,7 +77,14 @@ pub unsafe fn test_2() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p4_6_data_members_HasTwoInts { pub first: i32, 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 0ccbfbc21f..5a6c15a91a 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct HasTwoInts { pub first: i32, 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 7b774d73ec..6948a5a22d 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p3_arrow_star_HasTwoInts { pub first: i32, @@ -34,7 +41,14 @@ pub unsafe fn test_0() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p4_object_expression_sequenced_first_HasValue { pub value: i32, @@ -70,7 +84,14 @@ pub unsafe fn test_7() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { pub first: i32, @@ -104,6 +125,7 @@ pub static mut moveCount_10: std::cell::LazyCell = std::cell::LazyCell::new VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, @@ -146,6 +168,7 @@ impl Clone for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, MemberwiseUnsafe, CopyAssignableUnsafe, 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 2e54a73cc6..e81ffa1ea9 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 @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, TriviallyCopyable, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + DefaultConstructible, + TriviallyCopyable, )] #[cpp_from(i32, construct, value)] #[byte_size(16)] @@ -38,6 +46,7 @@ pub fn test_0() { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] 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 f354f67d38..a35dd69c28 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, TriviallyCopyableUnsafe, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, )] #[cpp_from(i32, construct, value)] pub struct p1_default_member_initializer_names_object_Holder { @@ -43,6 +50,7 @@ pub unsafe fn test_0() { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] 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 e5ee0965ec..31cf739d9f 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 @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int___rebind_std_pair_const_int__int__ {} @@ -17,6 +26,11 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { #[offset(0)] pub id: i32, } +impl DefaultConstructible for p16_rebind_member_Alloc_std_pair_const_int__int__ { + fn default_constructor(this: &Ptr) { + field!((*this), id).write(0); + } +} impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { fn default() -> Self { { p16_rebind_member_Alloc_std_pair_const_int__int__ { id: 0 } } @@ -46,7 +60,16 @@ pub fn test_0() { assert!(({ ((*n.borrow()).len() == 1_usize) })); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p18_rebind_to_container_node_Alloc_std_pair_const_int__int__ {} 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 b6827e40a8..24bd0567b2 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 @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p16_rebind_member_Alloc_std_pair_const_int__int___rebind_std_pair_const_int__int__ {} #[repr(C)] @@ -16,6 +23,11 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int___rebind_std_pair_con pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { pub id: i32, } +impl DefaultConstructibleUnsafe for p16_rebind_member_Alloc_std_pair_const_int__int__ { + unsafe fn default_constructor(&mut self) { + (&raw mut self.id).write(0); + } +} impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { fn default() -> Self { unsafe { p16_rebind_member_Alloc_std_pair_const_int__int__ { id: 0 } } @@ -47,7 +59,14 @@ pub unsafe fn test_0() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p18_rebind_to_container_node_Alloc_std_pair_const_int__int__ {} pub unsafe fn test_1() { diff --git a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs index 30f24bee61..46a518858d 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs @@ -20,6 +20,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, + DefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -83,6 +84,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, + DefaultConstructible, Memberwise, CopyConstructible, Movable, diff --git a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs index 28f9e59dc9..6f86e43faa 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs @@ -15,6 +15,7 @@ pub static mut dtorCount_1: std::cell::LazyCell = std::cell::LazyCell::new( FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -77,6 +78,7 @@ pub static mut dtorCount_4: std::cell::LazyCell = std::cell::LazyCell::new( FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs index d29735ec5e..2c9a908f79 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs @@ -45,6 +45,12 @@ impl LifetimeTracked { }); } } +impl DefaultConstructible for LifetimeTracked { + fn default_constructor(this: &Ptr) { + field!((*this), uses).write(0); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CopyConstructible for LifetimeTracked { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), uses).write(0); @@ -72,7 +78,7 @@ impl Default for LifetimeTracked { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -89,7 +95,7 @@ pub fn test_6() { let mut choice: i32 = 9; { let guard: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&guard.as_pointer()); + DefaultConstructible::default_constructor(&guard.as_pointer()); let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); @@ -109,7 +115,7 @@ pub fn test_6() { assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); { let guard: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&guard.as_pointer()); + DefaultConstructible::default_constructor(&guard.as_pointer()); let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); @@ -207,14 +213,9 @@ fn main_0() -> i32 { return 0; } pub trait LifetimeTrackedImpl { - fn construct(&self); fn use_(&self); } impl LifetimeTrackedImpl for Ptr { - fn construct(&self) { - field!((*self), uses).write(0); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index bd0627b35e..642a65c7b5 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs @@ -45,6 +45,12 @@ impl LifetimeTracked { }); } } +impl DefaultConstructible for LifetimeTracked { + fn default_constructor(this: &Ptr) { + field!((*this), uses).write(0); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CopyConstructible for LifetimeTracked { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), uses).write(0); @@ -72,7 +78,7 @@ impl Default for LifetimeTracked { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -95,6 +101,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -157,7 +164,7 @@ pub fn test_10() { let mut selector: i32 = 9; { let guard: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::construct(&guard.as_pointer()); + DefaultConstructible::default_constructor(&guard.as_pointer()); let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); @@ -232,14 +239,9 @@ fn main_0() -> i32 { return 0; } pub trait LifetimeTrackedImpl { - fn construct(&self); fn use_(&self); } impl LifetimeTrackedImpl for Ptr { - fn construct(&self) { - field!((*self), uses).write(0); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs index 4c1c31a43f..679aebbfc6 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs @@ -29,15 +29,17 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn construct(&mut self) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - } pub unsafe fn use_(&self) { (*(&raw const self.uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for LifetimeTracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.uses).write(0); + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + } +} impl CopyConstructibleUnsafe for LifetimeTracked { unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); @@ -63,7 +65,7 @@ impl Default for LifetimeTracked { unsafe { { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -78,7 +80,7 @@ pub unsafe fn test_6() { let mut choice: i32 = 9; { let mut guard: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut guard); + DefaultConstructibleUnsafe::default_constructor(&mut guard); let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); @@ -98,7 +100,7 @@ pub unsafe fn test_6() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); { let mut guard: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut guard); + DefaultConstructibleUnsafe::default_constructor(&mut guard); let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs index 9e73cb1f6e..a483cd77f1 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs @@ -29,15 +29,17 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn construct(&mut self) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - } pub unsafe fn use_(&self) { (*(&raw const self.uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for LifetimeTracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.uses).write(0); + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + } +} impl CopyConstructibleUnsafe for LifetimeTracked { unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); @@ -63,7 +65,7 @@ impl Default for LifetimeTracked { unsafe { { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -81,6 +83,7 @@ pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new( FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -142,7 +145,7 @@ pub unsafe fn test_10() { let mut selector: i32 = 9; { let mut guard: LifetimeTracked = ::zero_init(); - LifetimeTracked::construct(&mut guard); + DefaultConstructibleUnsafe::default_constructor(&mut guard); let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); diff --git a/tests/std/temp/out/refcount/temp.type.rs b/tests/std/temp/out/refcount/temp.type.rs index c79f313bee..5309ac5b21 100644 --- a/tests/std/temp/out/refcount/temp.type.rs +++ b/tests/std/temp/out/refcount/temp.type.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p2_6_pointer_to_member_argument_HasTwoInts { @@ -20,7 +29,16 @@ thread_local!( pub static count_0: Value = Rc::new(RefCell::new(0)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_refp2_6_pointer_to_member_argument_HasTwoInts_first_ @@ -29,7 +47,16 @@ thread_local!( pub static count_1: Value = Rc::new(RefCell::new(0)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_refp2_6_pointer_to_member_argument_HasTwoInts_second_ @@ -38,7 +65,16 @@ thread_local!( pub static count_2: Value = Rc::new(RefCell::new(0)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_nullptr_ {} diff --git a/tests/std/temp/out/unsafe/temp.type.rs b/tests/std/temp/out/unsafe/temp.type.rs index bea9cdbfc9..14eacf2404 100644 --- a/tests/std/temp/out/unsafe/temp.type.rs +++ b/tests/std/temp/out/unsafe/temp.type.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_6_pointer_to_member_argument_HasTwoInts { pub first: i32, @@ -17,21 +24,42 @@ pub struct p2_6_pointer_to_member_argument_HasTwoInts { pub static mut count_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_6_pointer_to_member_argument_CountsPerMember_refp2_6_pointer_to_member_argument_HasTwoInts_first_ {} pub static mut count_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_6_pointer_to_member_argument_CountsPerMember_refp2_6_pointer_to_member_argument_HasTwoInts_second_ {} pub static mut count_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p2_6_pointer_to_member_argument_CountsPerMember_nullptr_ {} pub unsafe fn test_3() { 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 a0c1d9cc91..d4de75e7f6 100644 --- a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs @@ -12,6 +12,11 @@ pub struct p2_reference_does_not_instantiate_Member { #[offset(0)] pub value: i32, } +impl DefaultConstructible for p2_reference_does_not_instantiate_Member { + fn default_constructor(this: &Ptr) { + field!((*this), value).write(1); + } +} impl Default for p2_reference_does_not_instantiate_Member { fn default() -> Self { { p2_reference_does_not_instantiate_Member { value: 1 } } @@ -25,12 +30,19 @@ pub struct p2_reference_does_not_instantiate_Holder { #[byte_size(4)] pub member: p2_reference_does_not_instantiate_Member, } +impl DefaultConstructible for p2_reference_does_not_instantiate_Holder { + fn default_constructor(this: &Ptr) { + DefaultConstructible::default_constructor(&field_ptr!(this, member)); + } +} pub fn test_0() { - let mut holder: p2_reference_does_not_instantiate_Holder = - ::default(); - assert!((holder.member.value == 1)); - holder.member.value = 3; - assert!((holder.member.value == 3)); + let holder: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + DefaultConstructible::default_constructor(&holder.as_pointer()); + assert!(({ (*holder.borrow()).member.value } == 1)); + (*holder.borrow_mut()).member.value = 3; + assert!(({ (*holder.borrow()).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 6bc1120aca..e11b60685f 100644 --- a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs @@ -19,6 +19,11 @@ impl p2_reference_does_not_instantiate_Member { (&raw mut self.value).write(2); } } +impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Member { + unsafe fn default_constructor(&mut self) { + (&raw mut self.value).write(1); + } +} impl Default for p2_reference_does_not_instantiate_Member { fn default() -> Self { unsafe { p2_reference_does_not_instantiate_Member { value: 1 } } @@ -30,9 +35,15 @@ impl Default for p2_reference_does_not_instantiate_Member { pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } +impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Holder { + unsafe fn default_constructor(&mut self) { + DefaultConstructibleUnsafe::default_constructor(&mut self.member); + } +} pub unsafe fn test_0() { let mut holder: p2_reference_does_not_instantiate_Holder = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut holder); assert!(((holder.member.value) == (1))); holder.member.value = 3; assert!(((holder.member.value) == (3))); diff --git a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs index 449f96584a..b560e72340 100644 --- a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs @@ -108,7 +108,7 @@ pub unsafe fn test_3() { .1 .as_deref_mut() .map_or(::std::ptr::null_mut(), |v| v as *mut i32); - let mut target: (i64, Option>) = <(i64, Option>)>::default(); + let mut target: (i64, Option>) = (0_i64, None); { target = (((*&mut source.0) as i64), cpp_move_unsafe!(&mut source.1)); }; diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index aca3d2f6e6..8bb5c3e63c 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -21,7 +21,7 @@ pub fn test_0() { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, @@ -76,6 +76,11 @@ pub struct p6_forward_like_Holder { #[byte_size(4)] pub member: p6_forward_like_Movable, } +impl DefaultConstructible for p6_forward_like_Holder { + fn default_constructor(this: &Ptr) { + p6_forward_like_MovableImpl::construct(&field_ptr!(this, member), { 1 }); + } +} impl Default for p6_forward_like_Holder { fn default() -> Self { { @@ -101,7 +106,7 @@ pub fn take_2(this: Ptr, self_: Ptr = Rc::new(RefCell::new(::zero_init())); - p6_forward_like_HolderImpl::construct_1(&holder.as_pointer()); + DefaultConstructible::default_constructor(&holder.as_pointer()); let copied: Value = Rc::new(RefCell::new(::zero_init())); ({ take_1(Ptr::clone(&copied.as_pointer()), holder.as_pointer()) }); @@ -111,7 +116,9 @@ pub fn test_3() { ({ take_2(Ptr::clone(&moved.as_pointer()), holder.as_pointer()) }); assert!(({ (*moved.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 0)); } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p9_move_Movable { @@ -169,7 +176,7 @@ pub fn test_4() { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, @@ -254,7 +261,7 @@ pub fn test_7() { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, @@ -297,7 +304,7 @@ impl Clone for p11_move_if_noexcept_NoexceptMove { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, @@ -391,14 +398,6 @@ impl p11_move_if_noexcept_ThrowingMoveImpl for Ptr { - fn construct_1(&self) { - p6_forward_like_MovableImpl::construct(&field_ptr!(self, member), { 1 }); - } -} pub trait p6_forward_like_MovableImpl { fn construct(&self, value: i32); } diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index 7f4e4d2d44..864862627a 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -13,7 +13,16 @@ pub fn test_0() { assert!((source == 1)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct p9_move_trivially_copyable_Point { @@ -45,7 +54,9 @@ pub fn test_1() { assert!((points[0_usize].x == 5) && (points[0_usize].y == 6)); assert!((element.x == 5) && (element.y == 6)); } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p10_move_constructor_A { 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 78beb98f85..a5a0bb1817 100644 --- a/tests/std/utilities/utility/out/refcount/utility.as.const.rs +++ b/tests/std/utilities/utility/out/refcount/utility.as.const.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct p1_as_const_Counter { diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index 02d80b3f2f..9c200a3363 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -20,7 +20,7 @@ pub unsafe fn test_0() { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, @@ -74,8 +74,8 @@ impl Clone for p6_forward_like_Movable { pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } -impl p6_forward_like_Holder { - pub unsafe fn construct_1(&mut self) { +impl DefaultConstructibleUnsafe for p6_forward_like_Holder { + unsafe fn default_constructor(&mut self) { p6_forward_like_Movable::construct(&mut self.member, { 1 }); } } @@ -102,7 +102,7 @@ pub unsafe fn take_2(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_ } pub unsafe fn test_3() { let mut holder: p6_forward_like_Holder = ::zero_init(); - p6_forward_like_Holder::construct_1(&mut holder); + DefaultConstructibleUnsafe::default_constructor(&mut holder); let mut copied: p6_forward_like_Movable = ::zero_init(); (unsafe { take_1(&mut copied, &mut holder) }); assert!(((copied.value) == (1)) && ((holder.member.value) == (1))); @@ -111,7 +111,9 @@ pub unsafe fn test_3() { assert!(((moved.value) == (1)) && ((holder.member.value) == (0))); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, +)] #[cpp_from(i32, construct, value)] pub struct p9_move_Movable { pub value: i32, @@ -168,7 +170,7 @@ pub unsafe fn test_4() { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, @@ -244,7 +246,7 @@ pub unsafe fn test_7() { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, @@ -289,7 +291,7 @@ impl Clone for p11_move_if_noexcept_NoexceptMove { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index 77931edff5..d278478579 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -14,7 +14,14 @@ pub unsafe fn test_0() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p9_move_trivially_copyable_Point { pub x: i32, @@ -44,7 +51,9 @@ pub unsafe fn test_1() { assert!(((element.x) == (5)) && ((element.y) == (6))); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, +)] #[cpp_from(i32, construct, value)] pub struct p10_move_constructor_A { pub value: i32, 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 57fe1a564b..9e25c6649a 100644 --- a/tests/std/utilities/utility/out/unsafe/utility.as.const.rs +++ b/tests/std/utilities/utility/out/unsafe/utility.as.const.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct p1_as_const_Counter { pub value: i32, diff --git a/tests/ub/out/refcount/ctor_ref_member.rs b/tests/ub/out/refcount/ctor_ref_member.rs index 1c7a1b5590..68dafd7f6b 100644 --- a/tests/ub/out/refcount/ctor_ref_member.rs +++ b/tests/ub/out/refcount/ctor_ref_member.rs @@ -14,6 +14,7 @@ use std::rc::{Rc, Weak}; VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] diff --git a/tests/ub/out/refcount/self_referencing_initializer.rs b/tests/ub/out/refcount/self_referencing_initializer.rs index 13bfba46d5..0628392e3f 100644 --- a/tests/ub/out/refcount/self_referencing_initializer.rs +++ b/tests/ub/out/refcount/self_referencing_initializer.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct pair { diff --git a/tests/ub/out/refcount/ub6.rs b/tests/ub/out/refcount/ub6.rs index 56fd4f0be5..a6252b9b78 100644 --- a/tests/ub/out/refcount/ub6.rs +++ b/tests/ub/out/refcount/ub6.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Pair { diff --git a/tests/ub/out/unsafe/ctor_ref_member.rs b/tests/ub/out/unsafe/ctor_ref_member.rs index 0e0e52e6f6..c6052fc7b8 100644 --- a/tests/ub/out/unsafe/ctor_ref_member.rs +++ b/tests/ub/out/unsafe/ctor_ref_member.rs @@ -14,6 +14,7 @@ use std::rc::Rc; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] diff --git a/tests/ub/out/unsafe/self_referencing_initializer.rs b/tests/ub/out/unsafe/self_referencing_initializer.rs index 3a8b2f231e..cfa5cbcf96 100644 --- a/tests/ub/out/unsafe/self_referencing_initializer.rs +++ b/tests/ub/out/unsafe/self_referencing_initializer.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct pair { pub a: i32, diff --git a/tests/ub/out/unsafe/ub6.rs b/tests/ub/out/unsafe/ub6.rs index f06685299d..d1522f289f 100644 --- a/tests/ub/out/unsafe/ub6.rs +++ b/tests/ub/out/unsafe/ub6.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub x1: *mut i32, diff --git a/tests/unit/out/refcount/05_new.rs b/tests/unit/out/refcount/05_new.rs index 924b7edc4d..398bb6b1b1 100644 --- a/tests/unit/out/refcount/05_new.rs +++ b/tests/unit/out/refcount/05_new.rs @@ -7,12 +7,30 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct A {} #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct D {} diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index f51b0bce8c..0db8b537fa 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct GraphNode { @@ -18,7 +26,15 @@ pub struct GraphNode { pub next: Ptr, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Graph { @@ -35,6 +51,11 @@ pub struct Partial { #[byte_size(8)] pub p: Ptr, } +impl DefaultConstructible for Partial { + fn default_constructor(this: &Ptr) { + field!((*this), p).write(Ptr::::null()); + } +} impl Default for Partial { fn default() -> Self { { @@ -45,12 +66,29 @@ impl Default for Partial { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Declared {} #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct S { @@ -75,8 +113,9 @@ fn main_0() -> i32 { if ({ { (*it.borrow()).p.clone() } } != { arr.decay() }) { return 1; } - let mut def: Partial = ::default(); - if !((def.p).is_null()) { + let def: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&def.as_pointer()); + if !(({ (*def.borrow()).p.clone() }).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 5b4397813b..43a63d57af 100644 --- a/tests/unit/out/refcount/addr_of_global.rs +++ b/tests/unit/out/refcount/addr_of_global.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Inner { @@ -15,7 +24,15 @@ pub struct Inner { pub value: i32, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Outer { diff --git a/tests/unit/out/refcount/anonymous-struct.rs b/tests/unit/out/refcount/anonymous-struct.rs index 8ace8a102f..deaf67bd22 100644 --- a/tests/unit/out/refcount/anonymous-struct.rs +++ b/tests/unit/out/refcount/anonymous-struct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Outer_Named { @@ -17,7 +26,16 @@ pub struct Outer_Named { pub b: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct anon_0 { @@ -27,7 +45,16 @@ pub struct anon_0 { pub d: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct anon_1 { @@ -37,7 +64,16 @@ pub struct anon_1 { pub h: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct anon_2 { @@ -47,7 +83,16 @@ pub struct anon_2 { pub f: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct anon_4 { @@ -55,7 +100,16 @@ pub struct anon_4 { pub j: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct anon_5 { @@ -63,7 +117,16 @@ pub struct anon_5 { pub k: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(12)] pub struct anon_3 { @@ -77,7 +140,16 @@ pub struct anon_3 { pub anon_5: anon_5, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(44)] pub struct Outer { @@ -143,7 +215,16 @@ fn main_0() -> i32 { return 0; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct anon_6 { diff --git a/tests/unit/out/refcount/anonymous-struct_c.rs b/tests/unit/out/refcount/anonymous-struct_c.rs index 9d1ab67c4b..1edb3cd3f0 100644 --- a/tests/unit/out/refcount/anonymous-struct_c.rs +++ b/tests/unit/out/refcount/anonymous-struct_c.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Named { @@ -17,7 +26,16 @@ pub struct Named { pub b: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct anon_0 { @@ -27,7 +45,16 @@ pub struct anon_0 { pub d: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct anon_1 { @@ -37,7 +64,16 @@ pub struct anon_1 { pub h: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct anon_2 { @@ -47,7 +83,16 @@ pub struct anon_2 { pub f: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct anon_4 { @@ -55,7 +100,16 @@ pub struct anon_4 { pub j: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct anon_5 { @@ -63,7 +117,16 @@ pub struct anon_5 { pub k: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(12)] pub struct anon_3 { @@ -77,7 +140,16 @@ pub struct anon_3 { pub anon_5: anon_5, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(44)] pub struct Outer { @@ -149,7 +221,16 @@ fn main_0() -> i32 { return 0; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 26ed8c8e5e..7df4173370 100644 --- a/tests/unit/out/refcount/anonymous_enum.rs +++ b/tests/unit/out/refcount/anonymous_enum.rs @@ -13,7 +13,16 @@ pub type anon_1 = u32; pub const anon_1_SECOND_A: anon_1 = 0; pub const anon_1_SECOND_B: anon_1 = 1; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { @@ -27,7 +36,16 @@ pub type anon_2 = u32; pub const anon_2_FIELD_A: anon_2 = 0; pub const anon_2_FIELD_B: anon_2 = 1; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct WithAnonField { diff --git a/tests/unit/out/refcount/anonymous_enum_c.rs b/tests/unit/out/refcount/anonymous_enum_c.rs index dafdff28c1..c348d852a2 100644 --- a/tests/unit/out/refcount/anonymous_enum_c.rs +++ b/tests/unit/out/refcount/anonymous_enum_c.rs @@ -13,7 +13,16 @@ pub type anon_1 = u32; pub const anon_1_SECOND_A: anon_1 = 0; pub const anon_1_SECOND_B: anon_1 = 1; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { @@ -27,7 +36,16 @@ pub type anon_2 = u32; pub const anon_2_FIELD_A: anon_2 = 0; pub const anon_2_FIELD_B: anon_2 = 1; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 5270704b76..5cf0a6d7bc 100644 --- a/tests/unit/out/refcount/any.rs +++ b/tests/unit/out/refcount/any.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Point { diff --git a/tests/unit/out/refcount/array_const_init.rs b/tests/unit/out/refcount/array_const_init.rs index 2422bc4a53..4e1c28e929 100644 --- a/tests/unit/out/refcount/array_const_init.rs +++ b/tests/unit/out/refcount/array_const_init.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(20)] pub struct S { #[offset(0)] @@ -39,7 +48,16 @@ thread_local!( })); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 4786cf7a8d..0beecd6e81 100644 --- a/tests/unit/out/refcount/array_field_addr.rs +++ b/tests/unit/out/refcount/array_field_addr.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(12)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index 317bcf9bd7..62c02d5cfb 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -27,6 +27,12 @@ pub struct NonCopy { #[offset(24)] pub tag: i32, } +impl DefaultConstructible for NonCopy { + fn default_constructor(this: &Ptr) { + field!((*this), data).write(Vec::new()); + field!((*this), tag).write(0); + } +} impl Default for NonCopy { fn default() -> Self { { @@ -42,7 +48,11 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let mut arr: [NonCopy; 3] = std::array::from_fn::<_, 3, _>(|_| ::default()); + let mut arr: [NonCopy; 3] = std::array::from_fn::<_, 3, _>(|_| { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); arr[(0) as usize].tag = 7; { let __a1 = 42; diff --git a/tests/unit/out/refcount/array_reference.rs b/tests/unit/out/refcount/array_reference.rs index 722a013a49..5ff4b1c8bf 100644 --- a/tests/unit/out/refcount/array_reference.rs +++ b/tests/unit/out/refcount/array_reference.rs @@ -60,7 +60,16 @@ pub fn pick_10(s: Ptr) -> Ptr { return (s).clone(); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Point { diff --git a/tests/unit/out/refcount/as_const.rs b/tests/unit/out/refcount/as_const.rs index a8fdec8e55..cdddf6c9c4 100644 --- a/tests/unit/out/refcount/as_const.rs +++ b/tests/unit/out/refcount/as_const.rs @@ -10,7 +10,16 @@ pub type Overload = u32; pub const Overload_kMutableOverload: Overload = 1; pub const Overload_kConstOverload: Overload = 2; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/assign_rhs_first.rs b/tests/unit/out/refcount/assign_rhs_first.rs index c332364203..4f27f30445 100644 --- a/tests/unit/out/refcount/assign_rhs_first.rs +++ b/tests/unit/out/refcount/assign_rhs_first.rs @@ -16,7 +16,15 @@ pub fn advance_1() -> i32 { return 10; } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct S { diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index b5289ad4b8..b6e55f35cb 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -811,7 +811,15 @@ pub fn test_reference_members_9() { ); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Slot_6 { @@ -820,7 +828,15 @@ pub struct Slot_6 { pub value: Ptr, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Slot_8 { @@ -829,7 +845,15 @@ pub struct Slot_8 { pub value: Ptr, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Slot_10 { @@ -896,7 +920,15 @@ pub fn test_pointer_elements_11() { printf!(b"pointer increments %d %d\n", (*index.borrow()), value); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Holder_12 { @@ -932,7 +964,15 @@ pub fn test_reference_pointer_13() { ); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Node_14 { @@ -1031,7 +1071,16 @@ pub fn test_reference_subfields_18() { ); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Index_16 { @@ -1039,7 +1088,15 @@ pub struct Index_16 { pub value: u32, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Slot_17 { @@ -1048,7 +1105,16 @@ pub struct Slot_17 { pub ref_: Ptr, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(2)] pub struct Index_19 { @@ -1056,7 +1122,15 @@ pub struct Index_19 { pub value: i16, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Slot_20 { @@ -1100,7 +1174,16 @@ pub fn observe_24(mut assigned: i32, mut stored: Ptr) -> i32 { return ({ assigned } + { (stored.read()) }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct GlobalRecord_Inner { @@ -1108,7 +1191,16 @@ pub struct GlobalRecord_Inner { pub value: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct GlobalRecord { @@ -1351,7 +1443,16 @@ thread_local!( static flag_31: Value = Rc::new(RefCell::new(false)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Record_32 { @@ -1359,7 +1460,15 @@ pub struct Record_32 { pub value: i32, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Link_33 { @@ -1372,7 +1481,16 @@ thread_local!( Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct IndexedBinding {} @@ -1609,7 +1727,16 @@ thread_local!( ]))); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(12)] pub struct IndexedMember { @@ -1972,7 +2099,15 @@ thread_local!( ]))); ); #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct PointerSelector { @@ -2194,8 +2329,22 @@ pub struct Counts_59 { #[byte_size(24)] pub counts: Vec, } +impl DefaultConstructible for Counts_59 { + fn default_constructor(this: &Ptr) { + field!((*this), counts).write(Vec::new()); + } +} #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair_60 { @@ -2508,14 +2657,32 @@ fn main_0() -> i32 { return 0; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Index_62 { #[offset(0)] pub value: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(12)] pub struct Owner_63 { #[offset(0)] diff --git a/tests/unit/out/refcount/bounded_struct_ptr.rs b/tests/unit/out/refcount/bounded_struct_ptr.rs index 3de5649ccc..54fc36fef8 100644 --- a/tests/unit/out/refcount/bounded_struct_ptr.rs +++ b/tests/unit/out/refcount/bounded_struct_ptr.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Foo { diff --git a/tests/unit/out/refcount/bst.rs b/tests/unit/out/refcount/bst.rs index 8095021ce7..5cbf153e90 100644 --- a/tests/unit/out/refcount/bst.rs +++ b/tests/unit/out/refcount/bst.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(24)] pub struct node_t { diff --git a/tests/unit/out/refcount/c_struct.rs b/tests/unit/out/refcount/c_struct.rs index 1101707966..e1370c5c1b 100644 --- a/tests/unit/out/refcount/c_struct.rs +++ b/tests/unit/out/refcount/c_struct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Point { @@ -17,7 +26,16 @@ pub struct Point { pub y: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Line { @@ -29,7 +47,15 @@ pub struct Line { pub end: Point, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Node { @@ -44,7 +70,16 @@ pub const Color_RED: Color = 0; pub const Color_GREEN: Color = 1; pub const Color_BLUE: Color = 2; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Inner { @@ -54,7 +89,16 @@ pub struct Inner { pub b: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 ee1fe2634e..cbf9f35bc3 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -11,7 +11,16 @@ pub const E_A: E = 0; pub const E_B: E = 1; pub const E_C: E = 2; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { @@ -21,7 +30,16 @@ pub struct Pair { pub y: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(64)] #[byte_align(64)] @@ -29,7 +47,16 @@ pub struct Wide { #[offset(0)] pub c: i8, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(40)] pub struct Grid { #[offset(0)] @@ -78,6 +105,12 @@ pub struct Bag { #[byte_size(24)] pub items: Vec, } +impl DefaultConstructible for Bag { + fn default_constructor(this: &Ptr) { + field!((*this), n).write(0_i32); + field!((*this), items).write(Vec::new()); + } +} pub fn adjacent_arrays_0() { let a: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3, 4]))); let b: Value> = Rc::new(RefCell::new(Box::new([5, 6, 7, 8]))); @@ -347,7 +380,8 @@ 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)) })); - let b: Value = Rc::new(RefCell::new(::default())); + let b: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&b.as_pointer()); 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 65684a8a4a..33ddcd4565 100644 --- a/tests/unit/out/refcount/cast_array_to_pointer_decay.rs +++ b/tests/unit/out/refcount/cast_array_to_pointer_decay.rs @@ -16,7 +16,16 @@ pub fn strlen_1(mut s: Ptr) -> i32 { } return c; } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(12)] pub struct Row { #[offset(0)] diff --git a/tests/unit/out/refcount/class.rs b/tests/unit/out/refcount/class.rs index c0017c288d..6f965ac019 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { @@ -17,7 +26,16 @@ pub struct Pair { pub second: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Route { @@ -28,7 +46,16 @@ pub struct Route { pub cost: f64, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Counter { @@ -43,7 +70,16 @@ impl CppEq for Counter { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Tally { diff --git a/tests/unit/out/refcount/class_template_lazy_member.rs b/tests/unit/out/refcount/class_template_lazy_member.rs index e5730e47cf..59afd97391 100644 --- a/tests/unit/out/refcount/class_template_lazy_member.rs +++ b/tests/unit/out/refcount/class_template_lazy_member.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Point { @@ -15,7 +24,16 @@ pub struct Point { pub x: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Box_int_ { @@ -23,7 +41,16 @@ pub struct Box_int_ { pub val: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Box_Point_ { @@ -32,7 +59,16 @@ pub struct Box_Point_ { pub val: Point, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Deduced_int_ { @@ -40,7 +76,16 @@ pub struct Deduced_int_ { pub val: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Deduced_Point_ { diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index e0e8c740e3..7cab42315c 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -26,6 +26,11 @@ pub struct MyContainer_int_ { #[byte_size(24)] vec_: Vec, } +impl DefaultConstructible for MyContainer_int_ { + fn default_constructor(this: &Ptr) { + field!((*this), vec_).write(Vec::new()); + } +} #[derive( Clone, Record, @@ -46,6 +51,11 @@ pub struct MyContainer_char_ { #[byte_size(24)] vec_: Vec, } +impl DefaultConstructible for MyContainer_char_ { + fn default_constructor(this: &Ptr) { + field!((*this), vec_).write(Vec::new()); + } +} #[derive( Clone, Record, @@ -66,8 +76,22 @@ pub struct MyContainer_float_ { #[byte_size(24)] vec_: Vec, } +impl DefaultConstructible for MyContainer_float_ { + fn default_constructor(this: &Ptr) { + field!((*this), vec_).write(Vec::new()); + } +} #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(2)] pub struct Boxed_short_ { @@ -80,7 +104,16 @@ impl Boxed_short_ { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Boxed_int_ { @@ -93,7 +126,16 @@ impl Boxed_int_ { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Boxed_long_ { @@ -106,7 +148,16 @@ impl Boxed_long_ { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Outer_int__Inner_int_ { @@ -116,7 +167,16 @@ pub struct Outer_int__Inner_int_ { pub u: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Outer_int_ { @@ -124,7 +184,16 @@ pub struct Outer_int_ { pub v: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Outer_long__Inner_int_ { @@ -134,7 +203,16 @@ pub struct Outer_long__Inner_int_ { pub u: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Outer_long__Inner_char_ { @@ -144,7 +222,16 @@ pub struct Outer_long__Inner_char_ { pub u: i8, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Outer_long_ { @@ -152,7 +239,16 @@ pub struct Outer_long_ { pub v: i64, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Elem { @@ -206,7 +302,8 @@ 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_Impl::plus(&bl.as_pointer(), 1_i64,) }) == 8_i64)); - let imc: Value = Rc::new(RefCell::new(::default())); + let imc: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&imc.as_pointer()); assert!(({ MyContainer_int_Impl::empty(&imc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(1)); @@ -218,7 +315,8 @@ fn main_0() -> i32 { ); ({ MyContainer_int_Impl::pop_back(&imc.as_pointer()) }); assert!(({ MyContainer_int_Impl::empty(&imc.as_pointer(),) })); - let cmc: Value = Rc::new(RefCell::new(::default())); + let cmc: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&cmc.as_pointer()); assert!(({ MyContainer_char_Impl::empty(&cmc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(('a' as i8))); @@ -231,7 +329,8 @@ fn main_0() -> i32 { ); ({ MyContainer_char_Impl::pop_back(&cmc.as_pointer()) }); assert!(({ MyContainer_char_Impl::empty(&cmc.as_pointer(),) })); - let fmc: Value = Rc::new(RefCell::new(::default())); + let fmc: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&fmc.as_pointer()); assert!(({ MyContainer_float_Impl::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 8ff26fa496..936e88ed37 100644 --- a/tests/unit/out/refcount/clone_vs_move.rs +++ b/tests/unit/out/refcount/clone_vs_move.rs @@ -7,14 +7,32 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Bar { #[offset(0)] pub w: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(40)] pub struct Foo { #[offset(0)] @@ -47,7 +65,15 @@ impl Default for Foo { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Refs { diff --git a/tests/unit/out/refcount/comma_operator.rs b/tests/unit/out/refcount/comma_operator.rs index 01cfc91200..1352de2c61 100644 --- a/tests/unit/out/refcount/comma_operator.rs +++ b/tests/unit/out/refcount/comma_operator.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { diff --git a/tests/unit/out/refcount/complex_function.rs b/tests/unit/out/refcount/complex_function.rs index 17ef61eafd..c6fbbd220c 100644 --- a/tests/unit/out/refcount/complex_function.rs +++ b/tests/unit/out/refcount/complex_function.rs @@ -16,7 +16,16 @@ pub fn bar_2(x: Ptr) -> Ptr { return (x).clone(); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct X1 { @@ -24,7 +33,15 @@ pub struct X1 { pub v: i32, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct X2 { @@ -33,7 +50,15 @@ pub struct X2 { pub v: Ptr, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct X3 { @@ -42,7 +67,15 @@ pub struct X3 { pub v: Ptr, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct X4 { diff --git a/tests/unit/out/refcount/compound_assign_paren.rs b/tests/unit/out/refcount/compound_assign_paren.rs index b044d3da66..700b3a4f88 100644 --- a/tests/unit/out/refcount/compound_assign_paren.rs +++ b/tests/unit/out/refcount/compound_assign_paren.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Item { diff --git a/tests/unit/out/refcount/concepts.rs b/tests/unit/out/refcount/concepts.rs index 3791914faf..6d8bb7c121 100644 --- a/tests/unit/out/refcount/concepts.rs +++ b/tests/unit/out/refcount/concepts.rs @@ -12,7 +12,16 @@ const _: () = assert!( "sizeof(int) == 4" ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Sized {} diff --git a/tests/unit/out/refcount/constexpr_function.rs b/tests/unit/out/refcount/constexpr_function.rs index abcf1d334c..7d52dfa2b2 100644 --- a/tests/unit/out/refcount/constexpr_function.rs +++ b/tests/unit/out/refcount/constexpr_function.rs @@ -22,7 +22,16 @@ pub fn half_3(mut x: f64) -> f64 { return (x / 2_f64); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Flag { @@ -47,7 +56,16 @@ pub fn imm_7(mut b: bool) -> bool { return b; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct P { diff --git a/tests/unit/out/refcount/constructor.rs b/tests/unit/out/refcount/constructor.rs index 8cf4c9c971..ba2ca763c6 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -17,6 +17,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, + DefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -47,12 +48,20 @@ pub struct Point { #[offset(4)] pub y: i32, } +impl DefaultConstructible for Point { + fn default_constructor(this: &Ptr) { + PointImpl::construct_1(this, { 4 }); + { + field!((*this), x).with_mut(|__v| *__v = *__v + 100) + }; + } +} impl Default for Point { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct_3(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -73,7 +82,7 @@ fn main_0() -> i32 { } assert!((total_0.with(|rc| *rc.borrow()) == 18)); let p: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct_3(&p.as_pointer()); + DefaultConstructible::default_constructor(&p.as_pointer()); assert!(({ (*p.borrow()).x } == 104)); assert!(({ (*p.borrow()).y } == 50)); let q: Value = Rc::new(RefCell::new(::zero_init())); @@ -85,7 +94,6 @@ fn main_0() -> i32 { pub trait PointImpl { fn construct_2(&self, x: i32, y: i32); fn construct_1(&self, v: i32); - fn construct_3(&self); } impl PointImpl for Ptr { fn construct_2(&self, mut x: i32, mut y: i32) { @@ -98,12 +106,6 @@ impl PointImpl for Ptr { field!((*self), y).with_mut(|__v| *__v = *__v * 10) }; } - fn construct_3(&self) { - PointImpl::construct_1(self, { 4 }); - { - field!((*self), x).with_mut(|__v| *__v = *__v + 100) - }; - } } pub trait SImpl { fn const_method(&self) -> i32; diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index eee650b6ab..77daa6419f 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -13,7 +13,7 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Memberwise, CopyConstructible, CopyAssignable, diff --git a/tests/unit/out/refcount/container_field_addr.rs b/tests/unit/out/refcount/container_field_addr.rs index 6c59f17525..931646d616 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -28,6 +28,12 @@ pub struct S { #[byte_size(24)] pub v: Vec, } +impl DefaultConstructible for S { + fn default_constructor(this: &Ptr) { + field!((*this), tag).write(0_i32); + field!((*this), v).write(Vec::new()); + } +} pub fn add_0(mut v: Ptr>, mut k: i32) { { let a0_clone = k.clone(); @@ -55,10 +61,15 @@ 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(::zero_init())); + DefaultConstructible::default_constructor(&local.as_pointer()); (*local.borrow_mut()).tag = 7; ({ run_1((local.as_pointer())) }); - let mut heap: Ptr = Ptr::alloc(::default()); + let mut heap: Ptr = { + let __p = Ptr::alloc(::zero_init()); + DefaultConstructible::default_constructor(&__p); + __p + }; 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 d066554edb..45c44fe60d 100644 --- a/tests/unit/out/refcount/conversion_operator_same_translation.rs +++ b/tests/unit/out/refcount/conversion_operator_same_translation.rs @@ -15,6 +15,7 @@ use std::rc::{Rc, Weak}; VaArg, FnPtrArg, CppFrom, + TriviallyDefaultConstructible, TriviallyCopyable, Default, )] @@ -34,6 +35,7 @@ pub struct S { VaArg, FnPtrArg, CppFrom, + TriviallyDefaultConstructible, TriviallyCopyable, Default, )] diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index faf50d7ac0..47f52d2a2d 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -9,7 +9,9 @@ use std::rc::{Rc, Weak}; thread_local!( pub static assigns_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Movable, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, DefaultInitializable, Movable, Default, +)] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -52,13 +54,18 @@ pub struct NonConstAssign { #[offset(0)] pub mark: i32, } +impl DefaultConstructible for NonConstAssign { + fn default_constructor(this: &Ptr) { + field!((*this), mark).write(0); + } +} impl Default for NonConstAssign { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - NonConstAssignImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -81,6 +88,11 @@ pub struct RefQualified { #[offset(0)] pub mark: i32, } +impl DefaultConstructible for RefQualified { + fn default_constructor(this: &Ptr) { + field!((*this), mark).write(0); + } +} impl CopyAssignable for RefQualified { fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { field!((*this), mark).write((o.with(|__s| __s.mark) + 1)); @@ -92,7 +104,7 @@ impl Default for RefQualified { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefQualifiedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -105,7 +117,7 @@ impl Default for RefQualified { ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Memberwise, MoveConstructible, Swappable, @@ -143,7 +155,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, Movable, Default, @@ -176,7 +188,7 @@ impl Clone for CopyCounted { ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Memberwise, MoveConstructible, Swappable, @@ -233,6 +245,11 @@ impl CopyAssignable for ExplicitOperatorCall { return (*this).clone(); } } +impl DefaultConstructible for ExplicitOperatorCall { + fn default_constructor(this: &Ptr) { + field!((*this), w).write(Vec::new()); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -304,21 +321,21 @@ fn main_0() -> i32 { ); assert!((assigns_0.with(|rc| *rc.borrow()) == 8)); let n: Value = Rc::new(RefCell::new(::zero_init())); - NonConstAssignImpl::construct(&n.as_pointer()); + DefaultConstructible::default_constructor(&n.as_pointer()); let n1: Value = Rc::new(RefCell::new(::zero_init())); - NonConstAssignImpl::construct(&n1.as_pointer()); + DefaultConstructible::default_constructor(&n1.as_pointer()); let n2: Value = Rc::new(RefCell::new(::zero_init())); - NonConstAssignImpl::construct(&n2.as_pointer()); + DefaultConstructible::default_constructor(&n2.as_pointer()); let cn: Value = Rc::new(RefCell::new(::zero_init())); - NonConstAssignImpl::construct(&cn.as_pointer()); + DefaultConstructible::default_constructor(&cn.as_pointer()); ({ NonConstAssignImpl::operator_assign_2(&n1.as_pointer(), n.as_pointer()) }); ({ NonConstAssignImpl::operator_assign_3(&n2.as_pointer(), cn.as_pointer()) }); assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); let r: Value = Rc::new(RefCell::new(::zero_init())); - RefQualifiedImpl::construct(&r.as_pointer()); + DefaultConstructible::default_constructor(&r.as_pointer()); let r1: Value = Rc::new(RefCell::new(::zero_init())); - RefQualifiedImpl::construct(&r1.as_pointer()); + DefaultConstructible::default_constructor(&r1.as_pointer()); ({ CopyAssignable::copy_assign(&r1.as_pointer(), r.as_pointer()) }); assert!(({ (*r1.borrow()).mark } == 1)); let h2: Value = Rc::new(RefCell::new(Holder { @@ -398,8 +415,12 @@ fn main_0() -> i32 { && (array_elem!(hc1.as_pointer(), arr, 1).with(|__s| __s.v) == 6) ); assert!((copies_1.with(|rc| *rc.borrow()) == 0)); - let e1: Value = Rc::new(RefCell::new(::default())); - let e2: Value = Rc::new(RefCell::new(::default())); + let e1: Value = + Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&e1.as_pointer()); + let e2: Value = + Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&e2.as_pointer()); { let __a1 = 5; (*e1.borrow_mut()).w.push(__a1) @@ -423,14 +444,10 @@ impl CopyCountedImpl for Ptr { } } pub trait NonConstAssignImpl { - fn construct(&self); fn operator_assign_2(&self, o: Ptr) -> Ptr; fn operator_assign_3(&self, o: Ptr) -> Ptr; } impl NonConstAssignImpl for Ptr { - fn construct(&self) { - field!((*self), mark).write(0); - } fn operator_assign_2(&self, o: Ptr) -> Ptr { field!((*self), mark).write((o.with(|__s| __s.mark) + 1)); return (*self).clone(); @@ -449,14 +466,6 @@ impl PartialImpl for Ptr { field!((*self), keep).write(keep); } } -pub trait RefQualifiedImpl { - fn construct(&self); -} -impl RefQualifiedImpl for Ptr { - fn construct(&self) { - field!((*self), mark).write(0); - } -} pub fn __cpp2rust_init_globals() { let _ = assigns_0.with(|_| ()); let _ = copies_1.with(|_| ()); diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 474c83257c..6552133f34 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -16,7 +16,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, Movable, Default, @@ -59,6 +59,11 @@ pub struct NonConst { #[offset(0)] pub mark: i32, } +impl DefaultConstructible for NonConst { + fn default_constructor(this: &Ptr) { + field!((*this), mark).write(0); + } +} impl Clone for NonConst { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(NonConst { @@ -74,7 +79,7 @@ impl Default for NonConst { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - NonConstImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -87,7 +92,7 @@ impl Default for NonConst { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, Movable, Default, @@ -120,7 +125,7 @@ impl Clone for Ignored { ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Memberwise, MoveConstructible, Swappable, @@ -155,7 +160,7 @@ impl Default for Holder { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, CopyAssignable, MoveAssignable, @@ -191,7 +196,7 @@ impl Clone for Box_int_ { ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Memberwise, CopyAssignable, MoveAssignable, @@ -212,7 +217,7 @@ pub struct Owner { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, Movable, Default, @@ -244,6 +249,11 @@ pub struct Tracked { #[offset(0)] pub copied_from: i32, } +impl DefaultConstructible for Tracked { + fn default_constructor(this: &Ptr) { + field!((*this), copied_from).write(0); + } +} impl CopyConstructible for Tracked { fn copy_constructor(this: &Ptr, o: Ptr) { field!((*this), copied_from).write(0); @@ -387,21 +397,23 @@ fn main_0() -> i32 { assert!(({ (*ol2.borrow()).v } == 105)); assert!((copies_0.with(|rc| *rc.borrow()) == 12)); let n: Value = Rc::new(RefCell::new(::zero_init())); - NonConstImpl::construct(&n.as_pointer()); + DefaultConstructible::default_constructor(&n.as_pointer()); let n1: Value = Rc::new(RefCell::new(::zero_init())); NonConstImpl::construct_1(&n1.as_pointer(), { n.as_pointer() }); let cn: Value = Rc::new(RefCell::new(::zero_init())); - NonConstImpl::construct(&cn.as_pointer()); + DefaultConstructible::default_constructor(&cn.as_pointer()); let n2: Value = Rc::new(RefCell::new(::zero_init())); NonConstImpl::construct_2(&n2.as_pointer(), { cn.as_pointer() }); assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); - let t1: Value = Rc::new(RefCell::new(::default())); + let t1: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&t1.as_pointer()); let t2: Value = Rc::new(RefCell::new(::zero_init())); CopyConstructible::copy_constructor(&t2.as_pointer(), { t1.as_pointer() }); ({ CopyAssignable::copy_assign(&t2.as_pointer(), t1.as_pointer()) }); assert!(({ (*t1.borrow()).copied_from } == 2)); - let ct: Value = Rc::new(RefCell::new(::default())); + let ct: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&ct.as_pointer()); let t3: Value = Rc::new(RefCell::new(::zero_init())); CopyConstructible::copy_constructor(&t3.as_pointer(), { ct.as_pointer() }); ({ touch_1((ct.as_pointer())) }); @@ -433,14 +445,10 @@ impl IgnoredImpl for Ptr { } } pub trait NonConstImpl { - fn construct(&self); fn construct_1(&self, o: Ptr); fn construct_2(&self, o: Ptr); } impl NonConstImpl for Ptr { - fn construct(&self) { - field!((*self), mark).write(0); - } fn construct_1(&self, o: Ptr) { field!((*self), mark).write((o.with(|__s| __s.mark) + 1)); } diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index c009ee5638..fa6fbb7a29 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Inner { @@ -22,6 +31,7 @@ pub struct Inner { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, Memberwise, CopyConstructible, MoveConstructible, @@ -49,7 +59,16 @@ impl Default for Explicit { { ::zero_init() } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct Implicit { #[offset(0)] @@ -82,7 +101,7 @@ impl Default for Implicit { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, CopyConstructible, Swappable, @@ -115,7 +134,7 @@ impl MoveAssignable for DefaultCopyUserMove { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, Swappable, Default, @@ -149,7 +168,14 @@ impl Clone for UserCopyDefaultMove { } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Memberwise, Swappable, + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + CppFrom, + DefaultInitializable, + Memberwise, + Swappable, )] #[memberwise(move_constructor, move_assign)] #[cpp_from(i32, construct, value)] @@ -190,6 +216,14 @@ pub struct Owner { #[byte_size(8)] pub p: Option>, } +impl DefaultConstructible for Owner { + fn default_constructor(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); + } +} impl Default for Owner { fn default() -> Self { { @@ -222,13 +256,18 @@ pub struct Copyable { #[byte_size(24)] pub data: Vec, } +impl DefaultConstructible for Copyable { + fn default_constructor(this: &Ptr) { + field!((*this), data).write(Vec::new()); + } +} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, Swappable, Default, @@ -273,6 +312,11 @@ impl MoveAssignable for SeesThis { return (*this).clone(); } } +impl DefaultConstructible for SeesThis { + fn default_constructor(this: &Ptr) { + field!((*this), self_).write(Ptr::::null()); + } +} impl Default for SeesThis { fn default() -> Self { { @@ -293,6 +337,12 @@ pub struct HasSeesThis { #[byte_size(24)] pub v: Vec, } +impl DefaultConstructible for HasSeesThis { + fn default_constructor(this: &Ptr) { + DefaultConstructible::default_constructor(&field_ptr!(this, s)); + field!((*this), v).write(Vec::new()); + } +} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] #[byte_size(8)] pub struct Counted_int_ { @@ -301,6 +351,12 @@ pub struct Counted_int_ { #[offset(4)] pub moves: i32, } +impl DefaultConstructible for Counted_int_ { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(0_i32); + field!((*this), moves).write(0); + } +} impl MoveConstructible for Counted_int_ { fn move_constructor(this: &Ptr, o: Ptr) { field!((*this), v).write(o.with(|__s| __s.v)); @@ -332,6 +388,12 @@ pub struct HasCounted { #[byte_size(24)] pub w: Vec, } +impl DefaultConstructible for HasCounted { + fn default_constructor(this: &Ptr) { + DefaultConstructible::default_constructor(&field_ptr!(this, c)); + field!((*this), w).write(Vec::new()); + } +} #[derive( Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Swappable, )] @@ -344,6 +406,12 @@ pub struct CtorSeesThis { #[offset(8)] pub id: i32, } +impl DefaultConstructible for CtorSeesThis { + fn default_constructor(this: &Ptr) { + field!((*this), self_).write((*this).clone()); + field!((*this), id).write(0); + } +} impl CopyConstructible for CtorSeesThis { fn copy_constructor(this: &Ptr, _a0: Ptr) { field!((*this), self_).write((*this).clone()); @@ -382,7 +450,7 @@ impl Default for CtorSeesThis { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorSeesThisImpl::construct_2(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -410,6 +478,12 @@ pub struct HasCtorSeesThis { #[byte_size(24)] pub v: Vec, } +impl DefaultConstructible for HasCtorSeesThis { + fn default_constructor(this: &Ptr) { + DefaultConstructible::default_constructor(&field_ptr!(this, x)); + field!((*this), v).write(Vec::new()); + } +} #[derive( Clone, Record, @@ -431,13 +505,19 @@ pub struct InitsCtorSeesThis { #[byte_size(16)] pub y: CtorSeesThis, } +impl DefaultConstructible for InitsCtorSeesThis { + fn default_constructor(this: &Ptr) { + CtorSeesThisImpl::construct_1(&field_ptr!(this, x), { 1 }); + CtorSeesThisImpl::construct_1(&field_ptr!(this, y), { 2 }); + } +} impl Default for InitsCtorSeesThis { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - InitsCtorSeesThisImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -476,6 +556,13 @@ impl Clone for OutOfLineDefaulted { Rc::try_unwrap(__v).ok().unwrap().into_inner() } } +impl DefaultConstructible for OutOfLineDefaulted { + fn default_constructor(this: &Ptr) { + { + OutOfLineDefaultedImpl::construct(this); + } + } +} impl Default for OutOfLineDefaulted { fn default() -> Self { { @@ -501,6 +588,13 @@ pub struct OutOfLineAssign { #[byte_size(24)] pub w: Vec, } +impl DefaultConstructible for OutOfLineAssign { + fn default_constructor(this: &Ptr) { + DefaultConstructible::default_constructor(&field_ptr!(this, s)); + field!((*this), v).write(1); + field!((*this), w).write(Vec::new()); + } +} impl Default for OutOfLineAssign { fn default() -> Self { { @@ -712,7 +806,8 @@ fn main_0() -> i32 { && ((*bufs.borrow())[0_usize].data.is_empty()) }) ); - let o1: Value = Rc::new(RefCell::new(::default())); + let o1: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&o1.as_pointer()); { let __a1 = 5; (*o1.borrow_mut()).data.push(__a1) @@ -739,7 +834,8 @@ fn main_0() -> i32 { && (({ (*o1.borrow()).p.clone() }.as_pointer()).is_null()) }) ); - let o3: Value = Rc::new(RefCell::new(::default())); + let o3: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&o3.as_pointer()); ({ MoveAssignable::move_assign(&o3.as_pointer(), o2.as_pointer()) }); assert!( ((({ (*o3.borrow()).n } == 5) @@ -761,7 +857,8 @@ fn main_0() -> i32 { MoveConstructible::move_constructor(&c3.as_pointer(), { c1.as_pointer() }); assert!(({ (c2.data.len() == 2_usize) && ((*c3.borrow()).data.len() == 2_usize) })); assert!(({ (*c1.borrow()).data.is_empty() })); - let c4: Value = Rc::new(RefCell::new(::default())); + let c4: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&c4.as_pointer()); ({ MoveAssignable::move_assign(&c4.as_pointer(), c3.as_pointer()) }); assert!( ({ @@ -797,23 +894,28 @@ fn main_0() -> i32 { && (({ (*h3.borrow()).p.clone() }.as_pointer().read()) == 9)) && (({ (*h2.borrow()).p.clone() }.as_pointer()).is_null()) ); - let t1: Value = Rc::new(RefCell::new(::default())); - let t2: Value = Rc::new(RefCell::new(::default())); - let t3: Value = Rc::new(RefCell::new(::default())); + let t1: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&t1.as_pointer()); + let t2: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&t2.as_pointer()); + let t3: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&t3.as_pointer()); ({ MoveAssignable::move_assign(&t2.as_pointer(), t1.as_pointer()) }); assert!(({ { (*t2.borrow()).s.self_.clone() } } == { (field_ptr!(t2.as_pointer(), s)) })); ({ CopyAssignable::copy_assign(&t3.as_pointer(), t2.as_pointer()) }); assert!(({ { (*t3.borrow()).s.self_.clone() } } == { (field_ptr!(t3.as_pointer(), s)) })); - let k1: Value = Rc::new(RefCell::new(::default())); + let k1: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&k1.as_pointer()); let k2: Value = Rc::new(RefCell::new(::zero_init())); MoveConstructible::move_constructor(&k2.as_pointer(), { k1.as_pointer() }); assert!(({ (*k2.borrow()).c.moves } == 1)); - let k3: Value = Rc::new(RefCell::new(::default())); + let k3: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&k3.as_pointer()); ({ MoveAssignable::move_assign(&k3.as_pointer(), k2.as_pointer()) }); assert!(({ (*k3.borrow()).c.moves } == 2)); { let d: Value = Rc::new(RefCell::new(::zero_init())); - CtorSeesThisImpl::construct_2(&d.as_pointer()); + DefaultConstructible::default_constructor(&d.as_pointer()); assert!(({ { (*d.borrow()).self_.clone() } } == { (d.as_pointer()) })); let e: Value = Rc::new(RefCell::new(::zero_init())); CopyConstructible::copy_constructor(&e.as_pointer(), { d.as_pointer() }); @@ -825,7 +927,7 @@ fn main_0() -> i32 { && ({ (*f.borrow()).id } == 3) ); let h1: Value = Rc::new(RefCell::new(::zero_init())); - HasCtorSeesThisImpl::construct_1(&h1.as_pointer()); + DefaultConstructible::default_constructor(&h1.as_pointer()); assert!(({ { (*h1.borrow()).x.self_.clone() } } == { (field_ptr!(h1.as_pointer(), x)) })); let h2: Value = Rc::new(RefCell::new(::zero_init())); CopyConstructible::copy_constructor(&h2.as_pointer(), { h1.as_pointer() }); @@ -838,7 +940,7 @@ fn main_0() -> i32 { ({ CopyAssignable::copy_assign(&h2.as_pointer(), h1.as_pointer()) }); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); let i: Value = Rc::new(RefCell::new(::zero_init())); - InitsCtorSeesThisImpl::construct(&i.as_pointer()); + DefaultConstructible::default_constructor(&i.as_pointer()); assert!( ({ { (*i.borrow()).x.self_.clone() } } == { (field_ptr!(i.as_pointer(), x)) }) && ({ (*i.borrow()).x.id } == 1) @@ -871,9 +973,12 @@ fn main_0() -> i32 { ({ (*o2.borrow()).v } == 2) && ({ { (*o2.borrow()).x.self_.clone() } } == { (field_ptr!(o2.as_pointer(), x)) }) ); - let a1: Value = Rc::new(RefCell::new(::default())); - let a2: Value = Rc::new(RefCell::new(::default())); - let a3: Value = Rc::new(RefCell::new(::default())); + let a1: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&a1.as_pointer()); + let a2: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&a2.as_pointer()); + let a3: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&a3.as_pointer()); (*a1.borrow_mut()).v = 3; { let __a1 = 4; @@ -918,16 +1023,11 @@ impl BufferImpl for Ptr { } } pub trait CtorSeesThisImpl { - fn construct_2(&self); fn construct_1(&self, id: i32); } impl CtorSeesThisImpl for Ptr { - fn construct_2(&self) { - field!((*self), self_).write((*self).clone()); - field!((*self), id).write(0); - } fn construct_1(&self, mut id: i32) { - CtorSeesThisImpl::construct_2(self); + DefaultConstructible::default_constructor(self); field!((*self), id).write(id); } } @@ -949,15 +1049,6 @@ impl ExplicitImpl for Ptr { field!((*self), arr).write(Box::new([v, (v + 1)])); } } -pub trait HasCtorSeesThisImpl { - fn construct_1(&self); -} -impl HasCtorSeesThisImpl for Ptr { - fn construct_1(&self) { - CtorSeesThisImpl::construct_2(&field_ptr!(self, x)); - field!((*self), v).write(Vec::new()); - } -} pub trait HolderImpl { fn construct(&self, v: i32); } @@ -968,21 +1059,12 @@ impl HolderImpl for Ptr { field!((*self), p).write(None); } } -pub trait InitsCtorSeesThisImpl { - fn construct(&self); -} -impl InitsCtorSeesThisImpl for Ptr { - fn construct(&self) { - CtorSeesThisImpl::construct_1(&field_ptr!(self, x), { 1 }); - CtorSeesThisImpl::construct_1(&field_ptr!(self, y), { 2 }); - } -} pub trait OutOfLineDefaultedImpl { fn construct(&self); } impl OutOfLineDefaultedImpl for Ptr { fn construct(&self) { - CtorSeesThisImpl::construct_2(&field_ptr!(self, x)); + DefaultConstructible::default_constructor(&field_ptr!(self, x)); field!((*self), v).write(1); } } diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index 9f41453527..a2c9f2063b 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -7,7 +7,14 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable, Default, + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + CppFrom, + DefaultInitializable, + Swappable, + Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -34,6 +41,11 @@ pub struct PrivateCopy { #[offset(0)] pub v: i32, } +impl DefaultConstructible for PrivateCopy { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(0); + } +} impl MoveConstructible for PrivateCopy { fn move_constructor(this: &Ptr, o: Ptr) { field!((*this), v).write(o.with(|__s| __s.v)); @@ -52,7 +64,7 @@ impl Default for PrivateCopy { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PrivateCopyImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -64,19 +76,31 @@ pub struct Immovable { #[offset(0)] pub v: i32, } +impl DefaultConstructible for Immovable { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(0); + } +} impl Default for Immovable { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ImmovableImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + DefaultInitializable, + Memberwise, + Swappable, + Default, )] #[memberwise(move_constructor, move_assign)] #[byte_size(8)] @@ -97,6 +121,11 @@ pub struct VecHolder { #[byte_size(24)] pub items: Vec, } +impl DefaultConstructible for VecHolder { + fn default_constructor(this: &Ptr) { + field!((*this), items).write(Vec::new()); + } +} pub fn bump_0(mut p: Ptr) { field!(p, v).with_mut(|__v| __v.postfix_inc()); } @@ -118,7 +147,7 @@ fn main_0() -> i32 { ({ bump_0((a.as_pointer())) }); assert!(({ (*a.borrow()).v } == 2)); let p: Value = Rc::new(RefCell::new(::zero_init())); - PrivateCopyImpl::construct(&p.as_pointer()); + DefaultConstructible::default_constructor(&p.as_pointer()); (*p.borrow_mut()).v = 3; let q: Value = Rc::new(RefCell::new(::zero_init())); MoveConstructible::move_constructor(&q.as_pointer(), { p.as_pointer() }); @@ -126,7 +155,7 @@ fn main_0() -> i32 { ({ MoveAssignable::move_assign(&p.as_pointer(), q.as_pointer()) }); assert!(({ (*p.borrow()).v } == 3) && ({ (*q.borrow()).v } == 0)); let im: Value = Rc::new(RefCell::new(::zero_init())); - ImmovableImpl::construct(&im.as_pointer()); + DefaultConstructible::default_constructor(&im.as_pointer()); (*im.borrow_mut()).v = 4; ({ bump_ref_1(im.as_pointer()) }); let mut pim: Ptr = (im.as_pointer()); @@ -145,30 +174,23 @@ fn main_0() -> i32 { (({ (*d.borrow()).inner.v } == 6) && ({ (*d.borrow()).tag } == 7)) && ({ (*c.borrow()).inner.v } == 0) ); - let h: Value = Rc::new(RefCell::new(::default())); + let h: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&h.as_pointer()); let h2: Value = Rc::new(RefCell::new(::zero_init())); MoveConstructible::move_constructor(&h2.as_pointer(), { h.as_pointer() }); assert!(({ ((*h2.borrow()).items.len() == 0_usize) })); return 0; } impl CopyAssignable for PrivateCopy { - fn copy_assign(_: &Ptr, _: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, _: Ptr) -> Ptr { unreachable!("PrivateCopy::copy_assign is never defined") } } impl CopyConstructible for PrivateCopy { - fn copy_constructor(_: &Ptr, _: Ptr) { + fn copy_constructor(this: &Ptr, _: Ptr) { unreachable!("PrivateCopy::copy_constructor is never defined") } } -pub trait ImmovableImpl { - fn construct(&self); -} -impl ImmovableImpl for Ptr { - fn construct(&self) { - field!((*self), v).write(0); - } -} pub trait NoCopyImpl { fn construct(&self, v: i32); } @@ -177,12 +199,4 @@ impl NoCopyImpl for Ptr { field!((*self), v).write(v); } } -pub trait PrivateCopyImpl { - fn construct(&self); -} -impl PrivateCopyImpl for Ptr { - fn construct(&self) { - field!((*self), v).write(0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/default.rs b/tests/unit/out/refcount/default.rs index 9e96eabb62..f11e1d2ebc 100644 --- a/tests/unit/out/refcount/default.rs +++ b/tests/unit/out/refcount/default.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(144)] pub struct Pointers { #[offset(0)] @@ -43,7 +52,16 @@ impl Default for Pointers { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(440)] pub struct SmallArrays { #[offset(0)] @@ -78,7 +96,16 @@ impl Default for SmallArrays { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(132)] pub struct BigArray { #[offset(0)] diff --git a/tests/unit/out/refcount/default_function_arguments.rs b/tests/unit/out/refcount/default_function_arguments.rs index 01c5c1d526..e1a0921c83 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -21,6 +21,13 @@ pub struct Bar { #[offset(0)] pub v: i32, } +impl DefaultConstructible for Bar { + fn default_constructor(this: &Ptr) { + { + BarImpl::construct(this, { 1 }); + } + } +} impl Default for Bar { fn default() -> Self { { @@ -61,7 +68,16 @@ pub fn first_9(r: Ptr) -> i32 { return (elem!(r, 0).read()); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Holder_int_ { diff --git a/tests/unit/out/refcount/default_in_statics.rs b/tests/unit/out/refcount/default_in_statics.rs index abf994b3ed..b97707734c 100644 --- a/tests/unit/out/refcount/default_in_statics.rs +++ b/tests/unit/out/refcount/default_in_statics.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Inner { @@ -17,7 +25,16 @@ pub struct Inner { #[byte_size(8)] pub name: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(88)] pub struct Outer { #[offset(0)] @@ -64,7 +81,15 @@ impl Default for Outer { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(40)] pub struct Foo { diff --git a/tests/unit/out/refcount/delete_array_order.rs b/tests/unit/out/refcount/delete_array_order.rs index aad2b0276c..3aa1f925f8 100644 --- a/tests/unit/out/refcount/delete_array_order.rs +++ b/tests/unit/out/refcount/delete_array_order.rs @@ -13,6 +13,7 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index 67481c16d8..ca7ff9c803 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -16,6 +16,7 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -36,6 +37,7 @@ impl Destructible for S { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Destructible, Memberwise, CopyConstructible, @@ -57,6 +59,7 @@ pub struct Defaulted { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Destructible, Memberwise, CopyConstructible, @@ -79,6 +82,7 @@ pub struct Middle { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Destructible, Memberwise, CopyConstructible, @@ -101,6 +105,7 @@ pub struct Outer { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Destructible, Memberwise, CopyConstructible, @@ -132,6 +137,7 @@ impl Default for ArrayMember { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -156,6 +162,7 @@ impl Destructible for EmptyBody { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -184,6 +191,7 @@ impl Destructible for Templated_char_ { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -212,6 +220,7 @@ impl Destructible for Templated_int_ { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -242,6 +251,7 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -267,6 +277,7 @@ impl Destructible for Tagged { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Destructible, Memberwise, CopyConstructible, diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index a6a970b680..7ca26154cd 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -19,6 +19,7 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -46,7 +47,16 @@ pub fn with_default_3(s: S) -> i32 { return { (*s.borrow()).v }; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Holder { diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index a6852ad4f4..8d672240e5 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -19,6 +19,7 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -43,6 +44,7 @@ impl Destructible for S { ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Destructible, Memberwise, CopyConstructible, diff --git a/tests/unit/out/refcount/doubly_linked_list.rs b/tests/unit/out/refcount/doubly_linked_list.rs index 63273e8129..4e2e30115b 100644 --- a/tests/unit/out/refcount/doubly_linked_list.rs +++ b/tests/unit/out/refcount/doubly_linked_list.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(24)] pub struct Node { diff --git a/tests/unit/out/refcount/enum_default_in_static.rs b/tests/unit/out/refcount/enum_default_in_static.rs index 86f5e7d381..d0d934c149 100644 --- a/tests/unit/out/refcount/enum_default_in_static.rs +++ b/tests/unit/out/refcount/enum_default_in_static.rs @@ -11,7 +11,16 @@ pub const Mode_MODE_NONE: Mode = 0; pub const Mode_MODE_ONE: Mode = 1; pub const Mode_MODE_TWO: Mode = 2; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 829a40e61e..50af878240 100644 --- a/tests/unit/out/refcount/enum_int_interop.rs +++ b/tests/unit/out/refcount/enum_int_interop.rs @@ -20,7 +20,15 @@ pub const Tag_TAG_ZERO: Tag = 0; pub const Tag_TAG_ONE: Tag = 1; pub const Tag_TAG_TWO: Tag = 2; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Entry { diff --git a/tests/unit/out/refcount/enum_int_interop_c.rs b/tests/unit/out/refcount/enum_int_interop_c.rs index 42305144b2..d56a7cf2be 100644 --- a/tests/unit/out/refcount/enum_int_interop_c.rs +++ b/tests/unit/out/refcount/enum_int_interop_c.rs @@ -20,7 +20,15 @@ pub const Tag_enum_TAG_ZERO: Tag_enum = 0; pub const Tag_enum_TAG_ONE: Tag_enum = 1; pub const Tag_enum_TAG_TWO: Tag_enum = 2; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 44956ab035..b4a52f1c63 100644 --- a/tests/unit/out/refcount/enum_underlying_type.rs +++ b/tests/unit/out/refcount/enum_underlying_type.rs @@ -31,6 +31,11 @@ pub struct HoldsEmpty { #[offset(0)] pub e: Empty, } +impl DefaultConstructible for HoldsEmpty { + fn default_constructor(this: &Ptr) { + field!((*this), e).write(::default()); + } +} impl Default for HoldsEmpty { fn default() -> Self { { @@ -71,10 +76,11 @@ fn main_0() -> i32 { let mut sc: Scoped = Scoped_NEG; assert!(((sc as i32) == -2_i32)); assert!((((Scoped_POS as i8) as i32) == 2)); - let mut he: HoldsEmpty = ::default(); - assert!(!(he.e)); + let he: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&he.as_pointer()); + assert!(!({ (*he.borrow()).e })); let mut ev: Empty = ::default(); - assert!(((ev as i32) == (he.e as i32))); + assert!(((ev as i32) == ({ (*he.borrow()).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 d032496993..af35f930f7 100644 --- a/tests/unit/out/refcount/exprs.rs +++ b/tests/unit/out/refcount/exprs.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct X { @@ -15,7 +24,15 @@ pub struct X { pub x: i32, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Y { diff --git a/tests/unit/out/refcount/fft.rs b/tests/unit/out/refcount/fft.rs index 0c940fbdac..55acde50d1 100644 --- a/tests/unit/out/refcount/fft.rs +++ b/tests/unit/out/refcount/fft.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Complex { diff --git a/tests/unit/out/refcount/field_aliasing.rs b/tests/unit/out/refcount/field_aliasing.rs index f4137d0e56..7e17c2ef68 100644 --- a/tests/unit/out/refcount/field_aliasing.rs +++ b/tests/unit/out/refcount/field_aliasing.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct In { @@ -16,7 +25,16 @@ pub struct In { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(32)] pub struct S { #[offset(0)] @@ -44,7 +62,15 @@ impl Default for S { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 9127c29598..810952eb44 100644 --- a/tests/unit/out/refcount/field_array_elem_ptr.rs +++ b/tests/unit/out/refcount/field_array_elem_ptr.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Point { @@ -16,7 +25,16 @@ pub struct Point { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(48)] pub struct Shape { #[offset(0)] diff --git a/tests/unit/out/refcount/field_method_receiver.rs b/tests/unit/out/refcount/field_method_receiver.rs index d41c773bed..6733ac4975 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Counter { @@ -42,6 +51,18 @@ pub struct S { #[byte_size(24)] pub v: Vec, } +impl DefaultConstructible for S { + fn default_constructor(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()); + } +} impl Default for S { fn default() -> Self { { diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index a92ec2bf84..73093a856e 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(12)] pub struct Inner { #[offset(0)] @@ -27,7 +36,16 @@ impl Default for Inner { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Header { @@ -71,6 +89,16 @@ pub struct Outer { #[array_len(4)] pub buf: Box<[i32]>, } +impl DefaultConstructible for Outer { + fn default_constructor(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::>()); + } +} impl Default for Outer { fn default() -> Self { { diff --git a/tests/unit/out/refcount/field_pointers_malloced_struct.rs b/tests/unit/out/refcount/field_pointers_malloced_struct.rs index 4116a4be0d..351fee566e 100644 --- a/tests/unit/out/refcount/field_pointers_malloced_struct.rs +++ b/tests/unit/out/refcount/field_pointers_malloced_struct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(12)] pub struct S { diff --git a/tests/unit/out/refcount/field_reinterpret_write_through.rs b/tests/unit/out/refcount/field_reinterpret_write_through.rs index 63f42705c9..d4a33fd864 100644 --- a/tests/unit/out/refcount/field_reinterpret_write_through.rs +++ b/tests/unit/out/refcount/field_reinterpret_write_through.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct In { @@ -16,7 +25,16 @@ pub struct In { #[offset(4)] pub b: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(40)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index 6127f973e3..2c33f3e67e 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct P { 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 1b46246e21..dedbeb550e 100644 --- a/tests/unit/out/refcount/first_field_ptr_covers_struct.rs +++ b/tests/unit/out/refcount/first_field_ptr_covers_struct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct In { @@ -17,7 +26,16 @@ pub struct In { pub b: i16, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 5a666356f0..2ae2ba0ab5 100644 --- a/tests/unit/out/refcount/first_member_downcast.rs +++ b/tests/unit/out/refcount/first_member_downcast.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct base { @@ -15,7 +24,16 @@ pub struct base { pub kind: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 ddbc62be30..9cc982b938 100644 --- a/tests/unit/out/refcount/flex_array_member_incomplete.rs +++ b/tests/unit/out/refcount/flex_array_member_incomplete.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(4)] pub struct F { #[offset(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 4adacb075a..6e100bd2cf 100644 --- a/tests/unit/out/refcount/flex_array_member_sibling_write.rs +++ b/tests/unit/out/refcount/flex_array_member_sibling_write.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -27,7 +36,16 @@ impl Default for S { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct E { @@ -36,7 +54,16 @@ pub struct E { #[offset(4)] pub w: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct T { #[offset(0)] diff --git a/tests/unit/out/refcount/fn_ptr.rs b/tests/unit/out/refcount/fn_ptr.rs index 701d0c6524..12e5956a60 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -36,6 +36,7 @@ pub fn identity_hash_6(mut v: bool) -> usize { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] diff --git a/tests/unit/out/refcount/fn_ptr_cast.rs b/tests/unit/out/refcount/fn_ptr_cast.rs index 4dc050e5b3..5a0f58991f 100644 --- a/tests/unit/out/refcount/fn_ptr_cast.rs +++ b/tests/unit/out/refcount/fn_ptr_cast.rs @@ -25,7 +25,15 @@ pub fn test_double_cast_2() { assert!(({ (fn2).clone() } == { (fn_).clone() })); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Command { diff --git a/tests/unit/out/refcount/fn_ptr_stable_sort.rs b/tests/unit/out/refcount/fn_ptr_stable_sort.rs index 37e1c2b3b5..0bac0bb413 100644 --- a/tests/unit/out/refcount/fn_ptr_stable_sort.rs +++ b/tests/unit/out/refcount/fn_ptr_stable_sort.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Item { diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index 6002dc10e4..128d7d2399 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Handler { @@ -24,7 +32,16 @@ pub fn negate_1(mut x: i32) -> i32 { return -x; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct S {} @@ -39,7 +56,9 @@ impl S { return (x + 3); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct MoveOnly { diff --git a/tests/unit/out/refcount/fn_ptr_typedef_cast.rs b/tests/unit/out/refcount/fn_ptr_typedef_cast.rs index c65724388e..ee141633e2 100644 --- a/tests/unit/out/refcount/fn_ptr_typedef_cast.rs +++ b/tests/unit/out/refcount/fn_ptr_typedef_cast.rs @@ -19,7 +19,16 @@ pub fn via_size_t_return_3(mut b: u64) -> usize { return (b as usize); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 191b4b8b12..d7b6cf703b 100644 --- a/tests/unit/out/refcount/fn_ptr_vtable.rs +++ b/tests/unit/out/refcount/fn_ptr_vtable.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(24)] pub struct Vtable { diff --git a/tests/unit/out/refcount/fn_ref.rs b/tests/unit/out/refcount/fn_ref.rs index cf5f330954..ed88a34c1b 100644 --- a/tests/unit/out/refcount/fn_ref.rs +++ b/tests/unit/out/refcount/fn_ref.rs @@ -22,7 +22,15 @@ pub fn call_forwarded_4(f: FnPtr i32>, mut x: i32) -> i32 { return ({ f.call(x) }); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Holder { diff --git a/tests/unit/out/refcount/for_body_destructor.rs b/tests/unit/out/refcount/for_body_destructor.rs index a9fa542be7..77f04c5001 100644 --- a/tests/unit/out/refcount/for_body_destructor.rs +++ b/tests/unit/out/refcount/for_body_destructor.rs @@ -13,6 +13,7 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index f11222b3c3..becc3fb3a8 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -28,12 +28,19 @@ pub struct S { #[offset(24)] pub a: i32, } +impl DefaultConstructible for S { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(Vec::new()); + field!((*this), a).write(0_i32); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let s: Value = Rc::new(RefCell::new(::default())); + let s: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&s.as_pointer()); { let __a1 = 1; (*s.borrow_mut()).v.push(__a1) diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index 05b14668b6..63950f5e66 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -16,7 +16,7 @@ pub const Overload_kRvalueOverload: Overload = 2; VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, @@ -73,7 +73,7 @@ pub fn chosen_overload_1(_a0: Ptr) -> Overload { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, CopyAssignable, MoveAssignable, diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index b59e3838aa..7b95593c29 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -16,7 +16,7 @@ pub const Overload_kRvalueOverload: Overload = 2; VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index b26735659d..e0edf48c4c 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -18,7 +18,7 @@ pub const Overload_kIntRvalueOverload: Overload = 4; VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index 78e555afc0..b651ba2883 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -18,7 +18,7 @@ pub const Overload_kIntRvalueOverload: Overload = 4; VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, @@ -116,7 +116,7 @@ pub fn forward_pack_7( ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Memberwise, CopyAssignable, MoveAssignable, diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index 815a0be998..be8d73196f 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -19,7 +19,16 @@ pub fn scaled_3(v: Ptr, mut k: f64) -> f64 { return ({ (v.with(|__s| __s.x) as f64) } * { k }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct V { @@ -35,7 +44,16 @@ pub fn get_4(w: Ptr) -> i32 { return w.with(|__s| __s.x); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct W_int_ { @@ -46,7 +64,16 @@ pub fn get_5(w: Ptr) -> i64 { return w.with(|__s| __s.x); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct W_long_ { @@ -54,7 +81,16 @@ pub struct W_long_ { pub x: i64, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct D { diff --git a/tests/unit/out/refcount/function_overloading.rs b/tests/unit/out/refcount/function_overloading.rs index 6cc0887eb8..36a73a6ce5 100644 --- a/tests/unit/out/refcount/function_overloading.rs +++ b/tests/unit/out/refcount/function_overloading.rs @@ -22,7 +22,16 @@ pub fn bar_4(x: Ptr) -> i32 { return (x.read()); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Foo {} diff --git a/tests/unit/out/refcount/global_call_temporaries.rs b/tests/unit/out/refcount/global_call_temporaries.rs index 8a0fd53eb7..730dd447c5 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -95,7 +95,16 @@ thread_local!( })); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Item { diff --git a/tests/unit/out/refcount/global_init_side_effect.rs b/tests/unit/out/refcount/global_init_side_effect.rs index e93ba19d93..3372d4a4cb 100644 --- a/tests/unit/out/refcount/global_init_side_effect.rs +++ b/tests/unit/out/refcount/global_init_side_effect.rs @@ -18,6 +18,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index b9ca793e92..4969644ed1 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -38,12 +38,17 @@ pub struct Ctor { #[offset(0)] pub v: i32, } +impl DefaultConstructible for Ctor { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(({ next_0() })); + } +} impl Default for Ctor { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorImpl::construct_1(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -52,14 +57,14 @@ impl Default for Ctor { thread_local!( pub static default_ctor_7: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorImpl::construct_1(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); thread_local!( pub static arg_ctor_8: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorImpl::construct_2(&__v.as_pointer(), { 7 }); + CtorImpl::construct_1(&__v.as_pointer(), { 7 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -73,12 +78,21 @@ thread_local!( thread_local!( pub static inline_member_11: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorImpl::construct_2(&__v.as_pointer(), { 5 }); + CtorImpl::construct_1(&__v.as_pointer(), { 5 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Holder {} @@ -94,7 +108,7 @@ thread_local!( thread_local!( static local_ctor_14: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorImpl::construct_2(&__v.as_pointer(), { 3 }); + CtorImpl::construct_1(&__v.as_pointer(), { 3 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -109,12 +123,17 @@ impl Singleton { return s_15.with(|v| v.as_pointer()); } } +impl DefaultConstructible for Singleton { + fn default_constructor(this: &Ptr) { + field!((*this), hits).write(0); + } +} impl Default for Singleton { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - SingletonImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -123,7 +142,7 @@ impl Default for Singleton { thread_local!( static s_15: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - SingletonImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -171,25 +190,13 @@ fn main_0() -> i32 { return 0; } pub trait CtorImpl { - fn construct_1(&self); - fn construct_2(&self, x: i32); + fn construct_1(&self, x: i32); } impl CtorImpl for Ptr { - fn construct_1(&self) { - field!((*self), v).write(({ next_0() })); - } - fn construct_2(&self, mut x: i32) { + fn construct_1(&self, mut x: i32) { field!((*self), v).write(x); } } -pub trait SingletonImpl { - fn construct(&self); -} -impl SingletonImpl for Ptr { - fn construct(&self) { - field!((*self), hits).write(0); - } -} pub fn __cpp2rust_init_globals() { let _ = signature_3.with(|_| ()); let _ = single_4.with(|_| ()); diff --git a/tests/unit/out/refcount/global_pointers.rs b/tests/unit/out/refcount/global_pointers.rs index 7a522bc748..6d36fe5e09 100644 --- a/tests/unit/out/refcount/global_pointers.rs +++ b/tests/unit/out/refcount/global_pointers.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Entry { diff --git a/tests/unit/out/refcount/global_without_initializer.rs b/tests/unit/out/refcount/global_without_initializer.rs index b2b979c7da..021b71d9a2 100644 --- a/tests/unit/out/refcount/global_without_initializer.rs +++ b/tests/unit/out/refcount/global_without_initializer.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/goto_aggregate_default.rs b/tests/unit/out/refcount/goto_aggregate_default.rs index b8386b1071..e42b37f3b9 100644 --- a/tests/unit/out/refcount/goto_aggregate_default.rs +++ b/tests/unit/out/refcount/goto_aggregate_default.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 e367f14245..72d277e6a2 100644 --- a/tests/unit/out/refcount/goto_cleanup.rs +++ b/tests/unit/out/refcount/goto_cleanup.rs @@ -77,7 +77,15 @@ pub fn from_switch_2(mut n: i32) -> i32 { panic!("ub: non-void function does not return a value") } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 3331ded53d..48c9782dee 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(24)] pub struct MinHeapNode { @@ -61,6 +69,15 @@ pub struct MinHeap { #[byte_size(8)] pub alloc: Option>>, } +impl DefaultConstructible for MinHeap { + fn default_constructor(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); + } +} pub fn AllocMinHeap_1(mut capacity: i32) -> Option> { let mut minHeap: Option> = Some(Rc::new(RefCell::new(MinHeap { size: 0, 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 f91f095afb..32f82f427e 100644 --- a/tests/unit/out/refcount/immutable-deref-on-func-call.rs +++ b/tests/unit/out/refcount/immutable-deref-on-func-call.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Item { diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index 0ea580ff68..2416d2bca3 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -26,6 +26,11 @@ pub struct Holder { #[byte_size(24)] pub v: Vec, } +impl DefaultConstructible for Holder { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(Vec::new()); + } +} pub fn write_through_0(mut p: Ptr) { p.write(42); } @@ -46,7 +51,8 @@ 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); - let h: Value = Rc::new(RefCell::new(::default())); + let h: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&h.as_pointer()); { let __a1 = 40; (*h.borrow_mut()).v.push(__a1) diff --git a/tests/unit/out/refcount/in_class_field_initializer.rs b/tests/unit/out/refcount/in_class_field_initializer.rs index a37982771b..7dd361a93b 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.rs @@ -14,6 +14,12 @@ pub struct Inner { #[offset(4)] pub y: i32, } +impl DefaultConstructible for Inner { + fn default_constructor(this: &Ptr) { + field!((*this), x).write(3); + field!((*this), y).write(4); + } +} impl Default for Inner { fn default() -> Self { { Inner { x: 3, y: 4 } } @@ -33,6 +39,14 @@ pub struct S { #[byte_size(8)] pub d: Inner, } +impl DefaultConstructible for S { + fn default_constructor(this: &Ptr) { + field!((*this), a).write(1); + field!((*this), b).write(2_i8); + field!((*this), c).write(::default()); + DefaultConstructible::default_constructor(&field_ptr!(this, d)); + } +} impl Default for S { fn default() -> Self { { @@ -45,7 +59,17 @@ impl Default for S { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, +)] #[byte_size(8)] pub struct Boxed_int_ { #[offset(0)] @@ -63,13 +87,14 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let mut s: S = ::default(); - assert!((s.a == 1)); - assert!(((s.b as i32) == 2)); - assert!((s.c.x == 3)); - assert!((s.c.y == 4)); - assert!((s.d.x == 3)); - assert!((s.d.y == 4)); + let s: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&s.as_pointer()); + assert!(({ (*s.borrow()).a } == 1)); + assert!((({ (*s.borrow()).b } as i32) == 2)); + assert!(({ (*s.borrow()).c.x } == 3)); + assert!(({ (*s.borrow()).c.y } == 4)); + assert!(({ (*s.borrow()).d.x } == 3)); + assert!(({ (*s.borrow()).d.y } == 4)); let boxed: Value = Rc::new(RefCell::new(::zero_init())); Boxed_int_Impl::construct(&boxed.as_pointer(), { 5 }, { 9 }); assert!(({ (*boxed.borrow()).v } == 5)); diff --git a/tests/unit/out/refcount/init.rs b/tests/unit/out/refcount/init.rs index e0b31f7990..af6248358f 100644 --- a/tests/unit/out/refcount/init.rs +++ b/tests/unit/out/refcount/init.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct X { diff --git a/tests/unit/out/refcount/init_list.rs b/tests/unit/out/refcount/init_list.rs index 10c1f8308c..b143917b21 100644 --- a/tests/unit/out/refcount/init_list.rs +++ b/tests/unit/out/refcount/init_list.rs @@ -10,7 +10,16 @@ pub fn f_0(list: Vec) { let list: Value> = Rc::new(RefCell::new(list)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { @@ -26,6 +35,11 @@ pub struct Holder { #[byte_size(8)] pub p: Pair, } +impl DefaultConstructible for Holder { + fn default_constructor(this: &Ptr) { + field!((*this), p).write(Pair { a: 0, b: 0 }); + } +} impl Default for Holder { fn default() -> Self { { @@ -44,6 +58,11 @@ pub struct Seven { #[offset(0)] pub v: i32, } +impl DefaultConstructible for Seven { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(7); + } +} impl Default for Seven { fn default() -> Self { { Seven { v: 7 } } @@ -62,7 +81,8 @@ fn main_0() -> i32 { let mut vec_: Vec = Vec::from([1, 2, 3]); ({ f_0(Vec::from([1, 2, 3, 4])) }); let p: Value = Rc::new(RefCell::new(Pair { a: 1, b: 2 })); - let h: Value = Rc::new(RefCell::new(::default())); + let h: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&h.as_pointer()); ({ HolderImpl::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)); diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 3cd1dc735a..9e363fbfcf 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -31,6 +31,13 @@ pub struct Elem { #[byte_size(24)] pub coeffs: Vec, } +impl DefaultConstructible for Elem { + fn default_constructor(this: &Ptr) { + field!((*this), id).write(0_i32); + field!((*this), hist).write((0..4).map(|_| 0_i32).collect::>()); + field!((*this), coeffs).write(Vec::new()); + } +} impl Default for Elem { fn default() -> Self { { @@ -74,6 +81,21 @@ pub struct State { #[byte_size(24)] pub rows: Vec>, } +impl DefaultConstructible for State { + fn default_constructor(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()); + } +} impl Default for State { fn default() -> Self { { @@ -157,6 +179,11 @@ pub struct Counted { #[offset(0)] pub v: i32, } +impl DefaultConstructible for Counted { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(0); + } +} impl CopyConstructible for Counted { fn copy_constructor(this: &Ptr, o: Ptr) { field!((*this), v).write(o.with(|__s| __s.v)); diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index abccf8af04..c7bed88aaa 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Edge { @@ -116,6 +125,13 @@ pub struct DisjointSet { #[offset(16)] pub n: i32, } +impl DefaultConstructible for DisjointSet { + fn default_constructor(this: &Ptr) { + field!((*this), rank).write(None); + field!((*this), parent).write(None); + field!((*this), n).write(0_i32); + } +} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] @@ -130,6 +146,13 @@ pub struct Graph { #[offset(12)] pub E: i32, } +impl DefaultConstructible for Graph { + fn default_constructor(this: &Ptr) { + field!((*this), edges).write(None); + field!((*this), V).write(0_i32); + field!((*this), E).write(0_i32); + } +} pub fn MSTKruskal_2(graph: Ptr) -> f64 { ({ quicksort_1(field_ptr!(graph, edges), 0, (graph.with(|__s| __s.E) - 1)) }); let set: Value = Rc::new(RefCell::new(DisjointSet { diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index ca3165a8b4..8ed627fda3 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -13,6 +13,7 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, + TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, @@ -40,7 +41,17 @@ impl Default for Guard__lambda_at_lambda_as_field_cpp_34_13__ { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { #[offset(0)] @@ -52,7 +63,16 @@ impl Destructible for Guard__lambda_at_lambda_as_field_cpp_45_13__ { ({ (*(*this).upgrade().deref()).f.call() }); } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { #[offset(0)] @@ -76,7 +96,15 @@ impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { @@ -86,7 +114,7 @@ pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { #[offset(4)] pub calls: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable)] #[cpp_from(FnPtr i32 > , construct, value)] #[byte_size(8)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 8dca0a91ce..fd30292c1b 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -24,6 +24,12 @@ pub struct Counted { #[offset(4)] pub moves: i32, } +impl DefaultConstructible for Counted { + fn default_constructor(this: &Ptr) { + field!((*this), copies).write(0); + field!((*this), moves).write(0); + } +} impl CopyConstructible for Counted { fn copy_constructor(this: &Ptr, o: Ptr) { field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); @@ -52,7 +58,7 @@ impl Default for Counted { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,6 +72,9 @@ thread_local!( )] #[byte_size(1)] pub struct Dropped {} +impl DefaultConstructible for Dropped { + fn default_constructor(this: &Ptr) {} +} impl CopyConstructible for Dropped { fn copy_constructor(this: &Ptr, _a0: Ptr) {} } @@ -90,7 +99,7 @@ impl Default for Dropped { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DroppedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -102,7 +111,7 @@ pub fn main() { } fn main_0() -> i32 { let c: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::construct(&c.as_pointer()); + DefaultConstructible::default_constructor(&c.as_pointer()); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let c: Value = Rc::new(RefCell::new({ @@ -150,7 +159,7 @@ fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 2, _>(|_| { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); @@ -182,7 +191,7 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DroppedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -200,7 +209,7 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DroppedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -218,7 +227,7 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DroppedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -241,21 +250,6 @@ fn main_0() -> i32 { assert!((drops_0.with(|rc| *rc.borrow()) == 6)); return 0; } -pub trait CountedImpl { - fn construct(&self); -} -impl CountedImpl for Ptr { - fn construct(&self) { - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} -pub trait DroppedImpl { - fn construct(&self); -} -impl DroppedImpl for Ptr { - fn construct(&self) {} -} pub fn __cpp2rust_init_globals() { let _ = drops_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/lambda_capture_ref.rs b/tests/unit/out/refcount/lambda_capture_ref.rs index 03a59eddea..6eb83999c3 100644 --- a/tests/unit/out/refcount/lambda_capture_ref.rs +++ b/tests/unit/out/refcount/lambda_capture_ref.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct S { diff --git a/tests/unit/out/refcount/lambda_capture_star_this.rs b/tests/unit/out/refcount/lambda_capture_star_this.rs index e17b5a6ada..35f4e7de35 100644 --- a/tests/unit/out/refcount/lambda_capture_star_this.rs +++ b/tests/unit/out/refcount/lambda_capture_star_this.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/lambda_capture_this.rs b/tests/unit/out/refcount/lambda_capture_this.rs index 70ec2ff7c7..48cac3a0f0 100644 --- a/tests/unit/out/refcount/lambda_capture_this.rs +++ b/tests/unit/out/refcount/lambda_capture_this.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct S { diff --git a/tests/unit/out/refcount/lambda_capture_value.rs b/tests/unit/out/refcount/lambda_capture_value.rs index ace3ed41d7..dc0d6519a4 100644 --- a/tests/unit/out/refcount/lambda_capture_value.rs +++ b/tests/unit/out/refcount/lambda_capture_value.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct S { diff --git a/tests/unit/out/refcount/lambda_decltype_type.rs b/tests/unit/out/refcount/lambda_decltype_type.rs index d3eaefb6e1..860e8394c0 100644 --- a/tests/unit/out/refcount/lambda_decltype_type.rs +++ b/tests/unit/out/refcount/lambda_decltype_type.rs @@ -19,6 +19,19 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[byte_size(1)] pub cmp: FnPtr bool>, } +impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { + fn default_constructor(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); + } + }, + )); + } +} impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { fn default() -> Self { { @@ -47,6 +60,19 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { #[byte_size(1)] pub cmp: FnPtr bool>, } +impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { + fn default_constructor(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); + } + }, + )); + } +} impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { fn default() -> Self { { @@ -76,8 +102,9 @@ fn main_0() -> i32 { }, ))); let desc: Value = Rc::new(RefCell::new( - ::default(), + ::zero_init(), )); + DefaultConstructible::default_constructor(&desc.as_pointer()); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl::insert(&desc.as_pointer(), 2) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl::insert(&desc.as_pointer(), 7) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl::insert(&desc.as_pointer(), 4) }); @@ -85,8 +112,9 @@ fn main_0() -> i32 { assert!(((array_elem!(desc.as_pointer(), items, 1).read()) == 4)); assert!(((array_elem!(desc.as_pointer(), items, 2).read()) == 2)); let asc: Value = Rc::new(RefCell::new( - ::default(), + ::zero_init(), )); + DefaultConstructible::default_constructor(&asc.as_pointer()); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl::insert(&asc.as_pointer(), 2) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl::insert(&asc.as_pointer(), 7) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl::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 25f78269c9..4eb1a8cd82 100644 --- a/tests/unit/out/refcount/lambda_generic_explicit_args.rs +++ b/tests/unit/out/refcount/lambda_generic_explicit_args.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Val { diff --git a/tests/unit/out/refcount/lambda_immediate_init.rs b/tests/unit/out/refcount/lambda_immediate_init.rs index 37c42aa45d..3b67ac708b 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -17,6 +17,21 @@ pub struct S { #[offset(4)] pub k: i32, } +impl DefaultConstructible for S { + fn default_constructor(this: &Ptr) { + field!((*this), j).write(10); + field!((*this), k).write( + (({ + FnPtr:: i32>::new(|| -> i32 { + { + return 3; + } + }) + .call() + }) + 1), + ); + } +} impl Default for S { fn default() -> Self { { @@ -76,8 +91,9 @@ fn main_0() -> i32 { }) == 237) ); assert!((({ pick_0(1,) }) == 1)); - let mut s: S = ::default(); - assert!((s.k == 4)); + let s: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&s.as_pointer()); + assert!(({ (*s.borrow()).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_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index ca29059d5e..34a860c1c9 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -6,7 +6,9 @@ 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, CppFrom, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultConstructible, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(8)] pub struct Owner { diff --git a/tests/unit/out/refcount/lambda_nested.rs b/tests/unit/out/refcount/lambda_nested.rs index c53b4e3e1d..19cb26cbdb 100644 --- a/tests/unit/out/refcount/lambda_nested.rs +++ b/tests/unit/out/refcount/lambda_nested.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/lambda_static_local.rs b/tests/unit/out/refcount/lambda_static_local.rs index b790203e59..cc2b905054 100644 --- a/tests/unit/out/refcount/lambda_static_local.rs +++ b/tests/unit/out/refcount/lambda_static_local.rs @@ -79,7 +79,16 @@ thread_local!( static calls_3: Value = Rc::new(RefCell::new(0)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct P_4 { diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index a737d339ac..a24be77231 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -29,6 +29,14 @@ pub struct UserDefined { #[byte_size(24)] pub v: Vec, } +impl DefaultConstructible for UserDefined { + fn default_constructor(this: &Ptr) { + field!((*this), a).write(Box::<[i32]>::from(std::array::from_fn::<_, 1, _>(|_| { + 0_i32 + }))); + field!((*this), v).write(Vec::new()); + } +} impl Default for UserDefined { fn default() -> Self { { @@ -39,7 +47,16 @@ impl Default for UserDefined { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct FieldIsLibcType { #[offset(0)] @@ -80,7 +97,8 @@ 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))); - let ud: Value = Rc::new(RefCell::new(::default())); + let ud: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&ud.as_pointer()); 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 aa9f18a58f..eb9c1d7488 100644 --- a/tests/unit/out/refcount/linked_list.rs +++ b/tests/unit/out/refcount/linked_list.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Node { diff --git a/tests/unit/out/refcount/local_anon_struct_collision.rs b/tests/unit/out/refcount/local_anon_struct_collision.rs index 227c717c4b..54d8b3a425 100644 --- a/tests/unit/out/refcount/local_anon_struct_collision.rs +++ b/tests/unit/out/refcount/local_anon_struct_collision.rs @@ -13,7 +13,16 @@ pub fn first_0() -> i32 { return (p.x + p.y); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct anon_1 { @@ -29,7 +38,16 @@ pub fn second_2() -> i32 { return ((q.a + q.b) as i32); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 acee33e9c7..417268e98e 100644 --- a/tests/unit/out/refcount/local_record_template.rs +++ b/tests/unit/out/refcount/local_record_template.rs @@ -30,7 +30,16 @@ pub fn wrap_10(mut v: i64) -> i32 { return ({ get_6(l) }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Local_5 { @@ -38,7 +47,16 @@ pub struct Local_5 { pub x: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Local_7 { @@ -50,7 +68,16 @@ pub fn other_11() -> i32 { return (({ get_0(l) }) + (l.y as i32)); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Local_1 { @@ -73,7 +100,16 @@ fn main_0() -> i32 { return 0; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Local_3 { diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index ef7e401489..560aa8aeb7 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -23,12 +23,18 @@ pub struct Point { #[offset(4)] pub y: i32, } +impl DefaultConstructible for Point { + fn default_constructor(this: &Ptr) { + field!((*this), x).write(0); + field!((*this), y).write(0); + } +} impl Default for Point { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct_1(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -733,7 +739,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key1.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct_2(&__v.as_pointer(), { 3 }, { 4 }); + PointImpl::construct_1(&__v.as_pointer(), { 3 }, { 4 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -780,7 +786,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(({ (*key8.borrow()) }))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct_2(&__v.as_pointer(), { 5 }, { 6 }); + PointImpl::construct_1(&__v.as_pointer(), { 5 }, { 6 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -1035,15 +1041,10 @@ fn main_0() -> i32 { return 0; } pub trait PointImpl { - fn construct_1(&self); - fn construct_2(&self, x: i32, y: i32); + fn construct_1(&self, x: i32, y: i32); } impl PointImpl for Ptr { - fn construct_1(&self) { - field!((*self), x).write(0); - field!((*self), y).write(0); - } - fn construct_2(&self, mut x: i32, mut y: i32) { + fn construct_1(&self, mut x: i32, mut y: i32) { field!((*self), x).write(x); field!((*self), y).write(y); } diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index a49155dea2..89b7350153 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -22,7 +22,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index b717fbb0ae..dd7635eeaa 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -10,7 +10,16 @@ thread_local!( pub static default_constructions_0: Value = Rc::new(RefCell::new(0)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Key { @@ -41,12 +50,18 @@ pub struct Mapped { #[offset(0)] pub value: i32, } +impl DefaultConstructible for Mapped { + fn default_constructor(this: &Ptr) { + field!((*this), value).write(0); + (*default_constructions_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl Default for Mapped { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MappedImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -430,15 +445,6 @@ fn main_0() -> i32 { }; return if ok { 0 } else { 1 }; } -pub trait MappedImpl { - fn construct(&self); -} -impl MappedImpl for Ptr { - fn construct(&self) { - field!((*self), value).write(0); - (*default_constructions_0.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = default_constructions_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 1a85374413..c2be719489 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -36,6 +36,11 @@ pub struct Item { #[offset(0)] pub value: i32, } +impl DefaultConstructible for Item { + fn default_constructor(this: &Ptr) { + field!((*this), value).write(0); + } +} impl CopyConstructible for Item { fn copy_constructor(this: &Ptr, other: Ptr) { field!((*this), value).write(other.with(|__s| __s.value)); @@ -64,7 +69,7 @@ impl Default for Item { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -80,12 +85,17 @@ pub struct RefItem { #[offset(0)] pub value: i32, } +impl DefaultConstructible for RefItem { + fn default_constructor(this: &Ptr) { + field!((*this), value).write(0); + } +} impl Default for RefItem { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItemImpl::construct_1(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -554,7 +564,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItemImpl::construct_2(&__v.as_pointer(), { counter.as_pointer() }, { 5 }); + RefItemImpl::construct_1(&__v.as_pointer(), { counter.as_pointer() }, { 5 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -576,7 +586,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItemImpl::construct_2(&__v.as_pointer(), { (__tmp_10).clone() }, { + RefItemImpl::construct_1(&__v.as_pointer(), { (__tmp_10).clone() }, { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -609,7 +619,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItemImpl::construct_2(&__v.as_pointer(), { (__tmp_11).clone() }, { + RefItemImpl::construct_1(&__v.as_pointer(), { (__tmp_11).clone() }, { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -751,27 +761,19 @@ fn main_0() -> i32 { return if ok { 0 } else { 1 }; } pub trait ItemImpl { - fn construct_2(&self); fn construct_1(&self, value: i32); } impl ItemImpl for Ptr { - fn construct_2(&self) { - field!((*self), value).write(0); - } fn construct_1(&self, mut value: i32) { field!((*self), value).write(value); (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); } } pub trait RefItemImpl { - fn construct_1(&self); - fn construct_2(&self, counter: Ptr, amount: i32); + fn construct_1(&self, counter: Ptr, amount: i32); } impl RefItemImpl for Ptr { - fn construct_1(&self) { - field!((*self), value).write(0); - } - fn construct_2(&self, counter: Ptr, mut amount: i32) { + fn construct_1(&self, counter: Ptr, mut amount: i32) { field!((*self), value).write({ { counter.with_mut(|__v| *__v = *__v + amount) diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index 26fca55954..841f850e4e 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -18,12 +18,17 @@ pub struct Item { #[offset(0)] pub value: i32, } +impl DefaultConstructible for Item { + fn default_constructor(this: &Ptr) { + field!((*this), value).write(0); + } +} impl Default for Item { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -52,12 +57,19 @@ pub struct Temporary { #[array_len(2)] pub data: Box<[i32]>, } +impl DefaultConstructible for Temporary { + fn default_constructor(this: &Ptr) { + field!((*this), n).write(5); + field!((*this), data).write(Box::new([6, 7])); + (*temporary_calls_4.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl Default for Temporary { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - TemporaryImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -72,17 +84,22 @@ pub struct Nested { #[byte_size(12)] pub inner: Temporary, } +impl DefaultConstructible for Nested { + fn default_constructor(this: &Ptr) { + DefaultConstructible::default_constructor(&field_ptr!(this, inner)); + } +} pub fn make_temporary_5() -> Temporary { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - TemporaryImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn make_nested_6() -> Nested { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - NestedImpl::construct_1(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -94,12 +111,21 @@ pub struct Owner { #[byte_size(8)] pub ptr: Option>, } +impl DefaultConstructible for Owner { + fn default_constructor(this: &Ptr) { + field!((*this), ptr).write(Some(Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })))); + } +} impl Default for Owner { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - OwnerImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -111,6 +137,11 @@ pub struct Noncopy { #[offset(0)] pub n: i32, } +impl DefaultConstructible for Noncopy { + fn default_constructor(this: &Ptr) { + field!((*this), n).write(5); + } +} impl Default for Noncopy { fn default() -> Self { { Noncopy { n: 5 } } @@ -126,12 +157,17 @@ pub struct Held { #[byte_size(8)] pub ptr: Ptr, } +impl DefaultConstructible for Held { + fn default_constructor(this: &Ptr) { + field!((*this), ptr).write(Ptr::::null()); + } +} impl Default for Held { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HeldImpl::construct_2(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -247,7 +283,7 @@ thread_local!( (*{ __tmp_7 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TemporaryImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_7 @@ -342,7 +378,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer(), { counter.as_pointer() }, { 3 }); + ItemImpl::construct_1(&__v.as_pointer(), { counter.as_pointer() }, { 3 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -370,7 +406,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer(), { (__tmp_9).clone() }, { 2 }); + ItemImpl::construct_1(&__v.as_pointer(), { (__tmp_9).clone() }, { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -408,7 +444,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer(), { (__tmp_11).clone() }, { 2 }); + ItemImpl::construct_1(&__v.as_pointer(), { (__tmp_11).clone() }, { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -443,7 +479,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer(), { (__tmp_13).clone() }, { 2 }); + ItemImpl::construct_1(&__v.as_pointer(), { (__tmp_13).clone() }, { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -479,7 +515,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer(), { (__tmp_16).clone() }, { 2 }); + ItemImpl::construct_1(&__v.as_pointer(), { (__tmp_16).clone() }, { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -524,7 +560,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer(), { (__tmp_19).clone() }, { 3 }); + ItemImpl::construct_1(&__v.as_pointer(), { (__tmp_19).clone() }, { 3 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -555,7 +591,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer(), { (__tmp_21).clone() }, { 3 }); + ItemImpl::construct_1(&__v.as_pointer(), { (__tmp_21).clone() }, { 3 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -586,7 +622,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer(), { (__tmp_24).clone() }, { 3 }); + ItemImpl::construct_1(&__v.as_pointer(), { (__tmp_24).clone() }, { 3 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -625,7 +661,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer(), { (__tmp_27).clone() }, { 3 }); + ItemImpl::construct_1(&__v.as_pointer(), { (__tmp_27).clone() }, { 3 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -666,7 +702,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer(), { (__tmp_30).clone() }, { 3 }); + ItemImpl::construct_1(&__v.as_pointer(), { (__tmp_30).clone() }, { 3 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -693,7 +729,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_2(&__v.as_pointer(), { (__tmp_33).clone() }, { 3 }); + ItemImpl::construct_1(&__v.as_pointer(), { (__tmp_33).clone() }, { 3 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -1210,7 +1246,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - ItemImpl::construct_2( + ItemImpl::construct_1( &__v.as_pointer(), { (__tmp_61).clone() }, { 2 }, @@ -1263,7 +1299,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - ItemImpl::construct_2( + ItemImpl::construct_1( &__v.as_pointer(), { (__tmp_64).clone() }, { 2 }, @@ -1316,7 +1352,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - ItemImpl::construct_2( + ItemImpl::construct_1( &__v.as_pointer(), { (__tmp_69).clone() }, { 2 }, @@ -1687,7 +1723,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - HeldImpl::construct_3( + HeldImpl::construct_2( &__v.as_pointer(), { ordinary_array.decay() }, { 0 }, @@ -1740,7 +1776,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - HeldImpl::construct_3( + HeldImpl::construct_2( &__v.as_pointer(), { (__tmp_88).clone() }, { 0 }, @@ -1809,7 +1845,7 @@ fn main_0() -> i32 { __tmp_94 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TemporaryImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_94 @@ -1846,7 +1882,7 @@ fn main_0() -> i32 { __tmp_96 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - NestedImpl::construct_1(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_96 @@ -1884,7 +1920,7 @@ fn main_0() -> i32 { __tmp_98 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TemporaryImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_98 @@ -1921,7 +1957,7 @@ fn main_0() -> i32 { __tmp_100 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TemporaryImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_100 @@ -1957,7 +1993,7 @@ fn main_0() -> i32 { __tmp_102 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TemporaryImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_102 @@ -1993,7 +2029,7 @@ fn main_0() -> i32 { __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TemporaryImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })))))); &mut __tmp_104 @@ -2097,7 +2133,9 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - TemporaryImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor( + &__v.as_pointer(), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_106 @@ -2112,7 +2150,9 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - TemporaryImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor( + &__v.as_pointer(), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_107 @@ -2182,7 +2222,9 @@ fn main_0() -> i32 { { match (({ OwnerImpl::value(&{ - OwnerImpl::construct(&__tmp_109.as_pointer()); + DefaultConstructible::default_constructor( + &__tmp_109.as_pointer(), + ); __tmp_109.as_pointer() }) }),) @@ -2255,9 +2297,11 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new({ let __tmp_111: Value>>; match ({ - __tmp_111 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - ::default(), - ))))); + __tmp_111 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))))); __tmp_111.as_pointer() },) { @@ -2293,9 +2337,11 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new({ let __tmp_113: Value>>; match ({ - __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - ::default(), - ))))); + __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))))); __tmp_113.as_pointer() },) { @@ -2448,30 +2494,22 @@ fn main_0() -> i32 { return 0; } pub trait HeldImpl { - fn construct_2(&self); fn construct_1(&self, n: Ptr); - fn construct_3(&self, n: Ptr, _a1: i32); + fn construct_2(&self, n: Ptr, _a1: i32); } impl HeldImpl for Ptr { - fn construct_2(&self) { - field!((*self), ptr).write(Ptr::::null()); - } fn construct_1(&self, n: Ptr) { field!((*self), ptr).write((n).clone()); } - fn construct_3(&self, n: Ptr, mut _a1: i32) { + fn construct_2(&self, n: Ptr, mut _a1: i32) { field!((*self), ptr).write((n).clone()); } } pub trait ItemImpl { - fn construct_1(&self); - fn construct_2(&self, counter: Ptr, amount: i32); + fn construct_1(&self, counter: Ptr, amount: i32); } impl ItemImpl for Ptr { - fn construct_1(&self) { - field!((*self), value).write(0); - } - fn construct_2(&self, counter: Ptr, mut amount: i32) { + fn construct_1(&self, counter: Ptr, mut amount: i32) { field!((*self), value).write({ { counter.with_mut(|__v| *__v = *__v + amount) @@ -2481,40 +2519,14 @@ impl ItemImpl for Ptr { (*made_0.with(Value::clone).borrow_mut()).prefix_inc(); } } -pub trait NestedImpl { - fn construct_1(&self); -} -impl NestedImpl for Ptr { - fn construct_1(&self) { - TemporaryImpl::construct(&field_ptr!(self, inner)); - } -} pub trait OwnerImpl { - fn construct(&self); fn value(&self) -> Ptr; } impl OwnerImpl for Ptr { - fn construct(&self) { - field!((*self), ptr).write(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TemporaryImpl::construct(&__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })))); - } fn value(&self) -> Ptr { return field_ptr!((*self).with(|__s| __s.ptr.clone()).as_pointer(), n); } } -pub trait TemporaryImpl { - fn construct(&self); -} -impl TemporaryImpl for Ptr { - fn construct(&self) { - field!((*self), n).write(5); - field!((*self), data).write(Box::new([6, 7])); - (*temporary_calls_4.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = made_0.with(|_| ()); let _ = visits_1.with(|_| ()); diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index b811066a87..e8ce33d371 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -27,7 +27,7 @@ pub fn pick_3(mut i: i32) -> Ptr { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, Movable, Default, diff --git a/tests/unit/out/refcount/memcpy_struct_bytes.rs b/tests/unit/out/refcount/memcpy_struct_bytes.rs index e473748993..f4bfdf8820 100644 --- a/tests/unit/out/refcount/memcpy_struct_bytes.rs +++ b/tests/unit/out/refcount/memcpy_struct_bytes.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 847ea58c9a..79f7c8cd1a 100644 --- a/tests/unit/out/refcount/memcpy_struct_layouts.rs +++ b/tests/unit/out/refcount/memcpy_struct_layouts.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct packed { @@ -21,7 +30,16 @@ pub struct packed { pub d: i16, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(12)] pub struct reordered { @@ -33,7 +51,16 @@ pub struct reordered { pub c: i8, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct tail { @@ -43,7 +70,16 @@ pub struct tail { pub b: f64, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(24)] pub struct nested { @@ -53,7 +89,16 @@ pub struct nested { #[offset(16)] pub c: i8, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(8)] pub struct array { #[offset(0)] diff --git a/tests/unit/out/refcount/memcpy_struct_struct.rs b/tests/unit/out/refcount/memcpy_struct_struct.rs index d85880c2b9..8a4c3563f7 100644 --- a/tests/unit/out/refcount/memcpy_struct_struct.rs +++ b/tests/unit/out/refcount/memcpy_struct_struct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Entry { diff --git a/tests/unit/out/refcount/memset_struct_tail.rs b/tests/unit/out/refcount/memset_struct_tail.rs index f035b8b1dc..9debd268ff 100644 --- a/tests/unit/out/refcount/memset_struct_tail.rs +++ b/tests/unit/out/refcount/memset_struct_tail.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(32)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 7cb0d1c522..f7f5ad0e73 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -7,7 +7,14 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable, Default, + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + CppFrom, + DefaultInitializable, + Swappable, + Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -37,13 +44,18 @@ pub struct ConstMoveAssign { #[offset(0)] pub mark: i32, } +impl DefaultConstructible for ConstMoveAssign { + fn default_constructor(this: &Ptr) { + field!((*this), mark).write(0); + } +} impl Default for ConstMoveAssign { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstMoveAssignImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -112,13 +124,13 @@ fn main_0() -> i32 { assert!(({ (*vec_.borrow())[0_usize].v } == 8)); assert!(({ (*d.borrow()).v } == 0)); let m: Value = Rc::new(RefCell::new(::zero_init())); - ConstMoveAssignImpl::construct(&m.as_pointer()); + DefaultConstructible::default_constructor(&m.as_pointer()); let m1: Value = Rc::new(RefCell::new(::zero_init())); - ConstMoveAssignImpl::construct(&m1.as_pointer()); + DefaultConstructible::default_constructor(&m1.as_pointer()); let m2: Value = Rc::new(RefCell::new(::zero_init())); - ConstMoveAssignImpl::construct(&m2.as_pointer()); + DefaultConstructible::default_constructor(&m2.as_pointer()); let cm: Value = Rc::new(RefCell::new(::zero_init())); - ConstMoveAssignImpl::construct(&cm.as_pointer()); + DefaultConstructible::default_constructor(&cm.as_pointer()); ({ ConstMoveAssignImpl::operator_assign_2(&m1.as_pointer(), m.as_pointer()) }); ({ ConstMoveAssignImpl::operator_assign_3(&m2.as_pointer(), cm.as_pointer()) }); assert!(({ (*m1.borrow()).mark } == 1)); @@ -126,14 +138,10 @@ fn main_0() -> i32 { return 0; } pub trait ConstMoveAssignImpl { - fn construct(&self); fn operator_assign_2(&self, o: Ptr) -> Ptr; fn operator_assign_3(&self, o: Ptr) -> Ptr; } impl ConstMoveAssignImpl for Ptr { - fn construct(&self) { - field!((*self), mark).write(0); - } fn operator_assign_2(&self, o: Ptr) -> Ptr { field!((*self), mark).write((o.with(|__s| __s.mark) + 1)); return (*self).clone(); diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index 12cd305b33..f939859150 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -6,7 +6,9 @@ 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, CppFrom, Destructible, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct MoveOnly { @@ -25,12 +27,17 @@ pub struct ConstMove { #[offset(0)] pub mark: i32, } +impl DefaultConstructible for ConstMove { + fn default_constructor(this: &Ptr) { + field!((*this), mark).write(0); + } +} impl Default for ConstMove { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstMoveImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -43,7 +50,7 @@ impl Default for ConstMove { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, @@ -93,7 +100,7 @@ impl Clone for ThrowingMove { VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, @@ -208,11 +215,11 @@ fn main_0() -> i32 { assert!((vec_[0_usize].v == 7) && (vec_[1_usize].v == 8)); assert!(({ (*f.borrow()).v } == 0)); let m: Value = Rc::new(RefCell::new(::zero_init())); - ConstMoveImpl::construct(&m.as_pointer()); + DefaultConstructible::default_constructor(&m.as_pointer()); let m1: Value = Rc::new(RefCell::new(::zero_init())); ConstMoveImpl::construct_1(&m1.as_pointer(), { m.as_pointer() }); let cm: Value = Rc::new(RefCell::new(::zero_init())); - ConstMoveImpl::construct(&cm.as_pointer()); + DefaultConstructible::default_constructor(&cm.as_pointer()); let m2: Value = Rc::new(RefCell::new(::zero_init())); ConstMoveImpl::construct_2(&m2.as_pointer(), { cm.as_pointer() }); assert!(({ (*m1.borrow()).mark } == 1)); @@ -242,14 +249,10 @@ fn main_0() -> i32 { return 0; } pub trait ConstMoveImpl { - fn construct(&self); fn construct_1(&self, o: Ptr); fn construct_2(&self, o: Ptr); } impl ConstMoveImpl for Ptr { - fn construct(&self) { - field!((*self), mark).write(0); - } fn construct_1(&self, o: Ptr) { field!((*self), mark).write((o.with(|__s| __s.mark) + 1)); } diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index b6a984a28a..c246783611 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -13,7 +13,7 @@ use std::rc::{Rc, Weak}; VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, diff --git a/tests/unit/out/refcount/nested_structs.rs b/tests/unit/out/refcount/nested_structs.rs index 9be477ba18..e88997c5c7 100644 --- a/tests/unit/out/refcount/nested_structs.rs +++ b/tests/unit/out/refcount/nested_structs.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Level0_Level1_1_Level2_1_Level3_1 { @@ -15,7 +24,16 @@ pub struct Level0_Level1_1_Level2_1_Level3_1 { pub x1: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Level0_Level1_1_Level2_1_Level3_2 { @@ -25,7 +43,16 @@ pub struct Level0_Level1_1_Level2_1_Level3_2 { pub x2: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Level0_Level1_1_Level2_1 { @@ -33,7 +60,16 @@ pub struct Level0_Level1_1_Level2_1 { pub x1: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Level0_Level1_1 { @@ -41,7 +77,16 @@ pub struct Level0_Level1_1 { pub x1: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Level0_Level1_2 { @@ -51,7 +96,16 @@ pub struct Level0_Level1_2 { pub x2: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Level0 {} diff --git a/tests/unit/out/refcount/new.rs b/tests/unit/out/refcount/new.rs index 9565136037..8b075a627b 100644 --- a/tests/unit/out/refcount/new.rs +++ b/tests/unit/out/refcount/new.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { diff --git a/tests/unit/out/refcount/new_bst.rs b/tests/unit/out/refcount/new_bst.rs index 6ceb595ab8..84d527d72b 100644 --- a/tests/unit/out/refcount/new_bst.rs +++ b/tests/unit/out/refcount/new_bst.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(24)] pub struct node_t { diff --git a/tests/unit/out/refcount/new_struct.rs b/tests/unit/out/refcount/new_struct.rs index ff32f5d11a..f7d7b59779 100644 --- a/tests/unit/out/refcount/new_struct.rs +++ b/tests/unit/out/refcount/new_struct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { @@ -17,7 +26,16 @@ pub struct Pair { pub y: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Triple { diff --git a/tests/unit/out/refcount/nttp_distinct_specializations.rs b/tests/unit/out/refcount/nttp_distinct_specializations.rs index 4534577fd0..50684d62f7 100644 --- a/tests/unit/out/refcount/nttp_distinct_specializations.rs +++ b/tests/unit/out/refcount/nttp_distinct_specializations.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct S_2_ { @@ -17,7 +26,16 @@ pub struct S_2_ { pub w: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S_1_ { @@ -25,7 +43,16 @@ pub struct S_1_ { pub v: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S_3_ { diff --git a/tests/unit/out/refcount/offsetof.rs b/tests/unit/out/refcount/offsetof.rs index c5ef2ed022..5e769a9cf3 100644 --- a/tests/unit/out/refcount/offsetof.rs +++ b/tests/unit/out/refcount/offsetof.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(12)] pub struct Layout { @@ -18,7 +27,16 @@ pub struct Layout { #[offset(8)] pub c: u16, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(66)] pub struct Frame { #[offset(0)] diff --git a/tests/unit/out/refcount/opaque_forward_decl.rs b/tests/unit/out/refcount/opaque_forward_decl.rs index 69f6fbb662..57e54cc913 100644 --- a/tests/unit/out/refcount/opaque_forward_decl.rs +++ b/tests/unit/out/refcount/opaque_forward_decl.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 51bc05f6ab..868fa37299 100644 --- a/tests/unit/out/refcount/opaque_record_copy.rs +++ b/tests/unit/out/refcount/opaque_record_copy.rs @@ -7,12 +7,30 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Probe {} #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Wrapper_Probe_ { diff --git a/tests/unit/out/refcount/opaque_then_defined.rs b/tests/unit/out/refcount/opaque_then_defined.rs index 663c006b0b..6d8dc545f9 100644 --- a/tests/unit/out/refcount/opaque_then_defined.rs +++ b/tests/unit/out/refcount/opaque_then_defined.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct list { @@ -18,7 +26,15 @@ pub struct list { pub size: i32, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 54150ce7d4..6aa2ec1264 100644 --- a/tests/unit/out/refcount/operator_arithmetic_free.rs +++ b/tests/unit/out/refcount/operator_arithmetic_free.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_arithmetic_member.rs b/tests/unit/out/refcount/operator_arithmetic_member.rs index 7b57426f42..14fb214da2 100644 --- a/tests/unit/out/refcount/operator_arithmetic_member.rs +++ b/tests/unit/out/refcount/operator_arithmetic_member.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_bitwise_free.rs b/tests/unit/out/refcount/operator_bitwise_free.rs index 25087efa40..ba2321d034 100644 --- a/tests/unit/out/refcount/operator_bitwise_free.rs +++ b/tests/unit/out/refcount/operator_bitwise_free.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_bitwise_member.rs b/tests/unit/out/refcount/operator_bitwise_member.rs index f4b723a73e..aedd780f74 100644 --- a/tests/unit/out/refcount/operator_bitwise_member.rs +++ b/tests/unit/out/refcount/operator_bitwise_member.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index 1d684c95c8..1e95674b36 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Eq { @@ -22,7 +31,16 @@ impl CppEq for Eq { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Cmp { @@ -42,7 +60,16 @@ impl CppEq for Cmp { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Both { @@ -60,7 +87,16 @@ impl CppEq for Both { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct OrdOnly { @@ -78,7 +114,16 @@ impl CppEq for OrdOnly { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Inner { @@ -96,7 +141,16 @@ impl CppEq for Inner { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Outer { @@ -117,7 +171,16 @@ impl CppEq for Outer { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Secondary { @@ -135,7 +198,15 @@ impl CppEq for Secondary { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct PtrMember { diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index 8fc0a8ac09..1884dc7183 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { @@ -49,7 +58,16 @@ pub fn operator_lt_7(mut a: i32, b: Ptr) -> bool { return ({ a } < { b.with(|__s| __s.v) }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct V { diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index f9742e1b8d..ee3014ac10 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_comparison_mixed.rs b/tests/unit/out/refcount/operator_comparison_mixed.rs index 4ef2c1a398..d1cd37776b 100644 --- a/tests/unit/out/refcount/operator_comparison_mixed.rs +++ b/tests/unit/out/refcount/operator_comparison_mixed.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 0327803602..98305fe7aa 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct X { @@ -43,7 +52,16 @@ pub fn operator_ge_5(mut a: X, mut b: X) -> i32 { return if (a.v >= b.v) { 7 } else { 0 }; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Result { @@ -51,7 +69,16 @@ pub struct Result { pub r: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Custom { @@ -59,7 +86,16 @@ pub struct Custom { pub v: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Mixed { @@ -85,6 +121,7 @@ impl CppEq for Mixed { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -95,7 +132,16 @@ pub struct MyBool { pub value: bool, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Boolish { @@ -132,7 +178,9 @@ pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, +)] #[cpp_into(bool, to_bool)] #[byte_size(1)] pub struct RefBool { @@ -147,7 +195,16 @@ thread_local!( })); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct RefInt { diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index 97de158656..ea58048756 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -13,7 +13,14 @@ pub fn operator_lt_1(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.data_) } < { y.with(|__s| __s.data_) }); } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Memberwise, Default, + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + CppFrom, + DefaultInitializable, + Memberwise, + Default, )] #[memberwise(move_constructor)] #[cpp_from(i32, construct, value)] diff --git a/tests/unit/out/refcount/operator_compound_assignment_free.rs b/tests/unit/out/refcount/operator_compound_assignment_free.rs index 34d5b53645..581d157864 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_free.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_free.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_compound_assignment_member.rs b/tests/unit/out/refcount/operator_compound_assignment_member.rs index 030449d785..ba1b2cb9ae 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_member.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_member.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index 1d05674604..7fe14b5f97 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -11,7 +11,16 @@ pub fn operator_eq_0(_a0: Ptr, _a1: Ptr) -> bool { && ({ _a0.with(|__s| __s.b) } == { _a1.with(|__s| __s.b) }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Defaulted { @@ -41,7 +50,16 @@ pub fn operator_eq_2(_a0: Ptr, _a1: Ptr) -> bool { return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct DefaultedOrd { @@ -70,7 +88,16 @@ pub fn operator_add_5(x: Ptr, y: Ptr) -> Inline { }; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Inline { @@ -88,7 +115,16 @@ impl CppEq for Inline { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct OutOfLine { @@ -116,7 +152,16 @@ pub fn operator_eq_10(x: Ptr, y: Ptr) -> bool { return ({ (x.with(|__s| __s.v) as i64) } == { y.with(|__s| __s.v) }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Tmpl_int_ { @@ -134,7 +179,16 @@ impl CppEq for Tmpl_int_ { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Tmpl_long_ { @@ -145,7 +199,16 @@ pub fn operator_eq_11(_a0: Ptr, _a1: Ptr return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct TmplDefaulted_int_ { diff --git a/tests/unit/out/refcount/operator_less_than.rs b/tests/unit/out/refcount/operator_less_than.rs index 6ed2c5b32a..3450be62fc 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { diff --git a/tests/unit/out/refcount/operator_logical_free.rs b/tests/unit/out/refcount/operator_logical_free.rs index 86afec9078..00c15017c1 100644 --- a/tests/unit/out/refcount/operator_logical_free.rs +++ b/tests/unit/out/refcount/operator_logical_free.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_logical_member.rs b/tests/unit/out/refcount/operator_logical_member.rs index e14b6cdbeb..f633eada1d 100644 --- a/tests/unit/out/refcount/operator_logical_member.rs +++ b/tests/unit/out/refcount/operator_logical_member.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_member_pointer_free.rs b/tests/unit/out/refcount/operator_member_pointer_free.rs index e99e28946e..dc1f21b0e5 100644 --- a/tests/unit/out/refcount/operator_member_pointer_free.rs +++ b/tests/unit/out/refcount/operator_member_pointer_free.rs @@ -7,14 +7,32 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Inner { #[offset(0)] pub x: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_member_pointer_member.rs b/tests/unit/out/refcount/operator_member_pointer_member.rs index 74ac91c329..19aad4c322 100644 --- a/tests/unit/out/refcount/operator_member_pointer_member.rs +++ b/tests/unit/out/refcount/operator_member_pointer_member.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Inner { @@ -15,7 +24,16 @@ pub struct Inner { pub x: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Table {} @@ -27,7 +45,16 @@ impl Table { thread_local!( pub static table_0: Value> = Rc::new(RefCell::new(Box::new([7, 8, 9]))); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_other_free.rs b/tests/unit/out/refcount/operator_other_free.rs index dc4a505226..b374fe8e7c 100644 --- a/tests/unit/out/refcount/operator_other_free.rs +++ b/tests/unit/out/refcount/operator_other_free.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_other_member.rs b/tests/unit/out/refcount/operator_other_member.rs index 8622fd65b6..14e4b3ba85 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_member.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Static {} @@ -25,6 +34,7 @@ impl Static { VaArg, FnPtrArg, CppFrom, + TriviallyDefaultConstructible, TriviallyCopyable, Default, )] diff --git a/tests/unit/out/refcount/operator_overloads.rs b/tests/unit/out/refcount/operator_overloads.rs index 7e97765d20..0dace84931 100644 --- a/tests/unit/out/refcount/operator_overloads.rs +++ b/tests/unit/out/refcount/operator_overloads.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_qualifiers.rs b/tests/unit/out/refcount/operator_qualifiers.rs index 25080aa83f..7536bb88cb 100644 --- a/tests/unit/out/refcount/operator_qualifiers.rs +++ b/tests/unit/out/refcount/operator_qualifiers.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 53c88f7262..1989c8fa75 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 61480deea5..cf9740e798 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Lt { @@ -25,7 +34,16 @@ impl CppEq for Lt { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Eq { @@ -38,7 +56,16 @@ impl CppEq for Eq { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Cmp { @@ -56,7 +83,16 @@ impl CppEq for Cmp { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Free { @@ -80,7 +116,16 @@ pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Wrapped_int_ { diff --git a/tests/unit/out/refcount/overload_mangling.rs b/tests/unit/out/refcount/overload_mangling.rs index f4c4bca522..4518022b92 100644 --- a/tests/unit/out/refcount/overload_mangling.rs +++ b/tests/unit/out/refcount/overload_mangling.rs @@ -20,12 +20,30 @@ pub fn twice_2(mut n: i32) -> i32 { return (n * 2); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Access_S_ {} #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { @@ -33,7 +51,16 @@ pub struct S { pub base: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Box_ { diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index d9be805f1e..5229ffd044 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -15,6 +15,7 @@ use std::rc::{Rc, Weak}; VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -33,6 +34,7 @@ pub struct Celsius { VaArg, FnPtrArg, CppFrom, + TriviallyDefaultConstructible, TriviallyCopyable, Default, )] @@ -51,6 +53,7 @@ pub struct Meters { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -69,6 +72,7 @@ pub struct Label { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -90,6 +94,7 @@ pub struct Owner { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -108,6 +113,13 @@ pub struct Fallback { #[offset(0)] pub value: i32, } +impl DefaultConstructible for Fallback { + fn default_constructor(this: &Ptr) { + { + FallbackImpl::construct(this, { -1_i32 }); + } + } +} impl Default for Fallback { fn default() -> Self { { @@ -120,7 +132,16 @@ impl Default for Fallback { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Counter { @@ -136,6 +157,7 @@ pub struct Counter { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -154,6 +176,7 @@ pub struct Observer { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -172,6 +195,7 @@ pub struct Tag { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] diff --git a/tests/unit/out/refcount/pod.rs b/tests/unit/out/refcount/pod.rs index 63da4a0c34..f77fd3c72a 100644 --- a/tests/unit/out/refcount/pod.rs +++ b/tests/unit/out/refcount/pod.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(12)] pub struct POD { diff --git a/tests/unit/out/refcount/pointer_array.rs b/tests/unit/out/refcount/pointer_array.rs index ece5f0abce..2e0dd03248 100644 --- a/tests/unit/out/refcount/pointer_array.rs +++ b/tests/unit/out/refcount/pointer_array.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(24)] pub struct StackArray { #[offset(0)] diff --git a/tests/unit/out/refcount/pointers.rs b/tests/unit/out/refcount/pointers.rs index 88962e5de8..3bbb93fbe1 100644 --- a/tests/unit/out/refcount/pointers.rs +++ b/tests/unit/out/refcount/pointers.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Test { diff --git a/tests/unit/out/refcount/polymorphism.rs b/tests/unit/out/refcount/polymorphism.rs index cfdc0c2ddf..574e7324d3 100644 --- a/tests/unit/out/refcount/polymorphism.rs +++ b/tests/unit/out/refcount/polymorphism.rs @@ -17,7 +17,7 @@ pub trait Animal { ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Copyable, Default, )] @@ -31,7 +31,7 @@ pub struct Dog {} ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Copyable, Default, )] diff --git a/tests/unit/out/refcount/ptr_cast_init.rs b/tests/unit/out/refcount/ptr_cast_init.rs index efd5f6ae43..87969f89ab 100644 --- a/tests/unit/out/refcount/ptr_cast_init.rs +++ b/tests/unit/out/refcount/ptr_cast_init.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct header { @@ -17,7 +26,16 @@ pub struct header { pub size: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 3492f11f05..ec49f1451d 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Chunk { @@ -15,7 +24,15 @@ pub struct Chunk { pub data: i32, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Writer { @@ -49,6 +66,12 @@ pub struct JPEGData { #[byte_size(24)] pub app_data: Vec>, } +impl DefaultConstructible for JPEGData { + fn default_constructor(this: &Ptr) { + field!((*this), com_data).write(Vec::new()); + field!((*this), app_data).write(Vec::new()); + } +} pub fn push_param_0(mut dest: Ptr>>) { { let __a1 = Vec::new(); @@ -134,12 +157,18 @@ pub struct Pair { #[offset(4)] pub second: i32, } +impl DefaultConstructible for Pair { + fn default_constructor(this: &Ptr) { + field!((*this), first).write(-1_i32); + field!((*this), second).write(-1_i32); + } +} impl Default for Pair { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PairImpl::construct_2(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -150,7 +179,7 @@ pub fn emplace_ctor_args_7(mut pairs: Ptr>) { pairs.with_mut(|__v: &mut Vec| { __v.push({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - PairImpl::construct_2(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }); @@ -169,7 +198,7 @@ pub fn emplace_ctor_args_7(mut pairs: Ptr>) { let mut __tmp_5 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PairImpl::construct_3(&__v.as_pointer(), { 4 }, { 5 }); + PairImpl::construct_2(&__v.as_pointer(), { 4 }, { 5 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -181,7 +210,7 @@ pub fn emplace_deque_8(mut queue: Ptr>) { let mut __tmp_6 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PairImpl::construct_3(&__v.as_pointer(), { 6 }, { 7 }); + PairImpl::construct_2(&__v.as_pointer(), { 6 }, { 7 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -191,7 +220,7 @@ pub fn emplace_deque_8(mut queue: Ptr>) { queue.with_mut(|__v: &mut Vec| { __v.push({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - PairImpl::construct_2(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }); @@ -211,7 +240,7 @@ pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { let mut __tmp_7 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PairImpl::construct_3(&__v.as_pointer(), { 1 }, { 2 }); + PairImpl::construct_2(&__v.as_pointer(), { 1 }, { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -263,7 +292,7 @@ pub fn emplace_self_reads_12(mut values: Ptr>, mut pairs: Ptr let mut __tmp_11 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PairImpl::construct_3( + PairImpl::construct_2( &__v.as_pointer(), { pairs.with(|__s| { @@ -317,6 +346,12 @@ pub struct Bytes { #[array_len(3)] pub b: Box<[u8]>, } +impl DefaultConstructible for Bytes { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(Vec::new()); + field!((*this), b).write((0..3).map(|_| 0_u8).collect::>()); + } +} impl Default for Bytes { fn default() -> Self { { @@ -345,7 +380,16 @@ pub fn emplace_from_element_14(mut v: Ptr>>) { v.with_mut(|__v: &mut Vec>| __v.push(__tmp_14)); }; } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(24)] pub struct Plain { #[offset(0)] @@ -379,7 +423,16 @@ thread_local!( Rc::new(RefCell::new(Ptr::>::null())); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Counted { @@ -427,7 +480,8 @@ 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() })); - let jpg: Value = Rc::new(RefCell::new(::default())); + let jpg: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&jpg.as_pointer()); ({ push_local_from_field_1((jpg.as_pointer()), true) }); assert!(({ ((*jpg.borrow()).com_data.len() == 1_usize) })); assert!( @@ -575,7 +629,7 @@ fn main_0() -> i32 { let mut __tmp_18 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PairImpl::construct_3(&__v.as_pointer(), { 1 }, { 2 }); + PairImpl::construct_2(&__v.as_pointer(), { 1 }, { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -651,20 +705,15 @@ impl CountedImpl for Ptr { } } pub trait PairImpl { - fn construct_2(&self); fn construct_1(&self, a: i32); - fn construct_3(&self, a: i32, b: i32); + fn construct_2(&self, a: i32, b: i32); } impl PairImpl for Ptr { - fn construct_2(&self) { - field!((*self), first).write(-1_i32); - field!((*self), second).write(-1_i32); - } fn construct_1(&self, mut a: i32) { field!((*self), first).write(a); field!((*self), second).write(0); } - fn construct_3(&self, mut a: i32, mut b: i32) { + fn construct_2(&self, mut a: i32, mut b: i32) { field!((*self), first).write(a); field!((*self), second).write((b * 2)); } diff --git a/tests/unit/out/refcount/random.rs b/tests/unit/out/refcount/random.rs index 93ae6f283a..b1ada88bb9 100644 --- a/tests/unit/out/refcount/random.rs +++ b/tests/unit/out/refcount/random.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(72)] pub struct Pair { #[offset(0)] @@ -52,7 +61,16 @@ pub fn zero_0() -> i32 { return 0; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct X1 {} diff --git a/tests/unit/out/refcount/reference_wrapper.rs b/tests/unit/out/refcount/reference_wrapper.rs index 65381cce47..91523a2d9d 100644 --- a/tests/unit/out/refcount/reference_wrapper.rs +++ b/tests/unit/out/refcount/reference_wrapper.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Point { diff --git a/tests/unit/out/refcount/references.rs b/tests/unit/out/refcount/references.rs index c51ad1dbe1..ef780e7d66 100644 --- a/tests/unit/out/refcount/references.rs +++ b/tests/unit/out/refcount/references.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct Pair { #[offset(0)] @@ -30,7 +39,15 @@ impl Default for Pair { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct Nested { diff --git a/tests/unit/out/refcount/refs_as_args.rs b/tests/unit/out/refcount/refs_as_args.rs index 8f7383be46..b5de33dd10 100644 --- a/tests/unit/out/refcount/refs_as_args.rs +++ b/tests/unit/out/refcount/refs_as_args.rs @@ -31,7 +31,16 @@ pub fn more_refs_0(x1: i32, x2: i32, r1: Ptr, r2: Ptr) { r1.write((rx2.read())); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Val { diff --git a/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs b/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs index e777777307..d151e3b247 100644 --- a/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs +++ b/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct S { @@ -16,7 +25,16 @@ pub struct S { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(28)] pub struct W { #[offset(0)] @@ -36,7 +54,16 @@ impl Default for W { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(32)] pub struct P { #[offset(0)] diff --git a/tests/unit/out/refcount/reinterpret_cast_struct.rs b/tests/unit/out/refcount/reinterpret_cast_struct.rs index a0c237aba6..1e4384f563 100644 --- a/tests/unit/out/refcount/reinterpret_cast_struct.rs +++ b/tests/unit/out/refcount/reinterpret_cast_struct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Point { 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 2b4b15d4d6..c73b57bcaf 100644 --- a/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs +++ b/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Point { @@ -17,7 +26,16 @@ pub struct Point { pub y: u32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { diff --git a/tests/unit/out/refcount/reserved_keywords.rs b/tests/unit/out/refcount/reserved_keywords.rs index 61a59e4e1f..73a0131a8c 100644 --- a/tests/unit/out/refcount/reserved_keywords.rs +++ b/tests/unit/out/refcount/reserved_keywords.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(152)] pub struct S { @@ -89,7 +98,16 @@ pub struct S { pub vec_: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct type_ { @@ -97,7 +115,16 @@ pub struct type_ { pub v: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct loop_ { diff --git a/tests/unit/out/refcount/return_move.rs b/tests/unit/out/refcount/return_move.rs index c1b76be829..062413e198 100644 --- a/tests/unit/out/refcount/return_move.rs +++ b/tests/unit/out/refcount/return_move.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct node { @@ -18,7 +26,15 @@ pub struct node { pub next: Ptr, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct pair_t { diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index 885150a4b1..5b11cd1931 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -15,7 +15,9 @@ thread_local!( thread_local!( pub static moves_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Swappable)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, DefaultConstructible, Swappable, +)] #[cpp_from(i32, construct, value)] #[byte_size(20)] pub struct Buffer { diff --git a/tests/unit/out/refcount/rule_of_three.rs b/tests/unit/out/refcount/rule_of_three.rs index e6f864e501..691ec25d70 100644 --- a/tests/unit/out/refcount/rule_of_three.rs +++ b/tests/unit/out/refcount/rule_of_three.rs @@ -12,7 +12,9 @@ thread_local!( thread_local!( pub static copies_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Movable)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, DefaultConstructible, Movable, +)] #[cpp_from(i32, construct, value)] #[byte_size(20)] pub struct Buffer { diff --git a/tests/unit/out/refcount/rvalue_rule_arg_move.rs b/tests/unit/out/refcount/rvalue_rule_arg_move.rs index 266a6f3e7a..fe70068985 100644 --- a/tests/unit/out/refcount/rvalue_rule_arg_move.rs +++ b/tests/unit/out/refcount/rvalue_rule_arg_move.rs @@ -19,7 +19,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, Swappable, Default, diff --git a/tests/unit/out/refcount/rvalue_struct.rs b/tests/unit/out/refcount/rvalue_struct.rs index 7815aa553a..fd5ad5584b 100644 --- a/tests/unit/out/refcount/rvalue_struct.rs +++ b/tests/unit/out/refcount/rvalue_struct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct S { diff --git a/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs b/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs index 67b99a300a..315b80bea9 100644 --- a/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs +++ b/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Pod { diff --git a/tests/unit/out/refcount/self_referencing_initializer.rs b/tests/unit/out/refcount/self_referencing_initializer.rs index cc26e02cc3..a00d41a99d 100644 --- a/tests/unit/out/refcount/self_referencing_initializer.rs +++ b/tests/unit/out/refcount/self_referencing_initializer.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct list_head { @@ -16,7 +24,15 @@ pub struct list_head { pub next: Ptr, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct node { @@ -35,6 +51,12 @@ pub struct node_with_defaults { #[offset(8)] pub value: i32, } +impl DefaultConstructible for node_with_defaults { + fn default_constructor(this: &Ptr) { + field!((*this), next).write(Ptr::::null()); + field!((*this), value).write(3); + } +} impl Default for node_with_defaults { fn default() -> Self { { diff --git a/tests/unit/out/refcount/size_t_static_member.rs b/tests/unit/out/refcount/size_t_static_member.rs index 38685d971b..df8590e26b 100644 --- a/tests/unit/out/refcount/size_t_static_member.rs +++ b/tests/unit/out/refcount/size_t_static_member.rs @@ -10,7 +10,16 @@ thread_local!( pub static c_0: Value = Rc::new(RefCell::new(5_usize)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct S {} @@ -18,7 +27,16 @@ thread_local!( pub static table_size_1: Value = Rc::new(RefCell::new(256_usize)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Table_char_ {} diff --git a/tests/unit/out/refcount/size_t_template_param.rs b/tests/unit/out/refcount/size_t_template_param.rs index 44017a11ce..2a88bbef95 100644 --- a/tests/unit/out/refcount/size_t_template_param.rs +++ b/tests/unit/out/refcount/size_t_template_param.rs @@ -19,6 +19,7 @@ pub fn array_ref_0(a: Ptr) -> u64 { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -37,6 +38,7 @@ pub struct PtrCtor_unsigned_long_ { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index bef796ab38..60aa598e64 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -18,6 +18,11 @@ pub struct Tracked { #[offset(0)] pub v: i32, } +impl DefaultConstructible for Tracked { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(0); + } +} impl CopyConstructible for Tracked { fn copy_constructor(this: &Ptr, o: Ptr) { field!((*this), v).write(o.with(|__s| __s.v)); @@ -66,7 +71,7 @@ impl Default for Tracked { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct_2(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -84,7 +89,7 @@ pub fn greater_2(a: Ptr, b: Ptr) -> bool { ZeroInitialization, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, Memberwise, Swappable, Default, @@ -130,6 +135,11 @@ pub struct Bag { #[byte_size(24)] pub items: Vec, } +impl DefaultConstructible for Bag { + fn default_constructor(this: &Ptr) { + field!((*this), items).write(Vec::new()); + } +} impl CppLess for Bag { fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { operator_lt_4(__lhs.clone(), __rhs.clone()) @@ -329,9 +339,13 @@ 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( - (0..3).map(|_| ::default()).collect::>(), - )); + let bags: Value> = Rc::new(RefCell::new(Box::new(std::array::from_fn::<_, 3, _>( + |_| { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + )))); { let mut __tmp_9 = { { @@ -604,13 +618,9 @@ impl MoveOnlyImpl for Ptr { } } pub trait TrackedImpl { - fn construct_2(&self); fn construct_1(&self, v: i32); } impl TrackedImpl for Ptr { - fn construct_2(&self) { - field!((*self), v).write(0); - } fn construct_1(&self, mut v: i32) { field!((*self), v).write(v); } diff --git a/tests/unit/out/refcount/static_local.rs b/tests/unit/out/refcount/static_local.rs index 24ae2dfc21..0f536f87c9 100644 --- a/tests/unit/out/refcount/static_local.rs +++ b/tests/unit/out/refcount/static_local.rs @@ -34,7 +34,16 @@ thread_local!( static x_7: Value = Rc::new(RefCell::new(3)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct S_8 {} diff --git a/tests/unit/out/refcount/static_var_in_class.rs b/tests/unit/out/refcount/static_var_in_class.rs index 35e90123f8..e626bafe6b 100644 --- a/tests/unit/out/refcount/static_var_in_class.rs +++ b/tests/unit/out/refcount/static_var_in_class.rs @@ -10,7 +10,16 @@ thread_local!( static inner_const_0: Value = Rc::new(RefCell::new(1)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct C {} @@ -20,7 +29,16 @@ thread_local!( pub type anon_3 = u32; pub const anon_3_kValue: anon_3 = 3; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct S {} diff --git a/tests/unit/out/refcount/stdcopy.rs b/tests/unit/out/refcount/stdcopy.rs index b432be3106..8ab807fa76 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.rs @@ -15,6 +15,7 @@ use std::rc::{Rc, Weak}; VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] diff --git a/tests/unit/out/refcount/strdup.rs b/tests/unit/out/refcount/strdup.rs index 8e26d342dc..1135a0239a 100644 --- a/tests/unit/out/refcount/strdup.rs +++ b/tests/unit/out/refcount/strdup.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 207c5f0207..faecbb65d5 100644 --- a/tests/unit/out/refcount/string_literal_ptr_init.rs +++ b/tests/unit/out/refcount/string_literal_ptr_init.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 fd214114c0..ee651aa954 100644 --- a/tests/unit/out/refcount/string_substr.rs +++ b/tests/unit/out/refcount/string_substr.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Text { diff --git a/tests/unit/out/refcount/struct_2d_array_field.rs b/tests/unit/out/refcount/struct_2d_array_field.rs index 006d428772..8ac998a96b 100644 --- a/tests/unit/out/refcount/struct_2d_array_field.rs +++ b/tests/unit/out/refcount/struct_2d_array_field.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(40)] pub struct table { #[offset(0)] diff --git a/tests/unit/out/refcount/struct_ctor.rs b/tests/unit/out/refcount/struct_ctor.rs index 3d98fc2e88..f4d63e0bb7 100644 --- a/tests/unit/out/refcount/struct_ctor.rs +++ b/tests/unit/out/refcount/struct_ctor.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct StructWithCtor { @@ -28,6 +37,7 @@ pub fn foo_0(x: Ptr) -> Ptr { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -47,12 +57,18 @@ pub struct Ptr_ { #[byte_size(4)] pub v2: Value_, } +impl DefaultConstructible for Ptr_ { + fn default_constructor(this: &Ptr) { + Value_Impl::construct(&field_ptr!(this, v1), { 11 }); + Value_Impl::construct(&field_ptr!(this, v2), { 22 }); + } +} impl Default for Ptr_ { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - Ptr_Impl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -73,20 +89,11 @@ fn main_0() -> i32 { && ((({ StructWithCtorImpl::x2(&struct_with_ctor.as_pointer(),) }).read()) == 1) ); let p: Value = Rc::new(RefCell::new(::zero_init())); - Ptr_Impl::construct(&p.as_pointer()); + DefaultConstructible::default_constructor(&p.as_pointer()); assert!(({ (*p.borrow()).v1.v } == 11)); assert!(({ (*p.borrow()).v2.v } == 22)); return 0; } -pub trait Ptr_Impl { - fn construct(&self); -} -impl Ptr_Impl for Ptr { - fn construct(&self) { - Value_Impl::construct(&field_ptr!(self, v1), { 11 }); - Value_Impl::construct(&field_ptr!(self, v2), { 22 }); - } -} pub trait StructWithCtorImpl { fn construct(&self, x1: i32, x2: i32); fn x1(&self) -> Ptr; diff --git a/tests/unit/out/refcount/struct_default_ctor.rs b/tests/unit/out/refcount/struct_default_ctor.rs index 4f8707f78a..a1658d8694 100644 --- a/tests/unit/out/refcount/struct_default_ctor.rs +++ b/tests/unit/out/refcount/struct_default_ctor.rs @@ -14,12 +14,18 @@ pub struct S { #[offset(4)] pub b: bool, } +impl DefaultConstructible for S { + fn default_constructor(this: &Ptr) { + field!((*this), a).write(11); + field!((*this), b).write(true); + } +} impl Default for S { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - SImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -41,6 +47,15 @@ pub struct Holder { #[array_len(2)] pub items: Box<[S]>, } +impl DefaultConstructible for Holder { + fn default_constructor(this: &Ptr) { + field!((*this), items).write(Box::new(std::array::from_fn::<_, 2, _>(|_| { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); + } +} impl Default for Holder { fn default() -> Self { { @@ -59,6 +74,11 @@ pub struct FromStatic { #[offset(0)] pub v: i32, } +impl DefaultConstructible for FromStatic { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(kInit_0.with(|rc| *rc.borrow())); + } +} impl Default for FromStatic { fn default() -> Self { { @@ -76,7 +96,7 @@ fn main_0() -> i32 { let mut d: Ptr = Ptr::::null(); assert!((d).is_null()); let s: Value = Rc::new(RefCell::new(::zero_init())); - SImpl::construct(&s.as_pointer()); + DefaultConstructible::default_constructor(&s.as_pointer()); assert!(({ (*s.borrow()).a } == 11)); assert!((({ (*s.borrow()).b } as i32) == (true as i32))); let mut h: Ptr = Ptr::alloc_array( @@ -95,19 +115,9 @@ fn main_0() -> i32 { fs.delete(); return 0; } -pub trait DeclaredImpl { - fn construct(&self) { - unimplemented!() - } -} -impl DeclaredImpl for Ptr {} -pub trait SImpl { - fn construct(&self); -} -impl SImpl for Ptr { - fn construct(&self) { - field!((*self), a).write(11); - field!((*self), b).write(true); +impl DefaultConstructible for Declared { + fn default_constructor(this: &Ptr) { + unreachable!("Declared::default_constructor is never defined") } } pub fn __cpp2rust_init_globals() { diff --git a/tests/unit/out/refcount/struct_member_array_adjacency.rs b/tests/unit/out/refcount/struct_member_array_adjacency.rs index 51904107ec..62c22118f0 100644 --- a/tests/unit/out/refcount/struct_member_array_adjacency.rs +++ b/tests/unit/out/refcount/struct_member_array_adjacency.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(32)] pub struct pair { #[offset(0)] diff --git a/tests/unit/out/refcount/struct_ptr.rs b/tests/unit/out/refcount/struct_ptr.rs index 720a2e9fc5..6be6fcf0b2 100644 --- a/tests/unit/out/refcount/struct_ptr.rs +++ b/tests/unit/out/refcount/struct_ptr.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct XX { diff --git a/tests/unit/out/refcount/structured_binding_copy_ctor.rs b/tests/unit/out/refcount/structured_binding_copy_ctor.rs index 7e1d1d28ad..c9adaff061 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -15,7 +15,7 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Memberwise, Movable, Default, diff --git a/tests/unit/out/refcount/structured_binding_element_ctor.rs b/tests/unit/out/refcount/structured_binding_element_ctor.rs index 1f1f671a28..a4fafef0d9 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -19,7 +19,7 @@ thread_local!( VaArg, FnPtrArg, CppFrom, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, @@ -59,7 +59,7 @@ impl Clone for Elem { ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Memberwise, CopyAssignable, MoveAssignable, diff --git a/tests/unit/out/refcount/structured_binding_move_ctor.rs b/tests/unit/out/refcount/structured_binding_move_ctor.rs index 67d7d68b52..11c44c8f16 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -18,7 +18,7 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, CopyAssignable, MoveAssignable, Swappable, @@ -81,6 +81,12 @@ pub struct Holder { #[byte_size(24)] pub ys: Vec, } +impl DefaultConstructible for Holder { + fn default_constructor(this: &Ptr) { + field!((*this), xs).write(Vec::new()); + field!((*this), ys).write(Vec::new()); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/structured_binding_range_for.rs b/tests/unit/out/refcount/structured_binding_range_for.rs index acd97c4bfe..3f93184600 100644 --- a/tests/unit/out/refcount/structured_binding_range_for.rs +++ b/tests/unit/out/refcount/structured_binding_range_for.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { diff --git a/tests/unit/out/refcount/structured_binding_ref.rs b/tests/unit/out/refcount/structured_binding_ref.rs index 9f79ef66d1..87a29e0e56 100644 --- a/tests/unit/out/refcount/structured_binding_ref.rs +++ b/tests/unit/out/refcount/structured_binding_ref.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(12)] pub struct Triple { diff --git a/tests/unit/out/refcount/structured_binding_trivial.rs b/tests/unit/out/refcount/structured_binding_trivial.rs index 7214c5278d..6a388376ed 100644 --- a/tests/unit/out/refcount/structured_binding_trivial.rs +++ b/tests/unit/out/refcount/structured_binding_trivial.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index a864490df5..eca380789a 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -18,6 +18,11 @@ pub struct Tracked { #[offset(0)] pub v: i32, } +impl DefaultConstructible for Tracked { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(0); + } +} impl CopyConstructible for Tracked { fn copy_constructor(this: &Ptr, o: Ptr) { field!((*this), v).write(o.with(|__s| __s.v)); @@ -55,7 +60,7 @@ impl Default for Tracked { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct_2(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -83,6 +88,12 @@ pub struct Pair { #[byte_size(4)] pub y: Tracked, } +impl DefaultConstructible for Pair { + fn default_constructor(this: &Ptr) { + DefaultConstructible::default_constructor(&field_ptr!(this, x)); + DefaultConstructible::default_constructor(&field_ptr!(this, y)); + } +} #[derive( Clone, Record, @@ -106,6 +117,20 @@ pub struct Arrays { #[array_len(2)] pub b: Box<[Tracked]>, } +impl DefaultConstructible for Arrays { + fn default_constructor(this: &Ptr) { + field!((*this), a).write(Box::new(std::array::from_fn::<_, 2, _>(|_| { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&__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(::zero_init())); + DefaultConstructible::default_constructor(&__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); + } +} impl Default for Arrays { fn default() -> Self { { @@ -126,7 +151,17 @@ thread_local!( thread_local!( pub static copy_only_dtors_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Movable, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + DefaultConstructible, + Movable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct CopyOnly { @@ -166,7 +201,7 @@ impl Clone for CopyOnly { ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Memberwise, MoveConstructible, Swappable, @@ -193,7 +228,17 @@ thread_local!( thread_local!( pub static moved_dtors_5: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Swappable, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + DefaultConstructible, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Moved { @@ -248,7 +293,7 @@ impl Clone for Moved { ZeroInitialization, VaArg, FnPtrArg, - Destructible, + DefaultInitializable, Memberwise, Swappable, Default, @@ -292,6 +337,11 @@ pub struct Owner { #[byte_size(8)] pub p: Option>, } +impl DefaultConstructible for Owner { + fn default_constructor(this: &Ptr) { + field!((*this), p).write(None); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -572,7 +622,8 @@ fn main_0() -> i32 { && ({ (*pairs.borrow())[(1) as usize].y.v } == 8) ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - let arrays: Value = Rc::new(RefCell::new(::default())); + let arrays: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&arrays.as_pointer()); field!(array_elem!(arrays.as_pointer(), a, 0), v).write(1); field!(array_elem!(arrays.as_pointer(), b, 1), v).write(2); Swappable::swap( @@ -856,23 +907,10 @@ impl MovedImpl for Ptr { field!((*self), v).write(v); } } -pub trait PairImpl { - fn construct_1(&self); -} -impl PairImpl for Ptr { - fn construct_1(&self) { - TrackedImpl::construct_2(&field_ptr!(self, x)); - TrackedImpl::construct_2(&field_ptr!(self, y)); - } -} pub trait TrackedImpl { - fn construct_2(&self); fn construct_1(&self, v: i32); } impl TrackedImpl for Ptr { - fn construct_2(&self) { - field!((*self), v).write(0); - } fn construct_1(&self, mut v: i32) { field!((*self), v).write(v); } diff --git a/tests/unit/out/refcount/tag_vs_identifier_collision.rs b/tests/unit/out/refcount/tag_vs_identifier_collision.rs index 2db918945d..f86e8dbb0a 100644 --- a/tests/unit/out/refcount/tag_vs_identifier_collision.rs +++ b/tests/unit/out/refcount/tag_vs_identifier_collision.rs @@ -11,7 +11,16 @@ pub const widget_enum_MODE_IDLE: widget_enum = 0; pub const widget_enum_MODE_ACTIVE: widget_enum = 1; pub const widget_enum_MODE_DONE: widget_enum = 2; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct widget { @@ -21,7 +30,16 @@ pub struct widget { pub mode: widget_enum, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct point_struct { @@ -30,7 +48,15 @@ pub struct point_struct { #[offset(4)] pub y: i32, } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(4)] pub struct point { #[offset(0)] @@ -53,7 +79,15 @@ impl Default for point { } } } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(4)] pub struct slot_union { #[offset(0)] @@ -80,7 +114,16 @@ pub type slot = u32; pub const slot_SLOT_A: slot = 0; pub const slot_SLOT_B: slot = 1; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Inner { @@ -88,7 +131,16 @@ pub struct Inner { pub tag_field: i32, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Outer { @@ -97,7 +149,16 @@ pub struct Outer { pub field: Inner, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 9f7312a0c9..f595448251 100644 --- a/tests/unit/out/refcount/template_default_arg.rs +++ b/tests/unit/out/refcount/template_default_arg.rs @@ -15,12 +15,17 @@ pub struct A { #[offset(0)] pub v: i32, } +impl DefaultConstructible for A { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(1); + } +} impl Default for A { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - AImpl::construct_2(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -32,12 +37,17 @@ pub struct B { #[offset(0)] pub v: i32, } +impl DefaultConstructible for B { + fn default_constructor(this: &Ptr) { + field!((*this), v).write(2); + } +} impl Default for B { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - BImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -52,6 +62,7 @@ impl Default for B { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -82,6 +93,7 @@ pub fn always_given_3(mut x: NoDefault) -> i32 { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -100,7 +112,7 @@ fn main_0() -> i32 { (({ used_0({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - AImpl::construct_2(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 1) @@ -118,7 +130,7 @@ fn main_0() -> i32 { (({ used_1({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - BImpl::construct(&__v.as_pointer()); + DefaultConstructible::default_constructor(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 2) @@ -170,25 +182,13 @@ fn main_0() -> i32 { return 0; } pub trait AImpl { - fn construct_2(&self); fn construct_1(&self, v: i32); } impl AImpl for Ptr { - fn construct_2(&self) { - field!((*self), v).write(1); - } fn construct_1(&self, mut v: i32) { field!((*self), v).write(v); } } -pub trait BImpl { - fn construct(&self); -} -impl BImpl for Ptr { - fn construct(&self) { - field!((*self), v).write(2); - } -} pub trait NoDefaultImpl { fn construct(&self, v: i32); } diff --git a/tests/unit/out/refcount/template_static_member.rs b/tests/unit/out/refcount/template_static_member.rs index b97e23a677..8f0105ef25 100644 --- a/tests/unit/out/refcount/template_static_member.rs +++ b/tests/unit/out/refcount/template_static_member.rs @@ -10,7 +10,16 @@ thread_local!( pub static s_0: Value = Rc::new(RefCell::new(55)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Static_int_ {} @@ -18,7 +27,16 @@ thread_local!( pub static s_1: Value = Rc::new(RefCell::new(55_i8)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Static_char_ {} @@ -26,7 +44,16 @@ thread_local!( pub static s_2: Value = Rc::new(RefCell::new(55_i64)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Static_long_ {} @@ -37,7 +64,16 @@ thread_local!( pub static hi_4: Value = Rc::new(RefCell::new(1)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Range_int_ {} @@ -48,7 +84,16 @@ thread_local!( pub static hi_6: Value = Rc::new(RefCell::new(2_i64)); ); #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct Range_long_ {} diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index 9038daf9e3..d246ec5fa3 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -26,6 +26,11 @@ pub struct Inner { #[byte_size(24)] pub values: Vec, } +impl DefaultConstructible for Inner { + fn default_constructor(this: &Ptr) { + field!((*this), values).write(Vec::new()); + } +} #[derive( Clone, Record, @@ -52,6 +57,13 @@ pub struct Outer { #[array_len(8)] pub name: Box<[i8]>, } +impl DefaultConstructible for Outer { + fn default_constructor(this: &Ptr) { + field!((*this), values).write(Vec::new()); + DefaultConstructible::default_constructor(&field_ptr!(this, inner)); + field!((*this), name).write((0..8).map(|_| 0_i8).collect::>()); + } +} impl Default for Outer { fn default() -> Self { { diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index 546c4836c2..dd8e331040 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -26,6 +26,11 @@ pub struct Outer { #[byte_size(24)] pub values: Vec, } +impl DefaultConstructible for Outer { + fn default_constructor(this: &Ptr) { + field!((*this), values).write(Vec::new()); + } +} pub fn make_0(this: Ptr) { this.write(Outer { values: Vec::from([1, 2, 3, 4]), @@ -41,6 +46,7 @@ pub fn make_0(this: Ptr) { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index 3d2aaef51a..324e8a8a43 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -26,6 +26,11 @@ pub struct Inner { #[byte_size(24)] pub values: Vec, } +impl DefaultConstructible for Inner { + fn default_constructor(this: &Ptr) { + field!((*this), values).write(Vec::new()); + } +} #[derive( Clone, Record, @@ -49,6 +54,12 @@ pub struct Outer { #[byte_size(24)] pub inner: Inner, } +impl DefaultConstructible for Outer { + fn default_constructor(this: &Ptr) { + field!((*this), values).write(Vec::new()); + DefaultConstructible::default_constructor(&field_ptr!(this, inner)); + } +} pub fn make_0(this: Ptr) { this.write(Outer { values: Vec::from([1, 2, 3]), diff --git a/tests/unit/out/refcount/this.rs b/tests/unit/out/refcount/this.rs index 991563832f..c603b31c31 100644 --- a/tests/unit/out/refcount/this.rs +++ b/tests/unit/out/refcount/this.rs @@ -14,6 +14,7 @@ use std::rc::{Rc, Weak}; VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -38,6 +39,7 @@ pub fn bump_0(mut p: Ptr) { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index ffcc92c198..896757b8d9 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Outer_RunInfo { @@ -36,22 +45,28 @@ pub struct Outer { #[byte_size(24)] pub runs: Vec, } +impl DefaultConstructible for Outer { + fn default_constructor(this: &Ptr) { + field!((*this), runs).write(Vec::new()); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let mut o: Outer = ::default(); + let o: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&o.as_pointer()); let mut info: Outer_RunInfo = ::default(); info.block_idx = 1; info.num_extra_zero_runs = 2; { let a0_clone = info.clone(); - o.runs.push(a0_clone) + (*o.borrow_mut()).runs.push(a0_clone) }; - assert!((o.runs.len() == 1_usize)); - assert!((o.runs[0_usize].block_idx == 1)); - assert!((o.runs[0_usize].num_extra_zero_runs == 2)); + assert!(({ ((*o.borrow()).runs.len() == 1_usize) })); + assert!((vec_elem!(o.as_pointer(), runs, 0_usize).with(|__s| __s.block_idx) == 1)); + assert!((vec_elem!(o.as_pointer(), runs, 0_usize).with(|__s| __s.num_extra_zero_runs) == 2)); return 0; } pub fn __cpp2rust_init_globals() {} 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 7c88368be3..5016cccfce 100644 --- a/tests/unit/out/refcount/unary_expr_or_type_trait.rs +++ b/tests/unit/out/refcount/unary_expr_or_type_trait.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct S { diff --git a/tests/unit/out/refcount/unboxed_locals.rs b/tests/unit/out/refcount/unboxed_locals.rs index be0c5e2949..5b10d7646f 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -15,7 +15,16 @@ pub fn inc_1(r: Ptr) { }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { @@ -57,7 +66,15 @@ pub trait Shape { fn scale(&mut self, factor: i32) -> i32; } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultInitializable, + Copyable, )] #[byte_size(16)] pub struct Square { diff --git a/tests/unit/out/refcount/unboxed_records.rs b/tests/unit/out/refcount/unboxed_records.rs index d39d30b2e3..c8410306de 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Inner { @@ -16,7 +25,16 @@ pub struct Inner { #[offset(4)] pub b: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(48)] pub struct Cookie { #[offset(0)] @@ -54,6 +72,11 @@ pub struct Counter { #[offset(0)] pub n: i32, } +impl DefaultConstructible for Counter { + fn default_constructor(this: &Ptr) { + field!((*this), n).write(0); + } +} impl Default for Counter { fn default() -> Self { { Counter { n: 0 } } @@ -118,7 +141,8 @@ 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)); - let counter: Value = Rc::new(RefCell::new(::default())); + let counter: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&counter.as_pointer()); ({ CounterImpl::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 38db75558a..6987c6e70c 100644 --- a/tests/unit/out/refcount/union_addrof_external.rs +++ b/tests/unit/out/refcount/union_addrof_external.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct record { #[offset(0)] @@ -32,7 +41,15 @@ impl Default for record { } } } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(128)] pub struct anon_0 { #[offset(0)] @@ -56,7 +73,15 @@ impl Default for anon_0 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 4c0b892186..0dc7a5de49 100644 --- a/tests/unit/out/refcount/union_basic.rs +++ b/tests/unit/out/refcount/union_basic.rs @@ -6,7 +6,15 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(4)] pub struct basic { #[offset(0)] @@ -29,7 +37,15 @@ impl Default for basic { } } } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(1)] pub struct empty { #[offset(0)] @@ -45,7 +61,15 @@ impl Default for empty { } } } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct underscores { #[offset(0)] @@ -123,7 +147,15 @@ fn main_0() -> i32 { assert!(((__ + ___) == 3)); return 0; } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(4)] pub struct anon_0 { #[offset(0)] diff --git a/tests/unit/out/refcount/union_cross_arm_cast.rs b/tests/unit/out/refcount/union_cross_arm_cast.rs index bc6e773407..d4871fa382 100644 --- a/tests/unit/out/refcount/union_cross_arm_cast.rs +++ b/tests/unit/out/refcount/union_cross_arm_cast.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct shape_a { #[offset(0)] @@ -26,7 +35,16 @@ impl Default for shape_a { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(28)] pub struct shape_b { #[offset(0)] @@ -55,7 +73,15 @@ impl Default for shape_b { } } } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(64)] pub struct anon_0 { #[offset(0)] @@ -82,7 +108,15 @@ impl Default for anon_0 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 d91fb62317..f2f47c1f1b 100644 --- a/tests/unit/out/refcount/union_field_alignment.rs +++ b/tests/unit/out/refcount/union_field_alignment.rs @@ -6,7 +6,15 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -30,7 +38,15 @@ impl Default for anon_0 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 a69afd6de5..0cc7bfa269 100644 --- a/tests/unit/out/refcount/union_flex_array_member.rs +++ b/tests/unit/out/refcount/union_flex_array_member.rs @@ -6,7 +6,15 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -30,7 +38,15 @@ impl Default for anon_0 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 e215d22c1b..74c3826b41 100644 --- a/tests/unit/out/refcount/union_memset_memcpy.rs +++ b/tests/unit/out/refcount/union_memset_memcpy.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct shape_a { #[offset(0)] @@ -26,7 +35,16 @@ impl Default for shape_a { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct shape_b { #[offset(0)] @@ -52,7 +70,15 @@ impl Default for shape_b { } } } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(256)] pub struct anon_0 { #[offset(0)] @@ -79,7 +105,15 @@ impl Default for anon_0 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 3acf138887..85282bf7c9 100644 --- a/tests/unit/out/refcount/union_nested.rs +++ b/tests/unit/out/refcount/union_nested.rs @@ -6,7 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, +)] #[byte_size(16)] pub struct record { #[offset(0)] @@ -26,7 +35,15 @@ impl Default for record { } } } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(128)] pub struct anon_0 { #[offset(0)] @@ -50,7 +67,15 @@ impl Default for anon_0 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(128)] pub struct inner { @@ -58,7 +83,15 @@ pub struct inner { #[byte_size(128)] pub view: anon_0, } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(128)] pub struct anon_1 { #[offset(0)] @@ -82,7 +115,15 @@ impl Default for anon_1 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 687deafd25..69aea799ce 100644 --- a/tests/unit/out/refcount/union_pointer_pun_address.rs +++ b/tests/unit/out/refcount/union_pointer_pun_address.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct node_a { @@ -15,7 +24,15 @@ pub struct node_a { pub n: i32, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct node_b { @@ -38,7 +55,15 @@ fn main_0() -> i32 { assert!(({ (out).to_any() } == { (a.as_pointer()).to_any() })); return 0; } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] diff --git a/tests/unit/out/refcount/union_pointer_pun_writethrough.rs b/tests/unit/out/refcount/union_pointer_pun_writethrough.rs index 222fc22741..c256754f30 100644 --- a/tests/unit/out/refcount/union_pointer_pun_writethrough.rs +++ b/tests/unit/out/refcount/union_pointer_pun_writethrough.rs @@ -18,7 +18,15 @@ fn main_0() -> i32 { assert!(({ ((*x.borrow()) == 42_i64) })); return 0; } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] diff --git a/tests/unit/out/refcount/union_struct_dual_use.rs b/tests/unit/out/refcount/union_struct_dual_use.rs index 202db6881e..734892b9fe 100644 --- a/tests/unit/out/refcount/union_struct_dual_use.rs +++ b/tests/unit/out/refcount/union_struct_dual_use.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Inner { @@ -19,7 +28,15 @@ pub struct Inner { pub fn sum_inner_0(mut i: Ptr) -> i32 { return ({ i.with(|__s| __s.a) } + { i.with(|__s| __s.b) }); } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(16)] pub struct anon_1 { #[offset(0)] @@ -43,7 +60,15 @@ impl Default for anon_1 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 68a74d495f..83cc27c144 100644 --- a/tests/unit/out/refcount/union_tagged_many_arms.rs +++ b/tests/unit/out/refcount/union_tagged_many_arms.rs @@ -12,7 +12,15 @@ pub const Tag_enum_T_NUM_U: Tag_enum = 1; pub const Tag_enum_T_TEXT: Tag_enum = 2; pub const Tag_enum_T_FLOAT: Tag_enum = 3; pub const Tag_enum_T_REF: Tag_enum = 4; -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -45,7 +53,15 @@ impl Default for anon_0 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 9ac26454c1..8ecd6d388a 100644 --- a/tests/unit/out/refcount/union_tagged_simple.rs +++ b/tests/unit/out/refcount/union_tagged_simple.rs @@ -9,7 +9,15 @@ use std::rc::{Rc, Weak}; pub type Kind_enum = u32; pub const Kind_enum_KIND_NONE: Kind_enum = 0; pub const Kind_enum_KIND_DONE: Kind_enum = 1; -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -33,7 +41,15 @@ impl Default for anon_0 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 761cc43908..38b2f15ac3 100644 --- a/tests/unit/out/refcount/union_tagged_struct_arms.rs +++ b/tests/unit/out/refcount/union_tagged_struct_arms.rs @@ -11,7 +11,15 @@ pub const Choice_enum_C_LIST: Choice_enum = 1; pub const Choice_enum_C_LETTERS: Choice_enum = 2; pub const Choice_enum_C_INTEGERS: Choice_enum = 3; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(24)] pub struct anon_1 { @@ -24,7 +32,16 @@ pub struct anon_1 { pub cursor: i64, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(16)] pub struct anon_2 { @@ -38,7 +55,16 @@ pub struct anon_2 { pub step: u8, } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(40)] pub struct anon_3 { @@ -53,7 +79,15 @@ pub struct anon_3 { #[offset(32)] pub width: i32, } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(40)] pub struct anon_0 { #[offset(0)] @@ -80,7 +114,15 @@ impl Default for anon_0 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 ee6473ddef..4193557584 100644 --- a/tests/unit/out/refcount/union_void_ptr_sized_deref.rs +++ b/tests/unit/out/refcount/union_void_ptr_sized_deref.rs @@ -10,7 +10,15 @@ pub type Width_enum = u32; pub const Width_enum_W_64: Width_enum = 0; pub const Width_enum_W_32: Width_enum = 1; pub const Width_enum_W_16: Width_enum = 2; -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -40,7 +48,15 @@ impl Default for anon_0 { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 cfe9c99961..68bef48b82 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -16,8 +16,22 @@ pub struct SafePointer { #[byte_size(8)] pub ptr: Option>, } +impl DefaultConstructible for SafePointer { + fn default_constructor(this: &Ptr) { + field!((*this), ptr).write(None); + } +} #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Pair { diff --git a/tests/unit/out/refcount/unique_ptr_const_deref.rs b/tests/unit/out/refcount/unique_ptr_const_deref.rs index c13b1df61c..dcdbf722b9 100644 --- a/tests/unit/out/refcount/unique_ptr_const_deref.rs +++ b/tests/unit/out/refcount/unique_ptr_const_deref.rs @@ -16,6 +16,11 @@ pub struct Holder { #[byte_size(8)] pub val: Option>, } +impl DefaultConstructible for Holder { + fn default_constructor(this: &Ptr) { + field!((*this), val).write(None); + } +} pub fn read_val_0(mut h: Ptr) -> i32 { return (h.with(|__s| __s.val.clone()).as_pointer().read()); } @@ -27,7 +32,8 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let h: Value = Rc::new(RefCell::new(::default())); + let h: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&h.as_pointer()); { (*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 b2349d77b5..1485661a7a 100644 --- a/tests/unit/out/refcount/unique_ptr_field_reset.rs +++ b/tests/unit/out/refcount/unique_ptr_field_reset.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Data { @@ -26,12 +35,19 @@ pub struct Holder { #[offset(8)] pub n: i32, } +impl DefaultConstructible for Holder { + fn default_constructor(this: &Ptr) { + field!((*this), data).write(None); + field!((*this), n).write(0_i32); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let h: Value = Rc::new(RefCell::new(::default())); + let h: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&h.as_pointer()); (*h.borrow_mut()).n = 1; let mut hp: Ptr = (h.as_pointer()); { diff --git a/tests/unit/out/refcount/unique_ptr_nested.rs b/tests/unit/out/refcount/unique_ptr_nested.rs index 44621e9e33..83088c96fd 100644 --- a/tests/unit/out/refcount/unique_ptr_nested.rs +++ b/tests/unit/out/refcount/unique_ptr_nested.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Inner { @@ -26,6 +35,11 @@ pub struct Outer { #[byte_size(8)] pub inner: Option>, } +impl DefaultConstructible for Outer { + fn default_constructor(this: &Ptr) { + field!((*this), inner).write(None); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/unique_ptr_struct.rs b/tests/unit/out/refcount/unique_ptr_struct.rs index f2bd49ae0b..c265f0cfa5 100644 --- a/tests/unit/out/refcount/unique_ptr_struct.rs +++ b/tests/unit/out/refcount/unique_ptr_struct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Point { diff --git a/tests/unit/out/refcount/va_arg_mixed_types.rs b/tests/unit/out/refcount/va_arg_mixed_types.rs index 2a0b78aa51..15514399be 100644 --- a/tests/unit/out/refcount/va_arg_mixed_types.rs +++ b/tests/unit/out/refcount/va_arg_mixed_types.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 d606d5b110..b3b8484a2f 100644 --- a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 b68607d5f1..bff2e8b664 100644 --- a/tests/unit/out/refcount/va_arg_struct_ctx.rs +++ b/tests/unit/out/refcount/va_arg_struct_ctx.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct context { @@ -25,7 +34,15 @@ pub fn set_error_0(mut ctx: Ptr, fmt: Ptr, __args: Box<[VaArg]>) { field!(ctx, last_error).write((*ap.borrow_mut()).arg::()); } } -#[derive(VaArg, FnPtrArg, TriviallyCopyable, ByteRepr, Clone, ZeroInitialization)] +#[derive( + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + ByteRepr, + Clone, + ZeroInitialization, +)] #[byte_size(8)] pub struct value { #[offset(0)] diff --git a/tests/unit/out/refcount/va_arg_void_ptr.rs b/tests/unit/out/refcount/va_arg_void_ptr.rs index 9a7b947b8f..f852755b22 100644 --- a/tests/unit/out/refcount/va_arg_void_ptr.rs +++ b/tests/unit/out/refcount/va_arg_void_ptr.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + 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 274f49b328..24f3f3e71b 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -29,7 +29,16 @@ pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { return total; } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + DefaultConstructible, + Copyable, + Default, )] #[cpp_from(Ptr , construct, mut_ptr)] #[byte_size(16)] @@ -66,7 +75,15 @@ pub fn sum_ptr_2(n: i32, __args: Box<[VaArg]>) -> i32 { return total; } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Cursor_3 { diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index b3e7b67336..fc0ddfc548 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct S { @@ -38,6 +47,12 @@ pub struct Foo { #[byte_size(24)] pub b: Vec, } +impl DefaultConstructible for Foo { + fn default_constructor(this: &Ptr) { + field!((*this), a).write(Vec::new()); + field!((*this), b).write(Vec::new()); + } +} #[derive( Copy, Clone, @@ -47,6 +62,7 @@ pub struct Foo { VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -508,7 +524,8 @@ fn main_0() -> i32 { && ({ (*v11.borrow())[2_usize] } == 3) }) ); - let foo: Value = Rc::new(RefCell::new(::default())); + let foo: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&foo.as_pointer()); { let __a1 = 5; (*foo.borrow_mut()).a.push(__a1) diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index 6b64a33821..cc1b881f20 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -15,6 +15,7 @@ use std::rc::{Rc, Weak}; VaArg, FnPtrArg, CppFrom, + DefaultConstructible, TriviallyCopyable, Default, )] @@ -33,6 +34,7 @@ pub struct Degrees { VaArg, FnPtrArg, CppFrom, + TriviallyDefaultConstructible, TriviallyCopyable, Default, )] diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index 37fa62975d..ce4e2b4ca4 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(8)] pub struct Point { @@ -39,6 +48,12 @@ pub struct Holder { #[byte_size(24)] pub points: Vec, } +impl DefaultConstructible for Holder { + fn default_constructor(this: &Ptr) { + field!((*this), values).write(Vec::new()); + field!((*this), points).write(Vec::new()); + } +} pub fn push_and_index_0(v: Ptr>) -> i32 { { let __a1 = 42; @@ -95,7 +110,8 @@ 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))); - let h: Value = Rc::new(RefCell::new(::default())); + let h: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&h.as_pointer()); (*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 bf2a2a2fae..e8286a88f2 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -7,12 +7,30 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct TestAllocator_int_ {} #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(1)] pub struct TestAllocator_double_ {} diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 26f97d52a8..993d5af25f 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -27,6 +27,11 @@ pub struct NonTrivial { #[byte_size(24)] pub data: Vec, } +impl DefaultConstructible for NonTrivial { + fn default_constructor(this: &Ptr) { + field!((*this), data).write(Vec::new()); + } +} pub fn unused_ref_param_1(x: Ptr) {} pub fn unused_ptr_param_2(mut p: Ptr) {} thread_local!( @@ -37,7 +42,16 @@ pub fn bump_and_return_4() -> i32 { return side_effect_counter_3.with(|rc| *rc.borrow()); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, )] #[byte_size(4)] pub struct Holder { @@ -54,6 +68,11 @@ pub struct NonCopyable { #[byte_size(8)] pub value: Option>, } +impl DefaultConstructible for NonCopyable { + fn default_constructor(this: &Ptr) { + field!((*this), value).write(None); + } +} pub fn unused_noncopyable_param_5(x: Ptr) {} pub fn main() { __cpp2rust_init_globals(); @@ -102,7 +121,8 @@ 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()); - let nt: Value = Rc::new(RefCell::new(::default())); + let nt: Value = Rc::new(RefCell::new(::zero_init())); + DefaultConstructible::default_constructor(&nt.as_pointer()); ({ 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 ebd9cebebf..e759fb132e 100644 --- a/tests/unit/out/unsafe/05_new.rs +++ b/tests/unit/out/unsafe/05_new.rs @@ -8,12 +8,26 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct A {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct D {} impl D { diff --git a/tests/unit/out/unsafe/10_struct.rs b/tests/unit/out/unsafe/10_struct.rs index 613fd301d0..f4eca31939 100644 --- a/tests/unit/out/unsafe/10_struct.rs +++ b/tests/unit/out/unsafe/10_struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct GraphNode { pub dst: u32, @@ -16,7 +23,14 @@ pub struct GraphNode { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Graph { pub V: u32, @@ -44,6 +58,11 @@ impl Partial { (&raw mut self.p).write(q); } } +impl DefaultConstructibleUnsafe for Partial { + unsafe fn default_constructor(&mut self) { + (&raw mut self.p).write(std::ptr::null_mut()); + } +} impl Default for Partial { fn default() -> Self { unsafe { @@ -55,13 +74,27 @@ impl Default for Partial { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Declared {} impl Declared {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub i: i32, @@ -84,7 +117,8 @@ unsafe fn main_0() -> i32 { if ((it.p) != (arr.as_mut_ptr())) { return 1; } - let mut def: Partial = ::default(); + let mut def: Partial = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut def); 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 5e47f92c63..f341572944 100644 --- a/tests/unit/out/unsafe/addr_of_global.rs +++ b/tests/unit/out/unsafe/addr_of_global.rs @@ -8,14 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub value: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer { pub p: *mut Inner, diff --git a/tests/unit/out/unsafe/anonymous-struct.rs b/tests/unit/out/unsafe/anonymous-struct.rs index fc1e8b5c3a..41649bba63 100644 --- a/tests/unit/out/unsafe/anonymous-struct.rs +++ b/tests/unit/out/unsafe/anonymous-struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer_Named { pub a: i32, @@ -16,7 +23,14 @@ pub struct Outer_Named { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_0 { pub c: i32, @@ -24,7 +38,14 @@ pub struct anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_1 { pub g: i32, @@ -32,7 +53,14 @@ pub struct anon_1 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_2 { pub e: i32, @@ -40,21 +68,42 @@ pub struct anon_2 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_4 { pub j: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_5 { pub k: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_3 { pub i: i32, @@ -63,7 +112,14 @@ pub struct anon_3 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer { pub named: Outer_Named, @@ -121,7 +177,14 @@ unsafe fn main_0() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_6 { pub x: i32, diff --git a/tests/unit/out/unsafe/anonymous-struct_c.rs b/tests/unit/out/unsafe/anonymous-struct_c.rs index 405a2cac0b..b0a56bd075 100644 --- a/tests/unit/out/unsafe/anonymous-struct_c.rs +++ b/tests/unit/out/unsafe/anonymous-struct_c.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Named { pub a: i32, @@ -16,7 +23,14 @@ pub struct Named { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_0 { pub c: i32, @@ -24,7 +38,14 @@ pub struct anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_1 { pub g: i32, @@ -32,7 +53,14 @@ pub struct anon_1 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_2 { pub e: i32, @@ -40,21 +68,42 @@ pub struct anon_2 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_4 { pub j: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_5 { pub k: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_3 { pub i: i32, @@ -63,7 +112,14 @@ pub struct anon_3 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer { pub named: Named, @@ -127,7 +183,14 @@ unsafe fn main_0() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 f8e6e55e5f..0914fe7a73 100644 --- a/tests/unit/out/unsafe/anonymous_enum.rs +++ b/tests/unit/out/unsafe/anonymous_enum.rs @@ -14,7 +14,14 @@ pub const anon_1_SECOND_A: anon_1 = 0; pub const anon_1_SECOND_B: anon_1 = 1; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub a: i32, @@ -27,7 +34,14 @@ pub const anon_2_FIELD_A: anon_2 = 0; pub const anon_2_FIELD_B: anon_2 = 1; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct WithAnonField { pub a: i32, diff --git a/tests/unit/out/unsafe/anonymous_enum_c.rs b/tests/unit/out/unsafe/anonymous_enum_c.rs index 05055b8ed6..74794bce29 100644 --- a/tests/unit/out/unsafe/anonymous_enum_c.rs +++ b/tests/unit/out/unsafe/anonymous_enum_c.rs @@ -14,7 +14,14 @@ pub const anon_1_SECOND_A: anon_1 = 0; pub const anon_1_SECOND_B: anon_1 = 1; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub a: i32, @@ -27,7 +34,14 @@ pub const anon_2_FIELD_A: anon_2 = 0; pub const anon_2_FIELD_B: anon_2 = 1; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 855caed29d..45b278dea7 100644 --- a/tests/unit/out/unsafe/any.rs +++ b/tests/unit/out/unsafe/any.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Point { pub x: i32, diff --git a/tests/unit/out/unsafe/array_const_init.rs b/tests/unit/out/unsafe/array_const_init.rs index 2f76988087..4c1845c3e7 100644 --- a/tests/unit/out/unsafe/array_const_init.rs +++ b/tests/unit/out/unsafe/array_const_init.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub head: i32, @@ -24,7 +31,14 @@ pub static mut s_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 2625480bd5..268f5269a2 100644 --- a/tests/unit/out/unsafe/array_field_addr.rs +++ b/tests/unit/out/unsafe/array_field_addr.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 8639525a23..ce87fa9d47 100644 --- a/tests/unit/out/unsafe/array_of_noncopy_struct.rs +++ b/tests/unit/out/unsafe/array_of_noncopy_struct.rs @@ -22,6 +22,12 @@ pub struct NonCopy { pub data: Vec, pub tag: i32, } +impl DefaultConstructibleUnsafe for NonCopy { + unsafe fn default_constructor(&mut self) { + (&raw mut self.data).write(Vec::new()); + (&raw mut self.tag).write(0); + } +} impl Default for NonCopy { fn default() -> Self { unsafe { @@ -39,7 +45,11 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut arr: [NonCopy; 3] = std::array::from_fn::<_, 3, _>(|_| ::default()); + let mut arr: [NonCopy; 3] = std::array::from_fn::<_, 3, _>(|_| { + let mut __v: NonCopy = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut __v); + __v + }); arr[(0) as usize].tag = 7; { let __a1 = 42; diff --git a/tests/unit/out/unsafe/array_reference.rs b/tests/unit/out/unsafe/array_reference.rs index 77bec757c9..5f8e415d87 100644 --- a/tests/unit/out/unsafe/array_reference.rs +++ b/tests/unit/out/unsafe/array_reference.rs @@ -58,7 +58,14 @@ pub unsafe fn pick_10(s: *const [libc::c_char; 5]) -> *const [libc::c_char; 5] { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Point { pub x: i32, diff --git a/tests/unit/out/unsafe/as_const.rs b/tests/unit/out/unsafe/as_const.rs index 268e0a0336..cfe9e4b522 100644 --- a/tests/unit/out/unsafe/as_const.rs +++ b/tests/unit/out/unsafe/as_const.rs @@ -11,7 +11,14 @@ pub const Overload_kMutableOverload: Overload = 1; pub const Overload_kConstOverload: Overload = 2; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/assign_rhs_first.rs b/tests/unit/out/unsafe/assign_rhs_first.rs index 65997d2d5d..19cbba57bc 100644 --- a/tests/unit/out/unsafe/assign_rhs_first.rs +++ b/tests/unit/out/unsafe/assign_rhs_first.rs @@ -14,7 +14,14 @@ pub unsafe fn advance_1() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub ptr: *mut i32, diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index b8ee840454..d1b435ad6f 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -837,21 +837,42 @@ pub unsafe fn test_reference_members_9() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Slot_6 { pub value: *mut u32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Slot_8 { pub value: *mut i16, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Slot_10 { pub value: *mut i32, @@ -902,7 +923,14 @@ pub unsafe fn test_pointer_elements_11() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Holder_12 { pub p: *mut i32, @@ -930,7 +958,14 @@ pub unsafe fn test_reference_pointer_13() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Node_14 { pub link: *mut *mut Node_14, @@ -1005,28 +1040,56 @@ pub unsafe fn test_reference_subfields_18() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Index_16 { pub value: u32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Slot_17 { pub ref_: *mut Index_16, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Index_19 { pub value: i16, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Slot_20 { pub ref_: *mut Index_19, @@ -1068,14 +1131,28 @@ pub unsafe fn observe_24(mut assigned: i32, mut stored: *const i32) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct GlobalRecord_Inner { pub value: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct GlobalRecord { pub inner: GlobalRecord_Inner, @@ -1343,14 +1420,28 @@ static mut promoted_30: std::cell::LazyCell = std::cell::LazyCell::new(|| u static mut flag_31: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { false }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Record_32 { pub value: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Link_33 { pub next: *mut Link_33, @@ -1359,7 +1450,14 @@ pub static mut selected_values_34: std::cell::LazyCell<[u32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct IndexedBinding {} impl IndexedBinding { @@ -1580,7 +1678,14 @@ pub static mut global_rows_46: std::cell::LazyCell<[[u32; 2]; 2]> = std::cell::LazyCell::new(|| unsafe { [[0_u32, 10_u32], [20_u32, 30_u32]] }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct IndexedMember { pub key: i32, @@ -1841,7 +1946,14 @@ pub static mut scoped_pointers_53: std::cell::LazyCell<[*mut u32; 1]> = }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct PointerSelector { pub ptr: *mut u32, @@ -2013,9 +2125,21 @@ pub unsafe fn test_stable_containers_58() { pub struct Counts_59 { pub counts: Vec, } +impl DefaultConstructibleUnsafe for Counts_59 { + unsafe fn default_constructor(&mut self) { + (&raw mut self.counts).write(Vec::new()); + } +} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair_60 { pub u: u32, @@ -2319,14 +2443,28 @@ unsafe fn main_0() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Index_62 { pub value: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Owner_63 { pub values: [i32; 2], diff --git a/tests/unit/out/unsafe/bounded_struct_ptr.rs b/tests/unit/out/unsafe/bounded_struct_ptr.rs index 16f0402ee3..408ea795bd 100644 --- a/tests/unit/out/unsafe/bounded_struct_ptr.rs +++ b/tests/unit/out/unsafe/bounded_struct_ptr.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Foo { pub x1: i32, diff --git a/tests/unit/out/unsafe/bst.rs b/tests/unit/out/unsafe/bst.rs index 0058a5ad73..d66b21ad01 100644 --- a/tests/unit/out/unsafe/bst.rs +++ b/tests/unit/out/unsafe/bst.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct node_t { pub left: *mut node_t, diff --git a/tests/unit/out/unsafe/c_struct.rs b/tests/unit/out/unsafe/c_struct.rs index ff68b685b8..00cfcdd988 100644 --- a/tests/unit/out/unsafe/c_struct.rs +++ b/tests/unit/out/unsafe/c_struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Point { pub x: i32, @@ -16,7 +23,14 @@ pub struct Point { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Line { pub start: Point, @@ -24,7 +38,14 @@ pub struct Line { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Node { pub value: i32, @@ -36,7 +57,14 @@ pub const Color_GREEN: Color = 1; pub const Color_BLUE: Color = 2; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub a: i32, @@ -44,7 +72,14 @@ pub struct Inner { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 1f50aaa85e..a5affd3717 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -12,7 +12,14 @@ pub const E_B: E = 1; pub const E_C: E = 2; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub x: i32, @@ -20,14 +27,28 @@ pub struct Pair { } #[repr(C, align(64))] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Wide { pub c: libc::c_char, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Grid { pub h: i32, @@ -51,6 +72,12 @@ pub struct Bag { pub n: i32, pub items: Vec, } +impl DefaultConstructibleUnsafe for Bag { + unsafe fn default_constructor(&mut self) { + (&raw mut self.n).write(0_i32); + (&raw mut self.items).write(Vec::new()); + } +} pub unsafe fn adjacent_arrays_0() { let mut a: [i32; 4] = [1, 2, 3, 4]; let mut b: [i32; 4] = [5, 6, 7, 8]; @@ -283,7 +310,8 @@ 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))); - let mut b: Bag = ::default(); + let mut b: Bag = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut b); 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 325a9458f0..6cc29e2494 100644 --- a/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs +++ b/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs @@ -18,7 +18,14 @@ pub unsafe fn strlen_1(mut s: *mut libc::c_char) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Row { pub a: [i32; 3], diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index 750d263682..dbd48a62a6 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub first: i32, @@ -45,7 +52,14 @@ impl Pair { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Route { pub path: Pair, @@ -60,7 +74,14 @@ impl Route { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Counter { pub v: i32, @@ -84,7 +105,14 @@ impl std::cmp::PartialEq for Counter { impl std::cmp::Eq for Counter {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Tally { pub calls: i32, diff --git a/tests/unit/out/unsafe/class_template_lazy_member.rs b/tests/unit/out/unsafe/class_template_lazy_member.rs index 94e7837f31..acb08b983b 100644 --- a/tests/unit/out/unsafe/class_template_lazy_member.rs +++ b/tests/unit/out/unsafe/class_template_lazy_member.rs @@ -8,14 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Point { pub x: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Box_int_ { pub val: i32, @@ -27,7 +41,14 @@ impl Box_int_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Box_Point_ { pub val: Point, @@ -39,7 +60,14 @@ impl Box_Point_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Deduced_int_ { pub val: i32, @@ -51,7 +79,14 @@ impl Deduced_int_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Deduced_Point_ { pub val: Point, diff --git a/tests/unit/out/unsafe/class_templates.rs b/tests/unit/out/unsafe/class_templates.rs index e8129a85c2..443b017cc9 100644 --- a/tests/unit/out/unsafe/class_templates.rs +++ b/tests/unit/out/unsafe/class_templates.rs @@ -46,6 +46,11 @@ impl MyContainer_int_ { }; } } +impl DefaultConstructibleUnsafe for MyContainer_int_ { + unsafe fn default_constructor(&mut self) { + (&raw mut self.vec_).write(Vec::new()); + } +} #[repr(C)] #[derive( Clone, @@ -86,6 +91,11 @@ impl MyContainer_char_ { }; } } +impl DefaultConstructibleUnsafe for MyContainer_char_ { + unsafe fn default_constructor(&mut self) { + (&raw mut self.vec_).write(Vec::new()); + } +} #[repr(C)] #[derive( Clone, @@ -126,9 +136,21 @@ impl MyContainer_float_ { }; } } +impl DefaultConstructibleUnsafe for MyContainer_float_ { + unsafe fn default_constructor(&mut self) { + (&raw mut self.vec_).write(Vec::new()); + } +} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Boxed_short_ { pub value: i16, @@ -143,7 +165,14 @@ impl Boxed_short_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Boxed_int_ { pub value: i32, @@ -158,7 +187,14 @@ impl Boxed_int_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Boxed_long_ { pub value: i64, @@ -173,7 +209,14 @@ impl Boxed_long_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer_int__Inner_int_ { pub t: i32, @@ -186,7 +229,14 @@ impl Outer_int__Inner_int_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer_int_ { pub v: i32, @@ -198,7 +248,14 @@ impl Outer_int_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer_long__Inner_int_ { pub t: i64, @@ -211,7 +268,14 @@ impl Outer_long__Inner_int_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer_long__Inner_char_ { pub t: i64, @@ -224,7 +288,14 @@ impl Outer_long__Inner_char_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer_long_ { pub v: i64, @@ -236,7 +307,14 @@ impl Outer_long_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Elem { pub i: i32, @@ -277,7 +355,8 @@ 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(&bl, 1_i64,) }) == (8_i64))); - let mut imc: MyContainer_int_ = ::default(); + let mut imc: MyContainer_int_ = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut imc); assert!((unsafe { MyContainer_int_::empty(&imc,) })); (unsafe { let mut _item: i32 = 1; @@ -289,7 +368,8 @@ unsafe fn main_0() -> i32 { ); (unsafe { MyContainer_int_::pop_back(&mut imc) }); assert!((unsafe { MyContainer_int_::empty(&imc,) })); - let mut cmc: MyContainer_char_ = ::default(); + let mut cmc: MyContainer_char_ = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut cmc); assert!((unsafe { MyContainer_char_::empty(&cmc,) })); (unsafe { let mut _item: libc::c_char = ('a' as libc::c_char); @@ -302,7 +382,8 @@ unsafe fn main_0() -> i32 { ); (unsafe { MyContainer_char_::pop_back(&mut cmc) }); assert!((unsafe { MyContainer_char_::empty(&cmc,) })); - let mut fmc: MyContainer_float_ = ::default(); + let mut fmc: MyContainer_float_ = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut fmc); assert!((unsafe { MyContainer_float_::empty(&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 1bb270b340..9c028caa0f 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -8,14 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Bar { pub w: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Foo { pub x: i32, @@ -26,7 +40,14 @@ pub struct Foo { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Refs { pub a: *mut i32, diff --git a/tests/unit/out/unsafe/comma_operator.rs b/tests/unit/out/unsafe/comma_operator.rs index 2d4598027a..eb4f607e37 100644 --- a/tests/unit/out/unsafe/comma_operator.rs +++ b/tests/unit/out/unsafe/comma_operator.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub first: i32, diff --git a/tests/unit/out/unsafe/complex_function.rs b/tests/unit/out/unsafe/complex_function.rs index 0e2b7bebfb..6d0fe914cd 100644 --- a/tests/unit/out/unsafe/complex_function.rs +++ b/tests/unit/out/unsafe/complex_function.rs @@ -17,14 +17,28 @@ pub unsafe fn bar_2(x: *mut i32) -> *mut i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct X1 { pub v: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct X2 { pub v: *mut X1, @@ -36,7 +50,14 @@ impl X2 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct X3 { pub v: *mut X2, @@ -48,7 +69,14 @@ impl X3 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct X4 { pub v: X3, diff --git a/tests/unit/out/unsafe/compound_assign_paren.rs b/tests/unit/out/unsafe/compound_assign_paren.rs index d04fd5c815..076ee701db 100644 --- a/tests/unit/out/unsafe/compound_assign_paren.rs +++ b/tests/unit/out/unsafe/compound_assign_paren.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Item { pub flags: u8, diff --git a/tests/unit/out/unsafe/concepts.rs b/tests/unit/out/unsafe/concepts.rs index 480c879e74..23116f6ce1 100644 --- a/tests/unit/out/unsafe/concepts.rs +++ b/tests/unit/out/unsafe/concepts.rs @@ -13,7 +13,14 @@ const _: () = assert!( ); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Sized {} impl Sized { diff --git a/tests/unit/out/unsafe/constexpr_function.rs b/tests/unit/out/unsafe/constexpr_function.rs index 0ab56af31f..270760aadd 100644 --- a/tests/unit/out/unsafe/constexpr_function.rs +++ b/tests/unit/out/unsafe/constexpr_function.rs @@ -23,7 +23,14 @@ pub unsafe fn half_3(mut x: f64) -> f64 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Flag { pub v: i32, @@ -51,7 +58,14 @@ pub unsafe fn imm_7(mut b: bool) -> bool { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct P { pub v: i32, diff --git a/tests/unit/out/unsafe/constructor.rs b/tests/unit/out/unsafe/constructor.rs index c26e7350dd..8b32fe97b9 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -14,6 +14,7 @@ pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -63,7 +64,9 @@ impl Point { Point::construct_2(&mut *self, { v }, { ((v) + (1)) }); self.y *= 10; } - pub unsafe fn construct_3(&mut self) { +} +impl DefaultConstructibleUnsafe for Point { + unsafe fn default_constructor(&mut self) { Point::construct_1(&mut *self, { 4 }); self.x += 100; } @@ -73,7 +76,7 @@ impl Default for Point { unsafe { { let mut __v: Point = ::zero_init(); - Point::construct_3(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -97,7 +100,7 @@ unsafe fn main_0() -> i32 { } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (18))); let mut p: Point = ::zero_init(); - Point::construct_3(&mut p); + DefaultConstructibleUnsafe::default_constructor(&mut p); assert!(((p.x) == (104))); assert!(((p.y) == (50))); let mut q: Point = ::zero_init(); diff --git a/tests/unit/out/unsafe/container_element_receiver.rs b/tests/unit/out/unsafe/container_element_receiver.rs index 65a02fe5f0..257c22fb8f 100644 --- a/tests/unit/out/unsafe/container_element_receiver.rs +++ b/tests/unit/out/unsafe/container_element_receiver.rs @@ -12,7 +12,7 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, CopyAssignableUnsafe, diff --git a/tests/unit/out/unsafe/container_field_addr.rs b/tests/unit/out/unsafe/container_field_addr.rs index 366e060d2e..bcd097a4ca 100644 --- a/tests/unit/out/unsafe/container_field_addr.rs +++ b/tests/unit/out/unsafe/container_field_addr.rs @@ -23,6 +23,12 @@ pub struct S { pub tag: i32, pub v: Vec, } +impl DefaultConstructibleUnsafe for S { + unsafe fn default_constructor(&mut self) { + (&raw mut self.tag).write(0_i32); + (&raw mut self.v).write(Vec::new()); + } +} pub unsafe fn add_0(mut v: *mut Vec, mut k: i32) { { let a0_clone = k.clone(); @@ -53,10 +59,15 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut local: S = ::default(); + let mut local: S = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut local); local.tag = 7; (unsafe { run_1((&mut local as *mut S)) }); - let mut heap: *mut S = (Box::leak(Box::new(::default())) as *mut S); + let mut heap: *mut S = { + let __p: *mut S = Box::leak(Box::new(::zero_init())); + DefaultConstructibleUnsafe::default_constructor(&mut *__p); + __p + }; (*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 a80b02ea99..292c0bd955 100644 --- a/tests/unit/out/unsafe/conversion_operator_same_translation.rs +++ b/tests/unit/out/unsafe/conversion_operator_same_translation.rs @@ -14,6 +14,7 @@ use std::rc::Rc; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -38,6 +39,7 @@ impl S { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 2b5b3bdd0c..3e580b961b 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -8,7 +8,9 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub static mut assigns_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MovableUnsafe, Default)] +#[derive( + VaArg, FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MovableUnsafe, Default, +)] pub struct Partial { pub v: i32, pub keep: i32, @@ -52,9 +54,6 @@ pub struct NonConstAssign { pub mark: i32, } impl NonConstAssign { - pub unsafe fn construct(&mut self) { - (&raw mut self.mark).write(0); - } pub unsafe fn operator_assign_2(&mut self, o: *mut NonConstAssign) -> *mut NonConstAssign { self.mark = (((*o).mark) + (1)); return &mut (*(self as *mut NonConstAssign)); @@ -64,12 +63,17 @@ impl NonConstAssign { return &mut (*(self as *mut NonConstAssign)); } } +impl DefaultConstructibleUnsafe for NonConstAssign { + unsafe fn default_constructor(&mut self) { + (&raw mut self.mark).write(0); + } +} impl Default for NonConstAssign { fn default() -> Self { unsafe { { let mut __v: NonConstAssign = ::zero_init(); - NonConstAssign::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -89,8 +93,8 @@ impl Default for NonConstAssign { pub struct RefQualified { pub mark: i32, } -impl RefQualified { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for RefQualified { + unsafe fn default_constructor(&mut self) { (&raw mut self.mark).write(0); } } @@ -105,7 +109,7 @@ impl Default for RefQualified { unsafe { { let mut __v: RefQualified = ::zero_init(); - RefQualified::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -117,7 +121,7 @@ impl Default for RefQualified { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, SwappableUnsafe, @@ -135,7 +139,7 @@ pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MovableUnsafe, Default, @@ -171,7 +175,7 @@ impl Clone for CopyCounted { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, SwappableUnsafe, @@ -204,6 +208,11 @@ impl CopyAssignableUnsafe for ExplicitOperatorCall { return &mut (*(self as *mut ExplicitOperatorCall)); } } +impl DefaultConstructibleUnsafe for ExplicitOperatorCall { + unsafe fn default_constructor(&mut self) { + (&raw mut self.w).write(Vec::new()); + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -272,21 +281,21 @@ unsafe fn main_0() -> i32 { 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))); let mut n: NonConstAssign = ::zero_init(); - NonConstAssign::construct(&mut n); + DefaultConstructibleUnsafe::default_constructor(&mut n); let mut n1: NonConstAssign = ::zero_init(); - NonConstAssign::construct(&mut n1); + DefaultConstructibleUnsafe::default_constructor(&mut n1); let mut n2: NonConstAssign = ::zero_init(); - NonConstAssign::construct(&mut n2); + DefaultConstructibleUnsafe::default_constructor(&mut n2); let mut cn: NonConstAssign = ::zero_init(); - NonConstAssign::construct(&mut cn); + DefaultConstructibleUnsafe::default_constructor(&mut cn); (unsafe { NonConstAssign::operator_assign_2(&mut n1, &mut n) }); (unsafe { NonConstAssign::operator_assign_3(&mut n2, &cn) }); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); let mut r: RefQualified = ::zero_init(); - RefQualified::construct(&mut r); + DefaultConstructibleUnsafe::default_constructor(&mut r); let mut r1: RefQualified = ::zero_init(); - RefQualified::construct(&mut r1); + DefaultConstructibleUnsafe::default_constructor(&mut r1); (unsafe { CopyAssignableUnsafe::copy_assign(&mut r1, &r) }); assert!(((r1.mark) == (1))); let mut h2: Holder = Holder { @@ -362,8 +371,10 @@ unsafe fn main_0() -> i32 { && ((hc1.arr[(1) as usize].v) == (6)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (0))); - let mut e1: ExplicitOperatorCall = ::default(); - let mut e2: ExplicitOperatorCall = ::default(); + let mut e1: ExplicitOperatorCall = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut e1); + let mut e2: ExplicitOperatorCall = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut e2); { let __a1 = 5; e1.w.push(__a1) diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index f5e2d0c867..34df69c218 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -13,7 +13,7 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MovableUnsafe, Default, @@ -58,9 +58,6 @@ pub struct NonConst { pub mark: i32, } impl NonConst { - pub unsafe fn construct(&mut self) { - (&raw mut self.mark).write(0); - } pub unsafe fn construct_1(&mut self, o: *mut NonConst) { (&raw mut self.mark).write((((*o).mark) + (1))); } @@ -68,6 +65,11 @@ impl NonConst { (&raw mut self.mark).write((((*o).mark) + (10))); } } +impl DefaultConstructibleUnsafe for NonConst { + unsafe fn default_constructor(&mut self) { + (&raw mut self.mark).write(0); + } +} impl Clone for NonConst { fn clone(&self) -> Self { unsafe { @@ -82,7 +84,7 @@ impl Default for NonConst { unsafe { { let mut __v: NonConst = ::zero_init(); - NonConst::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -94,7 +96,7 @@ impl Default for NonConst { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MovableUnsafe, Default, @@ -130,7 +132,7 @@ impl Clone for Ignored { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, SwappableUnsafe, @@ -147,7 +149,7 @@ pub struct Holder { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, @@ -184,7 +186,7 @@ impl Clone for Box_int_ { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, @@ -201,7 +203,7 @@ pub struct Owner { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MovableUnsafe, Default, @@ -236,6 +238,11 @@ impl Clone for OutOfLine { pub struct Tracked { pub copied_from: i32, } +impl DefaultConstructibleUnsafe for Tracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.copied_from).write(0); + } +} impl CopyConstructibleUnsafe for Tracked { unsafe fn copy_constructor(&mut self, o: *const Tracked) { (&raw mut self.copied_from).write(0); @@ -371,21 +378,23 @@ unsafe fn main_0() -> i32 { assert!(((ol2.v) == (105))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (12))); let mut n: NonConst = ::zero_init(); - NonConst::construct(&mut n); + DefaultConstructibleUnsafe::default_constructor(&mut n); let mut n1: NonConst = ::zero_init(); NonConst::construct_1(&mut n1, { &mut n }); let mut cn: NonConst = ::zero_init(); - NonConst::construct(&mut cn); + DefaultConstructibleUnsafe::default_constructor(&mut cn); let mut n2: NonConst = ::zero_init(); NonConst::construct_2(&mut n2, { &cn }); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); - let mut t1: Tracked = ::default(); + let mut t1: Tracked = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut t1); let mut t2: Tracked = ::zero_init(); CopyConstructibleUnsafe::copy_constructor(&mut t2, { &t1 }); (unsafe { CopyAssignableUnsafe::copy_assign(&mut t2, &t1) }); assert!(((t1.copied_from) == (2))); - let ct: Tracked = ::default(); + let mut ct: Tracked = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut ct); let mut t3: Tracked = ::zero_init(); CopyConstructibleUnsafe::copy_constructor(&mut t3, { &ct }); (unsafe { touch_1((&ct as *const Tracked)) }); diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 3addbd8a8d..84c9ee1bee 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub x: i32, @@ -20,6 +27,7 @@ pub struct Inner { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MoveConstructibleUnsafe, @@ -45,7 +53,14 @@ impl DestructibleUnsafe for Explicit { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Implicit { pub v: i32, @@ -60,7 +75,7 @@ pub struct Implicit { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, SwappableUnsafe, @@ -95,7 +110,7 @@ impl MoveAssignableUnsafe for DefaultCopyUserMove { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, @@ -135,7 +150,7 @@ impl Clone for UserCopyDefaultMove { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, @@ -176,6 +191,14 @@ pub struct Owner { pub arr: [i32; 2], pub p: Option>, } +impl DefaultConstructibleUnsafe for Owner { + unsafe fn default_constructor(&mut self) { + (&raw mut self.data).write(Vec::new()); + (&raw mut self.n).write(0_i32); + (&raw mut self.arr).write([0_i32; 2]); + (&raw mut self.p).write(None); + } +} #[repr(C)] #[derive( Clone, @@ -192,12 +215,17 @@ pub struct Owner { pub struct Copyable { pub data: Vec, } +impl DefaultConstructibleUnsafe for Copyable { + unsafe fn default_constructor(&mut self) { + (&raw mut self.data).write(Vec::new()); + } +} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, @@ -239,6 +267,11 @@ impl MoveAssignableUnsafe for SeesThis { return &mut (*(self as *mut SeesThis)); } } +impl DefaultConstructibleUnsafe for SeesThis { + unsafe fn default_constructor(&mut self) { + (&raw mut self.self_).write(std::ptr::null_mut()); + } +} impl Default for SeesThis { fn default() -> Self { unsafe { @@ -255,12 +288,24 @@ pub struct HasSeesThis { pub s: SeesThis, pub v: Vec, } +impl DefaultConstructibleUnsafe for HasSeesThis { + unsafe fn default_constructor(&mut self) { + DefaultConstructibleUnsafe::default_constructor(&mut self.s); + (&raw mut self.v).write(Vec::new()); + } +} #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe)] pub struct Counted_int_ { pub v: i32, pub moves: i32, } +impl DefaultConstructibleUnsafe for Counted_int_ { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write(0_i32); + (&raw mut self.moves).write(0); + } +} impl MoveConstructibleUnsafe for Counted_int_ { unsafe fn move_constructor(&mut self, o: *mut Counted_int_) { (&raw mut self.v).write((*o).v); @@ -293,6 +338,12 @@ pub struct HasCounted { pub c: Counted_int_, pub w: Vec, } +impl DefaultConstructibleUnsafe for HasCounted { + unsafe fn default_constructor(&mut self) { + DefaultConstructibleUnsafe::default_constructor(&mut self.c); + (&raw mut self.w).write(Vec::new()); + } +} #[repr(C)] #[derive( VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, @@ -303,15 +354,17 @@ pub struct CtorSeesThis { pub id: i32, } impl CtorSeesThis { - pub unsafe fn construct_2(&mut self) { - (&raw mut self.self_).write((self as *mut CtorSeesThis)); - (&raw mut self.id).write(0); - } pub unsafe fn construct_1(&mut self, mut id: i32) { - CtorSeesThis::construct_2(&mut *self); + DefaultConstructibleUnsafe::default_constructor(&mut *self); self.id = id; } } +impl DefaultConstructibleUnsafe for CtorSeesThis { + unsafe fn default_constructor(&mut self) { + (&raw mut self.self_).write((self as *mut CtorSeesThis)); + (&raw mut self.id).write(0); + } +} impl CopyConstructibleUnsafe for CtorSeesThis { unsafe fn copy_constructor(&mut self, _a0: *const CtorSeesThis) { (&raw mut self.self_).write((self as *mut CtorSeesThis)); @@ -348,7 +401,7 @@ impl Default for CtorSeesThis { unsafe { { let mut __v: CtorSeesThis = ::zero_init(); - CtorSeesThis::construct_2(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -370,9 +423,9 @@ pub struct HasCtorSeesThis { pub x: CtorSeesThis, pub v: Vec, } -impl HasCtorSeesThis { - pub unsafe fn construct_1(&mut self) { - CtorSeesThis::construct_2(&mut self.x); +impl DefaultConstructibleUnsafe for HasCtorSeesThis { + unsafe fn default_constructor(&mut self) { + DefaultConstructibleUnsafe::default_constructor(&mut self.x); (&raw mut self.v).write(Vec::new()); } } @@ -391,8 +444,8 @@ pub struct InitsCtorSeesThis { pub x: CtorSeesThis, pub y: CtorSeesThis, } -impl InitsCtorSeesThis { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for InitsCtorSeesThis { + unsafe fn default_constructor(&mut self) { CtorSeesThis::construct_1(&mut self.x, { 1 }); CtorSeesThis::construct_1(&mut self.y, { 2 }); } @@ -402,7 +455,7 @@ impl Default for InitsCtorSeesThis { unsafe { { let mut __v: InitsCtorSeesThis = ::zero_init(); - InitsCtorSeesThis::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -419,7 +472,7 @@ pub struct OutOfLineDefaulted { } impl OutOfLineDefaulted { pub unsafe fn construct(&mut self) { - CtorSeesThis::construct_2(&mut self.x); + DefaultConstructibleUnsafe::default_constructor(&mut self.x); (&raw mut self.v).write(1); } } @@ -438,6 +491,13 @@ impl Clone for OutOfLineDefaulted { } } } +impl DefaultConstructibleUnsafe for OutOfLineDefaulted { + unsafe fn default_constructor(&mut self) { + unsafe { + OutOfLineDefaulted::construct(&mut *self); + } + } +} impl Default for OutOfLineDefaulted { fn default() -> Self { unsafe { @@ -457,6 +517,13 @@ pub struct OutOfLineAssign { pub v: i32, pub w: Vec, } +impl DefaultConstructibleUnsafe for OutOfLineAssign { + unsafe fn default_constructor(&mut self) { + DefaultConstructibleUnsafe::default_constructor(&mut self.s); + (&raw mut self.v).write(1); + (&raw mut self.w).write(Vec::new()); + } +} impl Default for OutOfLineAssign { fn default() -> Self { unsafe { @@ -646,7 +713,8 @@ unsafe fn main_0() -> i32 { (((bufs[(1_usize)].n) == (3)) && ((bufs[(1_usize)].data.len()) == (3_usize))) && (bufs[(0_usize)].data.is_empty()) ); - let mut o1: Owner = ::default(); + let mut o1: Owner = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut o1); { let __a1 = 5; o1.data.push(__a1) @@ -680,7 +748,8 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - let mut o3: Owner = ::default(); + let mut o3: Owner = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut o3); (unsafe { MoveAssignableUnsafe::move_assign(&mut o3, &mut o2) }); assert!( ((((o3.n) == (5)) && ((o3.data[(0_usize)]) == (5))) && ((o3.arr[(0) as usize]) == (5))) @@ -706,7 +775,8 @@ unsafe fn main_0() -> i32 { MoveConstructibleUnsafe::move_constructor(&mut c3, { &mut c1 }); assert!(((c2.data.len()) == (2_usize)) && ((c3.data.len()) == (2_usize))); assert!(c1.data.is_empty()); - let mut c4: Copyable = ::default(); + let mut c4: Copyable = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut c4); (unsafe { MoveAssignableUnsafe::move_assign(&mut c4, &mut c3) }); assert!(((c4.data[(1_usize)]) == (2)) && (c3.data.is_empty())); let mut h1: Holder = ::zero_init(); @@ -759,23 +829,28 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - let mut t1: HasSeesThis = ::default(); - let mut t2: HasSeesThis = ::default(); - let mut t3: HasSeesThis = ::default(); + let mut t1: HasSeesThis = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut t1); + let mut t2: HasSeesThis = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut t2); + let mut t3: HasSeesThis = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut t3); (unsafe { MoveAssignableUnsafe::move_assign(&mut t2, &mut t1) }); assert!(((t2.s.self_) == (&mut t2.s as *mut SeesThis))); (unsafe { CopyAssignableUnsafe::copy_assign(&mut t3, &t2) }); assert!(((t3.s.self_) == (&mut t3.s as *mut SeesThis))); - let mut k1: HasCounted = ::default(); + let mut k1: HasCounted = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut k1); let mut k2: HasCounted = ::zero_init(); MoveConstructibleUnsafe::move_constructor(&mut k2, { &mut k1 }); assert!(((k2.c.moves) == (1))); - let mut k3: HasCounted = ::default(); + let mut k3: HasCounted = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut k3); (unsafe { MoveAssignableUnsafe::move_assign(&mut k3, &mut k2) }); assert!(((k3.c.moves) == (2))); { let mut d: CtorSeesThis = ::zero_init(); - CtorSeesThis::construct_2(&mut d); + DefaultConstructibleUnsafe::default_constructor(&mut d); assert!(((d.self_) == (&mut d as *mut CtorSeesThis))); let mut e: CtorSeesThis = ::zero_init(); CopyConstructibleUnsafe::copy_constructor(&mut e, { &d }); @@ -784,7 +859,7 @@ unsafe fn main_0() -> i32 { CtorSeesThis::construct_1(&mut f, { 3 }); assert!(((f.self_) == (&mut f as *mut CtorSeesThis)) && ((f.id) == (3))); let mut h1: HasCtorSeesThis = ::zero_init(); - HasCtorSeesThis::construct_1(&mut h1); + DefaultConstructibleUnsafe::default_constructor(&mut h1); assert!(((h1.x.self_) == (&mut h1.x as *mut CtorSeesThis))); let mut h2: HasCtorSeesThis = ::zero_init(); CopyConstructibleUnsafe::copy_constructor(&mut h2, { &h1 }); @@ -797,7 +872,7 @@ unsafe fn main_0() -> i32 { (unsafe { CopyAssignableUnsafe::copy_assign(&mut h2, &h1) }); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); let mut i: InitsCtorSeesThis = ::zero_init(); - InitsCtorSeesThis::construct(&mut i); + DefaultConstructibleUnsafe::default_constructor(&mut i); assert!(((i.x.self_) == (&mut i.x as *mut CtorSeesThis)) && ((i.x.id) == (1))); assert!(((i.y.self_) == (&mut i.y as *mut CtorSeesThis)) && ((i.y.id) == (2))); let mut p: *mut CtorSeesThis = { @@ -819,9 +894,12 @@ unsafe fn main_0() -> i32 { let mut o2: OutOfLineDefaulted = ::zero_init(); CopyConstructibleUnsafe::copy_constructor(&mut o2, { &o1 }); assert!(((o2.v) == (2)) && ((o2.x.self_) == (&mut o2.x as *mut CtorSeesThis))); - let mut a1: OutOfLineAssign = ::default(); - let mut a2: OutOfLineAssign = ::default(); - let mut a3: OutOfLineAssign = ::default(); + let mut a1: OutOfLineAssign = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut a1); + let mut a2: OutOfLineAssign = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut a2); + let mut a3: OutOfLineAssign = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut a3); a1.v = 3; { let __a1 = 4; diff --git a/tests/unit/out/unsafe/copy_move_deleted.rs b/tests/unit/out/unsafe/copy_move_deleted.rs index 7a8826e6c0..7c292af683 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.rs @@ -8,7 +8,12 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, Default, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DefaultInitializableUnsafe, + SwappableUnsafe, + Default, )] #[cpp_from(i32, construct, value)] pub struct NoCopy { @@ -37,8 +42,8 @@ impl MoveAssignableUnsafe for NoCopy { pub struct PrivateCopy { pub v: i32, } -impl PrivateCopy { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for PrivateCopy { + unsafe fn default_constructor(&mut self) { (&raw mut self.v).write(0); } } @@ -60,7 +65,7 @@ impl Default for PrivateCopy { unsafe { { let mut __v: PrivateCopy = ::zero_init(); - PrivateCopy::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -71,8 +76,8 @@ impl Default for PrivateCopy { pub struct Immovable { pub v: i32, } -impl Immovable { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for Immovable { + unsafe fn default_constructor(&mut self) { (&raw mut self.v).write(0); } } @@ -81,7 +86,7 @@ impl Default for Immovable { unsafe { { let mut __v: Immovable = ::zero_init(); - Immovable::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -91,7 +96,7 @@ impl Default for Immovable { #[derive( FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, @@ -114,6 +119,11 @@ pub struct Container { pub struct VecHolder { pub items: Vec, } +impl DefaultConstructibleUnsafe for VecHolder { + unsafe fn default_constructor(&mut self) { + (&raw mut self.items).write(Vec::new()); + } +} pub unsafe fn bump_0(mut p: *mut NoCopy) { (*p).v.postfix_inc(); } @@ -137,7 +147,7 @@ unsafe fn main_0() -> i32 { (unsafe { bump_0((&mut a as *mut NoCopy)) }); assert!(((a.v) == (2))); let mut p: PrivateCopy = ::zero_init(); - PrivateCopy::construct(&mut p); + DefaultConstructibleUnsafe::default_constructor(&mut p); p.v = 3; let mut q: PrivateCopy = ::zero_init(); MoveConstructibleUnsafe::move_constructor(&mut q, { &mut p }); @@ -145,7 +155,7 @@ unsafe fn main_0() -> i32 { (unsafe { MoveAssignableUnsafe::move_assign(&mut p, &mut q) }); assert!(((p.v) == (3)) && ((q.v) == (0))); let mut im: Immovable = ::zero_init(); - Immovable::construct(&mut im); + DefaultConstructibleUnsafe::default_constructor(&mut im); im.v = 4; (unsafe { bump_ref_1(&mut im) }); let mut pim: *mut Immovable = (&mut im as *mut Immovable); @@ -161,7 +171,8 @@ unsafe fn main_0() -> i32 { let mut d: Container = ::zero_init(); MoveConstructibleUnsafe::move_constructor(&mut d, { &mut c }); assert!((((d.inner.v) == (6)) && ((d.tag) == (7))) && ((c.inner.v) == (0))); - let mut h: VecHolder = ::default(); + let mut h: VecHolder = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut h); let mut h2: VecHolder = ::zero_init(); MoveConstructibleUnsafe::move_constructor(&mut h2, { &mut h }); assert!(((h2.items.len()) == (0_usize))); diff --git a/tests/unit/out/unsafe/default.rs b/tests/unit/out/unsafe/default.rs index 7a7e47d5e3..a192846a4e 100644 --- a/tests/unit/out/unsafe/default.rs +++ b/tests/unit/out/unsafe/default.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pointers { pub x1: *mut i32, @@ -19,7 +26,14 @@ pub struct Pointers { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct SmallArrays { pub a: [i32; 32], @@ -28,7 +42,15 @@ pub struct SmallArrays { pub p: [Pointers; 2], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub struct BigArray { pub a: [i32; 33], } diff --git a/tests/unit/out/unsafe/default_function_arguments.rs b/tests/unit/out/unsafe/default_function_arguments.rs index 78d8544017..1ea5ec908a 100644 --- a/tests/unit/out/unsafe/default_function_arguments.rs +++ b/tests/unit/out/unsafe/default_function_arguments.rs @@ -25,6 +25,13 @@ impl Bar { (&raw mut self.v).write(v); } } +impl DefaultConstructibleUnsafe for Bar { + unsafe fn default_constructor(&mut self) { + unsafe { + Bar::construct(&mut *self, { 1 }); + } + } +} impl Default for Bar { fn default() -> Self { unsafe { @@ -64,7 +71,14 @@ pub unsafe fn first_9(r: *mut [i32; 3]) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Holder_int_ { pub v: i32, diff --git a/tests/unit/out/unsafe/default_in_statics.rs b/tests/unit/out/unsafe/default_in_statics.rs index 34002d7223..b6fea9700d 100644 --- a/tests/unit/out/unsafe/default_in_statics.rs +++ b/tests/unit/out/unsafe/default_in_statics.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub v: i32, @@ -16,7 +23,14 @@ pub struct Inner { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer { pub p1: *mut i32, @@ -30,7 +44,14 @@ pub struct Outer { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Foo { pub s1: *const libc::c_char, diff --git a/tests/unit/out/unsafe/delete_array_order.rs b/tests/unit/out/unsafe/delete_array_order.rs index c2ab8fcfbf..485dbff706 100644 --- a/tests/unit/out/unsafe/delete_array_order.rs +++ b/tests/unit/out/unsafe/delete_array_order.rs @@ -12,6 +12,7 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index 15b5d3977c..e2e15135cb 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -13,6 +13,7 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -31,6 +32,7 @@ impl DestructibleUnsafe for S { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, @@ -48,6 +50,7 @@ pub struct Defaulted { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, @@ -66,6 +69,7 @@ pub struct Middle { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, @@ -84,6 +88,7 @@ pub struct Outer { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, @@ -102,6 +107,7 @@ pub struct ArrayMember { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -122,6 +128,7 @@ impl DestructibleUnsafe for EmptyBody { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -144,6 +151,7 @@ impl DestructibleUnsafe for Templated_char_ { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -166,6 +174,7 @@ impl DestructibleUnsafe for Templated_int_ { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -189,6 +198,7 @@ pub static mut order_count_2: std::cell::LazyCell = std::cell::LazyCell::ne VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -211,6 +221,7 @@ impl DestructibleUnsafe for Tagged { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index 871d406641..3295a48960 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -14,6 +14,7 @@ pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| un VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -38,7 +39,14 @@ pub unsafe fn with_default_3(mut s: S) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Holder { pub v: i32, diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index e9957badc9..7f127cade6 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -14,6 +14,7 @@ pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| un VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -40,6 +41,7 @@ impl DestructibleUnsafe for S { VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, diff --git a/tests/unit/out/unsafe/doubly_linked_list.rs b/tests/unit/out/unsafe/doubly_linked_list.rs index 49791e76f9..dc47af772b 100644 --- a/tests/unit/out/unsafe/doubly_linked_list.rs +++ b/tests/unit/out/unsafe/doubly_linked_list.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Node { pub val: i32, diff --git a/tests/unit/out/unsafe/enum_default_in_static.rs b/tests/unit/out/unsafe/enum_default_in_static.rs index 5cad8e0ea3..4b5e366821 100644 --- a/tests/unit/out/unsafe/enum_default_in_static.rs +++ b/tests/unit/out/unsafe/enum_default_in_static.rs @@ -12,7 +12,14 @@ pub const Mode_MODE_ONE: Mode = 1; pub const Mode_MODE_TWO: Mode = 2; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 465cf425c9..8a143f7963 100644 --- a/tests/unit/out/unsafe/enum_int_interop.rs +++ b/tests/unit/out/unsafe/enum_int_interop.rs @@ -21,7 +21,14 @@ pub const Tag_TAG_ONE: Tag = 1; pub const Tag_TAG_TWO: Tag = 2; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Entry { pub name: *const libc::c_char, diff --git a/tests/unit/out/unsafe/enum_int_interop_c.rs b/tests/unit/out/unsafe/enum_int_interop_c.rs index 196efb71de..c2b02f1435 100644 --- a/tests/unit/out/unsafe/enum_int_interop_c.rs +++ b/tests/unit/out/unsafe/enum_int_interop_c.rs @@ -21,7 +21,14 @@ pub const Tag_enum_TAG_ONE: Tag_enum = 1; pub const Tag_enum_TAG_TWO: Tag_enum = 2; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 df814b3919..0e4a01774d 100644 --- a/tests/unit/out/unsafe/enum_underlying_type.rs +++ b/tests/unit/out/unsafe/enum_underlying_type.rs @@ -30,6 +30,11 @@ pub type Empty = bool; pub struct HoldsEmpty { pub e: Empty, } +impl DefaultConstructibleUnsafe for HoldsEmpty { + unsafe fn default_constructor(&mut self) { + (&raw mut self.e).write(false); + } +} impl Default for HoldsEmpty { fn default() -> Self { unsafe { HoldsEmpty { e: false } } @@ -68,7 +73,8 @@ 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))); - let mut he: HoldsEmpty = ::default(); + let mut he: HoldsEmpty = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut he); 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 587c772493..496aac9ce2 100644 --- a/tests/unit/out/unsafe/exprs.rs +++ b/tests/unit/out/unsafe/exprs.rs @@ -8,14 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct X { pub x: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Y { pub x: X, diff --git a/tests/unit/out/unsafe/fft.rs b/tests/unit/out/unsafe/fft.rs index 4b58094771..77b617c94d 100644 --- a/tests/unit/out/unsafe/fft.rs +++ b/tests/unit/out/unsafe/fft.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Complex { pub re: f64, diff --git a/tests/unit/out/unsafe/field_aliasing.rs b/tests/unit/out/unsafe/field_aliasing.rs index ae45a46254..5f3bd26f5a 100644 --- a/tests/unit/out/unsafe/field_aliasing.rs +++ b/tests/unit/out/unsafe/field_aliasing.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct In { pub x: i32, @@ -16,7 +23,14 @@ pub struct In { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub in_: In, @@ -26,7 +40,14 @@ pub struct S { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 9d94aafcd0..5550ca4167 100644 --- a/tests/unit/out/unsafe/field_array_elem_ptr.rs +++ b/tests/unit/out/unsafe/field_array_elem_ptr.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Point { pub x: i32, @@ -16,7 +23,14 @@ pub struct Point { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Shape { pub id: i32, diff --git a/tests/unit/out/unsafe/field_method_receiver.rs b/tests/unit/out/unsafe/field_method_receiver.rs index b09f1527c6..2b5cd1dfa4 100644 --- a/tests/unit/out/unsafe/field_method_receiver.rs +++ b/tests/unit/out/unsafe/field_method_receiver.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Counter { pub n: i32, @@ -55,6 +62,14 @@ impl S { }); } } +impl DefaultConstructibleUnsafe for S { + unsafe fn default_constructor(&mut self) { + (&raw mut self.tag).write(0_i32); + (&raw mut self.c).write(::default()); + (&raw mut self.arr).write([::default(); 2]); + (&raw mut self.v).write(Vec::new()); + } +} pub unsafe fn run_0(mut o: *mut S) { (unsafe { Counter::add(&mut (*o).c, 2) }); assert!(((unsafe { Counter::get(&(*o).c,) }) == (2))); diff --git a/tests/unit/out/unsafe/field_pointers.rs b/tests/unit/out/unsafe/field_pointers.rs index df6ff0c4d5..3dd4ad79f0 100644 --- a/tests/unit/out/unsafe/field_pointers.rs +++ b/tests/unit/out/unsafe/field_pointers.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub a: i32, @@ -16,7 +23,14 @@ pub struct Inner { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Header { pub tag: i32, @@ -57,6 +71,16 @@ impl Outer { }; } } +impl DefaultConstructibleUnsafe for Outer { + unsafe fn default_constructor(&mut self) { + (&raw mut self.x).write(0_i32); + (&raw mut self.inner).write(::default()); + (&raw mut self.items).write([::default(); 3]); + (&raw mut self.v).write(Vec::new()); + (&raw mut self.cursor).write(std::ptr::null_mut()); + (&raw mut self.buf).write([0_i32; 4]); + } +} pub unsafe fn set_0(mut p: *mut i32, mut value: i32) { (*p) = value; } diff --git a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs index 599048e691..a7ac86a38a 100644 --- a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs +++ b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub a: i32, diff --git a/tests/unit/out/unsafe/field_reinterpret_write_through.rs b/tests/unit/out/unsafe/field_reinterpret_write_through.rs index 322d84a1ac..8e75578838 100644 --- a/tests/unit/out/unsafe/field_reinterpret_write_through.rs +++ b/tests/unit/out/unsafe/field_reinterpret_write_through.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct In { pub a: i16, @@ -16,7 +23,14 @@ pub struct In { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 d6a9669f68..8a91f42547 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct P { pub x: i32, 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 c8d27d5f2d..0c54613d31 100644 --- a/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs +++ b/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct In { pub a: i16, @@ -16,7 +23,14 @@ pub struct In { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 10998b103e..d3f4ab0bee 100644 --- a/tests/unit/out/unsafe/first_member_downcast.rs +++ b/tests/unit/out/unsafe/first_member_downcast.rs @@ -8,14 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct base { pub kind: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 bd098b41b0..8750661ff8 100644 --- a/tests/unit/out/unsafe/flex_array_member_incomplete.rs +++ b/tests/unit/out/unsafe/flex_array_member_incomplete.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub struct F { pub n: i32, pub tail: [libc::c_char; 0], 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 ab6c9a3511..752bdf1574 100644 --- a/tests/unit/out/unsafe/flex_array_member_sibling_write.rs +++ b/tests/unit/out/unsafe/flex_array_member_sibling_write.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub n: i32, @@ -16,7 +23,14 @@ pub struct S { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct E { pub id: i32, @@ -24,7 +38,14 @@ pub struct E { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 edc159f955..3be14a6a1b 100644 --- a/tests/unit/out/unsafe/fn_ptr.rs +++ b/tests/unit/out/unsafe/fn_ptr.rs @@ -39,6 +39,7 @@ pub unsafe fn identity_hash_6(mut v: bool) -> usize { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] diff --git a/tests/unit/out/unsafe/fn_ptr_cast.rs b/tests/unit/out/unsafe/fn_ptr_cast.rs index 825705351a..d7985a0583 100644 --- a/tests/unit/out/unsafe/fn_ptr_cast.rs +++ b/tests/unit/out/unsafe/fn_ptr_cast.rs @@ -31,7 +31,14 @@ pub unsafe fn test_double_cast_2() { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Command { pub data: *mut ::libc::c_void, diff --git a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs index df7044da69..104280bce2 100644 --- a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs +++ b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Item { pub key: i32, diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index 5caba87dc5..2dfe9fcc22 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Handler { pub tag: i32, @@ -22,7 +29,14 @@ pub unsafe fn negate_1(mut x: i32) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S {} impl S { @@ -37,7 +51,9 @@ impl S { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, +)] #[cpp_from(i32, construct, value)] pub struct MoveOnly { pub data_: i32, diff --git a/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs b/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs index 1d944e9e7a..f9c0c8fd7e 100644 --- a/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs +++ b/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs @@ -20,7 +20,14 @@ pub unsafe fn via_size_t_return_3(mut b: u64) -> usize { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 7cf2c23e14..26dce17a82 100644 --- a/tests/unit/out/unsafe/fn_ptr_vtable.rs +++ b/tests/unit/out/unsafe/fn_ptr_vtable.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Vtable { pub create: Option *mut ::libc::c_void>, diff --git a/tests/unit/out/unsafe/fn_ref.rs b/tests/unit/out/unsafe/fn_ref.rs index b4d5eef237..85484ae166 100644 --- a/tests/unit/out/unsafe/fn_ref.rs +++ b/tests/unit/out/unsafe/fn_ref.rs @@ -23,7 +23,14 @@ pub unsafe fn call_forwarded_4(f: Option i32>, mut x: i32) -> } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Holder { pub f: Option i32>, diff --git a/tests/unit/out/unsafe/for_body_destructor.rs b/tests/unit/out/unsafe/for_body_destructor.rs index 6d98c6f0fb..f06ca860aa 100644 --- a/tests/unit/out/unsafe/for_body_destructor.rs +++ b/tests/unit/out/unsafe/for_body_destructor.rs @@ -12,6 +12,7 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, diff --git a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs index eee6559f8c..2dd1a83093 100644 --- a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs @@ -23,6 +23,12 @@ pub struct S { pub v: Vec, pub a: i32, } +impl DefaultConstructibleUnsafe for S { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write(Vec::new()); + (&raw mut self.a).write(0_i32); + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -30,7 +36,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut s: S = ::default(); + let mut s: S = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut s); { let __a1 = 1; s.v.push(__a1) diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 3be3338cf7..2c16f7c39a 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -15,7 +15,7 @@ pub const Overload_kRvalueOverload: Overload = 2; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, @@ -81,7 +81,7 @@ impl Holder { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, diff --git a/tests/unit/out/unsafe/forward_decltype.rs b/tests/unit/out/unsafe/forward_decltype.rs index 4a72585444..cbd14e5e34 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -15,7 +15,7 @@ pub const Overload_kRvalueOverload: Overload = 2; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index 819ff4cbb9..743926faf8 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -17,7 +17,7 @@ pub const Overload_kIntRvalueOverload: Overload = 4; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index e8bd03f9a9..24a1d3baf4 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -17,7 +17,7 @@ pub const Overload_kIntRvalueOverload: Overload = 4; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, @@ -118,7 +118,7 @@ impl Pair { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, diff --git a/tests/unit/out/unsafe/friend.rs b/tests/unit/out/unsafe/friend.rs index 9640b96b2a..d1636d2ed8 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -20,7 +20,14 @@ pub unsafe fn scaled_3(v: *const V, mut k: f64) -> f64 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct V { pub x: i32, @@ -36,7 +43,14 @@ pub unsafe fn get_4(w: *const W_int_) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct W_int_ { pub x: i32, @@ -46,14 +60,28 @@ pub unsafe fn get_5(w: *const W_long_) -> i64 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct W_long_ { pub x: i64, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct D { pub x: i32, diff --git a/tests/unit/out/unsafe/function_overloading.rs b/tests/unit/out/unsafe/function_overloading.rs index f4a7056241..d35fad6066 100644 --- a/tests/unit/out/unsafe/function_overloading.rs +++ b/tests/unit/out/unsafe/function_overloading.rs @@ -23,7 +23,14 @@ pub unsafe fn bar_4(x: *mut i32) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Foo {} impl Foo { diff --git a/tests/unit/out/unsafe/global_call_temporaries.rs b/tests/unit/out/unsafe/global_call_temporaries.rs index b5136c2e10..7ce2af698a 100644 --- a/tests/unit/out/unsafe/global_call_temporaries.rs +++ b/tests/unit/out/unsafe/global_call_temporaries.rs @@ -78,7 +78,14 @@ pub static mut call_assigned_6: std::cell::LazyCell = std::cell::LazyCell:: }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Item { pub value: i32, diff --git a/tests/unit/out/unsafe/global_init_side_effect.rs b/tests/unit/out/unsafe/global_init_side_effect.rs index 19ef3b0524..10d4ea7348 100644 --- a/tests/unit/out/unsafe/global_init_side_effect.rs +++ b/tests/unit/out/unsafe/global_init_side_effect.rs @@ -15,6 +15,7 @@ pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] diff --git a/tests/unit/out/unsafe/global_non_const_init.rs b/tests/unit/out/unsafe/global_non_const_init.rs index 7a1fc91ea3..464645f68c 100644 --- a/tests/unit/out/unsafe/global_non_const_init.rs +++ b/tests/unit/out/unsafe/global_non_const_init.rs @@ -33,19 +33,21 @@ pub struct Ctor { pub v: i32, } impl Ctor { - pub unsafe fn construct_1(&mut self) { - (&raw mut self.v).write((unsafe { next_0() })); - } - pub unsafe fn construct_2(&mut self, mut x: i32) { + pub unsafe fn construct_1(&mut self, mut x: i32) { (&raw mut self.v).write(x); } } +impl DefaultConstructibleUnsafe for Ctor { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write((unsafe { next_0() })); + } +} impl Default for Ctor { fn default() -> Self { unsafe { { let mut __v: Ctor = ::zero_init(); - Ctor::construct_1(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -54,14 +56,14 @@ impl Default for Ctor { pub static mut default_ctor_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - Ctor::construct_1(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } }); pub static mut arg_ctor_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - Ctor::construct_2(&mut __v, { 7 }); + Ctor::construct_1(&mut __v, { 7 }); __v } }); @@ -76,13 +78,20 @@ pub static mut str_9: std::cell::LazyCell> = pub static mut inline_member_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - Ctor::construct_2(&mut __v, { 5 }); + Ctor::construct_1(&mut __v, { 5 }); __v } }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Holder {} pub static mut member_10: std::cell::LazyCell = @@ -96,7 +105,7 @@ static mut once_13: std::cell::LazyCell = static mut local_ctor_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - Ctor::construct_2(&mut __v, { 3 }); + Ctor::construct_1(&mut __v, { 3 }); __v } }); @@ -106,19 +115,21 @@ pub struct Singleton { pub hits: i32, } impl Singleton { - pub unsafe fn construct(&mut self) { - (&raw mut self.hits).write(0); - } pub unsafe fn instance() -> *mut Singleton { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut s_15)); } } +impl DefaultConstructibleUnsafe for Singleton { + unsafe fn default_constructor(&mut self) { + (&raw mut self.hits).write(0); + } +} impl Default for Singleton { fn default() -> Self { unsafe { { let mut __v: Singleton = ::zero_init(); - Singleton::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -127,7 +138,7 @@ impl Default for Singleton { static mut s_15: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Singleton = ::zero_init(); - Singleton::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } }); diff --git a/tests/unit/out/unsafe/global_pointers.rs b/tests/unit/out/unsafe/global_pointers.rs index 8eecf5ac09..a9c88f06ad 100644 --- a/tests/unit/out/unsafe/global_pointers.rs +++ b/tests/unit/out/unsafe/global_pointers.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Entry { pub name: *const libc::c_char, diff --git a/tests/unit/out/unsafe/global_without_initializer.rs b/tests/unit/out/unsafe/global_without_initializer.rs index 074b02c2c8..7b58d8de0b 100644 --- a/tests/unit/out/unsafe/global_without_initializer.rs +++ b/tests/unit/out/unsafe/global_without_initializer.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub a: i32, diff --git a/tests/unit/out/unsafe/goto_aggregate_default.rs b/tests/unit/out/unsafe/goto_aggregate_default.rs index c098ed98ac..dae9dd1997 100644 --- a/tests/unit/out/unsafe/goto_aggregate_default.rs +++ b/tests/unit/out/unsafe/goto_aggregate_default.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 b37692ba80..17ac7a507a 100644 --- a/tests/unit/out/unsafe/goto_cleanup.rs +++ b/tests/unit/out/unsafe/goto_cleanup.rs @@ -78,7 +78,14 @@ pub unsafe fn from_switch_2(mut n: i32) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 aecc080728..7bd66bd8f0 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct MinHeapNode { pub data: libc::c_char, @@ -245,6 +252,15 @@ impl MinHeap { } } } +impl DefaultConstructibleUnsafe for MinHeap { + unsafe fn default_constructor(&mut self) { + (&raw mut self.size).write(0_i32); + (&raw mut self.capacity).write(0_i32); + (&raw mut self.arr).write(None); + (&raw mut self.next).write(0_i32); + (&raw mut self.alloc).write(None); + } +} pub unsafe fn AllocMinHeap_1(mut capacity: i32) -> Option> { let mut minHeap: Option> = Some(Box::new(MinHeap { size: 0, 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 02cd1fd8ca..dfb8ab5645 100644 --- a/tests/unit/out/unsafe/immutable-deref-on-func-call.rs +++ b/tests/unit/out/unsafe/immutable-deref-on-func-call.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Item { pub value: i32, diff --git a/tests/unit/out/unsafe/implicit_autoref.rs b/tests/unit/out/unsafe/implicit_autoref.rs index 077bb0b899..04e93654e4 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -22,6 +22,11 @@ use std::rc::Rc; pub struct Holder { pub v: Vec, } +impl DefaultConstructibleUnsafe for Holder { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write(Vec::new()); + } +} pub unsafe fn write_through_0(mut p: *mut i32) { (*p) = 42; } @@ -44,7 +49,8 @@ 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; - let mut h: Holder = ::default(); + let mut h: Holder = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut h); { let __a1 = 40; h.v.push(__a1) diff --git a/tests/unit/out/unsafe/in_class_field_initializer.rs b/tests/unit/out/unsafe/in_class_field_initializer.rs index 4372b9097c..04cd99efe7 100644 --- a/tests/unit/out/unsafe/in_class_field_initializer.rs +++ b/tests/unit/out/unsafe/in_class_field_initializer.rs @@ -12,6 +12,12 @@ pub struct Inner { pub x: i32, pub y: i32, } +impl DefaultConstructibleUnsafe for Inner { + unsafe fn default_constructor(&mut self) { + (&raw mut self.x).write(3); + (&raw mut self.y).write(4); + } +} impl Default for Inner { fn default() -> Self { unsafe { Inner { x: 3, y: 4 } } @@ -25,6 +31,14 @@ pub struct S { pub c: Inner, pub d: Inner, } +impl DefaultConstructibleUnsafe for S { + unsafe fn default_constructor(&mut self) { + (&raw mut self.a).write(1); + (&raw mut self.b).write((2 as libc::c_char)); + (&raw mut self.c).write(::default()); + DefaultConstructibleUnsafe::default_constructor(&mut self.d); + } +} impl Default for S { fn default() -> Self { unsafe { @@ -38,7 +52,15 @@ impl Default for S { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub struct Boxed_int_ { pub v: i32, pub tag: i32, @@ -61,7 +83,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut s: S = ::default(); + let mut s: S = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut s); assert!(((s.a) == (1))); assert!(((s.b as i32) == (2))); assert!(((s.c.x) == (3))); diff --git a/tests/unit/out/unsafe/init.rs b/tests/unit/out/unsafe/init.rs index dff1966872..3d59a03d41 100644 --- a/tests/unit/out/unsafe/init.rs +++ b/tests/unit/out/unsafe/init.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct X { pub x: i32, diff --git a/tests/unit/out/unsafe/init_list.rs b/tests/unit/out/unsafe/init_list.rs index c77ac10955..7860f3812f 100644 --- a/tests/unit/out/unsafe/init_list.rs +++ b/tests/unit/out/unsafe/init_list.rs @@ -9,7 +9,14 @@ use std::rc::Rc; pub unsafe fn f_0(mut list: Vec) {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub a: i32, @@ -26,6 +33,11 @@ impl Holder { return &mut (*(self as *mut Holder)); } } +impl DefaultConstructibleUnsafe for Holder { + unsafe fn default_constructor(&mut self) { + (&raw mut self.p).write(Pair { a: 0, b: 0 }); + } +} impl Default for Holder { fn default() -> Self { unsafe { @@ -43,6 +55,11 @@ pub unsafe fn sum_1(p: *const Pair) -> i32 { pub struct Seven { pub v: i32, } +impl DefaultConstructibleUnsafe for Seven { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write(7); + } +} impl Default for Seven { fn default() -> Self { unsafe { Seven { v: 7 } } @@ -63,7 +80,8 @@ unsafe fn main_0() -> i32 { let mut vec_: Vec = Vec::from([1, 2, 3]); (unsafe { f_0(Vec::from([1, 2, 3, 4])) }); let mut p: Pair = Pair { a: 1, b: 2 }; - let mut h: Holder = ::default(); + let mut h: Holder = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut h); (unsafe { Holder::operator_assign_1(&mut h, &mut p) }); assert!(((h.p.a) == (1)) && ((h.p.b) == (2))); assert!(((unsafe { sum_1(&p,) }) == (3))); diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index a574455fe6..c0038a17ea 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -24,6 +24,13 @@ pub struct Elem { pub hist: [i32; 4], pub coeffs: Vec, } +impl DefaultConstructibleUnsafe for Elem { + unsafe fn default_constructor(&mut self) { + (&raw mut self.id).write(0_i32); + (&raw mut self.hist).write([0_i32; 4]); + (&raw mut self.coeffs).write(Vec::new()); + } +} #[repr(C)] #[derive( Clone, @@ -43,6 +50,15 @@ pub struct State { pub elems: Vec, pub rows: Vec>, } +impl DefaultConstructibleUnsafe for State { + unsafe fn default_constructor(&mut self) { + (&raw mut self.count).write(0_i32); + (&raw mut self.grid).write([[0_i32; 3]; 2]); + (&raw mut self.arr).write(std::array::from_fn::<_, 3, _>(|_| 0_i32)); + (&raw mut self.elems).write(Vec::new()); + (&raw mut self.rows).write(Vec::new()); + } +} impl Default for State { fn default() -> Self { unsafe { @@ -116,6 +132,11 @@ pub static mut move_assigns_5: std::cell::LazyCell = std::cell::LazyCell::n pub struct Counted { pub v: i32, } +impl DefaultConstructibleUnsafe for Counted { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write(0); + } +} impl CopyConstructibleUnsafe for Counted { unsafe fn copy_constructor(&mut self, o: *const Counted) { (&raw mut self.v).write((*o).v); diff --git a/tests/unit/out/unsafe/kruskal.rs b/tests/unit/out/unsafe/kruskal.rs index 4b3e877125..897b47150b 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Edge { pub u: i32, @@ -285,6 +292,13 @@ impl DisjointSet { } } } +impl DefaultConstructibleUnsafe for DisjointSet { + unsafe fn default_constructor(&mut self) { + (&raw mut self.rank).write(None); + (&raw mut self.parent).write(None); + (&raw mut self.n).write(0_i32); + } +} #[repr(C)] #[derive( FnPtrArg, @@ -300,6 +314,13 @@ pub struct Graph { pub V: i32, pub E: i32, } +impl DefaultConstructibleUnsafe for Graph { + unsafe fn default_constructor(&mut self) { + (&raw mut self.edges).write(None); + (&raw mut self.V).write(0_i32); + (&raw mut self.E).write(0_i32); + } +} pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { (unsafe { let _arr: *mut Option> = &mut (*graph).edges; diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index a272565864..2228dec7ef 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -12,6 +12,7 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, @@ -37,7 +38,15 @@ impl Default for Guard__lambda_at_lambda_as_field_cpp_34_13__ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { pub f: FnPtr, } @@ -47,7 +56,14 @@ impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_45_13__ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { pub f: FnPtr i32>, pub calls: i32, @@ -73,7 +89,15 @@ impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, +)] pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { pub f: FnPtr i32>, pub calls: i32, @@ -85,7 +109,7 @@ impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe)] #[cpp_from(FnPtr i32 > , construct, value)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { pub f: FnPtr i32>, diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index e12c4a9d84..aa225e35f9 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -20,8 +20,8 @@ pub struct Counted { pub copies: i32, pub moves: i32, } -impl Counted { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for Counted { + unsafe fn default_constructor(&mut self) { (&raw mut self.copies).write(0); (&raw mut self.moves).write(0); } @@ -52,7 +52,7 @@ impl Default for Counted { unsafe { { let mut __v: Counted = ::zero_init(); - Counted::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -69,8 +69,8 @@ pub static mut drops_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u SwappableUnsafe, )] pub struct Dropped {} -impl Dropped { - pub unsafe fn construct(&mut self) {} +impl DefaultConstructibleUnsafe for Dropped { + unsafe fn default_constructor(&mut self) {} } impl CopyConstructibleUnsafe for Dropped { unsafe fn copy_constructor(&mut self, _a0: *const Dropped) {} @@ -97,7 +97,7 @@ impl Default for Dropped { unsafe { { let mut __v: Dropped = ::zero_init(); - Dropped::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -111,7 +111,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut c: Counted = ::zero_init(); - Counted::construct(&mut c); + DefaultConstructibleUnsafe::default_constructor(&mut c); let mut f: FnPtr i32> = lambda_unsafe!( { let c: Counted = { @@ -156,7 +156,7 @@ unsafe fn main_0() -> i32 { assert!(((returned) == (2))); let mut arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|_| { let mut __v: Counted = ::zero_init(); - Counted::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }); let mut a: FnPtr i32> = lambda_unsafe!( @@ -181,7 +181,7 @@ unsafe fn main_0() -> i32 { { let d: Dropped = { let mut __v: Dropped = ::zero_init(); - Dropped::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; }, @@ -201,7 +201,7 @@ unsafe fn main_0() -> i32 { { let d: Dropped = { let mut __v: Dropped = ::zero_init(); - Dropped::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; }, @@ -221,7 +221,7 @@ unsafe fn main_0() -> i32 { { let d: Dropped = { let mut __v: Dropped = ::zero_init(); - Dropped::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; }, diff --git a/tests/unit/out/unsafe/lambda_capture_ref.rs b/tests/unit/out/unsafe/lambda_capture_ref.rs index 273bccdd6d..6590dbd343 100644 --- a/tests/unit/out/unsafe/lambda_capture_ref.rs +++ b/tests/unit/out/unsafe/lambda_capture_ref.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub x: i32, diff --git a/tests/unit/out/unsafe/lambda_capture_star_this.rs b/tests/unit/out/unsafe/lambda_capture_star_this.rs index be3bf1f6e9..da181b4648 100644 --- a/tests/unit/out/unsafe/lambda_capture_star_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_star_this.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub n: i32, diff --git a/tests/unit/out/unsafe/lambda_capture_this.rs b/tests/unit/out/unsafe/lambda_capture_this.rs index ee019462ca..77bec8611a 100644 --- a/tests/unit/out/unsafe/lambda_capture_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_this.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub n: i32, diff --git a/tests/unit/out/unsafe/lambda_capture_value.rs b/tests/unit/out/unsafe/lambda_capture_value.rs index 1d721ec289..fc656980c3 100644 --- a/tests/unit/out/unsafe/lambda_capture_value.rs +++ b/tests/unit/out/unsafe/lambda_capture_value.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub x: i32, diff --git a/tests/unit/out/unsafe/lambda_decltype_type.rs b/tests/unit/out/unsafe/lambda_decltype_type.rs index 16f90a62a7..c2045e123a 100644 --- a/tests/unit/out/unsafe/lambda_decltype_type.rs +++ b/tests/unit/out/unsafe/lambda_decltype_type.rs @@ -29,6 +29,19 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { self.size.postfix_inc(); } } +impl DefaultConstructibleUnsafe for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { + unsafe fn default_constructor(&mut self) { + (&raw mut self.items).write([0_i32; 4]); + (&raw mut self.size).write(0); + (&raw mut self.cmp).write(FnPtr:: bool>::new( + |mut a: i32, mut b: i32| -> bool { + unsafe { + return ((a) > (b)); + } + }, + )); + } +} impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { fn default() -> Self { unsafe { @@ -67,6 +80,19 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { self.size.postfix_inc(); } } +impl DefaultConstructibleUnsafe for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { + unsafe fn default_constructor(&mut self) { + (&raw mut self.items).write([0_i32; 4]); + (&raw mut self.size).write(0); + (&raw mut self.cmp).write(FnPtr:: bool>::new( + |mut a: i32, mut b: i32| -> bool { + unsafe { + return ((a) < (b)); + } + }, + )); + } +} impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { fn default() -> Self { unsafe { @@ -96,7 +122,8 @@ unsafe fn main_0() -> i32 { } }); let mut desc: Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut desc); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&mut desc, 2) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&mut desc, 7) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&mut desc, 4) }); @@ -104,7 +131,8 @@ unsafe fn main_0() -> i32 { assert!(((desc.items[(1) as usize]) == (4))); assert!(((desc.items[(2) as usize]) == (2))); let mut asc: Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ = - ::default(); + ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut asc); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&mut asc, 2) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&mut asc, 7) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&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 887fadc14d..5de0535d40 100644 --- a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs +++ b/tests/unit/out/unsafe/lambda_generic_explicit_args.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Val { pub x: i32, diff --git a/tests/unit/out/unsafe/lambda_immediate_init.rs b/tests/unit/out/unsafe/lambda_immediate_init.rs index 63e8e560ae..278473131e 100644 --- a/tests/unit/out/unsafe/lambda_immediate_init.rs +++ b/tests/unit/out/unsafe/lambda_immediate_init.rs @@ -15,6 +15,21 @@ pub struct S { pub j: i32, pub k: i32, } +impl DefaultConstructibleUnsafe for S { + unsafe fn default_constructor(&mut self) { + (&raw mut self.j).write(10); + (&raw mut self.k).write( + ((unsafe { + FnPtr:: i32>::new(|| -> i32 { + unsafe { + return 3; + } + }) + .call() + }) + (1)), + ); + } +} impl Default for S { fn default() -> Self { unsafe { @@ -74,7 +89,8 @@ unsafe fn main_0() -> i32 { }) == (237)) ); assert!(((unsafe { pick_0(1,) }) == (1))); - let mut s: S = ::default(); + let mut s: S = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut s); 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_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index d527d39c0f..605f07f325 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -7,7 +7,9 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultConstructibleUnsafe, Default, +)] #[cpp_from(i32, construct, value)] pub struct Owner { pub p: *mut i32, diff --git a/tests/unit/out/unsafe/lambda_nested.rs b/tests/unit/out/unsafe/lambda_nested.rs index 1afcc23943..9617322fc0 100644 --- a/tests/unit/out/unsafe/lambda_nested.rs +++ b/tests/unit/out/unsafe/lambda_nested.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/lambda_static_local.rs b/tests/unit/out/unsafe/lambda_static_local.rs index 8c46892420..5e0406de52 100644 --- a/tests/unit/out/unsafe/lambda_static_local.rs +++ b/tests/unit/out/unsafe/lambda_static_local.rs @@ -69,7 +69,14 @@ static mut calls_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsaf static mut calls_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct P_4 { pub x: i32, diff --git a/tests/unit/out/unsafe/libc_struct_without_default.rs b/tests/unit/out/unsafe/libc_struct_without_default.rs index aca94964ca..34101b89d6 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -22,6 +22,12 @@ pub struct UserDefined { pub a: [i32; 1], pub v: Vec, } +impl DefaultConstructibleUnsafe for UserDefined { + unsafe fn default_constructor(&mut self) { + (&raw mut self.a).write(std::array::from_fn::<_, 1, _>(|_| 0_i32)); + (&raw mut self.v).write(Vec::new()); + } +} impl Default for UserDefined { fn default() -> Self { unsafe { @@ -33,7 +39,15 @@ impl Default for UserDefined { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub struct FieldIsLibcType { pub addr: libc::sockaddr, } @@ -73,7 +87,8 @@ 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))); - let mut ud: UserDefined = ::default(); + let mut ud: UserDefined = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut ud); 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 17392bf6ab..6cf73c6397 100644 --- a/tests/unit/out/unsafe/linked_list.rs +++ b/tests/unit/out/unsafe/linked_list.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Node { pub val: i32, diff --git a/tests/unit/out/unsafe/local_anon_struct_collision.rs b/tests/unit/out/unsafe/local_anon_struct_collision.rs index 22a5a31b74..6bc09413c4 100644 --- a/tests/unit/out/unsafe/local_anon_struct_collision.rs +++ b/tests/unit/out/unsafe/local_anon_struct_collision.rs @@ -14,7 +14,14 @@ pub unsafe fn first_0() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_1 { pub x: i32, @@ -28,7 +35,14 @@ pub unsafe fn second_2() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 6bfee633be..86593fe51e 100644 --- a/tests/unit/out/unsafe/local_record_template.rs +++ b/tests/unit/out/unsafe/local_record_template.rs @@ -31,14 +31,28 @@ pub unsafe fn wrap_10(mut v: i64) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Local_5 { pub x: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Local_7 { pub x: i64, @@ -49,7 +63,14 @@ pub unsafe fn other_11() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Local_1 { pub x: i64, @@ -72,7 +93,14 @@ unsafe fn main_0() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Local_3 { pub x: i32, diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index 5df1205c96..79f7fa8b55 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -22,21 +22,23 @@ pub struct Point { pub y: i32, } impl Point { - pub unsafe fn construct_1(&mut self) { - (&raw mut self.x).write(0); - (&raw mut self.y).write(0); - } - pub unsafe fn construct_2(&mut self, mut x: i32, mut y: i32) { + pub unsafe fn construct_1(&mut self, mut x: i32, mut y: i32) { (&raw mut self.x).write(x); (&raw mut self.y).write(y); } } +impl DefaultConstructibleUnsafe for Point { + unsafe fn default_constructor(&mut self) { + (&raw mut self.x).write(0); + (&raw mut self.y).write(0); + } +} impl Default for Point { fn default() -> Self { unsafe { { let mut __v: Point = ::zero_init(); - Point::construct_1(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -445,7 +447,7 @@ unsafe fn main_0() -> i32 { let mut point_new: (UnsafeBidirectionalIterator<(i32, Point)>, bool) = points.try_emplace(key1, || { let mut __v: Point = ::zero_init(); - Point::construct_2(&mut __v, { 3 }, { 4 }); + Point::construct_1(&mut __v, { 3 }, { 4 }); __v }); assert!(((point_new.1) as bool)); @@ -479,7 +481,7 @@ unsafe fn main_0() -> i32 { }; points.emplace((key8, { let mut __v: Point = ::zero_init(); - Point::construct_2(&mut __v, { 5 }, { 6 }); + Point::construct_1(&mut __v, { 5 }, { 6 }); __v })); { diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 92f323efd5..3b78d2c538 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -15,7 +15,7 @@ pub static mut made_2: std::cell::LazyCell = std::cell::LazyCell::new(|| un FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index 579d8cc551..d7f3b4279f 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -10,7 +10,14 @@ pub static mut default_constructions_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Key { pub order: i32, @@ -51,8 +58,8 @@ pub unsafe fn operator_eq_2(a: *const Key, b: *const Key) -> bool { pub struct Mapped { pub value: i32, } -impl Mapped { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for Mapped { + unsafe fn default_constructor(&mut self) { (&raw mut self.value).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)).prefix_inc(); } @@ -62,7 +69,7 @@ impl Default for Mapped { unsafe { { let mut __v: Mapped = ::zero_init(); - Mapped::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index cab1642c41..0736c71e2a 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -26,14 +26,16 @@ pub struct Item { pub value: i32, } impl Item { - pub unsafe fn construct_2(&mut self) { - (&raw mut self.value).write(0); - } pub unsafe fn construct_1(&mut self, mut value: i32) { (&raw mut self.value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for Item { + unsafe fn default_constructor(&mut self) { + (&raw mut self.value).write(0); + } +} impl CopyConstructibleUnsafe for Item { unsafe fn copy_constructor(&mut self, other: *const Item) { (&raw mut self.value).write((*other).value); @@ -61,7 +63,7 @@ impl Default for Item { unsafe { { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -77,10 +79,7 @@ pub struct RefItem { pub value: i32, } impl RefItem { - pub unsafe fn construct_1(&mut self) { - (&raw mut self.value).write(0); - } - pub unsafe fn construct_2(&mut self, counter: *mut i32, mut amount: i32) { + pub unsafe fn construct_1(&mut self, counter: *mut i32, mut amount: i32) { (&raw mut self.value).write({ (*counter) += amount; (*counter) @@ -88,12 +87,17 @@ impl RefItem { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for RefItem { + unsafe fn default_constructor(&mut self) { + (&raw mut self.value).write(0); + } +} impl Default for RefItem { fn default() -> Self { unsafe { { let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -351,7 +355,7 @@ unsafe fn main_0() -> i32 { let mut counter: i32 = 0; refs.try_emplace(key, || { let mut __v: RefItem = ::zero_init(); - RefItem::construct_2(&mut __v, { &mut counter }, { 5 }); + RefItem::construct_1(&mut __v, { &mut counter }, { 5 }); __v }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = 0; @@ -359,7 +363,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_10,) => refs.try_emplace(key, || { let mut __v: RefItem = ::zero_init(); - RefItem::construct_2(&mut __v, { __tmp_10 }, { 2 }); + RefItem::construct_1(&mut __v, { __tmp_10 }, { 2 }); __v }), }; @@ -374,7 +378,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_11,) => refs.try_emplace(key, || { let mut __v: RefItem = ::zero_init(); - RefItem::construct_2(&mut __v, { __tmp_11 }, { 2 }); + RefItem::construct_1(&mut __v, { __tmp_11 }, { 2 }); __v }), }; diff --git a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs index 1229f2461d..7236ef67ec 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -14,10 +14,7 @@ pub struct Item { pub value: i32, } impl Item { - pub unsafe fn construct_1(&mut self) { - (&raw mut self.value).write(0); - } - pub unsafe fn construct_2(&mut self, counter: *mut i32, mut amount: i32) { + pub unsafe fn construct_1(&mut self, counter: *mut i32, mut amount: i32) { (&raw mut self.value).write({ (*counter) += amount; (*counter) @@ -25,12 +22,17 @@ impl Item { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for Item { + unsafe fn default_constructor(&mut self) { + (&raw mut self.value).write(0); + } +} impl Default for Item { fn default() -> Self { unsafe { { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -52,8 +54,8 @@ pub struct Temporary { pub n: i32, pub data: [i32; 2], } -impl Temporary { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for Temporary { + unsafe fn default_constructor(&mut self) { (&raw mut self.n).write(5); (&raw mut self.data).write([6, 7]); (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)).prefix_inc(); @@ -64,7 +66,7 @@ impl Default for Temporary { unsafe { { let mut __v: Temporary = ::zero_init(); - Temporary::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -77,22 +79,22 @@ impl Default for Temporary { pub struct Nested { pub inner: Temporary, } -impl Nested { - pub unsafe fn construct_1(&mut self) { - Temporary::construct(&mut self.inner); +impl DefaultConstructibleUnsafe for Nested { + unsafe fn default_constructor(&mut self) { + DefaultConstructibleUnsafe::default_constructor(&mut self.inner); } } pub unsafe fn make_temporary_5() -> Temporary { return { let mut __v: Temporary = ::zero_init(); - Temporary::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; } pub unsafe fn make_nested_6() -> Nested { return { let mut __v: Nested = ::zero_init(); - Nested::construct_1(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }; } @@ -105,13 +107,6 @@ pub struct Owner { pub ptr: Option>, } impl Owner { - pub unsafe fn construct(&mut self) { - (&raw mut self.ptr).write(Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - Temporary::construct(&mut __v); - __v - }))); - } pub unsafe fn value(&mut self) -> *const i32 { return &(*self.ptr.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const Temporary as *mut Temporary @@ -119,12 +114,21 @@ impl Owner { .n; } } +impl DefaultConstructibleUnsafe for Owner { + unsafe fn default_constructor(&mut self) { + (&raw mut self.ptr).write(Some(Box::new({ + let mut __v: Temporary = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut __v); + __v + }))); + } +} impl Default for Owner { fn default() -> Self { unsafe { { let mut __v: Owner = ::zero_init(); - Owner::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -135,6 +139,11 @@ impl Default for Owner { pub struct Noncopy { pub n: i32, } +impl DefaultConstructibleUnsafe for Noncopy { + unsafe fn default_constructor(&mut self) { + (&raw mut self.n).write(5); + } +} impl Default for Noncopy { fn default() -> Self { unsafe { Noncopy { n: 5 } } @@ -149,22 +158,24 @@ pub struct Held { pub ptr: *const i32, } impl Held { - pub unsafe fn construct_2(&mut self) { - (&raw mut self.ptr).write(std::ptr::null()); - } pub unsafe fn construct_1(&mut self, n: *const i32) { (&raw mut self.ptr).write((n)); } - pub unsafe fn construct_3(&mut self, n: *const [i32; 2], mut _a1: i32) { + pub unsafe fn construct_2(&mut self, n: *const [i32; 2], mut _a1: i32) { (&raw mut self.ptr).write((*n).as_ptr()); } } +impl DefaultConstructibleUnsafe for Held { + unsafe fn default_constructor(&mut self) { + (&raw mut self.ptr).write(std::ptr::null()); + } +} impl Default for Held { fn default() -> Self { unsafe { { let mut __v: Held = ::zero_init(); - Held::construct_2(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -235,7 +246,7 @@ pub static mut global_owned_16: std::cell::LazyCell<( match ((&mut (*(*{ __tmp_6 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - Temporary::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v })); &mut __tmp_6 @@ -289,7 +300,7 @@ unsafe fn main_0() -> i32 { let mut counter: i32 = 0; m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { &mut counter }, { 3 }); + Item::construct_1(&mut __v, { &mut counter }, { 3 }); __v }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) = 0; @@ -303,7 +314,7 @@ unsafe fn main_0() -> i32 { ) { (__tmp_7, __tmp_8) => (*__tmp_7).try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_8 }, { 2 }); + Item::construct_1(&mut __v, { __tmp_8 }, { 2 }); __v }), }; @@ -321,7 +332,7 @@ unsafe fn main_0() -> i32 { { (__tmp_10,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_10 }, { 2 }); + Item::construct_1(&mut __v, { __tmp_10 }, { 2 }); __v }), }; @@ -339,7 +350,7 @@ unsafe fn main_0() -> i32 { { (__tmp_12,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_12 }, { 2 }); + Item::construct_1(&mut __v, { __tmp_12 }, { 2 }); __v }), }; @@ -358,7 +369,7 @@ unsafe fn main_0() -> i32 { { (__tmp_15,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_15 }, { 2 }); + Item::construct_1(&mut __v, { __tmp_15 }, { 2 }); __v }), }; @@ -381,7 +392,7 @@ unsafe fn main_0() -> i32 { { (__tmp_18,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_18 }, { 3 }); + Item::construct_1(&mut __v, { __tmp_18 }, { 3 }); __v }), }; @@ -402,7 +413,7 @@ unsafe fn main_0() -> i32 { { (__tmp_20,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_20 }, { 3 }); + Item::construct_1(&mut __v, { __tmp_20 }, { 3 }); __v }), }; @@ -419,7 +430,7 @@ unsafe fn main_0() -> i32 { { (__tmp_23,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_23 }, { 3 }); + Item::construct_1(&mut __v, { __tmp_23 }, { 3 }); __v }), }; @@ -445,7 +456,7 @@ unsafe fn main_0() -> i32 { { (__tmp_26,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_26 }, { 3 }); + Item::construct_1(&mut __v, { __tmp_26 }, { 3 }); __v }), }; @@ -470,7 +481,7 @@ unsafe fn main_0() -> i32 { { (__tmp_29,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_29 }, { 3 }); + Item::construct_1(&mut __v, { __tmp_29 }, { 3 }); __v }), }; @@ -485,7 +496,7 @@ unsafe fn main_0() -> i32 { { (__tmp_32,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_32 }, { 3 }); + Item::construct_1(&mut __v, { __tmp_32 }, { 3 }); __v }), }; @@ -716,7 +727,7 @@ unsafe fn main_0() -> i32 { { (__tmp_60,) => selected.try_emplace(keys[(0) as usize], || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_60 }, { 2 }); + Item::construct_1(&mut __v, { __tmp_60 }, { 2 }); __v }), }; @@ -739,7 +750,7 @@ unsafe fn main_0() -> i32 { { (__tmp_63,) => selected.try_emplace(keys[(1) as usize], || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_63 }, { 2 }); + Item::construct_1(&mut __v, { __tmp_63 }, { 2 }); __v }), }; @@ -762,7 +773,7 @@ unsafe fn main_0() -> i32 { { (__tmp_68,) => selected.try_emplace(keys[(2) as usize], || { let mut __v: Item = ::zero_init(); - Item::construct_2(&mut __v, { __tmp_68 }, { 2 }); + Item::construct_1(&mut __v, { __tmp_68 }, { 2 }); __v }), }; @@ -960,7 +971,7 @@ unsafe fn main_0() -> i32 { if (hit != 0) { arrays.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_3(&mut __v, { &ordinary_array }, { 0 }); + Held::construct_2(&mut __v, { &ordinary_array }, { 0 }); __v }); } @@ -989,7 +1000,7 @@ unsafe fn main_0() -> i32 { { (__tmp_82,) => arrays.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_3(&mut __v, { __tmp_82 }, { 0 }); + Held::construct_2(&mut __v, { __tmp_82 }, { 0 }); __v }), }; @@ -1034,7 +1045,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*(*{ __tmp_86 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - Temporary::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v })); &mut __tmp_86 @@ -1053,7 +1064,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*&mut (*(*{ __tmp_88 = Some(Box::new({ let mut __v: Nested = ::zero_init(); - Nested::construct_1(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v })); &mut __tmp_88 @@ -1073,7 +1084,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*(*{ __tmp_90 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - Temporary::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v })); &mut __tmp_90 @@ -1092,7 +1103,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*(*{ __tmp_92 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - Temporary::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v })); &mut __tmp_92 @@ -1109,7 +1120,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*((*{ __tmp_94 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - Temporary::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v })); &mut __tmp_94 @@ -1128,7 +1139,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*((*(*{ __tmp_96 = Some(Box::new(Some(Box::new({ let mut __v: Temporary = ::zero_init(); - Temporary::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v })))); &mut __tmp_96 @@ -1197,7 +1208,9 @@ unsafe fn main_0() -> i32 { (&mut (*(*{ __tmp_98 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - Temporary::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor( + &mut __v, + ); __v })); &mut __tmp_98 @@ -1211,7 +1224,9 @@ unsafe fn main_0() -> i32 { (&mut (*(*{ __tmp_99 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - Temporary::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor( + &mut __v, + ); __v })); &mut __tmp_99 @@ -1256,7 +1271,9 @@ unsafe fn main_0() -> i32 { match (((unsafe { Owner::value( &mut (*{ - Owner::construct(&mut __tmp_101); + DefaultConstructibleUnsafe::default_constructor( + &mut __tmp_101, + ); &mut __tmp_101 }), ) @@ -1287,7 +1304,11 @@ unsafe fn main_0() -> i32 { ) = { let mut __tmp_103: Option>; match (({ - __tmp_103 = Some(Box::new(::default())); + __tmp_103 = Some(Box::new({ + let mut __v: Noncopy = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut __v); + __v + })); &mut __tmp_103 } as *mut Option>),) { @@ -1300,7 +1321,11 @@ unsafe fn main_0() -> i32 { ) = { let mut __tmp_105: Option>; match (({ - __tmp_105 = Some(Box::new(::default())); + __tmp_105 = Some(Box::new({ + let mut __v: Noncopy = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut __v); + __v + })); &mut __tmp_105 } as *mut Option>),) { diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 3e34a334ab..9946680f13 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -22,7 +22,7 @@ pub unsafe fn pick_3(mut i: i32) -> *mut i32 { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MovableUnsafe, Default, diff --git a/tests/unit/out/unsafe/memcpy_struct_bytes.rs b/tests/unit/out/unsafe/memcpy_struct_bytes.rs index 52ed9a3a88..2009639c7e 100644 --- a/tests/unit/out/unsafe/memcpy_struct_bytes.rs +++ b/tests/unit/out/unsafe/memcpy_struct_bytes.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 b39f168db7..a5b4b4e426 100644 --- a/tests/unit/out/unsafe/memcpy_struct_layouts.rs +++ b/tests/unit/out/unsafe/memcpy_struct_layouts.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct packed { pub a: i32, @@ -18,7 +25,14 @@ pub struct packed { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct reordered { pub a: libc::c_char, @@ -27,7 +41,14 @@ pub struct reordered { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct tail { pub a: libc::c_char, @@ -35,7 +56,14 @@ pub struct tail { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct nested { pub t: tail, @@ -43,7 +71,14 @@ pub struct nested { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 0bc61206d3..80e3915330 100644 --- a/tests/unit/out/unsafe/memcpy_struct_struct.rs +++ b/tests/unit/out/unsafe/memcpy_struct_struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Entry { pub bits: u8, diff --git a/tests/unit/out/unsafe/memset_struct_tail.rs b/tests/unit/out/unsafe/memset_struct_tail.rs index 68364362d3..cd756001e9 100644 --- a/tests/unit/out/unsafe/memset_struct_tail.rs +++ b/tests/unit/out/unsafe/memset_struct_tail.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 1de05ce949..5e254cd5e5 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -8,7 +8,12 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, Default, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DefaultInitializableUnsafe, + SwappableUnsafe, + Default, )] #[cpp_from(i32, construct, value)] pub struct MoveOnly { @@ -41,9 +46,6 @@ pub struct ConstMoveAssign { pub mark: i32, } impl ConstMoveAssign { - pub unsafe fn construct(&mut self) { - (&raw mut self.mark).write(0); - } pub unsafe fn operator_assign_2(&mut self, o: *mut ConstMoveAssign) -> *mut ConstMoveAssign { self.mark = (((*o).mark) + (1)); return &mut (*(self as *mut ConstMoveAssign)); @@ -53,12 +55,17 @@ impl ConstMoveAssign { return &mut (*(self as *mut ConstMoveAssign)); } } +impl DefaultConstructibleUnsafe for ConstMoveAssign { + unsafe fn default_constructor(&mut self) { + (&raw mut self.mark).write(0); + } +} impl Default for ConstMoveAssign { fn default() -> Self { unsafe { { let mut __v: ConstMoveAssign = ::zero_init(); - ConstMoveAssign::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -130,13 +137,13 @@ unsafe fn main_0() -> i32 { assert!(((vec_[(0_usize)].v) == (8))); assert!(((d.v) == (0))); let mut m: ConstMoveAssign = ::zero_init(); - ConstMoveAssign::construct(&mut m); + DefaultConstructibleUnsafe::default_constructor(&mut m); let mut m1: ConstMoveAssign = ::zero_init(); - ConstMoveAssign::construct(&mut m1); + DefaultConstructibleUnsafe::default_constructor(&mut m1); let mut m2: ConstMoveAssign = ::zero_init(); - ConstMoveAssign::construct(&mut m2); + DefaultConstructibleUnsafe::default_constructor(&mut m2); let mut cm: ConstMoveAssign = ::zero_init(); - ConstMoveAssign::construct(&mut cm); + DefaultConstructibleUnsafe::default_constructor(&mut cm); (unsafe { ConstMoveAssign::operator_assign_2(&mut m1, &mut m) }); (unsafe { ConstMoveAssign::operator_assign_3(&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 1b424b4893..5e17dae306 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -7,7 +7,9 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, +)] #[cpp_from(i32, construct, value)] pub struct MoveOnly { pub v: i32, @@ -29,9 +31,6 @@ pub struct ConstMove { pub mark: i32, } impl ConstMove { - pub unsafe fn construct(&mut self) { - (&raw mut self.mark).write(0); - } pub unsafe fn construct_1(&mut self, o: *mut ConstMove) { (&raw mut self.mark).write((((*o).mark) + (1))); } @@ -39,12 +38,17 @@ impl ConstMove { (&raw mut self.mark).write((((*o).mark) + (10))); } } +impl DefaultConstructibleUnsafe for ConstMove { + unsafe fn default_constructor(&mut self) { + (&raw mut self.mark).write(0); + } +} impl Default for ConstMove { fn default() -> Self { unsafe { { let mut __v: ConstMove = ::zero_init(); - ConstMove::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -56,7 +60,7 @@ impl Default for ConstMove { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, @@ -105,7 +109,7 @@ impl Clone for ThrowingMove { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, @@ -222,11 +226,11 @@ unsafe fn main_0() -> i32 { assert!(((vec_[(0_usize)].v) == (7)) && ((vec_[(1_usize)].v) == (8))); assert!(((f.v) == (0))); let mut m: ConstMove = ::zero_init(); - ConstMove::construct(&mut m); + DefaultConstructibleUnsafe::default_constructor(&mut m); let mut m1: ConstMove = ::zero_init(); ConstMove::construct_1(&mut m1, { &mut m }); let mut cm: ConstMove = ::zero_init(); - ConstMove::construct(&mut cm); + DefaultConstructibleUnsafe::default_constructor(&mut cm); let mut m2: ConstMove = ::zero_init(); ConstMove::construct_2(&mut m2, { &cm }); assert!(((m1.mark) == (1))); diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index 4a4d682523..5106bbda02 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -12,7 +12,7 @@ use std::rc::Rc; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, diff --git a/tests/unit/out/unsafe/nested_structs.rs b/tests/unit/out/unsafe/nested_structs.rs index 44583fc00c..a32dba8a86 100644 --- a/tests/unit/out/unsafe/nested_structs.rs +++ b/tests/unit/out/unsafe/nested_structs.rs @@ -8,14 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Level0_Level1_1_Level2_1_Level3_1 { pub x1: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Level0_Level1_1_Level2_1_Level3_2 { pub x1: i32, @@ -23,21 +37,42 @@ pub struct Level0_Level1_1_Level2_1_Level3_2 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Level0_Level1_1_Level2_1 { pub x1: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Level0_Level1_1 { pub x1: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Level0_Level1_2 { pub x1: i32, @@ -45,7 +80,14 @@ pub struct Level0_Level1_2 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Level0 {} pub fn main() { diff --git a/tests/unit/out/unsafe/new.rs b/tests/unit/out/unsafe/new.rs index e0d3015cbc..122825c5c6 100644 --- a/tests/unit/out/unsafe/new.rs +++ b/tests/unit/out/unsafe/new.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub x: i32, diff --git a/tests/unit/out/unsafe/new_bst.rs b/tests/unit/out/unsafe/new_bst.rs index 97b631f9e3..dac1d68074 100644 --- a/tests/unit/out/unsafe/new_bst.rs +++ b/tests/unit/out/unsafe/new_bst.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct node_t { pub left: *mut node_t, diff --git a/tests/unit/out/unsafe/new_struct.rs b/tests/unit/out/unsafe/new_struct.rs index a9f66e50da..fe46b51827 100644 --- a/tests/unit/out/unsafe/new_struct.rs +++ b/tests/unit/out/unsafe/new_struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub x: i32, @@ -16,7 +23,14 @@ pub struct Pair { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Triple { pub a: i32, diff --git a/tests/unit/out/unsafe/nttp_distinct_specializations.rs b/tests/unit/out/unsafe/nttp_distinct_specializations.rs index 7e4ddc2f00..f9f374e227 100644 --- a/tests/unit/out/unsafe/nttp_distinct_specializations.rs +++ b/tests/unit/out/unsafe/nttp_distinct_specializations.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S_2_ { pub v: i32, @@ -21,7 +28,14 @@ impl S_2_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S_1_ { pub v: i32, @@ -33,7 +47,14 @@ impl S_1_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S_3_ { pub v: i32, diff --git a/tests/unit/out/unsafe/offsetof.rs b/tests/unit/out/unsafe/offsetof.rs index c65bc82147..fde3ab7987 100644 --- a/tests/unit/out/unsafe/offsetof.rs +++ b/tests/unit/out/unsafe/offsetof.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Layout { pub a: u8, @@ -16,7 +23,15 @@ pub struct Layout { pub c: u16, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub struct Frame { pub tag: u16, pub body: [libc::c_char; 64], diff --git a/tests/unit/out/unsafe/opaque_forward_decl.rs b/tests/unit/out/unsafe/opaque_forward_decl.rs index 35a56e4387..b3b437641c 100644 --- a/tests/unit/out/unsafe/opaque_forward_decl.rs +++ b/tests/unit/out/unsafe/opaque_forward_decl.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 935d03778c..1ec8a560a5 100644 --- a/tests/unit/out/unsafe/opaque_record_copy.rs +++ b/tests/unit/out/unsafe/opaque_record_copy.rs @@ -8,12 +8,26 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Probe {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Wrapper_Probe_ { pub base_: Probe, diff --git a/tests/unit/out/unsafe/opaque_then_defined.rs b/tests/unit/out/unsafe/opaque_then_defined.rs index b9fa7b8b1d..fabebaf001 100644 --- a/tests/unit/out/unsafe/opaque_then_defined.rs +++ b/tests/unit/out/unsafe/opaque_then_defined.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct list { pub head: *mut node, @@ -16,7 +23,14 @@ pub struct list { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 64109d8e9b..eb22d6f97f 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_free.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_free.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_arithmetic_member.rs b/tests/unit/out/unsafe/operator_arithmetic_member.rs index ee2d516935..5cae6acad9 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_member.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_member.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_bitwise_free.rs b/tests/unit/out/unsafe/operator_bitwise_free.rs index 3bb31d9b8e..f60a99aedd 100644 --- a/tests/unit/out/unsafe/operator_bitwise_free.rs +++ b/tests/unit/out/unsafe/operator_bitwise_free.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: u32, diff --git a/tests/unit/out/unsafe/operator_bitwise_member.rs b/tests/unit/out/unsafe/operator_bitwise_member.rs index 87bf73b2ab..df6d2e2d6c 100644 --- a/tests/unit/out/unsafe/operator_bitwise_member.rs +++ b/tests/unit/out/unsafe/operator_bitwise_member.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: u32, diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index 88aa881c93..f9b1fa5a6b 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Eq { pub a: i32, @@ -28,7 +35,14 @@ impl std::cmp::PartialEq for Eq { impl std::cmp::Eq for Eq {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Cmp { pub a: i32, @@ -75,7 +89,14 @@ impl std::cmp::PartialEq for Cmp { impl std::cmp::Eq for Cmp {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Both { pub a: i32, @@ -113,7 +134,14 @@ impl std::cmp::PartialEq for Both { impl std::cmp::Eq for Both {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct OrdOnly { pub a: i32, @@ -148,7 +176,14 @@ impl std::cmp::PartialEq for OrdOnly { impl std::cmp::Eq for OrdOnly {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub x: i32, @@ -186,7 +221,14 @@ impl std::cmp::PartialEq for Inner { impl std::cmp::Eq for Inner {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer { pub i: Inner, @@ -237,7 +279,14 @@ impl std::cmp::PartialEq for Outer { impl std::cmp::Eq for Outer {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Secondary { pub a: i32, @@ -286,7 +335,14 @@ impl std::cmp::PartialEq for Secondary { impl std::cmp::Eq for Secondary {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct PtrMember { pub p: *mut i32, diff --git a/tests/unit/out/unsafe/operator_comparison_free.rs b/tests/unit/out/unsafe/operator_comparison_free.rs index 32cff29854..9d49a17880 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, @@ -63,7 +70,14 @@ pub unsafe fn operator_lt_7(mut a: i32, b: *const S) -> bool { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct V { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_comparison_member.rs b/tests/unit/out/unsafe/operator_comparison_member.rs index ea4b46c0a2..8f040647f7 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_comparison_mixed.rs b/tests/unit/out/unsafe/operator_comparison_mixed.rs index ee981c88a3..eecee4a3b6 100644 --- a/tests/unit/out/unsafe/operator_comparison_mixed.rs +++ b/tests/unit/out/unsafe/operator_comparison_mixed.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index 2545422fb7..ba720b4e53 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct X { pub v: i32, @@ -57,14 +64,28 @@ pub unsafe fn operator_ge_5(mut a: X, mut b: X) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Result { pub r: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Custom { pub v: i32, @@ -78,7 +99,14 @@ impl Custom { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Mixed { pub v: i32, @@ -128,6 +156,7 @@ impl std::cmp::Eq for Mixed {} FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -145,7 +174,14 @@ impl MyBool { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Boolish { pub v: i32, @@ -200,7 +236,9 @@ pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { }; } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, +)] #[cpp_into(bool, to_bool)] pub struct RefBool { pub value: bool, @@ -222,7 +260,14 @@ pub static mut ref_true_8: std::cell::LazyCell = std::cell::LazyCell::n }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct RefInt { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index 9ff1c43465..32de47ce5c 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -14,7 +14,12 @@ pub unsafe fn operator_lt_1(x: *const S, y: *const S) -> bool { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, MemberwiseUnsafe, Default, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DefaultInitializableUnsafe, + MemberwiseUnsafe, + Default, )] #[memberwise(move_constructor)] #[cpp_from(i32, construct, value)] diff --git a/tests/unit/out/unsafe/operator_compound_assignment_free.rs b/tests/unit/out/unsafe/operator_compound_assignment_free.rs index fb40f51dc6..8f4b0ef00a 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_free.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_free.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: u32, diff --git a/tests/unit/out/unsafe/operator_compound_assignment_member.rs b/tests/unit/out/unsafe/operator_compound_assignment_member.rs index 0808deae9b..3989e666b1 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_member.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_member.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: u32, diff --git a/tests/unit/out/unsafe/operator_friend.rs b/tests/unit/out/unsafe/operator_friend.rs index a6df4497b0..f87c82e9c5 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -11,7 +11,14 @@ pub unsafe fn operator_eq_0(_a0: *const Defaulted, _a1: *const Defaulted) -> boo } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Defaulted { pub a: i32, @@ -40,7 +47,14 @@ pub unsafe fn operator_eq_2(_a0: *const DefaultedOrd, _a1: *const DefaultedOrd) } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct DefaultedOrd { pub a: i32, @@ -74,7 +88,14 @@ pub unsafe fn operator_add_5(x: *const Inline, y: *const Inline) -> Inline { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inline { pub a: i32, @@ -105,7 +126,14 @@ impl std::cmp::PartialEq for Inline { impl std::cmp::Eq for Inline {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct OutOfLine { pub a: i32, @@ -136,7 +164,14 @@ pub unsafe fn operator_eq_10(x: *const Tmpl_int_, y: *const Tmpl_long_) -> bool } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Tmpl_int_ { pub v: i32, @@ -167,7 +202,14 @@ impl std::cmp::PartialEq for Tmpl_int_ { impl std::cmp::Eq for Tmpl_int_ {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Tmpl_long_ { pub v: i64, @@ -180,7 +222,14 @@ pub unsafe fn operator_eq_11( } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct TmplDefaulted_int_ { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_less_than.rs b/tests/unit/out/unsafe/operator_less_than.rs index f103a49839..6f57bf5217 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub x: i32, diff --git a/tests/unit/out/unsafe/operator_logical_free.rs b/tests/unit/out/unsafe/operator_logical_free.rs index db4b49c826..4e7bbefdc5 100644 --- a/tests/unit/out/unsafe/operator_logical_free.rs +++ b/tests/unit/out/unsafe/operator_logical_free.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_logical_member.rs b/tests/unit/out/unsafe/operator_logical_member.rs index a368075737..562497a560 100644 --- a/tests/unit/out/unsafe/operator_logical_member.rs +++ b/tests/unit/out/unsafe/operator_logical_member.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_member_pointer_free.rs b/tests/unit/out/unsafe/operator_member_pointer_free.rs index ee71b10103..32ef575f1e 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_free.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_free.rs @@ -8,14 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub x: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub data: [i32; 3], diff --git a/tests/unit/out/unsafe/operator_member_pointer_member.rs b/tests/unit/out/unsafe/operator_member_pointer_member.rs index a8a73c8051..1da1aa4c95 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_member.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_member.rs @@ -8,14 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub x: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Table {} impl Table { @@ -27,7 +41,14 @@ pub static mut table_0: std::cell::LazyCell<[i32; 3]> = std::cell::LazyCell::new(|| unsafe { [7, 8, 9] }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub data: [i32; 3], diff --git a/tests/unit/out/unsafe/operator_other_free.rs b/tests/unit/out/unsafe/operator_other_free.rs index 720986742f..47881cca64 100644 --- a/tests/unit/out/unsafe/operator_other_free.rs +++ b/tests/unit/out/unsafe/operator_other_free.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_other_member.rs b/tests/unit/out/unsafe/operator_other_member.rs index a86f1392c8..c20b77e1cd 100644 --- a/tests/unit/out/unsafe/operator_other_member.rs +++ b/tests/unit/out/unsafe/operator_other_member.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Static {} impl Static { @@ -24,6 +31,7 @@ impl Static { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] diff --git a/tests/unit/out/unsafe/operator_overloads.rs b/tests/unit/out/unsafe/operator_overloads.rs index 40733c02ca..fc09de884e 100644 --- a/tests/unit/out/unsafe/operator_overloads.rs +++ b/tests/unit/out/unsafe/operator_overloads.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_qualifiers.rs b/tests/unit/out/unsafe/operator_qualifiers.rs index d8385e40b6..af429253b9 100644 --- a/tests/unit/out/unsafe/operator_qualifiers.rs +++ b/tests/unit/out/unsafe/operator_qualifiers.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index 6ee24d91b7..eb74b41521 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index 00009f4690..ff4e03fc64 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Lt { pub v: i32, @@ -47,7 +54,14 @@ impl std::cmp::PartialEq for Lt { impl std::cmp::Eq for Lt {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Eq { pub v: i32, @@ -65,7 +79,14 @@ impl std::cmp::PartialEq for Eq { impl std::cmp::Eq for Eq {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Cmp { pub v: i32, @@ -96,7 +117,14 @@ impl std::cmp::PartialEq for Cmp { impl std::cmp::Eq for Cmp {} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Free { pub v: i32, @@ -133,7 +161,14 @@ pub unsafe fn operator_eq_1(a: *const Free, b: *const Free) -> bool { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Wrapped_int_ { pub v: i32, diff --git a/tests/unit/out/unsafe/overload_mangling.rs b/tests/unit/out/unsafe/overload_mangling.rs index c03438486d..a508eda753 100644 --- a/tests/unit/out/unsafe/overload_mangling.rs +++ b/tests/unit/out/unsafe/overload_mangling.rs @@ -17,7 +17,14 @@ pub unsafe fn twice_2(mut n: i32) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Access_S_ {} impl Access_S_ { @@ -36,7 +43,14 @@ impl Access_S_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub base: i32, @@ -112,7 +126,14 @@ impl S { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Box_ { pub v: i32, diff --git a/tests/unit/out/unsafe/pair.rs b/tests/unit/out/unsafe/pair.rs index 5517bc3b36..bdb5aec7b5 100644 --- a/tests/unit/out/unsafe/pair.rs +++ b/tests/unit/out/unsafe/pair.rs @@ -27,7 +27,7 @@ unsafe fn main_0() -> i32 { let arr: [i32; 2] = [1, 2]; let mut n: u32 = 2_u32; let mut const_ptr_pairs: Vec<(*const i32, u64)> = - Vec::from_fn(1_usize, |_| <(*const i32, u64)>::default()); + Vec::from_fn(1_usize, |_| (std::ptr::null(), 0_u64)); match ( (&mut const_ptr_pairs[(0_usize)] as *mut (*const i32, u64)), (&mut (arr.as_ptr().offset((1) as isize), n) as *mut (*const i32, u32)), diff --git a/tests/unit/out/unsafe/pair_converting_construction.rs b/tests/unit/out/unsafe/pair_converting_construction.rs index 21764ba5f4..d8dab07195 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.rs @@ -14,6 +14,7 @@ use std::rc::Rc; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -34,6 +35,7 @@ impl Celsius { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -54,6 +56,7 @@ impl Meters { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -74,6 +77,7 @@ impl Label { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -101,6 +105,7 @@ impl Owner { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -126,6 +131,13 @@ impl Fallback { (&raw mut self.value).write(v); } } +impl DefaultConstructibleUnsafe for Fallback { + unsafe fn default_constructor(&mut self) { + unsafe { + Fallback::construct(&mut *self, { -1_i32 }); + } + } +} impl Default for Fallback { fn default() -> Self { unsafe { @@ -139,7 +151,14 @@ impl Default for Fallback { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Counter { pub hits: i32, @@ -152,6 +171,7 @@ pub struct Counter { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -178,6 +198,7 @@ impl Tag { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -193,6 +214,7 @@ pub struct Tag { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] diff --git a/tests/unit/out/unsafe/pod.rs b/tests/unit/out/unsafe/pod.rs index 426d5907a1..6e89b4f531 100644 --- a/tests/unit/out/unsafe/pod.rs +++ b/tests/unit/out/unsafe/pod.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct POD { pub x1: i32, diff --git a/tests/unit/out/unsafe/pointer_array.rs b/tests/unit/out/unsafe/pointer_array.rs index ed7cea0ce1..56b9a155dc 100644 --- a/tests/unit/out/unsafe/pointer_array.rs +++ b/tests/unit/out/unsafe/pointer_array.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct StackArray { pub arr: [*mut i32; 3], diff --git a/tests/unit/out/unsafe/pointers.rs b/tests/unit/out/unsafe/pointers.rs index befa1c43c2..6a1d56e4fc 100644 --- a/tests/unit/out/unsafe/pointers.rs +++ b/tests/unit/out/unsafe/pointers.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Test { pub x: i32, diff --git a/tests/unit/out/unsafe/polymorphism.rs b/tests/unit/out/unsafe/polymorphism.rs index 5cd87101e7..393fb634c0 100644 --- a/tests/unit/out/unsafe/polymorphism.rs +++ b/tests/unit/out/unsafe/polymorphism.rs @@ -16,7 +16,7 @@ pub unsafe trait Animal { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyableUnsafe, Default, )] @@ -28,7 +28,7 @@ pub struct Dog {} VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyableUnsafe, Default, )] diff --git a/tests/unit/out/unsafe/ptr_cast_init.rs b/tests/unit/out/unsafe/ptr_cast_init.rs index b75e0c1aa8..2d789809c0 100644 --- a/tests/unit/out/unsafe/ptr_cast_init.rs +++ b/tests/unit/out/unsafe/ptr_cast_init.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct header { pub tag: i32, @@ -16,7 +23,14 @@ pub struct header { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 a641089e2b..d2ac4d13b8 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -8,14 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Chunk { pub data: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Writer { pub output: *mut Vec, @@ -38,6 +52,12 @@ pub struct JPEGData { pub com_data: Vec>, pub app_data: Vec>, } +impl DefaultConstructibleUnsafe for JPEGData { + unsafe fn default_constructor(&mut self) { + (&raw mut self.com_data).write(Vec::new()); + (&raw mut self.app_data).write(Vec::new()); + } +} pub unsafe fn push_param_0(mut dest: *mut Vec>) { { let __a1 = Vec::new(); @@ -113,25 +133,27 @@ pub struct Pair { pub second: i32, } impl Pair { - pub unsafe fn construct_2(&mut self) { - (&raw mut self.first).write(-1_i32); - (&raw mut self.second).write(-1_i32); - } pub unsafe fn construct_1(&mut self, mut a: i32) { (&raw mut self.first).write(a); (&raw mut self.second).write(0); } - pub unsafe fn construct_3(&mut self, mut a: i32, mut b: i32) { + pub unsafe fn construct_2(&mut self, mut a: i32, mut b: i32) { (&raw mut self.first).write(a); (&raw mut self.second).write(((b) * (2))); } } +impl DefaultConstructibleUnsafe for Pair { + unsafe fn default_constructor(&mut self) { + (&raw mut self.first).write(-1_i32); + (&raw mut self.second).write(-1_i32); + } +} impl Default for Pair { fn default() -> Self { unsafe { { let mut __v: Pair = ::zero_init(); - Pair::construct_2(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -140,7 +162,7 @@ impl Default for Pair { pub unsafe fn emplace_ctor_args_7(mut pairs: *mut Vec) { (*pairs).push_mut({ let mut __v: Pair = ::zero_init(); - Pair::construct_2(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }); (*pairs).push_mut({ @@ -150,19 +172,19 @@ pub unsafe fn emplace_ctor_args_7(mut pairs: *mut Vec) { }); (*pairs).push_mut({ let mut __v: Pair = ::zero_init(); - Pair::construct_3(&mut __v, { 4 }, { 5 }); + Pair::construct_2(&mut __v, { 4 }, { 5 }); __v }); } pub unsafe fn emplace_deque_8(mut queue: *mut Vec) { (*queue).push_mut({ let mut __v: Pair = ::zero_init(); - Pair::construct_3(&mut __v, { 6 }, { 7 }); + Pair::construct_2(&mut __v, { 6 }, { 7 }); __v }); (*queue).push_mut({ let mut __v: Pair = ::zero_init(); - Pair::construct_2(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }); } @@ -173,7 +195,7 @@ pub unsafe fn emplace_scalar_9(mut values: *mut Vec, mut x: i32) { pub unsafe fn emplace_ref_through_ptr_10(mut pairs: *mut Vec) { let p: *mut Pair = (*pairs).push_mut({ let mut __v: Pair = ::zero_init(); - Pair::construct_3(&mut __v, { 1 }, { 2 }); + Pair::construct_2(&mut __v, { 1 }, { 2 }); __v }); (*p).second = 3; @@ -192,7 +214,7 @@ pub unsafe fn emplace_self_reads_12(mut values: *mut Vec, mut pairs: *mut V (*pairs).push_mut((&mut (*pairs))[(0_usize)]); (*pairs).push_mut({ let mut __v: Pair = ::zero_init(); - Pair::construct_3( + Pair::construct_2( &mut __v, { (*{ @@ -226,6 +248,12 @@ pub struct Bytes { pub v: Vec>, pub b: [u8; 3], } +impl DefaultConstructibleUnsafe for Bytes { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write(Vec::new()); + (&raw mut self.b).write([0_u8; 3]); + } +} pub unsafe fn emplace_from_element_14(mut v: *mut Vec>) { let mut p: *mut u8 = (&mut (*v))[(0_usize)].as_mut_ptr(); (*v).push_mut({ @@ -241,7 +269,14 @@ pub unsafe fn emplace_from_element_14(mut v: *mut Vec>) { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Plain { pub a: i32, @@ -258,7 +293,14 @@ pub static mut all_counted_16: std::cell::LazyCell<*mut Vec> = std::cell::LazyCell::new(|| unsafe { std::ptr::null_mut() }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Counted { pub seen: usize, @@ -303,7 +345,8 @@ 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()); - let mut jpg: JPEGData = ::default(); + let mut jpg: JPEGData = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut jpg); (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))); @@ -382,7 +425,7 @@ unsafe fn main_0() -> i32 { let mut self_pairs: Vec = Vec::new(); self_pairs.push_mut({ let mut __v: Pair = ::zero_init(); - Pair::construct_3(&mut __v, { 1 }, { 2 }); + Pair::construct_2(&mut __v, { 1 }, { 2 }); __v }); (unsafe { diff --git a/tests/unit/out/unsafe/random.rs b/tests/unit/out/unsafe/random.rs index 1d648ec428..4c27c970b7 100644 --- a/tests/unit/out/unsafe/random.rs +++ b/tests/unit/out/unsafe/random.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub x: i32, @@ -44,7 +51,14 @@ pub unsafe fn zero_0() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct X1 {} pub unsafe fn foo_1(mut x1: i32, x2: *mut i32, mut x3: *mut i32, p2: *mut Pair, mut p3: *mut Pair) { diff --git a/tests/unit/out/unsafe/reference_wrapper.rs b/tests/unit/out/unsafe/reference_wrapper.rs index 1b0bea1b7d..a76872bfa6 100644 --- a/tests/unit/out/unsafe/reference_wrapper.rs +++ b/tests/unit/out/unsafe/reference_wrapper.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Point { pub x: i32, diff --git a/tests/unit/out/unsafe/references.rs b/tests/unit/out/unsafe/references.rs index 3aee6a8e84..20b4026bfa 100644 --- a/tests/unit/out/unsafe/references.rs +++ b/tests/unit/out/unsafe/references.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub x: i32, @@ -17,7 +24,14 @@ pub struct Pair { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Nested { pub p: Pair, diff --git a/tests/unit/out/unsafe/refs_as_args.rs b/tests/unit/out/unsafe/refs_as_args.rs index 6787508651..e3b97faeb2 100644 --- a/tests/unit/out/unsafe/refs_as_args.rs +++ b/tests/unit/out/unsafe/refs_as_args.rs @@ -19,7 +19,14 @@ pub unsafe fn more_refs_0(mut x1: i32, mut x2: i32, r1: *mut i32, r2: *const i32 } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Val { pub x: i32, diff --git a/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs b/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs index 4d4b50fbf5..685c6ac1b7 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub x: i32, @@ -16,7 +23,14 @@ pub struct S { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct W { pub h: i32, @@ -24,7 +38,14 @@ pub struct W { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct P { pub a: *mut i32, diff --git a/tests/unit/out/unsafe/reinterpret_cast_struct.rs b/tests/unit/out/unsafe/reinterpret_cast_struct.rs index 70c3f03d6a..228c415c15 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_struct.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Point { pub x: i32, 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 5d4fe4a7a4..c7c67b47d4 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_struct_to_struct.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_struct_to_struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Point { pub x: u32, @@ -16,7 +23,14 @@ pub struct Point { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub first: u32, diff --git a/tests/unit/out/unsafe/reserved_keywords.rs b/tests/unit/out/unsafe/reserved_keywords.rs index 877a6e3bd7..7383370766 100644 --- a/tests/unit/out/unsafe/reserved_keywords.rs +++ b/tests/unit/out/unsafe/reserved_keywords.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub as_: i32, @@ -52,14 +59,28 @@ pub struct S { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct type_ { pub v: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct loop_ { pub t: type_, diff --git a/tests/unit/out/unsafe/return_move.rs b/tests/unit/out/unsafe/return_move.rs index 55e500cd2f..3218f6d59d 100644 --- a/tests/unit/out/unsafe/return_move.rs +++ b/tests/unit/out/unsafe/return_move.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct node { pub value: i32, @@ -16,7 +23,14 @@ pub struct node { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct pair_t { pub a: i32, diff --git a/tests/unit/out/unsafe/rule_of_five.rs b/tests/unit/out/unsafe/rule_of_five.rs index 4642b609a7..00095af8a8 100644 --- a/tests/unit/out/unsafe/rule_of_five.rs +++ b/tests/unit/out/unsafe/rule_of_five.rs @@ -10,7 +10,15 @@ pub static mut alive_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moves_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, SwappableUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DefaultConstructibleUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Buffer { pub data: [i32; 4], diff --git a/tests/unit/out/unsafe/rule_of_three.rs b/tests/unit/out/unsafe/rule_of_three.rs index 35fb03efd2..2c4522dbcb 100644 --- a/tests/unit/out/unsafe/rule_of_three.rs +++ b/tests/unit/out/unsafe/rule_of_three.rs @@ -9,7 +9,15 @@ use std::rc::Rc; pub static mut alive_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, MovableUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DefaultConstructibleUnsafe, + MovableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Buffer { pub data: [i32; 4], diff --git a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs index bfb0002d1d..b44c23448b 100644 --- a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs +++ b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs @@ -14,7 +14,7 @@ pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, diff --git a/tests/unit/out/unsafe/rvalue_struct.rs b/tests/unit/out/unsafe/rvalue_struct.rs index d6ce18406c..8c37674c4b 100644 --- a/tests/unit/out/unsafe/rvalue_struct.rs +++ b/tests/unit/out/unsafe/rvalue_struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub a: i32, diff --git a/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs b/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs index a2269572cb..5d83198246 100644 --- a/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs +++ b/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pod { pub v: i32, diff --git a/tests/unit/out/unsafe/self_referencing_initializer.rs b/tests/unit/out/unsafe/self_referencing_initializer.rs index 2b3660c3e9..6328732c61 100644 --- a/tests/unit/out/unsafe/self_referencing_initializer.rs +++ b/tests/unit/out/unsafe/self_referencing_initializer.rs @@ -8,14 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct list_head { pub next: *mut list_head, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct node { pub value: i32, @@ -27,6 +41,12 @@ pub struct node_with_defaults { pub next: *mut node_with_defaults, pub value: i32, } +impl DefaultConstructibleUnsafe for node_with_defaults { + unsafe fn default_constructor(&mut self) { + (&raw mut self.next).write(std::ptr::null_mut()); + (&raw mut self.value).write(3); + } +} impl Default for node_with_defaults { fn default() -> Self { unsafe { diff --git a/tests/unit/out/unsafe/size_t_static_member.rs b/tests/unit/out/unsafe/size_t_static_member.rs index 769cdd00c5..a515d8b1e0 100644 --- a/tests/unit/out/unsafe/size_t_static_member.rs +++ b/tests/unit/out/unsafe/size_t_static_member.rs @@ -9,14 +9,28 @@ use std::rc::Rc; pub static mut c_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 5_usize }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S {} pub static mut table_size_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 256_usize }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Table_char_ {} pub fn main() { diff --git a/tests/unit/out/unsafe/size_t_template_param.rs b/tests/unit/out/unsafe/size_t_template_param.rs index 2ae0627be2..154b0534be 100644 --- a/tests/unit/out/unsafe/size_t_template_param.rs +++ b/tests/unit/out/unsafe/size_t_template_param.rs @@ -18,6 +18,7 @@ pub unsafe fn array_ref_0(a: *mut [u64; 3]) -> u64 { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -38,6 +39,7 @@ impl PtrCtor_unsigned_long_ { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index 23aa4f3ae7..a423be5afe 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -16,13 +16,15 @@ pub struct Tracked { pub v: i32, } impl Tracked { - pub unsafe fn construct_2(&mut self) { - (&raw mut self.v).write(0); - } pub unsafe fn construct_1(&mut self, mut v: i32) { (&raw mut self.v).write(v); } } +impl DefaultConstructibleUnsafe for Tracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write(0); + } +} impl CopyConstructibleUnsafe for Tracked { unsafe fn copy_constructor(&mut self, o: *const Tracked) { (&raw mut self.v).write((*o).v); @@ -88,7 +90,7 @@ impl Default for Tracked { unsafe { { let mut __v: Tracked = ::zero_init(); - Tracked::construct_2(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -105,7 +107,7 @@ pub unsafe fn greater_2(a: *const Tracked, b: *const Tracked) -> bool { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, @@ -166,6 +168,11 @@ pub unsafe fn operator_lt_3(a: *const MoveOnly, b: *const MoveOnly) -> bool { pub struct Bag { pub items: Vec, } +impl DefaultConstructibleUnsafe for Bag { + unsafe fn default_constructor(&mut self) { + (&raw mut self.items).write(Vec::new()); + } +} impl std::cmp::Ord for Bag { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { @@ -395,7 +402,11 @@ 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, _>(|_| ::default()); + let mut bags: [Bag; 3] = std::array::from_fn::<_, 3, _>(|_| { + let mut __v: Bag = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut __v); + __v + }); bags[(0) as usize].items.push_mut({ let mut __v: Tracked = ::zero_init(); Tracked::construct_1(&mut __v, { 1 }); diff --git a/tests/unit/out/unsafe/static_local.rs b/tests/unit/out/unsafe/static_local.rs index bb036d12a4..9e1e9cab3d 100644 --- a/tests/unit/out/unsafe/static_local.rs +++ b/tests/unit/out/unsafe/static_local.rs @@ -23,7 +23,14 @@ pub unsafe fn from_local_class_6() -> i32 { static mut x_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S_8 {} impl S_8 { diff --git a/tests/unit/out/unsafe/static_var_in_class.rs b/tests/unit/out/unsafe/static_var_in_class.rs index 47d463cbbe..51fca0f3dd 100644 --- a/tests/unit/out/unsafe/static_var_in_class.rs +++ b/tests/unit/out/unsafe/static_var_in_class.rs @@ -9,7 +9,14 @@ use std::rc::Rc; static mut inner_const_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct C {} impl C { @@ -22,7 +29,14 @@ pub type anon_3 = u32; pub const anon_3_kValue: anon_3 = 3; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S {} impl S { diff --git a/tests/unit/out/unsafe/stdcopy.rs b/tests/unit/out/unsafe/stdcopy.rs index 166d2a7737..8062f30857 100644 --- a/tests/unit/out/unsafe/stdcopy.rs +++ b/tests/unit/out/unsafe/stdcopy.rs @@ -14,6 +14,7 @@ use std::rc::Rc; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] diff --git a/tests/unit/out/unsafe/strdup.rs b/tests/unit/out/unsafe/strdup.rs index f8f193d880..6956bfcdf4 100644 --- a/tests/unit/out/unsafe/strdup.rs +++ b/tests/unit/out/unsafe/strdup.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 db1f57c658..2e80d468b6 100644 --- a/tests/unit/out/unsafe/string_literal_ptr_init.rs +++ b/tests/unit/out/unsafe/string_literal_ptr_init.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 8a30096f81..653aaaa9b4 100644 --- a/tests/unit/out/unsafe/string_substr.rs +++ b/tests/unit/out/unsafe/string_substr.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Text { pub value: *mut Vec, diff --git a/tests/unit/out/unsafe/struct_2d_array_field.rs b/tests/unit/out/unsafe/struct_2d_array_field.rs index eede3d9f91..029a03a6c9 100644 --- a/tests/unit/out/unsafe/struct_2d_array_field.rs +++ b/tests/unit/out/unsafe/struct_2d_array_field.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 0590ff9da9..9b32ca8b9e 100644 --- a/tests/unit/out/unsafe/struct_ctor.rs +++ b/tests/unit/out/unsafe/struct_ctor.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct StructWithCtor { x1_: i32, @@ -39,6 +46,7 @@ pub unsafe fn foo_0(x: *mut i32) -> *mut i32 { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -57,8 +65,8 @@ pub struct Ptr_ { pub v1: Value_, pub v2: Value_, } -impl Ptr_ { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for Ptr_ { + unsafe fn default_constructor(&mut self) { Value_::construct(&mut self.v1, { 11 }); Value_::construct(&mut self.v2, { 22 }); } @@ -68,7 +76,7 @@ impl Default for Ptr_ { unsafe { { let mut __v: Ptr_ = ::zero_init(); - Ptr_::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -90,7 +98,7 @@ unsafe fn main_0() -> i32 { && ((*(unsafe { StructWithCtor::x2(&struct_with_ctor,) })) == (1)) ); let mut p: Ptr_ = ::zero_init(); - Ptr_::construct(&mut p); + DefaultConstructibleUnsafe::default_constructor(&mut p); assert!(((p.v1.v) == (11))); assert!(((p.v2.v) == (22))); return 0; diff --git a/tests/unit/out/unsafe/struct_default_ctor.rs b/tests/unit/out/unsafe/struct_default_ctor.rs index 639719e520..c003d64bf9 100644 --- a/tests/unit/out/unsafe/struct_default_ctor.rs +++ b/tests/unit/out/unsafe/struct_default_ctor.rs @@ -12,8 +12,8 @@ pub struct S { pub a: i32, pub b: bool, } -impl S { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for S { + unsafe fn default_constructor(&mut self) { (&raw mut self.a).write(11); (&raw mut self.b).write(true); } @@ -23,7 +23,7 @@ impl Default for S { unsafe { { let mut __v: S = ::zero_init(); - S::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -36,7 +36,6 @@ impl Default for S { pub struct Declared { pub v: i32, } -impl Declared {} #[repr(C)] #[derive( Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, @@ -44,12 +43,26 @@ impl Declared {} pub struct Holder { pub items: [S; 2], } +impl DefaultConstructibleUnsafe for Holder { + unsafe fn default_constructor(&mut self) { + (&raw mut self.items).write(std::array::from_fn::<_, 2, _>(|_| { + let mut __v: S = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut __v); + __v + })); + } +} pub static mut kInit_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] pub struct FromStatic { pub v: i32, } +impl DefaultConstructibleUnsafe for FromStatic { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write((*std::cell::LazyCell::force_mut(&mut *&raw mut kInit_0))); + } +} impl Default for FromStatic { fn default() -> Self { unsafe { @@ -69,7 +82,7 @@ unsafe fn main_0() -> i32 { let mut d: *mut Declared = std::ptr::null_mut(); assert!((d).is_null()); let mut s: S = ::zero_init(); - S::construct(&mut s); + DefaultConstructibleUnsafe::default_constructor(&mut s); assert!(((s.a) == (11))); assert!(((s.b as i32) == (true as i32))); let mut h: *mut Holder = Box::leak( @@ -108,6 +121,11 @@ unsafe fn main_0() -> i32 { }; return 0; } +impl DefaultConstructibleUnsafe for Declared { + unsafe fn default_constructor(&mut self) { + unreachable!("Declared::default_constructor is never defined") + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const kInit_0); } diff --git a/tests/unit/out/unsafe/struct_member_array_adjacency.rs b/tests/unit/out/unsafe/struct_member_array_adjacency.rs index 3e0de4505b..6f27ef0fe8 100644 --- a/tests/unit/out/unsafe/struct_member_array_adjacency.rs +++ b/tests/unit/out/unsafe/struct_member_array_adjacency.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 16cebb0e9f..81b8aac399 100644 --- a/tests/unit/out/unsafe/struct_ptr.rs +++ b/tests/unit/out/unsafe/struct_ptr.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct XX { pub x: i32, diff --git a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs index 6cd2a5ad8d..496c724b7e 100644 --- a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs @@ -12,7 +12,7 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MovableUnsafe, Default, diff --git a/tests/unit/out/unsafe/structured_binding_element_ctor.rs b/tests/unit/out/unsafe/structured_binding_element_ctor.rs index 53168c11e1..c47d0957ed 100644 --- a/tests/unit/out/unsafe/structured_binding_element_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_element_ctor.rs @@ -14,7 +14,7 @@ pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, @@ -57,7 +57,7 @@ impl Clone for Elem { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, diff --git a/tests/unit/out/unsafe/structured_binding_move_ctor.rs b/tests/unit/out/unsafe/structured_binding_move_ctor.rs index e771405876..8d6f40f20d 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -13,7 +13,7 @@ pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe, SwappableUnsafe, @@ -80,6 +80,12 @@ impl Holder { return; } } +impl DefaultConstructibleUnsafe for Holder { + unsafe fn default_constructor(&mut self) { + (&raw mut self.xs).write(Vec::new()); + (&raw mut self.ys).write(Vec::new()); + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/structured_binding_range_for.rs b/tests/unit/out/unsafe/structured_binding_range_for.rs index 0e7b34de55..e38ab74e1d 100644 --- a/tests/unit/out/unsafe/structured_binding_range_for.rs +++ b/tests/unit/out/unsafe/structured_binding_range_for.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub first: i32, diff --git a/tests/unit/out/unsafe/structured_binding_ref.rs b/tests/unit/out/unsafe/structured_binding_ref.rs index 22848283b9..771faa1782 100644 --- a/tests/unit/out/unsafe/structured_binding_ref.rs +++ b/tests/unit/out/unsafe/structured_binding_ref.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Triple { pub a: i32, diff --git a/tests/unit/out/unsafe/structured_binding_trivial.rs b/tests/unit/out/unsafe/structured_binding_trivial.rs index 5c791ba031..cf68a5946d 100644 --- a/tests/unit/out/unsafe/structured_binding_trivial.rs +++ b/tests/unit/out/unsafe/structured_binding_trivial.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub first: i32, diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index 3e364975ed..429b098864 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -16,13 +16,15 @@ pub struct Tracked { pub v: i32, } impl Tracked { - pub unsafe fn construct_2(&mut self) { - (&raw mut self.v).write(0); - } pub unsafe fn construct_1(&mut self, mut v: i32) { (&raw mut self.v).write(v); } } +impl DefaultConstructibleUnsafe for Tracked { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write(0); + } +} impl CopyConstructibleUnsafe for Tracked { unsafe fn copy_constructor(&mut self, o: *const Tracked) { (&raw mut self.v).write((*o).v); @@ -61,7 +63,7 @@ impl Default for Tracked { unsafe { { let mut __v: Tracked = ::zero_init(); - Tracked::construct_2(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -83,10 +85,10 @@ pub struct Pair { pub x: Tracked, pub y: Tracked, } -impl Pair { - pub unsafe fn construct_1(&mut self) { - Tracked::construct_2(&mut self.x); - Tracked::construct_2(&mut self.y); +impl DefaultConstructibleUnsafe for Pair { + unsafe fn default_constructor(&mut self) { + DefaultConstructibleUnsafe::default_constructor(&mut self.x); + DefaultConstructibleUnsafe::default_constructor(&mut self.y); } } #[repr(C)] @@ -105,12 +107,34 @@ pub struct Arrays { pub a: [Tracked; 2], pub b: [Tracked; 2], } +impl DefaultConstructibleUnsafe for Arrays { + unsafe fn default_constructor(&mut self) { + (&raw mut self.a).write(std::array::from_fn::<_, 2, _>(|_| { + let mut __v: Tracked = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut __v); + __v + })); + (&raw mut self.b).write(std::array::from_fn::<_, 2, _>(|_| { + let mut __v: Tracked = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut __v); + __v + })); + } +} pub static mut copy_only_copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut copy_only_dtors_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, MovableUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DefaultConstructibleUnsafe, + MovableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct CopyOnly { pub v: i32, @@ -153,7 +177,7 @@ impl Clone for CopyOnly { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, SwappableUnsafe, @@ -170,7 +194,15 @@ pub static mut moves_3: std::cell::LazyCell = std::cell::LazyCell::new(|| u pub static mut move_assigns_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moved_dtors_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, SwappableUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DefaultConstructibleUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Moved { pub v: i32, @@ -228,7 +260,7 @@ impl Clone for Moved { VaArg, FnPtrArg, ZeroInitializationUnsafe, - DestructibleUnsafe, + DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, @@ -266,6 +298,11 @@ pub unsafe fn swapped_once_6() -> bool { pub struct Owner { pub p: Option>, } +impl DefaultConstructibleUnsafe for Owner { + unsafe fn default_constructor(&mut self) { + (&raw mut self.p).write(None); + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -550,7 +587,8 @@ 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))); - let mut arrays: Arrays = ::default(); + let mut arrays: Arrays = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut arrays); arrays.a[(0) as usize].v = 1; arrays.b[(1) as usize].v = 2; { diff --git a/tests/unit/out/unsafe/tag_vs_identifier_collision.rs b/tests/unit/out/unsafe/tag_vs_identifier_collision.rs index b877ab1c96..4519752d15 100644 --- a/tests/unit/out/unsafe/tag_vs_identifier_collision.rs +++ b/tests/unit/out/unsafe/tag_vs_identifier_collision.rs @@ -12,7 +12,14 @@ pub const widget_enum_MODE_ACTIVE: widget_enum = 1; pub const widget_enum_MODE_DONE: widget_enum = 2; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct widget { pub id: i32, @@ -20,14 +27,29 @@ pub struct widget { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct point_struct { pub x: i32, pub y: i32, } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union point { pub whole: i32, pub half: i16, @@ -38,7 +60,15 @@ impl Default for point { } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union slot_union { pub i: i32, pub u: u32, @@ -53,21 +83,42 @@ pub const slot_SLOT_A: slot = 0; pub const slot_SLOT_B: slot = 1; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub tag_field: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer { pub field: Inner, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 e7439926b7..47483c2e50 100644 --- a/tests/unit/out/unsafe/template_default_arg.rs +++ b/tests/unit/out/unsafe/template_default_arg.rs @@ -15,19 +15,21 @@ pub struct A { pub v: i32, } impl A { - pub unsafe fn construct_2(&mut self) { - (&raw mut self.v).write(1); - } pub unsafe fn construct_1(&mut self, mut v: i32) { (&raw mut self.v).write(v); } } +impl DefaultConstructibleUnsafe for A { + unsafe fn default_constructor(&mut self) { + (&raw mut self.v).write(1); + } +} impl Default for A { fn default() -> Self { unsafe { { let mut __v: A = ::zero_init(); - A::construct_2(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -38,8 +40,8 @@ impl Default for A { pub struct B { pub v: i32, } -impl B { - pub unsafe fn construct(&mut self) { +impl DefaultConstructibleUnsafe for B { + unsafe fn default_constructor(&mut self) { (&raw mut self.v).write(2); } } @@ -48,7 +50,7 @@ impl Default for B { unsafe { { let mut __v: B = ::zero_init(); - B::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v } } @@ -62,6 +64,7 @@ impl Default for B { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -94,6 +97,7 @@ pub unsafe fn always_given_3(mut x: NoDefault) -> i32 { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -120,7 +124,7 @@ unsafe fn main_0() -> i32 { ((unsafe { used_0({ let mut __v: A = ::zero_init(); - A::construct_2(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }) }) == (1)) @@ -138,7 +142,7 @@ unsafe fn main_0() -> i32 { ((unsafe { used_1({ let mut __v: B = ::zero_init(); - B::construct(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&mut __v); __v }) }) == (2)) diff --git a/tests/unit/out/unsafe/template_static_member.rs b/tests/unit/out/unsafe/template_static_member.rs index bc79dde79b..0036ac4a57 100644 --- a/tests/unit/out/unsafe/template_static_member.rs +++ b/tests/unit/out/unsafe/template_static_member.rs @@ -9,27 +9,55 @@ use std::rc::Rc; pub static mut s_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 55 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Static_int_ {} pub static mut s_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { (55 as libc::c_char) }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Static_char_ {} pub static mut s_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 55_i64 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Static_long_ {} pub static mut lo_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { -1_i32 }); pub static mut hi_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Range_int_ {} pub static mut lo_5: std::cell::LazyCell = @@ -37,7 +65,14 @@ pub static mut lo_5: std::cell::LazyCell = pub static mut hi_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 2_i64 }); #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Range_long_ {} pub fn main() { diff --git a/tests/unit/out/unsafe/temporary_field_addr.rs b/tests/unit/out/unsafe/temporary_field_addr.rs index 7f21ff56bf..f49b2ebbbc 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -22,6 +22,11 @@ use std::rc::Rc; pub struct Inner { pub values: Vec, } +impl DefaultConstructibleUnsafe for Inner { + unsafe fn default_constructor(&mut self) { + (&raw mut self.values).write(Vec::new()); + } +} #[repr(C)] #[derive( Clone, @@ -40,6 +45,13 @@ pub struct Outer { pub inner: Inner, pub name: [libc::c_char; 8], } +impl DefaultConstructibleUnsafe for Outer { + unsafe fn default_constructor(&mut self) { + (&raw mut self.values).write(Vec::new()); + DefaultConstructibleUnsafe::default_constructor(&mut self.inner); + (&raw mut self.name).write([(0 as libc::c_char); 8]); + } +} pub unsafe fn make_0(this: *mut Outer, calls: *mut i32) { (*calls).prefix_inc(); this.write(Outer { diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index 6f6520eed7..d2f7645b92 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -22,6 +22,11 @@ use std::rc::Rc; pub struct Outer { pub values: Vec, } +impl DefaultConstructibleUnsafe for Outer { + unsafe fn default_constructor(&mut self) { + (&raw mut self.values).write(Vec::new()); + } +} pub unsafe fn make_0(this: *mut Outer) { this.write(Outer { values: Vec::from([1, 2, 3, 4]), @@ -36,6 +41,7 @@ pub unsafe fn make_0(this: *mut Outer) { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index e2abfbf781..35738bb6ba 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -22,6 +22,11 @@ use std::rc::Rc; pub struct Inner { pub values: Vec, } +impl DefaultConstructibleUnsafe for Inner { + unsafe fn default_constructor(&mut self) { + (&raw mut self.values).write(Vec::new()); + } +} #[repr(C)] #[derive( Clone, @@ -39,6 +44,12 @@ pub struct Outer { pub values: Vec, pub inner: Inner, } +impl DefaultConstructibleUnsafe for Outer { + unsafe fn default_constructor(&mut self) { + (&raw mut self.values).write(Vec::new()); + DefaultConstructibleUnsafe::default_constructor(&mut self.inner); + } +} pub unsafe fn make_0(this: *mut Outer) { this.write(Outer { values: Vec::from([1, 2, 3]), diff --git a/tests/unit/out/unsafe/this.rs b/tests/unit/out/unsafe/this.rs index cca0ba2b77..1406ae60bf 100644 --- a/tests/unit/out/unsafe/this.rs +++ b/tests/unit/out/unsafe/this.rs @@ -14,6 +14,7 @@ use std::rc::Rc; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -117,6 +118,7 @@ pub unsafe fn bump_0(mut p: *mut S) { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] diff --git a/tests/unit/out/unsafe/typedef-anon-struct.rs b/tests/unit/out/unsafe/typedef-anon-struct.rs index fc3bf233d1..a718d740da 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Outer_RunInfo { pub block_idx: i32, @@ -30,6 +37,11 @@ pub struct Outer_RunInfo { pub struct Outer { pub runs: Vec, } +impl DefaultConstructibleUnsafe for Outer { + unsafe fn default_constructor(&mut self) { + (&raw mut self.runs).write(Vec::new()); + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -37,7 +49,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut o: Outer = ::default(); + let mut o: Outer = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut o); let mut info: Outer_RunInfo = ::default(); info.block_idx = 1; info.num_extra_zero_runs = 2; 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 21d2a4b70d..15e272bafb 100644 --- a/tests/unit/out/unsafe/unary_expr_or_type_trait.rs +++ b/tests/unit/out/unsafe/unary_expr_or_type_trait.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C, align(16))] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub c: libc::c_char, diff --git a/tests/unit/out/unsafe/unboxed_locals.rs b/tests/unit/out/unsafe/unboxed_locals.rs index ba618290d5..d2133b3f1a 100644 --- a/tests/unit/out/unsafe/unboxed_locals.rs +++ b/tests/unit/out/unsafe/unboxed_locals.rs @@ -14,7 +14,14 @@ pub unsafe fn inc_1(r: *mut i32) { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub first: i32, @@ -54,7 +61,13 @@ pub unsafe trait Shape { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultInitializableUnsafe, + CopyableUnsafe, )] pub struct Square { pub side: i32, diff --git a/tests/unit/out/unsafe/unboxed_records.rs b/tests/unit/out/unsafe/unboxed_records.rs index e417e9742c..fa5ce3612b 100644 --- a/tests/unit/out/unsafe/unboxed_records.rs +++ b/tests/unit/out/unsafe/unboxed_records.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub a: i32, @@ -16,7 +23,14 @@ pub struct Inner { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Cookie { pub x: i32, @@ -35,6 +49,11 @@ impl Counter { self.n.prefix_inc(); } } +impl DefaultConstructibleUnsafe for Counter { + unsafe fn default_constructor(&mut self) { + (&raw mut self.n).write(0); + } +} impl Default for Counter { fn default() -> Self { unsafe { Counter { n: 0 } } @@ -102,7 +121,8 @@ 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))); - let mut counter: Counter = ::default(); + let mut counter: Counter = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut counter); (unsafe { Counter::inc(&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 0f754c8ee8..074e9570c5 100644 --- a/tests/unit/out/unsafe/union_addrof_external.rs +++ b/tests/unit/out/unsafe/union_addrof_external.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct record { pub code: u16, @@ -17,7 +24,15 @@ pub struct record { pub pad: [libc::c_char; 8], } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub h: record, pub raw_: [libc::c_char; 128], @@ -29,7 +44,14 @@ impl Default for anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 a7abc7ab17..3db1c405cc 100644 --- a/tests/unit/out/unsafe/union_basic.rs +++ b/tests/unit/out/unsafe/union_basic.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union basic { pub i: i32, pub f: f32, @@ -18,7 +26,15 @@ impl Default for basic { } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union empty { __empty: u8, } @@ -28,7 +44,15 @@ impl Default for empty { } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union underscores { pub __: i32, pub ___: f64, @@ -91,7 +115,15 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub ai: i32, pub af: f32, diff --git a/tests/unit/out/unsafe/union_cross_arm_cast.rs b/tests/unit/out/unsafe/union_cross_arm_cast.rs index 09ac989918..4c6f8cb4ab 100644 --- a/tests/unit/out/unsafe/union_cross_arm_cast.rs +++ b/tests/unit/out/unsafe/union_cross_arm_cast.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct shape_a { pub code: u16, @@ -16,7 +23,14 @@ pub struct shape_a { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct shape_b { pub code: u16, @@ -26,7 +40,15 @@ pub struct shape_b { pub tail: u32, } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub a: shape_a, pub b: shape_b, @@ -39,7 +61,14 @@ impl Default for anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 e8e05f86a0..770621d105 100644 --- a/tests/unit/out/unsafe/union_field_alignment.rs +++ b/tests/unit/out/unsafe/union_field_alignment.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub bytes: [u8; 1], pub aligner: *mut ::libc::c_void, @@ -19,7 +27,14 @@ impl Default for anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 db9fcda57c..5dd0cae24b 100644 --- a/tests/unit/out/unsafe/union_flex_array_member.rs +++ b/tests/unit/out/unsafe/union_flex_array_member.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub bytes: [u8; 1], pub aligner: *mut ::libc::c_void, @@ -19,7 +27,14 @@ impl Default for anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 55f7fccb24..002f4c8e92 100644 --- a/tests/unit/out/unsafe/union_memset_memcpy.rs +++ b/tests/unit/out/unsafe/union_memset_memcpy.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct shape_a { pub code: u16, @@ -16,7 +23,14 @@ pub struct shape_a { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct shape_b { pub code: u16, @@ -25,7 +39,15 @@ pub struct shape_b { pub fill: [libc::c_char; 8], } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub a: shape_a, pub b: shape_b, @@ -38,7 +60,14 @@ impl Default for anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 8d3fcb317c..d01e16aaf6 100644 --- a/tests/unit/out/unsafe/union_nested.rs +++ b/tests/unit/out/unsafe/union_nested.rs @@ -8,14 +8,29 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct record { pub code: u16, pub pad: [libc::c_char; 14], } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub h: record, pub raw_: [libc::c_char; 128], @@ -27,13 +42,28 @@ impl Default for anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct inner { pub view: anon_0, } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_1 { pub h: record, pub nested: inner, @@ -45,7 +75,14 @@ impl Default for anon_1 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 69afa6f4c5..800d16877e 100644 --- a/tests/unit/out/unsafe/union_pointer_pun_address.rs +++ b/tests/unit/out/unsafe/union_pointer_pun_address.rs @@ -8,14 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct node_a { pub n: i32, } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct node_b { pub data: *mut ::libc::c_void, @@ -36,7 +50,15 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub to_a: *mut node_a, pub to_b: *mut node_b, diff --git a/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs b/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs index 61886a058c..abf73be7db 100644 --- a/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs +++ b/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs @@ -21,7 +21,15 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub as_unsigned: *mut u64, pub as_signed: *mut i64, diff --git a/tests/unit/out/unsafe/union_struct_dual_use.rs b/tests/unit/out/unsafe/union_struct_dual_use.rs index 002cfff370..eb77ee61b0 100644 --- a/tests/unit/out/unsafe/union_struct_dual_use.rs +++ b/tests/unit/out/unsafe/union_struct_dual_use.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub a: i32, @@ -18,7 +25,15 @@ pub unsafe fn sum_inner_0(mut i: *mut Inner) -> i32 { return (((*i).a) + ((*i).b)); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_1 { pub inner: Inner, pub raw_: [libc::c_char; 16], @@ -30,7 +45,14 @@ impl Default for anon_1 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 28a1e52f33..2b2c7abcde 100644 --- a/tests/unit/out/unsafe/union_tagged_many_arms.rs +++ b/tests/unit/out/unsafe/union_tagged_many_arms.rs @@ -13,7 +13,15 @@ pub const Tag_enum_T_TEXT: Tag_enum = 2; pub const Tag_enum_T_FLOAT: Tag_enum = 3; pub const Tag_enum_T_REF: Tag_enum = 4; #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub text: *const libc::c_char, pub handle: *mut ::libc::c_void, @@ -28,7 +36,14 @@ impl Default for anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 852e094d49..0797efcf2a 100644 --- a/tests/unit/out/unsafe/union_tagged_simple.rs +++ b/tests/unit/out/unsafe/union_tagged_simple.rs @@ -10,7 +10,15 @@ pub type Kind_enum = u32; pub const Kind_enum_KIND_NONE: Kind_enum = 0; pub const Kind_enum_KIND_DONE: Kind_enum = 1; #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub obj: *mut ::libc::c_void, pub code: i32, @@ -22,7 +30,14 @@ impl Default for anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 f55e0018a5..50de080c50 100644 --- a/tests/unit/out/unsafe/union_tagged_struct_arms.rs +++ b/tests/unit/out/unsafe/union_tagged_struct_arms.rs @@ -12,7 +12,14 @@ pub const Choice_enum_C_LETTERS: Choice_enum = 2; pub const Choice_enum_C_INTEGERS: Choice_enum = 3; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_1 { pub items: *mut *mut libc::c_char, @@ -21,7 +28,14 @@ pub struct anon_1 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_2 { pub lo: i32, @@ -31,7 +45,14 @@ pub struct anon_2 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct anon_3 { pub lo: i64, @@ -41,7 +62,15 @@ pub struct anon_3 { pub width: i32, } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub list: anon_1, pub letters: anon_2, @@ -54,7 +83,14 @@ impl Default for anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 4ab15acce4..404e5b9cb3 100644 --- a/tests/unit/out/unsafe/union_void_ptr_sized_deref.rs +++ b/tests/unit/out/unsafe/union_void_ptr_sized_deref.rs @@ -11,7 +11,15 @@ pub const Width_enum_W_64: Width_enum = 0; pub const Width_enum_W_32: Width_enum = 1; pub const Width_enum_W_16: Width_enum = 2; #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union anon_0 { pub text: *const libc::c_char, pub handle: *mut ::libc::c_void, @@ -25,7 +33,14 @@ impl Default for anon_0 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 c149f5685f..c0dcabc255 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -28,9 +28,21 @@ impl SafePointer { .prefix_inc(); } } +impl DefaultConstructibleUnsafe for SafePointer { + unsafe fn default_constructor(&mut self) { + (&raw mut self.ptr).write(None); + } +} #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Pair { pub x: i32, diff --git a/tests/unit/out/unsafe/unique_ptr_const_deref.rs b/tests/unit/out/unsafe/unique_ptr_const_deref.rs index e94b5ca597..4262d071d6 100644 --- a/tests/unit/out/unsafe/unique_ptr_const_deref.rs +++ b/tests/unit/out/unsafe/unique_ptr_const_deref.rs @@ -19,6 +19,11 @@ use std::rc::Rc; pub struct Holder { pub val: Option>, } +impl DefaultConstructibleUnsafe for Holder { + unsafe fn default_constructor(&mut self) { + (&raw mut self.val).write(None); + } +} pub unsafe fn read_val_0(mut h: *const Holder) -> i32 { return (*(*h) .val @@ -38,7 +43,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut h: Holder = ::default(); + let mut h: Holder = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut h); { 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 af0389c13b..e8e9a643f6 100644 --- a/tests/unit/out/unsafe/unique_ptr_field_reset.rs +++ b/tests/unit/out/unsafe/unique_ptr_field_reset.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Data { pub v: i32, @@ -39,6 +46,12 @@ impl Holder { }; } } +impl DefaultConstructibleUnsafe for Holder { + unsafe fn default_constructor(&mut self) { + (&raw mut self.data).write(None); + (&raw mut self.n).write(0_i32); + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -46,7 +59,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut h: Holder = ::default(); + let mut h: Holder = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut h); 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 1e46c6f7f9..3ff0cfe3eb 100644 --- a/tests/unit/out/unsafe/unique_ptr_nested.rs +++ b/tests/unit/out/unsafe/unique_ptr_nested.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Inner { pub x: i32, @@ -27,6 +34,11 @@ pub struct Inner { pub struct Outer { pub inner: Option>, } +impl DefaultConstructibleUnsafe for Outer { + unsafe fn default_constructor(&mut self) { + (&raw mut self.inner).write(None); + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/unique_ptr_struct.rs b/tests/unit/out/unsafe/unique_ptr_struct.rs index a19bcfabac..6fbf268dcf 100644 --- a/tests/unit/out/unsafe/unique_ptr_struct.rs +++ b/tests/unit/out/unsafe/unique_ptr_struct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Point { pub x: i32, diff --git a/tests/unit/out/unsafe/va_arg_mixed_types.rs b/tests/unit/out/unsafe/va_arg_mixed_types.rs index bfbaf84296..a49854d2a7 100644 --- a/tests/unit/out/unsafe/va_arg_mixed_types.rs +++ b/tests/unit/out/unsafe/va_arg_mixed_types.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 203e407a40..ca56031b25 100644 --- a/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 f8beb11294..234eabf4d5 100644 --- a/tests/unit/out/unsafe/va_arg_struct_ctx.rs +++ b/tests/unit/out/unsafe/va_arg_struct_ctx.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct context { pub verbose: i32, @@ -26,7 +33,15 @@ pub unsafe fn set_error_0( } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + FnPtrArg, + VaArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, +)] pub union value { pub i: i32, pub l: i64, diff --git a/tests/unit/out/unsafe/va_arg_void_ptr.rs b/tests/unit/out/unsafe/va_arg_void_ptr.rs index 134c4d2127..02d10525e7 100644 --- a/tests/unit/out/unsafe/va_arg_void_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_void_ptr.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + 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 dfa3571717..f1a33733a0 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -28,7 +28,14 @@ pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DefaultConstructibleUnsafe, + CopyableUnsafe, + Default, )] #[cpp_from(*const VaArg , construct, mut_ptr)] pub struct Guard_1 { @@ -66,7 +73,14 @@ pub unsafe fn sum_ptr_2(mut n: i32, __args: Box<[VaArg]>) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Cursor_3 { pub ap: *mut *const VaArg, diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index 9a18bc7161..5e4e804b63 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct S { pub x: i32, @@ -31,6 +38,12 @@ pub struct Foo { pub a: Vec, pub b: Vec, } +impl DefaultConstructibleUnsafe for Foo { + unsafe fn default_constructor(&mut self) { + (&raw mut self.a).write(Vec::new()); + (&raw mut self.b).write(Vec::new()); + } +} #[repr(C)] #[derive( Copy, @@ -39,6 +52,7 @@ pub struct Foo { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -249,8 +263,7 @@ unsafe fn main_0() -> i32 { i.prefix_inc(); } } - let mut v7: Vec<(*const i32, i32)> = - Vec::from_fn(200_usize, |_| <(*const i32, i32)>::default()); + let mut v7: Vec<(*const i32, i32)> = Vec::from_fn(200_usize, |_| (std::ptr::null(), 0_i32)); assert!(((v7.len()) == (200_usize))); { let mut i: u32 = 0_u32; @@ -390,7 +403,8 @@ unsafe fn main_0() -> i32 { ((((v10.len()) == (1_usize)) && ((v10[(0_usize)]) == (4))) && ((v11.len()) == (3_usize))) && ((v11[(2_usize)]) == (3)) ); - let mut foo: Foo = ::default(); + let mut foo: Foo = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut foo); { let __a1 = 5; foo.a.push(__a1) diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index c01dfed5bc..950aef3614 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -14,6 +14,7 @@ use std::rc::Rc; FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] @@ -34,6 +35,7 @@ impl Degrees { FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, + TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, )] diff --git a/tests/unit/out/unsafe/vector_subscript_direct.rs b/tests/unit/out/unsafe/vector_subscript_direct.rs index 19e48705ef..73e285d3c4 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Point { pub x: i32, @@ -36,6 +43,12 @@ pub struct Holder { pub values: Vec, pub points: Vec, } +impl DefaultConstructibleUnsafe for Holder { + unsafe fn default_constructor(&mut self) { + (&raw mut self.values).write(Vec::new()); + (&raw mut self.points).write(Vec::new()); + } +} pub unsafe fn push_and_index_0(v: *mut Vec) -> i32 { { let __a1 = 42; @@ -96,7 +109,8 @@ unsafe fn main_0() -> i32 { (*p) = 9; assert!(((v[(2_usize)]) == (9))); assert!(((unsafe { sum_ref_1(&v,) }) == (((((3) + (0)) + (9)) + (42)) + (5)))); - let mut h: Holder = ::default(); + let mut h: Holder = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut h); 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 6ea2e26239..1f17dc9a6d 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -8,7 +8,14 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct TestAllocator_int_ {} impl TestAllocator_int_ { @@ -30,7 +37,14 @@ impl TestAllocator_int_ { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct TestAllocator_double_ {} impl TestAllocator_double_ { diff --git a/tests/unit/out/unsafe/void_cast.rs b/tests/unit/out/unsafe/void_cast.rs index 4851a690fa..38d8a90d65 100644 --- a/tests/unit/out/unsafe/void_cast.rs +++ b/tests/unit/out/unsafe/void_cast.rs @@ -23,6 +23,11 @@ pub unsafe fn unused_param_0(mut x: i32) {} pub struct NonTrivial { pub data: Vec, } +impl DefaultConstructibleUnsafe for NonTrivial { + unsafe fn default_constructor(&mut self) { + (&raw mut self.data).write(Vec::new()); + } +} pub unsafe fn unused_ref_param_1(x: *const NonTrivial) {} pub unsafe fn unused_ptr_param_2(mut p: *const NonTrivial) {} pub static mut side_effect_counter_3: std::cell::LazyCell = @@ -33,7 +38,14 @@ pub unsafe fn bump_and_return_4() -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, )] pub struct Holder { pub field: i32, @@ -51,6 +63,11 @@ pub struct Holder { pub struct NonCopyable { pub value: Option>, } +impl DefaultConstructibleUnsafe for NonCopyable { + unsafe fn default_constructor(&mut self) { + (&raw mut self.value).write(None); + } +} pub unsafe fn unused_noncopyable_param_5(x: *const NonCopyable) {} pub fn main() { unsafe { @@ -101,7 +118,8 @@ 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); - let mut nt: NonTrivial = ::default(); + let mut nt: NonTrivial = ::zero_init(); + DefaultConstructibleUnsafe::default_constructor(&mut nt); (unsafe { unused_ref_param_1(&nt) }); (unsafe { unused_ptr_param_2((&mut nt as *mut NonTrivial).cast_const()) }); let mut g: NonCopyable = NonCopyable {