diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 9765771a79..c564fa71ad 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -34,6 +34,10 @@ std::unordered_set Converter::globals_; std::vector Converter::global_inits_; Converter::RecordIndex Converter::record_decls_; std::map Converter::virtual_methods_; +std::map> + Converter::declared_record_traits_; +std::set> + Converter::converted_record_traits_; void Converter::EmitFilePreamble() { StrCat(R"( @@ -62,6 +66,31 @@ void Converter::EmitVirtualMethods(std::string &out) { } } +void Converter::EmitUndefinedRecordTraits(Model model, std::string &out) { + bool is_unsafe = model == Model::kUnsafe; + for (const auto &[record, traits] : declared_record_traits_) { + for (const auto &[name, trait] : traits) { + if (converted_record_traits_.contains({record, name})) { + continue; + } + 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); + } + } +} + +void Converter::DeclareRecordTraits(const clang::CXXRecordDecl *decl) { + for (auto *method : decl->methods()) { + if (auto *trait = GetRecordTrait(method)) { + declared_record_traits_[GetRecordName(decl)].emplace(trait->name, trait); + } + } +} + std::string Converter::ForceGlobalInit(const clang::VarDecl *decl) { return std::format("std::cell::LazyCell::force(&*&raw const {});", GetNamedDeclAsString(decl)); @@ -753,8 +782,8 @@ bool Converter::VarTypeNeedsDestructor(clang::QualType type) const { } std::string Converter::StaticDestructorCall(const clang::VarDecl *decl) { - return std::format("DestructibleUnsafe::destroy(&raw mut " - "*std::cell::LazyCell::force_mut(&mut *&raw mut {}))", + return std::format("DestructibleUnsafe::destroy(" + "std::cell::LazyCell::force_mut(&mut *&raw mut {}))", GetNamedDeclAsString(decl)); } @@ -762,10 +791,11 @@ void Converter::EmitScopedDestructor(const clang::VarDecl *decl) { if (!NeedsScopedDestructor(decl)) { return; } - StrCat(token::kSemiColon, - std::format("let _dtor_{0} = std::mem::DropGuard::new(&raw mut {0}, " - "|__p| unsafe {{ DestructibleUnsafe::destroy(__p) }})", - GetNamedDeclAsString(decl))); + StrCat( + token::kSemiColon, + std::format("let _dtor_{0} = std::mem::DropGuard::new(&raw mut {0}, " + "|__p| unsafe {{ DestructibleUnsafe::destroy(&mut *__p) }})", + GetNamedDeclAsString(decl))); } bool Converter::RecordDerivesDefault(const clang::RecordDecl *decl) { @@ -991,6 +1021,7 @@ void Converter::EmitRustStructOrUnion(clang::RecordDecl *decl) { ConvertCXXRecordMethods(cxx); ConvertVirtualMethods(cxx); AddOrdTrait(cxx); + DeclareRecordTraits(cxx); } AddCloneTrait(decl); AddDefaultTrait(decl); @@ -1007,36 +1038,57 @@ void Converter::ConvertTemplateInstantiatedCtors(clang::CXXRecordDecl *decl) { } void Converter::ConvertLateInstantiatedMethods(clang::CXXRecordDecl *decl) { + auto predicate = [](clang::CXXMethodDecl *method) { + return IsEmittableMethod(method) && method->hasBody() && + !decl_ids_.contains(GetMethodID(method)); + }; ConvertCXXMethodDecls( decl, std::format("{} {}", keyword::kImpl, GetRecordName(decl)), - [](auto *method) { - return IsEmittableMethod(method) && method->hasBody() && - !decl_ids_.contains(GetMethodID(method)); - }); + predicate); + ConvertCopyOrMoveTraitImpls(decl, predicate); +} + +void Converter::ConvertCopyOrMoveTraitImpls( + const clang::CXXRecordDecl *decl, + bool (*predicate)(clang::CXXMethodDecl *)) { + ForEachMethod(decl, [&](clang::CXXMethodDecl *method) { + if (predicate(method) && GetRecordTrait(method)) { + VisitCXXMethodDecl(method); + } + }); +} + +void Converter::ConvertCopyOrMoveTraitImpl(clang::CXXMethodDecl *method, + const RecordTrait &trait) { + std::string body; + { + Buffer buf(*this); + ConvertCXXMethodDecl(method); + body = std::move(buf).str(); + } + if (body.empty()) { + return; + } + converted_record_traits_.emplace(GetRecordName(method->getParent()), + trait.name); + StrCat(keyword::kImpl, GetCopyOrMoveTraitName(trait), "for", + GetRecordName(method->getParent())); + PushBrace brace(*this); + StrCat(body); } void Converter::ConvertCXXRecordMethods(clang::CXXRecordDecl *decl) { ConvertCXXMethodDecls( decl, std::format("{} {}", keyword::kImpl, GetRecordName(decl)), IsEmittableMethod); - - if (GetUserDefinedDestructor(decl) || !HasFieldsNeedingDestruction(decl)) { - return; - } - StrCat(keyword::kImpl, GetRecordName(decl)); - PushBrace impl_brace(*this); - StrCat(keyword::kPub, keyword_unsafe_, keyword::kFn, kDestructorName, - "(&mut self)"); - PushBrace fn_brace(*this); - StrCat(DestroyMembers(decl)); + ConvertCopyOrMoveTraitImpls(decl, IsEmittableMethod); } std::string Converter::DestroyMembers(const clang::CXXRecordDecl *decl) { std::string out; for (auto *field : FieldsToDestroy(decl)) { auto name = GetNamedDeclAsString(field); - out += - std::format("DestructibleUnsafe::destroy(&raw mut self.{});\n", name); + out += std::format("DestructibleUnsafe::destroy(&mut self.{});\n", name); } return out; } @@ -1168,6 +1220,10 @@ bool Converter::VisitCXXMethodDecl(clang::CXXMethodDecl *decl) { } ScopedValue push_fn(curr_function_, decl); + if (auto *trait = GetRecordTrait(decl)) { + ConvertCopyOrMoveTraitImpl(decl, *trait); + return false; + } if (decl->isOutOfLine() && !decl->overridden_methods().empty()) { return ConvertOutOfLineVirtualMethod(decl); } @@ -1188,6 +1244,9 @@ bool Converter::ConvertOutOfLineMethod(clang::CXXMethodDecl *decl) { } std::string Converter::GetMethodName(const clang::CXXMethodDecl *decl) { + if (auto *trait = GetRecordTrait(decl)) { + return trait->method; + } if (clang::isa(decl)) { return kDestructorName; } @@ -1227,7 +1286,7 @@ bool Converter::ConvertCXXMethodDecl(clang::CXXMethodDecl *decl) { return VisitCXXConstructorDecl(ctor); } - if (method_target_ == MethodTarget::ValueImpl && + if (method_target_ == MethodTarget::ValueImpl && !GetRecordTrait(decl) && (decl->isStatic() || (!decl->isVirtual() && !decl->getParent()->isAbstract()))) { StrCat(AccessSpecifierAsString(decl->getAccess())); @@ -1260,6 +1319,9 @@ std::string Converter::GetSelfMaybeWithMut(const clang::CXXMethodDecl *decl) { } std::string Converter::GetCtorName(clang::CXXConstructorDecl *decl) { + if (auto *trait = GetRecordTrait(decl)) { + return trait->method; + } if (decl->isCopyOrMoveConstructor()) { if (const char *name = GetCopyOrMoveName(decl); CanUseCopyOrMoveName(decl, name)) { @@ -1278,7 +1340,7 @@ bool Converter::VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl) { } ScopedValue push_fn(curr_function_, decl); - if (method_target_ == MethodTarget::ValueImpl) { + if (method_target_ == MethodTarget::ValueImpl && !GetRecordTrait(decl)) { StrCat(AccessSpecifierAsString(decl->getAccess())); } StrCat(keyword_unsafe_, keyword::kFn, GetCtorName(decl)); @@ -2456,9 +2518,16 @@ void Converter::ConvertGenericCallExpr(clang::CallExpr *expr) { } std::string Converter::GetUFCSName(const clang::CXXMethodDecl *method) const { + if (auto *trait = GetRecordTrait(method)) { + return GetCopyOrMoveTraitName(*trait); + } return GetRecordName(method->getParent()); } +const char *Converter::GetCopyOrMoveTraitName(const RecordTrait &trait) const { + return trait.unsafe_name; +} + void Converter::ConvertUserOperatorCall(clang::CXXOperatorCallExpr *expr) { auto *callee = expr->getDirectCallee(); PushParen outer(*this); @@ -3904,8 +3973,7 @@ bool Converter::VisitMemberExpr(clang::MemberExpr *expr) { if (auto *method = clang::dyn_cast(member); method && IsMethodOnPtr(method) && !Mapper::Contains(ctx_, expr)) { SetUFCSReceiver(expr->getBase(), expr->isArrow(), method); - StrCat(GetRecordName(method->getParent()), token::kDoubleColon, - GetMethodName(method)); + StrCat(GetUFCSName(method), token::kDoubleColon, GetMethodName(method)); MarkFresh(); return false; } @@ -4369,10 +4437,10 @@ bool Converter::VisitCXXDeleteExpr(clang::CXXDeleteExpr *expr) { StrCat( std::format("for __i in (0..libcc2rs::malloc_usable_size(__p as *mut " "::libc::c_void) / ::std::mem::size_of::<{0}>()).rev() {{ " - "DestructibleUnsafe::destroy(__p.add(__i)); }}", + "DestructibleUnsafe::destroy(&mut *__p.add(__i)); }}", record_name)); } else { - StrCat("DestructibleUnsafe::destroy(__p)", token::kSemiColon); + StrCat("DestructibleUnsafe::destroy(&mut *__p)", token::kSemiColon); } EmitDeallocation(expr, "__p"); return false; @@ -4440,6 +4508,9 @@ const char *Converter::GetConstructorWrite() const { std::string Converter::GetConstructorPath(const clang::CXXConstructorDecl *ctor) const { + if (auto *trait = GetRecordTrait(ctor)) { + return GetCopyOrMoveTraitName(*trait); + } return GetRecordName(ctor->getParent()); } @@ -4964,7 +5035,14 @@ std::string Converter::GetRecordName(const clang::NamedDecl *decl) const { std::vector Converter::GetStructAttributes(const clang::RecordDecl *decl) { if (decl->isUnion()) { - return {"Copy", "Clone", "FnPtrArg", "VaArg", "ZeroInitializationUnsafe"}; + std::vector union_attrs = {"Copy", + "Clone", + "FnPtrArg", + "VaArg", + "ZeroInitializationUnsafe", + "DestructibleUnsafe"}; + AddCopyAndMoveDerives(decl, union_attrs); + return union_attrs; } std::vector struct_attrs; @@ -4983,27 +5061,16 @@ Converter::GetStructAttributes(const clang::RecordDecl *decl) { struct_attrs.emplace_back("FnPtrArg"); struct_attrs.emplace_back("ZeroInitializationUnsafe"); - if (HasMoveFromConstructor(decl)) { - struct_attrs.emplace_back("MoveCtorUnsafe"); - } - if (HasImplicitConversions(decl)) { struct_attrs.emplace_back("CppFromUnsafe"); } - if (HasCopyAssignOperator(decl)) { - struct_attrs.emplace_back("CopyAssignUnsafe"); - } - - if (HasMoveAssignOperator(decl)) { - struct_attrs.emplace_back("MoveAssignUnsafe"); - } - - if (auto *cxx = clang::dyn_cast(decl); - cxx && RecordNeedsDestruction(cxx)) { + if (!ImplementsRecordTrait(decl, kDestructible)) { struct_attrs.emplace_back("DestructibleUnsafe"); } + AddCopyAndMoveDerives(decl, struct_attrs); + if (RecordDerivesDefault(decl)) { struct_attrs.emplace_back("Default"); } @@ -5248,7 +5315,7 @@ void Converter::ConvertCXXMethodDecls( bool (*predicate)(clang::CXXMethodDecl *)) { bool first = true; auto convert_method = [&](clang::CXXMethodDecl *method) { - if (predicate(method)) { + if (predicate(method) && !GetRecordTrait(method)) { if (first) { StrCat(signature, token::kOpenCurlyBracket); first = false; @@ -5281,7 +5348,8 @@ void Converter::ConvertVirtualMethods(clang::CXXRecordDecl *decl) { bool any = false; Buffer buf(*this); for (auto *method : decl->methods()) { - if (!method->isImplicit() && method->isVirtual()) { + if (!method->isImplicit() && method->isVirtual() && + !GetRecordTrait(method)) { any = true; VisitCXXMethodDecl(method); } @@ -5512,6 +5580,44 @@ void Converter::AddCloneTrait(const clang::RecordDecl *decl) { TakePlacementValue())); } +void Converter::AddCopyAndMoveDerives(const clang::RecordDecl *decl, + std::vector &attrs) { + auto implements = [&](const RecordTrait *trait) { + return ImplementsRecordTrait(decl, *trait); + }; + const RecordTrait *copy[] = {&kCopyConstructible, &kCopyAssignable}; + const RecordTrait *move[] = {&kMoveConstructible, &kMoveAssignable}; + bool copies = decl->isUnion() || RecordImplementsClone(decl); + bool writes_move = llvm::any_of(move, implements); + if (copies && !writes_move && llvm::none_of(copy, implements)) { + attrs.emplace_back(GetCopyOrMoveTraitName(kCopyable)); + return; + } + if (copies) { + for (const auto *trait : copy) { + if (!implements(trait)) { + attrs.emplace_back(GetCopyOrMoveTraitName(*trait)); + } + } + } + if (!writes_move) { + if (copies) { + attrs.emplace_back(GetCopyOrMoveTraitName(kMovable)); + } + return; + } + if (copies) { + for (const auto *trait : move) { + if (!implements(trait)) { + attrs.emplace_back(GetCopyOrMoveTraitName(*trait)); + } + } + } + if (copies || llvm::all_of(move, implements)) { + attrs.emplace_back(GetCopyOrMoveTraitName(kSwappable)); + } +} + bool Converter::RecordImplementsClone(const clang::RecordDecl *decl) { return HasDefaultedCopyConstructor(decl) || GetUserDefinedCopyConstructor(decl) != nullptr; @@ -6458,39 +6564,6 @@ std::string Converter::ConvertGenericCall( assert(call_args.empty() && "default takes no arguments"); return GetUnboxedDefaultAsString(type); } - if (call.method == "move_ctor") { - assert(call_args.size() == 1 && "move_ctor takes one argument"); - auto *record = type->getAsCXXRecordDecl(); - if (record && (HasMoveFromConstructor(record) || - (!IsUserDefinedDecl(record) && - !record->hasTrivialMoveConstructor()))) { - return std::format("<{} as {}>::move_ctor({})", - GetUnboxedTypeAsString(type), GetMoveCtorTraitName(), - call_args[0]); - } - return ConvertPtrRead(type, call_args[0]); - } - if (call.method == "move_assign" || call.method == "copy_assign") { - assert(call_args.size() == 2 && "assignments take two arguments"); - bool is_move = call.method == "move_assign"; - auto *record = type->getAsCXXRecordDecl(); - if (record && is_move && HasMoveAssignOperator(record)) { - return ConvertPointeeMethodCall("move_assign", call_args[0], - call_args[1]); - } - if (record && HasCopyAssignOperator(record)) { - return ConvertPointeeMethodCall("copy_assign", call_args[0], - call_args[1]); - } - if (is_move && record && !IsUserDefinedDecl(record) && - !record->hasTrivialMoveAssignment()) { - return ConvertPtrWrite(call_args[0], - std::format("<{} as {}>::move_ctor({})", - GetUnboxedTypeAsString(type), - GetMoveCtorTraitName(), call_args[1])); - } - return ConvertPtrWrite(call_args[0], ConvertPtrRead(type, call_args[1])); - } if (call.method == "cpp_from" || call.method == "cpp_from_move") { assert(call_args.size() == 1 && "cpp_from takes one argument"); return ConvertConversion( @@ -6530,27 +6603,6 @@ const char *Converter::GetConversionTraitName() const { return "CppFromUnsafe"; } -std::string Converter::ConvertPtrRead(clang::QualType type, - const std::string &src) { - if (type->isScalarType()) { - return std::format("(*{})", src); - } - return std::format("(*{}).clone()", src); -} - -std::string Converter::ConvertPtrWrite(const std::string &dst, - const std::string &value) { - return std::format("*{} = {}", dst, value); -} - -std::string Converter::ConvertPointeeMethodCall(const char *method, - const std::string &dst, - const std::string &src) { - return std::format("(*{}).{}({})", dst, method, src); -} - -const char *Converter::GetMoveCtorTraitName() const { return "MoveCtorUnsafe"; } - std::string Converter::DerefPtrExpr(std::string_view ptr_expr, clang::QualType pointee_type) { return std::format("({}{})", GetPointerDerefPrefix(pointee_type), ptr_expr); diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 8919834443..61afaa0057 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -108,6 +109,7 @@ class Converter : public clang::RecursiveASTVisitor { static void EmitGlobalInits(Model model, std::string &out); static void EmitVirtualMethods(std::string &out); + static void EmitUndefinedRecordTraits(Model model, std::string &out); virtual bool VisitBuiltinType(clang::BuiltinType *type); @@ -358,17 +360,10 @@ class Converter : public clang::RecursiveASTVisitor { virtual const char *GetConversionTraitName() const; - virtual std::string ConvertPtrRead(clang::QualType type, - const std::string &src); + virtual const char *GetCopyOrMoveTraitName(const RecordTrait &trait) const; - virtual std::string ConvertPtrWrite(const std::string &dst, - const std::string &value); - - virtual std::string ConvertPointeeMethodCall(const char *method, - const std::string &dst, - const std::string &src); - - virtual const char *GetMoveCtorTraitName() const; + void AddCopyAndMoveDerives(const clang::RecordDecl *decl, + std::vector &attrs); virtual std::string DerefPtrExpr(std::string_view ptr_expr, clang::QualType pointee_type); @@ -892,6 +887,12 @@ class Converter : public clang::RecursiveASTVisitor { virtual void ConvertAbstractClass(clang::CXXRecordDecl *decl); + void ConvertCopyOrMoveTraitImpls(const clang::CXXRecordDecl *decl, + bool (*predicate)(clang::CXXMethodDecl *)); + + void ConvertCopyOrMoveTraitImpl(clang::CXXMethodDecl *method, + const RecordTrait &trait); + void ConvertCXXMethodDecls(const clang::CXXRecordDecl *decl, const std::string_view signature, bool (*predicate)(clang::CXXMethodDecl *)); @@ -1271,6 +1272,11 @@ class Converter : public clang::RecursiveASTVisitor { std::string body; }; static std::map virtual_methods_; + static std::map> + declared_record_traits_; + static std::set> converted_record_traits_; + + void DeclareRecordTraits(const clang::CXXRecordDecl *decl); static void EmitDeferredBlock(const DeferredBlock &block, std::string &out); diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 8656ef2717..04bd24e1a2 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -602,6 +602,58 @@ bool CanUseCopyOrMoveName(const clang::CXXMethodDecl *decl, return is_unique_member && !HasMethodNamed(record, name); } +static bool IsTranslatedCopyAssignment(const clang::CXXMethodDecl *method); + +static bool IsTranslatedMoveAssignment(const clang::CXXMethodDecl *method); + +static bool IsTranslatedCopyOrMove(const clang::CXXMethodDecl *method) { + if (auto *ctor = clang::dyn_cast(method)) { + return IsConvertibleCopyOrMoveConstructor(ctor); + } + return method->isCopyAssignmentOperator() + ? IsTranslatedCopyAssignment(method) + : IsTranslatedMoveAssignment(method); +} + +static bool IsUserWrittenMember(const clang::CXXMethodDecl *method) { + if (!method->isUserProvided() || !IsUserDefinedDecl(method)) { + return false; + } + auto *definition = method->getDefinition(); + return !definition || !definition->isDefaulted(); +} + +const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { + method = method->getCanonicalDecl(); + if (auto *dtor = clang::dyn_cast(method)) { + return (IsUserWrittenMember(dtor) || IsConvertedDestructor(dtor)) && + !dtor->getParent()->isAbstract() + ? &kDestructible + : nullptr; + } + const char *name = GetCopyOrMoveName(method); + if (!name || method->isDeleted() || method->isVirtual() || + !CanUseCopyOrMoveName(method, name) || + (!IsUserWrittenMember(method) && !IsTranslatedCopyOrMove(method))) { + return nullptr; + } + auto *ctor = clang::dyn_cast(method); + if (!ctor && !method->getReturnType()->isLValueReferenceType()) { + return nullptr; + } + auto param = method->getParamDecl(0)->getType(); + bool is_copy = + ctor ? ctor->isCopyConstructor() : method->isCopyAssignmentOperator(); + if (!param->isReferenceType() || + param.getNonReferenceType().isConstQualified() != is_copy) { + return nullptr; + } + if (ctor) { + return is_copy ? &kCopyConstructible : &kMoveConstructible; + } + return is_copy ? &kCopyAssignable : &kMoveAssignable; +} + bool IsUserDefinedCopyConstructor(const clang::CXXConstructorDecl *ctor) { return ctor->isCopyConstructor() && ctor->isUserProvided() && IsUserDefinedDecl(ctor); @@ -731,7 +783,7 @@ static bool HasFieldWithMoveAssign(const clang::RecordDecl *decl) { return !record->hasTrivialMoveAssignment(); } return llvm::any_of(record->methods(), [](auto *method) { - return IsConvertibleMoveAssignment(method); + return IsTranslatedMoveAssignment(method); }); }); } @@ -743,11 +795,22 @@ static bool NeedsDefaultedMoveAssignment(const clang::CXXRecordDecl *decl) { bool IsConvertibleMoveAssignment(const clang::CXXMethodDecl *method) { auto *parent = method->getParent(); + if (!method->isMoveAssignmentOperator() || method->isUserProvided() || + method->isDeleted() || !method->hasBody() || + !IsConvertibleImplicitMemberParent(parent)) { + return false; + } + return NeedsDefaultedMoveAssignment(parent); +} + +static bool IsTranslatedMoveAssignment(const clang::CXXMethodDecl *method) { if (!method->isMoveAssignmentOperator() || method->isDeleted() || - !method->hasBody() || !IsConvertibleImplicitMemberParent(parent)) { + method->isVirtual()) { return false; } - return method->isUserProvided() || NeedsDefaultedMoveAssignment(parent); + return (method->isUserProvided() && IsUserDefinedDecl(method) && + method->hasBody()) || + IsConvertibleMoveAssignment(method); } static bool IsTranslatedCopyAssignment(const clang::CXXMethodDecl *method) { @@ -771,7 +834,7 @@ bool HasCopyAssignOperator(const clang::RecordDecl *decl) { bool HasMoveAssignOperator(const clang::RecordDecl *decl) { auto *cxx = clang::dyn_cast(decl); return cxx && llvm::any_of(cxx->methods(), [](auto *method) { - return IsConvertibleMoveAssignment(method) && !method->isVirtual() && + return IsTranslatedMoveAssignment(method) && CanUseCopyOrMoveName(method, "move_assign"); }); } @@ -918,8 +981,8 @@ bool IsConvertibleCXXRecordDecl(const clang::CXXRecordDecl *decl) { } bool IsConvertibleCXXMethodDecl(const clang::CXXMethodDecl *decl) { - if (llvm::isa(decl)) { - return GetUserDefinedDestructor(decl->getParent()) != nullptr; + if (auto *dtor = llvm::dyn_cast(decl)) { + return IsConvertedDestructor(dtor); } return !decl->isImplicit() || IsComparisonOperator(decl) || IsConvertibleImplicitMember(decl); @@ -1756,6 +1819,23 @@ GetUserDefinedDestructor(const clang::CXXRecordDecl *decl) { return dtor; } +bool IsConvertedDestructor(const clang::CXXDestructorDecl *dtor) { + auto *parent = dtor->getParent(); + if (auto *user = GetUserDefinedDestructor(parent)) { + return user->getCanonicalDecl() == dtor->getCanonicalDecl(); + } + return !dtor->isUserProvided() && !dtor->isDeleted() && dtor->hasBody() && + IsUserDefinedDecl(parent) && HasFieldsNeedingDestruction(parent); +} + +bool ImplementsRecordTrait(const clang::RecordDecl *decl, + const RecordTrait &trait) { + auto *cxx = clang::dyn_cast(decl); + return cxx && llvm::any_of(cxx->methods(), [&](auto *method) { + return GetRecordTrait(method) == &trait; + }); +} + bool TypeNeedsDestruction(clang::QualType type) { if (type->isArrayType()) { type = clang::QualType(type->getBaseElementTypeUnsafe(), 0); @@ -1862,6 +1942,13 @@ void DefineImplicitMembers(clang::Sema &sema, clang::CXXRecordDecl *decl) { }); } } + if (auto *dtor = decl->getDestructor(); + dtor && !dtor->isUserProvided() && + !dtor->doesThisDeclarationHaveABody() && !dtor->isDeleted() && + HasFieldsNeedingDestruction(decl)) { + define(dtor, + [&] { sema.DefineImplicitDestructor(decl->getLocation(), dtor); }); + } for (auto *method : decl->methods()) { if (method->isMoveAssignmentOperator() && !method->isUserProvided() && !method->doesThisDeclarationHaveABody() && !method->isDeleted() && @@ -1906,8 +1993,8 @@ bool IsEmittableMethod(clang::CXXMethodDecl *method) { if (method->isDeleted()) { return false; } - if (clang::isa(method)) { - return GetUserDefinedDestructor(method->getParent()) && + if (auto *dtor = clang::dyn_cast(method)) { + return IsConvertedDestructor(dtor) && method->isThisDeclarationADefinition(); } // Virtual methods go into the base trait impl diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index da432b5929..515f6637d7 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -105,6 +105,44 @@ const char *GetCopyOrMoveName(const clang::CXXMethodDecl *method); bool CanUseCopyOrMoveName(const clang::CXXMethodDecl *decl, const std::string &name); +struct RecordTrait { + const char *name; + const char *unsafe_name; + const char *method; + const char *signature; + const char *unsafe_signature; +}; + +inline constexpr RecordTrait kCopyConstructible{ + "CopyConstructible", "CopyConstructibleUnsafe", "copy_constructor", + "fn copy_constructor(_: &Ptr, _: Ptr)", + "unsafe fn copy_constructor(&mut self, _: *const Self)"}; +inline constexpr RecordTrait kMoveConstructible{ + "MoveConstructible", "MoveConstructibleUnsafe", "move_constructor", + "fn move_constructor(_: &Ptr, _: Ptr)", + "unsafe fn move_constructor(&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"}; +inline constexpr RecordTrait kMoveAssignable{ + "MoveAssignable", "MoveAssignableUnsafe", "move_assign", + "fn move_assign(_: &Ptr, _: Ptr) -> Ptr", + "unsafe fn move_assign(&mut self, _: *mut Self) -> *mut Self"}; +inline constexpr RecordTrait kSwappable{ + "Swappable", "SwappableUnsafe", "swap", + "fn swap(_: &Ptr, _: Ptr)", + "unsafe fn swap(&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}; + +const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method); + bool IsUserDefinedCopyConstructor(const clang::CXXConstructorDecl *ctor); bool IsConvertibleCopyOrMoveConstructor(const clang::CXXConstructorDecl *ctor); @@ -288,6 +326,11 @@ bool IsSameTypeComparison(const clang::FunctionDecl *fn, clang::CXXDestructorDecl * GetUserDefinedDestructor(const clang::CXXRecordDecl *decl); +bool IsConvertedDestructor(const clang::CXXDestructorDecl *dtor); + +bool ImplementsRecordTrait(const clang::RecordDecl *decl, + const RecordTrait &trait); + bool TypeNeedsDestruction(clang::QualType type); bool HasFieldsNeedingDestruction(const clang::CXXRecordDecl *decl); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 9bc5a22253..ad7de51b79 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -846,6 +846,9 @@ void ConverterRefCount::EmitByteSizeAttr(const clang::RecordDecl *decl) { std::string ConverterRefCount::GetSelfMaybeWithMut(const clang::CXXMethodDecl *decl) { + if (GetRecordTrait(decl)) { + return "this: &Ptr"; + } return NeedsMutAccess(decl, decl->getThisType()->getPointeeType()) ? "&mut self" : "&self"; @@ -981,14 +984,14 @@ void ConverterRefCount::EmitScopedDestructor(const clang::VarDecl *decl) { } StrCat(token::kSemiColon, std::format("let _dtor_{0} = std::mem::DropGuard::new({0}.clone(), " - "|__p| Destructible::destroy(__p.as_pointer()))", + "|__p| Destructible::destroy(&__p.as_pointer()))", GetNamedDeclAsString(decl))); } std::string ConverterRefCount::StaticDestructorCall(const clang::VarDecl *decl) { return std::format( - "Destructible::destroy({}.with(Value::clone).as_pointer())", + "Destructible::destroy(&{}.with(Value::clone).as_pointer())", GetNamedDeclAsString(decl)); } @@ -1806,8 +1809,7 @@ bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) { method && !known) { if (IsMethodOnPtr(method)) { SetUFCSReceiver(expr->getBase(), expr->isArrow(), method); - StrCat(TraitName(method->getParent()), token::kDoubleColon, - GetMethodName(method)); + StrCat(GetUFCSName(method), token::kDoubleColon, GetMethodName(method)); MarkFresh(); return false; } @@ -2083,9 +2085,9 @@ bool ConverterRefCount::VisitCXXDeleteExpr(clang::CXXDeleteExpr *expr) { token::kSemiColon); if (expr->isArrayForm()) { StrCat("for __i in (0..__p.len()).rev() { " - "Destructible::destroy(__p.offset(__i as isize)); }"); + "Destructible::destroy(&__p.offset(__i as isize)); }"); } else { - StrCat("Destructible::destroy(__p.clone());"); + StrCat("Destructible::destroy(&__p);"); } StrCat("__p.delete();"); return false; @@ -2326,7 +2328,10 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { std::vector attrs; if (decl->isUnion()) { - return {"VaArg", "FnPtrArg"}; + std::vector union_attrs = {"VaArg", "FnPtrArg", + "Destructible"}; + AddCopyAndMoveDerives(decl, union_attrs); + return union_attrs; } if (RecordDerivesCopyTrait(decl)) { @@ -2348,27 +2353,16 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { } attrs.emplace_back("FnPtrArg"); - if (HasMoveFromConstructor(decl)) { - attrs.emplace_back("MoveCtor"); - } - if (HasImplicitConversions(decl)) { attrs.emplace_back("CppFrom"); } - if (HasCopyAssignOperator(decl)) { - attrs.emplace_back("CopyAssign"); - } - - if (HasMoveAssignOperator(decl)) { - attrs.emplace_back("MoveAssign"); - } - - if (auto *cxx = clang::dyn_cast(decl); - cxx && RecordNeedsDestruction(cxx)) { + if (!ImplementsRecordTrait(decl, kDestructible)) { attrs.emplace_back("Destructible"); } + AddCopyAndMoveDerives(decl, attrs); + if (RecordDerivesDefault(decl)) { attrs.emplace_back("Default"); } @@ -2379,23 +2373,9 @@ const char *ConverterRefCount::GetConversionTraitName() const { return "CppFrom"; } -std::string ConverterRefCount::ConvertPtrRead(clang::QualType, - const std::string &src) { - return std::format("{}.read()", src); -} - -std::string ConverterRefCount::ConvertPtrWrite(const std::string &dst, - const std::string &value) { - return std::format("{}.write({})", dst, value); -} - -std::string ConverterRefCount::ConvertPointeeMethodCall( - const char *method, const std::string &dst, const std::string &src) { - return std::format("{}.{}({})", dst, method, src); -} - -const char *ConverterRefCount::GetMoveCtorTraitName() const { - return "MoveCtor"; +const char * +ConverterRefCount::GetCopyOrMoveTraitName(const RecordTrait &trait) const { + return trait.name; } bool ConverterRefCount::TypeDerivesDefault(clang::QualType qual_type) { @@ -3592,11 +3572,21 @@ std::string ConverterRefCount::ConvertPointeeType(clang::QualType ptr_type) { bool ConverterRefCount::ShouldConvertMethod(const clang::CXXMethodDecl *decl) { if (clang::isa(decl)) { - return IsMethodOnPtr(decl); + return GetRecordTrait(decl) != nullptr; } return Converter::ShouldConvertMethod(decl); } +// TODO: every trait on a Ptr should receive `this`. +bool ConverterRefCount::ReceivesThis() const { + auto *method = clang::dyn_cast_or_null(curr_function_); + return method && GetRecordTrait(method); +} + +const char *ConverterRefCount::SelfName() const { + return ReceivesThis() ? "this" : keyword::kSelfValue; +} + bool ConverterRefCount::ThisIsRustPtr() const { auto *method = clang::dyn_cast_or_null(curr_function_); return method && (IsMethodOnPtr(method) || @@ -3614,7 +3604,7 @@ void ConverterRefCount::SetUFCSReceiver(clang::Expr *base, bool is_arrow, if (clang::isa(base->IgnoreParenImpCasts()) && !AsLambdaOperatorCall(curr_function_)) { if (ThisIsRustPtr()) { - ufcs_receiver_ = keyword::kSelfValue; + ufcs_receiver_ = SelfName(); } else { ufcs_receiver_ = token::kRef + ConvertPointer(base); } @@ -3637,6 +3627,9 @@ void ConverterRefCount::SetUFCSReceiver(clang::Expr *base, bool is_arrow, std::string ConverterRefCount::GetUFCSName(const clang::CXXMethodDecl *method) const { + if (auto *trait = GetRecordTrait(method)) { + return GetCopyOrMoveTraitName(*trait); + } if (!IsMethodOnPtr(method)) { return GetRecordName(method->getParent()); } @@ -3679,6 +3672,9 @@ bool ConverterRefCount::ConvertOutOfLineMethod(clang::CXXMethodDecl *decl) { void ConverterRefCount::ConvertMethodOnPtrTraitDecl( clang::CXXMethodDecl *method) { + if (GetRecordTrait(method)) { + return; + } Buffer buf(*this); { ScopedValue push_fn(curr_function_, method); @@ -3691,8 +3687,9 @@ void ConverterRefCount::ConvertMethodOnPtrTraitDecl( } void ConverterRefCount::ConvertMethodOnPtr(clang::CXXMethodDecl *method) { - if (!method->isThisDeclarationADefinition() && - !clang::isa(method)) { + if ((!method->isThisDeclarationADefinition() && + !clang::isa(method)) || + GetRecordTrait(method)) { return; } Buffer buf(*this); @@ -3731,6 +3728,10 @@ void ConverterRefCount::ConvertLateInstantiatedMethods( ConvertMethodOnPtr(method); } }); + ConvertCopyOrMoveTraitImpls(decl, [](clang::CXXMethodDecl *method) { + return IsEmittableMethod(method) && method->hasBody() && + !decl_ids_.contains(GetMethodID(method)); + }); } void ConverterRefCount::ConvertCXXRecordMethods(clang::CXXRecordDecl *decl) { @@ -3755,39 +3756,39 @@ void ConverterRefCount::ConvertCXXRecordMethods(clang::CXXRecordDecl *decl) { ConvertMethodOnPtr(method); } }); - - if (!GetUserDefinedDestructor(decl) && HasFieldsNeedingDestruction(decl)) { - MethodsOnPtrFor(decl).trait.body += - std::format("fn {}(&self);\n", kDestructorName); - MethodsOnPtrFor(decl).impl.body += std::format( - "fn {}(&self) {{ {} }}\n", kDestructorName, DestroyMembers(decl)); - } + ConvertCopyOrMoveTraitImpls(decl, IsEmittableMethod); } std::string ConverterRefCount::DestroyMembers(const clang::CXXRecordDecl *decl) { std::string out; for (auto *field : FieldsToDestroy(decl)) { - out += std::format("Destructible::destroy(field_ptr!(self, {}));\n", + out += std::format("Destructible::destroy(&field_ptr!(this, {}));\n", GetNamedDeclAsString(field)); } return out; } -const char *ConverterRefCount::GetConstructorSelf() const { return "&self"; } +const char *ConverterRefCount::GetConstructorSelf() const { + return ReceivesThis() ? "this: &Ptr" : "&self"; +} std::string ConverterRefCount::ConvertConstructorFieldWrite(const std::string &field_name, const std::string &value) { - return std::format("field!((*self), {}).write({});", field_name, value); + return std::format("field!((*{}), {}).write({});", SelfName(), field_name, + value); } const char *ConverterRefCount::GetConstructorWrite() const { - return "self.write"; + return ReceivesThis() ? "this.write" : "self.write"; } std::string ConverterRefCount::GetConstructorPath( const clang::CXXConstructorDecl *ctor) const { + if (auto *trait = GetRecordTrait(ctor)) { + return GetCopyOrMoveTraitName(*trait); + } return TraitName(ctor->getParent()); } @@ -3819,7 +3820,7 @@ bool ConverterRefCount::VisitCXXThisExpr( } return false; } - StrCat("(*", keyword::kSelfValue, ')'); + StrCat("(*", SelfName(), ')'); MarkNotFresh(); return false; } diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 82df79596d..574a164bbf 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -431,6 +431,10 @@ class ConverterRefCount final : public Converter { MethodsOnPtr &MethodsOnPtrFor(const clang::CXXRecordDecl *decl); + bool ReceivesThis() const; + + const char *SelfName() const; + std::string DestroyMembers(const clang::CXXRecordDecl *decl) override; void EmitScopedDestructor(const clang::VarDecl *decl) override; @@ -526,17 +530,7 @@ class ConverterRefCount final : public Converter { const char *GetConversionTraitName() const override; - std::string ConvertPtrRead(clang::QualType type, - const std::string &src) override; - - std::string ConvertPtrWrite(const std::string &dst, - const std::string &value) override; - - std::string ConvertPointeeMethodCall(const char *method, - const std::string &dst, - const std::string &src) override; - - const char *GetMoveCtorTraitName() const override; + const char *GetCopyOrMoveTraitName(const RecordTrait &trait) const override; bool IsBoxedType(clang::QualType type); bool IsVecType(clang::QualType type); diff --git a/cpp2rust/cpp2rust_lib.cpp b/cpp2rust/cpp2rust_lib.cpp index ddf4539109..4196e5af85 100644 --- a/cpp2rust/cpp2rust_lib.cpp +++ b/cpp2rust/cpp2rust_lib.cpp @@ -33,6 +33,7 @@ std::string TranspileSrc(std::string_view cc_code, Model model, filename.ends_with(".c") ? CLANG_C_COMPILER : CLANG_CXX_COMPILER); Converter::EmitOpaqueRecords(model, rs_code); Converter::EmitVirtualMethods(rs_code); + Converter::EmitUndefinedRecordTraits(model, rs_code); if (model == Model::kRefCount) { ConverterRefCount::EmitMethodsOnPtr(rs_code); } @@ -78,6 +79,7 @@ std::string TranspileDir(std::string_view build_dir, Model model, Tool.run(&factory); Converter::EmitOpaqueRecords(model, rs_code); Converter::EmitVirtualMethods(rs_code); + Converter::EmitUndefinedRecordTraits(model, rs_code); if (model == Model::kRefCount) { ConverterRefCount::EmitMethodsOnPtr(rs_code); } diff --git a/libcc2rs-macros/src/assign.rs b/libcc2rs-macros/src/assign.rs deleted file mode 100644 index 4f83875cf6..0000000000 --- a/libcc2rs-macros/src/assign.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - -use proc_macro::TokenStream; -use quote::{format_ident, quote}; -use syn::{DeriveInput, parse_macro_input}; - -// Implements libcc2rs::CopyAssign or MoveAssign (or their unsafe versions) -// with the method of the same name, for `op` "copy" or "move". -pub fn expand(input: TokenStream, op: &str, 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(); - let method = format_ident!("{}_assign", op); - let is_move = op == "move"; - if is_unsafe { - let tr = if is_move { - quote!(::libcc2rs::MoveAssignUnsafe) - } else { - quote!(::libcc2rs::CopyAssignUnsafe) - }; - let src_ty = if is_move { - quote!(*mut Self) - } else { - quote!(*const Self) - }; - quote! { - impl #impl_generics #tr for #name #ty_generics #where_clause { - unsafe fn #method(dst: *mut Self, src: #src_ty) { - unsafe { (*dst).#method(src) }; - } - } - } - } else { - let tr = if is_move { - quote!(::libcc2rs::MoveAssign) - } else { - quote!(::libcc2rs::CopyAssign) - }; - quote! { - impl #impl_generics #tr for #name #ty_generics #where_clause { - fn #method(dst: &::libcc2rs::Ptr, src: ::libcc2rs::Ptr) { - dst.#method(src); - } - } - } - } - .into() -} diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs new file mode 100644 index 0000000000..712a782cf7 --- /dev/null +++ b/libcc2rs-macros/src/constructor.rs @@ -0,0 +1,127 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +use proc_macro::TokenStream; +use proc_macro2::TokenStream as TokenStream2; +use quote::{format_ident, quote}; +use syn::{DeriveInput, parse_macro_input}; + +pub fn expand(input: TokenStream, op: &str, is_assign: bool, is_unsafe: bool) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + impl_trait(&input, op, is_assign, is_unsafe).into() +} + +pub fn expand_copyable(input: TokenStream, is_unsafe: bool) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let impls = [ + ("copy", false), + ("move", false), + ("copy", true), + ("move", true), + ] + .map(|(op, is_assign)| impl_trait(&input, op, is_assign, is_unsafe)); + let swap = impl_swap(&input, is_unsafe); + quote!(#(#impls)* #swap).into() +} + +pub fn expand_movable(input: TokenStream, is_unsafe: bool) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let impls = [("move", false), ("move", true)] + .map(|(op, is_assign)| impl_trait(&input, op, is_assign, is_unsafe)); + let swap = impl_swap(&input, is_unsafe); + quote!(#(#impls)* #swap).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() +} + +fn impl_swap(input: &DeriveInput, is_unsafe: bool) -> TokenStream2 { + let name = &input.ident; + let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); + if is_unsafe { + quote! { + impl #impl_generics ::libcc2rs::SwappableUnsafe for #name #ty_generics #where_clause { + unsafe fn swap(&mut self, other: *mut Self) { + unsafe { ::libcc2rs::swap_by_move_unsafe(self, other) } + } + } + } + } else { + quote! { + impl #impl_generics ::libcc2rs::Swappable for #name #ty_generics #where_clause { + fn swap(this: &::libcc2rs::Ptr, other: ::libcc2rs::Ptr) { + ::libcc2rs::swap_by_move(this, other) + } + } + } + } +} + +fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) -> TokenStream2 { + let name = &input.ident; + let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); + let is_move = op == "move"; + let trait_name = format_ident!( + "{}{}{}", + if is_move { "Move" } else { "Copy" }, + if is_assign { + "Assignable" + } else { + "Constructible" + }, + if is_unsafe { "Unsafe" } else { "" } + ); + let method = if is_assign { + format_ident!("{}_assign", op) + } else { + format_ident!("{}_constructor", op) + }; + if is_unsafe { + let src_ty = if is_move { + quote!(*mut Self) + } else { + quote!(*const Self) + }; + let body = if is_assign { + quote! { + unsafe { *self = (*src).clone() }; + self + } + } else { + quote!(unsafe { ::std::ptr::write(self, (*src).clone()) }) + }; + let ret = if is_assign { + quote!(-> *mut Self) + } else { + quote!() + }; + quote! { + impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause { + unsafe fn #method(&mut self, src: #src_ty) #ret { + #body + } + } + } + } else { + let ret = if is_assign { + quote!(-> ::libcc2rs::Ptr) + } else { + quote!() + }; + let tail = if is_assign { + quote!(this.clone()) + } else { + quote!() + }; + quote! { + impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause { + fn #method(this: &::libcc2rs::Ptr, src: ::libcc2rs::Ptr) #ret { + this.write(src.read()); + #tail + } + } + } + } +} diff --git a/libcc2rs-macros/src/destructor.rs b/libcc2rs-macros/src/destructor.rs index a7a0ddbe42..49d9f955b7 100644 --- a/libcc2rs-macros/src/destructor.rs +++ b/libcc2rs-macros/src/destructor.rs @@ -12,17 +12,13 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { if is_unsafe { quote! { impl #impl_generics ::libcc2rs::DestructibleUnsafe for #name #ty_generics #where_clause { - unsafe fn destroy(p: *mut Self) { - unsafe { (*p).destructor() } - } + unsafe fn destroy(&mut self) {} } } } else { quote! { impl #impl_generics ::libcc2rs::Destructible for #name #ty_generics #where_clause { - fn destroy(p: ::libcc2rs::Ptr) { - p.destructor() - } + fn destroy(_: &::libcc2rs::Ptr) {} } } } diff --git a/libcc2rs-macros/src/lambda.rs b/libcc2rs-macros/src/lambda.rs index dd1bcc2775..c5c1c53960 100644 --- a/libcc2rs-macros/src/lambda.rs +++ b/libcc2rs-macros/src/lambda.rs @@ -258,9 +258,7 @@ fn expand_lambda(lambda: Lambda, is_unsafe: bool) -> Result TokenStream { initialization::expand_unsafe(input) } -// #[derive(MoveCtor)] -// pub struct S { ... } -// impl S { -// pub fn move_from(o: Ptr) -> Self { ... } -// } -// -// Implements libcc2rs::MoveCtor for S with its move constructor, move_from, -// such that lambda! moves the captures of type S with it. MoveCtorUnsafe is -// the same for the unsafe model, whose move_from takes a *mut S. +#[proc_macro_derive(CopyConstructible)] +pub fn derive_copy_constructible(input: TokenStream) -> TokenStream { + constructor::expand(input, "copy", false, false) +} -#[proc_macro_derive(MoveCtor)] -pub fn derive_move_ctor(input: TokenStream) -> TokenStream { - move_ctor::expand(input, false) +#[proc_macro_derive(CopyConstructibleUnsafe)] +pub fn derive_copy_constructible_unsafe(input: TokenStream) -> TokenStream { + constructor::expand(input, "copy", false, true) } -#[proc_macro_derive(MoveCtorUnsafe)] -pub fn derive_move_ctor_unsafe(input: TokenStream) -> TokenStream { - move_ctor::expand(input, true) +#[proc_macro_derive(Copyable)] +pub fn derive_copyable(input: TokenStream) -> TokenStream { + constructor::expand_copyable(input, false) } -// #[derive(CopyAssign, MoveAssign)] -// pub struct S { ... } -// impl SImpl for Ptr { -// fn copy_assign(&self, o: Ptr) -> Ptr { ... } -// fn move_assign(&self, o: Ptr) -> Ptr { ... } -// } -// -// Implements libcc2rs::CopyAssign and MoveAssign for S with its copy and move -// assignment operators, such that std::swap assigns the values of type S -// with them, as C++ does. CopyAssignUnsafe and MoveAssignUnsafe are the same -// for the unsafe model, whose copy_assign and move_assign are methods of S. - -#[proc_macro_derive(CopyAssign)] -pub fn derive_copy_assign(input: TokenStream) -> TokenStream { - assign::expand(input, "copy", false) +#[proc_macro_derive(CopyableUnsafe)] +pub fn derive_copyable_unsafe(input: TokenStream) -> TokenStream { + constructor::expand_copyable(input, true) } -#[proc_macro_derive(CopyAssignUnsafe)] -pub fn derive_copy_assign_unsafe(input: TokenStream) -> TokenStream { - assign::expand(input, "copy", true) +#[proc_macro_derive(Movable)] +pub fn derive_movable(input: TokenStream) -> TokenStream { + constructor::expand_movable(input, false) } -#[proc_macro_derive(MoveAssign)] -pub fn derive_move_assign(input: TokenStream) -> TokenStream { - assign::expand(input, "move", false) +#[proc_macro_derive(MovableUnsafe)] +pub fn derive_movable_unsafe(input: TokenStream) -> TokenStream { + constructor::expand_movable(input, true) } -#[proc_macro_derive(MoveAssignUnsafe)] -pub fn derive_move_assign_unsafe(input: TokenStream) -> TokenStream { - assign::expand(input, "move", true) +#[proc_macro_derive(Swappable)] +pub fn derive_swappable(input: TokenStream) -> TokenStream { + constructor::expand_swappable(input, false) } -// #[derive(Destructible)] -// pub struct S { ... } -// impl SImpl for Ptr { -// fn destructor(&self) { ... } -// } -// -// Implements libcc2rs::Destructible for S with its destructor, through which -// the translation destroys every object of type S. DestructibleUnsafe is the -// same for the unsafe model, whose destructor is a method of S. +#[proc_macro_derive(SwappableUnsafe)] +pub fn derive_swappable_unsafe(input: TokenStream) -> TokenStream { + constructor::expand_swappable(input, true) +} + +#[proc_macro_derive(CopyAssignable)] +pub fn derive_copy_assignable(input: TokenStream) -> TokenStream { + constructor::expand(input, "copy", true, false) +} + +#[proc_macro_derive(CopyAssignableUnsafe)] +pub fn derive_copy_assignable_unsafe(input: TokenStream) -> TokenStream { + constructor::expand(input, "copy", true, true) +} + +#[proc_macro_derive(MoveConstructible)] +pub fn derive_move_constructible(input: TokenStream) -> TokenStream { + constructor::expand(input, "move", false, false) +} + +#[proc_macro_derive(MoveConstructibleUnsafe)] +pub fn derive_move_constructible_unsafe(input: TokenStream) -> TokenStream { + constructor::expand(input, "move", false, true) +} + +#[proc_macro_derive(MoveAssignable)] +pub fn derive_move_assignable(input: TokenStream) -> TokenStream { + constructor::expand(input, "move", true, false) +} + +#[proc_macro_derive(MoveAssignableUnsafe)] +pub fn derive_move_assignable_unsafe(input: TokenStream) -> TokenStream { + constructor::expand(input, "move", true, true) +} #[proc_macro_derive(Destructible)] pub fn derive_destructible(input: TokenStream) -> TokenStream { diff --git a/libcc2rs-macros/src/move_ctor.rs b/libcc2rs-macros/src/move_ctor.rs deleted file mode 100644 index 7848b56352..0000000000 --- a/libcc2rs-macros/src/move_ctor.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - -use proc_macro::TokenStream; -use quote::{format_ident, quote}; -use syn::{DeriveInput, parse_macro_input}; - -pub fn expand(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(); - let body = - crate::initialization::construct(is_unsafe, name, &format_ident!("move_from"), quote!(src)); - if is_unsafe { - quote! { - impl #impl_generics ::libcc2rs::MoveCtorUnsafe for #name #ty_generics #where_clause { - unsafe fn move_ctor(src: *mut Self) -> Self { - unsafe { #body } - } - } - } - } else { - quote! { - impl #impl_generics ::libcc2rs::MoveCtor for #name #ty_generics #where_clause { - fn move_ctor(src: ::libcc2rs::Ptr) -> Self { - #body - } - } - } - } - .into() -} diff --git a/libcc2rs/src/capture.rs b/libcc2rs/src/capture.rs index e0eca957fd..af78508c1b 100644 --- a/libcc2rs/src/capture.rs +++ b/libcc2rs/src/capture.rs @@ -7,7 +7,7 @@ // specialization picks, among the impls below, the one with the most `&`s // whose bounds the capture's type satisfies: // - a lambda (a FnPtr) is copied and moved with its own constructors; -// - a type with a C++ move constructor (MoveCtor) is moved with it; +// - a type with a C++ move constructor (MoveConstructible) is moved with it; // - any other type is copied with Clone, also when it is moved, as C++ // copies the types without a move constructor; // - a type that is not Clone is not copyable, and neither is the lambda, @@ -20,160 +20,53 @@ #![allow(private_bounds, clippy::missing_safety_doc)] use std::cell::RefCell; -use std::collections::BTreeMap; use std::rc::Rc; +use crate::constructor::{ + CopyConstructible, CopyConstructibleUnsafe, MoveConstructible, MoveConstructibleUnsafe, +}; use crate::fn_ptr::{FnPtr, FnSig}; +use crate::initialization::ZeroInitialization; use crate::rc::{AsPointer, Decay, Ptr, Value}; use crate::reinterpret::ByteRepr; -use crate::{Map, UnsafeMap}; -// The C++ move constructor of a type, in the refcount model, for the types -// whose move isn't a copy. Records implement it with #[derive(MoveCtor)]. -pub trait MoveCtor: Sized { - fn move_ctor(src: Ptr) -> Self; -} - -// The C++ move constructor of a type, in the unsafe model. Records implement -// it with #[derive(MoveCtorUnsafe)]. -pub trait MoveCtorUnsafe: Sized { - /// # Safety - /// `src` must point to a live value. - unsafe fn move_ctor(src: *mut Self) -> Self; -} - -// The C++ copy assignment operator of a type, in the refcount model, for the -// types whose copy assignment isn't an assignment of a clone. Records -// implement it with #[derive(CopyAssign)]. -pub trait CopyAssign: Sized { - fn copy_assign(dst: &Ptr, src: Ptr); -} - -// The C++ copy assignment operator of a type, in the unsafe model. Records -// implement it with #[derive(CopyAssignUnsafe)]. -pub trait CopyAssignUnsafe: Sized { - /// # Safety - /// `dst` and `src` must point to live values. - unsafe fn copy_assign(dst: *mut Self, src: *const Self); -} - -// The C++ move assignment operator of a type, in the refcount model, for the -// types whose move assignment isn't an assignment of a moved value. Records -// implement it with #[derive(MoveAssign)]. -pub trait MoveAssign: Sized { - fn move_assign(dst: &Ptr, src: Ptr); -} - -// The C++ move assignment operator of a type, in the unsafe model. Records -// implement it with #[derive(MoveAssignUnsafe)]. -pub trait MoveAssignUnsafe: Sized { - /// # Safety - /// `dst` and `src` must point to live values. - unsafe fn move_assign(dst: *mut Self, src: *mut Self); -} - -impl MoveCtor for FnPtr { - fn move_ctor(src: Ptr) -> Self { - src.with(FnPtr::move_from) - } -} - -impl MoveCtorUnsafe for FnPtr { - unsafe fn move_ctor(src: *mut Self) -> Self { - unsafe { (*src).move_from() } - } -} - -// The library types whose move leaves the source empty. -macro_rules! impl_move_ctor_by_take { - ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( - impl<$($param),*> MoveCtor for $ty - where - Self: ByteRepr, - { - fn move_ctor(src: Ptr) -> Self { - src.with_mut(std::mem::take) - } - } - - impl<$($param),*> MoveCtorUnsafe for $ty { - unsafe fn move_ctor(src: *mut Self) -> Self { - std::mem::take(unsafe { &mut *src }) - } - } - )*}; -} - -impl_move_ctor_by_take!( - Vec, - BTreeMap, - Map, - UnsafeMap, -); - -// unique_ptr. -impl MoveCtor for Option> -where - Self: ByteRepr, -{ - fn move_ctor(src: Ptr) -> Self { - src.with_mut(Option::take) - } -} - -impl MoveCtorUnsafe for Option> { - unsafe fn move_ctor(src: *mut Self) -> Self { - unsafe { (*src).take() } - } -} - -impl MoveCtorUnsafe for [T; N] { - unsafe fn move_ctor(src: *mut Self) -> Self { - let src = src as *mut T; - std::array::from_fn(|i| unsafe { T::move_ctor(src.add(i)) }) - } -} - -// The C++ destructor of a type, in the refcount model, for the types that -// have one. Records implement it with #[derive(Destructible)]. +// The C++ destructor of a type, in the refcount model. pub trait Destructible: Sized { - fn destroy(p: Ptr); + fn destroy(this: &Ptr); } -// The C++ destructor of a type, in the unsafe model. Records implement it -// with #[derive(DestructibleUnsafe)]. +// The C++ destructor of a type, in the unsafe model. pub trait DestructibleUnsafe: Sized { /// # Safety - /// `p` must point to a live value. - unsafe fn destroy(p: *mut Self); + /// `self` must be a live value. + unsafe fn destroy(&mut self); } impl Destructible for FnPtr { - fn destroy(p: Ptr) { - p.with(|f| f.destroy()) + fn destroy(this: &Ptr) { + this.with(|f| f.destroy()) } } impl DestructibleUnsafe for FnPtr { - unsafe fn destroy(p: *mut Self) { - unsafe { (*p).destroy() } + unsafe fn destroy(&mut self) { + FnPtr::destroy(self) } } impl Destructible for Box<[T]> { - fn destroy(p: Ptr) { - let elems = p.decay(); + fn destroy(this: &Ptr) { + let elems = this.decay(); for i in (0..elems.len()).rev() { - T::destroy(elems.offset(i)); + T::destroy(&elems.offset(i)); } } } impl DestructibleUnsafe for [T; N] { - unsafe fn destroy(p: *mut Self) { - let p = p as *mut T; - for i in (0..N).rev() { - unsafe { T::destroy(p.add(i)) } + unsafe fn destroy(&mut self) { + for elem in self.iter_mut().rev() { + unsafe { DestructibleUnsafe::destroy(elem) } } } } @@ -187,7 +80,12 @@ pub trait CopyLambda { impl CopyLambda>> for &&Capture<'_, Value>> { fn copy_capture(&self) -> Value> { - Rc::new(RefCell::new(self.0.borrow().copy_from())) + let dst: Value> = Rc::new(RefCell::new(FnPtr::zero_init())); + CopyConstructible::copy_constructor( + &AsPointer::>::as_pointer(&dst), + AsPointer::>::as_pointer(self.0), + ); + dst } } @@ -217,29 +115,18 @@ impl CopyNone for Capture<'_, T> { } } -pub trait MoveElems { - fn move_capture(&self) -> T; -} - -impl MoveElems>> for &&&Capture<'_, Value>> { - fn move_capture(&self) -> Value> { - let src: Ptr = self.0.decay(); - let len = self.0.borrow().len(); - Rc::new(RefCell::new( - (0..len).map(|i| T::move_ctor(src.offset(i))).collect(), - )) - } -} - pub trait MoveWithCtor { fn move_capture(&self) -> T; } -impl MoveWithCtor> for &&Capture<'_, Value> { +impl MoveWithCtor> for &&Capture<'_, Value> { fn move_capture(&self) -> Value { - Rc::new(RefCell::new(T::move_ctor(AsPointer::::as_pointer( - self.0, - )))) + let dst: Value = Rc::new(RefCell::new(T::zero_init())); + T::move_constructor( + &AsPointer::::as_pointer(&dst), + AsPointer::::as_pointer(self.0), + ); + dst } } @@ -277,7 +164,7 @@ impl DestroyElems for &&Capture<'_, Value>> { fn destroy_capture(&self) { let p: Ptr = self.0.decay(); for i in (0..self.0.borrow().len()).rev() { - T::destroy(p.offset(i)); + T::destroy(&p.offset(i)); } } } @@ -288,7 +175,7 @@ pub trait DestroyWithDtor { impl DestroyWithDtor for &Capture<'_, Value> { fn destroy_capture(&self) { - T::destroy(AsPointer::::as_pointer(self.0)) + T::destroy(&AsPointer::::as_pointer(self.0)) } } @@ -310,7 +197,11 @@ pub trait CopyLambdaUnsafe { impl CopyLambdaUnsafe> for &&CaptureUnsafe> { unsafe fn copy_capture(&self) -> FnPtr { - unsafe { (*self.0).copy_from() } + let mut dst = std::mem::MaybeUninit::>::uninit(); + unsafe { + (*dst.as_mut_ptr()).copy_constructor(self.0); + dst.assume_init() + } } } @@ -338,9 +229,13 @@ pub trait MoveWithCtorUnsafe { unsafe fn move_capture(&self) -> T; } -impl MoveWithCtorUnsafe for &&CaptureUnsafe { +impl MoveWithCtorUnsafe for &&CaptureUnsafe { unsafe fn move_capture(&self) -> T { - unsafe { T::move_ctor(self.0) } + let mut dst = std::mem::MaybeUninit::::uninit(); + unsafe { + (*dst.as_mut_ptr()).move_constructor(self.0); + dst.assume_init() + } } } @@ -370,7 +265,7 @@ pub trait DestroyWithDtorUnsafe { impl DestroyWithDtorUnsafe for &CaptureUnsafe { unsafe fn destroy_capture(&self) { - unsafe { T::destroy(self.0) } + unsafe { DestructibleUnsafe::destroy(&mut *self.0) } } } diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs new file mode 100644 index 0000000000..b5069521d8 --- /dev/null +++ b/libcc2rs/src/constructor.rs @@ -0,0 +1,457 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +use crate::capture::{Destructible, DestructibleUnsafe}; +use crate::fn_ptr::{FnPtr, FnSig}; +use crate::initialization::ZeroInitialization; +use crate::rc::Ptr; +use crate::reinterpret::ByteRepr; +use crate::void::AnyPtr; + +pub trait MoveConstructible: Sized { + fn move_constructor(this: &Ptr, src: Ptr); +} + +pub trait CopyConstructible: Sized { + fn copy_constructor(this: &Ptr, src: Ptr); +} + +pub trait CopyAssignable: Sized { + fn copy_assign(this: &Ptr, src: Ptr) -> Ptr; +} + +pub trait MoveAssignable: Sized { + fn move_assign(this: &Ptr, src: Ptr) -> Ptr; +} + +pub trait Swappable: Sized { + fn swap(this: &Ptr, other: Ptr); +} + +pub trait Movable: MoveConstructible + MoveAssignable + Swappable + Destructible {} + +impl Movable for T {} + +pub trait Copyable: CopyConstructible + CopyAssignable + Movable {} + +impl Copyable for T {} + +pub trait MoveConstructibleUnsafe { + /// # Safety + /// `src` must point to a live value. + unsafe fn move_constructor(&mut self, src: *mut Self); +} + +pub trait CopyConstructibleUnsafe { + /// # Safety + /// `src` must point to a live value. + unsafe fn copy_constructor(&mut self, src: *const Self); +} + +pub trait CopyAssignableUnsafe { + /// # Safety + /// `src` must point to a live value. + unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self; +} + +pub trait MoveAssignableUnsafe { + /// # Safety + /// `src` must point to a live value. + unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self; +} + +pub trait SwappableUnsafe { + /// # Safety + /// `other` must point to a live value. + unsafe fn swap(&mut self, other: *mut Self); +} + +pub trait MovableUnsafe: + MoveConstructibleUnsafe + MoveAssignableUnsafe + SwappableUnsafe + DestructibleUnsafe +{ +} + +impl + MovableUnsafe for T +{ +} + +pub trait CopyableUnsafe: CopyConstructibleUnsafe + CopyAssignableUnsafe + MovableUnsafe {} + +impl CopyableUnsafe for T {} + +macro_rules! impl_copy_by_clone { + ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( + impl<$($param),*> $crate::CopyConstructible for $ty + where + $ty: Clone + $crate::ByteRepr, + { + fn copy_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + this.write(src.read()); + } + } + + impl<$($param),*> $crate::CopyAssignable for $ty + where + $ty: Clone + $crate::ByteRepr, + { + fn copy_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + this.write(src.read()); + this.clone() + } + } + + impl<$($param),*> $crate::CopyConstructibleUnsafe for $ty + where + $ty: Clone, + { + unsafe fn copy_constructor(&mut self, src: *const Self) { + unsafe { std::ptr::write(self, (*src).clone()) } + } + } + + impl<$($param),*> $crate::CopyAssignableUnsafe for $ty + where + $ty: Clone, + { + unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { + unsafe { *self = (*src).clone() }; + self + } + } + )*}; +} +pub(crate) use impl_copy_by_clone; + +macro_rules! impl_move_by_clone { + ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( + impl<$($param),*> $crate::MoveConstructible for $ty + where + $ty: Clone + $crate::ByteRepr, + { + fn move_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + this.write(src.read()); + } + } + + impl<$($param),*> $crate::MoveAssignable for $ty + where + $ty: Clone + $crate::ByteRepr, + { + fn move_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + this.write(src.read()); + this.clone() + } + } + + impl<$($param),*> $crate::MoveConstructibleUnsafe for $ty + where + $ty: Clone, + { + unsafe fn move_constructor(&mut self, src: *mut Self) { + unsafe { std::ptr::write(self, (*src).clone()) } + } + } + + impl<$($param),*> $crate::MoveAssignableUnsafe for $ty + where + $ty: Clone, + { + unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe { *self = (*src).clone() }; + self + } + } + + impl<$($param),*> $crate::Swappable for $ty + where + $ty: Clone + $crate::ByteRepr, + { + fn swap(this: &$crate::Ptr, other: $crate::Ptr) { + this.swap_with(&other, $crate::Ptr::read); + } + } + + impl<$($param),*> $crate::SwappableUnsafe for $ty { + unsafe fn swap(&mut self, other: *mut Self) { + unsafe { std::ptr::swap(self, other) } + } + } + )*}; +} +pub(crate) use impl_move_by_clone; + +macro_rules! impl_trivial_copy_move { + ($(<$($param:ident),*> $ty:ty),* $(,)?) => { + $crate::constructor::impl_copy_by_clone!($(<$($param),*> $ty),*); + $crate::constructor::impl_move_by_clone!($(<$($param),*> $ty),*); + }; + ($($ty:ty),* $(,)?) => { + $crate::constructor::impl_trivial_copy_move!($(<> $ty),*); + }; +} +pub(crate) use impl_trivial_copy_move; + +// The library types whose move leaves the source empty. +macro_rules! impl_move_by_take { + ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( + impl<$($param),*> $crate::MoveConstructible for $ty + where + $ty: Default + $crate::ByteRepr, + { + fn move_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + let value = src.with_mut(std::mem::take); + this.with_mut(|dst| *dst = value); + } + } + + impl<$($param),*> $crate::MoveAssignable for $ty + where + $ty: Default + $crate::ByteRepr, + { + fn move_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + let value = src.with_mut(std::mem::take); + this.with_mut(|dst| *dst = value); + this.clone() + } + } + + impl<$($param),*> $crate::MoveConstructibleUnsafe for $ty + where + $ty: Default, + { + unsafe fn move_constructor(&mut self, src: *mut Self) { + unsafe { std::ptr::write(self, std::mem::take(&mut *src)) } + } + } + + impl<$($param),*> $crate::MoveAssignableUnsafe for $ty + where + $ty: Default, + { + unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe { *self = std::mem::take(&mut *src) }; + self + } + } + + impl<$($param),*> $crate::Swappable for $ty + where + $ty: Default + $crate::ByteRepr, + { + fn swap(this: &$crate::Ptr, other: $crate::Ptr) { + this.swap_with(&other, |p| p.with_mut(std::mem::take)); + } + } + + impl<$($param),*> $crate::SwappableUnsafe for $ty { + unsafe fn swap(&mut self, other: *mut Self) { + unsafe { std::ptr::swap(self, other) } + } + } + )*}; +} +pub(crate) use impl_move_by_take; + +impl_trivial_copy_move!( + (), + bool, + i8, + u8, + i16, + u16, + i32, + u32, + i64, + u64, + i128, + u128, + isize, + usize, + f32, + f64, + std::cmp::Ordering, + AnyPtr, + crate::VaArg, + std::rc::Rc, +); + +impl_trivial_copy_move!( + Ptr, + *mut T, + *const T, + (A, B), +); + +impl MoveConstructible for FnPtr { + fn move_constructor(this: &Ptr, src: Ptr) { + let value = src.with(FnPtr::move_from); + this.with_mut(|dst| *dst = value); + } +} + +impl CopyConstructible for FnPtr { + fn copy_constructor(this: &Ptr, src: Ptr) { + let value = src.with(FnPtr::copy_from); + this.with_mut(|dst| *dst = value); + } +} + +impl MoveAssignable for FnPtr { + fn move_assign(this: &Ptr, src: Ptr) -> Ptr { + ::move_constructor(this, src); + this.clone() + } +} + +impl CopyAssignable for FnPtr { + fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { + ::copy_constructor(this, src); + this.clone() + } +} + +impl Swappable for FnPtr { + fn swap(this: &Ptr, other: Ptr) { + this.swap_with(&other, |p| p.with(FnPtr::move_from)); + } +} + +impl SwappableUnsafe for FnPtr { + unsafe fn swap(&mut self, other: *mut Self) { + unsafe { std::ptr::swap(self, other) } + } +} + +impl MoveConstructibleUnsafe for FnPtr { + unsafe fn move_constructor(&mut self, src: *mut Self) { + unsafe { std::ptr::write(self, (*src).move_from()) } + } +} + +impl CopyConstructibleUnsafe for FnPtr { + unsafe fn copy_constructor(&mut self, src: *const Self) { + unsafe { std::ptr::write(self, (*src).copy_from()) } + } +} + +impl MoveAssignableUnsafe for FnPtr { + unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe { *self = (*src).move_from() }; + self + } +} + +impl CopyAssignableUnsafe for FnPtr { + unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { + unsafe { *self = (*src).copy_from() }; + self + } +} + +fn construct_elems( + this: &Ptr>, + src: &Ptr>, + construct: fn(&Ptr, Ptr), +) { + let len = src.with(|elems| elems.len()); + this.with_mut(|elems| *elems = (0..len).map(|_| T::zero_init()).collect()); + let (dst, src) = (this.decay(), src.decay()); + for i in 0..len { + construct(&dst.offset(i), src.offset(i)); + } +} + +fn assign_elems( + this: &Ptr>, + src: &Ptr>, + assign: fn(&Ptr, Ptr) -> Ptr, +) -> Ptr> { + let len = src.with(|elems| elems.len()); + let (dst, src) = (this.decay(), src.decay()); + for i in 0..len { + assign(&dst.offset(i), src.offset(i)); + } + this.clone() +} + +impl MoveConstructible for Box<[T]> { + fn move_constructor(this: &Ptr, src: Ptr) { + construct_elems(this, &src, T::move_constructor); + } +} + +impl CopyConstructible for Box<[T]> { + fn copy_constructor(this: &Ptr, src: Ptr) { + construct_elems(this, &src, T::copy_constructor); + } +} + +impl MoveAssignable for Box<[T]> { + fn move_assign(this: &Ptr, src: Ptr) -> Ptr { + assign_elems(this, &src, T::move_assign) + } +} + +impl CopyAssignable for Box<[T]> { + fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { + assign_elems(this, &src, T::copy_assign) + } +} + +impl Swappable for Box<[T]> { + fn swap(this: &Ptr, other: Ptr) { + let len = other.with(|elems| elems.len()); + let (dst, src) = (this.decay(), other.decay()); + for i in 0..len { + T::swap(&dst.offset(i), src.offset(i)); + } + } +} + +impl SwappableUnsafe for [T; N] { + unsafe fn swap(&mut self, other: *mut Self) { + let other = other as *mut T; + for (i, elem) in self.iter_mut().enumerate() { + unsafe { SwappableUnsafe::swap(elem, other.add(i)) } + } + } +} + +impl MoveConstructibleUnsafe for [T; N] { + unsafe fn move_constructor(&mut self, src: *mut Self) { + let src = src as *mut T; + for (i, elem) in self.iter_mut().enumerate() { + unsafe { elem.move_constructor(src.add(i)) } + } + } +} + +impl CopyConstructibleUnsafe for [T; N] { + unsafe fn copy_constructor(&mut self, src: *const Self) { + let src = src as *const T; + for (i, elem) in self.iter_mut().enumerate() { + unsafe { elem.copy_constructor(src.add(i)) } + } + } +} + +impl MoveAssignableUnsafe for [T; N] { + unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + let src = src as *mut T; + for (i, elem) in self.iter_mut().enumerate() { + unsafe { elem.move_assign(src.add(i)) }; + } + self + } +} + +impl CopyAssignableUnsafe for [T; N] { + unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { + let src = src as *const T; + for (i, elem) in self.iter_mut().enumerate() { + unsafe { elem.copy_assign(src.add(i)) }; + } + self + } +} diff --git a/libcc2rs/src/initialization.rs b/libcc2rs/src/initialization.rs index afb1c38722..e8a9cc87c2 100644 --- a/libcc2rs/src/initialization.rs +++ b/libcc2rs/src/initialization.rs @@ -69,6 +69,20 @@ impl ZeroInitialization for Vec { } } +impl ZeroInitialization for Box<[T]> { + #[inline] + fn zero_init() -> Self { + Box::new([]) + } +} + +impl ZeroInitialization for std::collections::BTreeMap { + #[inline] + fn zero_init() -> Self { + std::collections::BTreeMap::new() + } +} + impl ZeroInitialization for Rc> { #[inline] fn zero_init() -> Self { diff --git a/libcc2rs/src/lib.rs b/libcc2rs/src/lib.rs index 50998a26ee..d90f1969e9 100644 --- a/libcc2rs/src/lib.rs +++ b/libcc2rs/src/lib.rs @@ -42,9 +42,13 @@ mod fn_ptr; pub use fn_ptr::{FnPtr, Generic}; mod capture; -pub use capture::{ - CopyAssign, CopyAssignUnsafe, Destructible, DestructibleUnsafe, MoveAssign, MoveAssignUnsafe, - MoveCtor, MoveCtorUnsafe, +pub use capture::{Destructible, DestructibleUnsafe}; + +mod constructor; +pub use constructor::{ + CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, Copyable, + CopyableUnsafe, Movable, MovableUnsafe, MoveAssignable, MoveAssignableUnsafe, + MoveConstructible, MoveConstructibleUnsafe, Swappable, SwappableUnsafe, }; mod cmp; @@ -57,7 +61,8 @@ mod initialization; pub use initialization::{ZeroInitialization, ZeroInitializationUnsafe}; mod swap; -// Used by cpp_swap! and cpp_swap_unsafe!. +pub use swap::{swap_by_move, swap_by_move_unsafe}; +// Used by cpp_move! and cpp_move_unsafe!. #[doc(hidden)] pub mod __swap { pub use crate::swap::*; @@ -68,8 +73,8 @@ pub mod __capture { pub use crate::capture::{ Capture, CaptureUnsafe, CopyClone, CopyCloneUnsafe, CopyLambda, CopyLambdaUnsafe, CopyNone, CopyNoneUnsafe, DestroyElems, DestroyNone, DestroyNoneUnsafe, DestroyWithDtor, - DestroyWithDtorUnsafe, MoveClone, MoveCloneUnsafe, MoveElems, MoveNone, MoveNoneUnsafe, - MoveWithCtor, MoveWithCtorUnsafe, + DestroyWithDtorUnsafe, MoveClone, MoveCloneUnsafe, MoveNone, MoveNoneUnsafe, MoveWithCtor, + MoveWithCtorUnsafe, }; } @@ -107,8 +112,9 @@ mod format; pub use format::*; pub use libcc2rs_macros::{ - ByteRepr, CopyAssign, CopyAssignUnsafe, CppFrom, CppFromUnsafe, Destructible, - DestructibleUnsafe, FnPtrArg, MoveAssign, MoveAssignUnsafe, MoveCtor, MoveCtorUnsafe, Record, - VaArg, ZeroInitialization, ZeroInitializationUnsafe, goto, goto_block, lambda, lambda_unsafe, - switch, + ByteRepr, CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, + Copyable, CopyableUnsafe, CppFrom, CppFromUnsafe, Destructible, DestructibleUnsafe, FnPtrArg, + Movable, MovableUnsafe, MoveAssignable, MoveAssignableUnsafe, MoveConstructible, + MoveConstructibleUnsafe, Record, Swappable, SwappableUnsafe, VaArg, ZeroInitialization, + ZeroInitializationUnsafe, goto, goto_block, lambda, lambda_unsafe, switch, }; diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index bd7eeb4ef7..5406b81667 100644 --- a/libcc2rs/src/swap.rs +++ b/libcc2rs/src/swap.rs @@ -1,93 +1,25 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// std::swap, for the translation rules: cpp_swap!(a, b), or -// cpp_swap_unsafe!(a, b), swaps the values that a and b point to as C++ -// does: -// T tmp(std::move(a)); a = std::move(b); b = std::move(tmp); ~tmp -// Each step is done with the special member functions of the type that C++ -// picks, which may have side effects. The macros call -// `(&&&Construct(..)).construct()`, `(&&&&&Assign(..)).assign()` and -// `(&&Destroy(..)).destroy()`, and autoref specialization picks, among the -// impls below, the one with the most `&`s whose bounds the type satisfies: -// - the temporary is made with the move constructor (MoveCtor), or else -// with the copy constructor (Clone); -// - a value is assigned with the move assignment operator (MoveAssign), or -// else with the copy assignment operator (CopyAssign), as C++ copies the -// types without one; the other types are assigned as a whole, by moving -// the value with the move constructor (MoveCtor), or else by copying it -// (Clone); -// - the temporary is destroyed with the destructor, if any (Destructible). -// The values are accessed one at a time, so they may be in the same -// allocation, e.g., two fields of a struct. -// -// The types without any of those special members are only copied by C++, and -// so their values (or bytes, if reinterpreted) are swapped instead, without a -// temporary, as `(&&&&&Trivial(..)).trivial()` tells. The other steps are -// still compiled for them, and are unreachable if they can't be copied. +// cpp_move!(p), or cpp_move_unsafe!(p), constructs a value from the one that +// p points to as C++ does with T(std::move(*p)): with the move constructor +// (MoveConstructible), or else with the copy constructor (Clone), as picked +// by autoref specialization. #![allow(private_bounds, clippy::missing_safety_doc)] use std::cell::RefCell; +use std::mem::MaybeUninit; use std::rc::Rc; -use crate::capture::{ - CopyAssign, CopyAssignUnsafe, Destructible, DestructibleUnsafe, MoveAssign, MoveAssignUnsafe, - MoveCtor, MoveCtorUnsafe, +use crate::capture::{Destructible, DestructibleUnsafe}; +use crate::constructor::{ + MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, }; +use crate::initialization::ZeroInitialization; use crate::rc::{AsPointer, Ptr, Value}; use crate::reinterpret::ByteRepr; -#[macro_export] -macro_rules! cpp_swap { - ($a:expr, $b:expr) => {{ - #[allow(unused_imports)] - use $crate::__swap::{ - AssignClone, AssignCopy, AssignMove, AssignMoveCtor, AssignNone, ConstructCopy, - ConstructMove, ConstructNone, DestroyNone, DestroyWithDtor, HasCopyAssign, - HasDestructor, HasMoveAssign, HasMoveCtor, HasNone, TakeClone, TakeNone, - }; - let __a = $a; - let __b = $b; - if (&&&&&$crate::__swap::Trivial(&__a)).trivial() { - __a.swap_with(&__b, (&&$crate::__swap::Take(&__a)).take()); - } else { - let __tmp = $crate::__swap::temporary((&&&$crate::__swap::Construct(&__a)).construct()); - let __tmp_ptr = $crate::__swap::pointer(&__tmp); - (&&&&&$crate::__swap::Assign(&__a, &__b)).assign(); - (&&&&&$crate::__swap::Assign(&__b, &__tmp_ptr)).assign(); - (&&$crate::__swap::Destroy(&__tmp_ptr)).destroy(); - } - }}; -} - -#[macro_export] -macro_rules! cpp_swap_unsafe { - ($a:expr, $b:expr) => {{ - #[allow(unused_imports)] - use $crate::__swap::{ - AssignCloneUnsafe, AssignCopyUnsafe, AssignMoveCtorUnsafe, AssignMoveUnsafe, - AssignNoneUnsafe, ConstructCopyUnsafe, ConstructMoveUnsafe, ConstructNoneUnsafe, - DestroyNoneUnsafe, DestroyWithDtorUnsafe, HasCopyAssignUnsafe, HasDestructorUnsafe, - HasMoveAssignUnsafe, HasMoveCtorUnsafe, HasNoneUnsafe, - }; - let __a: *mut _ = $a; - let __b: *mut _ = $b; - if (&&&&&$crate::__swap::TrivialUnsafe(&__a)).trivial() { - ::std::ptr::swap(__a, __b); - } else { - let mut __tmp = (&&&$crate::__swap::ConstructUnsafe(__a)).construct(); - let __tmp_ptr: *mut _ = &mut __tmp; - (&&&&&$crate::__swap::AssignUnsafe(__a, __b)).assign(); - (&&&&&$crate::__swap::AssignUnsafe(__b, __tmp_ptr)).assign(); - (&&$crate::__swap::DestroyUnsafe(__tmp_ptr)).destroy(); - } - }}; -} - -// cpp_move!(p), or cpp_move_unsafe!(p), constructs a value from the one that -// p points to as C++ does with T(std::move(*p)), like the temporary of the -// swap. #[macro_export] macro_rules! cpp_move { ($p:expr) => {{ @@ -106,87 +38,30 @@ macro_rules! cpp_move_unsafe { }}; } -// Whether the type has none of the special members that the swap calls. -macro_rules! trivial { - ($wrapper:ident, $ptr:ty, $none:ident, $($tr:ident: $bound:ident for $recv:ty),*) => { - pub struct $wrapper<'a, T>(pub &'a $ptr); - $( - pub trait $tr { - fn trivial(self) -> bool; - } - - impl $tr for $recv { - fn trivial(self) -> bool { - false - } - } - )* - - pub trait $none { - fn trivial(self) -> bool; - } - - impl $none for &$wrapper<'_, T> { - fn trivial(self) -> bool { - true - } - } - }; -} - -trivial!(Trivial, Ptr, HasNone, - HasMoveCtor: MoveCtor for &&&&&Trivial<'_, T>, - HasMoveAssign: MoveAssign for &&&&Trivial<'_, T>, - HasCopyAssign: CopyAssign for &&&Trivial<'_, T>, - HasDestructor: Destructible for &&Trivial<'_, T> -); - -trivial!(TrivialUnsafe, *mut T, HasNoneUnsafe, - HasMoveCtorUnsafe: MoveCtorUnsafe for &&&&&TrivialUnsafe<'_, T>, - HasMoveAssignUnsafe: MoveAssignUnsafe for &&&&TrivialUnsafe<'_, T>, - HasCopyAssignUnsafe: CopyAssignUnsafe for &&&TrivialUnsafe<'_, T>, - HasDestructorUnsafe: DestructibleUnsafe for &&TrivialUnsafe<'_, T> -); - #[cold] #[inline(never)] -fn not_swappable() -> ! { - panic!("std::swap of a type that can't be copied nor moved") +fn not_movable() -> ! { + panic!("move of a type that can't be copied nor moved") } -// How Ptr::swap_with copies a value of a trivial type into a temporary, if -// it needs one. -pub struct Take<'a, T>(pub &'a Ptr); - -pub trait TakeClone { - fn take(self) -> fn(&Ptr) -> T; -} - -pub trait TakeNone { - fn take(self) -> fn(&Ptr) -> T; +pub fn pointer(value: &Value) -> Ptr { + as AsPointer>::as_pointer(value) } -impl TakeClone for &&Take<'_, T> { - fn take(self) -> fn(&Ptr) -> T { - Ptr::read - } +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() } -impl TakeNone for &Take<'_, T> { - fn take(self) -> fn(&Ptr) -> T { - |_| not_swappable() +unsafe fn move_constructed_unsafe(src: *mut T) -> T { + let mut dst = std::mem::MaybeUninit::::uninit(); + unsafe { + (*dst.as_mut_ptr()).move_constructor(src); + dst.assume_init() } } -// The temporary of cpp_swap!, and a pointer to it. -pub fn temporary(value: T) -> Value { - Rc::new(RefCell::new(value)) -} - -pub fn pointer(value: &Value) -> Ptr { - as AsPointer>::as_pointer(value) -} - pub struct Construct<'a, T>(pub &'a Ptr); pub trait ConstructMove { @@ -201,9 +76,9 @@ pub trait ConstructNone { fn construct(self) -> T; } -impl ConstructMove for &&&Construct<'_, T> { +impl ConstructMove for &&&Construct<'_, T> { fn construct(self) -> T { - T::move_ctor(self.0.clone()) + move_constructed(self.0) } } @@ -215,83 +90,10 @@ impl ConstructCopy for &&Construct<'_, T> { impl ConstructNone for &Construct<'_, T> { fn construct(self) -> T { - not_swappable() - } -} - -// Assigns the value that the second pointer points to to the first one. -pub struct Assign<'a, T>(pub &'a Ptr, pub &'a Ptr); - -pub trait AssignMove { - fn assign(self); -} - -pub trait AssignCopy { - fn assign(self); -} - -pub trait AssignMoveCtor { - fn assign(self); -} - -pub trait AssignClone { - fn assign(self); -} - -pub trait AssignNone { - fn assign(self); -} - -impl AssignMove for &&&&&Assign<'_, T> { - fn assign(self) { - T::move_assign(self.0, self.1.clone()) + not_movable() } } -impl AssignCopy for &&&&Assign<'_, T> { - fn assign(self) { - T::copy_assign(self.0, self.1.clone()) - } -} - -impl AssignMoveCtor for &&&Assign<'_, T> { - fn assign(self) { - self.0.write(T::move_ctor(self.1.clone())) - } -} - -impl AssignClone for &&Assign<'_, T> { - fn assign(self) { - self.0.write(self.1.read()) - } -} - -impl AssignNone for &Assign<'_, T> { - fn assign(self) { - not_swappable() - } -} - -pub struct Destroy<'a, T>(pub &'a Ptr); - -pub trait DestroyWithDtor { - fn destroy(self); -} - -pub trait DestroyNone { - fn destroy(self); -} - -impl DestroyWithDtor for &&Destroy<'_, T> { - fn destroy(self) { - T::destroy(self.0.clone()) - } -} - -impl DestroyNone for &Destroy<'_, T> { - fn destroy(self) {} -} - pub struct ConstructUnsafe(pub *mut T); pub trait ConstructMoveUnsafe { @@ -306,9 +108,9 @@ pub trait ConstructNoneUnsafe { unsafe fn construct(self) -> T; } -impl ConstructMoveUnsafe for &&&ConstructUnsafe { +impl ConstructMoveUnsafe for &&&ConstructUnsafe { unsafe fn construct(self) -> T { - unsafe { T::move_ctor(self.0) } + unsafe { move_constructed_unsafe(self.0) } } } @@ -320,78 +122,34 @@ impl ConstructCopyUnsafe for &&ConstructUnsafe { impl ConstructNoneUnsafe for &ConstructUnsafe { unsafe fn construct(self) -> T { - not_swappable() + not_movable() + } +} + +pub fn swap_by_move(this: &Ptr, other: Ptr) +where + T: MoveConstructible + MoveAssignable + Destructible + ZeroInitialization, +{ + let storage: Value = Rc::new(RefCell::new(T::zero_init())); + let tmp = AsPointer::::as_pointer(&storage); + T::move_constructor(&tmp, this.clone()); + T::move_assign(this, other.clone()); + T::move_assign(&other, tmp.clone()); + T::destroy(&tmp); +} + +/// # Safety +/// `other` must point to a live value. +pub unsafe fn swap_by_move_unsafe(this: &mut T, other: *mut T) +where + T: MoveConstructibleUnsafe + MoveAssignableUnsafe + DestructibleUnsafe, +{ + let this: *mut T = this; + let mut tmp = MaybeUninit::::uninit(); + unsafe { + MoveConstructibleUnsafe::move_constructor(&mut *tmp.as_mut_ptr(), this); + MoveAssignableUnsafe::move_assign(&mut *this, other); + MoveAssignableUnsafe::move_assign(&mut *other, tmp.as_mut_ptr()); + DestructibleUnsafe::destroy(&mut *tmp.as_mut_ptr()); } } - -pub struct AssignUnsafe(pub *mut T, pub *mut T); - -pub trait AssignMoveUnsafe { - unsafe fn assign(self); -} - -pub trait AssignCopyUnsafe { - unsafe fn assign(self); -} - -pub trait AssignMoveCtorUnsafe { - unsafe fn assign(self); -} - -pub trait AssignCloneUnsafe { - unsafe fn assign(self); -} - -pub trait AssignNoneUnsafe { - unsafe fn assign(self); -} - -impl AssignMoveUnsafe for &&&&&AssignUnsafe { - unsafe fn assign(self) { - unsafe { T::move_assign(self.0, self.1) } - } -} - -impl AssignCopyUnsafe for &&&&AssignUnsafe { - unsafe fn assign(self) { - unsafe { T::copy_assign(self.0, self.1) } - } -} - -impl AssignMoveCtorUnsafe for &&&AssignUnsafe { - unsafe fn assign(self) { - unsafe { *self.0 = T::move_ctor(self.1) } - } -} - -impl AssignCloneUnsafe for &&AssignUnsafe { - unsafe fn assign(self) { - unsafe { *self.0 = (*self.1).clone() } - } -} - -impl AssignNoneUnsafe for &AssignUnsafe { - unsafe fn assign(self) { - not_swappable() - } -} - -pub struct DestroyUnsafe(pub *mut T); - -pub trait DestroyWithDtorUnsafe { - unsafe fn destroy(self); -} - -pub trait DestroyNoneUnsafe { - unsafe fn destroy(self); -} - -impl DestroyWithDtorUnsafe for &&DestroyUnsafe { - unsafe fn destroy(self) { - unsafe { T::destroy(self.0) } - } -} - -impl DestroyNoneUnsafe for &DestroyUnsafe { - unsafe fn destroy(self) {} -} diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index b3f952d4ac..43b71bcc9f 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -76,8 +76,8 @@ fn f8, T2: CppLess>(a0: T1, a1: T1) -> T1 { __best } -fn f9(a0: Ptr, a1: Ptr) { - cpp_swap!(a0, a1) +fn f9(a0: Ptr, a1: Ptr) { + Swappable::swap(&a0, a1) } fn f10, T2: CppEq + Clone + ByteRepr>(a0: T1, a1: T1) -> T1 { @@ -147,11 +147,11 @@ fn f17(a0: Ptr, a1: Ptr) -> Ptr { if CppLess::less(&a0, &a1) { a1 } else { a0 } } -fn f18, T2: Clone + ByteRepr>(a0: T1, a1: T1) { +fn f18, T2: Swappable>(a0: T1, a1: T1) { let __n = a1.iter_distance(&a0); let __random = std::hash::RandomState::new(); for __i in (1..__n).rev() { let __j = (std::hash::BuildHasher::hash_one(&__random, __i) % (__i + 1) as u64) as isize; - cpp_swap!(a0.iter_at(__i), a0.iter_at(__j)); + Swappable::swap(&a0.iter_at(__i), a0.iter_at(__j)); } } diff --git a/rules/algorithm/tgt_unsafe.rs b/rules/algorithm/tgt_unsafe.rs index 3a4b31be1c..9bdfe6a5e6 100644 --- a/rules/algorithm/tgt_unsafe.rs +++ b/rules/algorithm/tgt_unsafe.rs @@ -81,8 +81,10 @@ unsafe fn f8, T2: PartialOrd>(a0: T1, a1: T1) -> __best } -unsafe fn f9(a0: *mut T1, a1: *mut T1) { - cpp_swap_unsafe!(a0, a1) +unsafe fn f9(a0: *mut T1, a1: *mut T1) { + let __a: *mut T1 = a0; + let __b: *mut T1 = a1; + SwappableUnsafe::swap(&mut *__a, __b) } unsafe fn f10, T2: PartialEq + Clone>(a0: T1, a1: T1) -> T1 { @@ -156,10 +158,10 @@ unsafe fn f17(a0: *const T1, a1: *const T1) -> *const T1 { if *__a < *__b { __b } else { __a } } -unsafe fn f18, T2>(a0: T1, a1: T1) { +unsafe fn f18, T2: SwappableUnsafe>(a0: T1, a1: T1) { let __n = a1.iter_distance(&a0); for __i in (1..__n).rev() { let __j = libc::rand() as isize % (__i + 1); - cpp_swap_unsafe!(a0.iter_at(__i), a0.iter_at(__j)); + SwappableUnsafe::swap(&mut *a0.iter_at(__i), a0.iter_at(__j)); } } diff --git a/rules/array/tgt_refcount.rs b/rules/array/tgt_refcount.rs index a7eec2a600..dfd5d52304 100644 --- a/rules/array/tgt_refcount.rs +++ b/rules/array/tgt_refcount.rs @@ -29,16 +29,24 @@ fn f3(a0: Ptr) -> Ptr { a0 } -fn f4(a0: Ptr) -> Box<[T1]> { - (0..T2).map(|__i| T1::move_ctor(a0.offset(__i))).collect() +fn f4( + a0: Ptr, +) -> Box<[T1]> { + let __v: Value> = + Rc::new(RefCell::new((0..T2).map(|_| T1::zero_init()).collect())); + let __p: Ptr = __v.decay(); + for __i in 0..T2 { + MoveConstructible::move_constructor(&__p.offset(__i), a0.offset(__i)); + } + Rc::try_unwrap(__v).ok().unwrap().into_inner() } -fn f5( +fn f5( a0: Ptr>, a1: Ptr, ) -> Ptr> { for __i in 0..T2 { - T1::move_assign(&a0.decay().offset(__i), a1.offset(__i)); + MoveAssignable::move_assign(&a0.decay().offset(__i), a1.offset(__i)); } a0 } @@ -47,12 +55,12 @@ fn f6(a0: Ptr) -> Box<[T1]> { (0..T2).map(|__i| a0.read_at(__i)).collect() } -fn f7( +fn f7( a0: Ptr>, a1: Ptr, ) -> Ptr> { for __i in 0..T2 { - T1::copy_assign(&a0.decay().offset(__i), a1.offset(__i)); + CopyAssignable::copy_assign(&a0.decay().offset(__i), a1.offset(__i)); } a0 } diff --git a/rules/array/tgt_unsafe.rs b/rules/array/tgt_unsafe.rs index 29337299e1..8d01c78699 100644 --- a/rules/array/tgt_unsafe.rs +++ b/rules/array/tgt_unsafe.rs @@ -39,16 +39,21 @@ fn f3(a0: &mut [T1; T2]) -> *mut T1 { a0.as_mut_ptr() } -unsafe fn f4(a0: &mut [T1; T2]) -> [T1; T2] { - std::array::from_fn(|__i| T1::move_ctor(&mut a0[__i])) +unsafe fn f4(a0: &mut [T1; T2]) -> [T1; T2] { + let mut __v = std::mem::MaybeUninit::<[T1; T2]>::uninit(); + let __p = __v.as_mut_ptr() as *mut T1; + for __i in 0..T2 { + (*__p.add(__i)).move_constructor(&mut a0[__i]); + } + __v.assume_init() } -unsafe fn f5<'a, T1: MoveAssignUnsafe, const T2: usize>( +unsafe fn f5<'a, T1: MoveAssignableUnsafe, const T2: usize>( a0: &'a mut [T1; T2], a1: &mut [T1; T2], ) -> &'a mut [T1; T2] { for __i in 0..T2 { - T1::move_assign(&mut a0[__i], &mut a1[__i]); + a0[__i].move_assign(&mut a1[__i]); } a0 } @@ -57,12 +62,12 @@ fn f6(a0: [T1; T2]) -> [T1; T2] { a0.clone() } -unsafe fn f7<'a, T1: CopyAssignUnsafe, const T2: usize>( +unsafe fn f7<'a, T1: CopyAssignableUnsafe, const T2: usize>( a0: &'a mut [T1; T2], a1: &[T1; T2], ) -> &'a mut [T1; T2] { for __i in 0..T2 { - T1::copy_assign(&mut a0[__i], &a1[__i]); + a0[__i].copy_assign(&a1[__i]); } a0 } diff --git a/rules/dirent/shim.rs b/rules/dirent/shim.rs index 1d738cf2cc..7c444620db 100644 --- a/rules/dirent/shim.rs +++ b/rules/dirent/shim.rs @@ -1,11 +1,11 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Record, ZeroInitialization, size_of_field}; +use crate::{ByteRepr, Copyable, Destructible, Record, ZeroInitialization, size_of_field}; use std::cell::Cell; use std::mem::{offset_of, size_of}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(size_of::<::libc::dirent>())] pub struct Dirent { #[offset(offset_of!(::libc::dirent, d_ino))] @@ -85,3 +85,5 @@ impl CDir { impl ByteRepr for CDir {} impl ByteRepr for ::libc::dirent {} + +crate::constructor::impl_trivial_copy_move!(::libc::dirent,); diff --git a/rules/ifaddrs/shim.rs b/rules/ifaddrs/shim.rs index eff408a936..ed8e17bcd4 100644 --- a/rules/ifaddrs/shim.rs +++ b/rules/ifaddrs/shim.rs @@ -2,11 +2,12 @@ // Distributed under the MIT license that can be found in the LICENSE file. use crate::{ - ByteRepr, Ptr, Record, Sockaddr, SockaddrIn, SockaddrIn6, SockaddrStorage, ZeroInitialization, + ByteRepr, Copyable, Destructible, Ptr, Record, Sockaddr, SockaddrIn, SockaddrIn6, + SockaddrStorage, ZeroInitialization, }; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(size_of::<::libc::ifaddrs>())] pub struct Ifaddrs { #[offset(offset_of!(::libc::ifaddrs, ifa_next))] @@ -56,3 +57,5 @@ impl Ifaddrs { } impl ByteRepr for ::libc::ifaddrs {} + +crate::constructor::impl_trivial_copy_move!(::libc::ifaddrs,); diff --git a/rules/ip/shim.rs b/rules/ip/shim.rs index 842f81350e..65eb7d9fe7 100644 --- a/rules/ip/shim.rs +++ b/rules/ip/shim.rs @@ -1,16 +1,16 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Ptr, Record, ZeroInitialization}; +use crate::{ByteRepr, Copyable, Destructible, Ptr, Record, ZeroInitialization}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(4)] pub struct InAddr { #[offset(0)] pub s_addr: u32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(16)] pub struct In6Addr { #[offset(0)] @@ -35,3 +35,5 @@ impl Default for In6Addr { impl ByteRepr for ::libc::in_addr {} impl ByteRepr for ::libc::in6_addr {} + +crate::constructor::impl_trivial_copy_move!(::libc::in_addr, ::libc::in6_addr,); diff --git a/rules/map/shim.rs b/rules/map/shim.rs index caaf12d995..7bdfb4edfb 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -604,3 +604,14 @@ impl Iterator for UnsafeMapRange { Some(self.cur.iter_post_inc()) } } + +crate::constructor::impl_copy_by_clone!( + BTreeMap, + Map, + UnsafeMap, +); +crate::constructor::impl_move_by_take!( + BTreeMap, + Map, + UnsafeMap, +); diff --git a/rules/netdb/shim.rs b/rules/netdb/shim.rs index 9432b2adcf..e83e2d8b49 100644 --- a/rules/netdb/shim.rs +++ b/rules/netdb/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Ptr, Record, Sockaddr, ZeroInitialization}; +use crate::{ByteRepr, Copyable, Destructible, Ptr, Record, Sockaddr, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(size_of::<::libc::addrinfo>())] pub struct Addrinfo { #[offset(offset_of!(::libc::addrinfo, ai_flags))] @@ -26,3 +26,5 @@ pub struct Addrinfo { } impl ByteRepr for ::libc::addrinfo {} + +crate::constructor::impl_trivial_copy_move!(::libc::addrinfo,); diff --git a/rules/poll/shim.rs b/rules/poll/shim.rs index 06f6daa720..8a8a3dbe94 100644 --- a/rules/poll/shim.rs +++ b/rules/poll/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Record, ZeroInitialization}; +use crate::{ByteRepr, Copyable, Destructible, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(size_of::<::libc::pollfd>())] pub struct Pollfd { #[offset(offset_of!(::libc::pollfd, fd))] @@ -16,3 +16,5 @@ pub struct Pollfd { } impl ByteRepr for ::libc::pollfd {} + +crate::constructor::impl_trivial_copy_move!(::libc::pollfd,); diff --git a/rules/pwd/shim.rs b/rules/pwd/shim.rs index 01229b236f..7d5ee08abf 100644 --- a/rules/pwd/shim.rs +++ b/rules/pwd/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Ptr, Record, ZeroInitialization}; +use crate::{ByteRepr, Copyable, Destructible, Ptr, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(size_of::<::libc::passwd>())] pub struct Passwd { #[offset(offset_of!(::libc::passwd, pw_name))] @@ -51,3 +51,5 @@ impl Passwd { } impl ByteRepr for ::libc::passwd {} + +crate::constructor::impl_trivial_copy_move!(::libc::passwd,); diff --git a/rules/select/shim.rs b/rules/select/shim.rs index 7a108b2223..12d904b086 100644 --- a/rules/select/shim.rs +++ b/rules/select/shim.rs @@ -3,7 +3,9 @@ use std::collections::BTreeSet; -#[derive(Clone, Default)] +use crate::{Copyable, Destructible}; + +#[derive(Clone, Default, Copyable, Destructible)] pub struct CFdSet { fds: BTreeSet, } diff --git a/rules/socket/shim.rs b/rules/socket/shim.rs index 47ef06c5f9..baf2cc1242 100644 --- a/rules/socket/shim.rs +++ b/rules/socket/shim.rs @@ -1,10 +1,12 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, CChar, In6Addr, InAddr, Ptr, Record, ZeroInitialization}; +use crate::{ + ByteRepr, CChar, Copyable, Destructible, In6Addr, InAddr, Ptr, Record, ZeroInitialization, +}; // The fields are at the offsets of the byte representation below. -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(16)] pub struct Sockaddr { #[offset(0)] @@ -15,7 +17,7 @@ pub struct Sockaddr { pub sa_data: Box<[i8]>, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(16)] pub struct SockaddrIn { #[offset(0)] @@ -30,7 +32,7 @@ pub struct SockaddrIn { pub sin_zero: Box<[u8]>, } -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(28)] pub struct SockaddrIn6 { #[offset(0)] @@ -45,7 +47,7 @@ pub struct SockaddrIn6 { pub sin6_scope_id: u32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(110)] pub struct SockaddrUn { #[offset(0)] @@ -56,7 +58,7 @@ pub struct SockaddrUn { pub sun_path: Box<[i8]>, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(128)] pub struct SockaddrStorage { #[offset(0)] @@ -397,3 +399,11 @@ pub fn setsockopt_refcount(fd: i32, level: i32, optname: i32, optval: crate::Any } } } + +crate::constructor::impl_trivial_copy_move!( + ::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 423b6bbdd6..84e5e1ba09 100644 --- a/rules/stat/shim.rs +++ b/rules/stat/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Record, ZeroInitialization}; +use crate::{ByteRepr, Copyable, Destructible, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ZeroInitialization)] +#[derive(Clone, Default, Record, ZeroInitialization, Copyable, Destructible)] // 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"), @@ -69,3 +69,5 @@ impl ByteRepr for Stat { } impl ByteRepr for ::libc::stat {} + +crate::constructor::impl_trivial_copy_move!(::libc::stat,); diff --git a/rules/termios/shim.rs b/rules/termios/shim.rs index 2a4ea03734..94d6b0bcea 100644 --- a/rules/termios/shim.rs +++ b/rules/termios/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Record, ZeroInitialization}; +use crate::{ByteRepr, Copyable, Destructible, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(size_of::<::libc::termios>())] pub struct Termios { #[offset(offset_of!(::libc::termios, c_iflag))] @@ -105,7 +105,7 @@ impl Termios { } } -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[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 2c9066f65c..848c6f33e0 100644 --- a/rules/time/shim.rs +++ b/rules/time/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Ptr, Record, ZeroInitialization}; +use crate::{ByteRepr, Copyable, Destructible, Ptr, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(size_of::<::libc::tm>())] pub struct Tm { #[offset(offset_of!(::libc::tm, tm_sec))] @@ -65,7 +65,7 @@ impl Tm { } } -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(size_of::<::libc::timeval>())] pub struct Timeval { #[offset(offset_of!(::libc::timeval, tv_sec))] @@ -74,7 +74,7 @@ pub struct Timeval { pub tv_usec: i64, } -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable, Destructible)] #[byte_size(size_of::<::libc::timespec>())] pub struct Timespec { #[offset(offset_of!(::libc::timespec, tv_sec))] @@ -86,3 +86,5 @@ pub struct Timespec { impl ByteRepr for ::libc::tm {} impl ByteRepr for ::libc::timeval {} impl ByteRepr for ::libc::timespec {} + +crate::constructor::impl_trivial_copy_move!(::libc::tm, ::libc::timeval, ::libc::timespec,); diff --git a/rules/unique_ptr/shim.rs b/rules/unique_ptr/shim.rs index 67808c7161..264aad2598 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -1,4 +1,58 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::{ + ByteRepr, MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, + Ptr, Swappable, SwappableUnsafe, Value, +}; + pub trait CppArray {} + +impl MoveConstructible for Option> +where + Self: ByteRepr, +{ + fn move_constructor(this: &Ptr, src: Ptr) { + let value = src.with_mut(Option::take); + this.with_mut(|dst| *dst = value); + } +} + +impl MoveAssignable for Option> +where + Self: ByteRepr, +{ + fn move_assign(this: &Ptr, src: Ptr) -> Ptr { + let value = src.with_mut(Option::take); + this.with_mut(|dst| *dst = value); + this.clone() + } +} + +impl MoveConstructibleUnsafe for Option> { + unsafe fn move_constructor(&mut self, src: *mut Self) { + unsafe { std::ptr::write(self, (*src).take()) } + } +} + +impl MoveAssignableUnsafe for Option> { + unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe { *self = (*src).take() }; + self + } +} + +impl Swappable for Option> +where + Self: ByteRepr, +{ + fn swap(this: &Ptr, other: Ptr) { + this.swap_with(&other, |p| p.with_mut(Option::take)); + } +} + +impl SwappableUnsafe for Option> { + unsafe fn swap(&mut self, other: *mut Self) { + unsafe { std::ptr::swap(self, other) } + } +} diff --git a/rules/vector/shim.rs b/rules/vector/shim.rs index 40c224d6eb..b0761950ad 100644 --- a/rules/vector/shim.rs +++ b/rules/vector/shim.rs @@ -14,3 +14,6 @@ impl FnPtrArg for Vec { record_from_repr(r) } } + +crate::constructor::impl_copy_by_clone!( Vec); +crate::constructor::impl_move_by_take!( 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 e1598f3b78..19a771fe6d 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 @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct widget { #[offset(0)] 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 a67aba4a6a..5433370a74 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 @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 5b9a7e89c3..cf7c28f4c6 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 @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, MoveAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable)] #[cpp_from(i32, construct, value)] #[byte_size(32)] pub struct S { @@ -18,13 +18,44 @@ pub struct S { #[array_len(2)] pub n: Box<[i32]>, } +impl MoveConstructible for S { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), v).write(field!(_a0, v).with_mut(std::mem::take)); + field!((*this), n).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { + (*_a0.upgrade().deref()).n[(__i) as usize] + }))); + } +} +impl MoveAssignable for S { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).with_mut(|__b0| { + (*__b0) = field!(_a0, v).with_mut(std::mem::take); + }); + { + let mut __tmp_0 = { (array_field_ptr!((*this), n)).to_any() }; + __tmp_0.memcpy(&(array_field_ptr!(_a0, n)).to_any(), 8_usize); + (__tmp_0).clone() + }; + return (*this).clone(); + } +} impl Default for S { fn default() -> Self { { ::zero_init() } } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct T { @@ -32,6 +63,19 @@ pub struct T { #[byte_size(24)] pub v: Vec, } +impl MoveConstructible for T { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), v).write(field!(_a0, v).with_mut(std::mem::take)); + } +} +impl MoveAssignable for T { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).with_mut(|__b0| { + (*__b0) = field!(_a0, v).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} pub fn sum_0(s: Ptr) -> i32 { return ({ ({ (((*s.upgrade().deref()).v.len()) as i32) } + { (array_elem!(s, n, 0).read()) }) @@ -63,7 +107,7 @@ pub fn shuffle_1(mut x: i32) -> i32 { })); let b: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - SImpl::move_from(&__v.as_pointer(), { a.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!(({ (*a.borrow()).v.is_empty() })); @@ -72,16 +116,16 @@ pub fn shuffle_1(mut x: i32) -> i32 { SImpl::construct(&__v.as_pointer(), { 1 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - ({ SImpl::move_assign(&c.as_pointer(), b.as_pointer()) }); + ({ MoveAssignable::move_assign(&c.as_pointer(), b.as_pointer()) }); assert!(({ (*b.borrow()).v.is_empty() })); let t: Value = Rc::new(RefCell::new(T { v: Vec::from([1]) })); let u: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TImpl::move_from(&__v.as_pointer(), { t.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { t.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let w: Value = Rc::new(RefCell::new(::default())); - ({ TImpl::move_assign(&w.as_pointer(), u.as_pointer()) }); + ({ MoveAssignable::move_assign(&w.as_pointer(), u.as_pointer()) }); assert!( ((({ TImpl::size(&t.as_pointer(),) }) == 0) && (({ TImpl::size(&u.as_pointer(),) }) == 0)) && (({ TImpl::size(&w.as_pointer(),) }) == 1) @@ -90,49 +134,19 @@ pub fn shuffle_1(mut x: i32) -> i32 { } pub trait SImpl { fn construct(&self, x: i32); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl SImpl for Ptr { fn construct(&self, mut x: i32) { field!((*self), v).write(vec![x; (x as usize)]); field!((*self), n).write(Box::new([x, (x + 1)])); } - fn move_from(&self, _a0: Ptr) { - field!((*self), v).write(field!(_a0, v).with_mut(std::mem::take)); - field!((*self), n).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { - (*_a0.upgrade().deref()).n[(__i) as usize] - }))); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).with_mut(|__b0| { - (*__b0) = field!(_a0, v).with_mut(std::mem::take); - }); - { - let mut __tmp_0 = { (array_field_ptr!((*self), n)).to_any() }; - __tmp_0.memcpy(&(array_field_ptr!(_a0, n)).to_any(), 8_usize); - (__tmp_0).clone() - }; - return (*self).clone(); - } } pub trait TImpl { fn size(&self) -> i32; - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl TImpl for Ptr { fn size(&self) -> i32 { return (((*(*self).upgrade().deref()).v.len()) as i32); } - fn move_from(&self, _a0: Ptr) { - field!((*self), v).write(field!(_a0, v).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).with_mut(|__b0| { - (*__b0) = field!(_a0, v).with_mut(std::mem::take); - }); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() {} 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 771f119c8b..b2802b1dd2 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 @@ -8,7 +8,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, MoveAssignUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, Default, )] #[cpp_from(i32, construct, value)] pub struct S { @@ -20,11 +20,15 @@ impl S { (&raw mut self.v).write(vec![x; (x as usize)]); (&raw mut self.n).write([x, ((x) + (1))]); } - pub unsafe fn move_from(&mut self, _a0: *mut S) { +} +impl MoveConstructibleUnsafe for S { + unsafe fn move_constructor(&mut self, _a0: *mut S) { (&raw mut self.v).write(std::mem::take(&mut (*_a0).v)); (&raw mut self.n).write(std::array::from_fn::<_, 2, _>(|__i: usize| (*_a0).n[(__i)])); } - pub unsafe fn move_assign(&mut self, _a0: *mut S) -> *mut S { +} +impl MoveAssignableUnsafe for S { + unsafe fn move_assign(&mut self, _a0: *mut S) -> *mut S { { self.v = std::mem::take(&mut (*_a0).v); }; @@ -41,7 +45,15 @@ impl S { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct T { pub v: Vec, @@ -50,10 +62,14 @@ impl T { pub unsafe fn size(&self) -> i32 { return ((self.v.len()) as i32); } - pub unsafe fn move_from(&mut self, _a0: *mut T) { +} +impl MoveConstructibleUnsafe for T { + unsafe fn move_constructor(&mut self, _a0: *mut T) { (&raw mut self.v).write(std::mem::take(&mut (*_a0).v)); } - pub unsafe fn move_assign(&mut self, _a0: *mut T) -> *mut T { +} +impl MoveAssignableUnsafe for T { + unsafe fn move_assign(&mut self, _a0: *mut T) -> *mut T { { self.v = std::mem::take(&mut (*_a0).v); }; @@ -91,7 +107,7 @@ pub unsafe fn shuffle_1(mut x: i32) -> i32 { }; let mut b: S = { let mut __v: S = ::zero_init(); - S::move_from(&mut __v, { &mut a }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut a }); __v }; assert!(a.v.is_empty()); @@ -100,16 +116,16 @@ pub unsafe fn shuffle_1(mut x: i32) -> i32 { S::construct(&mut __v, { 1 }); __v }; - (unsafe { S::move_assign(&mut c, &mut b) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut c, &mut b) }); assert!(b.v.is_empty()); let mut t: T = T { v: Vec::from([1]) }; let mut u: T = { let mut __v: T = ::zero_init(); - T::move_from(&mut __v, { &mut t }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut t }); __v }; let mut w: T = ::default(); - (unsafe { T::move_assign(&mut w, &mut u) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut w, &mut u) }); assert!( (((unsafe { T::size(&t,) }) == (0)) && ((unsafe { T::size(&u,) }) == (0))) && ((unsafe { T::size(&w,) }) == (1)) 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 a5413a53c3..5fea9b06fb 100644 --- a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct S { #[offset(0)] 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 121763987a..a200a83083 100644 --- a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub a: i32, pub b: 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 bbba0d218a..9fe6482f96 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 @@ -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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct container { #[offset(0)] 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 251e8e1290..c7a550cfd7 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 @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct container { pub p: *mut opaque, pub x: i32, 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 f061ebd61d..03e64c397f 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 @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct S { #[offset(0)] pub v: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct M { #[offset(0)] @@ -21,13 +21,35 @@ pub struct M { pub trait Base { fn apply(&mut self, x: i32) -> i32; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct Derived { #[offset(8)] pub factor: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -59,13 +81,13 @@ fn main_0() -> i32 { })); let n: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - MImpl::move_from(&__v.as_pointer(), { m.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { m.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!(({ (*n.borrow()).v } == 2)); let mut c: M = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MImpl::copy_from(&__v.as_pointer(), { n.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { n.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((c.v == 3)); @@ -85,9 +107,20 @@ fn main_0() -> i32 { assert!((({ pair_diff_0((pair.as_pointer()),) }) == 4)); return 0; } +impl MoveConstructible for M { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), v).write({ (*_a0.upgrade().deref()).v }); + } +} +impl CopyConstructible for M { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write((o.with(|__s| __s.v) + 1)); + } +} impl S {} -impl M {} -impl M {} +impl Destructible for S { + fn destroy(this: &Ptr) {} +} impl M {} pub fn move_m_1(mut x: i32) -> i32 { let m: Value = Rc::new(RefCell::new({ @@ -97,7 +130,7 @@ pub fn move_m_1(mut x: i32) -> i32 { })); let mut n: M = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MImpl::move_from(&__v.as_pointer(), { m.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { m.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; return n.v; @@ -125,31 +158,16 @@ pub trait MImpl { fn construct(&self, mut x: i32) { unimplemented!() } - fn move_from(&self, _a0: Ptr) { - unimplemented!() - } - fn copy_from(&self, _a0: Ptr) { - unimplemented!() - } } impl MImpl for Ptr { fn construct(&self, mut x: i32) { field!((*self), v).write(x); } - fn move_from(&self, _a0: Ptr) { - field!((*self), v).write({ (*_a0.upgrade().deref()).v }); - } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write((o.with(|__s| __s.v) + 1)); - } } pub trait SImpl { fn construct(&self, mut x: i32) { unimplemented!() } - fn destructor(&self) { - unimplemented!() - } fn get(&self) -> i32; fn set(&self, mut x: i32) { unimplemented!() @@ -165,7 +183,6 @@ impl SImpl for Ptr { fn construct(&self, mut x: i32) { field!((*self), v).write(x); } - fn destructor(&self) {} fn set(&self, mut x: i32) { field!((*self), v).write(x); } 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 a88bfb4b53..01abac5d5a 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 @@ -7,7 +7,7 @@ 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, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct S { pub v: i32, } @@ -17,7 +17,7 @@ impl S { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] pub struct M { pub v: i32, } @@ -26,13 +26,31 @@ pub unsafe trait Base { unsafe fn apply(&mut self, x: i32) -> i32; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Derived { pub factor: i32, } impl Derived {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub first: i32, pub second: i32, @@ -63,13 +81,13 @@ unsafe fn main_0() -> i32 { }; let mut n: M = { let mut __v: M = ::zero_init(); - M::move_from(&mut __v, { &mut m }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut m }); __v }; assert!(((n.v) == (2))); let mut c: M = { let mut __v: M = ::zero_init(); - M::copy_from(&mut __v, { &n }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &n }); __v }; assert!(((c.v) == (3))); @@ -98,10 +116,14 @@ impl M { pub unsafe fn construct(&mut self, mut x: i32) { (&raw mut self.v).write(x); } - pub unsafe fn move_from(&mut self, _a0: *mut M) { +} +impl MoveConstructibleUnsafe for M { + unsafe fn move_constructor(&mut self, _a0: *mut M) { (&raw mut self.v).write((*_a0).v); } - pub unsafe fn copy_from(&mut self, o: *const M) { +} +impl CopyConstructibleUnsafe for M { + unsafe fn copy_constructor(&mut self, o: *const M) { (&raw mut self.v).write((((*o).v) + (1))); } } @@ -111,8 +133,8 @@ impl Derived { } } impl S {} -impl S { - pub unsafe fn destructor(&mut self) {} +impl DestructibleUnsafe for S { + unsafe fn destroy(&mut self) {} } impl S { pub unsafe fn set(&mut self, mut x: i32) { @@ -126,8 +148,6 @@ impl S { } } impl M {} -impl M {} -impl M {} pub unsafe fn move_m_1(mut x: i32) -> i32 { let mut m: M = { let mut __v: M = ::zero_init(); @@ -136,7 +156,7 @@ pub unsafe fn move_m_1(mut x: i32) -> i32 { }; let mut n: M = { let mut __v: M = ::zero_init(); - M::move_from(&mut __v, { &mut m }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut m }); __v }; return n.v; 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 a43e8c01ad..9124bb3a3f 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 @@ -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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct S_int_ { #[offset(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 a6bebb806c..492d0f2a0b 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 @@ -7,7 +7,9 @@ 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)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct S_int_ { pub x: i32, } 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 21d1ed5c32..3e06ae1365 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Movable)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +44,30 @@ impl LifetimeTracked { }); } } +impl CopyConstructible for LifetimeTracked { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), uses).write(0); + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for LifetimeTracked { + fn destroy(this: &Ptr) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for LifetimeTracked { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), uses).write(_a0.with(|__s| __s.uses)); + return (*this).clone(); + } +} impl Clone for LifetimeTracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,17 +83,22 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] pub expected: i32, } +impl Destructible for AssertsDtorCountAtExit { + fn destroy(this: &Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + } +} thread_local!( pub static check_4: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 2 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(check_4.with(Value::clone).as_pointer()) + Destructible::destroy(&check_4.with(Value::clone).as_pointer()) }); __static }; @@ -89,12 +111,23 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(shared_5.with(Value::clone).as_pointer()) + Destructible::destroy(&shared_5.with(Value::clone).as_pointer()) }); __static }; ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct HasInlineMembers {} impl HasInlineMembers { @@ -110,7 +143,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(local_6.with(Value::clone).as_pointer()) + Destructible::destroy(&local_6.with(Value::clone).as_pointer()) }); __static }; @@ -141,43 +174,21 @@ pub fn b_shared_address_8() -> Ptr { pub fn b_instance_address_9() -> Ptr { return ({ HasInlineMembers::instance() }); } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} pub trait LifetimeTrackedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn destructor(&self); fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl LifetimeTrackedImpl for Ptr { fn construct(&self) { field!((*self), uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), uses).write(0); - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write(_a0.with(|__s| __s.uses)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); 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 cefa6b408a..a19412d26f 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MovableUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,18 +32,24 @@ impl LifetimeTracked { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, _a0: *const LifetimeTracked) { + 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 CopyConstructibleUnsafe for LifetimeTracked { + unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for LifetimeTracked { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).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(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { +} +impl CopyAssignableUnsafe for LifetimeTracked { + unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { self.uses = (*_a0).uses; return &mut (*(self as *mut LifetimeTracked)); } @@ -52,7 +58,7 @@ impl Clone for LifetimeTracked { fn clone(&self) -> Self { unsafe { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, self as *const LifetimeTracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const LifetimeTracked); __v } } @@ -69,12 +75,12 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for AssertsDtorCountAtExit { + unsafe fn destroy(&mut self) { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); } } @@ -83,9 +89,7 @@ pub static mut check_4: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 2 }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut check_4, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut check_4)) }); __static } @@ -99,15 +103,22 @@ pub static mut shared_5: std::cell::LazyCell = __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut shared_5, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) }); __static } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct HasInlineMembers {} impl HasInlineMembers { pub unsafe fn instance() -> *mut LifetimeTracked { @@ -122,9 +133,7 @@ static mut local_6: std::cell::LazyCell = std::cell::LazyCell:: __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut local_6, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut local_6)) }); __static } 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 0d60533295..00512df143 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Movable)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +44,30 @@ impl LifetimeTracked { }); } } +impl CopyConstructible for LifetimeTracked { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), uses).write(0); + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for LifetimeTracked { + fn destroy(this: &Ptr) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for LifetimeTracked { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), uses).write(_a0.with(|__s| __s.uses)); + return (*this).clone(); + } +} impl Clone for LifetimeTracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -74,12 +91,23 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(member_4.with(Value::clone).as_pointer()) + Destructible::destroy(&member_4.with(Value::clone).as_pointer()) }); __static }; ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct HasStaticMember_int_ {} thread_local!( @@ -90,12 +118,23 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(member_5.with(Value::clone).as_pointer()) + Destructible::destroy(&member_5.with(Value::clone).as_pointer()) }); __static }; ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct HasStaticMember_long_ {} pub fn main() { @@ -124,33 +163,19 @@ pub fn b_int_address_8() -> Ptr { } pub trait LifetimeTrackedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn destructor(&self); fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl LifetimeTrackedImpl for Ptr { fn construct(&self) { field!((*self), uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), uses).write(0); - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write(_a0.with(|__s| __s.uses)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); 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 34e5ce487f..ed6754b990 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MovableUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,18 +32,24 @@ impl LifetimeTracked { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, _a0: *const LifetimeTracked) { + 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 CopyConstructibleUnsafe for LifetimeTracked { + unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for LifetimeTracked { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).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(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { +} +impl CopyAssignableUnsafe for LifetimeTracked { + unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { self.uses = (*_a0).uses; return &mut (*(self as *mut LifetimeTracked)); } @@ -52,7 +58,7 @@ impl Clone for LifetimeTracked { fn clone(&self) -> Self { unsafe { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, self as *const LifetimeTracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const LifetimeTracked); __v } } @@ -77,15 +83,22 @@ pub static mut member_4: std::cell::LazyCell = __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut member_4, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut member_4)) }); __static } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct HasStaticMember_int_ {} pub static mut member_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { @@ -96,15 +109,22 @@ pub static mut member_5: std::cell::LazyCell = __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut member_5, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut member_5)) }); __static } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct HasStaticMember_long_ {} pub fn main() { unsafe { 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 e9dd3137fd..59ba114c3f 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Movable)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +44,30 @@ impl LifetimeTracked { }); } } +impl CopyConstructible for LifetimeTracked { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), uses).write(0); + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for LifetimeTracked { + fn destroy(this: &Ptr) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for LifetimeTracked { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), uses).write(_a0.with(|__s| __s.uses)); + return (*this).clone(); + } +} impl Clone for LifetimeTracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,12 +83,17 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] pub expected: i32, } +impl Destructible for AssertsDtorCountAtExit { + fn destroy(this: &Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + } +} pub fn count_4() -> i32 { return (*(*n_6.with(Value::clone).borrow_mut()).prefix_inc()); } @@ -89,7 +111,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(t_5.with(Value::clone).as_pointer()) + Destructible::destroy(&t_5.with(Value::clone).as_pointer()) }); __static }; @@ -105,7 +127,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(t_8.with(Value::clone).as_pointer()) + Destructible::destroy(&t_8.with(Value::clone).as_pointer()) }); __static }; @@ -121,7 +143,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(t_11.with(Value::clone).as_pointer()) + Destructible::destroy(&t_11.with(Value::clone).as_pointer()) }); __static }; @@ -133,7 +155,7 @@ thread_local!( pub static check_13: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 4 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(check_13.with(Value::clone).as_pointer()) + Destructible::destroy(&check_13.with(Value::clone).as_pointer()) }); __static }; @@ -156,7 +178,18 @@ fn main_0() -> i32 { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 4)); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct S_14 {} pub fn count_18() -> i32 { @@ -170,7 +203,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(t_19.with(Value::clone).as_pointer()) + Destructible::destroy(&t_19.with(Value::clone).as_pointer()) }); __static }; @@ -187,46 +220,35 @@ pub fn b_count_long_17() -> i32 { pub fn b_count_local_15() -> i32 { return ({ count_18() }); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct S_21 {} -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} pub trait LifetimeTrackedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn destructor(&self); fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl LifetimeTrackedImpl for Ptr { fn construct(&self) { field!((*self), uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), uses).write(0); - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write(_a0.with(|__s| __s.uses)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); 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 3ac419bcf0..846ade9d3d 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MovableUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,18 +32,24 @@ impl LifetimeTracked { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, _a0: *const LifetimeTracked) { + 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 CopyConstructibleUnsafe for LifetimeTracked { + unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for LifetimeTracked { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).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(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { +} +impl CopyAssignableUnsafe for LifetimeTracked { + unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { self.uses = (*_a0).uses; return &mut (*(self as *mut LifetimeTracked)); } @@ -52,7 +58,7 @@ impl Clone for LifetimeTracked { fn clone(&self) -> Self { unsafe { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, self as *const LifetimeTracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const LifetimeTracked); __v } } @@ -69,12 +75,12 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for AssertsDtorCountAtExit { + unsafe fn destroy(&mut self) { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); } } @@ -95,9 +101,7 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut t_5, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut t_5)) }); __static } @@ -111,9 +115,7 @@ static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new( __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut t_8, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut t_8)) }); __static } @@ -127,9 +129,7 @@ static mut t_11: std::cell::LazyCell = std::cell::LazyCell::new __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut t_11, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut t_11)) }); __static } @@ -140,9 +140,7 @@ pub static mut check_13: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 4 }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut check_13, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut check_13)) }); __static } @@ -168,7 +166,16 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S_14 {} pub unsafe fn count_18() -> i32 { return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut n_20)).prefix_inc()); @@ -181,9 +188,7 @@ static mut t_19: std::cell::LazyCell = std::cell::LazyCell::new __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut t_19, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut t_19)) }); __static } @@ -199,7 +204,16 @@ pub unsafe fn b_count_local_15() -> i32 { return (unsafe { count_18() }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S_21 {} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const ctorCount_0); 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 d8c65b58ff..a5c622605e 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Movable)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +44,30 @@ impl LifetimeTracked { }); } } +impl CopyConstructible for LifetimeTracked { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), uses).write(0); + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for LifetimeTracked { + fn destroy(this: &Ptr) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for LifetimeTracked { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), uses).write(_a0.with(|__s| __s.uses)); + return (*this).clone(); + } +} impl Clone for LifetimeTracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,12 +83,17 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] pub expected: i32, } +impl Destructible for AssertsDtorCountAtExit { + fn destroy(this: &Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + } +} pub fn instance_4() -> Ptr { return t_5.with(|v| v.as_pointer()); } @@ -83,7 +105,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(t_5.with(Value::clone).as_pointer()) + Destructible::destroy(&t_5.with(Value::clone).as_pointer()) }); __static }; @@ -92,7 +114,7 @@ thread_local!( pub static check_6: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(check_6.with(Value::clone).as_pointer()) + Destructible::destroy(&check_6.with(Value::clone).as_pointer()) }); __static }; @@ -119,43 +141,21 @@ pub fn b_use_7() { pub fn b_address_8() -> Ptr { return ({ instance_4() }); } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} pub trait LifetimeTrackedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn destructor(&self); fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl LifetimeTrackedImpl for Ptr { fn construct(&self) { field!((*self), uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), uses).write(0); - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write(_a0.with(|__s| __s.uses)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); 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 a9d8bb2429..7cb48fd99d 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MovableUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,18 +32,24 @@ impl LifetimeTracked { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, _a0: *const LifetimeTracked) { + 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 CopyConstructibleUnsafe for LifetimeTracked { + unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for LifetimeTracked { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).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(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { +} +impl CopyAssignableUnsafe for LifetimeTracked { + unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { self.uses = (*_a0).uses; return &mut (*(self as *mut LifetimeTracked)); } @@ -52,7 +58,7 @@ impl Clone for LifetimeTracked { fn clone(&self) -> Self { unsafe { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, self as *const LifetimeTracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const LifetimeTracked); __v } } @@ -69,12 +75,12 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for AssertsDtorCountAtExit { + unsafe fn destroy(&mut self) { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); } } @@ -89,9 +95,7 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut t_5, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut t_5)) }); __static } @@ -101,9 +105,7 @@ pub static mut check_6: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 1 }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut check_6, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut check_6)) }); __static } 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 34ebfc62f9..e7f8a72e48 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Movable)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +44,30 @@ impl LifetimeTracked { }); } } +impl CopyConstructible for LifetimeTracked { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), uses).write(0); + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for LifetimeTracked { + fn destroy(this: &Ptr) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for LifetimeTracked { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), uses).write(_a0.with(|__s| __s.uses)); + return (*this).clone(); + } +} impl Clone for LifetimeTracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,17 +83,22 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] pub expected: i32, } +impl Destructible for AssertsDtorCountAtExit { + fn destroy(this: &Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + } +} thread_local!( pub static check_4: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(check_4.with(Value::clone).as_pointer()) + Destructible::destroy(&check_4.with(Value::clone).as_pointer()) }); __static }; @@ -89,7 +111,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(shared_5.with(Value::clone).as_pointer()) + Destructible::destroy(&shared_5.with(Value::clone).as_pointer()) }); __static }; @@ -114,43 +136,21 @@ pub fn b_use_6() { pub fn b_address_7() -> Ptr { return (shared_5.with(|v| v.as_pointer())); } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} pub trait LifetimeTrackedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn destructor(&self); fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl LifetimeTrackedImpl for Ptr { fn construct(&self) { field!((*self), uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), uses).write(0); - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write(_a0.with(|__s| __s.uses)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); 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 471dc7023e..9a88ea3956 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MovableUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,18 +32,24 @@ impl LifetimeTracked { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, _a0: *const LifetimeTracked) { + 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 CopyConstructibleUnsafe for LifetimeTracked { + unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for LifetimeTracked { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).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(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { +} +impl CopyAssignableUnsafe for LifetimeTracked { + unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { self.uses = (*_a0).uses; return &mut (*(self as *mut LifetimeTracked)); } @@ -52,7 +58,7 @@ impl Clone for LifetimeTracked { fn clone(&self) -> Self { unsafe { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, self as *const LifetimeTracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const LifetimeTracked); __v } } @@ -69,12 +75,12 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for AssertsDtorCountAtExit { + unsafe fn destroy(&mut self) { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); } } @@ -83,9 +89,7 @@ pub static mut check_4: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 1 }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut check_4, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut check_4)) }); __static } @@ -99,9 +103,7 @@ pub static mut shared_5: std::cell::LazyCell = __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut shared_5, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) }); __static } 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 9a21e5e86e..30103664db 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Movable)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +44,30 @@ impl LifetimeTracked { }); } } +impl CopyConstructible for LifetimeTracked { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), uses).write(0); + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for LifetimeTracked { + fn destroy(this: &Ptr) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for LifetimeTracked { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), uses).write(_a0.with(|__s| __s.uses)); + return (*this).clone(); + } +} impl Clone for LifetimeTracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,13 +83,29 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] pub expected: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +impl Destructible for AssertsDtorCountAtExit { + fn destroy(this: &Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + } +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct X {} thread_local!( @@ -83,7 +116,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(local_4.with(Value::clone).as_pointer()) + Destructible::destroy(&local_4.with(Value::clone).as_pointer()) }); __static }; @@ -92,7 +125,7 @@ thread_local!( pub static check_5: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(check_5.with(Value::clone).as_pointer()) + Destructible::destroy(&check_5.with(Value::clone).as_pointer()) }); __static }; @@ -132,43 +165,21 @@ pub fn b_call_6() { ) }); } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} pub trait LifetimeTrackedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn destructor(&self); fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl LifetimeTrackedImpl for Ptr { fn construct(&self) { field!((*self), uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), uses).write(0); - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write(_a0.with(|__s| __s.uses)); - return (*self).clone(); - } } pub trait XImpl { fn h(&self, cond: bool, p: FnPtr); 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 dc894849a6..8044442031 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MovableUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,18 +32,24 @@ impl LifetimeTracked { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, _a0: *const LifetimeTracked) { + 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 CopyConstructibleUnsafe for LifetimeTracked { + unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for LifetimeTracked { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).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(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { +} +impl CopyAssignableUnsafe for LifetimeTracked { + unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { self.uses = (*_a0).uses; return &mut (*(self as *mut LifetimeTracked)); } @@ -52,7 +58,7 @@ impl Clone for LifetimeTracked { fn clone(&self) -> Self { unsafe { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, self as *const LifetimeTracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const LifetimeTracked); __v } } @@ -69,17 +75,26 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for AssertsDtorCountAtExit { + unsafe fn destroy(&mut self) { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct X {} impl X { pub unsafe fn h(&mut self, mut cond: bool, mut p: Option) { @@ -110,9 +125,7 @@ static mut local_4: std::cell::LazyCell = std::cell::LazyCell:: __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut local_4, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut local_4)) }); __static } @@ -122,9 +135,7 @@ pub static mut check_5: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 1 }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut check_5, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut check_5)) }); __static } 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 97c52f8bd9..900d5daf58 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Movable)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +44,30 @@ impl LifetimeTracked { }); } } +impl CopyConstructible for LifetimeTracked { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), uses).write(0); + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for LifetimeTracked { + fn destroy(this: &Ptr) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for LifetimeTracked { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), uses).write(_a0.with(|__s| __s.uses)); + return (*this).clone(); + } +} impl Clone for LifetimeTracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,12 +83,17 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] pub expected: i32, } +impl Destructible for AssertsDtorCountAtExit { + fn destroy(this: &Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + } +} pub fn f_4(mut cond: bool, mut p: FnPtr) { if cond { ({ @@ -94,7 +116,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(local_5.with(Value::clone).as_pointer()) + Destructible::destroy(&local_5.with(Value::clone).as_pointer()) }); __static }; @@ -103,7 +125,7 @@ thread_local!( pub static check_6: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(check_6.with(Value::clone).as_pointer()) + Destructible::destroy(&check_6.with(Value::clone).as_pointer()) }); __static }; @@ -125,43 +147,21 @@ fn main_0() -> i32 { pub fn b_call_7() { ({ f_4(true, FnPtr::::null()) }); } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} pub trait LifetimeTrackedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn destructor(&self); fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl LifetimeTrackedImpl for Ptr { fn construct(&self) { field!((*self), uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), uses).write(0); - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write(_a0.with(|__s| __s.uses)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); 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 c4cf98de49..439b3df6e7 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MovableUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,18 +32,24 @@ impl LifetimeTracked { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, _a0: *const LifetimeTracked) { + 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 CopyConstructibleUnsafe for LifetimeTracked { + unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for LifetimeTracked { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).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(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { +} +impl CopyAssignableUnsafe for LifetimeTracked { + unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { self.uses = (*_a0).uses; return &mut (*(self as *mut LifetimeTracked)); } @@ -52,7 +58,7 @@ impl Clone for LifetimeTracked { fn clone(&self) -> Self { unsafe { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, self as *const LifetimeTracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const LifetimeTracked); __v } } @@ -69,12 +75,12 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for AssertsDtorCountAtExit { + unsafe fn destroy(&mut self) { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); } } @@ -104,9 +110,7 @@ static mut local_5: std::cell::LazyCell = std::cell::LazyCell:: __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut local_5, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut local_5)) }); __static } @@ -116,9 +120,7 @@ pub static mut check_6: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 1 }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut check_6, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut check_6)) }); __static } 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 41793dcac4..1dae912268 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,7 @@ 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, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct anon_13 { #[offset(0)] @@ -67,7 +67,9 @@ thread_local!( pub fn bump_18() -> i32 { return (*(*counter_17.with(Value::clone).borrow_mut()).prefix_inc()); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct Record_19 { #[offset(0)] @@ -103,7 +105,18 @@ pub fn test_29() { level_28.with(|rc| *rc.borrow_mut() = 10); assert!((({ raise_30(1,) }) == 11)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Tally_31 {} thread_local!( @@ -115,7 +128,18 @@ pub fn test_33() { assert!((({ add_in_b_34(1,) }) == 102)); assert!((total_32.with(|rc| *rc.borrow()) == 11)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p5_members_of_class_with_external_linkage_Ledger {} pub fn test_36() { @@ -183,7 +207,9 @@ pub fn test_55() { assert!((({ second_key_plus_value_53() }) == 32)); assert!((({ key_in_b_56() }) == 400)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct Entry_52 { #[offset(0)] @@ -194,7 +220,9 @@ impl Default for Entry_52 { { Entry_52 { key: 1 } } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct Entry_54 { #[offset(0)] @@ -266,7 +294,7 @@ thread_local!( pub fn ceiling_address_in_b_12() -> Ptr { return (ceiling_10.with(|v| v.as_pointer())); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct anon_62 { #[offset(0)] @@ -304,7 +332,9 @@ thread_local!( pub fn bump_64() -> i32 { return (*(*counter_63.with(Value::clone).borrow_mut()).prefix_inc()); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(16)] pub struct Record_65 { #[offset(0)] @@ -348,7 +378,18 @@ pub fn raise_30(mut by: i32) -> i32 { level_28.with(|rc| *rc.borrow_mut() += by); return level_28.with(|rc| *rc.borrow()); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Tally_67 {} thread_local!( @@ -390,7 +431,9 @@ pub fn key_in_b_56() -> i32 { let mut entry: Entry_71 = ::default(); return (entry.key as i32); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct Entry_71 { #[offset(0)] 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 e387afab9a..4109990271 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,9 @@ pub unsafe fn test_11() { ); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_13 { pub whole: i32, pub fraction: f32, @@ -60,7 +62,9 @@ pub unsafe fn bump_18() -> i32 { return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut counter_17)).prefix_inc()); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Record_19 { pub id: i32, } @@ -93,7 +97,16 @@ pub unsafe fn test_29() { assert!(((unsafe { raise_30(1,) }) == (11))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Tally_31 {} impl Tally_31 { pub unsafe fn add(&mut self, mut amount: i32) -> i32 { @@ -109,7 +122,16 @@ pub unsafe fn test_33() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)) == (11))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p5_members_of_class_with_external_linkage_Ledger {} pub unsafe fn test_36() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_35)) == (50))); @@ -171,7 +193,9 @@ pub unsafe fn test_55() { assert!(((unsafe { key_in_b_56() }) == (400))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Entry_52 { pub key: i32, } @@ -181,7 +205,9 @@ impl Default for Entry_52 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Entry_54 { pub key: i32, pub value: i32, @@ -243,7 +269,9 @@ 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)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_62 { pub whole: i32, pub fraction: f32, @@ -266,7 +294,9 @@ pub unsafe fn bump_64() -> i32 { return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut counter_63)).prefix_inc()); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Record_65 { pub id: i64, pub extra: i32, @@ -303,7 +333,16 @@ pub unsafe fn raise_30(mut by: i32) -> i32 { return (*std::cell::LazyCell::force_mut(&mut *&raw mut level_28)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Tally_67 {} impl Tally_67 { pub unsafe fn add(&mut self, mut amount: i32) -> i32 { @@ -341,7 +380,9 @@ pub unsafe fn key_in_b_56() -> i32 { return (entry.key as i32); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Entry_71 { pub key: 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 96054d9eed..a55c4e14ce 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Movable)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +44,30 @@ impl LifetimeTracked { }); } } +impl CopyConstructible for LifetimeTracked { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), uses).write(0); + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for LifetimeTracked { + fn destroy(this: &Ptr) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for LifetimeTracked { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), uses).write(_a0.with(|__s| __s.uses)); + return (*this).clone(); + } +} impl Clone for LifetimeTracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -75,19 +92,24 @@ thread_local!( thread_local!( pub static dtorCount_6: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] pub value: i32, } +impl Destructible for p1_1_condition_variable_visible_in_else_ConvertsToBool { + fn destroy(this: &Ptr) { + (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); + } +} pub fn test_7() { { let condition: Value = Rc::new( RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }), ); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); if ({ p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( @@ -109,7 +131,7 @@ pub fn test_7() { RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }), ); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); if ({ p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( @@ -153,7 +175,7 @@ pub fn test_9() { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); { @@ -167,7 +189,7 @@ pub fn test_9() { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); } index.prefix_inc(); @@ -182,7 +204,7 @@ pub fn test_9() { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 5)); @@ -195,7 +217,7 @@ pub fn test_9() { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 6)); @@ -231,7 +253,7 @@ pub fn test_11() { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_tracked = std::mem::DropGuard::new(tracked.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); { let tracked: Value = Rc::new(RefCell::new({ @@ -240,7 +262,7 @@ pub fn test_11() { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_tracked = std::mem::DropGuard::new(tracked.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); ({ LifetimeTrackedImpl::use_(&tracked.as_pointer()) }); @@ -329,37 +351,22 @@ fn main_0() -> i32 { } pub trait LifetimeTrackedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn destructor(&self); fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl LifetimeTrackedImpl for Ptr { fn construct(&self) { field!((*self), uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), uses).write(0); - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write(_a0.with(|__s| __s.uses)); - return (*self).clone(); - } } pub trait p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl { fn to_bool(&self) -> bool; - fn destructor(&self); } impl p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl for Ptr @@ -367,9 +374,6 @@ impl p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl fn to_bool(&self) -> bool { return ((*self).with(|__s| __s.value) != 0); } - fn destructor(&self) { - (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); - } } pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); 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 d4746df16b..737c83c38b 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 @@ -9,7 +9,9 @@ use std::rc::{Rc, Weak}; thread_local!( pub static balance_0: Value = Rc::new(RefCell::new(50)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct p1_member_hides_namespace_variable_HasBalance { #[offset(0)] @@ -45,7 +47,9 @@ pub fn test_1() { thread_local!( pub static initial_2: Value = Rc::new(RefCell::new(100)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { #[offset(0)] 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 43c9eec869..36dca359ea 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 @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { 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 da1b9d66d1..c003ab74e9 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 @@ -18,7 +18,9 @@ pub fn test_0() { } assert!((level == 5)); } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct p1_own_address_in_initializer_SelfLinked { #[offset(0)] @@ -73,7 +75,7 @@ pub fn test_3() { pub type anon_4 = u32; pub const anon_4_limit: anon_4 = 13; pub const anon_4_above: anon_4 = 14; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(8)] pub struct p9_func_declared_before_function_body_RecordsConstructorName { #[offset(0)] 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 20d909a493..fe2c5213a7 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 @@ -44,7 +44,18 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small: p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size = 3; 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} pub fn test_5() { @@ -72,7 +83,18 @@ pub fn test_5() { thread_local!( pub static count_6: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p2_12_class_name_in_own_scope_HasStaticCounter {} impl p2_12_class_name_in_own_scope_HasStaticCounter { @@ -88,7 +110,7 @@ pub fn test_7() { count_6.with(|rc| *rc.borrow_mut() = 6); assert!((count_6.with(|rc| *rc.borrow()) == 6)); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_8 { #[offset(0)] @@ -114,7 +136,7 @@ impl Default for anon_8 { thread_local!( pub static anon_8: Value = Rc::new(RefCell::new(::default())); ); -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_9 { #[offset(0)] @@ -137,7 +159,9 @@ impl Default for anon_9 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { #[offset(0)] @@ -173,7 +197,7 @@ 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, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_11 { #[offset(0)] @@ -196,7 +220,9 @@ impl Default for anon_11 { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { #[offset(0)] @@ -240,7 +266,9 @@ thread_local!( thread_local!( pub static rvalue_calls_14: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { #[offset(0)] @@ -282,7 +310,18 @@ thread_local!( thread_local!( pub static rvalue_calls_17: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} pub fn test_18() { @@ -320,7 +359,9 @@ pub fn test_18() { assert!((lvalue_calls_16.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_17.with(|rc| *rc.borrow()) == 2)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { #[offset(0)] @@ -367,7 +408,18 @@ thread_local!( thread_local!( pub static rvalue_calls_21: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} pub fn test_22() { @@ -397,14 +449,36 @@ pub fn test_22() { thread_local!( pub static friend_calls_23: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DeclaresFriend {} pub fn shared_friend_24() -> i32 { (*friend_calls_23.with(Value::clone).borrow_mut()).prefix_inc(); return 7; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DefinesFriend {} pub fn test_25() { @@ -436,7 +510,18 @@ pub fn test_30() { thread_local!( pub static function_calls_31: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct p4_2_class_and_function_share_name_Reading { #[offset(0)] @@ -454,7 +539,18 @@ pub fn test_33() { assert!((({ Reading_32(reading.value,) }) == 5)); assert!((function_calls_31.with(|rc| *rc.borrow()) == 1)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct p4_2_class_and_variable_share_name_Limit { #[offset(0)] 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 d5f103c910..cbf81df578 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MovableUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,18 +32,24 @@ impl LifetimeTracked { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, _a0: *const LifetimeTracked) { + 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 CopyConstructibleUnsafe for LifetimeTracked { + unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for LifetimeTracked { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).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(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { +} +impl CopyAssignableUnsafe for LifetimeTracked { + unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { self.uses = (*_a0).uses; return &mut (*(self as *mut LifetimeTracked)); } @@ -52,7 +58,7 @@ impl Clone for LifetimeTracked { fn clone(&self) -> Self { unsafe { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, self as *const LifetimeTracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const LifetimeTracked); __v } } @@ -74,7 +80,7 @@ pub static mut else_runs_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { pub value: i32, } @@ -82,7 +88,9 @@ impl p1_1_condition_variable_visible_in_else_ConvertsToBool { pub unsafe fn to_bool(&self) -> bool { return ((self.value) != (0)); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for p1_1_condition_variable_visible_in_else_ConvertsToBool { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); } } @@ -91,7 +99,7 @@ pub unsafe fn test_7() { let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) { @@ -109,7 +117,7 @@ pub unsafe fn test_7() { let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) { @@ -150,7 +158,7 @@ pub unsafe fn test_9() { __v }; let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); { @@ -163,7 +171,7 @@ pub unsafe fn test_9() { __v }; let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } index.prefix_inc(); @@ -178,7 +186,7 @@ pub unsafe fn test_9() { __v }; let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (5))); @@ -191,7 +199,7 @@ pub unsafe fn test_9() { __v }; let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (6))); @@ -223,7 +231,7 @@ pub unsafe fn test_11() { __v }; let _dtor_tracked = std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); { let mut tracked: LifetimeTracked = { @@ -232,7 +240,7 @@ pub unsafe fn test_11() { __v }; let _dtor_tracked = std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); (unsafe { LifetimeTracked::use_(&tracked) }); 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 d332543beb..cd37496ec4 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 @@ -8,7 +8,9 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub static mut balance_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p1_member_hides_namespace_variable_HasBalance { pub balance: i32, } @@ -46,7 +48,9 @@ pub unsafe fn test_1() { } pub static mut initial_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub held: i32, } 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 7a8e0eb7ff..e75522bcdb 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 @@ -7,7 +7,17 @@ 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, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { pub amount: i32, 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 6f6d6ec66c..46aaac1871 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 @@ -19,7 +19,16 @@ pub unsafe fn test_0() { assert!(((level) == (5))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p1_own_address_in_initializer_SelfLinked { pub next: *mut p1_own_address_in_initializer_SelfLinked, pub value: i32, @@ -72,7 +81,9 @@ pub type anon_4 = u32; pub const anon_4_limit: anon_4 = 13; pub const anon_4_above: anon_4 = 14; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: *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 139e923e4d..c149f64d3d 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 @@ -42,7 +42,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; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum { pub unsafe fn scale(&self, mut count: i32) -> i32 { @@ -69,7 +78,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p2_12_class_name_in_own_scope_HasStaticCounter {} impl p2_12_class_name_in_own_scope_HasStaticCounter { pub unsafe fn bump() { @@ -85,7 +103,9 @@ 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)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_8 { pub namespace_count: i32, pub namespace_ratio: f64, @@ -98,7 +118,9 @@ 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)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_9 { pub member_count: i32, pub member_ratio: f64, @@ -109,7 +131,16 @@ impl Default for anon_9 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { pub tag: i32, pub anon_9: anon_9, @@ -146,7 +177,9 @@ pub unsafe fn test_10() { assert!(((anon_11.block_ratio) == (0.75_f64))); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_11 { pub block_count: i32, pub block_ratio: f64, @@ -157,7 +190,9 @@ impl Default for anon_11 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { pub plain_calls: i32, pub const_calls: i32, @@ -205,7 +240,9 @@ pub static mut explicit_calls_13: std::cell::LazyCell = pub static mut rvalue_calls_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { pub base: i32, } @@ -257,7 +294,16 @@ pub static mut lvalue_calls_16: std::cell::LazyCell = pub static mut rvalue_calls_17: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads { pub unsafe fn get_1(&mut self) -> i32 { @@ -297,7 +343,9 @@ pub unsafe fn test_18() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_17)) == (2))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { pub plain_calls: i32, pub const_calls: i32, @@ -353,7 +401,16 @@ pub static mut lvalue_calls_20: std::cell::LazyCell = pub static mut rvalue_calls_21: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} impl p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads { pub unsafe fn get_1_int(&mut self, mut value: i32) -> i32 { @@ -392,14 +449,32 @@ pub unsafe fn test_22() { pub static mut friend_calls_23: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DeclaresFriend {} pub unsafe fn shared_friend_24() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut friend_calls_23)).prefix_inc(); return 7; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DefinesFriend {} pub unsafe fn test_25() { assert!(((unsafe { shared_friend_24() }) == (7))); @@ -428,7 +503,16 @@ pub unsafe fn test_30() { pub static mut function_calls_31: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p4_2_class_and_function_share_name_Reading { pub value: i32, } @@ -445,7 +529,16 @@ pub unsafe fn test_33() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut function_calls_31)) == (1))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 3f53a0a454..aae0286b89 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 @@ -6,12 +6,17 @@ 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, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct Tracker { #[offset(0)] pub tag: i32, } +impl Destructible for Tracker { + fn destroy(this: &Ptr) { + printf!(b"destroy %d\n", (*this).with(|__s| __s.tag)); + } +} thread_local!( pub static global_0: Value = { let __static = Rc::new(RefCell::new({ @@ -20,7 +25,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(global_0.with(Value::clone).as_pointer()) + Destructible::destroy(&global_0.with(Value::clone).as_pointer()) }); __static }; @@ -35,7 +40,7 @@ pub fn exit_from_nested_call_1() { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_automatic = std::mem::DropGuard::new(automatic.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); libcc2rs::cpp2rust_exit(0); } @@ -47,7 +52,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(local_static_2.with(Value::clone).as_pointer()) + Destructible::destroy(&local_static_2.with(Value::clone).as_pointer()) }); __static }; @@ -63,16 +68,12 @@ fn main_0() -> i32 { } pub trait TrackerImpl { fn construct(&self, tag: i32); - fn destructor(&self); } impl TrackerImpl for Ptr { fn construct(&self, mut tag: i32) { field!((*self), tag).write(tag); printf!(b"construct %d\n", tag); } - fn destructor(&self) { - printf!(b"destroy %d\n", (*self).with(|__s| __s.tag)); - } } pub fn __cpp2rust_init_globals() { let _ = global_0.with(|_| ()); 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 58b75dbf81..13e325123a 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 @@ -6,20 +6,41 @@ 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, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct Tracker { #[offset(0)] pub tag: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +impl Destructible for Tracker { + fn destroy(this: &Ptr) { + printf!(b"destroy %d\n", (*this).with(|__s| __s.tag)); + } +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct HoldsTracker { #[offset(0)] #[byte_size(4)] pub member: Tracker, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +impl Destructible for HoldsTracker { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, member)); + } +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct TriviallyDestructible { #[offset(0)] @@ -33,7 +54,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(global_0.with(Value::clone).as_pointer()) + Destructible::destroy(&global_0.with(Value::clone).as_pointer()) }); __static }; @@ -52,7 +73,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(never_constructed_2.with(Value::clone).as_pointer()) + Destructible::destroy(&never_constructed_2.with(Value::clone).as_pointer()) }); __static }; @@ -68,7 +89,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(before_6.with(Value::clone).as_pointer()) + Destructible::destroy(&before_6.with(Value::clone).as_pointer()) }); __static }; @@ -83,7 +104,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(after_7.with(Value::clone).as_pointer()) + Destructible::destroy(&after_7.with(Value::clone).as_pointer()) }); __static }; @@ -98,7 +119,7 @@ thread_local!( }, })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(holder_8.with(Value::clone).as_pointer()) + Destructible::destroy(&holder_8.with(Value::clone).as_pointer()) }); __static }; @@ -107,7 +128,18 @@ thread_local!( pub static trivial_9: Value = Rc::new(RefCell::new(TriviallyDestructible { value: 6 })); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p3_reverse_completion_order_WithStaticMember {} thread_local!( @@ -118,7 +150,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(member_10.with(Value::clone).as_pointer()) + Destructible::destroy(&member_10.with(Value::clone).as_pointer()) }); __static }; @@ -138,7 +170,7 @@ thread_local!( } ))); libcc2rs::register_static_destructor(|| { - Destructible::destroy(capturing_11.with(Value::clone).as_pointer()) + Destructible::destroy(&capturing_11.with(Value::clone).as_pointer()) }); __static }; @@ -165,7 +197,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(during_init_5.with(Value::clone).as_pointer()) + Destructible::destroy(&during_init_5.with(Value::clone).as_pointer()) }); __static }; @@ -178,7 +210,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(during_main_13.with(Value::clone).as_pointer()) + Destructible::destroy(&during_main_13.with(Value::clone).as_pointer()) }); __static }; @@ -193,17 +225,8 @@ fn main_0() -> i32 { printf!(b"return from main\n"); return 0; } -pub trait HoldsTrackerImpl { - fn destructor(&self); -} -impl HoldsTrackerImpl for Ptr { - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, member)); - } -} pub trait TrackerImpl { fn construct(&self, tag: i32); - fn destructor(&self); fn touch(&self); } impl TrackerImpl for Ptr { @@ -211,9 +234,6 @@ impl TrackerImpl for Ptr { field!((*self), tag).write(tag); printf!(b"construct %d\n", tag); } - fn destructor(&self) { - printf!(b"destroy %d\n", (*self).with(|__s| __s.tag)); - } fn touch(&self) { printf!(b"touch %d\n", (*self).with(|__s| __s.tag)); } 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 dabbb973ac..804d3d61d8 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 @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Tracker { pub tag: i32, } @@ -16,7 +16,9 @@ impl Tracker { (&raw mut self.tag).write(tag); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for Tracker { + unsafe fn destroy(&mut self) { (unsafe { libc::printf(c"destroy %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); } } @@ -28,9 +30,7 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut global_0, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) }); __static } @@ -48,7 +48,7 @@ pub unsafe fn exit_from_nested_call_1() { __v }; let _dtor_automatic = std::mem::DropGuard::new(&raw mut automatic, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); libcc2rs::cpp2rust_exit(0); } @@ -60,7 +60,7 @@ static mut local_static_2: std::cell::LazyCell = std::cell::LazyCell::n __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut( &mut *&raw mut local_static_2, )) }); 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 1dcdcb2ff4..dc180aaa8a 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 @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Tracker { pub tag: i32, } @@ -16,25 +16,36 @@ impl Tracker { (&raw mut self.tag).write(tag); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); } - pub unsafe fn destructor(&mut self) { - (unsafe { libc::printf(c"destroy %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); - } pub unsafe fn touch(&self) { (unsafe { libc::printf(c"touch %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); } } +impl DestructibleUnsafe for Tracker { + unsafe fn destroy(&mut self) { + (unsafe { libc::printf(c"destroy %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); + } +} #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct HoldsTracker { pub member: Tracker, } -impl HoldsTracker { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.member); +impl DestructibleUnsafe for HoldsTracker { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.member); } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct TriviallyDestructible { pub value: i32, } @@ -46,9 +57,7 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut global_0, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) }); __static } @@ -70,7 +79,7 @@ static mut never_constructed_2: std::cell::LazyCell = __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut( &mut *&raw mut never_constructed_2, )) }); @@ -88,9 +97,7 @@ pub static mut before_6: std::cell::LazyCell = std::cell::LazyCell::new __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut before_6, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut before_6)) }); __static } @@ -105,9 +112,7 @@ pub static mut after_7: std::cell::LazyCell = std::cell::LazyCell::new( __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut after_7, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut after_7)) }); __static } @@ -122,9 +127,7 @@ pub static mut holder_8: std::cell::LazyCell = std::cell::LazyCell }, }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut holder_8, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut holder_8)) }); __static } @@ -132,7 +135,16 @@ pub static mut holder_8: std::cell::LazyCell = std::cell::LazyCell pub static mut trivial_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { TriviallyDestructible { value: 6 } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p3_reverse_completion_order_WithStaticMember {} pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { @@ -142,9 +154,7 @@ pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::ne __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( - &mut *&raw mut member_10, - )) + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut(&mut *&raw mut member_10)) }); __static } @@ -165,7 +175,7 @@ pub static mut capturing_11: std::cell::LazyCell i32>> = } ); libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut( &mut *&raw mut capturing_11, )) }); @@ -201,7 +211,7 @@ static mut during_init_5: std::cell::LazyCell = std::cell::LazyCell::ne __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut( &mut *&raw mut during_init_5, )) }); @@ -216,7 +226,7 @@ static mut during_main_13: std::cell::LazyCell = std::cell::LazyCell::n __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut( &mut *&raw mut during_main_13, )) }); 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 d50e4c91c2..a3dc69da99 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 @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { #[offset(0)] @@ -69,7 +80,18 @@ pub fn test_0() { }; assert!(({ ((*null_pm.borrow()) == -1_isize) })); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts { #[offset(0)] 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 954591d54c..db0fc740f3 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 @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { pub first: i32, pub second: i32, @@ -76,7 +85,16 @@ pub unsafe fn test_0() { assert!(((null_pm) == -1_isize)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts { pub first: i32, pub second: i32, diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 1a24258f2a..630c9c4417 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -9,7 +9,9 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copyCount_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Movable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct HasConstexprCtor { @@ -21,12 +23,24 @@ impl HasConstexprCtor { copyCount_0.with(|rc| *rc.borrow_mut() = 0); } } +impl CopyConstructible for HasConstexprCtor { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), m).write(o.with(|__s| __s.m)); + (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for HasConstexprCtor { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), m).write(_a0.with(|__s| __s.m)); + return (*this).clone(); + } +} impl Clone for HasConstexprCtor { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -42,7 +56,7 @@ thread_local!( thread_local!( pub static useCount_4: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Movable)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -68,13 +82,30 @@ impl LifetimeTracked { }); } } +impl CopyConstructible for LifetimeTracked { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), uses).write(0); + (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for LifetimeTracked { + fn destroy(this: &Ptr) { + (*dtorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for LifetimeTracked { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), uses).write(_a0.with(|__s| __s.uses)); + return (*this).clone(); + } +} impl Clone for LifetimeTracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -233,7 +264,18 @@ thread_local!( pub trait p4_1_pure_virtual_without_definition_HasPureVirtual { fn f(&mut self); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} pub fn test_11() { @@ -253,7 +295,7 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(global_12.with(Value::clone).as_pointer()) + Destructible::destroy(&global_12.with(Value::clone).as_pointer()) }); __static }; @@ -278,14 +320,14 @@ pub fn test_14() { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_t = - std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let r: Ptr = t.as_pointer(); let f: Value> = Rc::new(RefCell::new(lambda!( { let r: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), { (r).clone() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { (r).clone() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -294,7 +336,7 @@ pub fn test_14() { } ))); let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); ({ (*f.borrow()).call() }); assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); @@ -326,7 +368,7 @@ pub fn test_16() { let k: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::copy_from(&__v.as_pointer(), { k.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { k.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -334,7 +376,7 @@ pub fn test_16() { let mut c: HasConstexprCtor = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::copy_from(&__v.as_pointer(), { k.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { k.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; return c.m; @@ -357,7 +399,9 @@ pub fn test_17() { thread_local!( pub static copies_18: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Movable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(8)] pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { @@ -366,6 +410,26 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { #[offset(4)] pub scratch: i32, } +impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember { + fn copy_constructor( + this: &Ptr, + o: Ptr, + ) { + field!((*this), value).write(o.with(|__s| __s.value)); + field!((*this), scratch).write(o.with(|__s| __s.scratch)); + (*copies_18.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for p5_2_mutable_subobject_is_odr_used_HasMutableMember { + fn copy_assign( + this: &Ptr, + _a0: Ptr, + ) -> Ptr { + field!((*this), value).write(_a0.with(|__s| __s.value)); + field!((*this), scratch).write(_a0.with(|__s| __s.scratch)); + return (*this).clone(); + } +} impl Clone for p5_2_mutable_subobject_is_odr_used_HasMutableMember { fn clone(&self) -> Self { let __src: Value = Rc::new( @@ -377,10 +441,7 @@ impl Clone for p5_2_mutable_subobject_is_odr_used_HasMutableMember { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl::copy_from( - &__v.as_pointer(), - __src.as_pointer(), - ); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -402,10 +463,7 @@ pub fn test_19() { Rc::new(RefCell::new( ::zero_init(), )); - p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl::copy_from( - &__v.as_pointer(), - { k.as_pointer() }, - ); + CopyConstructible::copy_constructor(&__v.as_pointer(), { k.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -418,7 +476,15 @@ pub fn test_19() { assert!((copies_18.with(|rc| *rc.borrow()) == 1)); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + Movable, + Default, )] #[byte_size(8)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { @@ -429,6 +495,22 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[byte_size(4)] pub b: LifetimeTracked, } +impl Destructible for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, b)); + Destructible::destroy(&field_ptr!(this, a)); + } +} +impl CopyAssignable for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + fn copy_assign( + this: &Ptr, + _a0: Ptr, + ) -> Ptr { + ({ CopyAssignable::copy_assign(&field_ptr!((*this), a), field_ptr!(_a0, a)) }); + ({ CopyAssignable::copy_assign(&field_ptr!((*this), b), field_ptr!(_a0, b)) }); + return (*this).clone(); + } +} pub fn test_20() { ({ LifetimeTracked::reset() }); let p: Value = Rc::new(RefCell::new( @@ -448,7 +530,7 @@ pub fn test_20() { }, )); let _dtor_p = - std::mem::DropGuard::new(p.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(p.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let __decomp_21: Ptr = p.as_pointer(); let f: Value usize>> = Rc::new(RefCell::new(FnPtr:: usize>::new(|| -> usize { @@ -462,7 +544,7 @@ pub fn test_20() { assert!((useCount_4.with(|rc| *rc.borrow()) == 0)); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible, + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyConstructible, Movable, )] #[byte_size(8)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { @@ -472,6 +554,21 @@ pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(4)] pub n: i32, } +impl Destructible for p7_member_access_captures_this_HasMemberUsedInLambda { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, x)); + } +} +impl CopyAssignable for p7_member_access_captures_this_HasMemberUsedInLambda { + fn copy_assign( + this: &Ptr, + _a0: Ptr, + ) -> Ptr { + ({ CopyAssignable::copy_assign(&field_ptr!((*this), x), field_ptr!(_a0, x)) }); + field!((*this), n).write(_a0.with(|__s| __s.n)); + return (*this).clone(); + } +} impl Default for p7_member_access_captures_this_HasMemberUsedInLambda { fn default() -> Self { { @@ -488,7 +585,7 @@ pub fn test_22() { ::default(), )); let _dtor_c = - std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let f: Value i32>> = Rc::new(RefCell::new( ({ p7_member_access_captures_this_HasMemberUsedInLambdaImpl::makeLambda(&c.as_pointer()) }), )); @@ -501,7 +598,15 @@ pub fn test_22() { assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + Movable, + Default, )] #[byte_size(4)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { @@ -509,13 +614,27 @@ pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[byte_size(4)] pub x: LifetimeTracked, } +impl Destructible for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, x)); + } +} +impl CopyAssignable for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + fn copy_assign( + this: &Ptr, + _a0: Ptr, + ) -> Ptr { + ({ CopyAssignable::copy_assign(&field_ptr!((*this), x), field_ptr!(_a0, x)) }); + return (*this).clone(); + } +} pub fn test_23() { ({ LifetimeTracked::reset() }); let c: Value = Rc::new( RefCell::new(::default()), ); let _dtor_c = - std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let f: Value usize>> = Rc::new(RefCell::new( ({ p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl::sizer(&c.as_pointer()) @@ -548,7 +667,7 @@ pub fn test_26() { thread_local!( pub static t_ctors_27: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl Default for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { @@ -584,7 +703,7 @@ pub fn test_28() { thread_local!( pub static ctor_calls_29: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] #[byte_size(4)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { #[offset(0)] @@ -620,7 +739,18 @@ pub fn test_31() { thread_local!( pub static m_ctors_32: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + Movable, +)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { @@ -639,7 +769,18 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { #[offset(0)] @@ -784,61 +925,53 @@ impl p4_1_pure_virtual_without_definition_HasPureVirtual (*derived_calls_10.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + fn destroy(_: &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) { + 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 { + unreachable!( + "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" + ) + } +} pub trait HasConstexprCtorImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl HasConstexprCtorImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), m).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), m).write(o.with(|__s| __s.m)); - (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write(_a0.with(|__s| __s.m)); - return (*self).clone(); - } } pub trait LifetimeTrackedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn destructor(&self); fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl LifetimeTrackedImpl for Ptr { fn construct(&self) { field!((*self), uses).write(0); (*ctorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), uses).write(0); - (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*dtorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); }); (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write(_a0.with(|__s| __s.uses)); - return (*self).clone(); - } } pub trait p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn copy_assign( - &self, - _a0: Ptr, - ) -> Ptr; } impl p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl for Ptr @@ -847,50 +980,9 @@ impl p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl field!((*self), value).write(v); field!((*self), scratch).write(0); } - fn copy_from(&self, o: Ptr) { - field!((*self), value).write(o.with(|__s| __s.value)); - field!((*self), scratch).write(o.with(|__s| __s.scratch)); - (*copies_18.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign( - &self, - _a0: Ptr, - ) -> Ptr { - field!((*self), value).write(_a0.with(|__s| __s.value)); - field!((*self), scratch).write(_a0.with(|__s| __s.scratch)); - return (*self).clone(); - } -} -pub trait p6_unevaluated_binding_needs_no_capture_HasTwoMembersImpl { - fn copy_assign( - &self, - _a0: Ptr, - ) -> Ptr; - fn destructor(&self); -} -impl p6_unevaluated_binding_needs_no_capture_HasTwoMembersImpl - for Ptr -{ - fn copy_assign( - &self, - _a0: Ptr, - ) -> Ptr { - ({ LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), a), field_ptr!(_a0, a)) }); - ({ LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), b), field_ptr!(_a0, b)) }); - return (*self).clone(); - } - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, b)); - Destructible::destroy(field_ptr!(self, a)); - } } pub trait p7_member_access_captures_this_HasMemberUsedInLambdaImpl { fn makeLambda(&self) -> FnPtr i32>; - fn copy_assign( - &self, - _a0: Ptr, - ) -> Ptr; - fn destructor(&self); } impl p7_member_access_captures_this_HasMemberUsedInLambdaImpl for Ptr @@ -907,25 +999,9 @@ impl p7_member_access_captures_this_HasMemberUsedInLambdaImpl } ); } - fn copy_assign( - &self, - _a0: Ptr, - ) -> Ptr { - ({ LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), x), field_ptr!(_a0, x)) }); - field!((*self), n).write(_a0.with(|__s| __s.n)); - return (*self).clone(); - } - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, x)); - } } pub trait p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl { fn sizer(&self) -> FnPtr usize>; - fn copy_assign( - &self, - _a0: Ptr, - ) -> Ptr; - fn destructor(&self); } impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl for Ptr @@ -937,22 +1013,9 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl } }); } - fn copy_assign( - &self, - _a0: Ptr, - ) -> Ptr { - ({ LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), x), field_ptr!(_a0, x)) }); - return (*self).clone(); - } - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, x)); - } } pub trait p9_destructor_not_potentially_invoked_HasUndefinedDestructorImpl { fn construct(&self); - fn destructor(&self) { - unimplemented!() - } } impl p9_destructor_not_potentially_invoked_HasUndefinedDestructorImpl for Ptr @@ -963,9 +1026,6 @@ impl p9_destructor_not_potentially_invoked_HasUndefinedDestructorImpl } pub trait p9_unused_copy_constructor_HasUndefinedCopyCtorImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr) { - unimplemented!() - } } impl p9_unused_copy_constructor_HasUndefinedCopyCtorImpl for Ptr @@ -977,12 +1037,6 @@ impl p9_unused_copy_constructor_HasUndefinedCopyCtorImpl } pub trait p9_unused_implicit_assignment_HasUndefinedCopyAssignmentImpl { fn construct(&self); - fn copy_assign( - &self, - _a0: Ptr, - ) -> Ptr { - unimplemented!() - } } impl p9_unused_implicit_assignment_HasUndefinedCopyAssignmentImpl for Ptr diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 624bd9f248..b00c56c4a9 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -8,7 +8,15 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + MovableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct HasConstexprCtor { pub m: i32, @@ -20,11 +28,15 @@ impl HasConstexprCtor { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.m).write(v); } - pub unsafe fn copy_from(&mut self, o: *const HasConstexprCtor) { +} +impl CopyConstructibleUnsafe for HasConstexprCtor { + unsafe fn copy_constructor(&mut self, o: *const HasConstexprCtor) { (&raw mut self.m).write((*o).m); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { +} +impl CopyAssignableUnsafe for HasConstexprCtor { + unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { self.m = (*_a0).m; return &mut (*(self as *mut HasConstexprCtor)); } @@ -33,7 +45,7 @@ impl Clone for HasConstexprCtor { fn clone(&self) -> Self { unsafe { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::copy_from(&mut __v, self as *const HasConstexprCtor); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const HasConstexprCtor); __v } } @@ -43,7 +55,7 @@ pub static mut copyCount_2: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MovableUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -64,18 +76,24 @@ impl LifetimeTracked { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, _a0: *const LifetimeTracked) { + 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 CopyConstructibleUnsafe for LifetimeTracked { + unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for LifetimeTracked { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)).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(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { +} +impl CopyAssignableUnsafe for LifetimeTracked { + unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { self.uses = (*_a0).uses; return &mut (*(self as *mut LifetimeTracked)); } @@ -84,7 +102,7 @@ impl Clone for LifetimeTracked { fn clone(&self) -> Self { unsafe { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, self as *const LifetimeTracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const LifetimeTracked); __v } } @@ -224,7 +242,16 @@ pub unsafe trait p4_1_pure_virtual_without_definition_HasPureVirtual { unsafe fn f(&mut self); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} pub unsafe fn test_11() { let mut d: p4_1_pure_virtual_without_definition_OverridesPureVirtual = @@ -243,7 +270,7 @@ pub static mut global_12: std::cell::LazyCell = __v }; libcc2rs::register_static_destructor(|| { - DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + DestructibleUnsafe::destroy(std::cell::LazyCell::force_mut( &mut *&raw mut global_12, )) }); @@ -272,14 +299,14 @@ pub unsafe fn test_14() { __v }; let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let r: *mut LifetimeTracked = &mut t; let mut f: FnPtr = lambda_unsafe!( { let r: LifetimeTracked = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, { r }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { r }); __v }; }, @@ -288,7 +315,7 @@ pub unsafe fn test_14() { } ); let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (1))); (unsafe { f.call() }); @@ -320,14 +347,14 @@ pub unsafe fn test_16() { { let k: HasConstexprCtor = { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::copy_from(&mut __v, { &k }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &k }); __v }; }, || -> i32 { let mut c: HasConstexprCtor = { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::copy_from(&mut __v, { &k }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &k }); __v }; return c.m; @@ -348,7 +375,15 @@ pub unsafe fn test_17() { } pub static mut copies_18: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + MovableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { pub value: i32, @@ -359,7 +394,9 @@ impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { (&raw mut self.value).write(v); (&raw mut self.scratch).write(0); } - pub unsafe fn copy_from( +} +impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMember { + unsafe fn copy_constructor( &mut self, o: *const p5_2_mutable_subobject_is_odr_used_HasMutableMember, ) { @@ -367,7 +404,9 @@ impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { (&raw mut self.scratch).write((*o).scratch); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)).prefix_inc(); } - pub unsafe fn copy_assign( +} +impl CopyAssignableUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMember { + unsafe fn copy_assign( &mut self, _a0: *const p5_2_mutable_subobject_is_odr_used_HasMutableMember, ) -> *mut p5_2_mutable_subobject_is_odr_used_HasMutableMember { @@ -381,7 +420,7 @@ impl Clone for p5_2_mutable_subobject_is_odr_used_HasMutableMember { unsafe { let mut __v: p5_2_mutable_subobject_is_odr_used_HasMutableMember = ::zero_init(); - p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from( + CopyConstructibleUnsafe::copy_constructor( &mut __v, self as *const p5_2_mutable_subobject_is_odr_used_HasMutableMember, ); @@ -401,7 +440,7 @@ pub unsafe fn test_19() { let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = { let mut __v: p5_2_mutable_subobject_is_odr_used_HasMutableMember = ::zero_init(); - p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from(&mut __v, { &k }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &k }); __v }; }, @@ -415,34 +454,40 @@ pub unsafe fn test_19() { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, )] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { pub a: LifetimeTracked, pub b: LifetimeTracked, } -impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - pub unsafe fn copy_assign( +impl DestructibleUnsafe for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.b); + DestructibleUnsafe::destroy(&mut self.a); + } +} +impl CopyAssignableUnsafe for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + unsafe fn copy_assign( &mut self, _a0: *const p6_unevaluated_binding_needs_no_capture_HasTwoMembers, ) -> *mut p6_unevaluated_binding_needs_no_capture_HasTwoMembers { (unsafe { let _arg0: *const LifetimeTracked = &(*_a0).a; - LifetimeTracked::copy_assign(&mut self.a, _arg0) + CopyAssignableUnsafe::copy_assign(&mut self.a, _arg0) }); (unsafe { let _arg0: *const LifetimeTracked = &(*_a0).b; - LifetimeTracked::copy_assign(&mut self.b, _arg0) + CopyAssignableUnsafe::copy_assign(&mut self.b, _arg0) }); return &mut (*(self as *mut p6_unevaluated_binding_needs_no_capture_HasTwoMembers)); } } -impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.b); - DestructibleUnsafe::destroy(&raw mut self.a); - } -} pub unsafe fn test_20() { (unsafe { LifetimeTracked::reset() }); let mut p: p6_unevaluated_binding_needs_no_capture_HasTwoMembers = @@ -459,7 +504,7 @@ pub unsafe fn test_20() { }, }; let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let __decomp_21: *mut p6_unevaluated_binding_needs_no_capture_HasTwoMembers = &mut p; let mut f: FnPtr usize> = FnPtr:: usize>::new(|| -> usize { @@ -474,7 +519,7 @@ pub unsafe fn test_20() { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe, + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyConstructibleUnsafe, MovableUnsafe, )] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { pub x: LifetimeTracked, @@ -493,23 +538,25 @@ impl p7_member_access_captures_this_HasMemberUsedInLambda { } ); } - pub unsafe fn copy_assign( +} +impl DestructibleUnsafe for p7_member_access_captures_this_HasMemberUsedInLambda { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.x); + } +} +impl CopyAssignableUnsafe for p7_member_access_captures_this_HasMemberUsedInLambda { + unsafe fn copy_assign( &mut self, _a0: *const p7_member_access_captures_this_HasMemberUsedInLambda, ) -> *mut p7_member_access_captures_this_HasMemberUsedInLambda { (unsafe { let _arg0: *const LifetimeTracked = &(*_a0).x; - LifetimeTracked::copy_assign(&mut self.x, _arg0) + CopyAssignableUnsafe::copy_assign(&mut self.x, _arg0) }); self.n = (*_a0).n; return &mut (*(self as *mut p7_member_access_captures_this_HasMemberUsedInLambda)); } } -impl p7_member_access_captures_this_HasMemberUsedInLambda { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.x); - } -} impl Default for p7_member_access_captures_this_HasMemberUsedInLambda { fn default() -> Self { unsafe { @@ -525,7 +572,7 @@ pub unsafe fn test_22() { let mut c: p7_member_access_captures_this_HasMemberUsedInLambda = ::default(); let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut f: FnPtr i32> = (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&mut c) }); @@ -539,7 +586,13 @@ pub unsafe fn test_22() { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, )] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { pub x: LifetimeTracked, @@ -552,28 +605,30 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } }); } - pub unsafe fn copy_assign( +} +impl DestructibleUnsafe for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.x); + } +} +impl CopyAssignableUnsafe for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + unsafe fn copy_assign( &mut self, _a0: *const p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda, ) -> *mut p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { (unsafe { let _arg0: *const LifetimeTracked = &(*_a0).x; - LifetimeTracked::copy_assign(&mut self.x, _arg0) + CopyAssignableUnsafe::copy_assign(&mut self.x, _arg0) }); return &mut (*(self as *mut p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda)); } } -impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.x); - } -} pub unsafe fn test_23() { (unsafe { LifetimeTracked::reset() }); let mut c: p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda = ::default(); let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut f: FnPtr usize> = (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&mut c) }); @@ -604,7 +659,7 @@ pub unsafe fn test_26() { } pub static mut t_ctors_27: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { pub unsafe fn construct(&mut self) { @@ -637,7 +692,7 @@ pub unsafe fn test_28() { pub static mut ctor_calls_29: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } @@ -674,7 +729,16 @@ pub unsafe fn test_31() { } pub static mut m_ctors_32: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, +)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { pub unsafe fn construct(&mut self) { @@ -694,7 +758,16 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } @@ -823,6 +896,27 @@ unsafe impl p4_1_pure_virtual_without_definition_HasPureVirtual (*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_10)).prefix_inc(); } } +impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + unsafe fn destroy(&mut self) { + unreachable!( + "p9_destructor_not_potentially_invoked_HasUndefinedDestructor::destroy is never defined" + ) + } +} +impl CopyConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { + unsafe fn copy_constructor(&mut self, _: *const Self) { + unreachable!( + "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" + ) + } +} +impl CopyAssignableUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self { + unreachable!( + "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" + ) + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_0); std::cell::LazyCell::force(&*&raw const ctorCount_1); 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 6eac6ca310..596e18bd29 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 @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(8)] pub struct p13_3_member_reads_earlier_member_Pair { 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 dc48eed6d5..38e8c31df3 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 @@ -7,7 +7,17 @@ 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, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct p13_3_member_reads_earlier_member_Pair { pub first: i32, 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 a5e5f206a7..1f0581af39 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 @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct_2, value)] #[byte_size(4)] pub struct p1_template_constructor_from_own_type_Probe { 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 5cac9be66d..e8f37be34b 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 @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_into(i64, to_i64, mut_ptr)] #[byte_size(8)] pub struct p2_non_const_conversion_function_Gauge { 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 7ae7d0674b..9712fbd1eb 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 @@ -12,7 +12,17 @@ impl p1_template_constructor_from_own_type_Probe { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct_2, value)] pub struct p1_template_constructor_from_own_type_Probe { pub value: i32, 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 038852dc89..4bf4ef98d9 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 @@ -7,7 +7,17 @@ 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, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_into(i64, to_i64, mut_ptr)] pub struct p2_non_const_conversion_function_Gauge { pub value: i64, 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 3915204d7e..93b69a534b 100644 --- a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs @@ -6,13 +6,21 @@ 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, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { #[offset(0)] pub value: i32, } +impl MoveConstructible for p11_defaulted_move_constructor_is_trivial_MoveOnly { + fn move_constructor( + this: &Ptr, + _a0: Ptr, + ) { + field!((*this), value).write({ (*_a0.upgrade().deref()).value }); + } +} pub fn pass_0( object: p11_defaulted_move_constructor_is_trivial_MoveOnly, ) -> p11_defaulted_move_constructor_is_trivial_MoveOnly { @@ -22,9 +30,7 @@ pub fn pass_0( let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl::move_from(&__v.as_pointer(), { - object.as_pointer() - }); + MoveConstructible::move_constructor(&__v.as_pointer(), { object.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -70,7 +76,6 @@ fn main_0() -> i32 { } pub trait p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl { fn construct(&self, value: i32); - fn move_from(&self, _a0: Ptr); } impl p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl for Ptr @@ -78,8 +83,5 @@ impl p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl fn construct(&self, mut value: i32) { field!((*self), value).write(value); } - fn move_from(&self, _a0: Ptr) { - field!((*self), value).write({ (*_a0.upgrade().deref()).value }); - } } pub fn __cpp2rust_init_globals() {} 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 7b9a26b4bb..99e2b4b45b 100644 --- a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { pub value: i32, @@ -16,7 +16,9 @@ impl p11_defaulted_move_constructor_is_trivial_MoveOnly { pub unsafe fn construct(&mut self, mut value: i32) { (&raw mut self.value).write(value); } - pub unsafe fn move_from( +} +impl MoveConstructibleUnsafe for p11_defaulted_move_constructor_is_trivial_MoveOnly { + unsafe fn move_constructor( &mut self, _a0: *mut p11_defaulted_move_constructor_is_trivial_MoveOnly, ) { @@ -29,7 +31,7 @@ pub unsafe fn pass_0( return { let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = ::zero_init(); - p11_defaulted_move_constructor_is_trivial_MoveOnly::move_from(&mut __v, { &mut object }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut object }); __v }; } 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 f79f771bc7..2463097288 100644 --- a/tests/std/class/class.mem/out/refcount/class.free.rs +++ b/tests/std/class/class.mem/out/refcount/class.free.rs @@ -9,7 +9,18 @@ use std::rc::{Rc, Weak}; thread_local!( pub static allocations_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p1_allocation_function_is_static_Allocates {} impl p1_allocation_function_is_static_Allocates { @@ -46,7 +57,18 @@ pub fn test_1() { thread_local!( pub static deallocations_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p3_deallocation_function_is_static_Deallocates {} impl 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 5efab48289..658334d06e 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 @@ -14,7 +14,9 @@ pub fn minimum_1() -> i32 { } pub type anon_2 = u32; pub const anon_2_reserve: anon_2 = 30; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct p7_1_function_body_names_later_member_HasLaterMembers { #[offset(0)] @@ -43,7 +45,9 @@ thread_local!( thread_local!( pub static step_5: Value = Rc::new(RefCell::new(4)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { #[offset(0)] 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 c054dea9ca..38ed565fcf 100644 --- a/tests/std/class/class.mem/out/unsafe/class.free.rs +++ b/tests/std/class/class.mem/out/unsafe/class.free.rs @@ -8,7 +8,16 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p1_allocation_function_is_static_Allocates {} impl p1_allocation_function_is_static_Allocates { pub unsafe fn operator_new(mut size: usize) -> *mut ::libc::c_void { @@ -42,7 +51,16 @@ pub unsafe fn test_1() { pub static mut deallocations_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p3_deallocation_function_is_static_Deallocates {} impl p3_deallocation_function_is_static_Deallocates { pub unsafe fn operator_delete(mut ptr: *mut ::libc::c_void) { 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 6023773883..1c483add84 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 @@ -13,7 +13,9 @@ pub unsafe fn minimum_1() -> i32 { pub type anon_2 = u32; pub const anon_2_reserve: anon_2 = 30; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p7_1_function_body_names_later_member_HasLaterMembers { pub stock: i32, } @@ -46,7 +48,9 @@ pub unsafe fn test_3() { pub static mut step_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); pub static mut step_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { pub total: i32, } 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 7291632867..429b3a97c5 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 @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p6_2_zero_initialized_padding_Padded { #[offset(0)] @@ -14,7 +25,18 @@ pub struct p6_2_zero_initialized_padding_Padded { #[offset(4)] pub number: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p6_2_zero_initialized_padding_TailPadded { #[offset(0)] @@ -22,7 +44,18 @@ pub struct p6_2_zero_initialized_padding_TailPadded { #[offset(4)] pub letter: i8, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct p6_2_zero_initialized_padding_HoldsPadded { #[offset(0)] 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 2255e0a05e..443be25b98 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 @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { #[offset(0)] @@ -14,7 +25,9 @@ pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct p6_1_zero_initialized_pointer_to_member_HoldsSelector { #[offset(0)] @@ -111,7 +124,9 @@ pub fn test_12() { thread_local!( static counter_11: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(24)] pub struct p6_2_zero_initialized_class_Inner { #[offset(0)] @@ -122,7 +137,7 @@ pub struct p6_2_zero_initialized_class_Inner { #[byte_size(8)] pub pointer: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(96)] pub struct p6_2_zero_initialized_class_Outer { #[offset(0)] @@ -193,7 +208,7 @@ pub fn test_15() { ({ check_14((heap_outer).clone()) }); heap_outer.delete(); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct p6_3_zero_initialized_union_Number { #[offset(0)] @@ -230,7 +245,18 @@ pub fn test_17() { Rc::new(RefCell::new(::default())); assert!(((p6_3_zero_initialized_union_Number::integer(value_number.as_pointer()).read()) == 0)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p6_4_zero_initialized_array_Pair { #[offset(0)] @@ -334,7 +360,9 @@ pub fn test_21() { } heap_numbers.delete(); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { #[offset(0)] @@ -352,7 +380,9 @@ impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { #[offset(0)] @@ -374,7 +404,18 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { #[offset(0)] 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 cd2397ca8f..36f49890f4 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 @@ -7,19 +7,46 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p6_2_zero_initialized_padding_Padded { pub letter: libc::c_char, pub number: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p6_2_zero_initialized_padding_TailPadded { pub number: i32, pub letter: libc::c_char, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p6_2_zero_initialized_padding_HoldsPadded { pub letter: libc::c_char, pub inner: p6_2_zero_initialized_padding_Padded, 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 a8e664d1da..0257a1f952 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 @@ -7,13 +7,24 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p6_1_zero_initialized_pointer_to_member_HoldsSelector { pub selector: isize, } @@ -107,14 +118,32 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p6_2_zero_initialized_class_Inner { pub number: i32, pub real: f64, pub pointer: *mut i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p6_2_zero_initialized_class_Outer { pub letter: libc::c_char, pub inner: p6_2_zero_initialized_class_Inner, @@ -166,7 +195,9 @@ pub unsafe fn test_15() { }; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union p6_3_zero_initialized_union_Number { pub integer: i32, pub bytes: [libc::c_char; 8], @@ -185,7 +216,16 @@ pub unsafe fn test_17() { assert!(((value_number.integer) == (0))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p6_4_zero_initialized_array_Pair { pub first: i32, pub second: i32, @@ -275,7 +315,9 @@ pub unsafe fn test_21() { }; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { pub zeroed: i32, pub five: i32, @@ -291,7 +333,9 @@ impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } @@ -313,7 +357,16 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub number: i32, pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, 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 f7875ca5e8..f62ffefefc 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 @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(12)] pub struct p6_array_of_pointers_to_data_members_HasThreeInts { #[offset(0)] 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 4e7da1d1a3..20106a5a08 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 @@ -54,7 +54,9 @@ thread_local!( thread_local!( pub static step_10: Value = Rc::new(RefCell::new(4)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct p9_static_member_hides_namespace_variable_HasStaticStep { #[offset(0)] @@ -105,7 +107,18 @@ pub fn count_default_13() -> i32 { pub fn combine_14(mut first: i32, mut second: i32) -> i32 { return ((first * 100) + second); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Widget { @@ -132,7 +145,9 @@ thread_local!( ); pub type anon_16 = u32; pub const anon_16_kBonus: anon_16 = 5; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Account { #[offset(0)] @@ -221,7 +236,18 @@ pub fn test_17() { pub fn add_18(mut a: i32, mut b: i32) -> i32 { return (a + b); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] 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/refcount/dcl.mptr.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.mptr.rs index 815ad1c1cd..b55a188bb1 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,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(16)] pub struct p2_pointer_to_array_member_HasIntArray { #[offset(0)] @@ -40,7 +40,18 @@ pub fn test_0() { assert!(((array_elem!(obj.as_pointer(), elements, 1).read()) == 7)); assert!(({ (*obj.borrow()).before } == 1)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p2_pointer_to_data_member_HasTwoInts { #[offset(0)] @@ -68,7 +79,18 @@ pub fn test_1() { thread_local!( pub static pm_2: Value = Rc::new(RefCell::new(-1_isize)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p2_pointer_to_member_of_incomplete_class_CompletedLater { #[offset(0)] @@ -97,7 +119,18 @@ pub fn test_3() { == 4) ); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { #[offset(0)] @@ -105,7 +138,9 @@ 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)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[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 204a1d4fcc..fb656d70fc 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 @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p6_array_of_pointers_to_data_members_HasThreeInts { pub first: i32, pub second: 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 f14341b2a4..416419691f 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 @@ -54,7 +54,9 @@ pub unsafe fn test_8() { pub static mut step_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); pub static mut step_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p9_static_member_hides_namespace_variable_HasStaticStep { pub total: i32, } @@ -105,7 +107,16 @@ pub unsafe fn combine_14(mut first: i32, mut second: i32) -> i32 { return (((first) * (100)) + (second)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, +)] #[cpp_from(i32, construct, value)] pub struct p9_evaluated_each_time_called_Widget { pub id: i32, @@ -133,7 +144,9 @@ static mut base_15: std::cell::LazyCell = std::cell::LazyCell::new(|| unsaf pub type anon_16 = u32; pub const anon_16_kBonus: anon_16 = 5; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p9_evaluated_each_time_called_Account { pub balance: i32, } @@ -227,7 +240,16 @@ pub unsafe fn add_18(mut a: i32, mut b: i32) -> i32 { return ((a) + (b)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p9_not_part_of_the_type_Scale {} impl p9_not_part_of_the_type_Scale { pub unsafe fn times(mut a: i32, mut b: i32) -> i32 { 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 27a87e5ea3..323a5e53dd 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 @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p2_pointer_to_array_member_HasIntArray { pub before: i32, pub elements: [i32; 3], @@ -38,7 +47,16 @@ pub unsafe fn test_0() { assert!(((obj.before) == (1))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p2_pointer_to_data_member_HasTwoInts { pub first: i32, pub second: i32, @@ -76,7 +94,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p2_pointer_to_member_of_incomplete_class_CompletedLater { pub first: i32, pub second: i32, @@ -100,13 +127,24 @@ pub unsafe fn test_3() { ); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] 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 74a595f022..e4244a961a 100644 --- a/tests/std/expr/conv/out/refcount/conv.mem.rs +++ b/tests/std/expr/conv/out/refcount/conv.mem.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p1_null_distinct_from_first_member_HasTwoInts { #[offset(0)] diff --git a/tests/std/expr/conv/out/unsafe/conv.mem.rs b/tests/std/expr/conv/out/unsafe/conv.mem.rs index 0c8703d9e1..203929dd10 100644 --- a/tests/std/expr/conv/out/unsafe/conv.mem.rs +++ b/tests/std/expr/conv/out/unsafe/conv.mem.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p1_null_distinct_from_first_member_HasTwoInts { pub first: i32, pub second: 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 82485c58d0..dc1677da4e 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 @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct p4_reference_const_cast_Pair { #[offset(0)] 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 36e1b8a0b8..904ef402d2 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 @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct HasTwoInts { #[offset(0)] @@ -14,7 +25,18 @@ pub struct HasTwoInts { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct AlsoHasTwoInts { #[offset(0)] 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 e0ee6af6db..9d03378a52 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 @@ -16,7 +16,18 @@ pub fn test_0() { (*value.borrow_mut()) = 7; assert!((((converted.read()).read()) == 7)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p10_null_converts_to_null_HasTwoInts { #[offset(0)] @@ -24,7 +35,18 @@ pub struct p10_null_converts_to_null_HasTwoInts { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p10_null_converts_to_null_HasChar { #[offset(0)] @@ -35,7 +57,18 @@ pub fn test_1() { let mut converted: isize = pm; assert!(((converted) == -1_isize)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p10_2_data_member_round_trip_HasTwoInts { #[offset(0)] @@ -43,7 +76,18 @@ pub struct p10_2_data_member_round_trip_HasTwoInts { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p10_2_data_member_round_trip_HasChar { #[offset(0)] 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 106cbcb48c..1df476df5c 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 @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 19f5758fbf..ce31f7bc5f 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 @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct HasTwoInts { pub first: i32, pub second: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct AlsoHasTwoInts { pub first: i32, pub second: 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 712dee1955..343354726f 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 @@ -17,13 +17,31 @@ pub unsafe fn test_0() { assert!(((*(*converted)) == (7))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p10_null_converts_to_null_HasTwoInts { pub first: i32, pub second: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p10_null_converts_to_null_HasChar { pub character: libc::c_char, } @@ -33,13 +51,31 @@ pub unsafe fn test_1() { assert!(((converted) == -1_isize)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p10_2_data_member_round_trip_HasTwoInts { pub first: i32, pub second: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 5abe461cf4..84324b3a78 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 @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct p1_result_is_updated_operand_Counter { #[offset(0)] 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 b597866a64..e74703caa0 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 @@ -12,7 +12,18 @@ thread_local!( thread_local!( pub static calls_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p3_2_static_member_is_ordinary_pointer_HasStaticMembers {} impl p3_2_static_member_is_ordinary_pointer_HasStaticMembers { @@ -30,7 +41,18 @@ pub fn test_2() { ({ function_pointer.call() }); assert!((calls_1.with(|rc| *rc.borrow()) == 1)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { #[offset(0)] @@ -46,7 +68,18 @@ pub fn test_3() { (*object.borrow_mut()).base = 5; assert!((({ function_pointer.call(object.as_pointer(), 1,) }) == 6)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { #[offset(0)] 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 2e68a582ca..7d9a6d05ed 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 @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 5e194343d7..fb74001edb 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 @@ -9,7 +9,16 @@ use std::rc::Rc; pub static mut shared_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); pub static mut calls_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p3_2_static_member_is_ordinary_pointer_HasStaticMembers {} impl p3_2_static_member_is_ordinary_pointer_HasStaticMembers { pub unsafe fn run() { @@ -28,7 +37,16 @@ pub unsafe fn test_2() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_1)) == (1))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { pub base: i32, } @@ -54,7 +72,16 @@ pub unsafe fn test_3() { assert!(((unsafe { (function_pointer).unwrap()(&object, 1,) }) == (6))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 d0cf7c81d8..306f13b18e 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.cond.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.cond.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p7_4_pointer_to_member_and_null_HasTwoInts { #[offset(0)] 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 2e7cca7b6a..ee222e9dcf 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.eq.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.eq.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p4_1_both_null_HasTwoInts { #[offset(0)] @@ -20,7 +31,18 @@ pub fn test_0() { assert!((first_null == second_null)); assert!(!(first_null != second_null)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p4_2_one_null_HasTwoInts { #[offset(0)] @@ -36,7 +58,7 @@ pub fn test_1() { assert!((null_pm != first_pm)); assert!(!(null_pm == first_pm)); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct p4_5_members_of_same_union_HasTwoIntMembers { #[offset(0)] @@ -65,7 +87,18 @@ pub fn test_2() { assert!((first_pm == second_pm)); assert!(!(first_pm != second_pm)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p4_6_data_members_HasTwoInts { #[offset(0)] 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 58dba1bf76..f44da5d369 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 @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct HasTwoInts { #[offset(0)] 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 818abc1fc9..ebfd834ff9 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 @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p3_arrow_star_HasTwoInts { #[offset(0)] @@ -27,7 +38,18 @@ pub fn test_0() { assert!(({ (*obj.borrow()).first } == 3)); assert!((((p).member::(pm)) == ((p).member::(pm)))); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct p4_object_expression_sequenced_first_HasValue { #[offset(0)] @@ -69,7 +91,18 @@ pub fn test_7() { assert!((object_stamp_2.with(|rc| *rc.borrow()) == 1)); assert!((member_stamp_3.with(|rc| *rc.borrow()) == 2)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { #[offset(0)] @@ -98,9 +131,36 @@ thread_local!( thread_local!( pub static moveCount_10: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[byte_size(1)] pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} +impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { + fn copy_constructor( + this: &Ptr, + _a0: Ptr, + ) { + (*copyCount_9.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl MoveConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { + fn move_constructor( + this: &Ptr, + _a0: Ptr, + ) { + (*moveCount_10.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl Clone for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { fn clone(&self) -> Self { let __src: Value = Rc::new( @@ -109,20 +169,45 @@ impl Clone for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMovesImpl::copy_from( - &__v.as_pointer(), - __src.as_pointer(), - ); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[byte_size(1)] pub struct p6_data_member_of_rvalue_is_xvalue_HoldsCounted { #[offset(0)] #[byte_size(1)] pub member: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, } +impl MoveConstructible for p6_data_member_of_rvalue_is_xvalue_HoldsCounted { + fn move_constructor( + this: &Ptr, + _a0: Ptr, + ) { + field!((*this), member).write({ + let __v: Value = + Rc::new(RefCell::new( + ::zero_init(), + )); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, member) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + } +} pub fn test_11() { let mut pm: isize = (offset_of_field!(p6_data_member_of_rvalue_is_xvalue_HoldsCounted, member) as isize); @@ -133,13 +218,10 @@ pub fn test_11() { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMovesImpl::copy_from( - &__v.as_pointer(), - { - (holder.as_pointer()) - .member::(pm) - }, - ); + CopyConstructible::copy_constructor(&__v.as_pointer(), { + (holder.as_pointer()) + .member::(pm) + }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((copyCount_9.with(|rc| *rc.borrow()) == 1)); @@ -148,13 +230,10 @@ pub fn test_11() { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMovesImpl::move_from( - &__v.as_pointer(), - { - (holder.as_pointer()) - .member::(pm) - }, - ); + MoveConstructible::move_constructor(&__v.as_pointer(), { + (holder.as_pointer()) + .member::(pm) + }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((copyCount_9.with(|rc| *rc.borrow()) == 1)); @@ -171,40 +250,6 @@ fn main_0() -> i32 { ({ test_11() }); return 0; } -pub trait p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMovesImpl { - fn copy_from(&self, _a0: Ptr); - fn move_from(&self, _a0: Ptr); -} -impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMovesImpl - for Ptr -{ - fn copy_from(&self, _a0: Ptr) { - (*copyCount_9.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn move_from(&self, _a0: Ptr) { - (*moveCount_10.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p6_data_member_of_rvalue_is_xvalue_HoldsCountedImpl { - fn move_from(&self, _a0: Ptr); -} -impl p6_data_member_of_rvalue_is_xvalue_HoldsCountedImpl - for Ptr -{ - fn move_from(&self, _a0: Ptr) { - field!((*self), member).write({ - let __v: Value = - Rc::new(RefCell::new( - ::zero_init(), - )); - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMovesImpl::move_from( - &__v.as_pointer(), - { field_ptr!(_a0, member) }, - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - } -} pub fn __cpp2rust_init_globals() { let _ = sequence_1.with(|_| ()); let _ = object_stamp_2.with(|_| ()); 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 892aa79d43..c75bd283b4 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.cond.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.cond.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p7_4_pointer_to_member_and_null_HasTwoInts { pub first: i32, pub second: 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 c388d066f0..dc14f74efd 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.eq.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.eq.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p4_1_both_null_HasTwoInts { pub first: i32, pub second: i32, @@ -19,7 +28,16 @@ pub unsafe fn test_0() { assert!(!((first_null) != (second_null))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p4_2_one_null_HasTwoInts { pub first: i32, pub second: i32, @@ -33,7 +51,9 @@ pub unsafe fn test_1() { assert!(!((null_pm) == (first_pm))); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union p4_5_members_of_same_union_HasTwoIntMembers { pub first: i32, pub second: i32, @@ -50,7 +70,16 @@ pub unsafe fn test_2() { assert!(!((first_pm) != (second_pm))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p4_6_data_members_HasTwoInts { pub first: i32, pub second: 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 7f8464f86b..c52cd320d1 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 @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct HasTwoInts { pub first: i32, pub second: 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 2a1e254a13..a565cb70ea 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 @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p3_arrow_star_HasTwoInts { pub first: i32, pub second: i32, @@ -31,7 +40,16 @@ pub unsafe fn test_0() { ); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p4_object_expression_sequenced_first_HasValue { pub value: i32, } @@ -65,7 +83,16 @@ pub unsafe fn test_7() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut member_stamp_3)) == (2))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { pub first: i32, pub second: i32, @@ -94,16 +121,27 @@ pub unsafe fn test_8() { pub static mut copyCount_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moveCount_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} -impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { - pub unsafe fn copy_from( +impl CopyConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { + unsafe fn copy_constructor( &mut self, _a0: *const p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, ) { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)).prefix_inc(); } - pub unsafe fn move_from( +} +impl MoveConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { + unsafe fn move_constructor( &mut self, _a0: *mut p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, ) { @@ -115,7 +153,7 @@ impl Clone for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { unsafe { let mut __v: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = ::zero_init(); - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::copy_from( + CopyConstructibleUnsafe::copy_constructor( &mut __v, self as *const p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, ); @@ -124,18 +162,30 @@ impl Clone for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] pub struct p6_data_member_of_rvalue_is_xvalue_HoldsCounted { pub member: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, } -impl p6_data_member_of_rvalue_is_xvalue_HoldsCounted { - pub unsafe fn move_from(&mut self, _a0: *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) { +impl MoveConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_HoldsCounted { + unsafe fn move_constructor( + &mut self, + _a0: *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted, + ) { (&raw mut self.member).write({ let mut __v: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = ::zero_init(); - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::move_from(&mut __v, { - &mut (*_a0).member - }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).member }); __v }); } @@ -148,7 +198,7 @@ pub unsafe fn test_11() { let mut from_lvalue: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = { let mut __v: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = ::zero_init(); - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::copy_from(&mut __v, { + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) .wrapping_byte_offset(pm) .cast::()) @@ -160,7 +210,7 @@ pub unsafe fn test_11() { let mut from_xvalue: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = { let mut __v: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = ::zero_init(); - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::move_from(&mut __v, { + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) .wrapping_byte_offset(pm) .cast::()) diff --git a/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs b/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs index 27248df28a..649629304e 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 @@ -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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Copyable, +)] #[cpp_from(i32, construct, value)] #[byte_size(16)] pub struct p1_default_member_initializer_names_object_Holder { @@ -31,7 +33,18 @@ pub fn test_0() { }; assert!((holder.value == 4)); } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(16)] pub struct p1_mem_initializer_names_object_Holder { 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 1091720b88..47bc9597e7 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 @@ -7,7 +7,16 @@ 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, CppFromUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, +)] #[cpp_from(i32, construct, value)] pub struct p1_default_member_initializer_names_object_Holder { pub self_: *mut p1_default_member_initializer_names_object_Holder, @@ -37,7 +46,17 @@ pub unsafe fn test_0() { assert!(((holder.value) == (4))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct p1_mem_initializer_names_object_Holder { pub self_: *mut p1_mem_initializer_names_object_Holder, 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 25d3d46062..1dec3736c0 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 @@ -6,10 +6,23 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int___rebind_std_pair_const_int__int__ {} -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { #[offset(0)] @@ -43,7 +56,18 @@ pub fn test_0() { ); assert!(({ ((*n.borrow()).len() == 1_usize) })); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p18_rebind_to_container_node_Alloc_std_pair_const_int__int__ {} pub fn test_1() { 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 b3c39ca5b6..2368ba1774 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 @@ -7,10 +7,21 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int___rebind_std_pair_const_int__int__ {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { pub id: i32, } @@ -30,7 +41,16 @@ pub unsafe fn test_0() { assert!(((n.len()) == (1_usize))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p18_rebind_to_container_node_Alloc_std_pair_const_int__int__ {} pub unsafe fn test_1() { let mut m: UnsafeMap = UnsafeMap::new(); 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 32eb159e55..c5d95fb531 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 @@ -13,7 +13,7 @@ thread_local!( pub static dtorCount_1: Value = Rc::new(RefCell::new(0)); ); #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Default, + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -21,6 +21,11 @@ pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { #[offset(0)] pub value: i32, } +impl Destructible for p2_condition_variable_created_each_iteration_ConvertsToBool { + fn destroy(this: &Ptr) { + (*dtorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} pub fn test_2() { let mut remaining: i32 = 2; let mut iterations: i32 = 0; @@ -38,7 +43,7 @@ pub fn test_2() { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); if !({ p2_condition_variable_created_each_iteration_ConvertsToBoolImpl::to_bool( @@ -64,7 +69,7 @@ thread_local!( pub static dtorCount_4: Value = Rc::new(RefCell::new(0)); ); #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Default, + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -72,6 +77,11 @@ pub struct p2_continue_destroys_condition_variable_ConvertsToBool { #[offset(0)] pub value: i32, } +impl Destructible for p2_continue_destroys_condition_variable_ConvertsToBool { + fn destroy(this: &Ptr) { + (*dtorCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + } +} pub fn test_5() { let mut remaining: i32 = 3; let mut continued: i32 = 0; @@ -90,7 +100,7 @@ pub fn test_5() { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); if !({ p2_continue_destroys_condition_variable_ConvertsToBoolImpl::to_bool( @@ -126,7 +136,6 @@ fn main_0() -> i32 { } pub trait p2_condition_variable_created_each_iteration_ConvertsToBoolImpl { fn construct(&self, value: i32); - fn destructor(&self); fn to_bool(&self) -> bool; } impl p2_condition_variable_created_each_iteration_ConvertsToBoolImpl @@ -136,16 +145,12 @@ impl p2_condition_variable_created_each_iteration_ConvertsToBoolImpl field!((*self), value).write(value); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn destructor(&self) { - (*dtorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } fn to_bool(&self) -> bool { return ((*self).with(|__s| __s.value) != 0); } } pub trait p2_continue_destroys_condition_variable_ConvertsToBoolImpl { fn construct(&self, value: i32); - fn destructor(&self); fn to_bool(&self) -> bool; } impl p2_continue_destroys_condition_variable_ConvertsToBoolImpl @@ -155,9 +160,6 @@ impl p2_continue_destroys_condition_variable_ConvertsToBoolImpl field!((*self), value).write(value); (*ctorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn destructor(&self) { - (*dtorCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - } fn to_bool(&self) -> bool { return ((*self).with(|__s| __s.value) != 0); } 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 57d7121ea3..3cc778ea4d 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 @@ -10,7 +10,7 @@ pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default, + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, )] #[cpp_from(i32, construct, value)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { @@ -21,13 +21,15 @@ impl p2_condition_variable_created_each_iteration_ConvertsToBool { (&raw mut self.value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_1)).prefix_inc(); - } pub unsafe fn to_bool(&self) -> bool { return ((self.value) != (0)); } } +impl DestructibleUnsafe for p2_condition_variable_created_each_iteration_ConvertsToBool { + unsafe fn destroy(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_1)).prefix_inc(); + } +} pub unsafe fn test_2() { let mut remaining: i32 = 2; let mut iterations: i32 = 0; @@ -41,7 +43,7 @@ pub unsafe fn test_2() { __v }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); if !(unsafe { p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool(&condition) @@ -64,7 +66,7 @@ pub static mut ctorCount_3: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default, + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, )] #[cpp_from(i32, construct, value)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { @@ -75,13 +77,15 @@ impl p2_continue_destroys_condition_variable_ConvertsToBool { (&raw mut self.value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_3)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_4)).prefix_inc(); - } pub unsafe fn to_bool(&self) -> bool { return ((self.value) != (0)); } } +impl DestructibleUnsafe for p2_continue_destroys_condition_variable_ConvertsToBool { + unsafe fn destroy(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_4)).prefix_inc(); + } +} pub unsafe fn test_5() { let mut remaining: i32 = 3; let mut continued: i32 = 0; @@ -96,7 +100,7 @@ pub unsafe fn test_5() { __v }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); if !(unsafe { p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(&condition) }) { 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 9beda4a205..6c811cd0f4 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Movable)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +44,30 @@ impl LifetimeTracked { }); } } +impl CopyConstructible for LifetimeTracked { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), uses).write(0); + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for LifetimeTracked { + fn destroy(this: &Ptr) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for LifetimeTracked { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), uses).write(_a0.with(|__s| __s.uses)); + return (*this).clone(); + } +} impl Clone for LifetimeTracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -81,8 +98,9 @@ pub fn test_6() { LifetimeTrackedImpl::construct(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - let _dtor_guard = - std::mem::DropGuard::new(guard.clone(), |__p| Destructible::destroy(__p.as_pointer())); + let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| { + Destructible::destroy(&__p.as_pointer()) + }); let mut choice: i32 = 0; if (choice != 0) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -103,8 +121,9 @@ pub fn test_6() { LifetimeTrackedImpl::construct(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - let _dtor_guard = - std::mem::DropGuard::new(guard.clone(), |__p| Destructible::destroy(__p.as_pointer())); + let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| { + Destructible::destroy(&__p.as_pointer()) + }); let mut choice: i32 = 4; if (choice != 0) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -200,33 +219,19 @@ fn main_0() -> i32 { } pub trait LifetimeTrackedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn destructor(&self); fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl LifetimeTrackedImpl for Ptr { fn construct(&self) { field!((*self), uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), uses).write(0); - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write(_a0.with(|__s| __s.uses)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); 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 7fa6a24aba..6ca3a182b8 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Movable)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +44,30 @@ impl LifetimeTracked { }); } } +impl CopyConstructible for LifetimeTracked { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), uses).write(0); + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for LifetimeTracked { + fn destroy(this: &Ptr) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for LifetimeTracked { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), uses).write(_a0.with(|__s| __s.uses)); + return (*this).clone(); + } +} impl Clone for LifetimeTracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - LifetimeTrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -76,7 +93,7 @@ thread_local!( pub static dtorCount_6: Value = Rc::new(RefCell::new(0)); ); #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Default, + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, )] #[cpp_into(i32, to_i32)] #[byte_size(4)] @@ -84,6 +101,11 @@ pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { #[offset(0)] pub value: i32, } +impl Destructible for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + fn destroy(this: &Ptr) { + (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); + } +} pub fn test_7() { { let selector: Value = @@ -91,7 +113,7 @@ pub fn test_7() { p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }, )); let _dtor_selector = std::mem::DropGuard::new(selector.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); 'switch: { match { @@ -133,8 +155,9 @@ pub fn test_10() { LifetimeTrackedImpl::construct(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - let _dtor_guard = - std::mem::DropGuard::new(guard.clone(), |__p| Destructible::destroy(__p.as_pointer())); + let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| { + Destructible::destroy(&__p.as_pointer()) + }); let mut selector: i32 = 2; 'switch: { match { selector } { @@ -207,37 +230,22 @@ fn main_0() -> i32 { } pub trait LifetimeTrackedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn destructor(&self); fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl LifetimeTrackedImpl for Ptr { fn construct(&self) { field!((*self), uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), uses).write(0); - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } fn use_(&self) { field!((*self), uses).with_mut(|__v| { __v.prefix_inc(); }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write(_a0.with(|__s| __s.uses)); - return (*self).clone(); - } } pub trait p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl { fn to_i32(&self) -> i32; - fn destructor(&self); } impl p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl for Ptr @@ -245,9 +253,6 @@ impl p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl fn to_i32(&self) -> i32 { return (*self).with(|__s| __s.value); } - fn destructor(&self) { - (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); - } } pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); 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 b5b0a0df24..4390692e96 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MovableUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,18 +32,24 @@ impl LifetimeTracked { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, _a0: *const LifetimeTracked) { + 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 CopyConstructibleUnsafe for LifetimeTracked { + unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for LifetimeTracked { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).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(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { +} +impl CopyAssignableUnsafe for LifetimeTracked { + unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { self.uses = (*_a0).uses; return &mut (*(self as *mut LifetimeTracked)); } @@ -52,7 +58,7 @@ impl Clone for LifetimeTracked { fn clone(&self) -> Self { unsafe { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, self as *const LifetimeTracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const LifetimeTracked); __v } } @@ -82,7 +88,7 @@ pub unsafe fn test_6() { __v }; let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut choice: i32 = 0; if (choice != 0) { @@ -105,7 +111,7 @@ pub unsafe fn test_6() { __v }; let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut choice: i32 = 4; if (choice != 0) { 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 4455608afe..d612c4f475 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MovableUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,18 +32,24 @@ impl LifetimeTracked { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, _a0: *const LifetimeTracked) { + 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 CopyConstructibleUnsafe for LifetimeTracked { + unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for LifetimeTracked { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).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(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { +} +impl CopyAssignableUnsafe for LifetimeTracked { + unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { self.uses = (*_a0).uses; return &mut (*(self as *mut LifetimeTracked)); } @@ -52,7 +58,7 @@ impl Clone for LifetimeTracked { fn clone(&self) -> Self { unsafe { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, self as *const LifetimeTracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const LifetimeTracked); __v } } @@ -75,7 +81,7 @@ pub static mut other_case_runs_5: std::cell::LazyCell = pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default, + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, )] #[cpp_into(i32, to_i32)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { @@ -85,7 +91,9 @@ impl p2_condition_variable_lives_for_whole_statement_ConvertsToInt { pub unsafe fn to_i32(&self) -> i32 { return self.value; } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); } } @@ -94,7 +102,7 @@ pub unsafe fn test_7() { let mut selector: p2_condition_variable_lives_for_whole_statement_ConvertsToInt = p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }; let _dtor_selector = std::mem::DropGuard::new(&raw mut selector, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); 'switch: { match { @@ -135,7 +143,7 @@ pub unsafe fn test_10() { __v }; let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut selector: i32 = 2; 'switch: { diff --git a/tests/std/temp/out/refcount/temp.type.rs b/tests/std/temp/out/refcount/temp.type.rs index ea929ef43c..a8738251f0 100644 --- a/tests/std/temp/out/refcount/temp.type.rs +++ b/tests/std/temp/out/refcount/temp.type.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p2_6_pointer_to_member_argument_HasTwoInts { #[offset(0)] @@ -17,21 +28,54 @@ pub struct p2_6_pointer_to_member_argument_HasTwoInts { thread_local!( pub static count_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_refp2_6_pointer_to_member_argument_HasTwoInts_first_ {} thread_local!( pub static count_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_refp2_6_pointer_to_member_argument_HasTwoInts_second_ {} thread_local!( pub static count_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_nullptr_ {} pub fn test_3() { diff --git a/tests/std/temp/out/unsafe/temp.type.rs b/tests/std/temp/out/unsafe/temp.type.rs index 8b23294894..49a9571e4a 100644 --- a/tests/std/temp/out/unsafe/temp.type.rs +++ b/tests/std/temp/out/unsafe/temp.type.rs @@ -7,24 +7,60 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p2_6_pointer_to_member_argument_HasTwoInts { pub first: i32, pub second: i32, } pub static mut count_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_nullptr_ {} pub unsafe fn test_3() { (*std::cell::LazyCell::force_mut(&mut *&raw mut count_0)).prefix_inc(); 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 2eab60289a..816a67c4a4 100644 --- a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/refcount/temp.inst.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct p2_reference_does_not_instantiate_Member { #[offset(0)] @@ -17,13 +19,18 @@ impl Default for p2_reference_does_not_instantiate_Member { { p2_reference_does_not_instantiate_Member { value: 1 } } } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct p2_reference_does_not_instantiate_Holder { #[offset(0)] #[byte_size(4)] pub member: p2_reference_does_not_instantiate_Member, } +impl MoveConstructible for p2_reference_does_not_instantiate_Holder { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), member).write({ (*_a0.upgrade().deref()).member }); + } +} pub fn test_0() { let mut holder: p2_reference_does_not_instantiate_Holder = ::default(); @@ -42,16 +49,6 @@ fn main_0() -> i32 { #[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] #[byte_size(1)] pub struct p2_reference_does_not_instantiate_Wrapper_int_; -pub trait p2_reference_does_not_instantiate_HolderImpl { - fn move_from(&self, _a0: Ptr); -} -impl p2_reference_does_not_instantiate_HolderImpl - for Ptr -{ - fn move_from(&self, _a0: Ptr) { - field!((*self), member).write({ (*_a0.upgrade().deref()).member }); - } -} pub trait p2_reference_does_not_instantiate_MemberImpl { fn construct_1(&self, _a0: Ptr); } 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 34ca7bfd39..c3983b5c7c 100644 --- a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/unsafe/temp.inst.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct p2_reference_does_not_instantiate_Member { pub value: i32, } @@ -25,12 +27,12 @@ impl Default for p2_reference_does_not_instantiate_Member { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } -impl p2_reference_does_not_instantiate_Holder { - pub unsafe fn move_from(&mut self, _a0: *mut p2_reference_does_not_instantiate_Holder) { +impl MoveConstructibleUnsafe for p2_reference_does_not_instantiate_Holder { + unsafe fn move_constructor(&mut self, _a0: *mut p2_reference_does_not_instantiate_Holder) { (&raw mut self.member).write((*_a0).member); } } diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 2a9f1c97a5..9a3935df25 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -14,13 +14,36 @@ pub fn test_0() { lvalue.write(2); assert!(({ ((*value.borrow()) == 2) })); } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p6_forward_like_Movable { #[offset(0)] pub value: i32, } +impl CopyConstructible for p6_forward_like_Movable { + fn copy_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + } +} +impl MoveConstructible for p6_forward_like_Movable { + fn move_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + field!(other, value).write(0); + } +} impl Clone for p6_forward_like_Movable { fn clone(&self) -> Self { let __src: Value = @@ -29,17 +52,39 @@ impl Clone for p6_forward_like_Movable { })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - p6_forward_like_MovableImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + MoveAssignable, + Swappable, +)] #[byte_size(4)] pub struct p6_forward_like_Holder { #[offset(0)] #[byte_size(4)] pub member: p6_forward_like_Movable, } +impl MoveConstructible for p6_forward_like_Holder { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), member).write({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, member) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + } +} impl Default for p6_forward_like_Holder { fn default() -> Self { { @@ -58,7 +103,7 @@ pub fn take_1(self_: Ptr) -> p6_forward_like_Movable { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - p6_forward_like_MovableImpl::copy_from(&__v.as_pointer(), { field_ptr!(self_, member) }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { field_ptr!(self_, member) }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -66,7 +111,7 @@ pub fn take_2(self_: Ptr) -> p6_forward_like_Movable { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - p6_forward_like_MovableImpl::move_from(&__v.as_pointer(), { field_ptr!(self_, member) }); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(self_, member) }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -78,13 +123,19 @@ pub fn test_3() { let mut moved: p6_forward_like_Movable = ({ take_2(holder.as_pointer()) }); assert!((moved.value == 1) && ({ (*holder.borrow()).member.value } == 0)); } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p9_move_Movable { #[offset(0)] pub value: i32, } +impl MoveConstructible for p9_move_Movable { + fn move_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + field!(other, value).write(0); + } +} pub fn test_4() { let mut number: i32 = 1; let mut moved: i32 = number; @@ -103,7 +154,7 @@ pub fn test_4() { })); let mut destination: p9_move_Movable = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - p9_move_MovableImpl::move_from(&__v.as_pointer(), { source.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { source.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((destination.value == 3) && ({ (*source.borrow()).value } == 0)); @@ -129,7 +180,18 @@ pub fn test_4() { }) ); } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct p10_forward_in_template_A { @@ -140,6 +202,21 @@ pub struct p10_forward_in_template_A { #[offset(8)] pub moves: i32, } +impl CopyConstructible for p10_forward_in_template_A { + fn copy_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + field!((*this), copies).write((other.with(|__s| __s.copies) + 1)); + field!((*this), moves).write(0); + } +} +impl MoveConstructible for p10_forward_in_template_A { + fn move_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + field!((*this), copies).write(0); + field!((*this), moves).write((other.with(|__s| __s.moves) + 1)); + field!(other, value).write(0); + } +} impl Clone for p10_forward_in_template_A { fn clone(&self) -> Self { let __src: Value = @@ -150,7 +227,7 @@ impl Clone for p10_forward_in_template_A { })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - p10_forward_in_template_AImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -163,7 +240,7 @@ pub fn make_5(source: Ptr) -> p10_forward_in_template return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - p10_forward_in_template_AImpl::copy_from(&__v.as_pointer(), { (source).clone() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { (source).clone() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -171,7 +248,7 @@ pub fn make_6(source: Ptr) -> p10_forward_in_template return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - p10_forward_in_template_AImpl::move_from(&__v.as_pointer(), { (source).clone() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { (source).clone() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -189,13 +266,36 @@ pub fn test_7() { assert!(((moved.value == 1) && (moved.copies == 0)) && (moved.moves == 1)); assert!(({ (*a.borrow()).value } == 0)); } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p11_move_if_noexcept_NoexceptMove { #[offset(0)] pub value: i32, } +impl CopyConstructible for p11_move_if_noexcept_NoexceptMove { + fn copy_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + } +} +impl MoveConstructible for p11_move_if_noexcept_NoexceptMove { + fn move_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + field!(other, value).write(0); + } +} impl Clone for p11_move_if_noexcept_NoexceptMove { fn clone(&self) -> Self { let __src: Value = @@ -205,17 +305,40 @@ impl Clone for p11_move_if_noexcept_NoexceptMove { let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - p11_move_if_noexcept_NoexceptMoveImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p11_move_if_noexcept_ThrowingMove { #[offset(0)] pub value: i32, } +impl CopyConstructible for p11_move_if_noexcept_ThrowingMove { + fn copy_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + } +} +impl MoveConstructible for p11_move_if_noexcept_ThrowingMove { + fn move_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + field!(other, value).write(0); + } +} impl Clone for p11_move_if_noexcept_ThrowingMove { fn clone(&self) -> Self { let __src: Value = @@ -225,7 +348,7 @@ impl Clone for p11_move_if_noexcept_ThrowingMove { let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - p11_move_if_noexcept_ThrowingMoveImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -241,9 +364,7 @@ pub fn test_8() { let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - p11_move_if_noexcept_NoexceptMoveImpl::move_from(&__v.as_pointer(), { - moved_from.as_pointer() - }); + MoveConstructible::move_constructor(&__v.as_pointer(), { moved_from.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((moved.value == 1) && ({ (*moved_from.borrow()).value } == 0)); @@ -258,9 +379,7 @@ pub fn test_8() { let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - p11_move_if_noexcept_ThrowingMoveImpl::copy_from(&__v.as_pointer(), { - copied_from.as_pointer() - }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { copied_from.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((copied.value == 2) && ({ (*copied_from.borrow()).value } == 2)); @@ -279,8 +398,6 @@ fn main_0() -> i32 { } pub trait p10_forward_in_template_AImpl { fn construct(&self, value: i32); - fn copy_from(&self, other: Ptr); - fn move_from(&self, other: Ptr); } impl p10_forward_in_template_AImpl for Ptr { fn construct(&self, mut value: i32) { @@ -288,93 +405,37 @@ impl p10_forward_in_template_AImpl for Ptr { field!((*self), copies).write(0); field!((*self), moves).write(0); } - fn copy_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - field!((*self), copies).write((other.with(|__s| __s.copies) + 1)); - field!((*self), moves).write(0); - } - fn move_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - field!((*self), copies).write(0); - field!((*self), moves).write((other.with(|__s| __s.moves) + 1)); - field!(other, value).write(0); - } } pub trait p11_move_if_noexcept_NoexceptMoveImpl { fn construct(&self, value: i32); - fn copy_from(&self, other: Ptr); - fn move_from(&self, other: Ptr); } impl p11_move_if_noexcept_NoexceptMoveImpl for Ptr { fn construct(&self, mut value: i32) { field!((*self), value).write(value); } - fn copy_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - } - fn move_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - field!(other, value).write(0); - } } pub trait p11_move_if_noexcept_ThrowingMoveImpl { fn construct(&self, value: i32); - fn copy_from(&self, other: Ptr); - fn move_from(&self, other: Ptr); } impl p11_move_if_noexcept_ThrowingMoveImpl for Ptr { fn construct(&self, mut value: i32) { field!((*self), value).write(value); } - fn copy_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - } - fn move_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - field!(other, value).write(0); - } -} -pub trait p6_forward_like_HolderImpl { - fn move_from(&self, _a0: Ptr); -} -impl p6_forward_like_HolderImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), member).write({ - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - p6_forward_like_MovableImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, member) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - } } pub trait p6_forward_like_MovableImpl { fn construct(&self, value: i32); - fn copy_from(&self, other: Ptr); - fn move_from(&self, other: Ptr); } impl p6_forward_like_MovableImpl for Ptr { fn construct(&self, mut value: i32) { field!((*self), value).write(value); } - fn copy_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - } - fn move_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - field!(other, value).write(0); - } } pub trait p9_move_MovableImpl { fn construct(&self, value: i32); - fn move_from(&self, other: Ptr); } impl p9_move_MovableImpl for Ptr { fn construct(&self, mut value: i32) { field!((*self), value).write(value); } - fn move_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - field!(other, value).write(0); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index aa13e0440e..eb803d192b 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -12,7 +12,18 @@ pub fn test_0() { assert!((target == 1)); assert!((source == 1)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct p9_move_trivially_copyable_Point { #[offset(0)] @@ -43,13 +54,19 @@ 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, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p10_move_constructor_A { #[offset(0)] pub value: i32, } +impl MoveConstructible for p10_move_constructor_A { + fn move_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + field!(other, value).write(0); + } +} pub fn test_2() { let source: Value = Rc::new(RefCell::new({ let __v: Value = @@ -60,7 +77,7 @@ pub fn test_2() { let mut target: p10_move_constructor_A = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - p10_move_constructor_AImpl::move_from(&__v.as_pointer(), { source.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { source.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((target.value == 1)); @@ -76,7 +93,7 @@ pub fn test_2() { let __a1 = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - p10_move_constructor_AImpl::move_from(&__v.as_pointer(), { element.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { element.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; values.push(__a1) @@ -96,15 +113,10 @@ fn main_0() -> i32 { } pub trait p10_move_constructor_AImpl { fn construct(&self, value: i32); - fn move_from(&self, other: Ptr); } impl p10_move_constructor_AImpl for Ptr { fn construct(&self, mut value: i32) { field!((*self), value).write(value); } - fn move_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - field!(other, value).write(0); - } } pub fn __cpp2rust_init_globals() {} 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 3d11aa6791..0574c8d526 100644 --- a/tests/std/utilities/utility/out/refcount/utility.as.const.rs +++ b/tests/std/utilities/utility/out/refcount/utility.as.const.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct p1_as_const_Counter { #[offset(0)] diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index c30596f714..65e0a3cf43 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -15,7 +15,17 @@ pub unsafe fn test_0() { assert!(((value) == (2))); } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct p6_forward_like_Movable { pub value: i32, @@ -24,10 +34,14 @@ impl p6_forward_like_Movable { pub unsafe fn construct(&mut self, mut value: i32) { (&raw mut self.value).write(value); } - pub unsafe fn copy_from(&mut self, other: *const p6_forward_like_Movable) { +} +impl CopyConstructibleUnsafe for p6_forward_like_Movable { + unsafe fn copy_constructor(&mut self, other: *const p6_forward_like_Movable) { (&raw mut self.value).write((*other).value); } - pub unsafe fn move_from(&mut self, other: *mut p6_forward_like_Movable) { +} +impl MoveConstructibleUnsafe for p6_forward_like_Movable { + unsafe fn move_constructor(&mut self, other: *mut p6_forward_like_Movable) { (&raw mut self.value).write((*other).value); (*other).value = 0; } @@ -36,21 +50,34 @@ impl Clone for p6_forward_like_Movable { fn clone(&self) -> Self { unsafe { let mut __v: p6_forward_like_Movable = ::zero_init(); - p6_forward_like_Movable::copy_from(&mut __v, self as *const p6_forward_like_Movable); + CopyConstructibleUnsafe::copy_constructor( + &mut __v, + self as *const p6_forward_like_Movable, + ); __v } } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, +)] pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } -impl p6_forward_like_Holder { - pub unsafe fn move_from(&mut self, _a0: *mut p6_forward_like_Holder) { +impl MoveConstructibleUnsafe for p6_forward_like_Holder { + unsafe fn move_constructor(&mut self, _a0: *mut p6_forward_like_Holder) { (&raw mut self.member).write({ let mut __v: p6_forward_like_Movable = ::zero_init(); - p6_forward_like_Movable::move_from(&mut __v, { &mut (*_a0).member }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).member }); __v }); } @@ -71,14 +98,14 @@ impl Default for p6_forward_like_Holder { pub unsafe fn take_1(self_: *mut p6_forward_like_Holder) -> p6_forward_like_Movable { return { let mut __v: p6_forward_like_Movable = ::zero_init(); - p6_forward_like_Movable::copy_from(&mut __v, { &(*self_).member }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &(*self_).member }); __v }; } pub unsafe fn take_2(self_: *mut p6_forward_like_Holder) -> p6_forward_like_Movable { return { let mut __v: p6_forward_like_Movable = ::zero_init(); - p6_forward_like_Movable::move_from(&mut __v, { &mut (*self_).member }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*self_).member }); __v }; } @@ -90,7 +117,7 @@ pub unsafe fn test_3() { assert!(((moved.value) == (1)) && ((holder.member.value) == (0))); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct p9_move_Movable { pub value: i32, @@ -99,7 +126,9 @@ impl p9_move_Movable { pub unsafe fn construct(&mut self, mut value: i32) { (&raw mut self.value).write(value); } - pub unsafe fn move_from(&mut self, other: *mut p9_move_Movable) { +} +impl MoveConstructibleUnsafe for p9_move_Movable { + unsafe fn move_constructor(&mut self, other: *mut p9_move_Movable) { (&raw mut self.value).write((*other).value); (*other).value = 0; } @@ -121,7 +150,7 @@ pub unsafe fn test_4() { }; let mut destination: p9_move_Movable = { let mut __v: p9_move_Movable = ::zero_init(); - p9_move_Movable::move_from(&mut __v, { &mut source }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut source }); __v }; assert!(((destination.value) == (3)) && ((source.value) == (0))); @@ -146,7 +175,16 @@ pub unsafe fn test_4() { ); } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, +)] #[cpp_from(i32, construct, value)] pub struct p10_forward_in_template_A { pub value: i32, @@ -159,12 +197,16 @@ impl p10_forward_in_template_A { (&raw mut self.copies).write(0); (&raw mut self.moves).write(0); } - pub unsafe fn copy_from(&mut self, other: *const p10_forward_in_template_A) { +} +impl CopyConstructibleUnsafe for p10_forward_in_template_A { + unsafe fn copy_constructor(&mut self, other: *const p10_forward_in_template_A) { (&raw mut self.value).write((*other).value); (&raw mut self.copies).write((((*other).copies) + (1))); (&raw mut self.moves).write(0); } - pub unsafe fn move_from(&mut self, other: *mut p10_forward_in_template_A) { +} +impl MoveConstructibleUnsafe for p10_forward_in_template_A { + unsafe fn move_constructor(&mut self, other: *mut p10_forward_in_template_A) { (&raw mut self.value).write((*other).value); (&raw mut self.copies).write(0); (&raw mut self.moves).write((((*other).moves) + (1))); @@ -175,7 +217,7 @@ impl Clone for p10_forward_in_template_A { fn clone(&self) -> Self { unsafe { let mut __v: p10_forward_in_template_A = ::zero_init(); - p10_forward_in_template_A::copy_from( + CopyConstructibleUnsafe::copy_constructor( &mut __v, self as *const p10_forward_in_template_A, ); @@ -191,14 +233,14 @@ impl Default for p10_forward_in_template_A { pub unsafe fn make_5(source: *mut p10_forward_in_template_A) -> p10_forward_in_template_A { return { let mut __v: p10_forward_in_template_A = ::zero_init(); - p10_forward_in_template_A::copy_from(&mut __v, { source }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { source }); __v }; } pub unsafe fn make_6(source: *mut p10_forward_in_template_A) -> p10_forward_in_template_A { return { let mut __v: p10_forward_in_template_A = ::zero_init(); - p10_forward_in_template_A::move_from(&mut __v, { source }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { source }); __v }; } @@ -216,7 +258,17 @@ pub unsafe fn test_7() { assert!(((a.value) == (0))); } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct p11_move_if_noexcept_NoexceptMove { pub value: i32, @@ -225,10 +277,14 @@ impl p11_move_if_noexcept_NoexceptMove { pub unsafe fn construct(&mut self, mut value: i32) { (&raw mut self.value).write(value); } - pub unsafe fn copy_from(&mut self, other: *const p11_move_if_noexcept_NoexceptMove) { +} +impl CopyConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { + unsafe fn copy_constructor(&mut self, other: *const p11_move_if_noexcept_NoexceptMove) { (&raw mut self.value).write((*other).value); } - pub unsafe fn move_from(&mut self, other: *mut p11_move_if_noexcept_NoexceptMove) { +} +impl MoveConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { + unsafe fn move_constructor(&mut self, other: *mut p11_move_if_noexcept_NoexceptMove) { (&raw mut self.value).write((*other).value); (*other).value = 0; } @@ -238,7 +294,7 @@ impl Clone for p11_move_if_noexcept_NoexceptMove { unsafe { let mut __v: p11_move_if_noexcept_NoexceptMove = ::zero_init(); - p11_move_if_noexcept_NoexceptMove::copy_from( + CopyConstructibleUnsafe::copy_constructor( &mut __v, self as *const p11_move_if_noexcept_NoexceptMove, ); @@ -247,7 +303,17 @@ impl Clone for p11_move_if_noexcept_NoexceptMove { } } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct p11_move_if_noexcept_ThrowingMove { pub value: i32, @@ -256,10 +322,14 @@ impl p11_move_if_noexcept_ThrowingMove { pub unsafe fn construct(&mut self, mut value: i32) { (&raw mut self.value).write(value); } - pub unsafe fn copy_from(&mut self, other: *const p11_move_if_noexcept_ThrowingMove) { +} +impl CopyConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { + unsafe fn copy_constructor(&mut self, other: *const p11_move_if_noexcept_ThrowingMove) { (&raw mut self.value).write((*other).value); } - pub unsafe fn move_from(&mut self, other: *mut p11_move_if_noexcept_ThrowingMove) { +} +impl MoveConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { + unsafe fn move_constructor(&mut self, other: *mut p11_move_if_noexcept_ThrowingMove) { (&raw mut self.value).write((*other).value); (*other).value = 0; } @@ -269,7 +339,7 @@ impl Clone for p11_move_if_noexcept_ThrowingMove { unsafe { let mut __v: p11_move_if_noexcept_ThrowingMove = ::zero_init(); - p11_move_if_noexcept_ThrowingMove::copy_from( + CopyConstructibleUnsafe::copy_constructor( &mut __v, self as *const p11_move_if_noexcept_ThrowingMove, ); @@ -287,7 +357,7 @@ pub unsafe fn test_8() { let mut moved: p11_move_if_noexcept_NoexceptMove = { let mut __v: p11_move_if_noexcept_NoexceptMove = ::zero_init(); - p11_move_if_noexcept_NoexceptMove::move_from(&mut __v, { &mut moved_from }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut moved_from }); __v }; assert!(((moved.value) == (1)) && ((moved_from.value) == (0))); @@ -300,7 +370,7 @@ pub unsafe fn test_8() { let mut copied: p11_move_if_noexcept_ThrowingMove = { let mut __v: p11_move_if_noexcept_ThrowingMove = ::zero_init(); - p11_move_if_noexcept_ThrowingMove::copy_from(&mut __v, { &copied_from }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &copied_from }); __v }; assert!(((copied.value) == (2)) && ((copied_from.value) == (2))); diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index 4d369471ad..8dd407cf36 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -13,7 +13,16 @@ pub unsafe fn test_0() { assert!(((source) == (1))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct p9_move_trivially_copyable_Point { pub x: i32, pub y: i32, @@ -42,7 +51,7 @@ pub unsafe fn test_1() { assert!(((element.x) == (5)) && ((element.y) == (6))); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct p10_move_constructor_A { pub value: i32, @@ -51,7 +60,9 @@ impl p10_move_constructor_A { pub unsafe fn construct(&mut self, mut value: i32) { (&raw mut self.value).write(value); } - pub unsafe fn move_from(&mut self, other: *mut p10_move_constructor_A) { +} +impl MoveConstructibleUnsafe for p10_move_constructor_A { + unsafe fn move_constructor(&mut self, other: *mut p10_move_constructor_A) { (&raw mut self.value).write((*other).value); (*other).value = 0; } @@ -64,7 +75,7 @@ pub unsafe fn test_2() { }; let mut target: p10_move_constructor_A = { let mut __v: p10_move_constructor_A = ::zero_init(); - p10_move_constructor_A::move_from(&mut __v, { &mut source }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut source }); __v }; assert!(((target.value) == (1))); @@ -78,7 +89,7 @@ pub unsafe fn test_2() { { let __a1 = { let mut __v: p10_move_constructor_A = ::zero_init(); - p10_move_constructor_A::move_from(&mut __v, { &mut element }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut element }); __v }; values.push(__a1) 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 ae0918d0ef..f200448202 100644 --- a/tests/std/utilities/utility/out/unsafe/utility.as.const.rs +++ b/tests/std/utilities/utility/out/unsafe/utility.as.const.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 36144e741d..9e8d47522d 100644 --- a/tests/ub/out/refcount/ctor_ref_member.rs +++ b/tests/ub/out/refcount/ctor_ref_member.rs @@ -6,7 +6,18 @@ 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, CppFrom, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, ptr)] #[byte_size(8)] pub struct S { diff --git a/tests/ub/out/refcount/self_referencing_initializer.rs b/tests/ub/out/refcount/self_referencing_initializer.rs index 4dd36b221f..b0edecb22b 100644 --- a/tests/ub/out/refcount/self_referencing_initializer.rs +++ b/tests/ub/out/refcount/self_referencing_initializer.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct pair { #[offset(0)] diff --git a/tests/ub/out/refcount/ub6.rs b/tests/ub/out/refcount/ub6.rs index 3c715edc92..1a84b35490 100644 --- a/tests/ub/out/refcount/ub6.rs +++ b/tests/ub/out/refcount/ub6.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Pair { #[offset(0)] diff --git a/tests/ub/out/unsafe/ctor_ref_member.rs b/tests/ub/out/unsafe/ctor_ref_member.rs index dc0191fb67..f94bb1e471 100644 --- a/tests/ub/out/unsafe/ctor_ref_member.rs +++ b/tests/ub/out/unsafe/ctor_ref_member.rs @@ -7,7 +7,17 @@ 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, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, ptr)] pub struct S { pub r: *const i32, diff --git a/tests/ub/out/unsafe/self_referencing_initializer.rs b/tests/ub/out/unsafe/self_referencing_initializer.rs index 8036b03c41..137783f696 100644 --- a/tests/ub/out/unsafe/self_referencing_initializer.rs +++ b/tests/ub/out/unsafe/self_referencing_initializer.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct pair { pub a: i32, pub b: i32, diff --git a/tests/ub/out/unsafe/ub6.rs b/tests/ub/out/unsafe/ub6.rs index f0cd73489f..0c250640dc 100644 --- a/tests/ub/out/unsafe/ub6.rs +++ b/tests/ub/out/unsafe/ub6.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub x1: *mut i32, pub x2: *mut i32, diff --git a/tests/unit/out/refcount/05_new.rs b/tests/unit/out/refcount/05_new.rs index bc5e4eb072..793b504939 100644 --- a/tests/unit/out/refcount/05_new.rs +++ b/tests/unit/out/refcount/05_new.rs @@ -6,10 +6,32 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct A {} -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct D {} pub fn main() { diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index d66369557b..4c6fed88d3 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct GraphNode { #[offset(0)] @@ -15,7 +17,9 @@ pub struct GraphNode { #[byte_size(8)] pub next: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Graph { #[offset(0)] @@ -24,7 +28,7 @@ pub struct Graph { #[byte_size(8)] pub adj: Ptr>, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -40,10 +44,23 @@ impl Default for Partial { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Declared {} -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/addr_of_global.rs b/tests/unit/out/refcount/addr_of_global.rs index d9a77441ee..9f9960c025 100644 --- a/tests/unit/out/refcount/addr_of_global.rs +++ b/tests/unit/out/refcount/addr_of_global.rs @@ -6,13 +6,26 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Inner { #[offset(0)] pub value: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/anonymous-struct.rs b/tests/unit/out/refcount/anonymous-struct.rs index eda0623019..5a0a49c95e 100644 --- a/tests/unit/out/refcount/anonymous-struct.rs +++ b/tests/unit/out/refcount/anonymous-struct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Outer_Named { #[offset(0)] @@ -14,7 +25,18 @@ pub struct Outer_Named { #[offset(4)] pub b: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -22,7 +44,18 @@ pub struct anon_0 { #[offset(4)] pub d: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct anon_1 { #[offset(0)] @@ -30,7 +63,18 @@ pub struct anon_1 { #[offset(4)] pub h: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct anon_2 { #[offset(0)] @@ -38,19 +82,52 @@ pub struct anon_2 { #[offset(4)] pub f: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct anon_4 { #[offset(0)] pub j: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct anon_5 { #[offset(0)] pub k: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(12)] pub struct anon_3 { #[offset(0)] @@ -62,7 +139,18 @@ pub struct anon_3 { #[byte_size(4)] pub anon_5: anon_5, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(44)] pub struct Outer { #[offset(0)] @@ -126,7 +214,18 @@ fn main_0() -> i32 { ); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct anon_6 { #[offset(0)] diff --git a/tests/unit/out/refcount/anonymous-struct_c.rs b/tests/unit/out/refcount/anonymous-struct_c.rs index 4dde61ed84..921e980c12 100644 --- a/tests/unit/out/refcount/anonymous-struct_c.rs +++ b/tests/unit/out/refcount/anonymous-struct_c.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Named { #[offset(0)] @@ -14,7 +25,18 @@ pub struct Named { #[offset(4)] pub b: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -22,7 +44,18 @@ pub struct anon_0 { #[offset(4)] pub d: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct anon_1 { #[offset(0)] @@ -30,7 +63,18 @@ pub struct anon_1 { #[offset(4)] pub h: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct anon_2 { #[offset(0)] @@ -38,19 +82,52 @@ pub struct anon_2 { #[offset(4)] pub f: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct anon_4 { #[offset(0)] pub j: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct anon_5 { #[offset(0)] pub k: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(12)] pub struct anon_3 { #[offset(0)] @@ -62,7 +139,18 @@ pub struct anon_3 { #[byte_size(4)] pub anon_5: anon_5, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(44)] pub struct Outer { #[offset(0)] @@ -132,7 +220,18 @@ fn main_0() -> i32 { ); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct anon_6 { #[offset(0)] diff --git a/tests/unit/out/refcount/anonymous_enum.rs b/tests/unit/out/refcount/anonymous_enum.rs index e2778966b9..ef1717ec58 100644 --- a/tests/unit/out/refcount/anonymous_enum.rs +++ b/tests/unit/out/refcount/anonymous_enum.rs @@ -12,7 +12,18 @@ pub const anon_0_FIRST_B: anon_0 = 1; 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -24,7 +35,18 @@ pub const TdEnum_TD_B: TdEnum = 1; 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct WithAnonField { #[offset(0)] diff --git a/tests/unit/out/refcount/anonymous_enum_c.rs b/tests/unit/out/refcount/anonymous_enum_c.rs index 5b19cd0c46..d1186dbcf0 100644 --- a/tests/unit/out/refcount/anonymous_enum_c.rs +++ b/tests/unit/out/refcount/anonymous_enum_c.rs @@ -12,7 +12,18 @@ pub const anon_0_FIRST_B: anon_0 = 1; 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -24,7 +35,18 @@ pub const TdEnum_enum_TD_B: TdEnum_enum = 1; 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct WithAnonField { #[offset(0)] diff --git a/tests/unit/out/refcount/any.rs b/tests/unit/out/refcount/any.rs index 493694219f..a2df3aa89f 100644 --- a/tests/unit/out/refcount/any.rs +++ b/tests/unit/out/refcount/any.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/array_const_init.rs b/tests/unit/out/refcount/array_const_init.rs index 46be73bee6..a560c3fc15 100644 --- a/tests/unit/out/refcount/array_const_init.rs +++ b/tests/unit/out/refcount/array_const_init.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(20)] pub struct S { #[offset(0)] @@ -38,7 +38,18 @@ thread_local!( buf: Box::new([0; 4]), })); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct P { #[offset(0)] diff --git a/tests/unit/out/refcount/array_field_addr.rs b/tests/unit/out/refcount/array_field_addr.rs index 26cbd4303f..6b227c8f37 100644 --- a/tests/unit/out/refcount/array_field_addr.rs +++ b/tests/unit/out/refcount/array_field_addr.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 bf0ca98779..2b054fa8bd 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -6,7 +6,18 @@ 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, MoveCtor, MoveAssign)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, +)] #[byte_size(32)] pub struct NonCopy { #[offset(0)] @@ -15,6 +26,21 @@ pub struct NonCopy { #[offset(24)] pub tag: i32, } +impl MoveConstructible for NonCopy { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), data).write(field!(_a0, data).with_mut(std::mem::take)); + field!((*this), tag).write({ (*_a0.upgrade().deref()).tag }); + } +} +impl MoveAssignable for NonCopy { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), data).with_mut(|__b0| { + (*__b0) = field!(_a0, data).with_mut(std::mem::take); + }); + field!((*this), tag).write({ (*_a0.upgrade().deref()).tag }); + return (*this).clone(); + } +} impl Default for NonCopy { fn default() -> Self { { @@ -43,21 +69,4 @@ fn main_0() -> i32 { assert!((arr[(2) as usize].data.len() == 0_usize)); return 0; } -pub trait NonCopyImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl NonCopyImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), data).write(field!(_a0, data).with_mut(std::mem::take)); - field!((*self), tag).write({ (*_a0.upgrade().deref()).tag }); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), data).with_mut(|__b0| { - (*__b0) = field!(_a0, data).with_mut(std::mem::take); - }); - field!((*self), tag).write({ (*_a0.upgrade().deref()).tag }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/array_reference.rs b/tests/unit/out/refcount/array_reference.rs index 7bf1089f73..4dce815b9a 100644 --- a/tests/unit/out/refcount/array_reference.rs +++ b/tests/unit/out/refcount/array_reference.rs @@ -59,7 +59,18 @@ pub fn fill_and_sum_9(a: Ptr, mut v: i32, out: Ptr) { pub fn pick_10(s: Ptr) -> Ptr { return (s).clone(); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/as_const.rs b/tests/unit/out/refcount/as_const.rs index cfda0a2235..38ecf0399f 100644 --- a/tests/unit/out/refcount/as_const.rs +++ b/tests/unit/out/refcount/as_const.rs @@ -9,7 +9,18 @@ use std::rc::{Rc, Weak}; pub type Overload = u32; pub const Overload_kMutableOverload: Overload = 1; pub const Overload_kConstOverload: Overload = 2; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/assign_rhs_first.rs b/tests/unit/out/refcount/assign_rhs_first.rs index 36b9ea5db5..8fa7ae2c2d 100644 --- a/tests/unit/out/refcount/assign_rhs_first.rs +++ b/tests/unit/out/refcount/assign_rhs_first.rs @@ -15,7 +15,9 @@ pub fn advance_1() -> i32 { }); return 10; } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index bbe8e8fc5e..666bc99c36 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -810,21 +810,27 @@ pub fn test_reference_members_9() { (*other.borrow()) ); } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Slot_6 { #[offset(0)] #[byte_size(8)] pub value: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Slot_8 { #[offset(0)] #[byte_size(8)] pub value: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Slot_10 { #[offset(0)] @@ -889,7 +895,9 @@ pub fn test_pointer_elements_11() { }; printf!(b"pointer increments %d %d\n", (*index.borrow()), value); } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Holder_12 { #[offset(0)] @@ -923,7 +931,9 @@ pub fn test_reference_pointer_13() { (({ (result).clone() } == { (second.as_pointer()) }) as i32) ); } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Node_14 { #[offset(0)] @@ -1020,26 +1030,52 @@ pub fn test_reference_subfields_18() { ({ (*other.borrow()).value } as i32) ); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Index_16 { #[offset(0)] pub value: u32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Slot_17 { #[offset(0)] #[byte_size(8)] pub ref_: Ptr, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(2)] pub struct Index_19 { #[offset(0)] pub value: i16, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Slot_20 { #[offset(0)] @@ -1081,13 +1117,35 @@ pub fn observe_global_23(mut assigned: i32) -> i32 { pub fn observe_24(mut assigned: i32, mut stored: Ptr) -> i32 { return ({ assigned } + { (stored.read()) }); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct GlobalRecord_Inner { #[offset(0)] pub value: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct GlobalRecord { #[offset(0)] @@ -1328,13 +1386,26 @@ thread_local!( thread_local!( static flag_31: Value = Rc::new(RefCell::new(false)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Record_32 { #[offset(0)] pub value: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Link_33 { #[offset(0)] @@ -1345,7 +1416,18 @@ thread_local!( pub static selected_values_34: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct IndexedBinding {} pub fn test_binding_35() { @@ -1580,7 +1662,18 @@ thread_local!( Box::new([20_u32, 30_u32]), ]))); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(12)] pub struct IndexedMember { #[offset(0)] @@ -1941,7 +2034,9 @@ thread_local!( scoped_values_52.with(|v| v.decay()), ]))); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct PointerSelector { #[offset(0)] @@ -2143,7 +2238,17 @@ pub fn test_stable_containers_58() { printf!(b"nonflat values %u %u\n", iterator_value, mapped_value); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct Counts_59 { @@ -2151,7 +2256,31 @@ pub struct Counts_59 { #[byte_size(24)] pub counts: Vec, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +impl MoveConstructible for Counts_59 { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), counts).write(field!(_a0, counts).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Counts_59 { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), counts).with_mut(|__b0| { + (*__b0) = field!(_a0, counts).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair_60 { #[offset(0)] @@ -2462,13 +2591,24 @@ fn main_0() -> i32 { ); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Index_62 { #[offset(0)] pub value: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(12)] pub struct Owner_63 { #[offset(0)] @@ -2488,21 +2628,6 @@ impl Default for Owner_63 { } } } -pub trait Counts_59Impl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl Counts_59Impl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), counts).write(field!(_a0, counts).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), counts).with_mut(|__b0| { - (*__b0) = field!(_a0, counts).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub trait IndexedBindingImpl { fn get_1_0(&self) -> Ptr; } diff --git a/tests/unit/out/refcount/bounded_struct_ptr.rs b/tests/unit/out/refcount/bounded_struct_ptr.rs index 1504753273..13d8b24e3a 100644 --- a/tests/unit/out/refcount/bounded_struct_ptr.rs +++ b/tests/unit/out/refcount/bounded_struct_ptr.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Foo { #[offset(0)] diff --git a/tests/unit/out/refcount/bst.rs b/tests/unit/out/refcount/bst.rs index bb456f8a87..3706c10845 100644 --- a/tests/unit/out/refcount/bst.rs +++ b/tests/unit/out/refcount/bst.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(24)] pub struct node_t { #[offset(0)] diff --git a/tests/unit/out/refcount/c_struct.rs b/tests/unit/out/refcount/c_struct.rs index 3ca4cf031e..5eaa76cdbe 100644 --- a/tests/unit/out/refcount/c_struct.rs +++ b/tests/unit/out/refcount/c_struct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -14,7 +25,18 @@ pub struct Point { #[offset(4)] pub y: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct Line { #[offset(0)] @@ -24,7 +46,9 @@ pub struct Line { #[byte_size(8)] pub end: Point, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Node { #[offset(0)] @@ -37,7 +61,18 @@ pub type Color = u32; 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -45,7 +80,18 @@ pub struct Inner { #[offset(4)] pub b: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct Container { #[offset(0)] diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index b935d1fca7..a5c5c64723 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -10,7 +10,18 @@ pub type E = u32; 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -18,14 +29,25 @@ pub struct Pair { #[offset(4)] pub y: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(64)] #[byte_align(64)] pub struct Wide { #[offset(0)] pub c: i8, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(40)] pub struct Grid { #[offset(0)] @@ -53,7 +75,17 @@ impl Default for Grid { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(32)] pub struct Bag { @@ -63,6 +95,21 @@ pub struct Bag { #[byte_size(24)] pub items: Vec, } +impl MoveConstructible for Bag { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), n).write({ (*_a0.upgrade().deref()).n }); + field!((*this), items).write(field!(_a0, items).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Bag { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), n).write({ (*_a0.upgrade().deref()).n }); + field!((*this), items).with_mut(|__b0| { + (*__b0) = field!(_a0, items).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} 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]))); @@ -516,21 +563,4 @@ fn main_0() -> i32 { ({ bool_to_floating_10() }); return 0; } -pub trait BagImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl BagImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), n).write({ (*_a0.upgrade().deref()).n }); - field!((*self), items).write(field!(_a0, items).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), n).write({ (*_a0.upgrade().deref()).n }); - field!((*self), items).with_mut(|__b0| { - (*__b0) = field!(_a0, items).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} 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 4c176fcd8b..cd4f406bc9 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,7 @@ pub fn strlen_1(mut s: Ptr) -> i32 { } return c; } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 ac2303a74e..e948e0bf4e 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -14,7 +25,18 @@ pub struct Pair { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct Route { #[offset(0)] @@ -23,7 +45,18 @@ pub struct Route { #[offset(8)] pub cost: f64, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Counter { #[offset(0)] @@ -36,7 +69,18 @@ impl CppEq for Counter { CounterImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Tally { #[offset(0)] diff --git a/tests/unit/out/refcount/class_template_lazy_member.rs b/tests/unit/out/refcount/class_template_lazy_member.rs index 0cd2514117..60b36ae596 100644 --- a/tests/unit/out/refcount/class_template_lazy_member.rs +++ b/tests/unit/out/refcount/class_template_lazy_member.rs @@ -6,32 +6,87 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Point { #[offset(0)] pub x: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Box_int_ { #[offset(0)] pub val: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Box_Point_ { #[offset(0)] #[byte_size(4)] pub val: Point, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Deduced_int_ { #[offset(0)] pub val: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Deduced_Point_ { #[offset(0)] diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index 51f926cd50..93d59d3042 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct MyContainer_int_ { @@ -15,8 +25,31 @@ pub struct MyContainer_int_ { #[byte_size(24)] vec_: Vec, } +impl MoveConstructible for MyContainer_int_ { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), vec_).write(field!(_a0, vec_).with_mut(std::mem::take)); + } +} +impl MoveAssignable for MyContainer_int_ { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), vec_).with_mut(|__b0| { + (*__b0) = field!(_a0, vec_).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct MyContainer_char_ { @@ -24,8 +57,31 @@ pub struct MyContainer_char_ { #[byte_size(24)] vec_: Vec, } +impl MoveConstructible for MyContainer_char_ { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), vec_).write(field!(_a0, vec_).with_mut(std::mem::take)); + } +} +impl MoveAssignable for MyContainer_char_ { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), vec_).with_mut(|__b0| { + (*__b0) = field!(_a0, vec_).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct MyContainer_float_ { @@ -33,7 +89,31 @@ pub struct MyContainer_float_ { #[byte_size(24)] vec_: Vec, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +impl MoveConstructible for MyContainer_float_ { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), vec_).write(field!(_a0, vec_).with_mut(std::mem::take)); + } +} +impl MoveAssignable for MyContainer_float_ { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), vec_).with_mut(|__b0| { + (*__b0) = field!(_a0, vec_).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(2)] pub struct Boxed_short_ { #[offset(0)] @@ -44,7 +124,18 @@ impl Boxed_short_ { return (((v as i32) + (v as i32)) as i16); } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Boxed_int_ { #[offset(0)] @@ -55,7 +146,18 @@ impl Boxed_int_ { return (v + v); } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Boxed_long_ { #[offset(0)] @@ -66,7 +168,18 @@ impl Boxed_long_ { return (v + v); } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Outer_int__Inner_int_ { #[offset(0)] @@ -74,13 +187,35 @@ pub struct Outer_int__Inner_int_ { #[offset(4)] pub u: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Outer_int_ { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct Outer_long__Inner_int_ { #[offset(0)] @@ -88,7 +223,18 @@ pub struct Outer_long__Inner_int_ { #[offset(8)] pub u: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct Outer_long__Inner_char_ { #[offset(0)] @@ -96,13 +242,35 @@ pub struct Outer_long__Inner_char_ { #[offset(8)] pub u: i8, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Outer_long_ { #[offset(0)] pub v: i64, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Elem { #[offset(0)] @@ -228,8 +396,6 @@ pub trait MyContainer_char_Impl { fn back_4(&self) -> Ptr; fn pop_back(&self); fn push_back(&self, item: Ptr); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl MyContainer_char_Impl for Ptr { fn empty(&self) -> bool { @@ -254,15 +420,6 @@ impl MyContainer_char_Impl for Ptr { field!((*self), vec_).with_mut(|__v: &mut Vec| __v.push(a0_clone)) }; } - fn move_from(&self, _a0: Ptr) { - field!((*self), vec_).write(field!(_a0, vec_).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), vec_).with_mut(|__b0| { - (*__b0) = field!(_a0, vec_).with_mut(std::mem::take); - }); - return (*self).clone(); - } } pub trait MyContainer_float_Impl { fn empty(&self) -> bool; @@ -273,8 +430,6 @@ pub trait MyContainer_float_Impl { fn back_4(&self) -> Ptr; fn pop_back(&self); fn push_back(&self, item: Ptr); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl MyContainer_float_Impl for Ptr { fn empty(&self) -> bool { @@ -299,15 +454,6 @@ impl MyContainer_float_Impl for Ptr { field!((*self), vec_).with_mut(|__v: &mut Vec| __v.push(a0_clone)) }; } - fn move_from(&self, _a0: Ptr) { - field!((*self), vec_).write(field!(_a0, vec_).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), vec_).with_mut(|__b0| { - (*__b0) = field!(_a0, vec_).with_mut(std::mem::take); - }); - return (*self).clone(); - } } pub trait MyContainer_int_Impl { fn empty(&self) -> bool; @@ -318,8 +464,6 @@ pub trait MyContainer_int_Impl { fn back_4(&self) -> Ptr; fn pop_back(&self); fn push_back(&self, item: Ptr); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl MyContainer_int_Impl for Ptr { fn empty(&self) -> bool { @@ -344,15 +488,6 @@ impl MyContainer_int_Impl for Ptr { field!((*self), vec_).with_mut(|__v: &mut Vec| __v.push(a0_clone)) }; } - fn move_from(&self, _a0: Ptr) { - field!((*self), vec_).write(field!(_a0, vec_).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), vec_).with_mut(|__b0| { - (*__b0) = field!(_a0, vec_).with_mut(std::mem::take); - }); - return (*self).clone(); - } } pub trait Outer_int_Impl { fn with(&self, n: i32) -> Outer_int__Inner_int_; diff --git a/tests/unit/out/refcount/clone_vs_move.rs b/tests/unit/out/refcount/clone_vs_move.rs index e039b96e3b..aeb644242d 100644 --- a/tests/unit/out/refcount/clone_vs_move.rs +++ b/tests/unit/out/refcount/clone_vs_move.rs @@ -6,13 +6,24 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Bar { #[offset(0)] pub w: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(40)] pub struct Foo { #[offset(0)] @@ -44,7 +55,9 @@ impl Default for Foo { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Refs { #[offset(0)] diff --git a/tests/unit/out/refcount/comma_operator.rs b/tests/unit/out/refcount/comma_operator.rs index dfa9317ee4..ee89c19b30 100644 --- a/tests/unit/out/refcount/comma_operator.rs +++ b/tests/unit/out/refcount/comma_operator.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/complex_function.rs b/tests/unit/out/refcount/complex_function.rs index 67a13bc86d..dd96d702c7 100644 --- a/tests/unit/out/refcount/complex_function.rs +++ b/tests/unit/out/refcount/complex_function.rs @@ -15,27 +15,44 @@ pub fn ptr_1(mut x: Ptr) -> Ptr { pub fn bar_2(x: Ptr) -> Ptr { return (x).clone(); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct X1 { #[offset(0)] pub v: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct X2 { #[offset(0)] #[byte_size(8)] pub v: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct X3 { #[offset(0)] #[byte_size(8)] pub v: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct X4 { #[offset(0)] diff --git a/tests/unit/out/refcount/compound_assign_paren.rs b/tests/unit/out/refcount/compound_assign_paren.rs index d0915965f7..8654df7d11 100644 --- a/tests/unit/out/refcount/compound_assign_paren.rs +++ b/tests/unit/out/refcount/compound_assign_paren.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Item { #[offset(0)] diff --git a/tests/unit/out/refcount/concepts.rs b/tests/unit/out/refcount/concepts.rs index 2f2400e07d..46439f3a75 100644 --- a/tests/unit/out/refcount/concepts.rs +++ b/tests/unit/out/refcount/concepts.rs @@ -11,7 +11,18 @@ const _: () = assert!( (::std::mem::size_of::() == 4_usize), "sizeof(int) == 4" ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Sized {} pub fn is_small_0() -> bool { diff --git a/tests/unit/out/refcount/constexpr_function.rs b/tests/unit/out/refcount/constexpr_function.rs index fc933ae67d..baebd31e6c 100644 --- a/tests/unit/out/refcount/constexpr_function.rs +++ b/tests/unit/out/refcount/constexpr_function.rs @@ -21,7 +21,18 @@ pub fn scaled_2(mut x: i32) -> i32 { pub fn half_3(mut x: f64) -> f64 { return (x / 2_f64); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Flag { #[offset(0)] @@ -44,7 +55,18 @@ const _: () = assert!(true, "in_constant_context()"); pub fn imm_7(mut b: bool) -> bool { return b; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct P { #[offset(0)] diff --git a/tests/unit/out/refcount/constructor.rs b/tests/unit/out/refcount/constructor.rs index 0663e02d8a..2f9412585b 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -10,7 +10,7 @@ thread_local!( pub static total_0: Value = Rc::new(RefCell::new(0)); ); #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Default, + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -18,7 +18,25 @@ pub struct S { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] +impl Destructible for S { + fn destroy(this: &Ptr) { + ({ SImpl::mut_method(this) }); + let __rhs = ({ SImpl::const_method(this) }); + total_0.with(|rc| *rc.borrow_mut() += __rhs); + } +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, +)] #[cpp_from(i32, construct_1, value)] #[byte_size(8)] pub struct Point { @@ -50,7 +68,7 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_s = - std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!(({ (*s.borrow()).v } == 4)); assert!((total_0.with(|rc| *rc.borrow()) == 8)); } @@ -106,7 +124,6 @@ pub trait SImpl { fn const_method(&self) -> i32; fn mut_method(&self); fn construct(&self, init: i32); - fn destructor(&self); } impl SImpl for Ptr { fn const_method(&self) -> i32 { @@ -123,11 +140,6 @@ impl SImpl for Ptr { let __rhs = ({ SImpl::const_method(self) }); total_0.with(|rc| *rc.borrow_mut() += __rhs); } - fn destructor(&self) { - ({ SImpl::mut_method(self) }); - let __rhs = ({ SImpl::const_method(self) }); - total_0.with(|rc| *rc.borrow_mut() += __rhs); - } } pub fn __cpp2rust_init_globals() { let _ = total_0.with(|_| ()); diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index ce9e3647ea..fa3e629895 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -6,7 +6,20 @@ 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, MoveCtor, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[byte_size(32)] pub struct Holder { #[offset(0)] @@ -16,6 +29,12 @@ pub struct Holder { #[byte_size(24)] pub vec_: Vec, } +impl MoveConstructible for Holder { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), ref_).write(({ (*_a0.upgrade().deref()).ref_.clone() }).clone()); + field!((*this), vec_).write(field!(_a0, vec_).with_mut(std::mem::take)); + } +} pub fn pick_0(a: Ptr>, b: Ptr>, mut first: bool) -> Ptr> { return if first { (a).clone() } else { (b).clone() }; } @@ -132,13 +151,4 @@ fn main_0() -> i32 { assert!((({ sum_1(v.as_pointer(),) }) == 7)); return 0; } -pub trait HolderImpl { - fn move_from(&self, _a0: Ptr); -} -impl HolderImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), ref_).write(({ (*_a0.upgrade().deref()).ref_.clone() }).clone()); - field!((*self), vec_).write(field!(_a0, vec_).with_mut(std::mem::take)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/container_field_addr.rs b/tests/unit/out/refcount/container_field_addr.rs index 8cf629f6a9..f30668cbab 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(32)] pub struct S { @@ -17,6 +27,21 @@ pub struct S { #[byte_size(24)] pub v: Vec, } +impl MoveConstructible for S { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), tag).write({ (*_a0.upgrade().deref()).tag }); + field!((*this), v).write(field!(_a0, v).with_mut(std::mem::take)); + } +} +impl MoveAssignable for S { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), tag).write({ (*_a0.upgrade().deref()).tag }); + field!((*this), v).with_mut(|__b0| { + (*__b0) = field!(_a0, v).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} pub fn add_0(mut v: Ptr>, mut k: i32) { { let a0_clone = k.clone(); @@ -53,21 +78,4 @@ fn main_0() -> i32 { heap.delete(); return 0; } -pub trait SImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl SImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), tag).write({ (*_a0.upgrade().deref()).tag }); - field!((*self), v).write(field!(_a0, v).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), tag).write({ (*_a0.upgrade().deref()).tag }); - field!((*self), v).with_mut(|__b0| { - (*__b0) = field!(_a0, v).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/conversion_operator_same_translation.rs b/tests/unit/out/refcount/conversion_operator_same_translation.rs index bad76bd5f0..78690ac1f7 100644 --- a/tests/unit/out/refcount/conversion_operator_same_translation.rs +++ b/tests/unit/out/refcount/conversion_operator_same_translation.rs @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_into(i8, to_i8)] #[cpp_into(u8, to_u8)] #[byte_size(4)] @@ -14,7 +26,19 @@ pub struct S { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_into(i64, to_i64_1)] #[byte_size(4)] pub struct T { diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index bd09ccb7a8..98b0f51f46 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; thread_local!( pub static assigns_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Movable, Default)] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -17,6 +17,22 @@ pub struct Partial { #[offset(4)] pub keep: i32, } +impl CopyConstructible for Partial { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), keep).write(o.with(|__s| __s.keep)); + } +} +impl CopyAssignable for Partial { + fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + if ((*this) == (o)) { + return (*this).clone(); + } + field!((*this), v).write(o.with(|__s| __s.v)); + (*assigns_0.with(Value::clone).borrow_mut()).prefix_inc(); + return (*this).clone(); + } +} impl Clone for Partial { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Partial { @@ -24,11 +40,13 @@ impl Clone for Partial { keep: self.keep.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - PartialImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct NonConstAssign { #[offset(0)] @@ -46,12 +64,29 @@ impl Default for NonConstAssign { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + Movable, +)] #[byte_size(4)] pub struct RefQualified { #[offset(0)] pub mark: i32, } +impl CopyAssignable for RefQualified { + fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), mark).write((o.with(|__s| __s.mark) + 1)); + return (*this).clone(); + } +} impl Default for RefQualified { fn default() -> Self { { @@ -63,7 +98,17 @@ impl Default for RefQualified { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + Movable, +)] #[byte_size(24)] pub struct Holder { #[offset(0)] @@ -74,6 +119,26 @@ pub struct Holder { #[array_len(2)] pub arr: Box<[Partial]>, } +impl CopyAssignable for Holder { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + ({ CopyAssignable::copy_assign(&field_ptr!((*this), p), field_ptr!(_a0, p)) }); + { + let mut __i0: usize = 0_usize; + 'loop_: while (__i0 != 2_usize) { + 'for_body: { + ({ + CopyAssignable::copy_assign( + &array_field_ptr!((*this), arr).offset((__i0) as isize), + array_field_ptr!(_a0, arr).offset((__i0) as isize), + ) + }); + } + __i0.prefix_inc(); + } + } + return (*this).clone(); + } +} impl Default for Holder { fn default() -> Self { { @@ -89,22 +154,46 @@ impl Default for Holder { thread_local!( pub static copies_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Movable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct CopyCounted { #[offset(0)] pub v: i32, } +impl CopyConstructible for CopyCounted { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for CopyCounted { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).write(_a0.with(|__s| __s.v)); + return (*this).clone(); + } +} impl Clone for CopyCounted { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(CopyCounted { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCountedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + Movable, +)] #[byte_size(12)] pub struct HasCopyCounted { #[offset(0)] @@ -115,6 +204,17 @@ pub struct HasCopyCounted { #[array_len(2)] pub arr: Box<[CopyCounted]>, } +impl CopyAssignable for HasCopyCounted { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + ({ CopyAssignable::copy_assign(&field_ptr!((*this), c), field_ptr!(_a0, c)) }); + { + let mut __tmp_0 = { (array_field_ptr!((*this), arr)).to_any() }; + __tmp_0.memcpy(&(array_field_ptr!(_a0, arr)).to_any(), 8_usize); + (__tmp_0).clone() + }; + return (*this).clone(); + } +} impl Default for HasCopyCounted { fn default() -> Self { { @@ -147,18 +247,18 @@ fn main_0() -> i32 { PartialImpl::construct(&__v.as_pointer(), { 3 }, { 300 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - ({ PartialImpl::copy_assign(&a.as_pointer(), b.as_pointer()) }); + ({ CopyAssignable::copy_assign(&a.as_pointer(), b.as_pointer()) }); assert!(({ (*a.borrow()).v } == 2) && ({ (*a.borrow()).keep } == 100)); assert!((assigns_0.with(|rc| *rc.borrow()) == 1)); ({ - PartialImpl::copy_assign( + CopyAssignable::copy_assign( &c.as_pointer(), - ({ PartialImpl::copy_assign(&a.as_pointer(), b.as_pointer()) }), + ({ CopyAssignable::copy_assign(&a.as_pointer(), b.as_pointer()) }), ) }); assert!(({ (*c.borrow()).v } == 2) && ({ (*c.borrow()).keep } == 300)); assert!((assigns_0.with(|rc| *rc.borrow()) == 3)); - ({ PartialImpl::copy_assign(&a.as_pointer(), a.as_pointer()) }); + ({ CopyAssignable::copy_assign(&a.as_pointer(), a.as_pointer()) }); assert!((assigns_0.with(|rc| *rc.borrow()) == 3)); ({ let _o: Value = Rc::new(RefCell::new({ @@ -166,15 +266,15 @@ fn main_0() -> i32 { PartialImpl::construct(&__v.as_pointer(), { 9 }, { 900 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - PartialImpl::copy_assign(&a.as_pointer(), _o.as_pointer()) + CopyAssignable::copy_assign(&a.as_pointer(), _o.as_pointer()) }); assert!(({ (*a.borrow()).v } == 9) && ({ (*a.borrow()).keep } == 100)); assert!((assigns_0.with(|rc| *rc.borrow()) == 4)); let ra: Ptr = a.as_pointer(); - ({ PartialImpl::copy_assign(&ra, c.as_pointer()) }); + ({ CopyAssignable::copy_assign(&ra, c.as_pointer()) }); assert!(({ (*a.borrow()).v } == 2)); let mut pa: Ptr = (a.as_pointer()); - ({ PartialImpl::copy_assign(&pa, b.as_pointer()) }); + ({ CopyAssignable::copy_assign(&pa, b.as_pointer()) }); assert!(({ (*a.borrow()).v } == 2)); assert!((assigns_0.with(|rc| *rc.borrow()) == 6)); let h: Value = Rc::new(RefCell::new(Holder { @@ -196,9 +296,9 @@ fn main_0() -> i32 { }, ]), })); - ({ PartialImpl::copy_assign(&field_ptr!(h.as_pointer(), p), b.as_pointer()) }); + ({ CopyAssignable::copy_assign(&field_ptr!(h.as_pointer(), p), b.as_pointer()) }); ({ - PartialImpl::copy_assign( + CopyAssignable::copy_assign( &array_field_ptr!(h.as_pointer(), arr).offset((1) as isize), c.as_pointer(), ) @@ -243,7 +343,7 @@ fn main_0() -> i32 { RefQualifiedImpl::construct(&__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - ({ RefQualifiedImpl::copy_assign(&r1.as_pointer(), r.as_pointer()) }); + ({ CopyAssignable::copy_assign(&r1.as_pointer(), r.as_pointer()) }); assert!(({ (*r1.borrow()).mark } == 1)); let h2: Value = Rc::new(RefCell::new(Holder { p: { @@ -264,7 +364,7 @@ fn main_0() -> i32 { }, ]), })); - ({ HolderImpl::copy_assign(&h2.as_pointer(), h.as_pointer()) }); + ({ CopyAssignable::copy_assign(&h2.as_pointer(), h.as_pointer()) }); assert!(({ (*h2.borrow()).p.v } == 2) && ({ (*h2.borrow()).p.keep } == 70)); assert!( (array_elem!(h2.as_pointer(), arr, 1).with(|__s| __s.v) == 2) @@ -281,7 +381,7 @@ fn main_0() -> i32 { CopyCountedImpl::construct(&__v.as_pointer(), { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - ({ CopyCountedImpl::copy_assign(&cc1.as_pointer(), cc2.as_pointer()) }); + ({ CopyAssignable::copy_assign(&cc1.as_pointer(), cc2.as_pointer()) }); assert!(({ (*cc1.borrow()).v } == 2)); let hc1: Value = Rc::new(RefCell::new(HasCopyCounted { c: { @@ -321,7 +421,7 @@ fn main_0() -> i32 { }, ]), })); - ({ HasCopyCountedImpl::copy_assign(&hc1.as_pointer(), hc2.as_pointer()) }); + ({ CopyAssignable::copy_assign(&hc1.as_pointer(), hc2.as_pointer()) }); assert!( (({ (*hc1.borrow()).c.v } == 4) && (array_elem!(hc1.as_pointer(), arr, 0).with(|__s| __s.v) == 5)) @@ -332,58 +432,11 @@ fn main_0() -> i32 { } pub trait CopyCountedImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl CopyCountedImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).write(_a0.with(|__s| __s.v)); - return (*self).clone(); - } -} -pub trait HasCopyCountedImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasCopyCountedImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - ({ CopyCountedImpl::copy_assign(&field_ptr!((*self), c), field_ptr!(_a0, c)) }); - { - let mut __tmp_0 = { (array_field_ptr!((*self), arr)).to_any() }; - __tmp_0.memcpy(&(array_field_ptr!(_a0, arr)).to_any(), 8_usize); - (__tmp_0).clone() - }; - return (*self).clone(); - } -} -pub trait HolderImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HolderImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - ({ PartialImpl::copy_assign(&field_ptr!((*self), p), field_ptr!(_a0, p)) }); - { - let mut __i0: usize = 0_usize; - 'loop_: while (__i0 != 2_usize) { - 'for_body: { - ({ - PartialImpl::copy_assign( - &array_field_ptr!((*self), arr).offset((__i0) as isize), - array_field_ptr!(_a0, arr).offset((__i0) as isize), - ) - }); - } - __i0.prefix_inc(); - } - } - return (*self).clone(); - } } pub trait NonConstAssignImpl { fn construct(&self); @@ -405,39 +458,20 @@ impl NonConstAssignImpl for Ptr { } pub trait PartialImpl { fn construct(&self, v: i32, keep: i32); - fn copy_from(&self, o: Ptr); - fn copy_assign(&self, o: Ptr) -> Ptr; } impl PartialImpl for Ptr { fn construct(&self, mut v: i32, mut keep: i32) { field!((*self), v).write(v); field!((*self), keep).write(keep); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), keep).write(o.with(|__s| __s.keep)); - } - fn copy_assign(&self, o: Ptr) -> Ptr { - if ((*self) == (o)) { - return (*self).clone(); - } - field!((*self), v).write(o.with(|__s| __s.v)); - (*assigns_0.with(Value::clone).borrow_mut()).prefix_inc(); - return (*self).clone(); - } } pub trait RefQualifiedImpl { fn construct(&self); - fn copy_assign(&self, o: Ptr) -> Ptr; } impl RefQualifiedImpl for Ptr { fn construct(&self) { field!((*self), mark).write(0); } - fn copy_assign(&self, o: Ptr) -> Ptr { - field!((*self), mark).write((o.with(|__s| __s.mark) + 1)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = assigns_0.with(|_| ()); diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 5191857c33..9c9ed0b670 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -9,27 +9,49 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Movable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Counted { #[offset(0)] pub v: i32, } +impl CopyConstructible for Counted { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for Counted { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).write(_a0.with(|__s| __s.v)); + return (*this).clone(); + } +} impl Clone for Counted { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Counted { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, CopyConstructible, Movable, +)] #[byte_size(4)] pub struct NonConst { #[offset(0)] pub mark: i32, } +impl CopyAssignable for NonConst { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), mark).write(_a0.with(|__s| __s.mark)); + return (*this).clone(); + } +} impl Clone for NonConst { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(NonConst { @@ -51,22 +73,46 @@ impl Default for NonConst { } } } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Movable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Ignored { #[offset(0)] pub v: i32, } +impl CopyConstructible for Ignored { + fn copy_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), v).write(-1_i32); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for Ignored { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).write(_a0.with(|__s| __s.v)); + return (*this).clone(); + } +} impl Clone for Ignored { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Ignored { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - IgnoredImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + Movable, +)] #[byte_size(12)] pub struct Holder { #[offset(0)] @@ -77,6 +123,17 @@ pub struct Holder { #[array_len(2)] pub arr: Box<[Counted]>, } +impl CopyAssignable for Holder { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + ({ CopyAssignable::copy_assign(&field_ptr!((*this), c), field_ptr!(_a0, c)) }); + { + let mut __tmp_0 = { (array_field_ptr!((*this), arr)).to_any() }; + __tmp_0.memcpy(&(array_field_ptr!(_a0, arr)).to_any(), 8_usize); + (__tmp_0).clone() + }; + return (*this).clone(); + } +} impl Default for Holder { fn default() -> Self { { @@ -89,59 +146,132 @@ impl Default for Holder { } } } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Box_int_ { #[offset(0)] pub val: i32, } +impl CopyConstructible for Box_int_ { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), val).write(o.with(|__s| __s.val)); + } +} +impl MoveConstructible for Box_int_ { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), val).write({ (*_a0.upgrade().deref()).val }); + } +} impl Clone for Box_int_ { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Box_int_ { val: self.val.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - Box_int_Impl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[byte_size(4)] pub struct Owner { #[offset(0)] #[byte_size(4)] pub box_: Box_int_, } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +impl MoveConstructible for Owner { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), box_).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, box_) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + } +} +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Movable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct OutOfLine { #[offset(0)] pub v: i32, } +impl CopyConstructible for OutOfLine { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write((o.with(|__s| __s.v) + 100)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for OutOfLine { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).write(_a0.with(|__s| __s.v)); + return (*this).clone(); + } +} impl Clone for OutOfLine { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(OutOfLine { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - OutOfLineImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -impl OutOfLine {} -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Movable)] #[byte_size(4)] pub struct Tracked { #[offset(0)] pub copied_from: i32, } +impl CopyConstructible for Tracked { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), copied_from).write(0); + field!(o, copied_from).with_mut(|__v| { + __v.prefix_inc(); + }); + } +} +impl CopyAssignable for Tracked { + fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + field!(o, copied_from).with_mut(|__v| { + __v.prefix_inc(); + }); + return (*this).clone(); + } +} impl Clone for Tracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Tracked { copied_from: self.copied_from.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -166,7 +296,7 @@ pub fn make_3(mut v: i32) -> Counted { })); return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), { c.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { c.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -182,17 +312,17 @@ fn main_0() -> i32 { })); let mut b: Counted = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), { a.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; let mut c: Counted = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), { a.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; let mut d: Counted = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), { a.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((copies_0.with(|rc| *rc.borrow()) == 3)); @@ -201,7 +331,7 @@ fn main_0() -> i32 { (({ by_value_2({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), { a.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 1) @@ -224,7 +354,7 @@ fn main_0() -> i32 { })); let mut h: Counted = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), { g.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { g.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((h.v == 7)); @@ -267,7 +397,7 @@ fn main_0() -> i32 { })); let mut i2: Ignored = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - IgnoredImpl::copy_from(&__v.as_pointer(), { i1.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { i1.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!(({ (*i1.borrow()).v } == 1) && (i2.v == -1_i32)); @@ -281,7 +411,7 @@ fn main_0() -> i32 { })); let mut o2: Owner = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - OwnerImpl::move_from(&__v.as_pointer(), { o.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { o.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((o2.box_.val == 3)); @@ -292,7 +422,7 @@ fn main_0() -> i32 { })); let mut ol2: OutOfLine = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - OutOfLineImpl::copy_from(&__v.as_pointer(), { ol1.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { ol1.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((ol2.v == 105)); @@ -322,15 +452,15 @@ fn main_0() -> i32 { let t1: Value = Rc::new(RefCell::new(::default())); let t2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), { t1.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { t1.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - ({ TrackedImpl::copy_assign(&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 mut t3: Tracked = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), { ct.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { ct.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; ({ touch_1((ct.as_pointer())) }); @@ -339,75 +469,32 @@ fn main_0() -> i32 { } pub trait Box_int_Impl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, _a0: Ptr); } impl Box_int_Impl for Ptr { fn construct(&self, mut v: i32) { field!((*self), val).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), val).write(o.with(|__s| __s.val)); - } - fn move_from(&self, _a0: Ptr) { - field!((*self), val).write({ (*_a0.upgrade().deref()).val }); - } } pub trait CountedImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl CountedImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).write(_a0.with(|__s| __s.v)); - return (*self).clone(); - } -} -pub trait HolderImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HolderImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - ({ CountedImpl::copy_assign(&field_ptr!((*self), c), field_ptr!(_a0, c)) }); - { - let mut __tmp_0 = { (array_field_ptr!((*self), arr)).to_any() }; - __tmp_0.memcpy(&(array_field_ptr!(_a0, arr)).to_any(), 8_usize); - (__tmp_0).clone() - }; - return (*self).clone(); - } } pub trait IgnoredImpl { fn construct(&self, v: i32); - fn copy_from(&self, _a0: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl IgnoredImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, _a0: Ptr) { - field!((*self), v).write(-1_i32); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).write(_a0.with(|__s| __s.v)); - return (*self).clone(); - } } pub trait NonConstImpl { fn construct(&self); fn construct_1(&self, o: Ptr); fn construct_2(&self, o: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl NonConstImpl for Ptr { fn construct(&self) { @@ -419,58 +506,14 @@ impl NonConstImpl for Ptr { fn construct_2(&self, o: Ptr) { field!((*self), mark).write((o.with(|__s| __s.mark) + 10)); } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), mark).write(_a0.with(|__s| __s.mark)); - return (*self).clone(); - } } pub trait OutOfLineImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl OutOfLineImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write((o.with(|__s| __s.v) + 100)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).write(_a0.with(|__s| __s.v)); - return (*self).clone(); - } -} -pub trait OwnerImpl { - fn move_from(&self, _a0: Ptr); -} -impl OwnerImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), box_).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Box_int_Impl::move_from(&__v.as_pointer(), { field_ptr!(_a0, box_) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - } -} -pub trait TrackedImpl { - fn copy_from(&self, o: Ptr); - fn copy_assign(&self, o: Ptr) -> Ptr; -} -impl TrackedImpl for Ptr { - fn copy_from(&self, o: Ptr) { - field!((*self), copied_from).write(0); - field!(o, copied_from).with_mut(|__v| { - __v.prefix_inc(); - }); - } - fn copy_assign(&self, o: Ptr) -> Ptr { - field!(o, copied_from).with_mut(|__v| { - __v.prefix_inc(); - }); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index dd1836bdcc..ae94d0c5e3 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -6,13 +6,24 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Inner { #[offset(0)] pub x: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable)] #[cpp_from(i32, construct, value)] #[byte_size(16)] pub struct Explicit { @@ -26,12 +37,15 @@ pub struct Explicit { #[array_len(2)] pub arr: Box<[i32]>, } +impl Destructible for Explicit { + fn destroy(this: &Ptr) {} +} impl Default for Explicit { fn default() -> Self { { ::zero_init() } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(16)] pub struct Implicit { #[offset(0)] @@ -63,9 +77,11 @@ impl Default for Implicit { ZeroInitialization, VaArg, FnPtrArg, - MoveCtor, CppFrom, - MoveAssign, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, Default, )] #[cpp_from(i32, construct, value)] @@ -74,17 +90,21 @@ pub struct DefaultCopyUserMove { #[offset(0)] pub v: i32, } +impl MoveConstructible for DefaultCopyUserMove { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(0); + } +} +impl MoveAssignable for DefaultCopyUserMove { + fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(0); + return (*this).clone(); + } +} #[derive( - Record, - ByteRepr, - ZeroInitialization, - VaArg, - FnPtrArg, - MoveCtor, - CppFrom, - CopyAssign, - MoveAssign, - Default, + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Swappable, Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -92,17 +112,39 @@ pub struct UserCopyDefaultMove { #[offset(0)] pub v: i32, } +impl CopyConstructible for UserCopyDefaultMove { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write((o.with(|__s| __s.v) + 100)); + } +} +impl MoveConstructible for UserCopyDefaultMove { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), v).write({ (*_a0.upgrade().deref()).v }); + } +} +impl CopyAssignable for UserCopyDefaultMove { + fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write((o.with(|__s| __s.v) + 100)); + return (*this).clone(); + } +} +impl MoveAssignable for UserCopyDefaultMove { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).write({ (*_a0.upgrade().deref()).v }); + return (*this).clone(); + } +} impl Clone for UserCopyDefaultMove { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(UserCopyDefaultMove { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - UserCopyDefaultMoveImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, MoveAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable)] #[cpp_from(i32, construct, value)] #[byte_size(64)] pub struct Buffer { @@ -119,12 +161,39 @@ pub struct Buffer { #[array_len(2)] pub arr: Box<[i32]>, } +impl MoveConstructible for Buffer { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), data).write(field!(_a0, data).with_mut(std::mem::take)); + field!((*this), rows).write(field!(_a0, rows).with_mut(std::mem::take)); + field!((*this), n).write({ (*_a0.upgrade().deref()).n }); + field!((*this), arr).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { + (*_a0.upgrade().deref()).arr[(__i) as usize] + }))); + } +} +impl MoveAssignable for Buffer { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), data).with_mut(|__b0| { + (*__b0) = field!(_a0, data).with_mut(std::mem::take); + }); + field!((*this), rows).with_mut(|__b0| { + (*__b0) = field!(_a0, rows).with_mut(std::mem::take); + }); + field!((*this), n).write({ (*_a0.upgrade().deref()).n }); + { + let mut __tmp_0 = { (array_field_ptr!((*this), arr)).to_any() }; + __tmp_0.memcpy(&(array_field_ptr!(_a0, arr)).to_any(), 8_usize); + (__tmp_0).clone() + }; + return (*this).clone(); + } +} impl Default for Buffer { fn default() -> Self { { ::zero_init() } } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] #[byte_size(48)] pub struct Owner { #[offset(0)] @@ -140,6 +209,34 @@ pub struct Owner { #[byte_size(8)] pub p: Option>, } +impl MoveConstructible for Owner { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), data).write(field!(_a0, data).with_mut(std::mem::take)); + field!((*this), n).write({ (*_a0.upgrade().deref()).n }); + field!((*this), arr).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { + (*_a0.upgrade().deref()).arr[(__i) as usize] + }))); + field!((*this), p) + .write(field!(_a0, p).with_mut(|__v: &mut Option>| __v.take())); + } +} +impl MoveAssignable for Owner { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), data).with_mut(|__b0| { + (*__b0) = field!(_a0, data).with_mut(std::mem::take); + }); + field!((*this), n).write({ (*_a0.upgrade().deref()).n }); + { + let mut __tmp_1 = { (array_field_ptr!((*this), arr)).to_any() }; + __tmp_1.memcpy(&(array_field_ptr!(_a0, arr)).to_any(), 8_usize); + (__tmp_1).clone() + }; + field!((*this), p).with_mut(|__b0| { + (*__b0) = field!(_a0, p).with_mut(|__v: &mut Option>| __v.take()); + }); + return (*this).clone(); + } +} impl Default for Owner { fn default() -> Self { { @@ -153,25 +250,38 @@ impl Default for Owner { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, -)] -#[byte_size(24)] -pub struct Copyable { - #[offset(0)] - #[byte_size(24)] - pub data: Vec, -} -#[derive( + Clone, Record, ByteRepr, ZeroInitialization, + VaArg, FnPtrArg, - MoveCtor, - CppFrom, - MoveAssign, Destructible, + CopyConstructible, + CopyAssignable, + Swappable, Default, )] +#[byte_size(24)] +pub struct Copyable { + #[offset(0)] + #[byte_size(24)] + pub data: Vec, +} +impl MoveConstructible for Copyable { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), data).write(field!(_a0, data).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Copyable { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), data).with_mut(|__b0| { + (*__b0) = field!(_a0, data).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Swappable, Default)] #[cpp_from(i32, construct, value)] #[byte_size(32)] pub struct Holder { @@ -185,6 +295,29 @@ pub struct Holder { #[byte_size(8)] pub p: Option>, } +impl MoveConstructible for Holder { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), inner).write({ (*_a0.upgrade().deref()).inner }); + field!((*this), e).write({ (*_a0.upgrade().deref()).e.clone() }); + field!((*this), p) + .write(field!(_a0, p).with_mut(|__v: &mut Option>| __v.take())); + } +} +impl MoveAssignable for Holder { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), inner).write({ (*_a0.upgrade().deref()).inner }); + field!((*this), e).write({ (*_a0.upgrade().deref()).e.clone() }); + field!((*this), p).with_mut(|__b0| { + (*__b0) = field!(_a0, p).with_mut(|__v: &mut Option>| __v.take()); + }); + return (*this).clone(); + } +} +impl Destructible for Holder { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, e)); + } +} pub fn same_0(a: Ptr, b: Ptr) -> bool { return ((({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }) && ({ a.with(|__s| __s.inner.x) } == { b.with(|__s| __s.inner.x) })) @@ -202,16 +335,16 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_a = - std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let b: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_b = - std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let c: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_c = - std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let d: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_d = - std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!( (({ same_0(b.as_pointer(), a.as_pointer(),) }) && ({ same_0(c.as_pointer(), a.as_pointer(),) })) @@ -223,14 +356,14 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_e = - std::mem::DropGuard::new(e.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(e.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let f: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); ExplicitImpl::construct(&__v.as_pointer(), { 3 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(&__p.as_pointer())); (*e.borrow_mut()) = (*b.borrow()).clone(); (*f.borrow_mut()) = (*c.borrow()).clone(); assert!( @@ -243,7 +376,7 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let __rhs = { (*e.borrow_mut()) = (*f.borrow()).clone(); (*e.borrow()).clone() @@ -293,7 +426,7 @@ fn main_0() -> i32 { let mut m2: DefaultCopyUserMove = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultCopyUserMoveImpl::move_from(&__v.as_pointer(), { m.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { m.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((({ (*m1.borrow()).v } == 7) && (m2.v == 7)) && ({ (*m.borrow()).v } == 0)); @@ -310,7 +443,7 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); m3 = (*m1.borrow()); - ({ DefaultCopyUserMoveImpl::move_assign(&m4.as_pointer(), m1.as_pointer()) }); + ({ MoveAssignable::move_assign(&m4.as_pointer(), m1.as_pointer()) }); assert!(((m3.v == 7) && ({ (*m4.borrow()).v } == 7)) && ({ (*m1.borrow()).v } == 0)); let u: Value = Rc::new(RefCell::new({ let __v: Value = @@ -321,13 +454,13 @@ fn main_0() -> i32 { let mut u1: UserCopyDefaultMove = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - UserCopyDefaultMoveImpl::copy_from(&__v.as_pointer(), { u.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { u.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; let u2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - UserCopyDefaultMoveImpl::move_from(&__v.as_pointer(), { u.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { u.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!(((u1.v == 108) && ({ (*u2.borrow()).v } == 8)) && ({ (*u.borrow()).v } == 8)); @@ -343,8 +476,8 @@ fn main_0() -> i32 { UserCopyDefaultMoveImpl::construct(&__v.as_pointer(), { 1 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - ({ UserCopyDefaultMoveImpl::copy_assign(&u3.as_pointer(), u2.as_pointer()) }); - ({ UserCopyDefaultMoveImpl::move_assign(&u4.as_pointer(), u2.as_pointer()) }); + ({ CopyAssignable::copy_assign(&u3.as_pointer(), u2.as_pointer()) }); + ({ MoveAssignable::move_assign(&u4.as_pointer(), u2.as_pointer()) }); assert!(({ (*u3.borrow()).v } == 108) && ({ (*u4.borrow()).v } == 8)); let p: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); @@ -353,7 +486,7 @@ fn main_0() -> i32 { })); let q: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - BufferImpl::move_from(&__v.as_pointer(), { p.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { p.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!( @@ -368,7 +501,7 @@ fn main_0() -> i32 { BufferImpl::construct(&__v.as_pointer(), { 1 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - ({ BufferImpl::move_assign(&r.as_pointer(), q.as_pointer()) }); + ({ MoveAssignable::move_assign(&r.as_pointer(), q.as_pointer()) }); assert!( ({ ((({ (*r.borrow()).n } == 3) && ((*r.borrow()).data.len() == 3_usize)) @@ -393,7 +526,7 @@ fn main_0() -> i32 { { let __a1 = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - BufferImpl::move_from(&__v.as_pointer(), { r.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { r.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; (*bufs.borrow_mut()).push(__a1) @@ -402,7 +535,9 @@ fn main_0() -> i32 { let mut __tmp_2 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - BufferImpl::move_from(&__v.as_pointer(), { bufs.decay().offset(0_usize) }); + MoveConstructible::move_constructor(&__v.as_pointer(), { + bufs.decay().offset(0_usize) + }); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -429,7 +564,7 @@ fn main_0() -> i32 { }; let o2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - OwnerImpl::move_from(&__v.as_pointer(), { o1.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { o1.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!( @@ -446,7 +581,7 @@ fn main_0() -> i32 { }) ); let o3: Value = Rc::new(RefCell::new(::default())); - ({ OwnerImpl::move_assign(&o3.as_pointer(), o2.as_pointer()) }); + ({ MoveAssignable::move_assign(&o3.as_pointer(), o2.as_pointer()) }); assert!( ((({ (*o3.borrow()).n } == 5) && ((vec_elem!(o3.as_pointer(), data, 0_usize).read()) == 5)) @@ -465,13 +600,13 @@ fn main_0() -> i32 { let mut c2: Copyable = (*c1.borrow()).clone(); let c3: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyableImpl::move_from(&__v.as_pointer(), { c1.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { c1.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); 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())); - ({ CopyableImpl::move_assign(&c4.as_pointer(), c3.as_pointer()) }); + ({ MoveAssignable::move_assign(&c4.as_pointer(), c3.as_pointer()) }); assert!( ({ ((vec_elem!(c4.as_pointer(), data, 1_usize).read()) == 2) @@ -484,18 +619,18 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_h1 = - std::mem::DropGuard::new(h1.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(h1.clone(), |__p| Destructible::destroy(&__p.as_pointer())); { let _p: Ptr<_> = Ptr::alloc(9); field_ptr!(h1.as_pointer(), p).write(_p.to_owned_opt()) }; let h2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - HolderImpl::move_from(&__v.as_pointer(), { h1.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { h1.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_h2 = - std::mem::DropGuard::new(h2.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(h2.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!( ((({ (*h2.borrow()).inner.x } == 4) && ({ (*h2.borrow()).e.v } == 4)) && (({ (*h2.borrow()).p.clone() }.as_pointer().read()) == 9)) @@ -507,8 +642,8 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_h3 = - std::mem::DropGuard::new(h3.clone(), |__p| Destructible::destroy(__p.as_pointer())); - ({ HolderImpl::move_assign(&h3.as_pointer(), h2.as_pointer()) }); + std::mem::DropGuard::new(h3.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + ({ MoveAssignable::move_assign(&h3.as_pointer(), h2.as_pointer()) }); assert!( ((({ (*h3.borrow()).inner.x } == 4) && ((array_elem!(field_ptr!(h3.as_pointer(), e), arr, 1).read()) == 5)) @@ -519,8 +654,6 @@ fn main_0() -> i32 { } pub trait BufferImpl { fn construct(&self, n: i32); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl BufferImpl for Ptr { fn construct(&self, mut n: i32) { @@ -533,67 +666,17 @@ impl BufferImpl for Ptr { field!((*self), rows).with_mut(|__v: &mut Vec>| __v.push(a0_clone)) }; } - fn move_from(&self, _a0: Ptr) { - field!((*self), data).write(field!(_a0, data).with_mut(std::mem::take)); - field!((*self), rows).write(field!(_a0, rows).with_mut(std::mem::take)); - field!((*self), n).write({ (*_a0.upgrade().deref()).n }); - field!((*self), arr).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { - (*_a0.upgrade().deref()).arr[(__i) as usize] - }))); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), data).with_mut(|__b0| { - (*__b0) = field!(_a0, data).with_mut(std::mem::take); - }); - field!((*self), rows).with_mut(|__b0| { - (*__b0) = field!(_a0, rows).with_mut(std::mem::take); - }); - field!((*self), n).write({ (*_a0.upgrade().deref()).n }); - { - let mut __tmp_0 = { (array_field_ptr!((*self), arr)).to_any() }; - __tmp_0.memcpy(&(array_field_ptr!(_a0, arr)).to_any(), 8_usize); - (__tmp_0).clone() - }; - return (*self).clone(); - } -} -pub trait CopyableImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl CopyableImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), data).write(field!(_a0, data).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), data).with_mut(|__b0| { - (*__b0) = field!(_a0, data).with_mut(std::mem::take); - }); - return (*self).clone(); - } } pub trait DefaultCopyUserMoveImpl { fn construct(&self, v: i32); - fn move_from(&self, o: Ptr); - fn move_assign(&self, o: Ptr) -> Ptr; } impl DefaultCopyUserMoveImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(0); - } - fn move_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(0); - return (*self).clone(); - } } pub trait ExplicitImpl { fn construct(&self, v: i32); - fn destructor(&self); } impl ExplicitImpl for Ptr { fn construct(&self, mut v: i32) { @@ -601,13 +684,9 @@ impl ExplicitImpl for Ptr { field!((*self), inner).write(Inner { x: (v * 10) }); field!((*self), arr).write(Box::new([v, (v + 1)])); } - fn destructor(&self) {} } pub trait HolderImpl { fn construct(&self, v: i32); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; - fn destructor(&self); } impl HolderImpl for Ptr { fn construct(&self, mut v: i32) { @@ -619,78 +698,13 @@ impl HolderImpl for Ptr { }); field!((*self), p).write(None); } - fn move_from(&self, _a0: Ptr) { - field!((*self), inner).write({ (*_a0.upgrade().deref()).inner }); - field!((*self), e).write({ (*_a0.upgrade().deref()).e.clone() }); - field!((*self), p) - .write(field!(_a0, p).with_mut(|__v: &mut Option>| __v.take())); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), inner).write({ (*_a0.upgrade().deref()).inner }); - field!((*self), e).write({ (*_a0.upgrade().deref()).e.clone() }); - field!((*self), p).with_mut(|__b0| { - (*__b0) = field!(_a0, p).with_mut(|__v: &mut Option>| __v.take()); - }); - return (*self).clone(); - } - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, e)); - } -} -pub trait OwnerImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl OwnerImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), data).write(field!(_a0, data).with_mut(std::mem::take)); - field!((*self), n).write({ (*_a0.upgrade().deref()).n }); - field!((*self), arr).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { - (*_a0.upgrade().deref()).arr[(__i) as usize] - }))); - field!((*self), p) - .write(field!(_a0, p).with_mut(|__v: &mut Option>| __v.take())); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), data).with_mut(|__b0| { - (*__b0) = field!(_a0, data).with_mut(std::mem::take); - }); - field!((*self), n).write({ (*_a0.upgrade().deref()).n }); - { - let mut __tmp_1 = { (array_field_ptr!((*self), arr)).to_any() }; - __tmp_1.memcpy(&(array_field_ptr!(_a0, arr)).to_any(), 8_usize); - (__tmp_1).clone() - }; - field!((*self), p).with_mut(|__b0| { - (*__b0) = field!(_a0, p).with_mut(|__v: &mut Option>| __v.take()); - }); - return (*self).clone(); - } } pub trait UserCopyDefaultMoveImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, _a0: Ptr); - fn copy_assign(&self, o: Ptr) -> Ptr; - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl UserCopyDefaultMoveImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write((o.with(|__s| __s.v) + 100)); - } - fn move_from(&self, _a0: Ptr) { - field!((*self), v).write({ (*_a0.upgrade().deref()).v }); - } - fn copy_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write((o.with(|__s| __s.v) + 100)); - return (*self).clone(); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).write({ (*_a0.upgrade().deref()).v }); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index c2005f408e..eb16520b9a 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable, Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -15,12 +15,38 @@ pub struct NoCopy { #[offset(0)] pub v: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign)] +impl MoveConstructible for NoCopy { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(0); + } +} +impl MoveAssignable for NoCopy { + fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(0); + return (*this).clone(); + } +} +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] #[byte_size(4)] pub struct PrivateCopy { #[offset(0)] pub v: i32, } +impl MoveConstructible for PrivateCopy { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(0); + } +} +impl MoveAssignable for PrivateCopy { + fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(0); + return (*this).clone(); + } +} impl Default for PrivateCopy { fn default() -> Self { { @@ -32,7 +58,7 @@ impl Default for PrivateCopy { } } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] #[byte_size(4)] pub struct Immovable { #[offset(0)] @@ -49,7 +75,7 @@ impl Default for Immovable { } } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Default)] #[byte_size(8)] pub struct Container { #[offset(0)] @@ -58,13 +84,43 @@ pub struct Container { #[offset(4)] pub tag: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +impl MoveConstructible for Container { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), inner).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, inner) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + field!((*this), tag).write({ (*_a0.upgrade().deref()).tag }); + } +} +impl MoveAssignable for Container { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + ({ MoveAssignable::move_assign(&field_ptr!((*this), inner), field_ptr!(_a0, inner)) }); + field!((*this), tag).write({ (*_a0.upgrade().deref()).tag }); + return (*this).clone(); + } +} +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Default)] #[byte_size(24)] pub struct VecHolder { #[offset(0)] #[byte_size(24)] pub items: Vec, } +impl MoveConstructible for VecHolder { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), items).write(field!(_a0, items).with_mut(std::mem::take)); + } +} +impl MoveAssignable for VecHolder { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), items).with_mut(|__b0| { + (*__b0) = field!(_a0, items).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} pub fn bump_0(mut p: Ptr) { field!(p, v).with_mut(|__v| __v.postfix_inc()); } @@ -83,11 +139,11 @@ fn main_0() -> i32 { })); let b: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoCopyImpl::move_from(&__v.as_pointer(), { a.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!(({ (*b.borrow()).v } == 1) && ({ (*a.borrow()).v } == 0)); - ({ NoCopyImpl::move_assign(&a.as_pointer(), b.as_pointer()) }); + ({ MoveAssignable::move_assign(&a.as_pointer(), b.as_pointer()) }); assert!(({ (*a.borrow()).v } == 1) && ({ (*b.borrow()).v } == 0)); ({ bump_0((a.as_pointer())) }); assert!(({ (*a.borrow()).v } == 2)); @@ -99,11 +155,11 @@ fn main_0() -> i32 { (*p.borrow_mut()).v = 3; let q: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - PrivateCopyImpl::move_from(&__v.as_pointer(), { p.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { p.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!(({ (*q.borrow()).v } == 3) && ({ (*p.borrow()).v } == 0)); - ({ PrivateCopyImpl::move_assign(&p.as_pointer(), q.as_pointer()) }); + ({ 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({ let __v: Value = Rc::new(RefCell::new(::zero_init())); @@ -124,36 +180,27 @@ fn main_0() -> i32 { })); let mut d: Container = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ContainerImpl::move_from(&__v.as_pointer(), { c.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { c.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!(((d.inner.v == 6) && (d.tag == 7)) && ({ (*c.borrow()).inner.v } == 0)); let h: Value = Rc::new(RefCell::new(::default())); let mut h2: VecHolder = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - VecHolderImpl::move_from(&__v.as_pointer(), { h.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { h.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((h2.items.len() == 0_usize)); return 0; } -pub trait ContainerImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl ContainerImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), inner).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoCopyImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, inner) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - field!((*self), tag).write({ (*_a0.upgrade().deref()).tag }); +impl CopyAssignable for PrivateCopy { + fn copy_assign(_: &Ptr, _: Ptr) -> Ptr { + unreachable!("PrivateCopy::copy_assign is never defined") } - fn move_assign(&self, _a0: Ptr) -> Ptr { - ({ NoCopyImpl::move_assign(&field_ptr!((*self), inner), field_ptr!(_a0, inner)) }); - field!((*self), tag).write({ (*_a0.upgrade().deref()).tag }); - return (*self).clone(); +} +impl CopyConstructible for PrivateCopy { + fn copy_constructor(_: &Ptr, _: Ptr) { + unreachable!("PrivateCopy::copy_constructor is never defined") } } pub trait ImmovableImpl { @@ -166,61 +213,18 @@ impl ImmovableImpl for Ptr { } pub trait NoCopyImpl { fn construct(&self, v: i32); - fn move_from(&self, o: Ptr); - fn move_assign(&self, o: Ptr) -> Ptr; } impl NoCopyImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(0); - } - fn move_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(0); - return (*self).clone(); - } } pub trait PrivateCopyImpl { - fn copy_from(&self, _a0: Ptr) { - unimplemented!() - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - unimplemented!() - } fn construct(&self); - fn move_from(&self, o: Ptr); - fn move_assign(&self, o: Ptr) -> Ptr; } impl PrivateCopyImpl for Ptr { fn construct(&self) { field!((*self), v).write(0); } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(0); - } - fn move_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(0); - return (*self).clone(); - } -} -pub trait VecHolderImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl VecHolderImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), items).write(field!(_a0, items).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), items).with_mut(|__b0| { - (*__b0) = field!(_a0, items).with_mut(std::mem::take); - }); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/default.rs b/tests/unit/out/refcount/default.rs index 907c89f632..10ee070fdd 100644 --- a/tests/unit/out/refcount/default.rs +++ b/tests/unit/out/refcount/default.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(144)] pub struct Pointers { #[offset(0)] @@ -43,7 +43,7 @@ impl Default for Pointers { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(440)] pub struct SmallArrays { #[offset(0)] @@ -78,7 +78,7 @@ impl Default for SmallArrays { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 a015bd1070..8c572b8024 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -12,7 +12,18 @@ pub fn foo_0(mut a: i32, mut b: i32) -> i32 { pub fn baz_1(mut a: Ptr, mut b: Ptr) -> bool { return ({ a } == { b }); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Bar { @@ -58,7 +69,18 @@ pub fn shifted_8(mut x: i32, mut y: i32) -> i32 { pub fn first_9(r: Ptr) -> i32 { return (elem!(r, 0).read()); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Holder_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/default_in_statics.rs b/tests/unit/out/refcount/default_in_statics.rs index cabc3838b4..0c8459ddbd 100644 --- a/tests/unit/out/refcount/default_in_statics.rs +++ b/tests/unit/out/refcount/default_in_statics.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Inner { #[offset(0)] @@ -15,7 +17,7 @@ pub struct Inner { #[byte_size(8)] pub name: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(88)] pub struct Outer { #[offset(0)] @@ -61,7 +63,9 @@ impl Default for Outer { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(40)] pub struct Foo { #[offset(0)] diff --git a/tests/unit/out/refcount/delete_array_order.rs b/tests/unit/out/refcount/delete_array_order.rs index 49b00ccf5b..fae54fc406 100644 --- a/tests/unit/out/refcount/delete_array_order.rs +++ b/tests/unit/out/refcount/delete_array_order.rs @@ -6,7 +6,7 @@ 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, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct Element { #[offset(0)] @@ -14,6 +14,15 @@ pub struct Element { #[offset(8)] pub value: i64, } +impl Destructible for Element { + fn destroy(this: &Ptr) { + printf!( + b"%ld:%ld ", + (*this).with(|__s| __s.id), + (*this).with(|__s| __s.value) + ); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -36,23 +45,11 @@ fn main_0() -> i32 { { let __p = a; for __i in (0..__p.len()).rev() { - Destructible::destroy(__p.offset(__i as isize)); + Destructible::destroy(&__p.offset(__i as isize)); } __p.delete(); }; printf!(b"\n"); return 0; } -pub trait ElementImpl { - fn destructor(&self); -} -impl ElementImpl for Ptr { - fn destructor(&self) { - printf!( - b"%ld:%ld ", - (*self).with(|__s| __s.id), - (*self).with(|__s| __s.value) - ); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index 4ac2b27a80..8f71a9300c 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -9,31 +9,51 @@ use std::rc::{Rc, Weak}; thread_local!( pub static global_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct S {} -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +impl Destructible for S { + fn destroy(this: &Ptr) { + (*global_0.with(Value::clone).borrow_mut()).postfix_inc(); + } +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct Defaulted { #[offset(0)] #[byte_size(1)] pub s: S, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +impl Destructible for Defaulted { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, s)); + } +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct Middle { #[offset(0)] #[byte_size(1)] pub s: S, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +impl Destructible for Middle { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, s)); + } +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct Outer { #[offset(0)] #[byte_size(1)] pub m: Middle, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible)] +impl Destructible for Outer { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, m)); + } +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(3)] pub struct ArrayMember { #[offset(0)] @@ -41,6 +61,11 @@ pub struct ArrayMember { #[array_len(3)] pub items: Box<[S]>, } +impl Destructible for ArrayMember { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, items)); + } +} impl Default for ArrayMember { fn default() -> Self { { @@ -50,31 +75,61 @@ impl Default for ArrayMember { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct EmptyBody { #[offset(0)] #[byte_size(1)] pub s: S, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +impl Destructible for EmptyBody { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, s)); + } +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct Templated_char_ { #[offset(0)] pub v: i8, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +impl Destructible for Templated_char_ { + fn destroy(this: &Ptr) { + global_0.with(|rc| { + *rc.borrow_mut() = { + ((global_0.with(|rc| *rc.borrow()) as usize) + .wrapping_add((::std::mem::size_of::() as usize))) as i32 + } + }); + } +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct Templated_int_ { #[offset(0)] pub v: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +impl Destructible for Templated_int_ { + fn destroy(this: &Ptr) { + global_0.with(|rc| { + *rc.borrow_mut() = { + ((global_0.with(|rc| *rc.borrow()) as usize) + .wrapping_add((::std::mem::size_of::() as usize))) as i32 + } + }); + } +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct Copied { #[offset(0)] pub v: i32, } +impl Destructible for Copied { + fn destroy(this: &Ptr) { + (*global_0.with(Value::clone).borrow_mut()).postfix_inc(); + } +} thread_local!( pub static order_1: Value> = Rc::new(RefCell::new((0..3).map(|_| 0_i32).collect::>())); @@ -82,13 +137,20 @@ thread_local!( thread_local!( pub static order_count_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct Tagged { #[offset(0)] pub tag: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +impl Destructible for Tagged { + fn destroy(this: &Ptr) { + (*order_1.with(Value::clone).borrow_mut()) + [((*order_count_2.with(Value::clone).borrow_mut()).postfix_inc()) as usize] = + (*this).with(|__s| __s.tag); + } +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(20)] pub struct Ordered { #[offset(0)] @@ -105,6 +167,13 @@ pub struct Ordered { #[byte_size(4)] pub third: Tagged, } +impl Destructible for Ordered { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, third)); + Destructible::destroy(&field_ptr!(this, second)); + Destructible::destroy(&field_ptr!(this, first)); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -113,55 +182,55 @@ fn main_0() -> i32 { { let s: Value = Rc::new(RefCell::new(::default())); let _dtor_s = - std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(&__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 1)); { let s: Value = Rc::new(RefCell::new(::default())); let _dtor_s = - std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(&__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 2)); { let d: Value = Rc::new(RefCell::new(::default())); let _dtor_d = - std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(&__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 3)); { let o: Value = Rc::new(RefCell::new(::default())); let _dtor_o = - std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(&__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 4)); { let am: Value = Rc::new(RefCell::new(::default())); let _dtor_am = - std::mem::DropGuard::new(am.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(am.clone(), |__p| Destructible::destroy(&__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 7)); { let e: Value = Rc::new(RefCell::new(::default())); let _dtor_e = - std::mem::DropGuard::new(e.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(e.clone(), |__p| Destructible::destroy(&__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 8)); { let tc: Value = Rc::new(RefCell::new(::default())); let _dtor_tc = - std::mem::DropGuard::new(tc.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(tc.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let ti: Value = Rc::new(RefCell::new(::default())); let _dtor_ti = - std::mem::DropGuard::new(ti.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(ti.clone(), |__p| Destructible::destroy(&__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 13)); { let a: Value = Rc::new(RefCell::new(Copied { v: 5 })); let _dtor_a = - std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let b: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_b = - std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!(({ (*b.borrow()).v } == 5)); } assert!((global_0.with(|rc| *rc.borrow()) == 15)); @@ -174,7 +243,7 @@ fn main_0() -> i32 { third: Tagged { tag: 3 }, })); let _dtor_o = - std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(&__p.as_pointer())); } assert!((order_count_2.with(|rc| *rc.borrow()) == 3)); assert!( @@ -199,113 +268,11 @@ fn main_0() -> i32 { { let cs: Value = Rc::new(RefCell::new(::default())); let _dtor_cs = - std::mem::DropGuard::new(cs.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(cs.clone(), |__p| Destructible::destroy(&__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == (before + 1))); return 0; } -pub trait ArrayMemberImpl { - fn destructor(&self); -} -impl ArrayMemberImpl for Ptr { - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, items)); - } -} -pub trait CopiedImpl { - fn destructor(&self); -} -impl CopiedImpl for Ptr { - fn destructor(&self) { - (*global_0.with(Value::clone).borrow_mut()).postfix_inc(); - } -} -pub trait DefaultedImpl { - fn destructor(&self); -} -impl DefaultedImpl for Ptr { - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, s)); - } -} -pub trait EmptyBodyImpl { - fn destructor(&self); -} -impl EmptyBodyImpl for Ptr { - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, s)); - } -} -pub trait MiddleImpl { - fn destructor(&self); -} -impl MiddleImpl for Ptr { - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, s)); - } -} -pub trait OrderedImpl { - fn destructor(&self); -} -impl OrderedImpl for Ptr { - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, third)); - Destructible::destroy(field_ptr!(self, second)); - Destructible::destroy(field_ptr!(self, first)); - } -} -pub trait OuterImpl { - fn destructor(&self); -} -impl OuterImpl for Ptr { - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, m)); - } -} -pub trait SImpl { - fn destructor(&self); -} -impl SImpl for Ptr { - fn destructor(&self) { - (*global_0.with(Value::clone).borrow_mut()).postfix_inc(); - } -} -pub trait TaggedImpl { - fn destructor(&self); -} -impl TaggedImpl for Ptr { - fn destructor(&self) { - (*order_1.with(Value::clone).borrow_mut()) - [((*order_count_2.with(Value::clone).borrow_mut()).postfix_inc()) as usize] = - (*self).with(|__s| __s.tag); - } -} -pub trait Templated_char_Impl { - fn destructor(&self); -} -impl Templated_char_Impl for Ptr { - fn destructor(&self) { - global_0.with(|rc| { - *rc.borrow_mut() = { - ((global_0.with(|rc| *rc.borrow()) as usize) - .wrapping_add((::std::mem::size_of::() as usize))) as i32 - } - }); - } -} -pub trait Templated_int_Impl { - fn destructor(&self); -} -impl Templated_int_Impl for Ptr { - fn destructor(&self) { - global_0.with(|rc| { - *rc.borrow_mut() = { - ((global_0.with(|rc| *rc.borrow()) as usize) - .wrapping_add((::std::mem::size_of::() as usize))) as i32 - } - }); - } -} pub fn __cpp2rust_init_globals() { let _ = global_0.with(|_| ()); let _ = order_1.with(|_| ()); diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index ee4c0cc0cb..bdeac71267 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -12,12 +12,18 @@ thread_local!( thread_local!( pub static last_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct S { #[offset(0)] pub v: i32, } +impl Destructible for S { + fn destroy(this: &Ptr) { + (*destroyed_0.with(Value::clone).borrow_mut()).postfix_inc(); + last_1.with(|rc| *rc.borrow_mut() = (*this).with(|__s| __s.v)); + } +} pub fn by_value_2(s: S) -> i32 { let s: Value = Rc::new(RefCell::new(s)); assert!((destroyed_0.with(|rc| *rc.borrow()) == 0)); @@ -27,7 +33,18 @@ pub fn with_default_3(s: S) -> i32 { let s: Value = Rc::new(RefCell::new(s)); return { (*s.borrow()).v }; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Holder { #[offset(0)] @@ -41,7 +58,7 @@ fn main_0() -> i32 { { let s: Value = Rc::new(RefCell::new(S { v: 1 })); let _dtor_s = - std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!((({ by_value_2({ (*s.borrow()).clone() },) }) == 1)); assert!( (destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 1) @@ -86,15 +103,6 @@ impl HolderImpl for Ptr { return ((*self).with(|__s| __s.v) + { (*s.borrow()).v }); } } -pub trait SImpl { - fn destructor(&self); -} -impl SImpl for Ptr { - fn destructor(&self) { - (*destroyed_0.with(Value::clone).borrow_mut()).postfix_inc(); - last_1.with(|rc| *rc.borrow_mut() = (*self).with(|__s| __s.v)); - } -} pub fn __cpp2rust_init_globals() { let _ = destroyed_0.with(|_| ()); let _ = last_1.with(|_| ()); diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index 382cd76114..c25682cce1 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -12,13 +12,19 @@ thread_local!( thread_local!( pub static last_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct S { #[offset(0)] pub v: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +impl Destructible for S { + fn destroy(this: &Ptr) { + (*destroyed_0.with(Value::clone).borrow_mut()).postfix_inc(); + last_1.with(|rc| *rc.borrow_mut() = (*this).with(|__s| __s.v)); + } +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Outer { #[offset(0)] @@ -27,6 +33,11 @@ pub struct Outer { #[offset(4)] pub w: i32, } +impl Destructible for Outer { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, inner)); + } +} pub fn make_2(mut v: i32) -> S { return S { v: v }; } @@ -116,7 +127,7 @@ fn main_0() -> i32 { { let s: Value = Rc::new(RefCell::new(S { v: 12 })); let _dtor_s = - std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let __rhs = ({ make_2(13) }); (*s.borrow_mut()) = __rhs; assert!( @@ -127,23 +138,10 @@ fn main_0() -> i32 { assert!((destroyed_0.with(|rc| *rc.borrow()) == 2) && (last_1.with(|rc| *rc.borrow()) == 13)); return 0; } -pub trait OuterImpl { - fn destructor(&self); -} -impl OuterImpl for Ptr { - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, inner)); - } -} pub trait SImpl { - fn destructor(&self); fn get(&self) -> i32; } impl SImpl for Ptr { - fn destructor(&self) { - (*destroyed_0.with(Value::clone).borrow_mut()).postfix_inc(); - last_1.with(|rc| *rc.borrow_mut() = (*self).with(|__s| __s.v)); - } fn get(&self) -> i32 { return (*self).with(|__s| __s.v); } diff --git a/tests/unit/out/refcount/doubly_linked_list.rs b/tests/unit/out/refcount/doubly_linked_list.rs index 827ab5b981..2f8d9f12dc 100644 --- a/tests/unit/out/refcount/doubly_linked_list.rs +++ b/tests/unit/out/refcount/doubly_linked_list.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(24)] pub struct Node { #[offset(0)] diff --git a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs index 2db8397828..144e6264c0 100644 --- a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs @@ -43,7 +43,7 @@ fn main_0() -> i32 { for __i in (1..__n).rev() { let __j = (std::hash::BuildHasher::hash_one(&__random, __i) % (__i + 1) as u64) as isize; - cpp_swap!(__tmp_3.iter_at(__i), __tmp_3.iter_at(__j)); + Swappable::swap(&__tmp_3.iter_at(__i), __tmp_3.iter_at(__j)); } }; { diff --git a/tests/unit/out/refcount/enum_default_in_static.rs b/tests/unit/out/refcount/enum_default_in_static.rs index bbfeeb0727..0c83cd09dc 100644 --- a/tests/unit/out/refcount/enum_default_in_static.rs +++ b/tests/unit/out/refcount/enum_default_in_static.rs @@ -10,7 +10,18 @@ pub type Mode = u32; 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Config { #[offset(0)] diff --git a/tests/unit/out/refcount/enum_int_interop.rs b/tests/unit/out/refcount/enum_int_interop.rs index fb4ecd5f32..65ea7203a7 100644 --- a/tests/unit/out/refcount/enum_int_interop.rs +++ b/tests/unit/out/refcount/enum_int_interop.rs @@ -19,7 +19,9 @@ pub type Tag = u32; 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, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Entry { #[offset(0)] diff --git a/tests/unit/out/refcount/enum_int_interop_c.rs b/tests/unit/out/refcount/enum_int_interop_c.rs index 3e6628f69c..88326b8ab0 100644 --- a/tests/unit/out/refcount/enum_int_interop_c.rs +++ b/tests/unit/out/refcount/enum_int_interop_c.rs @@ -19,7 +19,9 @@ pub type Tag_enum = u32; 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, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Entry { #[offset(0)] diff --git a/tests/unit/out/refcount/enum_underlying_type.rs b/tests/unit/out/refcount/enum_underlying_type.rs index b7f3132c3c..289812f810 100644 --- a/tests/unit/out/refcount/enum_underlying_type.rs +++ b/tests/unit/out/refcount/enum_underlying_type.rs @@ -25,7 +25,9 @@ pub type Scoped = i8; pub const Scoped_NEG: Scoped = -2; pub const Scoped_POS: Scoped = 2; pub type Empty = bool; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(1)] pub struct HoldsEmpty { #[offset(0)] diff --git a/tests/unit/out/refcount/exprs.rs b/tests/unit/out/refcount/exprs.rs index 4e234f4962..fbd6ae2577 100644 --- a/tests/unit/out/refcount/exprs.rs +++ b/tests/unit/out/refcount/exprs.rs @@ -6,13 +6,26 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct X { #[offset(0)] pub x: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Y { #[offset(0)] diff --git a/tests/unit/out/refcount/fft.rs b/tests/unit/out/refcount/fft.rs index e59b50a1cb..d2b9250904 100644 --- a/tests/unit/out/refcount/fft.rs +++ b/tests/unit/out/refcount/fft.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct Complex { #[offset(0)] diff --git a/tests/unit/out/refcount/field_aliasing.rs b/tests/unit/out/refcount/field_aliasing.rs index e367fbe455..76304864d6 100644 --- a/tests/unit/out/refcount/field_aliasing.rs +++ b/tests/unit/out/refcount/field_aliasing.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct In { #[offset(0)] @@ -14,7 +25,7 @@ pub struct In { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(32)] pub struct S { #[offset(0)] @@ -41,7 +52,9 @@ impl Default for S { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Node { #[offset(0)] diff --git a/tests/unit/out/refcount/field_array_elem_ptr.rs b/tests/unit/out/refcount/field_array_elem_ptr.rs index c16d51922f..ce1212d113 100644 --- a/tests/unit/out/refcount/field_array_elem_ptr.rs +++ b/tests/unit/out/refcount/field_array_elem_ptr.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -14,7 +25,7 @@ pub struct Point { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 a4ce080c59..fa79395ec9 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -6,13 +6,35 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Counter { #[offset(0)] pub n: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, +)] #[byte_size(40)] pub struct S { #[offset(0)] @@ -28,6 +50,31 @@ pub struct S { #[byte_size(24)] pub v: Vec, } +impl MoveConstructible for S { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), tag).write({ (*_a0.upgrade().deref()).tag }); + field!((*this), c).write({ (*_a0.upgrade().deref()).c }); + field!((*this), arr).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { + (*_a0.upgrade().deref()).arr[(__i) as usize] + }))); + field!((*this), v).write(field!(_a0, v).with_mut(std::mem::take)); + } +} +impl MoveAssignable for S { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), tag).write({ (*_a0.upgrade().deref()).tag }); + field!((*this), c).write({ (*_a0.upgrade().deref()).c }); + { + let mut __tmp_0 = { (array_field_ptr!((*this), arr)).to_any() }; + __tmp_0.memcpy(&(array_field_ptr!(_a0, arr)).to_any(), 8_usize); + (__tmp_0).clone() + }; + field!((*this), v).with_mut(|__b0| { + (*__b0) = field!(_a0, v).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} impl Default for S { fn default() -> Self { { @@ -117,33 +164,10 @@ impl CounterImpl for Ptr { } pub trait SImpl { fn bump(&self); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl SImpl for Ptr { fn bump(&self) { ({ CounterImpl::add(&field_ptr!((*self), c), (*self).with(|__s| __s.tag)) }); } - fn move_from(&self, _a0: Ptr) { - field!((*self), tag).write({ (*_a0.upgrade().deref()).tag }); - field!((*self), c).write({ (*_a0.upgrade().deref()).c }); - field!((*self), arr).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { - (*_a0.upgrade().deref()).arr[(__i) as usize] - }))); - field!((*self), v).write(field!(_a0, v).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), tag).write({ (*_a0.upgrade().deref()).tag }); - field!((*self), c).write({ (*_a0.upgrade().deref()).c }); - { - let mut __tmp_0 = { (array_field_ptr!((*self), arr)).to_any() }; - __tmp_0.memcpy(&(array_field_ptr!(_a0, arr)).to_any(), 8_usize); - (__tmp_0).clone() - }; - field!((*self), v).with_mut(|__b0| { - (*__b0) = field!(_a0, v).with_mut(std::mem::take); - }); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index 30c229b036..a786847e46 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(12)] pub struct Inner { #[offset(0)] @@ -26,7 +26,18 @@ impl Default for Inner { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Header { #[offset(0)] @@ -34,7 +45,18 @@ pub struct Header { #[offset(4)] pub size: i16, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, +)] #[byte_size(104)] pub struct Outer { #[offset(0)] @@ -57,6 +79,41 @@ pub struct Outer { #[array_len(4)] pub buf: Box<[i32]>, } +impl MoveConstructible for Outer { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), x).write({ (*_a0.upgrade().deref()).x }); + field!((*this), inner).write({ (*_a0.upgrade().deref()).inner.clone() }); + field!((*this), items).write(Box::new(std::array::from_fn::<_, 3, _>(|__i: usize| { + ((*_a0.upgrade().deref()).items[(__i) as usize]).clone() + }))); + field!((*this), v).write(field!(_a0, v).with_mut(std::mem::take)); + field!((*this), cursor).write({ (*_a0.upgrade().deref()).cursor.clone() }); + field!((*this), buf).write(Box::new(std::array::from_fn::<_, 4, _>(|__i: usize| { + (*_a0.upgrade().deref()).buf[(__i) as usize] + }))); + } +} +impl MoveAssignable for Outer { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), x).write({ (*_a0.upgrade().deref()).x }); + field!((*this), inner).write({ (*_a0.upgrade().deref()).inner.clone() }); + { + let mut __tmp_0 = { (array_field_ptr!((*this), items)).to_any() }; + __tmp_0.memcpy(&(array_field_ptr!(_a0, items)).to_any(), 36_usize); + (__tmp_0).clone() + }; + field!((*this), v).with_mut(|__b0| { + (*__b0) = field!(_a0, v).with_mut(std::mem::take); + }); + field!((*this), cursor).write({ (*_a0.upgrade().deref()).cursor.clone() }); + { + let mut __tmp_1 = { (array_field_ptr!((*this), buf)).to_any() }; + __tmp_1.memcpy(&(array_field_ptr!(_a0, buf)).to_any(), 16_usize); + (__tmp_1).clone() + }; + return (*this).clone(); + } +} impl Default for Outer { fn default() -> Self { { @@ -212,8 +269,6 @@ pub trait OuterImpl { fn next(&self) -> i32; fn sum(&self) -> i32; fn push(&self, k: i32); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl OuterImpl for Ptr { fn next(&self) -> i32 { @@ -233,36 +288,5 @@ impl OuterImpl for Ptr { field!((*self), v).with_mut(|__v: &mut Vec| __v.push(__a1)) }; } - fn move_from(&self, _a0: Ptr) { - field!((*self), x).write({ (*_a0.upgrade().deref()).x }); - field!((*self), inner).write({ (*_a0.upgrade().deref()).inner.clone() }); - field!((*self), items).write(Box::new(std::array::from_fn::<_, 3, _>(|__i: usize| { - ((*_a0.upgrade().deref()).items[(__i) as usize]).clone() - }))); - field!((*self), v).write(field!(_a0, v).with_mut(std::mem::take)); - field!((*self), cursor).write({ (*_a0.upgrade().deref()).cursor.clone() }); - field!((*self), buf).write(Box::new(std::array::from_fn::<_, 4, _>(|__i: usize| { - (*_a0.upgrade().deref()).buf[(__i) as usize] - }))); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), x).write({ (*_a0.upgrade().deref()).x }); - field!((*self), inner).write({ (*_a0.upgrade().deref()).inner.clone() }); - { - let mut __tmp_0 = { (array_field_ptr!((*self), items)).to_any() }; - __tmp_0.memcpy(&(array_field_ptr!(_a0, items)).to_any(), 36_usize); - (__tmp_0).clone() - }; - field!((*self), v).with_mut(|__b0| { - (*__b0) = field!(_a0, v).with_mut(std::mem::take); - }); - field!((*self), cursor).write({ (*_a0.upgrade().deref()).cursor.clone() }); - { - let mut __tmp_1 = { (array_field_ptr!((*self), buf)).to_any() }; - __tmp_1.memcpy(&(array_field_ptr!(_a0, buf)).to_any(), 16_usize); - (__tmp_1).clone() - }; - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/field_pointers_malloced_struct.rs b/tests/unit/out/refcount/field_pointers_malloced_struct.rs index 57d6b0f8d2..7841b69904 100644 --- a/tests/unit/out/refcount/field_pointers_malloced_struct.rs +++ b/tests/unit/out/refcount/field_pointers_malloced_struct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(12)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/field_reinterpret_write_through.rs b/tests/unit/out/refcount/field_reinterpret_write_through.rs index f8bfab8fe5..5118789f6b 100644 --- a/tests/unit/out/refcount/field_reinterpret_write_through.rs +++ b/tests/unit/out/refcount/field_reinterpret_write_through.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct In { #[offset(0)] @@ -14,7 +25,7 @@ pub struct In { #[offset(4)] pub b: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 b1b2b36bdb..9ffe9bbeb8 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct P { #[offset(0)] 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 81358273ee..856f139bd7 100644 --- a/tests/unit/out/refcount/first_field_ptr_covers_struct.rs +++ b/tests/unit/out/refcount/first_field_ptr_covers_struct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct In { #[offset(0)] @@ -14,7 +25,18 @@ pub struct In { #[offset(2)] pub b: i16, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(12)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/first_member_downcast.rs b/tests/unit/out/refcount/first_member_downcast.rs index 0e766a79e7..195568f94f 100644 --- a/tests/unit/out/refcount/first_member_downcast.rs +++ b/tests/unit/out/refcount/first_member_downcast.rs @@ -6,13 +6,35 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct base { #[offset(0)] pub kind: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct derived { #[offset(0)] diff --git a/tests/unit/out/refcount/flex_array_member_incomplete.rs b/tests/unit/out/refcount/flex_array_member_incomplete.rs index 1be33956bd..f1cd55656c 100644 --- a/tests/unit/out/refcount/flex_array_member_incomplete.rs +++ b/tests/unit/out/refcount/flex_array_member_incomplete.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 443107535a..fb2308cf26 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,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -26,7 +26,18 @@ impl Default for S { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct E { #[offset(0)] @@ -34,7 +45,7 @@ pub struct E { #[offset(4)] pub w: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 28d06980e6..8b4fab1644 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -28,7 +28,18 @@ pub fn call_fn_5(mut f: FnPtr usize>, mut v: i32) -> usize { pub fn identity_hash_6(mut v: bool) -> usize { return (v as usize); } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(FnPtr u64 > , construct, ptr)] #[byte_size(8)] pub struct HashHolder_unsigned_long__ptr__bool__ { diff --git a/tests/unit/out/refcount/fn_ptr_cast.rs b/tests/unit/out/refcount/fn_ptr_cast.rs index 72fe1d2075..4795535e3a 100644 --- a/tests/unit/out/refcount/fn_ptr_cast.rs +++ b/tests/unit/out/refcount/fn_ptr_cast.rs @@ -24,7 +24,9 @@ pub fn test_double_cast_2() { assert!((({ fn2.call(5,) }) == 10)); assert!(({ (fn2).clone() } == { (fn_).clone() })); } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Command { #[offset(0)] diff --git a/tests/unit/out/refcount/fn_ptr_stable_sort.rs b/tests/unit/out/refcount/fn_ptr_stable_sort.rs index aa4abe2bfa..fd8cbc9470 100644 --- a/tests/unit/out/refcount/fn_ptr_stable_sort.rs +++ b/tests/unit/out/refcount/fn_ptr_stable_sort.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Item { #[offset(0)] diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index e01ed25ebb..5b5a84f3c8 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Handler { #[offset(0)] @@ -21,7 +23,18 @@ pub fn double_it_0(mut x: i32) -> i32 { pub fn negate_1(mut x: i32) -> i32 { return -x; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct S {} impl S { @@ -35,13 +48,19 @@ impl S { return (x + 3); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub data_: i32, } +impl MoveConstructible for MoveOnly { + fn move_constructor(this: &Ptr, x: Ptr) { + field!((*this), data_).write(x.with(|__s| __s.data_)); + field!(x, data_).write(0); + } +} pub fn make_move_only_2() -> MoveOnly { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); @@ -97,7 +116,7 @@ fn main_0() -> i32 { ({ sc.call({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::move_from(&__v.as_pointer(), { m.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { m.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }), @@ -108,17 +127,12 @@ fn main_0() -> i32 { } pub trait MoveOnlyImpl { fn construct(&self, data: i32); - fn move_from(&self, x: Ptr); fn get(&self) -> i32; } impl MoveOnlyImpl for Ptr { fn construct(&self, mut data: i32) { field!((*self), data_).write(data); } - fn move_from(&self, x: Ptr) { - field!((*self), data_).write(x.with(|__s| __s.data_)); - field!(x, data_).write(0); - } fn get(&self) -> i32 { return (*self).with(|__s| __s.data_); } diff --git a/tests/unit/out/refcount/fn_ptr_typedef_cast.rs b/tests/unit/out/refcount/fn_ptr_typedef_cast.rs index a72c15adba..b8085c2601 100644 --- a/tests/unit/out/refcount/fn_ptr_typedef_cast.rs +++ b/tests/unit/out/refcount/fn_ptr_typedef_cast.rs @@ -18,7 +18,18 @@ pub fn via_size_t_param_2(mut b: usize) -> u64 { pub fn via_size_t_return_3(mut b: u64) -> usize { return (b as usize); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct pair { #[offset(0)] diff --git a/tests/unit/out/refcount/fn_ptr_vtable.rs b/tests/unit/out/refcount/fn_ptr_vtable.rs index b9281b2847..1e96ee5819 100644 --- a/tests/unit/out/refcount/fn_ptr_vtable.rs +++ b/tests/unit/out/refcount/fn_ptr_vtable.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(24)] pub struct Vtable { #[offset(0)] diff --git a/tests/unit/out/refcount/fn_ref.rs b/tests/unit/out/refcount/fn_ref.rs index e00efd7f20..bc8234aaf6 100644 --- a/tests/unit/out/refcount/fn_ref.rs +++ b/tests/unit/out/refcount/fn_ref.rs @@ -21,7 +21,9 @@ pub fn call_deduced_3(f: FnPtr i32>, mut x: i32) -> i32 { pub fn call_forwarded_4(f: FnPtr i32>, mut x: i32) -> i32 { return ({ f.call(x) }); } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/for_body_destructor.rs b/tests/unit/out/refcount/for_body_destructor.rs index 986304af95..c0b9801e5b 100644 --- a/tests/unit/out/refcount/for_body_destructor.rs +++ b/tests/unit/out/refcount/for_body_destructor.rs @@ -6,12 +6,17 @@ 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, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct Guard { #[offset(0)] pub digit: i32, } +impl Destructible for Guard { + fn destroy(this: &Ptr) { + printf!(b"%d ", (*this).with(|__s| __s.digit)); + } +} pub fn step_0(i: Ptr) { printf!(b"9 "); i.with_mut(|__v| { @@ -30,11 +35,11 @@ fn main_0() -> i32 { 'for_body: { let first: Value = Rc::new(RefCell::new(Guard { digit: 1 })); let _dtor_first = std::mem::DropGuard::new(first.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); let second: Value = Rc::new(RefCell::new(Guard { digit: 2 })); let _dtor_second = std::mem::DropGuard::new(second.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); if ((*i.borrow()) == 0) { break 'for_body; @@ -50,7 +55,7 @@ fn main_0() -> i32 { 'for_body: { let g: Value = Rc::new(RefCell::new(Guard { digit: 3 })); let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); break 'loop_; } @@ -64,7 +69,7 @@ fn main_0() -> i32 { 'for_body: { let outer: Value = Rc::new(RefCell::new(Guard { digit: 4 })); let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); { let j: Value = Rc::new(RefCell::new(0)); @@ -72,7 +77,7 @@ fn main_0() -> i32 { 'for_body: { let inner: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); if ((*j.borrow()) == 0) { break 'for_body; @@ -94,13 +99,13 @@ fn main_0() -> i32 { 'for_body: { let outer: Value = Rc::new(RefCell::new(Guard { digit: 4 })); let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); let mut j: i32 = 0; 'loop_: while ((*j.prefix_inc()) < 3) { let inner: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); if (j == 1) { continue 'loop_; @@ -112,7 +117,7 @@ fn main_0() -> i32 { __do_while = false; let inner: Value = Rc::new(RefCell::new(Guard { digit: 6 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); continue 'loop_; } @@ -123,7 +128,7 @@ fn main_0() -> i32 { let mut value: i32 = (value.read()); let inner: Value = Rc::new(RefCell::new(Guard { digit: value })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); if (value == 1) { continue 'loop_; @@ -141,7 +146,7 @@ fn main_0() -> i32 { 'loop_: loop { let condition: Value = Rc::new(RefCell::new(Guard { digit: i })); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); if !({ GuardImpl::to_bool(&condition.as_pointer()) }) { break; @@ -149,7 +154,7 @@ fn main_0() -> i32 { 'for_body: { let body: Value = Rc::new(RefCell::new(Guard { digit: 4 })); let _dtor_body = std::mem::DropGuard::new(body.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); if (i == 2) { break 'for_body; @@ -166,12 +171,12 @@ fn main_0() -> i32 { { let init: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_init = - std::mem::DropGuard::new(init.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(init.clone(), |__p| Destructible::destroy(&__p.as_pointer())); 'loop_: while ((*i.borrow()) < 2) { 'for_body: { let body: Value = Rc::new(RefCell::new(Guard { digit: 6 })); let _dtor_body = std::mem::DropGuard::new(body.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); } ({ step_0(i.as_pointer()) }); @@ -185,7 +190,7 @@ fn main_0() -> i32 { digit: (*j.prefix_inc()), })); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); continue 'loop_; } } @@ -193,13 +198,9 @@ fn main_0() -> i32 { return 0; } pub trait GuardImpl { - fn destructor(&self); fn to_bool(&self) -> bool; } impl GuardImpl for Ptr { - fn destructor(&self) { - printf!(b"%d ", (*self).with(|__s| __s.digit)); - } fn to_bool(&self) -> bool { return ((*self).with(|__s| __s.digit) != 0); } diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index fb614609a0..418f5f7166 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(32)] pub struct S { @@ -17,6 +27,21 @@ pub struct S { #[offset(24)] pub a: i32, } +impl MoveConstructible for S { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), v).write(field!(_a0, v).with_mut(std::mem::take)); + field!((*this), a).write({ (*_a0.upgrade().deref()).a }); + } +} +impl MoveAssignable for S { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).with_mut(|__b0| { + (*__b0) = field!(_a0, v).with_mut(std::mem::take); + }); + field!((*this), a).write({ (*_a0.upgrade().deref()).a }); + return (*this).clone(); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -36,21 +61,4 @@ fn main_0() -> i32 { } return 0; } -pub trait SImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl SImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), v).write(field!(_a0, v).with_mut(std::mem::take)); - field!((*self), a).write({ (*_a0.upgrade().deref()).a }); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).with_mut(|__b0| { - (*__b0) = field!(_a0, v).with_mut(std::mem::take); - }); - field!((*self), a).write({ (*_a0.upgrade().deref()).a }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index ee9c29495f..9a48c48c83 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -9,7 +9,19 @@ use std::rc::{Rc, Weak}; pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct Tracked { @@ -20,6 +32,21 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl CopyConstructible for Tracked { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); + field!((*this), moves).write(o.with(|__s| __s.moves)); + } +} +impl MoveConstructible for Tracked { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write(o.with(|__s| __s.copies)); + field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + field!(o, v).write(0); + } +} impl Clone for Tracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Tracked { @@ -28,7 +55,7 @@ impl Clone for Tracked { moves: self.moves.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -39,7 +66,19 @@ pub fn chosen_overload_1(_a0: Ptr) -> Overload { return Overload_kRvalueOverload; } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyConstructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, )] #[cpp_from(Tracked, construct_1, mut_ptr)] #[cpp_from_move(Tracked, construct_2, ptr)] @@ -49,6 +88,15 @@ pub struct Holder { #[byte_size(12)] pub t: Tracked, } +impl MoveConstructible for Holder { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), t).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, t) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + } +} pub fn forward_once_2(x: Ptr) -> Overload { return ({ chosen_overload_0((x).clone()) }); } @@ -147,35 +195,25 @@ fn main_0() -> i32 { pub trait HolderImpl { fn construct_1(&self, x: Ptr); fn construct_2(&self, x: Ptr); - fn move_from(&self, _a0: Ptr); } impl HolderImpl for Ptr { fn construct_1(&self, x: Ptr) { field!((*self), t).write({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), { (x).clone() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { (x).clone() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }); } fn construct_2(&self, x: Ptr) { field!((*self), t).write({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::move_from(&__v.as_pointer(), { (x).clone() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - } - fn move_from(&self, _a0: Ptr) { - field!((*self), t).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, t) }); + MoveConstructible::move_constructor(&__v.as_pointer(), { (x).clone() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }); } } pub trait TrackedImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); } impl TrackedImpl for Ptr { fn construct(&self, mut v: i32) { @@ -183,16 +221,5 @@ impl TrackedImpl for Ptr { field!((*self), copies).write(0); field!((*self), moves).write(0); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*self), moves).write(o.with(|__s| __s.moves)); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write(o.with(|__s| __s.copies)); - field!((*self), moves).write((o.with(|__s| __s.moves) + 1)); - field!(o, v).write(0); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index 0a2ee40a47..80fe8d509e 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -9,7 +9,19 @@ use std::rc::{Rc, Weak}; pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct Tracked { @@ -20,6 +32,21 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl CopyConstructible for Tracked { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); + field!((*this), moves).write(o.with(|__s| __s.moves)); + } +} +impl MoveConstructible for Tracked { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write(o.with(|__s| __s.copies)); + field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + field!(o, v).write(0); + } +} impl Clone for Tracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Tracked { @@ -28,7 +55,7 @@ impl Clone for Tracked { moves: self.moves.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -122,8 +149,6 @@ fn main_0() -> i32 { } pub trait TrackedImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); } impl TrackedImpl for Ptr { fn construct(&self, mut v: i32) { @@ -131,16 +156,5 @@ impl TrackedImpl for Ptr { field!((*self), copies).write(0); field!((*self), moves).write(0); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*self), moves).write(o.with(|__s| __s.moves)); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write(o.with(|__s| __s.copies)); - field!((*self), moves).write((o.with(|__s| __s.moves) + 1)); - field!(o, v).write(0); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index f4e9495078..18f19eb42e 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -11,7 +11,19 @@ pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct Tracked { @@ -22,6 +34,21 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl CopyConstructible for Tracked { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); + field!((*this), moves).write(o.with(|__s| __s.moves)); + } +} +impl MoveConstructible for Tracked { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write(o.with(|__s| __s.copies)); + field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + field!(o, v).write(0); + } +} impl Clone for Tracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Tracked { @@ -30,7 +57,7 @@ impl Clone for Tracked { moves: self.moves.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -50,7 +77,7 @@ pub fn copy_or_move_into_param_4(t: Tracked) -> Tracked { let t: Value = Rc::new(RefCell::new(t)); return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::move_from(&__v.as_pointer(), { t.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { t.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -80,7 +107,7 @@ fn main_0() -> i32 { let mut moved: Tracked = ({ copy_or_move_into_param_4({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::move_from(&__v.as_pointer(), { b.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { b.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }); @@ -96,7 +123,7 @@ fn main_0() -> i32 { let mut copied: Tracked = ({ copy_or_move_into_param_4({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), { c.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { c.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }); @@ -119,8 +146,6 @@ fn main_0() -> i32 { } pub trait TrackedImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); } impl TrackedImpl for Ptr { fn construct(&self, mut v: i32) { @@ -128,16 +153,5 @@ impl TrackedImpl for Ptr { field!((*self), copies).write(0); field!((*self), moves).write(0); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*self), moves).write(o.with(|__s| __s.moves)); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write(o.with(|__s| __s.copies)); - field!((*self), moves).write((o.with(|__s| __s.moves) + 1)); - field!(o, v).write(0); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index 561384a886..42d2c2f8d6 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -11,7 +11,19 @@ pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct Tracked { @@ -22,6 +34,21 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl CopyConstructible for Tracked { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); + field!((*this), moves).write(o.with(|__s| __s.moves)); + } +} +impl MoveConstructible for Tracked { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write(o.with(|__s| __s.copies)); + field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + field!(o, v).write(0); + } +} impl Clone for Tracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Tracked { @@ -30,7 +57,7 @@ impl Clone for Tracked { moves: self.moves.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -82,7 +109,20 @@ pub fn forward_pack_7( }; return digits; } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[byte_size(24)] pub struct Pair { #[offset(0)] @@ -92,6 +132,20 @@ pub struct Pair { #[byte_size(12)] pub b: Tracked, } +impl MoveConstructible for Pair { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), a).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, a) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + field!((*this), b).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, b) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + } +} pub fn forward_pack_into_ctor_8(args_0: Ptr, args_1: Ptr) -> Pair { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); @@ -166,38 +220,23 @@ fn main_0() -> i32 { } pub trait PairImpl { fn construct(&self, x: Ptr, y: Ptr); - fn move_from(&self, _a0: Ptr); } impl PairImpl for Ptr { fn construct(&self, x: Ptr, y: Ptr) { field!((*self), a).write({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), { (x).clone() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { (x).clone() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }); field!((*self), b).write({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::move_from(&__v.as_pointer(), { (y).clone() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - } - fn move_from(&self, _a0: Ptr) { - field!((*self), a).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, a) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - field!((*self), b).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, b) }); + MoveConstructible::move_constructor(&__v.as_pointer(), { (y).clone() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }); } } pub trait TrackedImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); } impl TrackedImpl for Ptr { fn construct(&self, mut v: i32) { @@ -205,16 +244,5 @@ impl TrackedImpl for Ptr { field!((*self), copies).write(0); field!((*self), moves).write(0); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*self), moves).write(o.with(|__s| __s.moves)); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write(o.with(|__s| __s.copies)); - field!((*self), moves).write((o.with(|__s| __s.moves) + 1)); - field!(o, v).write(0); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index 95cc1dd0b7..f7d2a25091 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -18,7 +18,18 @@ pub fn scaled_2(v: Ptr, mut k: i32) -> i32 { 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct V { #[offset(0)] @@ -32,7 +43,18 @@ impl CppEq for V { pub fn get_4(w: Ptr) -> i32 { return w.with(|__s| __s.x); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct W_int_ { #[offset(0)] @@ -41,13 +63,35 @@ pub struct W_int_ { pub fn get_5(w: Ptr) -> i64 { return w.with(|__s| __s.x); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct W_long_ { #[offset(0)] pub x: i64, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct D { #[offset(0)] diff --git a/tests/unit/out/refcount/function_overloading.rs b/tests/unit/out/refcount/function_overloading.rs index 68f8ead863..b1ab134eb2 100644 --- a/tests/unit/out/refcount/function_overloading.rs +++ b/tests/unit/out/refcount/function_overloading.rs @@ -21,7 +21,18 @@ pub fn foo_3(mut x: Ptr, mut y: Ptr, z: Ptr) -> i32 { pub fn bar_4(x: Ptr) -> i32 { return (x.read()); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Foo {} pub fn func_5(mut x: i32) -> i32 { diff --git a/tests/unit/out/refcount/global_call_temporaries.rs b/tests/unit/out/refcount/global_call_temporaries.rs index d193aca603..3b8182691d 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -94,7 +94,18 @@ thread_local!( }) })); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Item { #[offset(0)] diff --git a/tests/unit/out/refcount/global_init_side_effect.rs b/tests/unit/out/refcount/global_init_side_effect.rs index b9d2bfff87..04c40e3b04 100644 --- a/tests/unit/out/refcount/global_init_side_effect.rs +++ b/tests/unit/out/refcount/global_init_side_effect.rs @@ -9,7 +9,19 @@ use std::rc::{Rc, Weak}; thread_local!( pub static total_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(1)] pub struct S {} diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index 314f10214c..5fcb3f2525 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -32,7 +32,9 @@ thread_local!( pub static depends_on_call_6: Value = Rc::new(RefCell::new((from_call_5.with(|rc| *rc.borrow()) + 1))); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct Ctor { #[offset(0)] @@ -77,7 +79,18 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Holder {} thread_local!( @@ -96,7 +109,9 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct Singleton { #[offset(0)] diff --git a/tests/unit/out/refcount/global_pointers.rs b/tests/unit/out/refcount/global_pointers.rs index 5fe456b7d9..e6e5d870c6 100644 --- a/tests/unit/out/refcount/global_pointers.rs +++ b/tests/unit/out/refcount/global_pointers.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Entry { #[offset(0)] diff --git a/tests/unit/out/refcount/global_without_initializer.rs b/tests/unit/out/refcount/global_without_initializer.rs index 1990136dff..3a0b902f95 100644 --- a/tests/unit/out/refcount/global_without_initializer.rs +++ b/tests/unit/out/refcount/global_without_initializer.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/goto_aggregate_default.rs b/tests/unit/out/refcount/goto_aggregate_default.rs index 0449ac8471..1bd3ed041f 100644 --- a/tests/unit/out/refcount/goto_aggregate_default.rs +++ b/tests/unit/out/refcount/goto_aggregate_default.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/goto_cleanup.rs b/tests/unit/out/refcount/goto_cleanup.rs index 6dd03f7dd7..6c7b2e00f7 100644 --- a/tests/unit/out/refcount/goto_cleanup.rs +++ b/tests/unit/out/refcount/goto_cleanup.rs @@ -76,7 +76,9 @@ 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, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct wrapper { #[offset(0)] diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index f0bffcbeb3..55d16100fc 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(24)] pub struct MinHeapNode { #[offset(0)] @@ -40,7 +42,7 @@ pub fn Swap_0(a: Ptr, b: Ptr) { right: (t.right).clone(), }); } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Default)] #[byte_size(32)] pub struct MinHeap { #[offset(0)] @@ -56,6 +58,36 @@ pub struct MinHeap { #[byte_size(8)] pub alloc: Option>>, } +impl MoveConstructible for MinHeap { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), size).write({ (*_a0.upgrade().deref()).size }); + field!((*this), capacity).write({ (*_a0.upgrade().deref()).capacity }); + field!((*this), arr).write( + field!(_a0, arr) + .with_mut(|__v: &mut Option]>>>| __v.take()), + ); + field!((*this), next).write({ (*_a0.upgrade().deref()).next }); + field!((*this), alloc).write( + field!(_a0, alloc).with_mut(|__v: &mut Option>>| __v.take()), + ); + } +} +impl MoveAssignable for MinHeap { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), size).write({ (*_a0.upgrade().deref()).size }); + field!((*this), capacity).write({ (*_a0.upgrade().deref()).capacity }); + field!((*this), arr).with_mut(|__b0| { + (*__b0) = field!(_a0, arr) + .with_mut(|__v: &mut Option]>>>| __v.take()); + }); + field!((*this), next).write({ (*_a0.upgrade().deref()).next }); + field!((*this), alloc).with_mut(|__b0| { + (*__b0) = field!(_a0, alloc) + .with_mut(|__v: &mut Option>>| __v.take()); + }); + return (*this).clone(); + } +} pub fn AllocMinHeap_1(mut capacity: i32) -> Option> { let mut minHeap: Option> = Some(Rc::new(RefCell::new(MinHeap { size: 0, @@ -272,8 +304,6 @@ pub trait MinHeapImpl { freq: Ptr>>>, n: i32, ); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl MinHeapImpl for Ptr { fn Alloc(&self, mut data: i8, mut freq: i32) -> Ptr { @@ -439,32 +469,6 @@ impl MinHeapImpl for Ptr { } } } - fn move_from(&self, _a0: Ptr) { - field!((*self), size).write({ (*_a0.upgrade().deref()).size }); - field!((*self), capacity).write({ (*_a0.upgrade().deref()).capacity }); - field!((*self), arr).write( - field!(_a0, arr) - .with_mut(|__v: &mut Option]>>>| __v.take()), - ); - field!((*self), next).write({ (*_a0.upgrade().deref()).next }); - field!((*self), alloc).write( - field!(_a0, alloc).with_mut(|__v: &mut Option>>| __v.take()), - ); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), size).write({ (*_a0.upgrade().deref()).size }); - field!((*self), capacity).write({ (*_a0.upgrade().deref()).capacity }); - field!((*self), arr).with_mut(|__b0| { - (*__b0) = field!(_a0, arr) - .with_mut(|__v: &mut Option]>>>| __v.take()); - }); - field!((*self), next).write({ (*_a0.upgrade().deref()).next }); - field!((*self), alloc).with_mut(|__b0| { - (*__b0) = field!(_a0, alloc) - .with_mut(|__v: &mut Option>>| __v.take()); - }); - return (*self).clone(); - } } pub trait MinHeapNodeImpl { fn IsLeaf(&self) -> bool; 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 49e3c1531e..60f2c6aa0d 100644 --- a/tests/unit/out/refcount/immutable-deref-on-func-call.rs +++ b/tests/unit/out/refcount/immutable-deref-on-func-call.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Item { #[offset(0)] diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index 46b99638a5..bfd881dba1 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct Holder { @@ -15,6 +25,19 @@ pub struct Holder { #[byte_size(24)] pub v: Vec, } +impl MoveConstructible for Holder { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), v).write(field!(_a0, v).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Holder { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).with_mut(|__b0| { + (*__b0) = field!(_a0, v).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} pub fn write_through_0(mut p: Ptr) { p.write(42); } @@ -64,19 +87,4 @@ fn main_0() -> i32 { assert!(((index!(p, 0_usize).read()) == 42)); return 0; } -pub trait HolderImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl HolderImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), v).write(field!(_a0, v).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).with_mut(|__b0| { - (*__b0) = field!(_a0, v).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/in_class_field_initializer.rs b/tests/unit/out/refcount/in_class_field_initializer.rs index 9551e73365..891a7a9dbf 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -19,7 +21,9 @@ impl Default for Inner { { Inner { x: 3, y: 4 } } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(24)] pub struct S { #[offset(0)] @@ -45,7 +49,9 @@ impl Default for S { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct Boxed_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/init.rs b/tests/unit/out/refcount/init.rs index f9b6d67e5a..35e6480e8f 100644 --- a/tests/unit/out/refcount/init.rs +++ b/tests/unit/out/refcount/init.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct X { #[offset(0)] diff --git a/tests/unit/out/refcount/init_list.rs b/tests/unit/out/refcount/init_list.rs index cc2f4ea860..97cc998466 100644 --- a/tests/unit/out/refcount/init_list.rs +++ b/tests/unit/out/refcount/init_list.rs @@ -9,7 +9,18 @@ use std::rc::{Rc, Weak}; pub fn f_0(list: Vec) { let list: Value> = Rc::new(RefCell::new(list)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -17,7 +28,9 @@ pub struct Pair { #[offset(4)] pub b: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct Holder { #[offset(0)] @@ -36,7 +49,9 @@ impl Default for Holder { pub fn sum_1(p: Ptr) -> i32 { return ({ p.with(|__s| __s.a) } + { p.with(|__s| __s.b) }); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct Seven { #[offset(0)] diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 0910c0c4fa..23cd250573 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -6,7 +6,18 @@ 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, MoveCtor, MoveAssign)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, +)] #[byte_size(48)] pub struct Elem { #[offset(0)] @@ -19,6 +30,29 @@ pub struct Elem { #[byte_size(24)] pub coeffs: Vec, } +impl MoveConstructible for Elem { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), id).write({ (*_a0.upgrade().deref()).id }); + field!((*this), hist).write(Box::new(std::array::from_fn::<_, 4, _>(|__i: usize| { + (*_a0.upgrade().deref()).hist[(__i) as usize] + }))); + field!((*this), coeffs).write(field!(_a0, coeffs).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Elem { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), id).write({ (*_a0.upgrade().deref()).id }); + { + let mut __tmp_0 = { (array_field_ptr!((*this), hist)).to_any() }; + __tmp_0.memcpy(&(array_field_ptr!(_a0, hist)).to_any(), 16_usize); + (__tmp_0).clone() + }; + field!((*this), coeffs).with_mut(|__b0| { + (*__b0) = field!(_a0, coeffs).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} impl Default for Elem { fn default() -> Self { { @@ -30,7 +64,18 @@ impl Default for Elem { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, +)] #[byte_size(88)] pub struct State { #[offset(0)] @@ -50,6 +95,56 @@ pub struct State { #[byte_size(24)] pub rows: Vec>, } +impl MoveConstructible for State { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), count).write({ (*_a0.upgrade().deref()).count }); + field!((*this), grid).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { + Box::<[_]>::from(std::array::from_fn::<_, 3, _>(|__i2: usize| { + (*_a0.upgrade().deref()).grid[(__i) as usize][(__i2) as usize] + })) + }))); + field!((*this), arr).write({ + let __v: Value> = + Rc::new(RefCell::new((0..3).map(|_| ::zero_init()).collect())); + let __p: Ptr = __v.decay(); + for __i in 0..3 { + MoveConstructible::move_constructor( + &__p.offset(__i), + field_ref!(_a0, arr).decay().offset(__i), + ); + } + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + field!((*this), elems).write(field!(_a0, elems).with_mut(std::mem::take)); + field!((*this), rows).write(field!(_a0, rows).with_mut(std::mem::take)); + } +} +impl MoveAssignable for State { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), count).write({ (*_a0.upgrade().deref()).count }); + { + let mut __tmp_1 = { (array_field_ptr!((*this), grid)).to_any() }; + __tmp_1.memcpy(&(array_field_ptr!(_a0, grid)).to_any(), 24_usize); + (__tmp_1).clone() + }; + { + for __i in 0..3 { + MoveAssignable::move_assign( + &field_ref!((*this), arr).as_pointer().decay().offset(__i), + field_ref!(_a0, arr).decay().offset(__i), + ); + } + field_ref!((*this), arr).as_pointer() + }; + field!((*this), elems).with_mut(|__b0| { + (*__b0) = field!(_a0, elems).with_mut(std::mem::take); + }); + field!((*this), rows).with_mut(|__b0| { + (*__b0) = field!(_a0, rows).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} impl Default for State { fn default() -> Self { { @@ -127,19 +222,45 @@ thread_local!( thread_local!( pub static move_assigns_5: Value = Rc::new(RefCell::new(0)); ); -#[derive( - Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CopyAssign, MoveAssign, -)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Swappable)] #[byte_size(4)] pub struct Counted { #[offset(0)] pub v: i32, } +impl CopyConstructible for Counted { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl MoveConstructible for Counted { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(-1_i32); + (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for Counted { + fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copy_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); + return (*this).clone(); + } +} +impl MoveAssignable for Counted { + fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(-1_i32); + (*move_assigns_5.with(Value::clone).borrow_mut()).prefix_inc(); + return (*this).clone(); + } +} impl Clone for Counted { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Counted { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -268,7 +389,7 @@ fn main_0() -> i32 { ); let moved: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - StateImpl::move_from(&__v.as_pointer(), { t.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { t.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!( @@ -288,7 +409,7 @@ fn main_0() -> i32 { && ((elem!(field_ref!(t.as_pointer(), arr).decay(), 1_usize).read()) == 7) ); let assigned: Value = Rc::new(RefCell::new(::default())); - ({ StateImpl::move_assign(&assigned.as_pointer(), moved.as_pointer()) }); + ({ MoveAssignable::move_assign(&assigned.as_pointer(), moved.as_pointer()) }); assert!( ({ ((*assigned.borrow()).grid[(0) as usize][(0) as usize] == 100) @@ -319,11 +440,16 @@ fn main_0() -> i32 { ::default() })))); (*ca.borrow_mut())[1_usize].v = 5; - let cb: Value> = Rc::new(RefCell::new( - (0..3) - .map(|__i| ::move_ctor(ca.decay().offset(__i))) - .collect(), - )); + let cb: Value> = Rc::new(RefCell::new({ + let __v: Value> = Rc::new(RefCell::new( + (0..3).map(|_| ::zero_init()).collect(), + )); + let __p: Ptr = __v.decay(); + for __i in 0..3 { + MoveConstructible::move_constructor(&__p.offset(__i), ca.decay().offset(__i)); + } + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( (((moves_3.with(|rc| *rc.borrow()) == 3) && (copies_2.with(|rc| *rc.borrow()) == 0)) && ({ (*cb.borrow())[1_usize].v } == 5)) @@ -340,10 +466,10 @@ fn main_0() -> i32 { (*cc.borrow_mut())[2_usize].v = 8; { for __i in 0..3 { - &cb.as_pointer() - .decay() - .offset(__i) - .copy_assign(cc.decay().offset(__i)); + CopyAssignable::copy_assign( + &cb.as_pointer().decay().offset(__i), + cc.decay().offset(__i), + ); } cb.as_pointer() }; @@ -354,10 +480,10 @@ fn main_0() -> i32 { ); { for __i in 0..3 { - &ca.as_pointer() - .decay() - .offset(__i) - .move_assign(cb.decay().offset(__i)); + MoveAssignable::move_assign( + &ca.as_pointer().decay().offset(__i), + cb.decay().offset(__i), + ); } ca.as_pointer() }; @@ -376,11 +502,16 @@ fn main_0() -> i32 { let __a1 = 1; elem!(va.decay(), 0_usize).with_mut(|__v: &mut Vec| __v.push(__a1)) }; - let vb: Value]>> = Rc::new(RefCell::new( - (0..2) - .map(|__i| as MoveCtor>::move_ctor(va.decay().offset(__i))) - .collect(), - )); + let vb: Value]>> = Rc::new(RefCell::new({ + let __v: Value]>> = Rc::new(RefCell::new( + (0..2).map(|_| >::zero_init()).collect(), + )); + let __p: Ptr> = __v.decay(); + for __i in 0..2 { + MoveConstructible::move_constructor(&__p.offset(__i), va.decay().offset(__i)); + } + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( ({ ((*vb.decay().offset(0_usize).upgrade().deref()).len() == 1_usize) @@ -392,10 +523,10 @@ fn main_0() -> i32 { ))); { for __i in 0..2 { - &vc.as_pointer() - .decay() - .offset(__i) - .write( as MoveCtor>::move_ctor(vb.decay().offset(__i))); + MoveAssignable::move_assign( + &vc.as_pointer().decay().offset(__i), + vb.decay().offset(__i), + ); } vc.as_pointer() }; @@ -407,105 +538,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait CountedImpl { - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); - fn copy_assign(&self, o: Ptr) -> Ptr; - fn move_assign(&self, o: Ptr) -> Ptr; -} -impl CountedImpl for Ptr { - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(-1_i32); - (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copy_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); - return (*self).clone(); - } - fn move_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(-1_i32); - (*move_assigns_5.with(Value::clone).borrow_mut()).prefix_inc(); - return (*self).clone(); - } -} -pub trait ElemImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl ElemImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), id).write({ (*_a0.upgrade().deref()).id }); - field!((*self), hist).write(Box::new(std::array::from_fn::<_, 4, _>(|__i: usize| { - (*_a0.upgrade().deref()).hist[(__i) as usize] - }))); - field!((*self), coeffs).write(field!(_a0, coeffs).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), id).write({ (*_a0.upgrade().deref()).id }); - { - let mut __tmp_0 = { (array_field_ptr!((*self), hist)).to_any() }; - __tmp_0.memcpy(&(array_field_ptr!(_a0, hist)).to_any(), 16_usize); - (__tmp_0).clone() - }; - field!((*self), coeffs).with_mut(|__b0| { - (*__b0) = field!(_a0, coeffs).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} -pub trait StateImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl StateImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), count).write({ (*_a0.upgrade().deref()).count }); - field!((*self), grid).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { - Box::<[_]>::from(std::array::from_fn::<_, 3, _>(|__i2: usize| { - (*_a0.upgrade().deref()).grid[(__i) as usize][(__i2) as usize] - })) - }))); - field!((*self), arr).write( - (0..3) - .map(|__i| field_ref!(_a0, arr).decay().offset(__i).read()) - .collect(), - ); - field!((*self), elems).write(field!(_a0, elems).with_mut(std::mem::take)); - field!((*self), rows).write(field!(_a0, rows).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), count).write({ (*_a0.upgrade().deref()).count }); - { - let mut __tmp_1 = { (array_field_ptr!((*self), grid)).to_any() }; - __tmp_1.memcpy(&(array_field_ptr!(_a0, grid)).to_any(), 24_usize); - (__tmp_1).clone() - }; - { - for __i in 0..3 { - &field_ref!((*self), arr) - .as_pointer() - .decay() - .offset(__i) - .write(field_ref!(_a0, arr).decay().offset(__i).read()); - } - field_ref!((*self), arr).as_pointer() - }; - field!((*self), elems).with_mut(|__b0| { - (*__b0) = field!(_a0, elems).with_mut(std::mem::take); - }); - field!((*self), rows).with_mut(|__b0| { - (*__b0) = field!(_a0, rows).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() { let _ = copies_2.with(|_| ()); let _ = moves_3.with(|_| ()); diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index bb969d73c1..005368c8f3 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct Edge { #[offset(0)] @@ -99,7 +110,7 @@ pub fn quicksort_1(arr: Ptr>>>, mut start: i32, mut end ({ quicksort_1((arr).clone(), start, (p - 1)) }); ({ quicksort_1((arr).clone(), (p + 1), end) }); } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Default)] #[byte_size(24)] pub struct DisjointSet { #[offset(0)] @@ -111,7 +122,29 @@ pub struct DisjointSet { #[offset(16)] pub n: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +impl MoveConstructible for DisjointSet { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), rank) + .write(field!(_a0, rank).with_mut(|__v: &mut Option>>| __v.take())); + field!((*this), parent) + .write(field!(_a0, parent).with_mut(|__v: &mut Option>>| __v.take())); + field!((*this), n).write({ (*_a0.upgrade().deref()).n }); + } +} +impl MoveAssignable for DisjointSet { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), rank).with_mut(|__b0| { + (*__b0) = field!(_a0, rank).with_mut(|__v: &mut Option>>| __v.take()); + }); + field!((*this), parent).with_mut(|__b0| { + (*__b0) = + field!(_a0, parent).with_mut(|__v: &mut Option>>| __v.take()); + }); + field!((*this), n).write({ (*_a0.upgrade().deref()).n }); + return (*this).clone(); + } +} +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Default)] #[byte_size(16)] pub struct Graph { #[offset(0)] @@ -122,6 +155,25 @@ pub struct Graph { #[offset(12)] pub E: i32, } +impl MoveConstructible for Graph { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), edges) + .write(field!(_a0, edges).with_mut(|__v: &mut Option>>| __v.take())); + field!((*this), V).write({ (*_a0.upgrade().deref()).V }); + field!((*this), E).write({ (*_a0.upgrade().deref()).E }); + } +} +impl MoveAssignable for Graph { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), edges).with_mut(|__b0| { + (*__b0) = + field!(_a0, edges).with_mut(|__v: &mut Option>>| __v.take()); + }); + field!((*this), V).write({ (*_a0.upgrade().deref()).V }); + field!((*this), E).write({ (*_a0.upgrade().deref()).E }); + return (*this).clone(); + } +} 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 { @@ -234,8 +286,6 @@ pub trait DisjointSetImpl { fn makeSet(&self); fn find(&self, x: i32) -> i32; fn merge(&self, x: i32, y: i32); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl DisjointSetImpl for Ptr { fn makeSet(&self) { @@ -346,44 +396,5 @@ impl DisjointSetImpl for Ptr { ); } } - fn move_from(&self, _a0: Ptr) { - field!((*self), rank) - .write(field!(_a0, rank).with_mut(|__v: &mut Option>>| __v.take())); - field!((*self), parent) - .write(field!(_a0, parent).with_mut(|__v: &mut Option>>| __v.take())); - field!((*self), n).write({ (*_a0.upgrade().deref()).n }); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), rank).with_mut(|__b0| { - (*__b0) = field!(_a0, rank).with_mut(|__v: &mut Option>>| __v.take()); - }); - field!((*self), parent).with_mut(|__b0| { - (*__b0) = - field!(_a0, parent).with_mut(|__v: &mut Option>>| __v.take()); - }); - field!((*self), n).write({ (*_a0.upgrade().deref()).n }); - return (*self).clone(); - } -} -pub trait GraphImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl GraphImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), edges) - .write(field!(_a0, edges).with_mut(|__v: &mut Option>>| __v.take())); - field!((*self), V).write({ (*_a0.upgrade().deref()).V }); - field!((*self), E).write({ (*_a0.upgrade().deref()).E }); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), edges).with_mut(|__b0| { - (*__b0) = - field!(_a0, edges).with_mut(|__v: &mut Option>>| __v.take()); - }); - field!((*self), V).write({ (*_a0.upgrade().deref()).V }); - field!((*self), E).write({ (*_a0.upgrade().deref()).E }); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index edd5e2beea..fad6f544a2 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -6,13 +6,18 @@ 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, Destructible)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(1)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { #[offset(0)] #[byte_size(1)] pub f: FnPtr, } +impl Destructible for Guard__lambda_at_lambda_as_field_cpp_34_13__ { + fn destroy(this: &Ptr) { + ({ (*(*this).upgrade().deref()).f.call() }); + } +} impl Default for Guard__lambda_at_lambda_as_field_cpp_34_13__ { fn default() -> Self { { @@ -24,14 +29,19 @@ impl Default for Guard__lambda_at_lambda_as_field_cpp_34_13__ { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { #[offset(0)] #[byte_size(8)] pub f: FnPtr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +impl Destructible for Guard__lambda_at_lambda_as_field_cpp_45_13__ { + fn destroy(this: &Ptr) { + ({ (*(*this).upgrade().deref()).f.call() }); + } +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { #[offset(0)] @@ -54,7 +64,9 @@ impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { #[offset(0)] @@ -63,7 +75,7 @@ pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { #[offset(4)] pub calls: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible)] #[cpp_from(FnPtr i32 > , construct, value)] #[byte_size(8)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { @@ -73,6 +85,12 @@ pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { #[offset(4)] pub moves: i32, } +impl MoveConstructible for Moving__lambda_at_lambda_as_field_cpp_64_12__ { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), f).write((*o.upgrade().deref()).f.move_from()); + field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + } +} impl Default for Moving__lambda_at_lambda_as_field_cpp_64_12__ { fn default() -> Self { { ::zero_init() } @@ -118,7 +136,7 @@ fn main_0() -> i32 { }), })); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!((count_0.with(|rc| *rc.borrow()) == 0)); } assert!((count_0.with(|rc| *rc.borrow()) == 1)); @@ -150,7 +168,7 @@ fn main_0() -> i32 { ), })); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!(({ ((*cleaned.borrow()) == 0) })); } assert!(({ ((*cleaned.borrow()) == 1) })); @@ -212,35 +230,13 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - Moving__lambda_at_lambda_as_field_cpp_64_12__Impl::move_from(&__v.as_pointer(), { - m.as_pointer() - }); + MoveConstructible::move_constructor(&__v.as_pointer(), { m.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!(({ (({ (*m2.borrow()).f.call(3,) }) == 6) })); assert!(({ (*m2.borrow()).moves } == 1)); return 0; } -pub trait Guard__lambda_at_lambda_as_field_cpp_34_13__Impl { - fn destructor(&self); -} -impl Guard__lambda_at_lambda_as_field_cpp_34_13__Impl - for Ptr -{ - fn destructor(&self) { - ({ (*(*self).upgrade().deref()).f.call() }); - } -} -pub trait Guard__lambda_at_lambda_as_field_cpp_45_13__Impl { - fn destructor(&self); -} -impl Guard__lambda_at_lambda_as_field_cpp_45_13__Impl - for Ptr -{ - fn destructor(&self) { - ({ (*(*self).upgrade().deref()).f.call() }); - } -} pub trait Holder__lambda_at_lambda_as_field_cpp_39_12__Impl { fn call(&self, x: i32) -> i32; } @@ -265,7 +261,6 @@ impl Holder__lambda_at_lambda_as_field_cpp_51_12__Impl } pub trait Moving__lambda_at_lambda_as_field_cpp_64_12__Impl { fn construct(&self, f: FnPtr i32>); - fn move_from(&self, o: Ptr); } impl Moving__lambda_at_lambda_as_field_cpp_64_12__Impl for Ptr @@ -275,10 +270,6 @@ impl Moving__lambda_at_lambda_as_field_cpp_64_12__Impl field!((*self), f).write((*f.borrow()).copy_from()); field!((*self), moves).write(0); } - fn move_from(&self, o: Ptr) { - field!((*self), f).write((*o.upgrade().deref()).f.move_from()); - field!((*self), moves).write((o.with(|__s| __s.moves) + 1)); - } } pub fn __cpp2rust_init_globals() { let _ = count_0.with(|_| ()); diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 0379ac5c45..fa5779da44 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -6,7 +6,17 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, +)] #[byte_size(8)] pub struct Counted { #[offset(0)] @@ -14,6 +24,18 @@ pub struct Counted { #[offset(4)] pub moves: i32, } +impl CopyConstructible for Counted { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); + field!((*this), moves).write(o.with(|__s| __s.moves)); + } +} +impl MoveConstructible for Counted { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), copies).write(o.with(|__s| __s.copies)); + field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + } +} impl Clone for Counted { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Counted { @@ -21,7 +43,7 @@ impl Clone for Counted { moves: self.moves.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -39,14 +61,27 @@ impl Default for Counted { thread_local!( pub static drops_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Destructible)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssignable, MoveAssignable, Swappable, +)] #[byte_size(1)] pub struct Dropped {} +impl CopyConstructible for Dropped { + fn copy_constructor(this: &Ptr, _a0: Ptr) {} +} +impl MoveConstructible for Dropped { + fn move_constructor(this: &Ptr, _a0: Ptr) {} +} +impl Destructible for Dropped { + fn destroy(this: &Ptr) { + (*drops_0.with(Value::clone).borrow_mut()).postfix_inc(); + } +} impl Clone for Dropped { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Dropped {})); let __v: Value = Rc::new(RefCell::new(::zero_init())); - DroppedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -75,7 +110,7 @@ fn main_0() -> i32 { { let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), { c.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { c.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -95,14 +130,14 @@ fn main_0() -> i32 { { let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), { c.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { c.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || -> Counted { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), { c.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { c.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -124,7 +159,9 @@ fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 2, _>(|__i: usize| { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), { arr.decay().offset(__i) }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { + arr.decay().offset(__i) + }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); @@ -152,10 +189,10 @@ fn main_0() -> i32 { || {} ))); let _dtor_m = - std::mem::DropGuard::new(m.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(m.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let m2: Value> = Rc::new(RefCell::new((*m.borrow()).move_from())); let _dtor_m2 = - std::mem::DropGuard::new(m2.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(m2.clone(), |__p| Destructible::destroy(&__p.as_pointer())); } assert!((drops_0.with(|rc| *rc.borrow()) == 2)); { @@ -170,10 +207,10 @@ fn main_0() -> i32 { || {} ))); let _dtor_k = - std::mem::DropGuard::new(k.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(k.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let k2: Value> = Rc::new(RefCell::new((*k.borrow()).copy_from())); let _dtor_k2 = - std::mem::DropGuard::new(k2.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(k2.clone(), |__p| Destructible::destroy(&__p.as_pointer())); } assert!((drops_0.with(|rc| *rc.borrow()) == 4)); { @@ -187,8 +224,9 @@ fn main_0() -> i32 { }, || {} ))); - let _dtor_inner = - std::mem::DropGuard::new(inner.clone(), |__p| Destructible::destroy(__p.as_pointer())); + let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { + Destructible::destroy(&__p.as_pointer()) + }); let outer: Value> = Rc::new(RefCell::new(lambda!( { let inner: Value> = @@ -196,44 +234,27 @@ fn main_0() -> i32 { }, || {} ))); - let _dtor_outer = - std::mem::DropGuard::new(outer.clone(), |__p| Destructible::destroy(__p.as_pointer())); + let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { + Destructible::destroy(&__p.as_pointer()) + }); } assert!((drops_0.with(|rc| *rc.borrow()) == 6)); return 0; } pub trait CountedImpl { fn construct(&self); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); } impl CountedImpl for Ptr { fn construct(&self) { field!((*self), copies).write(0); field!((*self), moves).write(0); } - fn copy_from(&self, o: Ptr) { - field!((*self), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*self), moves).write(o.with(|__s| __s.moves)); - } - fn move_from(&self, o: Ptr) { - field!((*self), copies).write(o.with(|__s| __s.copies)); - field!((*self), moves).write((o.with(|__s| __s.moves) + 1)); - } } pub trait DroppedImpl { fn construct(&self); - fn copy_from(&self, _a0: Ptr); - fn move_from(&self, _a0: Ptr); - fn destructor(&self); } impl DroppedImpl for Ptr { fn construct(&self) {} - fn copy_from(&self, _a0: Ptr) {} - fn move_from(&self, _a0: Ptr) {} - fn destructor(&self) { - (*drops_0.with(Value::clone).borrow_mut()).postfix_inc(); - } } 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 6ececc76f2..708c81ee8f 100644 --- a/tests/unit/out/refcount/lambda_capture_ref.rs +++ b/tests/unit/out/refcount/lambda_capture_ref.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_capture_star_this.rs b/tests/unit/out/refcount/lambda_capture_star_this.rs index baebf700dd..5ac4e1d755 100644 --- a/tests/unit/out/refcount/lambda_capture_star_this.rs +++ b/tests/unit/out/refcount/lambda_capture_star_this.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_capture_this.rs b/tests/unit/out/refcount/lambda_capture_this.rs index 66a24ed128..6dcc0d3a5d 100644 --- a/tests/unit/out/refcount/lambda_capture_this.rs +++ b/tests/unit/out/refcount/lambda_capture_this.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_capture_value.rs b/tests/unit/out/refcount/lambda_capture_value.rs index 4fa6b5688b..dd7ba0095a 100644 --- a/tests/unit/out/refcount/lambda_capture_value.rs +++ b/tests/unit/out/refcount/lambda_capture_value.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_decltype_type.rs b/tests/unit/out/refcount/lambda_decltype_type.rs index 7237a10fac..caf6c587fe 100644 --- a/tests/unit/out/refcount/lambda_decltype_type.rs +++ b/tests/unit/out/refcount/lambda_decltype_type.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(24)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[offset(0)] @@ -34,7 +34,7 @@ impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(24)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_generic_explicit_args.rs b/tests/unit/out/refcount/lambda_generic_explicit_args.rs index d8889d4ff4..4bab369ba4 100644 --- a/tests/unit/out/refcount/lambda_generic_explicit_args.rs +++ b/tests/unit/out/refcount/lambda_generic_explicit_args.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Val { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_immediate_init.rs b/tests/unit/out/refcount/lambda_immediate_init.rs index 6aeb494e2e..ddbfd8875f 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -9,7 +9,9 @@ use std::rc::{Rc, Weak}; pub fn pick_0(mut x: i32) -> i32 { return x; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index 4d45c1d7cd..55e497a35c 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -6,9 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, Destructible, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, construct, value)] #[byte_size(8)] pub struct Owner { @@ -16,6 +14,17 @@ pub struct Owner { #[byte_size(8)] pub p: Ptr, } +impl MoveConstructible for Owner { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), p).write(o.with(|__s| __s.p.clone())); + field!(o, p).write(Ptr::::null()); + } +} +impl Destructible for Owner { + fn destroy(this: &Ptr) { + (*this).with(|__s| __s.p.clone()).delete(); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -27,12 +36,12 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_o = - std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let h: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - OwnerImpl::move_from(&__v.as_pointer(), { o.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { o.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -41,12 +50,12 @@ fn main_0() -> i32 { } ))); let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!(({ (*o.borrow()).p.clone() }).is_null()); assert!(({ (({ (*f.borrow()).call() }) == 5) })); let g: Value i32>> = Rc::new(RefCell::new((*f.borrow()).move_from())); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!(({ (({ (*g.borrow()).call() }) == 5) })); let total: Value = Rc::new(RefCell::new(0)); let consume: Value> = Rc::new(RefCell::new(lambda!( @@ -67,7 +76,7 @@ fn main_0() -> i32 { } ))); let _dtor_consume = std::mem::DropGuard::new(consume.clone(), |__p| { - Destructible::destroy(__p.as_pointer()) + Destructible::destroy(&__p.as_pointer()) }); ({ (*consume.borrow()).call() }); ({ (*consume.borrow()).call() }); @@ -78,38 +87,29 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_o2 = - std::mem::DropGuard::new(o2.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(o2.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let t: Value i32>> = Rc::new(RefCell::new(({ OwnerImpl::take(&o2.as_pointer()) }))); let _dtor_t = - std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!(({ (*o2.borrow()).p.clone() }).is_null()); assert!(({ (({ (*t.borrow()).call() }) == 9) })); return 0; } pub trait OwnerImpl { fn construct(&self, v: i32); - fn move_from(&self, o: Ptr); - fn destructor(&self); fn take(&self) -> FnPtr i32>; } impl OwnerImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), p).write(Ptr::alloc(v)); } - fn move_from(&self, o: Ptr) { - field!((*self), p).write(o.with(|__s| __s.p.clone())); - field!(o, p).write(Ptr::::null()); - } - fn destructor(&self) { - (*self).with(|__s| __s.p.clone()).delete(); - } fn take(&self) -> FnPtr i32> { return lambda!( { let self_: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - OwnerImpl::move_from(&__v.as_pointer(), { (*self).clone() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { (*self).clone() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, diff --git a/tests/unit/out/refcount/lambda_nested.rs b/tests/unit/out/refcount/lambda_nested.rs index ba8bf59b16..86099a1d5d 100644 --- a/tests/unit/out/refcount/lambda_nested.rs +++ b/tests/unit/out/refcount/lambda_nested.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_static_local.rs b/tests/unit/out/refcount/lambda_static_local.rs index 7015e7960a..19e5be804d 100644 --- a/tests/unit/out/refcount/lambda_static_local.rs +++ b/tests/unit/out/refcount/lambda_static_local.rs @@ -78,7 +78,18 @@ thread_local!( thread_local!( static calls_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct P_4 { #[offset(0)] diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index 77edb687dc..5b317af604 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -6,7 +6,18 @@ 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, MoveCtor, MoveAssign)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, +)] #[byte_size(32)] pub struct UserDefined { #[offset(0)] @@ -17,6 +28,40 @@ pub struct UserDefined { #[byte_size(24)] pub v: Vec, } +impl MoveConstructible for UserDefined { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), a).write({ + let __v: Value> = + Rc::new(RefCell::new((0..1).map(|_| ::zero_init()).collect())); + let __p: Ptr = __v.decay(); + for __i in 0..1 { + MoveConstructible::move_constructor( + &__p.offset(__i), + field_ref!(_a0, a).decay().offset(__i), + ); + } + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + field!((*this), v).write(field!(_a0, v).with_mut(std::mem::take)); + } +} +impl MoveAssignable for UserDefined { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + { + for __i in 0..1 { + MoveAssignable::move_assign( + &field_ref!((*this), a).as_pointer().decay().offset(__i), + field_ref!(_a0, a).decay().offset(__i), + ); + } + field_ref!((*this), a).as_pointer() + }; + field!((*this), v).with_mut(|__b0| { + (*__b0) = field!(_a0, v).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} impl Default for UserDefined { fn default() -> Self { { @@ -27,7 +72,7 @@ impl Default for UserDefined { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(16)] pub struct FieldIsLibcType { #[offset(0)] @@ -77,34 +122,4 @@ fn main_0() -> i32 { assert!(((filt.addr.sa_family as i32) == 2)); return 0; } -pub trait UserDefinedImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl UserDefinedImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), a).write( - (0..1) - .map(|__i| field_ref!(_a0, a).decay().offset(__i).read()) - .collect(), - ); - field!((*self), v).write(field!(_a0, v).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - { - for __i in 0..1 { - &field_ref!((*self), a) - .as_pointer() - .decay() - .offset(__i) - .write(field_ref!(_a0, a).decay().offset(__i).read()); - } - field_ref!((*self), a).as_pointer() - }; - field!((*self), v).with_mut(|__b0| { - (*__b0) = field!(_a0, v).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/linked_list.rs b/tests/unit/out/refcount/linked_list.rs index 703bb1b63e..ff42063ca8 100644 --- a/tests/unit/out/refcount/linked_list.rs +++ b/tests/unit/out/refcount/linked_list.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Node { #[offset(0)] diff --git a/tests/unit/out/refcount/local_anon_struct_collision.rs b/tests/unit/out/refcount/local_anon_struct_collision.rs index c00fcb21b3..160a144651 100644 --- a/tests/unit/out/refcount/local_anon_struct_collision.rs +++ b/tests/unit/out/refcount/local_anon_struct_collision.rs @@ -12,7 +12,18 @@ pub fn first_0() -> i32 { p.y = 2; return (p.x + p.y); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct anon_1 { #[offset(0)] @@ -26,7 +37,18 @@ pub fn second_2() -> i32 { q.b = 20_i64; return ((q.a + q.b) as i32); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct anon_3 { #[offset(0)] diff --git a/tests/unit/out/refcount/local_record_template.rs b/tests/unit/out/refcount/local_record_template.rs index a8902e358c..74cf1465ee 100644 --- a/tests/unit/out/refcount/local_record_template.rs +++ b/tests/unit/out/refcount/local_record_template.rs @@ -29,13 +29,35 @@ pub fn wrap_10(mut v: i64) -> i32 { let mut l: Local_7 = Local_7 { x: v }; return ({ get_6(l) }); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Local_5 { #[offset(0)] pub x: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Local_7 { #[offset(0)] @@ -45,7 +67,18 @@ pub fn other_11() -> i32 { let mut l: Local_1 = Local_1 { x: 3_i64, y: 4_i64 }; return (({ get_0(l) }) + (l.y as i32)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct Local_1 { #[offset(0)] @@ -66,7 +99,18 @@ fn main_0() -> i32 { assert!((({ wrap_10(6_i64,) }) == 6)); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Local_3 { #[offset(0)] diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index f24a258731..94bb6dd99b 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -12,7 +12,9 @@ pub fn foo_0(mut x: u32) { pub fn bar_1(x: Ptr) { x.write((x.read()).wrapping_add(1_u32)); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 34c8521669..17e56d6648 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -15,13 +15,37 @@ thread_local!( thread_local!( pub static made_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Key { #[offset(0)] pub k: i32, } +impl CopyConstructible for Key { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), k).write(o.with(|__s| __s.k)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl MoveConstructible for Key { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), k).write(o.with(|__s| __s.k)); + (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl CppLess for Key { fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { KeyImpl::operator_lt(__lhs, __rhs.clone()) @@ -37,7 +61,7 @@ impl Clone for Key { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Key { k: self.k.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - KeyImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -286,22 +310,12 @@ fn main_0() -> i32 { } pub trait KeyImpl { fn construct(&self, k: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); fn operator_lt(&self, o: Ptr) -> bool; } impl KeyImpl for Ptr { fn construct(&self, mut k: i32) { field!((*self), k).write(k); } - fn copy_from(&self, o: Ptr) { - field!((*self), k).write(o.with(|__s| __s.k)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn move_from(&self, o: Ptr) { - field!((*self), k).write(o.with(|__s| __s.k)); - (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); - } fn operator_lt(&self, o: Ptr) -> bool { return ({ (*self).with(|__s| __s.k) } < { o.with(|__s| __s.k) }); } diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index ed8ffcd313..0ec9a86cb1 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -9,7 +9,18 @@ use std::rc::{Rc, Weak}; thread_local!( pub static default_constructions_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Key { #[offset(0)] @@ -33,7 +44,9 @@ pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { pub fn operator_eq_2(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct Mapped { #[offset(0)] diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 2d50a7996a..d46c318386 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -18,20 +18,44 @@ thread_local!( thread_local!( pub static moves_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, +)] #[cpp_from(i32, construct_1, value)] #[byte_size(4)] pub struct Item { #[offset(0)] pub value: i32, } +impl CopyConstructible for Item { + fn copy_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl MoveConstructible for Item { + fn move_constructor(this: &Ptr, other: Ptr) { + field!((*this), value).write(other.with(|__s| __s.value)); + (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); + field!(other, value).write(-1_i32); + } +} impl Clone for Item { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Item { value: self.value.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -50,7 +74,9 @@ pub fn argument_4(item: Ptr) -> Ptr { (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); return (item).clone(); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct RefItem { #[offset(0)] @@ -369,7 +395,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::copy_from(&__v.as_pointer(), { (__tmp_6).clone() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { + (__tmp_6).clone() + }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -408,7 +436,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::move_from(&__v.as_pointer(), { (__tmp_7).clone() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { + (__tmp_7).clone() + }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -446,7 +476,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::copy_from(&__v.as_pointer(), { (__tmp_8).clone() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { + (__tmp_8).clone() + }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -486,7 +518,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::move_from(&__v.as_pointer(), { (__tmp_9).clone() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { + (__tmp_9).clone() + }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -642,7 +676,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::move_from(&__v.as_pointer(), { (__tmp_12).clone() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { + (__tmp_12).clone() + }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -686,7 +722,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::move_from(&__v.as_pointer(), { (__tmp_14).clone() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { + (__tmp_14).clone() + }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -726,8 +764,6 @@ fn main_0() -> i32 { pub trait ItemImpl { fn construct_2(&self); fn construct_1(&self, value: i32); - fn copy_from(&self, other: Ptr); - fn move_from(&self, other: Ptr); } impl ItemImpl for Ptr { fn construct_2(&self) { @@ -737,15 +773,6 @@ impl ItemImpl for Ptr { field!((*self), value).write(value); (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); } - fn copy_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn move_from(&self, other: Ptr) { - field!((*self), value).write(other.with(|__s| __s.value)); - (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); - field!(other, value).write(-1_i32); - } } pub trait RefItemImpl { fn construct_1(&self); diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index ef25415bda..643221e4b6 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -12,7 +12,9 @@ thread_local!( thread_local!( pub static visits_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct Item { #[offset(0)] @@ -42,7 +44,7 @@ pub fn place_3(n: Ptr) -> Ptr { thread_local!( pub static temporary_calls_4: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(12)] pub struct Temporary { #[offset(0)] @@ -63,7 +65,9 @@ impl Default for Temporary { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(12)] pub struct Nested { #[offset(0)] @@ -80,13 +84,27 @@ pub fn make_temporary_5() -> Temporary { pub fn make_nested_6() -> Nested { return ::default(); } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] #[byte_size(8)] pub struct Owner { #[offset(0)] #[byte_size(8)] pub ptr: Option>, } +impl MoveConstructible for Owner { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), ptr) + .write(field!(_a0, ptr).with_mut(|__v: &mut Option>| __v.take())); + } +} +impl MoveAssignable for Owner { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), ptr).with_mut(|__b0| { + (*__b0) = field!(_a0, ptr).with_mut(|__v: &mut Option>| __v.take()); + }); + return (*this).clone(); + } +} impl Default for Owner { fn default() -> Self { { @@ -98,7 +116,7 @@ impl Default for Owner { } } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] #[byte_size(4)] pub struct Noncopy { #[offset(0)] @@ -109,7 +127,9 @@ impl Default for Noncopy { { Noncopy { n: 5 } } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Copyable, +)] #[cpp_from(i32, construct_1, ptr)] #[byte_size(8)] pub struct Held { @@ -2434,8 +2454,6 @@ impl ItemImpl for Ptr { pub trait OwnerImpl { fn construct(&self); fn value(&self) -> Ptr; - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl OwnerImpl for Ptr { fn construct(&self) { @@ -2448,16 +2466,6 @@ impl OwnerImpl for Ptr { fn value(&self) -> Ptr { return field_ptr!((*self).with(|__s| __s.ptr.clone()).as_pointer(), n); } - fn move_from(&self, _a0: Ptr) { - field!((*self), ptr) - .write(field!(_a0, ptr).with_mut(|__v: &mut Option>| __v.take())); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), ptr).with_mut(|__b0| { - (*__b0) = field!(_a0, ptr).with_mut(|__v: &mut Option>| __v.take()); - }); - return (*self).clone(); - } } pub trait TemporaryImpl { fn construct(&self); diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index 0cd14d48ef..4d9b73ac1d 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -20,13 +20,27 @@ pub fn pick_3(mut i: i32) -> Ptr { (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); return xs_1.with(|v| v.decay()).offset(i); } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Movable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Bag { #[offset(0)] pub n: i32, } +impl CopyConstructible for Bag { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), n).write(o.with(|__s| __s.n)); + (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for Bag { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), n).write(_a0.with(|__s| __s.n)); + return (*this).clone(); + } +} impl CppLess for Bag { fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { operator_lt_4(__lhs.clone(), __rhs.clone()) @@ -42,7 +56,7 @@ impl Clone for Bag { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Bag { n: self.n.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - BagImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -207,21 +221,11 @@ fn main_0() -> i32 { } pub trait BagImpl { fn construct(&self, n: i32); - fn copy_from(&self, o: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl BagImpl for Ptr { fn construct(&self, mut n: i32) { field!((*self), n).write(n); } - fn copy_from(&self, o: Ptr) { - field!((*self), n).write(o.with(|__s| __s.n)); - (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), n).write(_a0.with(|__s| __s.n)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = calls_0.with(|_| ()); diff --git a/tests/unit/out/refcount/memcpy_struct_bytes.rs b/tests/unit/out/refcount/memcpy_struct_bytes.rs index af4970383b..91d682ee59 100644 --- a/tests/unit/out/refcount/memcpy_struct_bytes.rs +++ b/tests/unit/out/refcount/memcpy_struct_bytes.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct point { #[offset(0)] diff --git a/tests/unit/out/refcount/memcpy_struct_layouts.rs b/tests/unit/out/refcount/memcpy_struct_layouts.rs index a90e59a069..7775a6e873 100644 --- a/tests/unit/out/refcount/memcpy_struct_layouts.rs +++ b/tests/unit/out/refcount/memcpy_struct_layouts.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct packed { #[offset(0)] @@ -18,7 +29,18 @@ pub struct packed { #[offset(6)] pub d: i16, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(12)] pub struct reordered { #[offset(0)] @@ -28,7 +50,18 @@ pub struct reordered { #[offset(8)] pub c: i8, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct tail { #[offset(0)] @@ -36,7 +69,18 @@ pub struct tail { #[offset(8)] pub b: f64, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(24)] pub struct nested { #[offset(0)] @@ -45,7 +89,7 @@ pub struct nested { #[offset(16)] pub c: i8, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 3aa8c319d5..830e7b3bbb 100644 --- a/tests/unit/out/refcount/memcpy_struct_struct.rs +++ b/tests/unit/out/refcount/memcpy_struct_struct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Entry { #[offset(0)] diff --git a/tests/unit/out/refcount/memset_struct_tail.rs b/tests/unit/out/refcount/memset_struct_tail.rs index eca67abf50..f153f64372 100644 --- a/tests/unit/out/refcount/memset_struct_tail.rs +++ b/tests/unit/out/refcount/memset_struct_tail.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 b98f1c1fab..f9573b331e 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable, Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -15,7 +15,23 @@ pub struct MoveOnly { #[offset(0)] pub v: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] +impl MoveConstructible for MoveOnly { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(0); + } +} +impl MoveAssignable for MoveOnly { + fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + if ((*this) == (o)) { + return (*this).clone(); + } + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(0); + return (*this).clone(); + } +} +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] #[byte_size(4)] pub struct ConstMoveAssign { #[offset(0)] @@ -41,7 +57,7 @@ pub fn make_0(mut v: i32) -> MoveOnly { })); return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::move_from(&__v.as_pointer(), { m.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { m.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -65,7 +81,7 @@ fn main_0() -> i32 { MoveOnlyImpl::construct(&__v.as_pointer(), { 3 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - ({ MoveOnlyImpl::move_assign(&a.as_pointer(), b.as_pointer()) }); + ({ MoveAssignable::move_assign(&a.as_pointer(), b.as_pointer()) }); assert!(({ (*a.borrow()).v } == 2)); assert!(({ (*b.borrow()).v } == 0)); ({ @@ -74,12 +90,12 @@ fn main_0() -> i32 { MoveOnlyImpl::construct(&__v.as_pointer(), { 3 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - MoveOnlyImpl::move_assign(&b.as_pointer(), _o.as_pointer()) + MoveAssignable::move_assign(&b.as_pointer(), _o.as_pointer()) }); ({ - MoveOnlyImpl::move_assign( + MoveAssignable::move_assign( &c.as_pointer(), - ({ MoveOnlyImpl::move_assign(&a.as_pointer(), b.as_pointer()) }), + ({ MoveAssignable::move_assign(&a.as_pointer(), b.as_pointer()) }), ) }); assert!( @@ -91,15 +107,15 @@ fn main_0() -> i32 { MoveOnlyImpl::construct(&__v.as_pointer(), { 5 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - MoveOnlyImpl::move_assign(&a.as_pointer(), _o.as_pointer()) + MoveAssignable::move_assign(&a.as_pointer(), _o.as_pointer()) }); assert!(({ (*a.borrow()).v } == 5)); ({ let _o: Value = Rc::new(RefCell::new(({ make_0(6) }))); - MoveOnlyImpl::move_assign(&a.as_pointer(), _o.as_pointer()) + MoveAssignable::move_assign(&a.as_pointer(), _o.as_pointer()) }); assert!(({ (*a.borrow()).v } == 6)); - ({ MoveOnlyImpl::move_assign(&a.as_pointer(), a.as_pointer()) }); + ({ MoveAssignable::move_assign(&a.as_pointer(), a.as_pointer()) }); assert!(({ (*a.borrow()).v } == 6)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { @@ -115,7 +131,7 @@ fn main_0() -> i32 { MoveOnlyImpl::construct(&__v.as_pointer(), { 8 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - ({ MoveOnlyImpl::move_assign(&vec_.decay().offset(0_usize), d.as_pointer()) }); + ({ MoveAssignable::move_assign(&vec_.decay().offset(0_usize), d.as_pointer()) }); assert!(({ (*vec_.borrow())[0_usize].v } == 8)); assert!(({ (*d.borrow()).v } == 0)); let m: Value = Rc::new(RefCell::new({ @@ -164,24 +180,10 @@ impl ConstMoveAssignImpl for Ptr { } pub trait MoveOnlyImpl { fn construct(&self, v: i32); - fn move_from(&self, o: Ptr); - fn move_assign(&self, o: Ptr) -> Ptr; } impl MoveOnlyImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(0); - } - fn move_assign(&self, o: Ptr) -> Ptr { - if ((*self) == (o)) { - return (*self).clone(); - } - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(0); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index e93ce86953..08ef3312ce 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -6,14 +6,20 @@ 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, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub v: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] +impl MoveConstructible for MoveOnly { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(0); + } +} +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] #[byte_size(4)] pub struct ConstMove { #[offset(0)] @@ -30,7 +36,19 @@ impl Default for ConstMove { } } } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct ThrowingMove { @@ -41,6 +59,21 @@ pub struct ThrowingMove { #[offset(8)] pub moves: i32, } +impl CopyConstructible for ThrowingMove { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); + field!((*this), moves).write(o.with(|__s| __s.moves)); + } +} +impl MoveConstructible for ThrowingMove { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write(o.with(|__s| __s.copies)); + field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + field!(o, v).write(0); + } +} impl Clone for ThrowingMove { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(ThrowingMove { @@ -49,11 +82,23 @@ impl Clone for ThrowingMove { moves: self.moves.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - ThrowingMoveImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct NoexceptMove { @@ -64,6 +109,21 @@ pub struct NoexceptMove { #[offset(8)] pub moves: i32, } +impl CopyConstructible for NoexceptMove { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); + field!((*this), moves).write(o.with(|__s| __s.moves)); + } +} +impl MoveConstructible for NoexceptMove { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!((*this), copies).write(o.with(|__s| __s.copies)); + field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + field!(o, v).write(0); + } +} impl Clone for NoexceptMove { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(NoexceptMove { @@ -72,7 +132,7 @@ impl Clone for NoexceptMove { moves: self.moves.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoexceptMoveImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -87,7 +147,7 @@ pub fn make_1(mut v: i32) -> MoveOnly { })); return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::move_from(&__v.as_pointer(), { m.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { m.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -103,21 +163,21 @@ fn main_0() -> i32 { })); let b: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::move_from(&__v.as_pointer(), { a.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!(({ (*b.borrow()).v } == 1)); assert!(({ (*a.borrow()).v } == 0)); let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::move_from(&__v.as_pointer(), { b.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { b.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!(({ (*c.borrow()).v } == 1)); assert!(({ (*b.borrow()).v } == 0)); let mut d: MoveOnly = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::move_from(&__v.as_pointer(), { c.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { c.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((d.v == 1)); @@ -137,7 +197,7 @@ fn main_0() -> i32 { (({ by_value_0({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::move_from(&__v.as_pointer(), { e.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { e.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 5) @@ -160,7 +220,7 @@ fn main_0() -> i32 { { let __a1 = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::move_from(&__v.as_pointer(), { f.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { f.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; vec_.push(__a1) @@ -196,7 +256,7 @@ fn main_0() -> i32 { })); let mut t1: ThrowingMove = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ThrowingMoveImpl::copy_from(&__v.as_pointer(), { t.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { t.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((t1.v == 1)); @@ -210,7 +270,7 @@ fn main_0() -> i32 { })); let mut n1: NoexceptMove = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoexceptMoveImpl::move_from(&__v.as_pointer(), { n.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { n.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((n1.v == 2)); @@ -224,7 +284,7 @@ fn main_0() -> i32 { })); let mut g1: MoveOnly = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::move_from(&__v.as_pointer(), { g.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { g.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((g1.v == 3)); @@ -249,21 +309,14 @@ impl ConstMoveImpl for Ptr { } pub trait MoveOnlyImpl { fn construct(&self, v: i32); - fn move_from(&self, o: Ptr); } impl MoveOnlyImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(0); - } } pub trait NoexceptMoveImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); } impl NoexceptMoveImpl for Ptr { fn construct(&self, mut v: i32) { @@ -271,22 +324,9 @@ impl NoexceptMoveImpl for Ptr { field!((*self), copies).write(0); field!((*self), moves).write(0); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*self), moves).write(o.with(|__s| __s.moves)); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write(o.with(|__s| __s.copies)); - field!((*self), moves).write((o.with(|__s| __s.moves) + 1)); - field!(o, v).write(0); - } } pub trait ThrowingMoveImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); } impl ThrowingMoveImpl for Ptr { fn construct(&self, mut v: i32) { @@ -294,16 +334,5 @@ impl ThrowingMoveImpl for Ptr { field!((*self), copies).write(0); field!((*self), moves).write(0); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*self), moves).write(o.with(|__s| __s.moves)); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!((*self), copies).write(o.with(|__s| __s.copies)); - field!((*self), moves).write((o.with(|__s| __s.moves) + 1)); - field!(o, v).write(0); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index 6ca5996737..c104778360 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -6,18 +6,41 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Chain { #[offset(0)] pub v: i32, } +impl CopyConstructible for Chain { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write((o.with(|__s| __s.v) + 100)); + } +} +impl MoveConstructible for Chain { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write((o.with(|__s| __s.v) + 1)); + field!(o, v).write(0); + } +} impl Clone for Chain { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Chain { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - ChainImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -43,7 +66,7 @@ fn main_0() -> i32 { })); let mut b: Chain = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ChainImpl::move_from(&__v.as_pointer(), { + MoveConstructible::move_constructor(&__v.as_pointer(), { ({ ChainImpl::add_5(&({ ChainImpl::add_5(&b0.as_pointer(), 1) }), 1) }) }); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -73,7 +96,7 @@ fn main_0() -> i32 { (({ consume_0({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ChainImpl::move_from(&__v.as_pointer(), { + MoveConstructible::move_constructor(&__v.as_pointer(), { ({ ChainImpl::self_(&g.as_pointer()) }) }); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -91,8 +114,6 @@ fn main_0() -> i32 { } pub trait ChainImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); fn add_4(&self, n: i32) -> Ptr; fn add_5(&self, n: i32) -> Ptr; fn take(&self) -> Chain; @@ -103,13 +124,6 @@ impl ChainImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write((o.with(|__s| __s.v) + 100)); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write((o.with(|__s| __s.v) + 1)); - field!(o, v).write(0); - } fn add_4(&self, mut n: i32) -> Ptr { { field!((*self), v).with_mut(|__v| *__v = *__v + n) @@ -125,14 +139,14 @@ impl ChainImpl for Ptr { fn take(&self) -> Chain { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ChainImpl::move_from(&__v.as_pointer(), { (*self).clone() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { (*self).clone() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } fn copy(&self) -> Chain { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ChainImpl::copy_from(&__v.as_pointer(), { (*self).clone() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { (*self).clone() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } diff --git a/tests/unit/out/refcount/nested_structs.rs b/tests/unit/out/refcount/nested_structs.rs index 92ff0d5cc2..0a458a2036 100644 --- a/tests/unit/out/refcount/nested_structs.rs +++ b/tests/unit/out/refcount/nested_structs.rs @@ -6,13 +6,35 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Level0_Level1_1_Level2_1_Level3_1 { #[offset(0)] pub x1: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Level0_Level1_1_Level2_1_Level3_2 { #[offset(0)] @@ -20,19 +42,52 @@ pub struct Level0_Level1_1_Level2_1_Level3_2 { #[offset(4)] pub x2: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Level0_Level1_1_Level2_1 { #[offset(0)] pub x1: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Level0_Level1_1 { #[offset(0)] pub x1: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Level0_Level1_2 { #[offset(0)] @@ -40,7 +95,18 @@ pub struct Level0_Level1_2 { #[offset(4)] pub x2: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Level0 {} pub fn main() { diff --git a/tests/unit/out/refcount/new.rs b/tests/unit/out/refcount/new.rs index 0bf358cc6a..221cae51ee 100644 --- a/tests/unit/out/refcount/new.rs +++ b/tests/unit/out/refcount/new.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/new_bst.rs b/tests/unit/out/refcount/new_bst.rs index e442c4263b..858cab58f3 100644 --- a/tests/unit/out/refcount/new_bst.rs +++ b/tests/unit/out/refcount/new_bst.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(24)] pub struct node_t { #[offset(0)] diff --git a/tests/unit/out/refcount/new_struct.rs b/tests/unit/out/refcount/new_struct.rs index 0431d6d7d1..4cc30a0eb4 100644 --- a/tests/unit/out/refcount/new_struct.rs +++ b/tests/unit/out/refcount/new_struct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -14,7 +25,18 @@ pub struct Pair { #[offset(4)] pub y: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct Triple { #[offset(0)] diff --git a/tests/unit/out/refcount/nttp_distinct_specializations.rs b/tests/unit/out/refcount/nttp_distinct_specializations.rs index 7c5fb3ec65..b5dc29044c 100644 --- a/tests/unit/out/refcount/nttp_distinct_specializations.rs +++ b/tests/unit/out/refcount/nttp_distinct_specializations.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct S_2_ { #[offset(0)] @@ -14,13 +25,35 @@ pub struct S_2_ { #[offset(4)] pub w: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S_1_ { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S_3_ { #[offset(0)] diff --git a/tests/unit/out/refcount/offsetof.rs b/tests/unit/out/refcount/offsetof.rs index db02cf3294..36994ff6b2 100644 --- a/tests/unit/out/refcount/offsetof.rs +++ b/tests/unit/out/refcount/offsetof.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(12)] pub struct Layout { #[offset(0)] @@ -16,7 +27,7 @@ pub struct Layout { #[offset(8)] pub c: u16, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 68b7285f7f..8cf372314e 100644 --- a/tests/unit/out/refcount/opaque_forward_decl.rs +++ b/tests/unit/out/refcount/opaque_forward_decl.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct container { #[offset(0)] diff --git a/tests/unit/out/refcount/opaque_record_copy.rs b/tests/unit/out/refcount/opaque_record_copy.rs index 52f209175c..895fb5a3d3 100644 --- a/tests/unit/out/refcount/opaque_record_copy.rs +++ b/tests/unit/out/refcount/opaque_record_copy.rs @@ -6,10 +6,32 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Probe {} -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Wrapper_Probe_ { #[offset(0)] diff --git a/tests/unit/out/refcount/opaque_then_defined.rs b/tests/unit/out/refcount/opaque_then_defined.rs index c848e68b1a..2431b3fa76 100644 --- a/tests/unit/out/refcount/opaque_then_defined.rs +++ b/tests/unit/out/refcount/opaque_then_defined.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct list { #[offset(0)] @@ -15,7 +17,9 @@ pub struct list { #[offset(8)] pub size: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct node { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_arithmetic_free.rs b/tests/unit/out/refcount/operator_arithmetic_free.rs index 02d95197f9..0e6fc29041 100644 --- a/tests/unit/out/refcount/operator_arithmetic_free.rs +++ b/tests/unit/out/refcount/operator_arithmetic_free.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_arithmetic_member.rs b/tests/unit/out/refcount/operator_arithmetic_member.rs index eaacebd799..e6cfbe1295 100644 --- a/tests/unit/out/refcount/operator_arithmetic_member.rs +++ b/tests/unit/out/refcount/operator_arithmetic_member.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_bitwise_free.rs b/tests/unit/out/refcount/operator_bitwise_free.rs index 63f57d0d91..6e924fec5e 100644 --- a/tests/unit/out/refcount/operator_bitwise_free.rs +++ b/tests/unit/out/refcount/operator_bitwise_free.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_bitwise_member.rs b/tests/unit/out/refcount/operator_bitwise_member.rs index 45aba391cb..87bf27bf14 100644 --- a/tests/unit/out/refcount/operator_bitwise_member.rs +++ b/tests/unit/out/refcount/operator_bitwise_member.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index ecf6df1e15..24c07de6a9 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Eq { #[offset(0)] @@ -19,7 +30,18 @@ impl CppEq for Eq { EqImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Cmp { #[offset(0)] @@ -37,7 +59,18 @@ impl CppEq for Cmp { CmpImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Both { #[offset(0)] @@ -53,7 +86,18 @@ impl CppEq for Both { BothImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct OrdOnly { #[offset(0)] @@ -69,7 +113,18 @@ impl CppEq for OrdOnly { OrdOnlyImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Inner { #[offset(0)] @@ -85,7 +140,18 @@ impl CppEq for Inner { InnerImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Outer { #[offset(0)] @@ -104,7 +170,18 @@ impl CppEq for Outer { OuterImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Secondary { #[offset(0)] @@ -120,7 +197,9 @@ impl CppEq for Secondary { SecondaryImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct PtrMember { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index eb141c4358..f71a6e8aee 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -46,7 +57,18 @@ pub fn operator_lt_6(a: Ptr, mut b: i32) -> bool { 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct V { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index c6316b011c..05666dc49e 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_mixed.rs b/tests/unit/out/refcount/operator_comparison_mixed.rs index d4cc7e01d0..471115e727 100644 --- a/tests/unit/out/refcount/operator_comparison_mixed.rs +++ b/tests/unit/out/refcount/operator_comparison_mixed.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 455f1ffdc5..3ce340e94a 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct X { #[offset(0)] @@ -40,19 +51,52 @@ pub fn operator_le_4(mut a: X, mut b: X) -> i32 { 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Result { #[offset(0)] pub r: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Custom { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Mixed { #[offset(0)] @@ -68,14 +112,37 @@ impl CppEq for Mixed { ((MixedImpl::operator_eq(__lhs, __rhs.clone())) != 0) } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_into(bool, to_bool)] #[byte_size(1)] pub struct MyBool { #[offset(0)] pub value: bool, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Boolish { #[offset(0)] @@ -111,7 +178,7 @@ 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, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_into(bool, to_bool)] #[byte_size(1)] pub struct RefBool { @@ -125,7 +192,18 @@ thread_local!( Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct RefInt { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index c99f609601..c47a3d7af4 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -12,13 +12,18 @@ pub fn operator_eq_0(x: Ptr, y: Ptr) -> bool { 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, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct S { #[offset(0)] data_: i32, } +impl MoveConstructible for S { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), data_).write({ (*_a0.upgrade().deref()).data_ }); + } +} impl CppLess for S { fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { operator_lt_1(__lhs.clone(), __rhs.clone()) @@ -56,14 +61,10 @@ fn main_0() -> i32 { } pub trait SImpl { fn construct(&self, data: i32); - fn move_from(&self, _a0: Ptr); } impl SImpl for Ptr { fn construct(&self, mut data: i32) { field!((*self), data_).write(data); } - fn move_from(&self, _a0: Ptr) { - field!((*self), data_).write({ (*_a0.upgrade().deref()).data_ }); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_compound_assignment_free.rs b/tests/unit/out/refcount/operator_compound_assignment_free.rs index 865ca036ff..56b85f7015 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_free.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_free.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_compound_assignment_member.rs b/tests/unit/out/refcount/operator_compound_assignment_member.rs index 3cfb3136fc..2617630e38 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_member.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_member.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index 57ea87a36f..c39d0b434a 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -10,7 +10,18 @@ pub fn operator_eq_0(_a0: Ptr, _a1: Ptr) -> bool { return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }) && ({ _a0.with(|__s| __s.b) } == { _a1.with(|__s| __s.b) }); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Defaulted { #[offset(0)] @@ -38,7 +49,18 @@ pub fn operator_cmp_1(_a0: Ptr, _a1: Ptr) -> std::cm 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct DefaultedOrd { #[offset(0)] @@ -65,7 +87,18 @@ pub fn operator_add_5(x: Ptr, y: Ptr) -> Inline { a: ({ x.with(|__s| __s.a) } + { y.with(|__s| __s.a) }), }; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Inline { #[offset(0)] @@ -81,7 +114,18 @@ impl CppEq for Inline { operator_eq_3(__lhs.clone(), __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct OutOfLine { #[offset(0)] @@ -107,7 +151,18 @@ pub fn operator_lt_9(x: Ptr, y: Ptr) -> bool { 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Tmpl_int_ { #[offset(0)] @@ -123,7 +178,18 @@ impl CppEq for Tmpl_int_ { operator_eq_8(__lhs.clone(), __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Tmpl_long_ { #[offset(0)] @@ -132,7 +198,18 @@ pub struct Tmpl_long_ { pub fn operator_eq_11(_a0: Ptr, _a1: Ptr) -> bool { return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct TmplDefaulted_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_less_than.rs b/tests/unit/out/refcount/operator_less_than.rs index 7785126728..5eeef3d0d0 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_logical_free.rs b/tests/unit/out/refcount/operator_logical_free.rs index 19d2e7e167..48c1b5c6bc 100644 --- a/tests/unit/out/refcount/operator_logical_free.rs +++ b/tests/unit/out/refcount/operator_logical_free.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_logical_member.rs b/tests/unit/out/refcount/operator_logical_member.rs index 7db68dd321..5345dbd5f5 100644 --- a/tests/unit/out/refcount/operator_logical_member.rs +++ b/tests/unit/out/refcount/operator_logical_member.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_member_pointer_free.rs b/tests/unit/out/refcount/operator_member_pointer_free.rs index 0a7ee74641..2c66cb5afb 100644 --- a/tests/unit/out/refcount/operator_member_pointer_free.rs +++ b/tests/unit/out/refcount/operator_member_pointer_free.rs @@ -6,13 +6,24 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Inner { #[offset(0)] pub x: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 ed1b0db50b..86d4510d24 100644 --- a/tests/unit/out/refcount/operator_member_pointer_member.rs +++ b/tests/unit/out/refcount/operator_member_pointer_member.rs @@ -6,13 +6,35 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Inner { #[offset(0)] pub x: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Table {} impl Table { @@ -23,7 +45,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 1171d169bf..409ab783e2 100644 --- a/tests/unit/out/refcount/operator_other_free.rs +++ b/tests/unit/out/refcount/operator_other_free.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_other_member.rs b/tests/unit/out/refcount/operator_other_member.rs index 3b627eea25..6fcd805ee8 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_member.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Static {} impl Static { @@ -14,7 +25,19 @@ impl Static { return (a * b); } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_into(i32, to_i32)] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_overloads.rs b/tests/unit/out/refcount/operator_overloads.rs index 6c532c24ef..8846356ec0 100644 --- a/tests/unit/out/refcount/operator_overloads.rs +++ b/tests/unit/out/refcount/operator_overloads.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_qualifiers.rs b/tests/unit/out/refcount/operator_qualifiers.rs index 6bf6f81a61..1f63235bb0 100644 --- a/tests/unit/out/refcount/operator_qualifiers.rs +++ b/tests/unit/out/refcount/operator_qualifiers.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 9298036a09..1483c52297 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 8b372ebfe5..6ad9644827 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Lt { #[offset(0)] @@ -22,7 +33,18 @@ impl CppEq for Lt { !(LtImpl::operator_lt(__lhs, __rhs.clone())) && !(LtImpl::operator_lt(__rhs, __lhs.clone())) } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Eq { #[offset(0)] @@ -33,7 +55,18 @@ impl CppEq for Eq { EqImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Cmp { #[offset(0)] @@ -49,7 +82,18 @@ impl CppEq for Cmp { CmpImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Free { #[offset(0)] @@ -71,7 +115,18 @@ pub fn operator_lt_0(a: Ptr, b: Ptr) -> bool { 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Wrapped_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/overload_mangling.rs b/tests/unit/out/refcount/overload_mangling.rs index 0ae65e219a..8d5fc58c8d 100644 --- a/tests/unit/out/refcount/overload_mangling.rs +++ b/tests/unit/out/refcount/overload_mangling.rs @@ -19,16 +19,49 @@ pub fn add_1(mut p: Ptr, mut n: i32) { pub fn twice_2(mut n: i32) -> i32 { return (n * 2); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Access_S_ {} -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] pub base: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Box_ { #[offset(0)] diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index fcef65dc27..31fd836459 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -6,28 +6,76 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Celsius { #[offset(0)] pub degrees: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_into(i32, to_i32)] #[byte_size(4)] pub struct Meters { #[offset(0)] pub value: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(Celsius, construct, ptr)] #[byte_size(4)] pub struct Label { #[offset(0)] pub id: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(Celsius, construct_1, ptr)] #[cpp_from_move(Celsius, construct_2, ptr)] #[byte_size(8)] @@ -37,14 +85,37 @@ pub struct Owner { #[offset(4)] pub copied: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(Celsius, construct, value)] #[byte_size(4)] pub struct Holder { #[offset(0)] pub value: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Fallback { @@ -62,27 +133,74 @@ impl Default for Fallback { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Counter { #[offset(0)] pub hits: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(Counter, construct, mut_ptr)] #[byte_size(4)] pub struct Observer { #[offset(0)] pub seen: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(Celsius, construct, ptr)] #[byte_size(4)] pub struct Tag { #[offset(0)] pub code: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(Ptr< i8 > , construct, value)] #[byte_size(4)] pub struct Name { diff --git a/tests/unit/out/refcount/pod.rs b/tests/unit/out/refcount/pod.rs index 3cec3b41ca..93604057df 100644 --- a/tests/unit/out/refcount/pod.rs +++ b/tests/unit/out/refcount/pod.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(12)] pub struct POD { #[offset(0)] diff --git a/tests/unit/out/refcount/pointer_array.rs b/tests/unit/out/refcount/pointer_array.rs index 266a5c06da..5a6f756a60 100644 --- a/tests/unit/out/refcount/pointer_array.rs +++ b/tests/unit/out/refcount/pointer_array.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 b8b20f0d84..00b9e937ac 100644 --- a/tests/unit/out/refcount/pointers.rs +++ b/tests/unit/out/refcount/pointers.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Test { #[offset(0)] diff --git a/tests/unit/out/refcount/polymorphism.rs b/tests/unit/out/refcount/polymorphism.rs index 4d5ad299ef..cfdc0c2ddf 100644 --- a/tests/unit/out/refcount/polymorphism.rs +++ b/tests/unit/out/refcount/polymorphism.rs @@ -9,10 +9,32 @@ use std::rc::{Rc, Weak}; pub trait Animal { fn bark(&self) -> bool; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Dog {} -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Cat {} pub fn main() { diff --git a/tests/unit/out/refcount/ptr_cast_init.rs b/tests/unit/out/refcount/ptr_cast_init.rs index c46b52bef4..73cfebcf5f 100644 --- a/tests/unit/out/refcount/ptr_cast_init.rs +++ b/tests/unit/out/refcount/ptr_cast_init.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct header { #[offset(0)] @@ -14,7 +25,18 @@ pub struct header { #[offset(4)] pub size: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct view { #[offset(0)] diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index f417b12556..fdcef4e945 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -6,13 +6,26 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Chunk { #[offset(0)] pub data: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Writer { #[offset(0)] @@ -23,7 +36,17 @@ pub struct Writer { pub chunk: Chunk, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(48)] pub struct JPEGData { @@ -34,6 +57,23 @@ pub struct JPEGData { #[byte_size(24)] pub app_data: Vec>, } +impl MoveConstructible for JPEGData { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), com_data).write(field!(_a0, com_data).with_mut(std::mem::take)); + field!((*this), app_data).write(field!(_a0, app_data).with_mut(std::mem::take)); + } +} +impl MoveAssignable for JPEGData { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), com_data).with_mut(|__b0| { + (*__b0) = field!(_a0, com_data).with_mut(std::mem::take); + }); + field!((*this), app_data).with_mut(|__b0| { + (*__b0) = field!(_a0, app_data).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} pub fn push_param_0(mut dest: Ptr>>) { { let __a1 = Vec::new(); @@ -108,7 +148,18 @@ pub fn self_ref_push_6(mut comps: Ptr>) { comps.with_mut(|__v: &mut Vec| __v.push(a0_clone)) }; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, +)] #[cpp_from(i32, construct_1, value)] #[byte_size(8)] pub struct Pair { @@ -277,7 +328,18 @@ pub fn emplace_ref_self_read_13(values: Ptr>) -> Ptr { }) }; } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, +)] #[byte_size(32)] pub struct Bytes { #[offset(0)] @@ -288,6 +350,27 @@ pub struct Bytes { #[array_len(3)] pub b: Box<[u8]>, } +impl MoveConstructible for Bytes { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), v).write(field!(_a0, v).with_mut(std::mem::take)); + field!((*this), b).write(Box::new(std::array::from_fn::<_, 3, _>(|__i: usize| { + (*_a0.upgrade().deref()).b[(__i) as usize] + }))); + } +} +impl MoveAssignable for Bytes { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).with_mut(|__b0| { + (*__b0) = field!(_a0, v).with_mut(std::mem::take); + }); + { + let mut __tmp_13 = { (array_field_ptr!((*this), b)).to_any() }; + __tmp_13.memcpy(&(array_field_ptr!(_a0, b)).to_any(), 3_usize); + (__tmp_13).clone() + }; + return (*this).clone(); + } +} impl Default for Bytes { fn default() -> Self { { @@ -316,7 +399,7 @@ pub fn emplace_from_element_14(mut v: Ptr>>) { v.with_mut(|__v: &mut Vec>| __v.push(__tmp_15)); }; } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(24)] pub struct Plain { #[offset(0)] @@ -349,7 +432,18 @@ thread_local!( pub static all_counted_16: Value>> = Rc::new(RefCell::new(Ptr::>::null())); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Counted { #[offset(0)] @@ -606,29 +700,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait BytesImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl BytesImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), v).write(field!(_a0, v).with_mut(std::mem::take)); - field!((*self), b).write(Box::new(std::array::from_fn::<_, 3, _>(|__i: usize| { - (*_a0.upgrade().deref()).b[(__i) as usize] - }))); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).with_mut(|__b0| { - (*__b0) = field!(_a0, v).with_mut(std::mem::take); - }); - { - let mut __tmp_13 = { (array_field_ptr!((*self), b)).to_any() }; - __tmp_13.memcpy(&(array_field_ptr!(_a0, b)).to_any(), 3_usize); - (__tmp_13).clone() - }; - return (*self).clone(); - } -} pub trait CountedImpl { fn construct(&self, _a0: i32); } @@ -642,25 +713,6 @@ impl CountedImpl for Ptr { ); } } -pub trait JPEGDataImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl JPEGDataImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), com_data).write(field!(_a0, com_data).with_mut(std::mem::take)); - field!((*self), app_data).write(field!(_a0, app_data).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), com_data).with_mut(|__b0| { - (*__b0) = field!(_a0, com_data).with_mut(std::mem::take); - }); - field!((*self), app_data).with_mut(|__b0| { - (*__b0) = field!(_a0, app_data).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub trait PairImpl { fn construct_2(&self); fn construct_1(&self, a: i32); diff --git a/tests/unit/out/refcount/random.rs b/tests/unit/out/refcount/random.rs index e6df9f83f1..2ffcd7de94 100644 --- a/tests/unit/out/refcount/random.rs +++ b/tests/unit/out/refcount/random.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(72)] pub struct Pair { #[offset(0)] @@ -51,7 +51,18 @@ impl Default for Pair { pub fn zero_0() -> i32 { return 0; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct X1 {} pub fn foo_1(mut x1: i32, x2: Ptr, mut x3: Ptr, p2: Ptr, mut p3: Ptr) {} diff --git a/tests/unit/out/refcount/reference_wrapper.rs b/tests/unit/out/refcount/reference_wrapper.rs index 1faada9efa..a04c1d154d 100644 --- a/tests/unit/out/refcount/reference_wrapper.rs +++ b/tests/unit/out/refcount/reference_wrapper.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/references.rs b/tests/unit/out/refcount/references.rs index af7cbe7a47..6ff278f0e7 100644 --- a/tests/unit/out/refcount/references.rs +++ b/tests/unit/out/refcount/references.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(16)] pub struct Pair { #[offset(0)] @@ -29,7 +29,9 @@ impl Default for Pair { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Nested { #[offset(0)] diff --git a/tests/unit/out/refcount/refs_as_args.rs b/tests/unit/out/refcount/refs_as_args.rs index 27bd3854be..b2dfbc5d6a 100644 --- a/tests/unit/out/refcount/refs_as_args.rs +++ b/tests/unit/out/refcount/refs_as_args.rs @@ -30,7 +30,18 @@ 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Val { #[offset(0)] diff --git a/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs b/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs index 16a49ba0ec..efe2391dbf 100644 --- a/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs +++ b/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -14,7 +25,7 @@ pub struct S { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(28)] pub struct W { #[offset(0)] @@ -34,7 +45,7 @@ impl Default for W { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 e823d6b293..9d25cc866c 100644 --- a/tests/unit/out/refcount/reinterpret_cast_struct.rs +++ b/tests/unit/out/refcount/reinterpret_cast_struct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Point { #[offset(0)] 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 f2f3dc1419..2e5f87afc4 100644 --- a/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs +++ b/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -14,7 +25,18 @@ pub struct Point { #[offset(4)] pub y: u32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/reserved_keywords.rs b/tests/unit/out/refcount/reserved_keywords.rs index 93b8d77d2a..fcc83ace8d 100644 --- a/tests/unit/out/refcount/reserved_keywords.rs +++ b/tests/unit/out/refcount/reserved_keywords.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(152)] pub struct S { #[offset(0)] @@ -86,13 +97,35 @@ pub struct S { #[offset(148)] pub vec_: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct type_ { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct loop_ { #[offset(0)] diff --git a/tests/unit/out/refcount/return_move.rs b/tests/unit/out/refcount/return_move.rs index fa754bd11b..6efac38e6b 100644 --- a/tests/unit/out/refcount/return_move.rs +++ b/tests/unit/out/refcount/return_move.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct node { #[offset(0)] @@ -15,7 +17,9 @@ pub struct node { #[byte_size(8)] pub next: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct pair_t { #[offset(0)] diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index 50fd3a28b2..0998c8c2a5 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -15,18 +15,7 @@ thread_local!( thread_local!( pub static moves_2: Value = Rc::new(RefCell::new(0)); ); -#[derive( - Record, - ByteRepr, - ZeroInitialization, - VaArg, - FnPtrArg, - MoveCtor, - CppFrom, - CopyAssign, - MoveAssign, - Destructible, -)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Swappable)] #[cpp_from(i32, construct, value)] #[byte_size(20)] pub struct Buffer { @@ -37,6 +26,87 @@ pub struct Buffer { #[offset(16)] pub size: i32, } +impl Destructible for Buffer { + fn destroy(this: &Ptr) { + (*alive_0.with(Value::clone).borrow_mut()).prefix_dec(); + } +} +impl CopyConstructible for Buffer { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), data).write((0..4).map(|_| 0_i32).collect::>()); + field!((*this), size).write(o.with(|__s| __s.size)); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + 'for_body: { + array_elem!((*this), data, i).write((array_elem!(o, data, i).read())); + } + i.prefix_inc(); + } + } + (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); + (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl MoveConstructible for Buffer { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), data).write((0..4).map(|_| 0_i32).collect::>()); + field!((*this), size).write(o.with(|__s| __s.size)); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + 'for_body: { + array_elem!((*this), data, i).write((array_elem!(o, data, i).read())); + array_elem!(o, data, i).write(-1_i32); + } + i.prefix_inc(); + } + } + field!(o, size).write(0); + (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); + (*moves_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for Buffer { + fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + if ((*this) == (o)) { + return (*this).clone(); + } + field!((*this), size).write(o.with(|__s| __s.size)); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + 'for_body: { + array_elem!((*this), data, i).write((array_elem!(o, data, i).read())); + } + i.prefix_inc(); + } + } + (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); + return (*this).clone(); + } +} +impl MoveAssignable for Buffer { + fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + if ((*this) == (o)) { + return (*this).clone(); + } + field!((*this), size).write(o.with(|__s| __s.size)); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + 'for_body: { + array_elem!((*this), data, i).write((array_elem!(o, data, i).read())); + array_elem!(o, data, i).write(-1_i32); + } + i.prefix_inc(); + } + } + field!(o, size).write(0); + (*moves_2.with(Value::clone).borrow_mut()).prefix_inc(); + return (*this).clone(); + } +} impl Clone for Buffer { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Buffer { @@ -44,7 +114,7 @@ impl Clone for Buffer { size: self.size.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - BufferImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -60,10 +130,10 @@ pub fn make_3(mut size: i32) -> Buffer { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_b = - std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(&__p.as_pointer())); return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - BufferImpl::move_from(&__v.as_pointer(), { b.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { b.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -79,14 +149,14 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_a = - std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let b: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - BufferImpl::copy_from(&__v.as_pointer(), { a.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_b = - std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!( ((alive_0.with(|rc| *rc.borrow()) == 2) && (copies_1.with(|rc| *rc.borrow()) == 1)) && (moves_2.with(|rc| *rc.borrow()) == 0) @@ -95,11 +165,11 @@ fn main_0() -> i32 { assert!(((array_elem!(a.as_pointer(), data, 0).read()) == 0)); let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - BufferImpl::move_from(&__v.as_pointer(), { a.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_c = - std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 3) && (moves_2.with(|rc| *rc.borrow()) == 1)); assert!( ({ (*a.borrow()).size } == 0) @@ -110,20 +180,20 @@ fn main_0() -> i32 { ); let d: Value = Rc::new(RefCell::new(({ make_3(2) }))); let _dtor_d = - std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!(({ (*d.borrow()).size } == 2) && (moves_2.with(|rc| *rc.borrow()) == 2)); - ({ BufferImpl::copy_assign(&d.as_pointer(), b.as_pointer()) }); + ({ CopyAssignable::copy_assign(&d.as_pointer(), b.as_pointer()) }); assert!( (({ (*d.borrow()).size } == 4) && ((array_elem!(d.as_pointer(), data, 0).read()) == 100)) && (copies_1.with(|rc| *rc.borrow()) == 2) ); - ({ BufferImpl::move_assign(&d.as_pointer(), c.as_pointer()) }); + ({ MoveAssignable::move_assign(&d.as_pointer(), c.as_pointer()) }); assert!( (((array_elem!(d.as_pointer(), data, 0).read()) == 0) && ({ (*c.borrow()).size } == 0)) && (moves_2.with(|rc| *rc.borrow()) == 3) ); - ({ BufferImpl::move_assign(&d.as_pointer(), d.as_pointer()) }); + ({ MoveAssignable::move_assign(&d.as_pointer(), d.as_pointer()) }); assert!(({ (*d.borrow()).size } == 4) && (moves_2.with(|rc| *rc.borrow()) == 3)); } assert!((alive_0.with(|rc| *rc.borrow()) == 0)); @@ -131,11 +201,6 @@ fn main_0() -> i32 { } pub trait BufferImpl { fn construct(&self, size: i32); - fn destructor(&self); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); - fn copy_assign(&self, o: Ptr) -> Ptr; - fn move_assign(&self, o: Ptr) -> Ptr; } impl BufferImpl for Ptr { fn construct(&self, mut size: i32) { @@ -152,77 +217,6 @@ impl BufferImpl for Ptr { } (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn destructor(&self) { - (*alive_0.with(Value::clone).borrow_mut()).prefix_dec(); - } - fn copy_from(&self, o: Ptr) { - field!((*self), data).write((0..4).map(|_| 0_i32).collect::>()); - field!((*self), size).write(o.with(|__s| __s.size)); - { - let mut i: i32 = 0; - 'loop_: while (i < 4) { - 'for_body: { - array_elem!((*self), data, i).write((array_elem!(o, data, i).read())); - } - i.prefix_inc(); - } - } - (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); - (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn move_from(&self, o: Ptr) { - field!((*self), data).write((0..4).map(|_| 0_i32).collect::>()); - field!((*self), size).write(o.with(|__s| __s.size)); - { - let mut i: i32 = 0; - 'loop_: while (i < 4) { - 'for_body: { - array_elem!((*self), data, i).write((array_elem!(o, data, i).read())); - array_elem!(o, data, i).write(-1_i32); - } - i.prefix_inc(); - } - } - field!(o, size).write(0); - (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); - (*moves_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, o: Ptr) -> Ptr { - if ((*self) == (o)) { - return (*self).clone(); - } - field!((*self), size).write(o.with(|__s| __s.size)); - { - let mut i: i32 = 0; - 'loop_: while (i < 4) { - 'for_body: { - array_elem!((*self), data, i).write((array_elem!(o, data, i).read())); - } - i.prefix_inc(); - } - } - (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); - return (*self).clone(); - } - fn move_assign(&self, o: Ptr) -> Ptr { - if ((*self) == (o)) { - return (*self).clone(); - } - field!((*self), size).write(o.with(|__s| __s.size)); - { - let mut i: i32 = 0; - 'loop_: while (i < 4) { - 'for_body: { - array_elem!((*self), data, i).write((array_elem!(o, data, i).read())); - array_elem!(o, data, i).write(-1_i32); - } - i.prefix_inc(); - } - } - field!(o, size).write(0); - (*moves_2.with(Value::clone).borrow_mut()).prefix_inc(); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = alive_0.with(|_| ()); diff --git a/tests/unit/out/refcount/rule_of_three.rs b/tests/unit/out/refcount/rule_of_three.rs index 1b3279006d..9a27222ee3 100644 --- a/tests/unit/out/refcount/rule_of_three.rs +++ b/tests/unit/out/refcount/rule_of_three.rs @@ -12,9 +12,7 @@ thread_local!( thread_local!( pub static copies_1: Value = Rc::new(RefCell::new(0)); ); -#[derive( - Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Destructible, -)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Movable)] #[cpp_from(i32, construct, value)] #[byte_size(20)] pub struct Buffer { @@ -25,6 +23,47 @@ pub struct Buffer { #[offset(16)] pub size: i32, } +impl Destructible for Buffer { + fn destroy(this: &Ptr) { + (*alive_0.with(Value::clone).borrow_mut()).prefix_dec(); + } +} +impl CopyConstructible for Buffer { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), data).write((0..4).map(|_| 0_i32).collect::>()); + field!((*this), size).write(o.with(|__s| __s.size)); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + 'for_body: { + array_elem!((*this), data, i).write((array_elem!(o, data, i).read())); + } + i.prefix_inc(); + } + } + (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); + (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for Buffer { + fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + if ((*this) == (o)) { + return (*this).clone(); + } + field!((*this), size).write(o.with(|__s| __s.size)); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + 'for_body: { + array_elem!((*this), data, i).write((array_elem!(o, data, i).read())); + } + i.prefix_inc(); + } + } + (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); + return (*this).clone(); + } +} impl Clone for Buffer { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Buffer { @@ -32,7 +71,7 @@ impl Clone for Buffer { size: self.size.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - BufferImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,14 +105,14 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_a = - std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let b: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - BufferImpl::copy_from(&__v.as_pointer(), { a.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_b = - std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 2) && (copies_1.with(|rc| *rc.borrow()) == 1)); array_elem!(b.as_pointer(), data, 0).write(100); assert!(((array_elem!(a.as_pointer(), data, 0).read()) == 0)); @@ -83,28 +122,28 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_c = - std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); - ({ BufferImpl::copy_assign(&c.as_pointer(), a.as_pointer()) }); + std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + ({ CopyAssignable::copy_assign(&c.as_pointer(), a.as_pointer()) }); assert!( ({ (*c.borrow()).size } == 4) && ((array_elem!(c.as_pointer(), data, 3).read()) == 3) ); assert!((alive_0.with(|rc| *rc.borrow()) == 3) && (copies_1.with(|rc| *rc.borrow()) == 2)); - ({ BufferImpl::copy_assign(&c.as_pointer(), c.as_pointer()) }); + ({ CopyAssignable::copy_assign(&c.as_pointer(), c.as_pointer()) }); assert!((copies_1.with(|rc| *rc.borrow()) == 2)); assert!((({ sum_2(a.as_pointer(),) }) == 6)); assert!((({ sum_2(b.as_pointer(),) }) == 106)); let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - BufferImpl::copy_from(&__v.as_pointer(), { a.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_d = - std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 4) && (copies_1.with(|rc| *rc.borrow()) == 3)); assert!( ({ (*a.borrow()).size } == 4) && ((array_elem!(a.as_pointer(), data, 3).read()) == 3) ); - ({ BufferImpl::copy_assign(&d.as_pointer(), b.as_pointer()) }); + ({ CopyAssignable::copy_assign(&d.as_pointer(), b.as_pointer()) }); assert!((copies_1.with(|rc| *rc.borrow()) == 4)); assert!( ((array_elem!(b.as_pointer(), data, 0).read()) == 100) @@ -116,9 +155,6 @@ fn main_0() -> i32 { } pub trait BufferImpl { fn construct(&self, size: i32); - fn destructor(&self); - fn copy_from(&self, o: Ptr); - fn copy_assign(&self, o: Ptr) -> Ptr; } impl BufferImpl for Ptr { fn construct(&self, mut size: i32) { @@ -135,41 +171,6 @@ impl BufferImpl for Ptr { } (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn destructor(&self) { - (*alive_0.with(Value::clone).borrow_mut()).prefix_dec(); - } - fn copy_from(&self, o: Ptr) { - field!((*self), data).write((0..4).map(|_| 0_i32).collect::>()); - field!((*self), size).write(o.with(|__s| __s.size)); - { - let mut i: i32 = 0; - 'loop_: while (i < 4) { - 'for_body: { - array_elem!((*self), data, i).write((array_elem!(o, data, i).read())); - } - i.prefix_inc(); - } - } - (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); - (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, o: Ptr) -> Ptr { - if ((*self) == (o)) { - return (*self).clone(); - } - field!((*self), size).write(o.with(|__s| __s.size)); - { - let mut i: i32 = 0; - 'loop_: while (i < 4) { - 'for_body: { - array_elem!((*self), data, i).write((array_elem!(o, data, i).read())); - } - i.prefix_inc(); - } - } - (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = alive_0.with(|_| ()); diff --git a/tests/unit/out/refcount/rvalue_rule_arg_move.rs b/tests/unit/out/refcount/rvalue_rule_arg_move.rs index 1355ce2156..c9a4113809 100644 --- a/tests/unit/out/refcount/rvalue_rule_arg_move.rs +++ b/tests/unit/out/refcount/rvalue_rule_arg_move.rs @@ -13,7 +13,16 @@ thread_local!( pub static moves_1: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, Default, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + MoveAssignable, + Swappable, + Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -21,11 +30,29 @@ pub struct Elem { #[offset(0)] pub v: i32, } +impl CopyConstructible for Elem { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl MoveConstructible for Elem { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for Elem { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).write(_a0.with(|__s| __s.v)); + return (*this).clone(); + } +} impl Clone for Elem { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Elem { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - ElemImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -55,7 +82,7 @@ fn main_0() -> i32 { let mut __tmp_0 = { >::from(v.decay().end()) }; (*v.borrow_mut()).insert(__tmp_0.index(), { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ElemImpl::move_from(&__v.as_pointer(), { a.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { a.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }); (__tmp_0).clone() @@ -80,26 +107,11 @@ fn main_0() -> i32 { } pub trait ElemImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl ElemImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).write(_a0.with(|__s| __s.v)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); diff --git a/tests/unit/out/refcount/rvalue_struct.rs b/tests/unit/out/refcount/rvalue_struct.rs index a4211a9a33..d6ec68ea12 100644 --- a/tests/unit/out/refcount/rvalue_struct.rs +++ b/tests/unit/out/refcount/rvalue_struct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs b/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs index 03011be665..ed4aea1f54 100644 --- a/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs +++ b/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Pod { #[offset(0)] diff --git a/tests/unit/out/refcount/self_referencing_initializer.rs b/tests/unit/out/refcount/self_referencing_initializer.rs index cefaaf414b..1d66d96e9a 100644 --- a/tests/unit/out/refcount/self_referencing_initializer.rs +++ b/tests/unit/out/refcount/self_referencing_initializer.rs @@ -6,14 +6,18 @@ 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, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct list_head { #[offset(0)] #[byte_size(8)] pub next: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct node { #[offset(0)] @@ -22,7 +26,7 @@ pub struct node { #[byte_size(8)] pub value_ptr: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(16)] pub struct node_with_defaults { #[offset(0)] diff --git a/tests/unit/out/refcount/size_t_static_member.rs b/tests/unit/out/refcount/size_t_static_member.rs index 10d3177ae3..770ab41197 100644 --- a/tests/unit/out/refcount/size_t_static_member.rs +++ b/tests/unit/out/refcount/size_t_static_member.rs @@ -9,13 +9,35 @@ use std::rc::{Rc, Weak}; thread_local!( pub static c_0: Value = Rc::new(RefCell::new(5_usize)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct S {} thread_local!( pub static table_size_1: Value = Rc::new(RefCell::new(256_usize)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Table_char_ {} pub fn main() { diff --git a/tests/unit/out/refcount/size_t_template_param.rs b/tests/unit/out/refcount/size_t_template_param.rs index 488e0e08f6..4df9bccb72 100644 --- a/tests/unit/out/refcount/size_t_template_param.rs +++ b/tests/unit/out/refcount/size_t_template_param.rs @@ -10,14 +10,38 @@ pub fn array_ref_0(a: Ptr) -> u64 { elem!(a, 0).write({ (elem!(a, 0).read()).wrapping_add(1_u64) }); return (elem!(a, (3_u64 as u64).wrapping_sub(1_u64)).read()); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(Ptr< u64 > , construct, value)] #[byte_size(8)] pub struct PtrCtor_unsigned_long_ { #[offset(0)] pub v: u64, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(u64, construct, ptr)] #[byte_size(8)] pub struct RefCtor_unsigned_long_ { diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index 7c10ca9b49..be37c3749a 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -10,7 +10,7 @@ thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign, + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Swappable, )] #[cpp_from(i32, construct_1, value)] #[byte_size(4)] @@ -18,6 +18,30 @@ pub struct Tracked { #[offset(0)] pub v: i32, } +impl CopyConstructible for Tracked { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl MoveConstructible for Tracked { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + } +} +impl CopyAssignable for Tracked { + fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + return (*this).clone(); + } +} +impl MoveAssignable for Tracked { + fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + return (*this).clone(); + } +} impl CppLess for Tracked { fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { operator_lt_1(__lhs.clone(), __rhs.clone()) @@ -33,7 +57,7 @@ impl Clone for Tracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Tracked { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -55,7 +79,7 @@ pub fn greater_2(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) }); } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable, Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -63,6 +87,17 @@ pub struct MoveOnly { #[offset(0)] pub v: i32, } +impl MoveConstructible for MoveOnly { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), v).write({ (*_a0.upgrade().deref()).v }); + } +} +impl MoveAssignable for MoveOnly { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), v).write({ (*_a0.upgrade().deref()).v }); + return (*this).clone(); + } +} impl CppLess for MoveOnly { fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { operator_lt_3(__lhs.clone(), __rhs.clone()) @@ -78,7 +113,17 @@ pub fn operator_lt_3(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct Bag { @@ -86,6 +131,19 @@ pub struct Bag { #[byte_size(24)] pub items: Vec, } +impl MoveConstructible for Bag { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), items).write(field!(_a0, items).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Bag { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), items).with_mut(|__b0| { + (*__b0) = field!(_a0, items).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} impl CppLess for Bag { fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { operator_lt_4(__lhs.clone(), __rhs.clone()) @@ -551,45 +609,17 @@ fn main_0() -> i32 { ); return copies_0.with(|rc| *rc.borrow()); } -pub trait BagImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl BagImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), items).write(field!(_a0, items).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), items).with_mut(|__b0| { - (*__b0) = field!(_a0, items).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub trait MoveOnlyImpl { fn construct(&self, v: i32); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl MoveOnlyImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn move_from(&self, _a0: Ptr) { - field!((*self), v).write({ (*_a0.upgrade().deref()).v }); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), v).write({ (*_a0.upgrade().deref()).v }); - return (*self).clone(); - } } pub trait TrackedImpl { fn construct_2(&self); fn construct_1(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); - fn copy_assign(&self, o: Ptr) -> Ptr; - fn move_assign(&self, o: Ptr) -> Ptr; } impl TrackedImpl for Ptr { fn construct_2(&self) { @@ -598,22 +628,6 @@ impl TrackedImpl for Ptr { fn construct_1(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - } - fn copy_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - return (*self).clone(); - } - fn move_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); diff --git a/tests/unit/out/refcount/static_local.rs b/tests/unit/out/refcount/static_local.rs index 388d6c7496..3ed175144e 100644 --- a/tests/unit/out/refcount/static_local.rs +++ b/tests/unit/out/refcount/static_local.rs @@ -33,7 +33,18 @@ pub fn from_local_class_6() -> i32 { thread_local!( static x_7: Value = Rc::new(RefCell::new(3)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct S_8 {} pub fn main() { diff --git a/tests/unit/out/refcount/static_var_in_class.rs b/tests/unit/out/refcount/static_var_in_class.rs index ccae0ec716..8d391a6b1b 100644 --- a/tests/unit/out/refcount/static_var_in_class.rs +++ b/tests/unit/out/refcount/static_var_in_class.rs @@ -9,7 +9,18 @@ use std::rc::{Rc, Weak}; thread_local!( static inner_const_0: Value = Rc::new(RefCell::new(1)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct C {} thread_local!( @@ -17,7 +28,18 @@ thread_local!( ); pub type anon_3 = u32; pub const anon_3_kValue: anon_3 = 3; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct S {} impl S { diff --git a/tests/unit/out/refcount/stdcopy.rs b/tests/unit/out/refcount/stdcopy.rs index 18e5dd694b..6d528d4b26 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.rs @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Degrees { diff --git a/tests/unit/out/refcount/strdup.rs b/tests/unit/out/refcount/strdup.rs index 11e6da6767..9b7f36ba1c 100644 --- a/tests/unit/out/refcount/strdup.rs +++ b/tests/unit/out/refcount/strdup.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct record { #[offset(0)] diff --git a/tests/unit/out/refcount/string_literal_ptr_init.rs b/tests/unit/out/refcount/string_literal_ptr_init.rs index f37832da8a..a9db369bff 100644 --- a/tests/unit/out/refcount/string_literal_ptr_init.rs +++ b/tests/unit/out/refcount/string_literal_ptr_init.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(24)] pub struct label { #[offset(0)] diff --git a/tests/unit/out/refcount/string_substr.rs b/tests/unit/out/refcount/string_substr.rs index 1139944553..9654157b5f 100644 --- a/tests/unit/out/refcount/string_substr.rs +++ b/tests/unit/out/refcount/string_substr.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Text { #[offset(0)] diff --git a/tests/unit/out/refcount/struct_2d_array_field.rs b/tests/unit/out/refcount/struct_2d_array_field.rs index 48508b8750..8d55fa4e4c 100644 --- a/tests/unit/out/refcount/struct_2d_array_field.rs +++ b/tests/unit/out/refcount/struct_2d_array_field.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 08388d9416..6d9217fe9a 100644 --- a/tests/unit/out/refcount/struct_ctor.rs +++ b/tests/unit/out/refcount/struct_ctor.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct StructWithCtor { #[offset(0)] @@ -17,14 +28,28 @@ pub struct StructWithCtor { pub fn foo_0(x: Ptr) -> Ptr { return (x).clone(); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Value_ { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct Ptr_ { #[offset(0)] diff --git a/tests/unit/out/refcount/struct_default_ctor.rs b/tests/unit/out/refcount/struct_default_ctor.rs index 419500f560..02999b4f04 100644 --- a/tests/unit/out/refcount/struct_default_ctor.rs +++ b/tests/unit/out/refcount/struct_default_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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -25,13 +27,24 @@ impl Default for S { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Declared { #[offset(0)] pub v: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(16)] pub struct Holder { #[offset(0)] @@ -51,7 +64,9 @@ impl Default for Holder { thread_local!( pub static kInit_0: Value = Rc::new(RefCell::new(3)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct FromStatic { #[offset(0)] diff --git a/tests/unit/out/refcount/struct_member_array_adjacency.rs b/tests/unit/out/refcount/struct_member_array_adjacency.rs index 9392526a17..0f42dbdec4 100644 --- a/tests/unit/out/refcount/struct_member_array_adjacency.rs +++ b/tests/unit/out/refcount/struct_member_array_adjacency.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[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 c34fbc8c35..645a01d1e2 100644 --- a/tests/unit/out/refcount/struct_ptr.rs +++ b/tests/unit/out/refcount/struct_ptr.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct XX { #[offset(0)] diff --git a/tests/unit/out/refcount/structured_binding_copy_ctor.rs b/tests/unit/out/refcount/structured_binding_copy_ctor.rs index f98ca642eb..34fa568b56 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Movable, Default)] #[byte_size(8)] pub struct Counted { #[offset(0)] @@ -17,6 +17,20 @@ pub struct Counted { #[offset(4)] pub y: i32, } +impl CopyConstructible for Counted { + fn copy_constructor(this: &Ptr, other: Ptr) { + field!((*this), x).write((other.with(|__s| __s.x) * 2)); + field!((*this), y).write((other.with(|__s| __s.y) * 2)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for Counted { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), x).write(_a0.with(|__s| __s.x)); + field!((*this), y).write(_a0.with(|__s| __s.y)); + return (*this).clone(); + } +} impl Clone for Counted { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Counted { @@ -24,7 +38,7 @@ impl Clone for Counted { y: self.y.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -47,7 +61,7 @@ fn main_0() -> i32 { })); let __decomp_2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::copy_from(&__v.as_pointer(), { s.as_pointer() }); + CopyConstructible::copy_constructor(&__v.as_pointer(), { s.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((copies_0.with(|rc| *rc.borrow()) == 1)); @@ -68,24 +82,12 @@ fn main_0() -> i32 { } pub trait CountedImpl { fn construct(&self, x: i32, y: i32); - fn copy_from(&self, other: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; } impl CountedImpl for Ptr { fn construct(&self, mut x: i32, mut y: i32) { field!((*self), x).write(x); field!((*self), y).write(y); } - fn copy_from(&self, other: Ptr) { - field!((*self), x).write((other.with(|__s| __s.x) * 2)); - field!((*self), y).write((other.with(|__s| __s.y) * 2)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), x).write(_a0.with(|__s| __s.x)); - field!((*self), y).write(_a0.with(|__s| __s.y)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); diff --git a/tests/unit/out/refcount/structured_binding_element_ctor.rs b/tests/unit/out/refcount/structured_binding_element_ctor.rs index f73a2d0c41..c604e9ece0 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -12,22 +12,60 @@ thread_local!( thread_local!( pub static moves_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Elem { #[offset(0)] pub v: i32, } +impl CopyConstructible for Elem { + fn copy_constructor(this: &Ptr, other: Ptr) { + field!((*this), v).write((other.with(|__s| __s.v) + 100)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl MoveConstructible for Elem { + fn move_constructor(this: &Ptr, other: Ptr) { + field!((*this), v).write((other.with(|__s| __s.v) + 1000)); + field!(other, v).write(-1_i32); + (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl Clone for Elem { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Elem { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - ElemImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[byte_size(8)] pub struct Two { #[offset(0)] @@ -37,6 +75,20 @@ pub struct Two { #[byte_size(4)] pub b: Elem, } +impl MoveConstructible for Two { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), a).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, a) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + field!((*this), b).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, b) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + } +} pub fn make_two_2() -> Two { return Two { a: { @@ -82,7 +134,7 @@ fn main_0() -> i32 { assert!(({ (*t.borrow()).a.v } == 50)); let __decomp_5: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TwoImpl::move_from(&__v.as_pointer(), { t.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { t.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((moves_1.with(|rc| *rc.borrow()) == (base_moves + 2))); @@ -121,39 +173,11 @@ fn main_0() -> i32 { } pub trait ElemImpl { fn construct(&self, v: i32); - fn copy_from(&self, other: Ptr); - fn move_from(&self, other: Ptr); } impl ElemImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, other: Ptr) { - field!((*self), v).write((other.with(|__s| __s.v) + 100)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn move_from(&self, other: Ptr) { - field!((*self), v).write((other.with(|__s| __s.v) + 1000)); - field!(other, v).write(-1_i32); - (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait TwoImpl { - fn move_from(&self, _a0: Ptr); -} -impl TwoImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), a).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ElemImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, a) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - field!((*self), b).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ElemImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, b) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - } } pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); diff --git a/tests/unit/out/refcount/structured_binding_move_ctor.rs b/tests/unit/out/refcount/structured_binding_move_ctor.rs index 8fce5a265f..9343853cc3 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -12,7 +12,18 @@ thread_local!( thread_local!( pub static moves_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyAssignable, + MoveAssignable, + Swappable, + Default, +)] #[byte_size(8)] pub struct Movable { #[offset(0)] @@ -20,6 +31,22 @@ pub struct Movable { #[offset(4)] pub y: i32, } +impl CopyConstructible for Movable { + fn copy_constructor(this: &Ptr, other: Ptr) { + field!((*this), x).write(other.with(|__s| __s.x)); + field!((*this), y).write(other.with(|__s| __s.y)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl MoveConstructible for Movable { + fn move_constructor(this: &Ptr, other: Ptr) { + field!((*this), x).write(other.with(|__s| __s.x)); + field!((*this), y).write(other.with(|__s| __s.y)); + field!(other, x).write(0); + field!(other, y).write(0); + (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl Clone for Movable { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Movable { @@ -27,12 +54,22 @@ impl Clone for Movable { y: self.y.clone(), })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - MovableImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(48)] pub struct Holder { @@ -43,6 +80,23 @@ pub struct Holder { #[byte_size(24)] pub ys: Vec, } +impl MoveConstructible for Holder { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), xs).write(field!(_a0, xs).with_mut(std::mem::take)); + field!((*this), ys).write(field!(_a0, ys).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Holder { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), xs).with_mut(|__b0| { + (*__b0) = field!(_a0, xs).with_mut(std::mem::take); + }); + field!((*this), ys).with_mut(|__b0| { + (*__b0) = field!(_a0, ys).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -55,7 +109,7 @@ fn main_0() -> i32 { })); let __decomp_2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - MovableImpl::move_from(&__v.as_pointer(), { m.as_pointer() }); + MoveConstructible::move_constructor(&__v.as_pointer(), { m.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((moves_1.with(|rc| *rc.borrow()) == 1)); @@ -80,8 +134,6 @@ fn main_0() -> i32 { } pub trait HolderImpl { fn extract(&self) -> Holder; - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl HolderImpl for Ptr { fn extract(&self) -> Holder { @@ -90,42 +142,15 @@ impl HolderImpl for Ptr { ys: field!((*self), ys).with_mut(std::mem::take), }; } - fn move_from(&self, _a0: Ptr) { - field!((*self), xs).write(field!(_a0, xs).with_mut(std::mem::take)); - field!((*self), ys).write(field!(_a0, ys).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), xs).with_mut(|__b0| { - (*__b0) = field!(_a0, xs).with_mut(std::mem::take); - }); - field!((*self), ys).with_mut(|__b0| { - (*__b0) = field!(_a0, ys).with_mut(std::mem::take); - }); - return (*self).clone(); - } } pub trait MovableImpl { fn construct(&self, x: i32, y: i32); - fn copy_from(&self, other: Ptr); - fn move_from(&self, other: Ptr); } impl MovableImpl for Ptr { fn construct(&self, mut x: i32, mut y: i32) { field!((*self), x).write(x); field!((*self), y).write(y); } - fn copy_from(&self, other: Ptr) { - field!((*self), x).write(other.with(|__s| __s.x)); - field!((*self), y).write(other.with(|__s| __s.y)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn move_from(&self, other: Ptr) { - field!((*self), x).write(other.with(|__s| __s.x)); - field!((*self), y).write(other.with(|__s| __s.y)); - field!(other, x).write(0); - field!(other, y).write(0); - (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); - } } pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); diff --git a/tests/unit/out/refcount/structured_binding_range_for.rs b/tests/unit/out/refcount/structured_binding_range_for.rs index 468abc78a8..7569d20585 100644 --- a/tests/unit/out/refcount/structured_binding_range_for.rs +++ b/tests/unit/out/refcount/structured_binding_range_for.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/structured_binding_ref.rs b/tests/unit/out/refcount/structured_binding_ref.rs index b0fbabb77b..6e61003ae0 100644 --- a/tests/unit/out/refcount/structured_binding_ref.rs +++ b/tests/unit/out/refcount/structured_binding_ref.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(12)] pub struct Triple { #[offset(0)] diff --git a/tests/unit/out/refcount/structured_binding_trivial.rs b/tests/unit/out/refcount/structured_binding_trivial.rs index 8d4fcf3756..49f6ed7177 100644 --- a/tests/unit/out/refcount/structured_binding_trivial.rs +++ b/tests/unit/out/refcount/structured_binding_trivial.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/swap_malloc.rs b/tests/unit/out/refcount/swap_malloc.rs index d153f5305b..f40b2a8bc5 100644 --- a/tests/unit/out/refcount/swap_malloc.rs +++ b/tests/unit/out/refcount/swap_malloc.rs @@ -17,31 +17,31 @@ fn main_0() -> i32 { elem!(buf, 0).write(1); elem!(buf, 1).write(2); elem!(buf, 2).write(3); - cpp_swap!(buf.offset((0) as isize), buf.offset((2) as isize)); + Swappable::swap(&buf.offset((0) as isize), buf.offset((2) as isize)); assert!( (((elem!(buf, 0).read()) == 3) && ((elem!(buf, 1).read()) == 2)) && ((elem!(buf, 2).read()) == 1) ); - cpp_swap!(buf.offset((1) as isize), buf.offset((1) as isize)); + Swappable::swap(&buf.offset((1) as isize), buf.offset((1) as isize)); assert!(((elem!(buf, 1).read()) == 2)); let local: Value = Rc::new(RefCell::new(4)); - cpp_swap!(buf.offset((1) as isize), local.as_pointer()); + Swappable::swap(&buf.offset((1) as isize), local.as_pointer()); assert!(({ ((elem!(buf, 1).read()) == 4) && ((*local.borrow()) == 2) })); let mut other: Ptr = libcc2rs::malloc_refcount(::std::mem::size_of::()).reinterpret_cast::(); other.write(5); - cpp_swap!((buf).clone(), (other).clone()); + Swappable::swap(&(buf).clone(), (other).clone()); assert!(((elem!(buf, 0).read()) == 5) && ((other.read()) == 3)); let mut bytes: Ptr = buf.reinterpret_cast::(); elem!(bytes, 0).write(170_u8); elem!(bytes, 4).write(187_u8); - cpp_swap!(bytes.offset((0) as isize), bytes.offset((4) as isize)); + Swappable::swap(&bytes.offset((0) as isize), bytes.offset((4) as isize)); assert!( (((elem!(bytes, 0).read()) as i32) == 187) && (((elem!(bytes, 4).read()) as i32) == 170) ); let words: Value> = Rc::new(RefCell::new(Box::new([16909060_u32, 84281096_u32]))); let mut halves: Ptr = words.decay().reinterpret_cast::(); - cpp_swap!(halves.offset((0) as isize), halves.offset((3) as isize)); + Swappable::swap(&halves.offset((0) as isize), halves.offset((3) as isize)); assert!( ({ ((*words.borrow())[(0) as usize] == 16909574_u32) @@ -52,7 +52,7 @@ fn main_0() -> i32 { let s2: Value = Rc::new(RefCell::new(2)); let sp: Value> = Rc::new(RefCell::new((s1.as_pointer()))); let sq: Value> = Rc::new(RefCell::new((s2.as_pointer()))); - cpp_swap!(sp.as_pointer(), sq.as_pointer()); + Swappable::swap(&sp.as_pointer(), sq.as_pointer()); assert!( ({ ({ (*sp.borrow()).clone() } == { (s2.as_pointer()) }) @@ -61,7 +61,7 @@ fn main_0() -> i32 { ); assert!(({ ((*s1.borrow()) == 1) && ((*s2.borrow()) == 2) })); let null_ptr: Value> = Rc::new(RefCell::new(Ptr::::null())); - cpp_swap!(null_ptr.as_pointer(), sp.as_pointer()); + Swappable::swap(&null_ptr.as_pointer(), sp.as_pointer()); assert!( ({ ({ (*null_ptr.borrow()).clone() } == { (s2.as_pointer()) }) diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 1cecae8b63..a6d469ae37 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -10,7 +10,7 @@ thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign, + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Swappable, )] #[cpp_from(i32, construct_1, value)] #[byte_size(4)] @@ -18,11 +18,35 @@ pub struct Tracked { #[offset(0)] pub v: i32, } +impl CopyConstructible for Tracked { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl MoveConstructible for Tracked { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + } +} +impl CopyAssignable for Tracked { + fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + return (*this).clone(); + } +} +impl MoveAssignable for Tracked { + fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + return (*this).clone(); + } +} impl Clone for Tracked { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Tracked { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -44,9 +68,9 @@ impl Default for Tracked { ZeroInitialization, VaArg, FnPtrArg, - MoveCtor, - CopyAssign, - MoveAssign, + Destructible, + CopyConstructible, + Swappable, Default, )] #[byte_size(8)] @@ -58,8 +82,44 @@ pub struct Pair { #[byte_size(4)] pub y: Tracked, } +impl MoveConstructible for Pair { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), x).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, x) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + field!((*this), y).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, y) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + } +} +impl CopyAssignable for Pair { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + ({ CopyAssignable::copy_assign(&field_ptr!((*this), x), field_ptr!(_a0, x)) }); + ({ CopyAssignable::copy_assign(&field_ptr!((*this), y), field_ptr!(_a0, y)) }); + return (*this).clone(); + } +} +impl MoveAssignable for Pair { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + ({ MoveAssignable::move_assign(&field_ptr!((*this), x), field_ptr!(_a0, x)) }); + ({ MoveAssignable::move_assign(&field_ptr!((*this), y), field_ptr!(_a0, y)) }); + return (*this).clone(); + } +} #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CopyAssign, MoveAssign, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + Swappable, )] #[byte_size(16)] pub struct Arrays { @@ -72,6 +132,90 @@ pub struct Arrays { #[array_len(2)] pub b: Box<[Tracked]>, } +impl MoveConstructible for Arrays { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), a).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { + array_field_ptr!(_a0, a).offset(__i) + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); + field!((*this), b).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { + array_field_ptr!(_a0, b).offset(__i) + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); + } +} +impl CopyAssignable for Arrays { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + { + let mut __i0: usize = 0_usize; + 'loop_: while (__i0 != 2_usize) { + 'for_body: { + ({ + CopyAssignable::copy_assign( + &array_field_ptr!((*this), a).offset((__i0) as isize), + array_field_ptr!(_a0, a).offset((__i0) as isize), + ) + }); + } + __i0.prefix_inc(); + } + } + { + let mut __i0: usize = 0_usize; + 'loop_: while (__i0 != 2_usize) { + 'for_body: { + ({ + CopyAssignable::copy_assign( + &array_field_ptr!((*this), b).offset((__i0) as isize), + array_field_ptr!(_a0, b).offset((__i0) as isize), + ) + }); + } + __i0.prefix_inc(); + } + } + return (*this).clone(); + } +} +impl MoveAssignable for Arrays { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + { + let mut __i0: usize = 0_usize; + 'loop_: while (__i0 != 2_usize) { + 'for_body: { + ({ + MoveAssignable::move_assign( + &array_field_ptr!((*this), a).offset((__i0) as isize), + array_field_ptr!(_a0, a).offset((__i0) as isize), + ) + }); + } + __i0.prefix_inc(); + } + } + { + let mut __i0: usize = 0_usize; + 'loop_: while (__i0 != 2_usize) { + 'for_body: { + ({ + MoveAssignable::move_assign( + &array_field_ptr!((*this), b).offset((__i0) as isize), + array_field_ptr!(_a0, b).offset((__i0) as isize), + ) + }); + } + __i0.prefix_inc(); + } + } + return (*this).clone(); + } +} impl Default for Arrays { fn default() -> Self { { @@ -92,33 +236,49 @@ thread_local!( thread_local!( pub static copy_only_dtors_2: Value = Rc::new(RefCell::new(0)); ); -#[derive( - Record, - ByteRepr, - ZeroInitialization, - VaArg, - FnPtrArg, - CppFrom, - CopyAssign, - Destructible, - Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Movable, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct CopyOnly { #[offset(0)] pub v: i32, } +impl CopyConstructible for CopyOnly { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copy_only_copies_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl Destructible for CopyOnly { + fn destroy(this: &Ptr) { + (*copy_only_dtors_2.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for CopyOnly { + fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copy_only_copies_1.with(Value::clone).borrow_mut()).prefix_inc(); + return (*this).clone(); + } +} impl Clone for CopyOnly { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(CopyOnly { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyOnlyImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructible, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + Movable, + Default, )] #[byte_size(8)] pub struct CopyOnlyPair { @@ -129,6 +289,19 @@ pub struct CopyOnlyPair { #[byte_size(4)] pub y: CopyOnly, } +impl CopyAssignable for CopyOnlyPair { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + ({ CopyAssignable::copy_assign(&field_ptr!((*this), x), field_ptr!(_a0, x)) }); + ({ CopyAssignable::copy_assign(&field_ptr!((*this), y), field_ptr!(_a0, y)) }); + return (*this).clone(); + } +} +impl Destructible for CopyOnlyPair { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, y)); + Destructible::destroy(&field_ptr!(this, x)); + } +} thread_local!( pub static moves_3: Value = Rc::new(RefCell::new(0)); ); @@ -138,30 +311,51 @@ thread_local!( thread_local!( pub static moved_dtors_5: Value = Rc::new(RefCell::new(0)); ); -#[derive( - Record, - ByteRepr, - ZeroInitialization, - VaArg, - FnPtrArg, - MoveCtor, - CppFrom, - CopyAssign, - MoveAssign, - Destructible, - Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Swappable, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Moved { #[offset(0)] pub v: i32, } +impl CopyConstructible for Moved { + fn copy_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl MoveConstructible for Moved { + fn move_constructor(this: &Ptr, o: Ptr) { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(-1_i32); + (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +impl CopyAssignable for Moved { + fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + return (*this).clone(); + } +} +impl MoveAssignable for Moved { + fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + field!((*this), v).write(o.with(|__s| __s.v)); + field!(o, v).write(-1_i32); + (*move_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); + return (*this).clone(); + } +} +impl Destructible for Moved { + fn destroy(this: &Ptr) { + (*moved_dtors_5.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl Clone for Moved { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Moved { v: self.v.clone() })); let __v: Value = Rc::new(RefCell::new(::zero_init())); - MovedImpl::copy_from(&__v.as_pointer(), __src.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), __src.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -172,10 +366,8 @@ impl Clone for Moved { ZeroInitialization, VaArg, FnPtrArg, - MoveCtor, - CopyAssign, - MoveAssign, - Destructible, + CopyConstructible, + Swappable, Default, )] #[byte_size(8)] @@ -187,6 +379,40 @@ pub struct MovedPair { #[byte_size(4)] pub y: Moved, } +impl MoveConstructible for MovedPair { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), x).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, x) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + field!((*this), y).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, y) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + } +} +impl CopyAssignable for MovedPair { + fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + ({ CopyAssignable::copy_assign(&field_ptr!((*this), x), field_ptr!(_a0, x)) }); + ({ CopyAssignable::copy_assign(&field_ptr!((*this), y), field_ptr!(_a0, y)) }); + return (*this).clone(); + } +} +impl MoveAssignable for MovedPair { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + ({ MoveAssignable::move_assign(&field_ptr!((*this), x), field_ptr!(_a0, x)) }); + ({ MoveAssignable::move_assign(&field_ptr!((*this), y), field_ptr!(_a0, y)) }); + return (*this).clone(); + } +} +impl Destructible for MovedPair { + fn destroy(this: &Ptr) { + Destructible::destroy(&field_ptr!(this, y)); + Destructible::destroy(&field_ptr!(this, x)); + } +} pub fn swapped_once_6() -> bool { let mut ok: bool = ((moves_3.with(|rc| *rc.borrow()) == 1) && (move_assigns_4.with(|rc| *rc.borrow()) == 2)) @@ -204,13 +430,27 @@ pub fn swapped_once_6() -> bool { }); return ok; } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Default)] #[byte_size(8)] pub struct Owner { #[offset(0)] #[byte_size(8)] pub p: Option>, } +impl MoveConstructible for Owner { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), p) + .write(field!(_a0, p).with_mut(|__v: &mut Option>| __v.take())); + } +} +impl MoveAssignable for Owner { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), p).with_mut(|__b0| { + (*__b0) = field!(_a0, p).with_mut(|__v: &mut Option>| __v.take()); + }); + return (*this).clone(); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -226,7 +466,7 @@ fn main_0() -> i32 { TrackedImpl::construct_1(&__v.as_pointer(), { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - cpp_swap!(a.as_pointer(), b.as_pointer()); + Swappable::swap(&a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 2) && ({ (*b.borrow()).v } == 1)); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let m1: Value, Value)>> = Rc::new(RefCell::new(Map::new())); @@ -236,7 +476,7 @@ fn main_0() -> i32 { TrackedImpl::construct_1(&__v.as_pointer(), { 10 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - TrackedImpl::move_assign( + MoveAssignable::move_assign( &match (Rc::new(RefCell::new(1)).as_pointer(),) { (__tmp_0,) => { ({ @@ -257,7 +497,7 @@ fn main_0() -> i32 { TrackedImpl::construct_1(&__v.as_pointer(), { 20 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - TrackedImpl::move_assign( + MoveAssignable::move_assign( &match (Rc::new(RefCell::new(2)).as_pointer(),) { (__tmp_1,) => { ({ @@ -279,7 +519,7 @@ fn main_0() -> i32 { TrackedImpl::construct_1(&__v.as_pointer(), { 30 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - TrackedImpl::move_assign( + MoveAssignable::move_assign( &match (Rc::new(RefCell::new(3)).as_pointer(),) { (__tmp_2,) => { ({ @@ -295,8 +535,8 @@ fn main_0() -> i32 { ) }); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - cpp_swap!( - match (Rc::new(RefCell::new(1)).as_pointer(),) { + Swappable::swap( + &match (Rc::new(RefCell::new(1)).as_pointer(),) { (__tmp_3,) => { ({ (*m1.borrow_mut()).subscript_move( @@ -317,7 +557,7 @@ fn main_0() -> i32 { ) }) } - } + }, ); assert!( (match (Rc::new(RefCell::new(1)).as_pointer(),) { @@ -348,7 +588,7 @@ fn main_0() -> i32 { == 10) ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - cpp_swap!(m1.as_pointer(), m2.as_pointer()); + Swappable::swap(&m1.as_pointer(), m2.as_pointer()); assert!( ((*m1.borrow()).len() == 1_usize) && (match (Rc::new(RefCell::new(3)).as_pointer(),) { @@ -412,11 +652,11 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]))); - cpp_swap!(arr.decay().offset(0), arr.decay().offset(2)); + Swappable::swap(&arr.decay().offset(0), arr.decay().offset(2)); assert!( ({ (*arr.borrow())[(0) as usize].v } == 3) && ({ (*arr.borrow())[(2) as usize].v } == 1) ); - cpp_swap!(arr.decay().offset(1), arr.decay().offset(1)); + Swappable::swap(&arr.decay().offset(1), arr.decay().offset(1)); assert!(({ (*arr.borrow())[(1) as usize].v } == 2)); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); @@ -440,7 +680,7 @@ fn main_0() -> i32 { }; (*vec_.borrow_mut()).push(__tmp_11); }; - cpp_swap!(vec_.decay().offset(0_usize), vec_.decay().offset(1_usize)); + Swappable::swap(&vec_.decay().offset(0_usize), vec_.decay().offset(1_usize)); assert!(({ (*vec_.borrow())[0_usize].v } == 5) && ({ (*vec_.borrow())[1_usize].v } == 4)); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let pairs: Value> = Rc::new(RefCell::new(Box::new([ @@ -481,22 +721,25 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); - cpp_swap!( - field_ptr!(pairs.decay().offset(0), x), - field_ptr!(p.as_pointer(), y) + Swappable::swap( + &field_ptr!(pairs.decay().offset(0), x), + field_ptr!(p.as_pointer(), y), ); assert!(({ (*pairs.borrow())[(0) as usize].x.v } == 11) && ({ (*p.borrow()).y.v } == 6)); - cpp_swap!(pairs.decay().offset(0), pairs.decay().offset(1)); + Swappable::swap(&pairs.decay().offset(0), pairs.decay().offset(1)); assert!( ({ (*pairs.borrow())[(0) as usize].x.v } == 8) && ({ (*pairs.borrow())[(1) as usize].x.v } == 11) ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - cpp_swap!(field_ptr!(p.as_pointer(), x), field_ptr!(p.as_pointer(), y)); + Swappable::swap( + &field_ptr!(p.as_pointer(), x), + field_ptr!(p.as_pointer(), y), + ); assert!(({ (*p.borrow()).x.v } == 6) && ({ (*p.borrow()).y.v } == 10)); - cpp_swap!( - field_ptr!(pairs.decay().offset(0), x), - field_ptr!(pairs.decay().offset(1), y) + Swappable::swap( + &field_ptr!(pairs.decay().offset(0), x), + field_ptr!(pairs.decay().offset(1), y), ); assert!( ({ (*pairs.borrow())[(0) as usize].x.v } == 7) @@ -506,17 +749,17 @@ fn main_0() -> i32 { let arrays: Value = Rc::new(RefCell::new(::default())); field!(array_elem!(arrays.as_pointer(), a, 0), v).write(1); field!(array_elem!(arrays.as_pointer(), b, 1), v).write(2); - cpp_swap!( - array_field_ptr!(arrays.as_pointer(), a).offset((0) as isize), - array_field_ptr!(arrays.as_pointer(), b).offset((1) as isize) + Swappable::swap( + &array_field_ptr!(arrays.as_pointer(), a).offset((0) as isize), + array_field_ptr!(arrays.as_pointer(), b).offset((1) as isize), ); assert!( (array_elem!(arrays.as_pointer(), a, 0).with(|__s| __s.v) == 2) && (array_elem!(arrays.as_pointer(), b, 1).with(|__s| __s.v) == 1) ); - cpp_swap!( - array_field_ptr!(arrays.as_pointer(), a).offset((0) as isize), - array_field_ptr!(arrays.as_pointer(), a).offset((1) as isize) + Swappable::swap( + &array_field_ptr!(arrays.as_pointer(), a).offset((0) as isize), + array_field_ptr!(arrays.as_pointer(), a).offset((1) as isize), ); assert!( (array_elem!(arrays.as_pointer(), a, 0).with(|__s| __s.v) == 0) @@ -558,15 +801,15 @@ fn main_0() -> i32 { __tmp_16.with_mut(|__v: &mut Vec| __v.push(__tmp_17)); } }; - cpp_swap!( - grid.decay().offset(0_usize).decay().offset(1_usize), - grid.decay().offset(1_usize).decay().offset(0_usize) + Swappable::swap( + &grid.decay().offset(0_usize).decay().offset(1_usize), + grid.decay().offset(1_usize).decay().offset(0_usize), ); assert!( (index!(elem!(grid.decay(), 0_usize), 1_usize).with(|__s| __s.v) == 3) && (index!(elem!(grid.decay(), 1_usize), 0_usize).with(|__s| __s.v) == 2) ); - cpp_swap!(grid.decay().offset(0_usize), grid.decay().offset(1_usize)); + Swappable::swap(&grid.decay().offset(0_usize), grid.decay().offset(1_usize)); assert!( ({ ((*grid.decay().offset(0_usize).upgrade().deref()).len() == 1_usize) @@ -585,7 +828,7 @@ fn main_0() -> i32 { TrackedImpl::construct_1(&__v.as_pointer(), { 1 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - TrackedImpl::move_assign( + MoveAssignable::move_assign( &match (Rc::new(RefCell::new(1)).as_pointer(),) { (__tmp_18,) => { ({ @@ -606,7 +849,7 @@ fn main_0() -> i32 { TrackedImpl::construct_1(&__v.as_pointer(), { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - TrackedImpl::move_assign( + MoveAssignable::move_assign( &match (Rc::new(RefCell::new(2)).as_pointer(),) { (__tmp_19,) => { ({ @@ -621,7 +864,7 @@ fn main_0() -> i32 { _o.as_pointer(), ) }); - cpp_swap!(maps.decay().offset(0), maps.decay().offset(1)); + Swappable::swap(&maps.decay().offset(0), maps.decay().offset(1)); assert!( ((*maps.borrow())[(0) as usize].len() == 1_usize) && (match (Rc::new(RefCell::new(2)).as_pointer(),) { @@ -661,15 +904,15 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_c1 = - std::mem::DropGuard::new(c1.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(c1.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let c2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); CopyOnlyImpl::construct(&__v.as_pointer(), { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_c2 = - std::mem::DropGuard::new(c2.clone(), |__p| Destructible::destroy(__p.as_pointer())); - cpp_swap!(c1.as_pointer(), c2.as_pointer()); + std::mem::DropGuard::new(c2.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + Swappable::swap(&c1.as_pointer(), c2.as_pointer()); assert!(({ (*c1.borrow()).v } == 2) && ({ (*c2.borrow()).v } == 1)); assert!( (copy_only_copies_1.with(|rc| *rc.borrow()) == 3) @@ -688,10 +931,10 @@ fn main_0() -> i32 { }, })); let _dtor_cp = - std::mem::DropGuard::new(cp.clone(), |__p| Destructible::destroy(__p.as_pointer())); - cpp_swap!( - field_ptr!(cp.as_pointer(), x), - field_ptr!(cp.as_pointer(), y) + std::mem::DropGuard::new(cp.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + Swappable::swap( + &field_ptr!(cp.as_pointer(), x), + field_ptr!(cp.as_pointer(), y), ); assert!(({ (*cp.borrow()).x.v } == 4) && ({ (*cp.borrow()).y.v } == 3)); assert!( @@ -710,7 +953,7 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]))); - cpp_swap!(carr.decay().offset(0), carr.decay().offset(1)); + Swappable::swap(&carr.decay().offset(0), carr.decay().offset(1)); assert!( ({ (*carr.borrow())[(0) as usize].v } == 6) && ({ (*carr.borrow())[(1) as usize].v } == 5) ); @@ -724,15 +967,15 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_mv1 = - std::mem::DropGuard::new(mv1.clone(), |__p| Destructible::destroy(__p.as_pointer())); + std::mem::DropGuard::new(mv1.clone(), |__p| Destructible::destroy(&__p.as_pointer())); let mv2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); MovedImpl::construct(&__v.as_pointer(), { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let _dtor_mv2 = - std::mem::DropGuard::new(mv2.clone(), |__p| Destructible::destroy(__p.as_pointer())); - cpp_swap!(mv1.as_pointer(), mv2.as_pointer()); + std::mem::DropGuard::new(mv2.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + Swappable::swap(&mv1.as_pointer(), mv2.as_pointer()); assert!(({ (*mv1.borrow()).v } == 2) && ({ (*mv2.borrow()).v } == 1)); assert!(({ swapped_once_6() })); let mp: Value = Rc::new(RefCell::new(MovedPair { @@ -748,10 +991,10 @@ fn main_0() -> i32 { }, })); let _dtor_mp = - std::mem::DropGuard::new(mp.clone(), |__p| Destructible::destroy(__p.as_pointer())); - cpp_swap!( - field_ptr!(mp.as_pointer(), x), - field_ptr!(mp.as_pointer(), y) + std::mem::DropGuard::new(mp.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + Swappable::swap( + &field_ptr!(mp.as_pointer(), x), + field_ptr!(mp.as_pointer(), y), ); assert!(({ (*mp.borrow()).x.v } == 4) && ({ (*mp.borrow()).y.v } == 3)); assert!(({ swapped_once_6() })); @@ -767,12 +1010,12 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]))); - cpp_swap!(marr.decay().offset(0), marr.decay().offset(1)); + Swappable::swap(&marr.decay().offset(0), marr.decay().offset(1)); assert!( ({ (*marr.borrow())[(0) as usize].v } == 6) && ({ (*marr.borrow())[(1) as usize].v } == 5) ); assert!(({ swapped_once_6() })); - cpp_swap!(mv1.as_pointer(), mv1.as_pointer()); + Swappable::swap(&mv1.as_pointer(), mv1.as_pointer()); assert!(({ (*mv1.borrow()).v } == 2)); assert!(({ swapped_once_6() })); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); @@ -782,254 +1025,32 @@ fn main_0() -> i32 { let o2: Value = Rc::new(RefCell::new(Owner { p: Some(Rc::new(RefCell::new(2))), })); - cpp_swap!(o1.as_pointer(), o2.as_pointer()); + Swappable::swap(&o1.as_pointer(), o2.as_pointer()); assert!( (({ (*o1.borrow()).p.clone() }.as_pointer().read()) == 2) && (({ (*o2.borrow()).p.clone() }.as_pointer().read()) == 1) ); return copies_0.with(|rc| *rc.borrow()); } -pub trait ArraysImpl { - fn move_from(&self, _a0: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl ArraysImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), a).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::move_from(&__v.as_pointer(), { array_field_ptr!(_a0, a).offset(__i) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }))); - field!((*self), b).write(Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::move_from(&__v.as_pointer(), { array_field_ptr!(_a0, b).offset(__i) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }))); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - { - let mut __i0: usize = 0_usize; - 'loop_: while (__i0 != 2_usize) { - 'for_body: { - ({ - TrackedImpl::copy_assign( - &array_field_ptr!((*self), a).offset((__i0) as isize), - array_field_ptr!(_a0, a).offset((__i0) as isize), - ) - }); - } - __i0.prefix_inc(); - } - } - { - let mut __i0: usize = 0_usize; - 'loop_: while (__i0 != 2_usize) { - 'for_body: { - ({ - TrackedImpl::copy_assign( - &array_field_ptr!((*self), b).offset((__i0) as isize), - array_field_ptr!(_a0, b).offset((__i0) as isize), - ) - }); - } - __i0.prefix_inc(); - } - } - return (*self).clone(); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - { - let mut __i0: usize = 0_usize; - 'loop_: while (__i0 != 2_usize) { - 'for_body: { - ({ - TrackedImpl::move_assign( - &array_field_ptr!((*self), a).offset((__i0) as isize), - array_field_ptr!(_a0, a).offset((__i0) as isize), - ) - }); - } - __i0.prefix_inc(); - } - } - { - let mut __i0: usize = 0_usize; - 'loop_: while (__i0 != 2_usize) { - 'for_body: { - ({ - TrackedImpl::move_assign( - &array_field_ptr!((*self), b).offset((__i0) as isize), - array_field_ptr!(_a0, b).offset((__i0) as isize), - ) - }); - } - __i0.prefix_inc(); - } - } - return (*self).clone(); - } -} pub trait CopyOnlyImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn destructor(&self); - fn copy_assign(&self, o: Ptr) -> Ptr; } impl CopyOnlyImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copy_only_copies_1.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn destructor(&self) { - (*copy_only_dtors_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copy_only_copies_1.with(Value::clone).borrow_mut()).prefix_inc(); - return (*self).clone(); - } -} -pub trait CopyOnlyPairImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; - fn destructor(&self); -} -impl CopyOnlyPairImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - ({ CopyOnlyImpl::copy_assign(&field_ptr!((*self), x), field_ptr!(_a0, x)) }); - ({ CopyOnlyImpl::copy_assign(&field_ptr!((*self), y), field_ptr!(_a0, y)) }); - return (*self).clone(); - } - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, y)); - Destructible::destroy(field_ptr!(self, x)); - } } pub trait MovedImpl { fn construct(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); - fn copy_assign(&self, o: Ptr) -> Ptr; - fn move_assign(&self, o: Ptr) -> Ptr; - fn destructor(&self); } impl MovedImpl for Ptr { fn construct(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(-1_i32); - (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - return (*self).clone(); - } - fn move_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(-1_i32); - (*move_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); - return (*self).clone(); - } - fn destructor(&self) { - (*moved_dtors_5.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait MovedPairImpl { - fn move_from(&self, _a0: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; - fn move_assign(&self, _a0: Ptr) -> Ptr; - fn destructor(&self); -} -impl MovedPairImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), x).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MovedImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, x) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - field!((*self), y).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MovedImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, y) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - ({ MovedImpl::copy_assign(&field_ptr!((*self), x), field_ptr!(_a0, x)) }); - ({ MovedImpl::copy_assign(&field_ptr!((*self), y), field_ptr!(_a0, y)) }); - return (*self).clone(); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - ({ MovedImpl::move_assign(&field_ptr!((*self), x), field_ptr!(_a0, x)) }); - ({ MovedImpl::move_assign(&field_ptr!((*self), y), field_ptr!(_a0, y)) }); - return (*self).clone(); - } - fn destructor(&self) { - Destructible::destroy(field_ptr!(self, y)); - Destructible::destroy(field_ptr!(self, x)); - } -} -pub trait OwnerImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl OwnerImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), p) - .write(field!(_a0, p).with_mut(|__v: &mut Option>| __v.take())); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), p).with_mut(|__b0| { - (*__b0) = field!(_a0, p).with_mut(|__v: &mut Option>| __v.take()); - }); - return (*self).clone(); - } -} -pub trait PairImpl { - fn move_from(&self, _a0: Ptr); - fn copy_assign(&self, _a0: Ptr) -> Ptr; - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl PairImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), x).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, x) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - field!((*self), y).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, y) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - ({ TrackedImpl::copy_assign(&field_ptr!((*self), x), field_ptr!(_a0, x)) }); - ({ TrackedImpl::copy_assign(&field_ptr!((*self), y), field_ptr!(_a0, y)) }); - return (*self).clone(); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - ({ TrackedImpl::move_assign(&field_ptr!((*self), x), field_ptr!(_a0, x)) }); - ({ TrackedImpl::move_assign(&field_ptr!((*self), y), field_ptr!(_a0, y)) }); - return (*self).clone(); - } } pub trait TrackedImpl { fn construct_2(&self); fn construct_1(&self, v: i32); - fn copy_from(&self, o: Ptr); - fn move_from(&self, o: Ptr); - fn copy_assign(&self, o: Ptr) -> Ptr; - fn move_assign(&self, o: Ptr) -> Ptr; } impl TrackedImpl for Ptr { fn construct_2(&self) { @@ -1038,22 +1059,6 @@ impl TrackedImpl for Ptr { fn construct_1(&self, mut v: i32) { field!((*self), v).write(v); } - fn copy_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn move_from(&self, o: Ptr) { - field!((*self), v).write(o.with(|__s| __s.v)); - } - fn copy_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - return (*self).clone(); - } - fn move_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write(o.with(|__s| __s.v)); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); diff --git a/tests/unit/out/refcount/tag_vs_identifier_collision.rs b/tests/unit/out/refcount/tag_vs_identifier_collision.rs index 49be6f6017..626a554da7 100644 --- a/tests/unit/out/refcount/tag_vs_identifier_collision.rs +++ b/tests/unit/out/refcount/tag_vs_identifier_collision.rs @@ -10,7 +10,18 @@ pub type widget_enum = u32; 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct widget { #[offset(0)] @@ -18,7 +29,18 @@ pub struct widget { #[offset(4)] pub mode: widget_enum, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct point_struct { #[offset(0)] @@ -26,7 +48,7 @@ pub struct point_struct { #[offset(4)] pub y: i32, } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct point { #[offset(0)] @@ -49,7 +71,7 @@ impl Default for point { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct slot_union { #[offset(0)] @@ -75,20 +97,53 @@ impl Default for slot_union { 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, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Inner { #[offset(0)] pub tag_field: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Outer { #[offset(0)] #[byte_size(4)] pub field: Inner, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Inner_struct { #[offset(0)] diff --git a/tests/unit/out/refcount/template_default_arg.rs b/tests/unit/out/refcount/template_default_arg.rs index 6b720baba4..28573901f9 100644 --- a/tests/unit/out/refcount/template_default_arg.rs +++ b/tests/unit/out/refcount/template_default_arg.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, +)] #[cpp_from(i32, construct_1, value)] #[byte_size(4)] pub struct A { @@ -24,7 +35,9 @@ impl Default for A { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct B { #[offset(0)] @@ -41,7 +54,19 @@ impl Default for B { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct NoDefault { @@ -60,7 +85,19 @@ pub fn scaled_2(mut x: A, mut n: i32) -> i32 { pub fn always_given_3(mut x: NoDefault) -> i32 { return x.v; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct S_NoDefault_ { diff --git a/tests/unit/out/refcount/template_static_member.rs b/tests/unit/out/refcount/template_static_member.rs index 5af9536c09..94e9f890ae 100644 --- a/tests/unit/out/refcount/template_static_member.rs +++ b/tests/unit/out/refcount/template_static_member.rs @@ -9,19 +9,52 @@ use std::rc::{Rc, Weak}; thread_local!( pub static s_0: Value = Rc::new(RefCell::new(55)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Static_int_ {} thread_local!( pub static s_1: Value = Rc::new(RefCell::new(55_i8)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Static_char_ {} thread_local!( pub static s_2: Value = Rc::new(RefCell::new(55_i64)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Static_long_ {} thread_local!( @@ -30,7 +63,18 @@ thread_local!( thread_local!( pub static hi_4: Value = Rc::new(RefCell::new(1)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Range_int_ {} thread_local!( @@ -39,7 +83,18 @@ thread_local!( thread_local!( pub static hi_6: Value = Rc::new(RefCell::new(2_i64)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct Range_long_ {} pub fn main() { diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index 4c828b2701..6313a4469c 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct Inner { @@ -15,7 +25,31 @@ pub struct Inner { #[byte_size(24)] pub values: Vec, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +impl MoveConstructible for Inner { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), values).write(field!(_a0, values).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Inner { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), values).with_mut(|__b0| { + (*__b0) = field!(_a0, values).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, +)] #[byte_size(56)] pub struct Outer { #[offset(0)] @@ -29,6 +63,33 @@ pub struct Outer { #[array_len(8)] pub name: Box<[i8]>, } +impl MoveConstructible for Outer { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), values).write(field!(_a0, values).with_mut(std::mem::take)); + field!((*this), inner).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, inner) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + field!((*this), name).write(Box::new(std::array::from_fn::<_, 8, _>(|__i: usize| { + (*_a0.upgrade().deref()).name[(__i) as usize] + }))); + } +} +impl MoveAssignable for Outer { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), values).with_mut(|__b0| { + (*__b0) = field!(_a0, values).with_mut(std::mem::take); + }); + ({ MoveAssignable::move_assign(&field_ptr!((*this), inner), field_ptr!(_a0, inner)) }); + { + let mut __tmp_0 = { (array_field_ptr!((*this), name)).to_any() }; + __tmp_0.memcpy(&(array_field_ptr!(_a0, name)).to_any(), 8_usize); + (__tmp_0).clone() + }; + return (*this).clone(); + } +} impl Default for Outer { fn default() -> Self { { @@ -126,48 +187,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait InnerImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl InnerImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), values).write(field!(_a0, values).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), values).with_mut(|__b0| { - (*__b0) = field!(_a0, values).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} -pub trait OuterImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl OuterImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), values).write(field!(_a0, values).with_mut(std::mem::take)); - field!((*self), inner).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - InnerImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, inner) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - field!((*self), name).write(Box::new(std::array::from_fn::<_, 8, _>(|__i: usize| { - (*_a0.upgrade().deref()).name[(__i) as usize] - }))); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), values).with_mut(|__b0| { - (*__b0) = field!(_a0, values).with_mut(std::mem::take); - }); - ({ InnerImpl::move_assign(&field_ptr!((*self), inner), field_ptr!(_a0, inner)) }); - { - let mut __tmp_0 = { (array_field_ptr!((*self), name)).to_any() }; - __tmp_0.memcpy(&(array_field_ptr!(_a0, name)).to_any(), 8_usize); - (__tmp_0).clone() - }; - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index 6cbd2d0a77..c669df6d1c 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct Outer { @@ -15,12 +25,37 @@ pub struct Outer { #[byte_size(24)] pub values: Vec, } +impl MoveConstructible for Outer { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), values).write(field!(_a0, values).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Outer { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), values).with_mut(|__b0| { + (*__b0) = field!(_a0, values).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} pub fn make_0() -> Outer { return Outer { values: Vec::from([1, 2, 3, 4]), }; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(Vec , construct, ptr)] #[byte_size(4)] pub struct H { @@ -52,19 +87,4 @@ impl HImpl for Ptr { field!((*self), last).write((index!(values, 3_usize).read())); } } -pub trait OuterImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl OuterImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), values).write(field!(_a0, values).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), values).with_mut(|__b0| { - (*__b0) = field!(_a0, values).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index d0c102171b..ff14405a7b 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct Inner { @@ -15,8 +25,31 @@ pub struct Inner { #[byte_size(24)] pub values: Vec, } +impl MoveConstructible for Inner { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), values).write(field!(_a0, values).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Inner { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), values).with_mut(|__b0| { + (*__b0) = field!(_a0, values).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(48)] pub struct Outer { @@ -27,6 +60,25 @@ pub struct Outer { #[byte_size(24)] pub inner: Inner, } +impl MoveConstructible for Outer { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), values).write(field!(_a0, values).with_mut(std::mem::take)); + field!((*this), inner).write({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(_a0, inner) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + } +} +impl MoveAssignable for Outer { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), values).with_mut(|__b0| { + (*__b0) = field!(_a0, values).with_mut(std::mem::take); + }); + ({ MoveAssignable::move_assign(&field_ptr!((*this), inner), field_ptr!(_a0, inner)) }); + return (*this).clone(); + } +} pub fn make_0() -> Outer { return Outer { values: Vec::from([1, 2, 3]), @@ -58,40 +110,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait InnerImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl InnerImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), values).write(field!(_a0, values).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), values).with_mut(|__b0| { - (*__b0) = field!(_a0, values).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} -pub trait OuterImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl OuterImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), values).write(field!(_a0, values).with_mut(std::mem::take)); - field!((*self), inner).write({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - InnerImpl::move_from(&__v.as_pointer(), { field_ptr!(_a0, inner) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), values).with_mut(|__b0| { - (*__b0) = field!(_a0, values).with_mut(std::mem::take); - }); - ({ InnerImpl::move_assign(&field_ptr!((*self), inner), field_ptr!(_a0, inner)) }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/this.rs b/tests/unit/out/refcount/this.rs index dc4c2bdf58..8d9858b108 100644 --- a/tests/unit/out/refcount/this.rs +++ b/tests/unit/out/refcount/this.rs @@ -6,7 +6,18 @@ 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, CppFrom, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct_1, value)] #[byte_size(16)] pub struct S { @@ -19,7 +30,19 @@ pub struct S { pub fn bump_0(mut p: Ptr) { field!(p, a_).with_mut(|__v| __v.postfix_inc()); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct D { diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index 1c63a2e7a1..4c87ec7f37 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Outer_RunInfo { #[offset(0)] @@ -15,7 +26,17 @@ pub struct Outer_RunInfo { pub num_extra_zero_runs: i32, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct Outer { @@ -23,6 +44,19 @@ pub struct Outer { #[byte_size(24)] pub runs: Vec, } +impl MoveConstructible for Outer { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), runs).write(field!(_a0, runs).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Outer { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), runs).with_mut(|__b0| { + (*__b0) = field!(_a0, runs).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -41,19 +75,4 @@ fn main_0() -> i32 { assert!((o.runs[0_usize].num_extra_zero_runs == 2)); return 0; } -pub trait OuterImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl OuterImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), runs).write(field!(_a0, runs).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), runs).with_mut(|__b0| { - (*__b0) = field!(_a0, runs).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} 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 11cde1b667..3b5fb0661b 100644 --- a/tests/unit/out/refcount/unary_expr_or_type_trait.rs +++ b/tests/unit/out/refcount/unary_expr_or_type_trait.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/unboxed_locals.rs b/tests/unit/out/refcount/unboxed_locals.rs index b9f631eac6..ff2b8f3c91 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -14,7 +14,18 @@ pub fn inc_1(r: Ptr) { __v.prefix_inc(); }); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -54,7 +65,9 @@ pub fn countdown_4(mut n: i32, mut step: i32) -> i32 { pub trait Shape { fn scale(&mut self, factor: i32) -> i32; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(16)] pub struct Square { #[offset(8)] diff --git a/tests/unit/out/refcount/unboxed_records.rs b/tests/unit/out/refcount/unboxed_records.rs index ecca76a643..ddb769339e 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -14,7 +25,7 @@ pub struct Inner { #[offset(4)] pub b: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(48)] pub struct Cookie { #[offset(0)] @@ -46,7 +57,9 @@ impl Default for Cookie { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, +)] #[byte_size(4)] pub struct Counter { #[offset(0)] diff --git a/tests/unit/out/refcount/union_addrof_external.rs b/tests/unit/out/refcount/union_addrof_external.rs index 19af982d55..ca4c741423 100644 --- a/tests/unit/out/refcount/union_addrof_external.rs +++ b/tests/unit/out/refcount/union_addrof_external.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(16)] pub struct record { #[offset(0)] @@ -32,7 +32,7 @@ impl Default for record { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(128)] pub struct anon_0 { #[offset(0)] @@ -55,7 +55,9 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(128)] pub struct Container { #[offset(0)] diff --git a/tests/unit/out/refcount/union_basic.rs b/tests/unit/out/refcount/union_basic.rs index be25047476..f2c09a44d4 100644 --- a/tests/unit/out/refcount/union_basic.rs +++ b/tests/unit/out/refcount/union_basic.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct basic { #[offset(0)] @@ -29,7 +29,7 @@ impl Default for basic { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(1)] pub struct empty { #[offset(0)] @@ -45,7 +45,7 @@ impl Default for empty { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct underscores { #[offset(0)] @@ -123,7 +123,7 @@ fn main_0() -> i32 { assert!(((__ + ___) == 3)); return 0; } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, 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 a9d1479a1e..a6ff07790f 100644 --- a/tests/unit/out/refcount/union_cross_arm_cast.rs +++ b/tests/unit/out/refcount/union_cross_arm_cast.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(16)] pub struct shape_a { #[offset(0)] @@ -26,7 +26,7 @@ impl Default for shape_a { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(28)] pub struct shape_b { #[offset(0)] @@ -55,7 +55,7 @@ impl Default for shape_b { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(64)] pub struct anon_0 { #[offset(0)] @@ -81,7 +81,9 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(68)] pub struct Container { #[offset(0)] diff --git a/tests/unit/out/refcount/union_field_alignment.rs b/tests/unit/out/refcount/union_field_alignment.rs index 57809017f9..e689bccc26 100644 --- a/tests/unit/out/refcount/union_field_alignment.rs +++ b/tests/unit/out/refcount/union_field_alignment.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -29,7 +29,9 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct node { #[offset(0)] diff --git a/tests/unit/out/refcount/union_flex_array_member.rs b/tests/unit/out/refcount/union_flex_array_member.rs index 31db1da220..c7414be3fd 100644 --- a/tests/unit/out/refcount/union_flex_array_member.rs +++ b/tests/unit/out/refcount/union_flex_array_member.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -29,7 +29,9 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(24)] pub struct node { #[offset(0)] diff --git a/tests/unit/out/refcount/union_memset_memcpy.rs b/tests/unit/out/refcount/union_memset_memcpy.rs index 517b8b726f..514f11afab 100644 --- a/tests/unit/out/refcount/union_memset_memcpy.rs +++ b/tests/unit/out/refcount/union_memset_memcpy.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(16)] pub struct shape_a { #[offset(0)] @@ -26,7 +26,7 @@ impl Default for shape_a { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(16)] pub struct shape_b { #[offset(0)] @@ -52,7 +52,7 @@ impl Default for shape_b { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(256)] pub struct anon_0 { #[offset(0)] @@ -78,7 +78,9 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(256)] pub struct Container { #[offset(0)] diff --git a/tests/unit/out/refcount/union_nested.rs b/tests/unit/out/refcount/union_nested.rs index 7ef5b75524..807644bd3f 100644 --- a/tests/unit/out/refcount/union_nested.rs +++ b/tests/unit/out/refcount/union_nested.rs @@ -6,7 +6,7 @@ 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(16)] pub struct record { #[offset(0)] @@ -26,7 +26,7 @@ impl Default for record { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(128)] pub struct anon_0 { #[offset(0)] @@ -49,14 +49,16 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(128)] pub struct inner { #[offset(0)] #[byte_size(128)] pub view: anon_0, } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(128)] pub struct anon_1 { #[offset(0)] @@ -79,7 +81,9 @@ impl Default for anon_1 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(144)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/union_pointer_pun_address.rs b/tests/unit/out/refcount/union_pointer_pun_address.rs index 39eebeea38..b1833bf0fd 100644 --- a/tests/unit/out/refcount/union_pointer_pun_address.rs +++ b/tests/unit/out/refcount/union_pointer_pun_address.rs @@ -6,13 +6,26 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct node_a { #[offset(0)] pub n: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct node_b { #[offset(0)] @@ -34,7 +47,7 @@ fn main_0() -> i32 { assert!(({ (out).to_any() } == { (a.as_pointer()).to_any() })); return 0; } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, 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 c16a0a1c70..8d229bf8d2 100644 --- a/tests/unit/out/refcount/union_pointer_pun_writethrough.rs +++ b/tests/unit/out/refcount/union_pointer_pun_writethrough.rs @@ -18,7 +18,7 @@ fn main_0() -> i32 { assert!(({ ((*x.borrow()) == 42_i64) })); return 0; } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, 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 9a272dd59f..d366f54ebc 100644 --- a/tests/unit/out/refcount/union_struct_dual_use.rs +++ b/tests/unit/out/refcount/union_struct_dual_use.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -17,7 +28,7 @@ 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, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(16)] pub struct anon_1 { #[offset(0)] @@ -40,7 +51,9 @@ impl Default for anon_1 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/union_tagged_many_arms.rs b/tests/unit/out/refcount/union_tagged_many_arms.rs index e6015b90dc..1e70242f07 100644 --- a/tests/unit/out/refcount/union_tagged_many_arms.rs +++ b/tests/unit/out/refcount/union_tagged_many_arms.rs @@ -12,7 +12,7 @@ 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, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -44,7 +44,9 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Slot { #[offset(0)] diff --git a/tests/unit/out/refcount/union_tagged_simple.rs b/tests/unit/out/refcount/union_tagged_simple.rs index 40ff56b6a5..fe497f915f 100644 --- a/tests/unit/out/refcount/union_tagged_simple.rs +++ b/tests/unit/out/refcount/union_tagged_simple.rs @@ -9,7 +9,7 @@ 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, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -32,7 +32,9 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(24)] pub struct Event { #[offset(0)] diff --git a/tests/unit/out/refcount/union_tagged_struct_arms.rs b/tests/unit/out/refcount/union_tagged_struct_arms.rs index db388b5ac6..4003a5d6a0 100644 --- a/tests/unit/out/refcount/union_tagged_struct_arms.rs +++ b/tests/unit/out/refcount/union_tagged_struct_arms.rs @@ -10,7 +10,9 @@ pub type Choice_enum = u32; 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, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(24)] pub struct anon_1 { #[offset(0)] @@ -21,7 +23,18 @@ pub struct anon_1 { #[offset(16)] pub cursor: i64, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(16)] pub struct anon_2 { #[offset(0)] @@ -33,7 +46,18 @@ pub struct anon_2 { #[offset(12)] pub step: u8, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(40)] pub struct anon_3 { #[offset(0)] @@ -47,7 +71,7 @@ pub struct anon_3 { #[offset(32)] pub width: i32, } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(40)] pub struct anon_0 { #[offset(0)] @@ -73,7 +97,9 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(48)] pub struct Branch { #[offset(0)] 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 271b2b7121..93289f2704 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,7 @@ 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, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -39,7 +39,9 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Sink { #[offset(0)] diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index 66fa40e37c..d1763fad44 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -6,14 +6,39 @@ 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, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Default)] #[byte_size(8)] pub struct SafePointer { #[offset(0)] #[byte_size(8)] pub ptr: Option>, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +impl MoveConstructible for SafePointer { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), ptr) + .write(field!(_a0, ptr).with_mut(|__v: &mut Option>| __v.take())); + } +} +impl MoveAssignable for SafePointer { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), ptr).with_mut(|__b0| { + (*__b0) = field!(_a0, ptr).with_mut(|__v: &mut Option>| __v.take()); + }); + return (*this).clone(); + } +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -228,8 +253,6 @@ impl PairImpl for Ptr { } pub trait SafePointerImpl { fn inc(&self); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl SafePointerImpl for Ptr { fn inc(&self) { @@ -240,15 +263,5 @@ impl SafePointerImpl for Ptr { __v.prefix_inc(); }); } - fn move_from(&self, _a0: Ptr) { - field!((*self), ptr) - .write(field!(_a0, ptr).with_mut(|__v: &mut Option>| __v.take())); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), ptr).with_mut(|__b0| { - (*__b0) = field!(_a0, ptr).with_mut(|__v: &mut Option>| __v.take()); - }); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/unique_ptr_const_deref.rs b/tests/unit/out/refcount/unique_ptr_const_deref.rs index 46da6a9e3f..8bd495f361 100644 --- a/tests/unit/out/refcount/unique_ptr_const_deref.rs +++ b/tests/unit/out/refcount/unique_ptr_const_deref.rs @@ -6,13 +6,27 @@ 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, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Default)] #[byte_size(8)] pub struct Holder { #[offset(0)] #[byte_size(8)] pub val: Option>, } +impl MoveConstructible for Holder { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), val) + .write(field!(_a0, val).with_mut(|__v: &mut Option>| __v.take())); + } +} +impl MoveAssignable for Holder { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), val).with_mut(|__b0| { + (*__b0) = field!(_a0, val).with_mut(|__v: &mut Option>| __v.take()); + }); + return (*this).clone(); + } +} pub fn read_val_0(mut h: Ptr) -> i32 { return (h.with(|__s| __s.val.clone()).as_pointer().read()); } @@ -32,20 +46,4 @@ fn main_0() -> i32 { assert!((({ read_val_0((h.as_pointer()),) }) == 42)); return 0; } -pub trait HolderImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl HolderImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), val) - .write(field!(_a0, val).with_mut(|__v: &mut Option>| __v.take())); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), val).with_mut(|__b0| { - (*__b0) = field!(_a0, val).with_mut(|__v: &mut Option>| __v.take()); - }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/unique_ptr_field_reset.rs b/tests/unit/out/refcount/unique_ptr_field_reset.rs index 2ab5be9d04..89efc85aa4 100644 --- a/tests/unit/out/refcount/unique_ptr_field_reset.rs +++ b/tests/unit/out/refcount/unique_ptr_field_reset.rs @@ -6,13 +6,24 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Data { #[offset(0)] pub v: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Default)] #[byte_size(16)] pub struct Holder { #[offset(0)] @@ -21,6 +32,22 @@ pub struct Holder { #[offset(8)] pub n: i32, } +impl MoveConstructible for Holder { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), data) + .write(field!(_a0, data).with_mut(|__v: &mut Option>| __v.take())); + field!((*this), n).write({ (*_a0.upgrade().deref()).n }); + } +} +impl MoveAssignable for Holder { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), data).with_mut(|__b0| { + (*__b0) = field!(_a0, data).with_mut(|__v: &mut Option>| __v.take()); + }); + field!((*this), n).write({ (*_a0.upgrade().deref()).n }); + return (*this).clone(); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -60,8 +87,6 @@ fn main_0() -> i32 { } pub trait HolderImpl { fn set(&self, p: Ptr); - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; } impl HolderImpl for Ptr { fn set(&self, mut p: Ptr) { @@ -70,17 +95,5 @@ impl HolderImpl for Ptr { field_ptr!((*self), data).write(_p.to_owned_opt()) }; } - fn move_from(&self, _a0: Ptr) { - field!((*self), data) - .write(field!(_a0, data).with_mut(|__v: &mut Option>| __v.take())); - field!((*self), n).write({ (*_a0.upgrade().deref()).n }); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), data).with_mut(|__b0| { - (*__b0) = field!(_a0, data).with_mut(|__v: &mut Option>| __v.take()); - }); - field!((*self), n).write({ (*_a0.upgrade().deref()).n }); - return (*self).clone(); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/unique_ptr_nested.rs b/tests/unit/out/refcount/unique_ptr_nested.rs index 821aca80d8..3b92b3c090 100644 --- a/tests/unit/out/refcount/unique_ptr_nested.rs +++ b/tests/unit/out/refcount/unique_ptr_nested.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -14,13 +25,27 @@ pub struct Inner { #[offset(4)] pub y: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Default)] #[byte_size(8)] pub struct Outer { #[offset(0)] #[byte_size(8)] pub inner: Option>, } +impl MoveConstructible for Outer { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), inner) + .write(field!(_a0, inner).with_mut(|__v: &mut Option>| __v.take())); + } +} +impl MoveAssignable for Outer { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), inner).with_mut(|__b0| { + (*__b0) = field!(_a0, inner).with_mut(|__v: &mut Option>| __v.take()); + }); + return (*this).clone(); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -48,20 +73,4 @@ fn main_0() -> i32 { assert!(((sum + (b.as_pointer().read())) == 135)); return 0; } -pub trait OuterImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl OuterImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), inner) - .write(field!(_a0, inner).with_mut(|__v: &mut Option>| __v.take())); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), inner).with_mut(|__b0| { - (*__b0) = field!(_a0, inner).with_mut(|__v: &mut Option>| __v.take()); - }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/unique_ptr_struct.rs b/tests/unit/out/refcount/unique_ptr_struct.rs index 3db805c34e..5a0ddaa844 100644 --- a/tests/unit/out/refcount/unique_ptr_struct.rs +++ b/tests/unit/out/refcount/unique_ptr_struct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/va_arg_mixed_types.rs b/tests/unit/out/refcount/va_arg_mixed_types.rs index 2dd7e4c91d..904f4e39b6 100644 --- a/tests/unit/out/refcount/va_arg_mixed_types.rs +++ b/tests/unit/out/refcount/va_arg_mixed_types.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct pair { #[offset(0)] 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 7d5b5f9630..3a648b500c 100644 --- a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct node { #[offset(0)] diff --git a/tests/unit/out/refcount/va_arg_struct_ctx.rs b/tests/unit/out/refcount/va_arg_struct_ctx.rs index caa0d0e30a..22299d2d3c 100644 --- a/tests/unit/out/refcount/va_arg_struct_ctx.rs +++ b/tests/unit/out/refcount/va_arg_struct_ctx.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct context { #[offset(0)] @@ -23,7 +34,7 @@ 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, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Destructible, Copyable, 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 4e4cb67570..77278d4a99 100644 --- a/tests/unit/out/refcount/va_arg_void_ptr.rs +++ b/tests/unit/out/refcount/va_arg_void_ptr.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(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct registry { #[offset(0)] diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index 30ecce7183..d07dd3fdf2 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -16,8 +16,9 @@ pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { Guard_1Impl::construct(&__v.as_pointer(), { ap.as_pointer() }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - let _dtor_guard = - std::mem::DropGuard::new(guard.clone(), |__p| Destructible::destroy(__p.as_pointer())); + let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| { + Destructible::destroy(&__p.as_pointer()) + }); let mut total: i32 = 0; { let mut i: i32 = 0; @@ -31,7 +32,7 @@ pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { return total; } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructible, Default, + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, )] #[cpp_from(Ptr , construct, mut_ptr)] #[byte_size(16)] @@ -42,6 +43,11 @@ pub struct Guard_1 { #[offset(8)] pub active: bool, } +impl Destructible for Guard_1 { + fn destroy(this: &Ptr) { + if (*this).with(|__s| __s.active) {} + } +} pub fn sum_ptr_2(n: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let n: Value = Rc::new(RefCell::new(n)); @@ -62,7 +68,9 @@ pub fn sum_ptr_2(n: i32, __args: Box<[VaArg]>) -> i32 { }; return total; } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(8)] pub struct Cursor_3 { #[offset(0)] @@ -80,15 +88,11 @@ fn main_0() -> i32 { } pub trait Guard_1Impl { fn construct(&self, val: Ptr>); - fn destructor(&self); } impl Guard_1Impl for Ptr { fn construct(&self, val: Ptr>) { field!((*self), ap).write((val).clone()); field!((*self), active).write(true); } - fn destructor(&self) { - if (*self).with(|__s| __s.active) {} - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 8d9bbcd66e..65d72f38d9 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -14,7 +25,17 @@ pub struct S { } pub fn copy_0(mut copy_vector: Vec) {} #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(48)] pub struct Foo { @@ -25,6 +46,23 @@ pub struct Foo { #[byte_size(24)] pub b: Vec, } +impl MoveConstructible for Foo { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), a).write(field!(_a0, a).with_mut(std::mem::take)); + field!((*this), b).write(field!(_a0, b).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Foo { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), a).with_mut(|__b0| { + (*__b0) = field!(_a0, a).with_mut(std::mem::take); + }); + field!((*this), b).with_mut(|__b0| { + (*__b0) = field!(_a0, b).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} pub fn exchange_1(x: Ptr>, y: Ptr>) { x.swap_with(&(y).clone(), |__v| __v.with_mut(std::mem::take)); } @@ -610,23 +648,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait FooImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl FooImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), a).write(field!(_a0, a).with_mut(std::mem::take)); - field!((*self), b).write(field!(_a0, b).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), a).with_mut(|__b0| { - (*__b0) = field!(_a0, a).with_mut(std::mem::take); - }); - field!((*self), b).with_mut(|__b0| { - (*__b0) = field!(_a0, b).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index 6d3021f986..be0a3c3fb5 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -6,14 +6,38 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Degrees { #[offset(0)] pub value: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + Copyable, + Default, +)] #[cpp_into(i64, to_i64)] #[byte_size(4)] pub struct Reading { diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index f5558d0954..baece71457 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -15,7 +26,17 @@ pub struct Point { pub y: i32, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(48)] pub struct Holder { @@ -26,6 +47,23 @@ pub struct Holder { #[byte_size(24)] pub points: Vec, } +impl MoveConstructible for Holder { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), values).write(field!(_a0, values).with_mut(std::mem::take)); + field!((*this), points).write(field!(_a0, points).with_mut(std::mem::take)); + } +} +impl MoveAssignable for Holder { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), values).with_mut(|__b0| { + (*__b0) = field!(_a0, values).with_mut(std::mem::take); + }); + field!((*this), points).with_mut(|__b0| { + (*__b0) = field!(_a0, points).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} pub fn push_and_index_0(v: Ptr>) -> i32 { { let __a1 = 42; @@ -133,25 +171,6 @@ fn main_0() -> i32 { assert!(({ (*a.borrow())[1_usize] } == 10)); return 0; } -pub trait HolderImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl HolderImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), values).write(field!(_a0, values).with_mut(std::mem::take)); - field!((*self), points).write(field!(_a0, points).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), values).with_mut(|__b0| { - (*__b0) = field!(_a0, values).with_mut(std::mem::take); - }); - field!((*self), points).with_mut(|__b0| { - (*__b0) = field!(_a0, points).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub trait PointImpl { fn sum(&self) -> i32; } diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index baa5b6e9c0..95579428e4 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -6,10 +6,32 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct TestAllocator_int_ {} -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(1)] pub struct TestAllocator_double_ {} pub fn copy_0(mut copy_vector: Vec) {} diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 704036d77a..b7588b2501 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -8,7 +8,17 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn unused_param_0(mut x: i32) {} #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + CopyConstructible, + CopyAssignable, + Swappable, + Default, )] #[byte_size(24)] pub struct NonTrivial { @@ -16,6 +26,19 @@ pub struct NonTrivial { #[byte_size(24)] pub data: Vec, } +impl MoveConstructible for NonTrivial { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), data).write(field!(_a0, data).with_mut(std::mem::take)); + } +} +impl MoveAssignable for NonTrivial { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), data).with_mut(|__b0| { + (*__b0) = field!(_a0, data).with_mut(std::mem::take); + }); + return (*this).clone(); + } +} pub fn unused_ref_param_1(x: Ptr) {} pub fn unused_ptr_param_2(mut p: Ptr) {} thread_local!( @@ -25,19 +48,44 @@ pub fn bump_and_return_4() -> i32 { (*side_effect_counter_3.with(Value::clone).borrow_mut()).prefix_inc(); return side_effect_counter_3.with(|rc| *rc.borrow()); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Default, +)] #[byte_size(4)] pub struct Holder { #[offset(0)] pub field: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Default)] #[byte_size(8)] pub struct NonCopyable { #[offset(0)] #[byte_size(8)] pub value: Option>, } +impl MoveConstructible for NonCopyable { + fn move_constructor(this: &Ptr, _a0: Ptr) { + field!((*this), value) + .write(field!(_a0, value).with_mut(|__v: &mut Option>| __v.take())); + } +} +impl MoveAssignable for NonCopyable { + fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + field!((*this), value).with_mut(|__b0| { + (*__b0) = field!(_a0, value).with_mut(|__v: &mut Option>| __v.take()); + }); + return (*this).clone(); + } +} pub fn unused_noncopyable_param_5(x: Ptr) {} pub fn main() { __cpp2rust_init_globals(); @@ -97,37 +145,6 @@ fn main_0() -> i32 { assert!((({ (*g.borrow()).value.clone() }.as_pointer().read()) == 9)); return 0; } -pub trait NonCopyableImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl NonCopyableImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), value) - .write(field!(_a0, value).with_mut(|__v: &mut Option>| __v.take())); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), value).with_mut(|__b0| { - (*__b0) = field!(_a0, value).with_mut(|__v: &mut Option>| __v.take()); - }); - return (*self).clone(); - } -} -pub trait NonTrivialImpl { - fn move_from(&self, _a0: Ptr); - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl NonTrivialImpl for Ptr { - fn move_from(&self, _a0: Ptr) { - field!((*self), data).write(field!(_a0, data).with_mut(std::mem::take)); - } - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), data).with_mut(|__b0| { - (*__b0) = field!(_a0, data).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() { let _ = side_effect_counter_3.with(|_| ()); } diff --git a/tests/unit/out/unsafe/05_new.rs b/tests/unit/out/unsafe/05_new.rs index 6319da620d..e184846aad 100644 --- a/tests/unit/out/unsafe/05_new.rs +++ b/tests/unit/out/unsafe/05_new.rs @@ -7,10 +7,28 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct A {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct D {} impl D { pub unsafe fn operator_call(&self, mut ptr: *const A) { diff --git a/tests/unit/out/unsafe/10_struct.rs b/tests/unit/out/unsafe/10_struct.rs index 75a307ae5b..d0671ada1d 100644 --- a/tests/unit/out/unsafe/10_struct.rs +++ b/tests/unit/out/unsafe/10_struct.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct GraphNode { pub dst: u32, pub next: *mut GraphNode, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Graph { pub V: u32, pub adj: *mut *mut GraphNode, @@ -31,7 +49,9 @@ impl Graph { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Partial { pub p: *mut i32, } @@ -50,11 +70,29 @@ impl Default for Partial { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Declared {} impl Declared {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub i: i32, pub d: *mut Declared, diff --git a/tests/unit/out/unsafe/addr_of_global.rs b/tests/unit/out/unsafe/addr_of_global.rs index d8ffb6c456..6bf331e8f7 100644 --- a/tests/unit/out/unsafe/addr_of_global.rs +++ b/tests/unit/out/unsafe/addr_of_global.rs @@ -7,12 +7,30 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub value: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 a2cfc9f725..fce183f9a2 100644 --- a/tests/unit/out/unsafe/anonymous-struct.rs +++ b/tests/unit/out/unsafe/anonymous-struct.rs @@ -7,48 +7,120 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer_Named { pub a: i32, pub b: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_0 { pub c: i32, pub d: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_1 { pub g: i32, pub h: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_2 { pub e: i32, pub f: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_4 { pub j: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_5 { pub k: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_3 { pub i: i32, pub inner_named: anon_4, pub anon_5: anon_5, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer { pub named: Outer_Named, pub anonymous_named_0: anon_0, @@ -104,7 +176,16 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_6 { pub x: i32, pub z: i32, diff --git a/tests/unit/out/unsafe/anonymous-struct_c.rs b/tests/unit/out/unsafe/anonymous-struct_c.rs index 4bb61b622d..509da3b233 100644 --- a/tests/unit/out/unsafe/anonymous-struct_c.rs +++ b/tests/unit/out/unsafe/anonymous-struct_c.rs @@ -7,48 +7,120 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Named { pub a: i32, pub b: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_0 { pub c: i32, pub d: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_1 { pub g: i32, pub h: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_2 { pub e: i32, pub f: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_4 { pub j: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_5 { pub k: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_3 { pub i: i32, pub inner_named: anon_4, pub anon_5: anon_5, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer { pub named: Named, pub anon0: anon_0, @@ -110,7 +182,16 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_6 { pub x: i32, pub z: i32, diff --git a/tests/unit/out/unsafe/anonymous_enum.rs b/tests/unit/out/unsafe/anonymous_enum.rs index 94d75a3a98..066af2d3ed 100644 --- a/tests/unit/out/unsafe/anonymous_enum.rs +++ b/tests/unit/out/unsafe/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; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub a: i32, } @@ -24,7 +33,16 @@ pub type anon_2 = u32; 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct WithAnonField { pub a: i32, pub field: anon_2, diff --git a/tests/unit/out/unsafe/anonymous_enum_c.rs b/tests/unit/out/unsafe/anonymous_enum_c.rs index f34263d901..f8ddc173e8 100644 --- a/tests/unit/out/unsafe/anonymous_enum_c.rs +++ b/tests/unit/out/unsafe/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; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub a: i32, } @@ -24,7 +33,16 @@ pub type anon_2 = u32; 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct WithAnonField { pub a: i32, pub field: anon_2, diff --git a/tests/unit/out/unsafe/any.rs b/tests/unit/out/unsafe/any.rs index 4426625329..48c87082b1 100644 --- a/tests/unit/out/unsafe/any.rs +++ b/tests/unit/out/unsafe/any.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Point { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/array_const_init.rs b/tests/unit/out/unsafe/array_const_init.rs index dd3390eaf6..fc0bfe4233 100644 --- a/tests/unit/out/unsafe/array_const_init.rs +++ b/tests/unit/out/unsafe/array_const_init.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub head: i32, pub tail: [i32; 3], @@ -21,7 +30,16 @@ pub static mut s_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct P { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/array_field_addr.rs b/tests/unit/out/unsafe/array_field_addr.rs index 319a264a92..ab89391816 100644 --- a/tests/unit/out/unsafe/array_field_addr.rs +++ b/tests/unit/out/unsafe/array_field_addr.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub before: i32, pub mask: [u8; 4], diff --git a/tests/unit/out/unsafe/array_of_noncopy_struct.rs b/tests/unit/out/unsafe/array_of_noncopy_struct.rs index cf44260f8f..bf01f02a4a 100644 --- a/tests/unit/out/unsafe/array_of_noncopy_struct.rs +++ b/tests/unit/out/unsafe/array_of_noncopy_struct.rs @@ -7,17 +7,28 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, +)] pub struct NonCopy { pub data: Vec, pub tag: i32, } -impl NonCopy { - pub unsafe fn move_from(&mut self, _a0: *mut NonCopy) { +impl MoveConstructibleUnsafe for NonCopy { + unsafe fn move_constructor(&mut self, _a0: *mut NonCopy) { (&raw mut self.data).write(std::mem::take(&mut (*_a0).data)); (&raw mut self.tag).write((*_a0).tag); } - pub unsafe fn move_assign(&mut self, _a0: *mut NonCopy) -> *mut NonCopy { +} +impl MoveAssignableUnsafe for NonCopy { + unsafe fn move_assign(&mut self, _a0: *mut NonCopy) -> *mut NonCopy { { self.data = std::mem::take(&mut (*_a0).data); }; diff --git a/tests/unit/out/unsafe/array_reference.rs b/tests/unit/out/unsafe/array_reference.rs index 0bda2bcfe1..c0873c5a6e 100644 --- a/tests/unit/out/unsafe/array_reference.rs +++ b/tests/unit/out/unsafe/array_reference.rs @@ -57,7 +57,16 @@ pub unsafe fn pick_10(s: *const [libc::c_char; 5]) -> *const [libc::c_char; 5] { return s; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Point { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/as_const.rs b/tests/unit/out/unsafe/as_const.rs index a5695608b5..33d7afa5ea 100644 --- a/tests/unit/out/unsafe/as_const.rs +++ b/tests/unit/out/unsafe/as_const.rs @@ -10,7 +10,16 @@ pub type Overload = u32; pub const Overload_kMutableOverload: Overload = 1; pub const Overload_kConstOverload: Overload = 2; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 94d9dc5f88..44907d339d 100644 --- a/tests/unit/out/unsafe/assign_rhs_first.rs +++ b/tests/unit/out/unsafe/assign_rhs_first.rs @@ -13,7 +13,16 @@ pub unsafe fn advance_1() -> i32 { return 10; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 95a55113e5..a8c7275f99 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -836,17 +836,44 @@ pub unsafe fn test_reference_members_9() { }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Slot_6 { pub value: *mut u32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Slot_8 { pub value: *mut i16, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Slot_10 { pub value: *mut i32, } @@ -895,7 +922,16 @@ pub unsafe fn test_pointer_elements_11() { }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Holder_12 { pub p: *mut i32, } @@ -921,7 +957,16 @@ pub unsafe fn test_reference_pointer_13() { }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Node_14 { pub link: *mut *mut Node_14, } @@ -994,22 +1039,58 @@ pub unsafe fn test_reference_subfields_18() { }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Index_16 { pub value: u32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Slot_17 { pub ref_: *mut Index_16, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Index_19 { pub value: i16, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Slot_20 { pub ref_: *mut Index_19, } @@ -1049,12 +1130,30 @@ pub unsafe fn observe_24(mut assigned: i32, mut stored: *const i32) -> i32 { return ((assigned) + (*stored)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct GlobalRecord_Inner { pub value: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct GlobalRecord { pub inner: GlobalRecord_Inner, } @@ -1320,19 +1419,46 @@ pub unsafe fn test_borrows_29() { static mut promoted_30: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10_i16 }); static mut flag_31: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { false }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Record_32 { pub value: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Link_33 { pub next: *mut Link_33, } 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct IndexedBinding {} impl IndexedBinding { pub unsafe fn get_1_0(&mut self) -> *mut u32 { @@ -1551,7 +1677,16 @@ pub static mut global_array_45: std::cell::LazyCell<[u32; 3]> = 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct IndexedMember { pub key: i32, pub value: u32, @@ -1810,7 +1945,16 @@ pub static mut scoped_pointers_53: std::cell::LazyCell<[*mut u32; 1]> = [(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_values_52)).as_mut_ptr()] }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct PointerSelector { pub ptr: *mut u32, } @@ -1967,16 +2111,26 @@ pub unsafe fn test_stable_containers_58() { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Counts_59 { pub counts: Vec, } -impl Counts_59 { - pub unsafe fn move_from(&mut self, _a0: *mut Counts_59) { +impl MoveConstructibleUnsafe for Counts_59 { + unsafe fn move_constructor(&mut self, _a0: *mut Counts_59) { (&raw mut self.counts).write(std::mem::take(&mut (*_a0).counts)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Counts_59) -> *mut Counts_59 { +} +impl MoveAssignableUnsafe for Counts_59 { + unsafe fn move_assign(&mut self, _a0: *mut Counts_59) -> *mut Counts_59 { { self.counts = std::mem::take(&mut (*_a0).counts); }; @@ -1984,7 +2138,16 @@ impl Counts_59 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair_60 { pub u: u32, pub f: i32, @@ -2286,12 +2449,30 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Index_62 { pub value: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Owner_63 { pub values: [i32; 2], pub index: i32, diff --git a/tests/unit/out/unsafe/bounded_struct_ptr.rs b/tests/unit/out/unsafe/bounded_struct_ptr.rs index 19fdff786f..a56c5e762a 100644 --- a/tests/unit/out/unsafe/bounded_struct_ptr.rs +++ b/tests/unit/out/unsafe/bounded_struct_ptr.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Foo { pub x1: i32, pub x2: i32, diff --git a/tests/unit/out/unsafe/bst.rs b/tests/unit/out/unsafe/bst.rs index 46e5deefc6..dd9688cb32 100644 --- a/tests/unit/out/unsafe/bst.rs +++ b/tests/unit/out/unsafe/bst.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct node_t { pub left: *mut node_t, pub right: *mut node_t, diff --git a/tests/unit/out/unsafe/c_struct.rs b/tests/unit/out/unsafe/c_struct.rs index 37e28c701b..3e10ddfb2d 100644 --- a/tests/unit/out/unsafe/c_struct.rs +++ b/tests/unit/out/unsafe/c_struct.rs @@ -7,19 +7,46 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Point { pub x: i32, pub y: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Line { pub start: Point, pub end: Point, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Node { pub value: i32, pub next: *mut Node, @@ -29,13 +56,31 @@ pub const Color_RED: Color = 0; pub const Color_GREEN: Color = 1; pub const Color_BLUE: Color = 2; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub a: i32, pub b: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Container { pub inner: Inner, pub color: Color, diff --git a/tests/unit/out/unsafe/cast.rs b/tests/unit/out/unsafe/cast.rs index 0a9e9516bd..101f126452 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -11,18 +11,45 @@ pub const E_A: E = 0; pub const E_B: E = 1; pub const E_C: E = 2; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub x: i32, pub y: i32, } #[repr(C, align(64))] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Wide { pub c: libc::c_char, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Grid { pub h: i32, pub row: [i32; 3], @@ -30,18 +57,28 @@ pub struct Grid { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Bag { pub n: i32, pub items: Vec, } -impl Bag { - pub unsafe fn move_from(&mut self, _a0: *mut Bag) { +impl MoveConstructibleUnsafe for Bag { + unsafe fn move_constructor(&mut self, _a0: *mut Bag) { (&raw mut self.n).write((*_a0).n); (&raw mut self.items).write(std::mem::take(&mut (*_a0).items)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Bag) -> *mut Bag { +} +impl MoveAssignableUnsafe for Bag { + unsafe fn move_assign(&mut self, _a0: *mut Bag) -> *mut Bag { self.n = (*_a0).n; { self.items = std::mem::take(&mut (*_a0).items); 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 b7b8fcacd7..d8caf25784 100644 --- a/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs +++ b/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs @@ -17,7 +17,16 @@ pub unsafe fn strlen_1(mut s: *mut libc::c_char) -> i32 { return c; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 9a9fa256b4..95d24f2b3d 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub first: i32, pub second: i32, @@ -42,7 +51,16 @@ impl Pair { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Route { pub path: Pair, pub cost: f64, @@ -55,7 +73,16 @@ impl Route { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Counter { pub v: i32, pub calls: i32, @@ -77,7 +104,16 @@ impl std::cmp::PartialEq for Counter { } impl std::cmp::Eq for Counter {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 c0fbe7957c..66317dfa2f 100644 --- a/tests/unit/out/unsafe/class_template_lazy_member.rs +++ b/tests/unit/out/unsafe/class_template_lazy_member.rs @@ -7,12 +7,30 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Point { pub x: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Box_int_ { pub val: i32, } @@ -22,7 +40,16 @@ impl Box_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Box_Point_ { pub val: Point, } @@ -32,7 +59,16 @@ impl Box_Point_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Deduced_int_ { pub val: i32, } @@ -42,7 +78,16 @@ impl Deduced_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 4876139df6..7e0ca915b3 100644 --- a/tests/unit/out/unsafe/class_templates.rs +++ b/tests/unit/out/unsafe/class_templates.rs @@ -8,7 +8,15 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct MyContainer_int_ { vec_: Vec, @@ -36,10 +44,14 @@ impl MyContainer_int_ { self.vec_.push(a0_clone) }; } - pub unsafe fn move_from(&mut self, _a0: *mut MyContainer_int_) { +} +impl MoveConstructibleUnsafe for MyContainer_int_ { + unsafe fn move_constructor(&mut self, _a0: *mut MyContainer_int_) { (&raw mut self.vec_).write(std::mem::take(&mut (*_a0).vec_)); } - pub unsafe fn move_assign(&mut self, _a0: *mut MyContainer_int_) -> *mut MyContainer_int_ { +} +impl MoveAssignableUnsafe for MyContainer_int_ { + unsafe fn move_assign(&mut self, _a0: *mut MyContainer_int_) -> *mut MyContainer_int_ { { self.vec_ = std::mem::take(&mut (*_a0).vec_); }; @@ -48,7 +60,15 @@ impl MyContainer_int_ { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct MyContainer_char_ { vec_: Vec, @@ -76,10 +96,14 @@ impl MyContainer_char_ { self.vec_.push(a0_clone) }; } - pub unsafe fn move_from(&mut self, _a0: *mut MyContainer_char_) { +} +impl MoveConstructibleUnsafe for MyContainer_char_ { + unsafe fn move_constructor(&mut self, _a0: *mut MyContainer_char_) { (&raw mut self.vec_).write(std::mem::take(&mut (*_a0).vec_)); } - pub unsafe fn move_assign(&mut self, _a0: *mut MyContainer_char_) -> *mut MyContainer_char_ { +} +impl MoveAssignableUnsafe for MyContainer_char_ { + unsafe fn move_assign(&mut self, _a0: *mut MyContainer_char_) -> *mut MyContainer_char_ { { self.vec_ = std::mem::take(&mut (*_a0).vec_); }; @@ -88,7 +112,15 @@ impl MyContainer_char_ { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct MyContainer_float_ { vec_: Vec, @@ -116,10 +148,14 @@ impl MyContainer_float_ { self.vec_.push(a0_clone) }; } - pub unsafe fn move_from(&mut self, _a0: *mut MyContainer_float_) { +} +impl MoveConstructibleUnsafe for MyContainer_float_ { + unsafe fn move_constructor(&mut self, _a0: *mut MyContainer_float_) { (&raw mut self.vec_).write(std::mem::take(&mut (*_a0).vec_)); } - pub unsafe fn move_assign(&mut self, _a0: *mut MyContainer_float_) -> *mut MyContainer_float_ { +} +impl MoveAssignableUnsafe for MyContainer_float_ { + unsafe fn move_assign(&mut self, _a0: *mut MyContainer_float_) -> *mut MyContainer_float_ { { self.vec_ = std::mem::take(&mut (*_a0).vec_); }; @@ -127,7 +163,16 @@ impl MyContainer_float_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Boxed_short_ { pub value: i16, } @@ -140,7 +185,16 @@ impl Boxed_short_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Boxed_int_ { pub value: i32, } @@ -153,7 +207,16 @@ impl Boxed_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Boxed_long_ { pub value: i64, } @@ -166,7 +229,16 @@ impl Boxed_long_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer_int__Inner_int_ { pub t: i32, pub u: i32, @@ -177,7 +249,16 @@ impl Outer_int__Inner_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer_int_ { pub v: i32, } @@ -187,7 +268,16 @@ impl Outer_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer_long__Inner_int_ { pub t: i64, pub u: i32, @@ -198,7 +288,16 @@ impl Outer_long__Inner_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer_long__Inner_char_ { pub t: i64, pub u: libc::c_char, @@ -209,7 +308,16 @@ impl Outer_long__Inner_char_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer_long_ { pub v: i64, } @@ -219,7 +327,16 @@ impl Outer_long_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Elem { pub i: i32, } diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index c73dc0b25b..ed780956b4 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -7,12 +7,30 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Bar { pub w: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Foo { pub x: i32, pub y: *mut i32, @@ -21,7 +39,16 @@ pub struct Foo { pub bar: Bar, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Refs { pub a: *mut i32, pub b: *mut i32, diff --git a/tests/unit/out/unsafe/comma_operator.rs b/tests/unit/out/unsafe/comma_operator.rs index 6e4e24a5dd..b13c468668 100644 --- a/tests/unit/out/unsafe/comma_operator.rs +++ b/tests/unit/out/unsafe/comma_operator.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub first: i32, pub second: i32, diff --git a/tests/unit/out/unsafe/complex_function.rs b/tests/unit/out/unsafe/complex_function.rs index e470507a2f..affaad74ec 100644 --- a/tests/unit/out/unsafe/complex_function.rs +++ b/tests/unit/out/unsafe/complex_function.rs @@ -16,12 +16,30 @@ pub unsafe fn bar_2(x: *mut i32) -> *mut i32 { return x; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct X1 { pub v: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct X2 { pub v: *mut X1, } @@ -31,7 +49,16 @@ impl X2 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct X3 { pub v: *mut X2, } @@ -41,7 +68,16 @@ impl X3 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 e35bbb0148..be193150cb 100644 --- a/tests/unit/out/unsafe/compound_assign_paren.rs +++ b/tests/unit/out/unsafe/compound_assign_paren.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Item { pub flags: u8, } diff --git a/tests/unit/out/unsafe/concepts.rs b/tests/unit/out/unsafe/concepts.rs index 3e71e246ce..c8a2276495 100644 --- a/tests/unit/out/unsafe/concepts.rs +++ b/tests/unit/out/unsafe/concepts.rs @@ -12,7 +12,16 @@ const _: () = assert!( "sizeof(int) == 4" ); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Sized {} impl Sized { pub unsafe fn size(&mut self) -> i32 { diff --git a/tests/unit/out/unsafe/constexpr_function.rs b/tests/unit/out/unsafe/constexpr_function.rs index 3848b7afbb..af01c711a5 100644 --- a/tests/unit/out/unsafe/constexpr_function.rs +++ b/tests/unit/out/unsafe/constexpr_function.rs @@ -22,7 +22,16 @@ pub unsafe fn half_3(mut x: f64) -> f64 { return ((x) / (2_f64)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Flag { pub v: i32, } @@ -48,7 +57,16 @@ pub unsafe fn imm_7(mut b: bool) -> bool { return b; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct P { pub v: i32, } diff --git a/tests/unit/out/unsafe/constructor.rs b/tests/unit/out/unsafe/constructor.rs index 666fd35c87..30366ce9d6 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -9,7 +9,7 @@ use std::rc::Rc; pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default, + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, )] #[cpp_from(i32, construct, value)] pub struct S { @@ -28,14 +28,25 @@ impl S { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += (unsafe { S::const_method(self) }); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for S { + unsafe fn destroy(&mut self) { (unsafe { S::mut_method(self) }); (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += (unsafe { S::const_method(self) }); } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, +)] #[cpp_from(i32, construct_1, value)] pub struct Point { pub x: i32, @@ -88,7 +99,7 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!(((s.v) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (8))); diff --git a/tests/unit/out/unsafe/container_element_receiver.rs b/tests/unit/out/unsafe/container_element_receiver.rs index c6755e8cdb..c0c76f6f33 100644 --- a/tests/unit/out/unsafe/container_element_receiver.rs +++ b/tests/unit/out/unsafe/container_element_receiver.rs @@ -7,13 +7,24 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] pub struct Holder { pub ref_: *mut Vec, pub vec_: Vec, } -impl Holder { - pub unsafe fn move_from(&mut self, _a0: *mut Holder) { +impl MoveConstructibleUnsafe for Holder { + unsafe fn move_constructor(&mut self, _a0: *mut Holder) { (&raw mut self.ref_).write((*_a0).ref_); (&raw mut self.vec_).write(std::mem::take(&mut (*_a0).vec_)); } diff --git a/tests/unit/out/unsafe/container_field_addr.rs b/tests/unit/out/unsafe/container_field_addr.rs index 9886cba782..db9675e061 100644 --- a/tests/unit/out/unsafe/container_field_addr.rs +++ b/tests/unit/out/unsafe/container_field_addr.rs @@ -8,18 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct S { pub tag: i32, pub v: Vec, } -impl S { - pub unsafe fn move_from(&mut self, _a0: *mut S) { +impl MoveConstructibleUnsafe for S { + unsafe fn move_constructor(&mut self, _a0: *mut S) { (&raw mut self.tag).write((*_a0).tag); (&raw mut self.v).write(std::mem::take(&mut (*_a0).v)); } - pub unsafe fn move_assign(&mut self, _a0: *mut S) -> *mut S { +} +impl MoveAssignableUnsafe for S { + unsafe fn move_assign(&mut self, _a0: *mut S) -> *mut S { self.tag = (*_a0).tag; { self.v = std::mem::take(&mut (*_a0).v); diff --git a/tests/unit/out/unsafe/conversion_operator_same_translation.rs b/tests/unit/out/unsafe/conversion_operator_same_translation.rs index b03dc334a3..69fdad1457 100644 --- a/tests/unit/out/unsafe/conversion_operator_same_translation.rs +++ b/tests/unit/out/unsafe/conversion_operator_same_translation.rs @@ -7,7 +7,17 @@ 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, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_into(libc::c_char, to_libcc_char)] #[cpp_into(u8, to_u8)] pub struct S { @@ -22,7 +32,17 @@ impl S { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_into(i64, to_i64_1)] pub struct T { pub v: i32, diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 2eebab6f65..9eed7b4959 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -8,7 +8,7 @@ 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, CopyAssignUnsafe, Default)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MovableUnsafe, Default)] pub struct Partial { pub v: i32, pub keep: i32, @@ -18,11 +18,15 @@ impl Partial { (&raw mut self.v).write(v); (&raw mut self.keep).write(keep); } - pub unsafe fn copy_from(&mut self, o: *const Partial) { +} +impl CopyConstructibleUnsafe for Partial { + unsafe fn copy_constructor(&mut self, o: *const Partial) { (&raw mut self.v).write((*o).v); (&raw mut self.keep).write((*o).keep); } - pub unsafe fn copy_assign(&mut self, o: *const Partial) -> *mut Partial { +} +impl CopyAssignableUnsafe for Partial { + unsafe fn copy_assign(&mut self, o: *const Partial) -> *mut Partial { if (((self as *mut Partial).cast_const()) == (o)) { return &mut (*(self as *mut Partial)); } @@ -35,13 +39,15 @@ impl Clone for Partial { fn clone(&self) -> Self { unsafe { let mut __v: Partial = ::zero_init(); - Partial::copy_from(&mut __v, self as *const Partial); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Partial); __v } } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct NonConstAssign { pub mark: i32, } @@ -70,7 +76,16 @@ impl Default for NonConstAssign { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, +)] pub struct RefQualified { pub mark: i32, } @@ -78,7 +93,9 @@ impl RefQualified { pub unsafe fn construct(&mut self) { (&raw mut self.mark).write(0); } - pub unsafe fn copy_assign(&mut self, o: *const RefQualified) -> *mut RefQualified { +} +impl CopyAssignableUnsafe for RefQualified { + unsafe fn copy_assign(&mut self, o: *const RefQualified) -> *mut RefQualified { self.mark = (((*o).mark) + (1)); return &mut (*(self as *mut RefQualified)); } @@ -95,16 +112,25 @@ impl Default for RefQualified { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] pub struct Holder { pub p: Partial, pub arr: [Partial; 2], } -impl Holder { - pub unsafe fn copy_assign(&mut self, _a0: *const Holder) -> *mut Holder { +impl CopyAssignableUnsafe for Holder { + unsafe fn copy_assign(&mut self, _a0: *const Holder) -> *mut Holder { (unsafe { let _o: *const Partial = &(*_a0).p; - Partial::copy_assign(&mut self.p, _o) + CopyAssignableUnsafe::copy_assign(&mut self.p, _o) }); { let mut __i0: usize = 0_usize; @@ -112,7 +138,7 @@ impl Holder { 'for_body: { (unsafe { let _o: *const Partial = &(*_a0).arr[(__i0)]; - Partial::copy_assign(&mut self.arr[(__i0)], _o) + CopyAssignableUnsafe::copy_assign(&mut self.arr[(__i0)], _o) }); } __i0.prefix_inc(); @@ -123,7 +149,15 @@ impl Holder { } pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + MovableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct CopyCounted { pub v: i32, @@ -132,11 +166,15 @@ impl CopyCounted { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, o: *const CopyCounted) { +} +impl CopyConstructibleUnsafe for CopyCounted { + unsafe fn copy_constructor(&mut self, o: *const CopyCounted) { (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, _a0: *const CopyCounted) -> *mut CopyCounted { +} +impl CopyAssignableUnsafe for CopyCounted { + unsafe fn copy_assign(&mut self, _a0: *const CopyCounted) -> *mut CopyCounted { self.v = (*_a0).v; return &mut (*(self as *mut CopyCounted)); } @@ -145,22 +183,31 @@ impl Clone for CopyCounted { fn clone(&self) -> Self { unsafe { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::copy_from(&mut __v, self as *const CopyCounted); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const CopyCounted); __v } } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] pub struct HasCopyCounted { pub c: CopyCounted, pub arr: [CopyCounted; 2], } -impl HasCopyCounted { - pub unsafe fn copy_assign(&mut self, _a0: *const HasCopyCounted) -> *mut HasCopyCounted { +impl CopyAssignableUnsafe for HasCopyCounted { + unsafe fn copy_assign(&mut self, _a0: *const HasCopyCounted) -> *mut HasCopyCounted { (unsafe { let _arg0: *const CopyCounted = &(*_a0).c; - CopyCounted::copy_assign(&mut self.c, _arg0) + CopyAssignableUnsafe::copy_assign(&mut self.c, _arg0) }); { let mut __tmp_0 = { ((&mut self.arr as *mut [CopyCounted; 2]) as *mut ::libc::c_void) }; @@ -196,15 +243,20 @@ unsafe fn main_0() -> i32 { Partial::construct(&mut __v, { 3 }, { 300 }); __v }; - (unsafe { Partial::copy_assign(&mut a, &b) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut a, &b) }); assert!(((a.v) == (2)) && ((a.keep) == (100))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (1))); - (unsafe { Partial::copy_assign(&mut c, &(*(unsafe { Partial::copy_assign(&mut a, &b) }))) }); + (unsafe { + CopyAssignableUnsafe::copy_assign( + &mut c, + &(*(unsafe { CopyAssignableUnsafe::copy_assign(&mut a, &b) })), + ) + }); assert!(((c.v) == (2)) && ((c.keep) == (300))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3))); (unsafe { let _o: *const Partial = &a; - Partial::copy_assign(&mut a, _o) + CopyAssignableUnsafe::copy_assign(&mut a, _o) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3))); (unsafe { @@ -213,15 +265,15 @@ unsafe fn main_0() -> i32 { Partial::construct(&mut __v, { 9 }, { 900 }); __v }; - Partial::copy_assign(&mut a, &mut _o) + CopyAssignableUnsafe::copy_assign(&mut a, &mut _o) }); assert!(((a.v) == (9)) && ((a.keep) == (100))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (4))); let ra: *mut Partial = &mut a; - (unsafe { Partial::copy_assign(&mut (*ra), &c) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut (*ra), &c) }); assert!(((a.v) == (2))); let mut pa: *mut Partial = (&mut a as *mut Partial); - (unsafe { Partial::copy_assign(&mut (*pa), &b) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut (*pa), &b) }); assert!(((a.v) == (2))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (6))); let mut h: Holder = Holder { @@ -243,8 +295,8 @@ unsafe fn main_0() -> i32 { }, ], }; - (unsafe { Partial::copy_assign(&mut h.p, &b) }); - (unsafe { Partial::copy_assign(&mut h.arr[(1) as usize], &c) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut h.p, &b) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut h.arr[(1) as usize], &c) }); assert!(((h.p.v) == (2)) && ((h.p.keep) == (40))); assert!(((h.arr[(1) as usize].v) == (2)) && ((h.arr[(1) as usize].keep) == (60))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (8))); @@ -282,7 +334,7 @@ unsafe fn main_0() -> i32 { RefQualified::construct(&mut __v); __v }; - (unsafe { RefQualified::copy_assign(&mut r1, &r) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut r1, &r) }); assert!(((r1.mark) == (1))); let mut h2: Holder = Holder { p: { @@ -303,7 +355,7 @@ unsafe fn main_0() -> i32 { }, ], }; - (unsafe { Holder::copy_assign(&mut h2, &h) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut h2, &h) }); assert!(((h2.p.v) == (2)) && ((h2.p.keep) == (70))); assert!(((h2.arr[(1) as usize].v) == (2)) && ((h2.arr[(1) as usize].keep) == (90))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (11))); @@ -317,7 +369,7 @@ unsafe fn main_0() -> i32 { CopyCounted::construct(&mut __v, { 2 }); __v }; - (unsafe { CopyCounted::copy_assign(&mut cc1, &cc2) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut cc1, &cc2) }); assert!(((cc1.v) == (2))); let mut hc1: HasCopyCounted = HasCopyCounted { c: { @@ -357,7 +409,7 @@ unsafe fn main_0() -> i32 { }, ], }; - (unsafe { HasCopyCounted::copy_assign(&mut hc1, &hc2) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut hc1, &hc2) }); assert!( (((hc1.c.v) == (4)) && ((hc1.arr[(0) as usize].v) == (5))) && ((hc1.arr[(1) as usize].v) == (6)) diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index be812d8f53..622619e864 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -8,7 +8,15 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + MovableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Counted { pub v: i32, @@ -17,11 +25,15 @@ impl Counted { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, o: *const Counted) { +} +impl CopyConstructibleUnsafe for Counted { + unsafe fn copy_constructor(&mut self, o: *const Counted) { (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, _a0: *const Counted) -> *mut Counted { +} +impl CopyAssignableUnsafe for Counted { + unsafe fn copy_assign(&mut self, _a0: *const Counted) -> *mut Counted { self.v = (*_a0).v; return &mut (*(self as *mut Counted)); } @@ -30,13 +42,20 @@ impl Clone for Counted { fn clone(&self) -> Self { unsafe { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, self as *const Counted); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Counted); __v } } } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, +)] pub struct NonConst { pub mark: i32, } @@ -50,7 +69,9 @@ impl NonConst { pub unsafe fn construct_2(&mut self, o: *const NonConst) { (&raw mut self.mark).write((((*o).mark) + (10))); } - pub unsafe fn copy_assign(&mut self, _a0: *const NonConst) -> *mut NonConst { +} +impl CopyAssignableUnsafe for NonConst { + unsafe fn copy_assign(&mut self, _a0: *const NonConst) -> *mut NonConst { self.mark = (*_a0).mark; return &mut (*(self as *mut NonConst)); } @@ -76,7 +97,15 @@ impl Default for NonConst { } } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + MovableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Ignored { pub v: i32, @@ -85,11 +114,15 @@ impl Ignored { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, _a0: *const Ignored) { +} +impl CopyConstructibleUnsafe for Ignored { + unsafe fn copy_constructor(&mut self, _a0: *const Ignored) { (&raw mut self.v).write(-1_i32); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, _a0: *const Ignored) -> *mut Ignored { +} +impl CopyAssignableUnsafe for Ignored { + unsafe fn copy_assign(&mut self, _a0: *const Ignored) -> *mut Ignored { self.v = (*_a0).v; return &mut (*(self as *mut Ignored)); } @@ -98,22 +131,31 @@ impl Clone for Ignored { fn clone(&self) -> Self { unsafe { let mut __v: Ignored = ::zero_init(); - Ignored::copy_from(&mut __v, self as *const Ignored); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Ignored); __v } } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] pub struct Holder { pub c: Counted, pub arr: [Counted; 2], } -impl Holder { - pub unsafe fn copy_assign(&mut self, _a0: *const Holder) -> *mut Holder { +impl CopyAssignableUnsafe for Holder { + unsafe fn copy_assign(&mut self, _a0: *const Holder) -> *mut Holder { (unsafe { let _arg0: *const Counted = &(*_a0).c; - Counted::copy_assign(&mut self.c, _arg0) + CopyAssignableUnsafe::copy_assign(&mut self.c, _arg0) }); { let mut __tmp_0 = { ((&mut self.arr as *mut [Counted; 2]) as *mut ::libc::c_void) }; @@ -127,7 +169,17 @@ impl Holder { } } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Box_int_ { pub val: i32, @@ -136,10 +188,14 @@ impl Box_int_ { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.val).write(v); } - pub unsafe fn copy_from(&mut self, o: *const Box_int_) { +} +impl CopyConstructibleUnsafe for Box_int_ { + unsafe fn copy_constructor(&mut self, o: *const Box_int_) { (&raw mut self.val).write((*o).val); } - pub unsafe fn move_from(&mut self, _a0: *mut Box_int_) { +} +impl MoveConstructibleUnsafe for Box_int_ { + unsafe fn move_constructor(&mut self, _a0: *mut Box_int_) { (&raw mut self.val).write((*_a0).val); } } @@ -147,27 +203,46 @@ impl Clone for Box_int_ { fn clone(&self) -> Self { unsafe { let mut __v: Box_int_ = ::zero_init(); - Box_int_::copy_from(&mut __v, self as *const Box_int_); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Box_int_); __v } } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] pub struct Owner { pub box_: Box_int_, } -impl Owner { - pub unsafe fn move_from(&mut self, _a0: *mut Owner) { +impl MoveConstructibleUnsafe for Owner { + unsafe fn move_constructor(&mut self, _a0: *mut Owner) { (&raw mut self.box_).write({ let mut __v: Box_int_ = ::zero_init(); - Box_int_::move_from(&mut __v, { &mut (*_a0).box_ }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).box_ }); __v }); } } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + MovableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct OutOfLine { pub v: i32, @@ -176,11 +251,15 @@ impl OutOfLine { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, o: *const OutOfLine) { +} +impl CopyConstructibleUnsafe for OutOfLine { + unsafe fn copy_constructor(&mut self, o: *const OutOfLine) { (&raw mut self.v).write((((*o).v) + (100))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, _a0: *const OutOfLine) -> *mut OutOfLine { +} +impl CopyAssignableUnsafe for OutOfLine { + unsafe fn copy_assign(&mut self, _a0: *const OutOfLine) -> *mut OutOfLine { self.v = (*_a0).v; return &mut (*(self as *mut OutOfLine)); } @@ -189,23 +268,24 @@ impl Clone for OutOfLine { fn clone(&self) -> Self { unsafe { let mut __v: OutOfLine = ::zero_init(); - OutOfLine::copy_from(&mut __v, self as *const OutOfLine); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const OutOfLine); __v } } } -impl OutOfLine {} #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MovableUnsafe)] pub struct Tracked { pub copied_from: i32, } -impl Tracked { - pub unsafe fn copy_from(&mut self, o: *const Tracked) { +impl CopyConstructibleUnsafe for Tracked { + unsafe fn copy_constructor(&mut self, o: *const Tracked) { (&raw mut self.copied_from).write(0); (*(&raw const (*o).copied_from).cast_mut()).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, o: *const Tracked) -> *mut Tracked { +} +impl CopyAssignableUnsafe for Tracked { + unsafe fn copy_assign(&mut self, o: *const Tracked) -> *mut Tracked { (*(&raw const (*o).copied_from).cast_mut()).prefix_inc(); return &mut (*(self as *mut Tracked)); } @@ -214,7 +294,7 @@ impl Clone for Tracked { fn clone(&self) -> Self { unsafe { let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, self as *const Tracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Tracked); __v } } @@ -238,7 +318,7 @@ pub unsafe fn make_3(mut v: i32) -> Counted { }; return { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, { &c }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); __v }; } @@ -256,17 +336,17 @@ unsafe fn main_0() -> i32 { }; let mut b: Counted = { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, { &a }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &a }); __v }; let mut c: Counted = { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, { &a }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &a }); __v }; let mut d: Counted = { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, { &a }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &a }); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (3))); @@ -275,7 +355,7 @@ unsafe fn main_0() -> i32 { ((unsafe { by_value_2({ let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, { &a }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &a }); __v }) }) == (1)) @@ -298,7 +378,7 @@ unsafe fn main_0() -> i32 { }; let mut h: Counted = { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, { &g }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &g }); __v }; assert!(((h.v) == (7))); @@ -342,7 +422,7 @@ unsafe fn main_0() -> i32 { }; let mut i2: Ignored = { let mut __v: Ignored = ::zero_init(); - Ignored::copy_from(&mut __v, { &i1 }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &i1 }); __v }; assert!(((i1.v) == (1)) && ((i2.v) == (-1_i32))); @@ -356,7 +436,7 @@ unsafe fn main_0() -> i32 { }; let mut o2: Owner = { let mut __v: Owner = ::zero_init(); - Owner::move_from(&mut __v, { &mut o }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut o }); __v }; assert!(((o2.box_.val) == (3))); @@ -367,7 +447,7 @@ unsafe fn main_0() -> i32 { }; let mut ol2: OutOfLine = { let mut __v: OutOfLine = ::zero_init(); - OutOfLine::copy_from(&mut __v, { &ol1 }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &ol1 }); __v }; assert!(((ol2.v) == (105))); @@ -397,15 +477,15 @@ unsafe fn main_0() -> i32 { let mut t1: Tracked = ::default(); let mut t2: Tracked = { let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, { &t1 }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &t1 }); __v }; - (unsafe { Tracked::copy_assign(&mut t2, &t1) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut t2, &t1) }); assert!(((t1.copied_from) == (2))); let ct: Tracked = ::default(); let mut t3: Tracked = { let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, { &ct }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &ct }); __v }; (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 f7770e3ba4..d2300550dd 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -7,13 +7,22 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub x: i32, } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default, + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, )] #[cpp_from(i32, construct, value)] pub struct Explicit { @@ -27,10 +36,21 @@ impl Explicit { (&raw mut self.inner).write(Inner { x: ((v) * (10)) }); (&raw mut self.arr).write([v, ((v) + (1))]); } - pub unsafe fn destructor(&mut self) {} +} +impl DestructibleUnsafe for Explicit { + unsafe fn destroy(&mut self) {} } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Implicit { pub v: i32, pub inner: Inner, @@ -43,9 +63,11 @@ pub struct Implicit { VaArg, FnPtrArg, ZeroInitializationUnsafe, - MoveCtorUnsafe, CppFromUnsafe, - MoveAssignUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, Default, )] #[cpp_from(i32, construct, value)] @@ -56,11 +78,15 @@ impl DefaultCopyUserMove { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn move_from(&mut self, o: *mut DefaultCopyUserMove) { +} +impl MoveConstructibleUnsafe for DefaultCopyUserMove { + unsafe fn move_constructor(&mut self, o: *mut DefaultCopyUserMove) { (&raw mut self.v).write((*o).v); (*o).v = 0; } - pub unsafe fn move_assign(&mut self, o: *mut DefaultCopyUserMove) -> *mut DefaultCopyUserMove { +} +impl MoveAssignableUnsafe for DefaultCopyUserMove { + unsafe fn move_assign(&mut self, o: *mut DefaultCopyUserMove) -> *mut DefaultCopyUserMove { self.v = (*o).v; (*o).v = 0; return &mut (*(self as *mut DefaultCopyUserMove)); @@ -71,10 +97,9 @@ impl DefaultCopyUserMove { VaArg, FnPtrArg, ZeroInitializationUnsafe, - MoveCtorUnsafe, CppFromUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, + DestructibleUnsafe, + SwappableUnsafe, Default, )] #[cpp_from(i32, construct, value)] @@ -85,23 +110,25 @@ impl UserCopyDefaultMove { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, o: *const UserCopyDefaultMove) { +} +impl CopyConstructibleUnsafe for UserCopyDefaultMove { + unsafe fn copy_constructor(&mut self, o: *const UserCopyDefaultMove) { (&raw mut self.v).write((((*o).v) + (100))); } - pub unsafe fn move_from(&mut self, _a0: *mut UserCopyDefaultMove) { +} +impl MoveConstructibleUnsafe for UserCopyDefaultMove { + unsafe fn move_constructor(&mut self, _a0: *mut UserCopyDefaultMove) { (&raw mut self.v).write((*_a0).v); } - pub unsafe fn copy_assign( - &mut self, - o: *const UserCopyDefaultMove, - ) -> *mut UserCopyDefaultMove { +} +impl CopyAssignableUnsafe for UserCopyDefaultMove { + unsafe fn copy_assign(&mut self, o: *const UserCopyDefaultMove) -> *mut UserCopyDefaultMove { self.v = (((*o).v) + (100)); return &mut (*(self as *mut UserCopyDefaultMove)); } - pub unsafe fn move_assign( - &mut self, - _a0: *mut UserCopyDefaultMove, - ) -> *mut UserCopyDefaultMove { +} +impl MoveAssignableUnsafe for UserCopyDefaultMove { + unsafe fn move_assign(&mut self, _a0: *mut UserCopyDefaultMove) -> *mut UserCopyDefaultMove { self.v = (*_a0).v; return &mut (*(self as *mut UserCopyDefaultMove)); } @@ -110,14 +137,14 @@ impl Clone for UserCopyDefaultMove { fn clone(&self) -> Self { unsafe { let mut __v: UserCopyDefaultMove = ::zero_init(); - UserCopyDefaultMove::copy_from(&mut __v, self as *const UserCopyDefaultMove); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const UserCopyDefaultMove); __v } } } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, MoveAssignUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, Default, )] #[cpp_from(i32, construct, value)] pub struct Buffer { @@ -137,7 +164,9 @@ impl Buffer { self.rows.push(a0_clone) }; } - pub unsafe fn move_from(&mut self, _a0: *mut Buffer) { +} +impl MoveConstructibleUnsafe for Buffer { + unsafe fn move_constructor(&mut self, _a0: *mut Buffer) { (&raw mut self.data).write(std::mem::take(&mut (*_a0).data)); (&raw mut self.rows).write(std::mem::take(&mut (*_a0).rows)); (&raw mut self.n).write((*_a0).n); @@ -145,7 +174,9 @@ impl Buffer { (*_a0).arr[(__i)] })); } - pub unsafe fn move_assign(&mut self, _a0: *mut Buffer) -> *mut Buffer { +} +impl MoveAssignableUnsafe for Buffer { + unsafe fn move_assign(&mut self, _a0: *mut Buffer) -> *mut Buffer { { self.data = std::mem::take(&mut (*_a0).data); }; @@ -165,15 +196,15 @@ impl Buffer { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct Owner { pub data: Vec, pub n: i32, pub arr: [i32; 2], pub p: Option>, } -impl Owner { - pub unsafe fn move_from(&mut self, _a0: *mut Owner) { +impl MoveConstructibleUnsafe for Owner { + unsafe fn move_constructor(&mut self, _a0: *mut Owner) { (&raw mut self.data).write(std::mem::take(&mut (*_a0).data)); (&raw mut self.n).write((*_a0).n); (&raw mut self.arr).write(std::array::from_fn::<_, 2, _>(|__i: usize| { @@ -181,7 +212,9 @@ impl Owner { })); (&raw mut self.p).write((*_a0).p.take()); } - pub unsafe fn move_assign(&mut self, _a0: *mut Owner) -> *mut Owner { +} +impl MoveAssignableUnsafe for Owner { + unsafe fn move_assign(&mut self, _a0: *mut Owner) -> *mut Owner { { self.data = std::mem::take(&mut (*_a0).data); }; @@ -202,16 +235,26 @@ impl Owner { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Copyable { pub data: Vec, } -impl Copyable { - pub unsafe fn move_from(&mut self, _a0: *mut Copyable) { +impl MoveConstructibleUnsafe for Copyable { + unsafe fn move_constructor(&mut self, _a0: *mut Copyable) { (&raw mut self.data).write(std::mem::take(&mut (*_a0).data)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Copyable) -> *mut Copyable { +} +impl MoveAssignableUnsafe for Copyable { + unsafe fn move_assign(&mut self, _a0: *mut Copyable) -> *mut Copyable { { self.data = std::mem::take(&mut (*_a0).data); }; @@ -219,15 +262,7 @@ impl Copyable { } } #[repr(C)] -#[derive( - FnPtrArg, - ZeroInitializationUnsafe, - MoveCtorUnsafe, - CppFromUnsafe, - MoveAssignUnsafe, - DestructibleUnsafe, - Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, SwappableUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct Holder { pub inner: Inner, @@ -244,12 +279,16 @@ impl Holder { }); (&raw mut self.p).write(None); } - pub unsafe fn move_from(&mut self, _a0: *mut Holder) { +} +impl MoveConstructibleUnsafe for Holder { + unsafe fn move_constructor(&mut self, _a0: *mut Holder) { (&raw mut self.inner).write((*_a0).inner); (&raw mut self.e).write((*_a0).e.clone()); (&raw mut self.p).write((*_a0).p.take()); } - pub unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { +} +impl MoveAssignableUnsafe for Holder { + unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { self.inner = (*_a0).inner; self.e = ((*_a0).e).clone(); { @@ -258,9 +297,9 @@ impl Holder { return &mut (*(self as *mut Holder)); } } -impl Holder { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.e); +impl DestructibleUnsafe for Holder { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.e); } } pub unsafe fn same_0(a: *const Explicit, b: *const Explicit) -> bool { @@ -281,19 +320,19 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut b: Explicit = a.clone(); let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut c: Explicit = a.clone(); let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut d: Explicit = a.clone(); let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!( ((unsafe { same_0(&b, &a,) }) && (unsafe { same_0(&c, &a,) })) @@ -305,7 +344,7 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_e = std::mem::DropGuard::new(&raw mut e, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut f: Explicit = { let mut __v: Explicit = ::zero_init(); @@ -313,7 +352,7 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); e = (b).clone(); f = (c).clone(); @@ -324,7 +363,7 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); g = { e = (f).clone(); @@ -369,7 +408,7 @@ unsafe fn main_0() -> i32 { let mut m1: DefaultCopyUserMove = m; let mut m2: DefaultCopyUserMove = { let mut __v: DefaultCopyUserMove = ::zero_init(); - DefaultCopyUserMove::move_from(&mut __v, { &mut m }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut m }); __v }; assert!((((m1.v) == (7)) && ((m2.v) == (7))) && ((m.v) == (0))); @@ -384,7 +423,7 @@ unsafe fn main_0() -> i32 { __v }; m3 = m1; - (unsafe { DefaultCopyUserMove::move_assign(&mut m4, &mut m1) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut m4, &mut m1) }); assert!((((m3.v) == (7)) && ((m4.v) == (7))) && ((m1.v) == (0))); let mut u: UserCopyDefaultMove = { let mut __v: UserCopyDefaultMove = ::zero_init(); @@ -393,12 +432,12 @@ unsafe fn main_0() -> i32 { }; let mut u1: UserCopyDefaultMove = { let mut __v: UserCopyDefaultMove = ::zero_init(); - UserCopyDefaultMove::copy_from(&mut __v, { &u }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &u }); __v }; let mut u2: UserCopyDefaultMove = { let mut __v: UserCopyDefaultMove = ::zero_init(); - UserCopyDefaultMove::move_from(&mut __v, { &mut u }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut u }); __v }; assert!((((u1.v) == (108)) && ((u2.v) == (8))) && ((u.v) == (8))); @@ -412,8 +451,8 @@ unsafe fn main_0() -> i32 { UserCopyDefaultMove::construct(&mut __v, { 1 }); __v }; - (unsafe { UserCopyDefaultMove::copy_assign(&mut u3, &u2) }); - (unsafe { UserCopyDefaultMove::move_assign(&mut u4, &mut u2) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut u3, &u2) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut u4, &mut u2) }); assert!(((u3.v) == (108)) && ((u4.v) == (8))); let mut p: Buffer = { let mut __v: Buffer = ::zero_init(); @@ -422,7 +461,7 @@ unsafe fn main_0() -> i32 { }; let mut q: Buffer = { let mut __v: Buffer = ::zero_init(); - Buffer::move_from(&mut __v, { &mut p }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut p }); __v }; assert!( @@ -434,7 +473,7 @@ unsafe fn main_0() -> i32 { Buffer::construct(&mut __v, { 1 }); __v }; - (unsafe { Buffer::move_assign(&mut r, &mut q) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut r, &mut q) }); assert!( ((((r.n) == (3)) && ((r.data.len()) == (3_usize))) && ((r.arr[(1) as usize]) == (4))) && (q.data.is_empty()) @@ -447,7 +486,7 @@ unsafe fn main_0() -> i32 { { let __a1 = { let mut __v: Buffer = ::zero_init(); - Buffer::move_from(&mut __v, { &mut r }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut r }); __v }; bufs.push(__a1) @@ -456,7 +495,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_4 = { { let mut __v: Buffer = ::zero_init(); - Buffer::move_from(&mut __v, { &mut bufs[(0_usize)] }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut bufs[(0_usize)] }); __v } }; @@ -484,7 +523,7 @@ unsafe fn main_0() -> i32 { }; let mut o2: Owner = { let mut __v: Owner = ::zero_init(); - Owner::move_from(&mut __v, { &mut o1 }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut o1 }); __v }; assert!( @@ -504,7 +543,7 @@ unsafe fn main_0() -> i32 { .is_null()) ); let mut o3: Owner = ::default(); - (unsafe { Owner::move_assign(&mut o3, &mut o2) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut o3, &mut o2) }); assert!( ((((o3.n) == (5)) && ((o3.data[(0_usize)]) == (5))) && ((o3.arr[(0) as usize]) == (5))) && ((*o3 @@ -527,13 +566,13 @@ unsafe fn main_0() -> i32 { let mut c2: Copyable = c1.clone(); let mut c3: Copyable = { let mut __v: Copyable = ::zero_init(); - Copyable::move_from(&mut __v, { &mut c1 }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut c1 }); __v }; assert!(((c2.data.len()) == (2_usize)) && ((c3.data.len()) == (2_usize))); assert!(c1.data.is_empty()); let mut c4: Copyable = ::default(); - (unsafe { Copyable::move_assign(&mut c4, &mut c3) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut c4, &mut c3) }); assert!(((c4.data[(1_usize)]) == (2)) && (c3.data.is_empty())); let mut h1: Holder = { let mut __v: Holder = ::zero_init(); @@ -541,7 +580,7 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_h1 = std::mem::DropGuard::new(&raw mut h1, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); { let _a0: *mut i32 = (Box::leak(Box::new(9)) as *mut i32); @@ -553,11 +592,11 @@ unsafe fn main_0() -> i32 { }; let mut h2: Holder = { let mut __v: Holder = ::zero_init(); - Holder::move_from(&mut __v, { &mut h1 }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut h1 }); __v }; let _dtor_h2 = std::mem::DropGuard::new(&raw mut h2, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!( ((((h2.inner.x) == (4)) && ((h2.e.v) == (4))) @@ -578,9 +617,9 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_h3 = std::mem::DropGuard::new(&raw mut h3, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); - (unsafe { Holder::move_assign(&mut h3, &mut h2) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut h3, &mut h2) }); assert!( ((((h3.inner.x) == (4)) && ((h3.e.arr[(1) as usize]) == (5))) && ((*h3 diff --git a/tests/unit/out/unsafe/copy_move_deleted.rs b/tests/unit/out/unsafe/copy_move_deleted.rs index 89849f20f5..5d6bf31be6 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.rs @@ -8,7 +8,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, MoveAssignUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, Default, )] #[cpp_from(i32, construct, value)] pub struct NoCopy { @@ -18,18 +18,22 @@ impl NoCopy { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn move_from(&mut self, o: *mut NoCopy) { +} +impl MoveConstructibleUnsafe for NoCopy { + unsafe fn move_constructor(&mut self, o: *mut NoCopy) { (&raw mut self.v).write((*o).v); (*o).v = 0; } - pub unsafe fn move_assign(&mut self, o: *mut NoCopy) -> *mut NoCopy { +} +impl MoveAssignableUnsafe for NoCopy { + unsafe fn move_assign(&mut self, o: *mut NoCopy) -> *mut NoCopy { self.v = (*o).v; (*o).v = 0; return &mut (*(self as *mut NoCopy)); } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe)] pub struct PrivateCopy { pub v: i32, } @@ -37,11 +41,15 @@ impl PrivateCopy { pub unsafe fn construct(&mut self) { (&raw mut self.v).write(0); } - pub unsafe fn move_from(&mut self, o: *mut PrivateCopy) { +} +impl MoveConstructibleUnsafe for PrivateCopy { + unsafe fn move_constructor(&mut self, o: *mut PrivateCopy) { (&raw mut self.v).write((*o).v); (*o).v = 0; } - pub unsafe fn move_assign(&mut self, o: *mut PrivateCopy) -> *mut PrivateCopy { +} +impl MoveAssignableUnsafe for PrivateCopy { + unsafe fn move_assign(&mut self, o: *mut PrivateCopy) -> *mut PrivateCopy { self.v = (*o).v; (*o).v = 0; return &mut (*(self as *mut PrivateCopy)); @@ -59,7 +67,7 @@ impl Default for PrivateCopy { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] pub struct Immovable { pub v: i32, } @@ -80,39 +88,43 @@ impl Default for Immovable { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct Container { pub inner: NoCopy, pub tag: i32, } -impl Container { - pub unsafe fn move_from(&mut self, _a0: *mut Container) { +impl MoveConstructibleUnsafe for Container { + unsafe fn move_constructor(&mut self, _a0: *mut Container) { (&raw mut self.inner).write({ let mut __v: NoCopy = ::zero_init(); - NoCopy::move_from(&mut __v, { &mut (*_a0).inner }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).inner }); __v }); (&raw mut self.tag).write((*_a0).tag); } - pub unsafe fn move_assign(&mut self, _a0: *mut Container) -> *mut Container { +} +impl MoveAssignableUnsafe for Container { + unsafe fn move_assign(&mut self, _a0: *mut Container) -> *mut Container { (unsafe { let _o: *mut NoCopy = &mut (*_a0).inner; - NoCopy::move_assign(&mut self.inner, _o) + MoveAssignableUnsafe::move_assign(&mut self.inner, _o) }); self.tag = (*_a0).tag; return &mut (*(self as *mut Container)); } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct VecHolder { pub items: Vec, } -impl VecHolder { - pub unsafe fn move_from(&mut self, _a0: *mut VecHolder) { +impl MoveConstructibleUnsafe for VecHolder { + unsafe fn move_constructor(&mut self, _a0: *mut VecHolder) { (&raw mut self.items).write(std::mem::take(&mut (*_a0).items)); } - pub unsafe fn move_assign(&mut self, _a0: *mut VecHolder) -> *mut VecHolder { +} +impl MoveAssignableUnsafe for VecHolder { + unsafe fn move_assign(&mut self, _a0: *mut VecHolder) -> *mut VecHolder { { self.items = std::mem::take(&mut (*_a0).items); }; @@ -139,11 +151,11 @@ unsafe fn main_0() -> i32 { }; let mut b: NoCopy = { let mut __v: NoCopy = ::zero_init(); - NoCopy::move_from(&mut __v, { &mut a }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut a }); __v }; assert!(((b.v) == (1)) && ((a.v) == (0))); - (unsafe { NoCopy::move_assign(&mut a, &mut b) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut a, &mut b) }); assert!(((a.v) == (1)) && ((b.v) == (0))); (unsafe { bump_0((&mut a as *mut NoCopy)) }); assert!(((a.v) == (2))); @@ -155,11 +167,11 @@ unsafe fn main_0() -> i32 { p.v = 3; let mut q: PrivateCopy = { let mut __v: PrivateCopy = ::zero_init(); - PrivateCopy::move_from(&mut __v, { &mut p }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut p }); __v }; assert!(((q.v) == (3)) && ((p.v) == (0))); - (unsafe { PrivateCopy::move_assign(&mut p, &mut q) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut p, &mut q) }); assert!(((p.v) == (3)) && ((q.v) == (0))); let mut im: Immovable = { let mut __v: Immovable = ::zero_init(); @@ -180,17 +192,27 @@ unsafe fn main_0() -> i32 { }; let mut d: Container = { let mut __v: Container = ::zero_init(); - Container::move_from(&mut __v, { &mut c }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut c }); __v }; assert!((((d.inner.v) == (6)) && ((d.tag) == (7))) && ((c.inner.v) == (0))); let mut h: VecHolder = ::default(); let mut h2: VecHolder = { let mut __v: VecHolder = ::zero_init(); - VecHolder::move_from(&mut __v, { &mut h }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut h }); __v }; assert!(((h2.items.len()) == (0_usize))); return 0; } +impl CopyAssignableUnsafe for PrivateCopy { + unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self { + unreachable!("PrivateCopy::copy_assign is never defined") + } +} +impl CopyConstructibleUnsafe for PrivateCopy { + unsafe fn copy_constructor(&mut self, _: *const Self) { + unreachable!("PrivateCopy::copy_constructor is never defined") + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/default.rs b/tests/unit/out/unsafe/default.rs index 05fd21467a..db86e237ca 100644 --- a/tests/unit/out/unsafe/default.rs +++ b/tests/unit/out/unsafe/default.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pointers { pub x1: *mut i32, pub x2: *const i32, @@ -16,7 +25,16 @@ pub struct Pointers { pub x5: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct SmallArrays { pub a: [i32; 32], pub f: Option i32>, @@ -24,7 +42,9 @@ pub struct SmallArrays { pub p: [Pointers; 2], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] 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 33bed19cf6..6c3937e6d5 100644 --- a/tests/unit/out/unsafe/default_function_arguments.rs +++ b/tests/unit/out/unsafe/default_function_arguments.rs @@ -13,7 +13,16 @@ pub unsafe fn baz_1(mut a: *mut i32, mut b: *mut i32) -> bool { return ((a) == (b)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, +)] #[cpp_from(i32, construct, value)] pub struct Bar { pub v: i32, @@ -61,7 +70,16 @@ pub unsafe fn first_9(r: *mut [i32; 3]) -> i32 { return (*r)[(0) as usize]; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 15f4dfe71c..254bc6e763 100644 --- a/tests/unit/out/unsafe/default_in_statics.rs +++ b/tests/unit/out/unsafe/default_in_statics.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub v: i32, pub name: *const libc::c_char, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer { pub p1: *mut i32, pub p2: *const i32, @@ -25,7 +43,16 @@ pub struct Outer { pub fn_: Option i32>, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Foo { pub s1: *const libc::c_char, pub s2: *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 81497cbb60..6b2da5ceed 100644 --- a/tests/unit/out/unsafe/delete_array_order.rs +++ b/tests/unit/out/unsafe/delete_array_order.rs @@ -7,13 +7,13 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Element { pub id: i64, pub value: i64, } -impl Element { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for Element { + unsafe fn destroy(&mut self) { (unsafe { libc::printf( c"%ld:%ld ".as_ptr() as *const libc::c_char, @@ -52,7 +52,7 @@ unsafe fn main_0() -> i32 { / ::std::mem::size_of::()) .rev() { - DestructibleUnsafe::destroy(__p.add(__i)); + DestructibleUnsafe::destroy(&mut *__p.add(__i)); } ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( __p, diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index 9d957882a6..ec163db750 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -8,94 +8,94 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct S {} -impl S { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for S { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).postfix_inc(); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Defaulted { pub s: S, } -impl Defaulted { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.s); +impl DestructibleUnsafe for Defaulted { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.s); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Middle { pub s: S, } -impl Middle { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.s); +impl DestructibleUnsafe for Middle { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.s); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Outer { pub m: Middle, } -impl Outer { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.m); +impl DestructibleUnsafe for Outer { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.m); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct ArrayMember { pub items: [S; 3], } -impl ArrayMember { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.items); +impl DestructibleUnsafe for ArrayMember { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.items); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct EmptyBody { pub s: S, } -impl EmptyBody { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.s); +impl DestructibleUnsafe for EmptyBody { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.s); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Templated_char_ { pub v: libc::c_char, } -impl Templated_char_ { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for Templated_char_ { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) .wrapping_add((::std::mem::size_of::() as usize))) as i32; } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Templated_int_ { pub v: i32, } -impl Templated_int_ { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for Templated_int_ { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) .wrapping_add((::std::mem::size_of::() as usize))) as i32; } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Copied { pub v: i32, } -impl Copied { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for Copied { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).postfix_inc(); } } @@ -103,19 +103,19 @@ pub static mut order_1: std::cell::LazyCell<[i32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_i32; 3] }); pub static mut order_count_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Tagged { pub tag: i32, } -impl Tagged { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for Tagged { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut order_1)) [((*std::cell::LazyCell::force_mut(&mut *&raw mut order_count_2)).postfix_inc()) as usize] = self.tag; } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Ordered { pub first: Tagged, pub dummy1: i32, @@ -123,11 +123,11 @@ pub struct Ordered { pub dummy2: i32, pub third: Tagged, } -impl Ordered { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.third); - DestructibleUnsafe::destroy(&raw mut self.second); - DestructibleUnsafe::destroy(&raw mut self.first); +impl DestructibleUnsafe for Ordered { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.third); + DestructibleUnsafe::destroy(&mut self.second); + DestructibleUnsafe::destroy(&mut self.first); } } pub fn main() { @@ -140,64 +140,64 @@ unsafe fn main_0() -> i32 { { let mut s: S = ::default(); let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (1))); { let mut s: S = ::default(); let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (2))); { let mut d: Defaulted = ::default(); let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (3))); { let mut o: Outer = ::default(); let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (4))); { let mut am: ArrayMember = ::default(); let _dtor_am = std::mem::DropGuard::new(&raw mut am, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (7))); { let mut e: EmptyBody = ::default(); let _dtor_e = std::mem::DropGuard::new(&raw mut e, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (8))); { let mut tc: Templated_char_ = ::default(); let _dtor_tc = std::mem::DropGuard::new(&raw mut tc, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut ti: Templated_int_ = ::default(); let _dtor_ti = std::mem::DropGuard::new(&raw mut ti, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (13))); { let mut a: Copied = Copied { v: 5 }; let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut b: Copied = a.clone(); let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!(((b.v) == (5))); } @@ -211,7 +211,7 @@ unsafe fn main_0() -> i32 { third: Tagged { tag: 3 }, }; let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut order_count_2)) == (3))); @@ -222,7 +222,7 @@ unsafe fn main_0() -> i32 { { let mut cs: S = ::default(); let _dtor_cs = std::mem::DropGuard::new(&raw mut cs, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == ((before) + (1)))); diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index 6dc8046c61..8bf2d17cc3 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -9,12 +9,12 @@ use std::rc::Rc; pub static mut destroyed_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct S { pub v: i32, } -impl S { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for S { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)).postfix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = self.v; } @@ -27,7 +27,16 @@ pub unsafe fn with_default_3(mut s: S) -> i32 { return s.v; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Holder { pub v: i32, } @@ -49,7 +58,7 @@ unsafe fn main_0() -> i32 { { let mut s: S = S { v: 1 }; let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!(((unsafe { by_value_2(s.clone(),) }) == (1))); assert!( diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index fa79b0547c..69037a770c 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -9,28 +9,30 @@ use std::rc::Rc; pub static mut destroyed_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct S { pub v: i32, } impl S { - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)).postfix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = self.v; - } pub unsafe fn get(&self) -> i32 { return self.v; } } +impl DestructibleUnsafe for S { + unsafe fn destroy(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)).postfix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = self.v; + } +} #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Outer { pub inner: S, pub w: i32, } -impl Outer { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.inner); +impl DestructibleUnsafe for Outer { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.inner); } } pub unsafe fn make_2(mut v: i32) -> S { @@ -134,7 +136,7 @@ unsafe fn main_0() -> i32 { { let mut s: S = S { v: 12 }; let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); s = (unsafe { make_2(13) }); assert!( diff --git a/tests/unit/out/unsafe/doubly_linked_list.rs b/tests/unit/out/unsafe/doubly_linked_list.rs index 912cdbf0ca..1cce38f8cb 100644 --- a/tests/unit/out/unsafe/doubly_linked_list.rs +++ b/tests/unit/out/unsafe/doubly_linked_list.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Node { pub val: i32, pub next: *mut Node, diff --git a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs index 1e87ab39ce..0a5d147cf5 100644 --- a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs @@ -38,7 +38,7 @@ unsafe fn main_0() -> i32 { let __n = v.end().iter_distance(&__tmp_2); for __i in (1..__n).rev() { let __j = libc::rand() as isize % (__i + 1); - cpp_swap_unsafe!(__tmp_2.iter_at(__i), __tmp_2.iter_at(__j)); + SwappableUnsafe::swap(&mut *__tmp_2.iter_at(__i), __tmp_2.iter_at(__j)); } }; { diff --git a/tests/unit/out/unsafe/enum_default_in_static.rs b/tests/unit/out/unsafe/enum_default_in_static.rs index 472094aeb9..0bd954a6ce 100644 --- a/tests/unit/out/unsafe/enum_default_in_static.rs +++ b/tests/unit/out/unsafe/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; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Config { pub count: i32, pub mode: Mode, diff --git a/tests/unit/out/unsafe/enum_int_interop.rs b/tests/unit/out/unsafe/enum_int_interop.rs index 211b2e447c..b079413208 100644 --- a/tests/unit/out/unsafe/enum_int_interop.rs +++ b/tests/unit/out/unsafe/enum_int_interop.rs @@ -20,7 +20,16 @@ pub const Tag_TAG_ZERO: Tag = 0; pub const Tag_TAG_ONE: Tag = 1; pub const Tag_TAG_TWO: Tag = 2; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Entry { pub name: *const libc::c_char, pub color: Color, diff --git a/tests/unit/out/unsafe/enum_int_interop_c.rs b/tests/unit/out/unsafe/enum_int_interop_c.rs index fdc625c087..c28d97772b 100644 --- a/tests/unit/out/unsafe/enum_int_interop_c.rs +++ b/tests/unit/out/unsafe/enum_int_interop_c.rs @@ -20,7 +20,16 @@ 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; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Entry { pub name: *const libc::c_char, pub color: Color, diff --git a/tests/unit/out/unsafe/enum_underlying_type.rs b/tests/unit/out/unsafe/enum_underlying_type.rs index 6b128a0f78..d957cd98ed 100644 --- a/tests/unit/out/unsafe/enum_underlying_type.rs +++ b/tests/unit/out/unsafe/enum_underlying_type.rs @@ -26,7 +26,9 @@ pub const Scoped_NEG: Scoped = -2; pub const Scoped_POS: Scoped = 2; pub type Empty = bool; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct HoldsEmpty { pub e: Empty, } diff --git a/tests/unit/out/unsafe/exprs.rs b/tests/unit/out/unsafe/exprs.rs index cb3339a6fe..61e152ca29 100644 --- a/tests/unit/out/unsafe/exprs.rs +++ b/tests/unit/out/unsafe/exprs.rs @@ -7,12 +7,30 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct X { pub x: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Y { pub x: X, pub p: *mut X, diff --git a/tests/unit/out/unsafe/fft.rs b/tests/unit/out/unsafe/fft.rs index 6459d36e64..788a6c6834 100644 --- a/tests/unit/out/unsafe/fft.rs +++ b/tests/unit/out/unsafe/fft.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Complex { pub re: f64, pub img: f64, diff --git a/tests/unit/out/unsafe/field_aliasing.rs b/tests/unit/out/unsafe/field_aliasing.rs index a7c6f15676..6f02452a3b 100644 --- a/tests/unit/out/unsafe/field_aliasing.rs +++ b/tests/unit/out/unsafe/field_aliasing.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct In { pub x: i32, pub y: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub in_: In, pub total: i32, @@ -21,7 +39,16 @@ pub struct S { pub arr: [i32; 4], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Node { pub x: i32, pub self_: *mut Node, diff --git a/tests/unit/out/unsafe/field_array_elem_ptr.rs b/tests/unit/out/unsafe/field_array_elem_ptr.rs index 7fcffe7186..a9674c8fee 100644 --- a/tests/unit/out/unsafe/field_array_elem_ptr.rs +++ b/tests/unit/out/unsafe/field_array_elem_ptr.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Point { pub x: i32, pub y: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Shape { pub id: i32, pub coords: [i32; 4], diff --git a/tests/unit/out/unsafe/field_method_receiver.rs b/tests/unit/out/unsafe/field_method_receiver.rs index 038fbb710b..7215004943 100644 --- a/tests/unit/out/unsafe/field_method_receiver.rs +++ b/tests/unit/out/unsafe/field_method_receiver.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Counter { pub n: i32, } @@ -28,7 +37,15 @@ impl Counter { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct S { pub tag: i32, @@ -43,7 +60,9 @@ impl S { Counter::add(&mut self.c, _k) }); } - pub unsafe fn move_from(&mut self, _a0: *mut S) { +} +impl MoveConstructibleUnsafe for S { + unsafe fn move_constructor(&mut self, _a0: *mut S) { (&raw mut self.tag).write((*_a0).tag); (&raw mut self.c).write((*_a0).c); (&raw mut self.arr).write(std::array::from_fn::<_, 2, _>(|__i: usize| { @@ -51,7 +70,9 @@ impl S { })); (&raw mut self.v).write(std::mem::take(&mut (*_a0).v)); } - pub unsafe fn move_assign(&mut self, _a0: *mut S) -> *mut S { +} +impl MoveAssignableUnsafe for S { + unsafe fn move_assign(&mut self, _a0: *mut S) -> *mut S { self.tag = (*_a0).tag; self.c = (*_a0).c; { diff --git a/tests/unit/out/unsafe/field_pointers.rs b/tests/unit/out/unsafe/field_pointers.rs index 6dde0af000..2682f5e01d 100644 --- a/tests/unit/out/unsafe/field_pointers.rs +++ b/tests/unit/out/unsafe/field_pointers.rs @@ -7,20 +7,46 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub a: i32, pub name: [libc::c_char; 8], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Header { pub tag: i32, pub size: i16, } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Outer { pub x: i32, @@ -43,7 +69,9 @@ impl Outer { self.v.push(__a1) }; } - pub unsafe fn move_from(&mut self, _a0: *mut Outer) { +} +impl MoveConstructibleUnsafe for Outer { + unsafe fn move_constructor(&mut self, _a0: *mut Outer) { (&raw mut self.x).write((*_a0).x); (&raw mut self.inner).write((*_a0).inner); (&raw mut self.items).write(std::array::from_fn::<_, 3, _>(|__i: usize| { @@ -55,7 +83,9 @@ impl Outer { (*_a0).buf[(__i)] })); } - pub unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { +} +impl MoveAssignableUnsafe for Outer { + unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { self.x = (*_a0).x; self.inner = (*_a0).inner; { diff --git a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs index 13b23f2a2f..8b21831780 100644 --- a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs +++ b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub a: i32, pub b: i32, diff --git a/tests/unit/out/unsafe/field_reinterpret_write_through.rs b/tests/unit/out/unsafe/field_reinterpret_write_through.rs index de74176526..70ebbf27a0 100644 --- a/tests/unit/out/unsafe/field_reinterpret_write_through.rs +++ b/tests/unit/out/unsafe/field_reinterpret_write_through.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct In { pub a: i16, pub b: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub x: i32, pub in_: In, diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index 70572a49b2..d4e2d4d9e7 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 25518f53be..43a7044886 100644 --- a/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs +++ b/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct In { pub a: i16, pub b: i16, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub x: i32, pub in_: In, diff --git a/tests/unit/out/unsafe/first_member_downcast.rs b/tests/unit/out/unsafe/first_member_downcast.rs index f6ddfb29a4..66c8c06c7f 100644 --- a/tests/unit/out/unsafe/first_member_downcast.rs +++ b/tests/unit/out/unsafe/first_member_downcast.rs @@ -7,12 +7,30 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct base { pub kind: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct derived { pub head: base, pub value: usize, diff --git a/tests/unit/out/unsafe/flex_array_member_incomplete.rs b/tests/unit/out/unsafe/flex_array_member_incomplete.rs index 07ee75a28f..d6858e1859 100644 --- a/tests/unit/out/unsafe/flex_array_member_incomplete.rs +++ b/tests/unit/out/unsafe/flex_array_member_incomplete.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] 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 be0df75738..47fc857aa4 100644 --- a/tests/unit/out/unsafe/flex_array_member_sibling_write.rs +++ b/tests/unit/out/unsafe/flex_array_member_sibling_write.rs @@ -7,19 +7,46 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub n: i32, pub name: [libc::c_char; 1], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct E { pub id: i32, pub w: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct T { pub n: i32, pub cap: i32, diff --git a/tests/unit/out/unsafe/fn_ptr.rs b/tests/unit/out/unsafe/fn_ptr.rs index abad5a3c0d..0bdabf1fc8 100644 --- a/tests/unit/out/unsafe/fn_ptr.rs +++ b/tests/unit/out/unsafe/fn_ptr.rs @@ -32,7 +32,17 @@ pub unsafe fn identity_hash_6(mut v: bool) -> usize { return (v as usize); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(Option u64 > , construct, ptr)] pub struct HashHolder_unsigned_long__ptr__bool__ { pub h: Option u64>, diff --git a/tests/unit/out/unsafe/fn_ptr_cast.rs b/tests/unit/out/unsafe/fn_ptr_cast.rs index e9d0bc2af1..aa381b191f 100644 --- a/tests/unit/out/unsafe/fn_ptr_cast.rs +++ b/tests/unit/out/unsafe/fn_ptr_cast.rs @@ -30,7 +30,16 @@ pub unsafe fn test_double_cast_2() { assert!(((fn2) == (fn_))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 6ab8577bde..d32ebd39f3 100644 --- a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs +++ b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Item { pub key: i32, pub value: i32, diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index 9164445c60..db38c500b5 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Handler { pub tag: i32, pub cb: Option i32>, @@ -19,7 +28,16 @@ pub unsafe fn negate_1(mut x: i32) -> i32 { return -x; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S {} impl S { pub unsafe fn pick_1(mut x: i32) -> i32 { @@ -33,7 +51,7 @@ impl S { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct MoveOnly { pub data_: i32, @@ -42,14 +60,16 @@ impl MoveOnly { pub unsafe fn construct(&mut self, mut data: i32) { (&raw mut self.data_).write(data); } - pub unsafe fn move_from(&mut self, x: *mut MoveOnly) { - (&raw mut self.data_).write((*x).data_); - (*x).data_ = 0; - } pub unsafe fn get(&self) -> i32 { return self.data_; } } +impl MoveConstructibleUnsafe for MoveOnly { + unsafe fn move_constructor(&mut self, x: *mut MoveOnly) { + (&raw mut self.data_).write((*x).data_); + (*x).data_ = 0; + } +} pub unsafe fn make_move_only_2() -> MoveOnly { return { let mut __v: MoveOnly = ::zero_init(); @@ -102,7 +122,7 @@ unsafe fn main_0() -> i32 { let mut n: MoveOnly = (unsafe { (sc).unwrap()({ let mut __v: MoveOnly = ::zero_init(); - MoveOnly::move_from(&mut __v, { &mut m }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut m }); __v }) }); diff --git a/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs b/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs index 1d69da2fbb..4591740e50 100644 --- a/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs +++ b/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs @@ -19,7 +19,16 @@ pub unsafe fn via_size_t_return_3(mut b: u64) -> usize { return (b as usize); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct pair { pub a: i32, pub b: i32, diff --git a/tests/unit/out/unsafe/fn_ptr_vtable.rs b/tests/unit/out/unsafe/fn_ptr_vtable.rs index 250cedb781..3d73178885 100644 --- a/tests/unit/out/unsafe/fn_ptr_vtable.rs +++ b/tests/unit/out/unsafe/fn_ptr_vtable.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Vtable { pub create: Option *mut ::libc::c_void>, pub get: Option i32>, diff --git a/tests/unit/out/unsafe/fn_ref.rs b/tests/unit/out/unsafe/fn_ref.rs index c99ffe2a90..cc3c0559cb 100644 --- a/tests/unit/out/unsafe/fn_ref.rs +++ b/tests/unit/out/unsafe/fn_ref.rs @@ -22,7 +22,16 @@ pub unsafe fn call_forwarded_4(f: Option i32>, mut x: i32) -> return (unsafe { (f).unwrap()(x) }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 5810e7d54b..37f709250a 100644 --- a/tests/unit/out/unsafe/for_body_destructor.rs +++ b/tests/unit/out/unsafe/for_body_destructor.rs @@ -7,18 +7,20 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Guard { pub digit: i32, } impl Guard { - pub unsafe fn destructor(&mut self) { - (unsafe { libc::printf(c"%d ".as_ptr() as *const libc::c_char, (self.digit)) }); - } pub unsafe fn to_bool(&self) -> bool { return ((self.digit) != (0)); } } +impl DestructibleUnsafe for Guard { + unsafe fn destroy(&mut self) { + (unsafe { libc::printf(c"%d ".as_ptr() as *const libc::c_char, (self.digit)) }); + } +} pub unsafe fn step_0(i: *mut i32) { (unsafe { libc::printf(c"9 ".as_ptr() as *const libc::c_char) }); (*i).prefix_inc(); @@ -37,11 +39,11 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut first: Guard = Guard { digit: 1 }; let _dtor_first = std::mem::DropGuard::new(&raw mut first, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut second: Guard = Guard { digit: 2 }; let _dtor_second = std::mem::DropGuard::new(&raw mut second, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); if ((i) == (0)) { break 'for_body; @@ -57,7 +59,7 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut g: Guard = Guard { digit: 3 }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); break 'loop_; } @@ -71,7 +73,7 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut outer: Guard = Guard { digit: 4 }; let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); { let mut j: i32 = 0; @@ -80,7 +82,7 @@ unsafe fn main_0() -> i32 { let mut inner: Guard = Guard { digit: 5 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); if ((j) == (0)) { break 'for_body; @@ -102,13 +104,13 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut outer: Guard = Guard { digit: 4 }; let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut j: i32 = 0; 'loop_: while ((*j.prefix_inc()) < (3)) { let mut inner: Guard = Guard { digit: 5 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); if ((j) == (1)) { continue 'loop_; @@ -120,7 +122,7 @@ unsafe fn main_0() -> i32 { __do_while = false; let mut inner: Guard = Guard { digit: 6 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); continue 'loop_; } @@ -132,7 +134,7 @@ unsafe fn main_0() -> i32 { let mut value: i32 = (*value); let mut inner: Guard = Guard { digit: value }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); if ((value) == (1)) { continue 'loop_; @@ -150,7 +152,7 @@ unsafe fn main_0() -> i32 { 'loop_: loop { let mut condition: Guard = Guard { digit: i }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); if !(unsafe { Guard::to_bool(&condition) }) { break; @@ -158,7 +160,7 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut body: Guard = Guard { digit: 4 }; let _dtor_body = std::mem::DropGuard::new(&raw mut body, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); if ((i) == (2)) { break 'for_body; @@ -177,13 +179,13 @@ unsafe fn main_0() -> i32 { { let mut init: Guard = Guard { digit: 5 }; let _dtor_init = std::mem::DropGuard::new(&raw mut init, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); 'loop_: while ((i) < (2)) { 'for_body: { let mut body: Guard = Guard { digit: 6 }; let _dtor_body = std::mem::DropGuard::new(&raw mut body, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } (unsafe { step_0(&mut i) }); @@ -197,7 +199,7 @@ unsafe fn main_0() -> i32 { digit: (*j.prefix_inc()), }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); continue 'loop_; } diff --git a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs index f7ca6d019e..c5b7d9789d 100644 --- a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs @@ -8,18 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct S { pub v: Vec, pub a: i32, } -impl S { - pub unsafe fn move_from(&mut self, _a0: *mut S) { +impl MoveConstructibleUnsafe for S { + unsafe fn move_constructor(&mut self, _a0: *mut S) { (&raw mut self.v).write(std::mem::take(&mut (*_a0).v)); (&raw mut self.a).write((*_a0).a); } - pub unsafe fn move_assign(&mut self, _a0: *mut S) -> *mut S { +} +impl MoveAssignableUnsafe for S { + unsafe fn move_assign(&mut self, _a0: *mut S) -> *mut S { { self.v = std::mem::take(&mut (*_a0).v); }; diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 571d71b29a..983c52f2d5 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -10,7 +10,17 @@ pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Tracked { pub v: i32, @@ -23,12 +33,16 @@ impl Tracked { (&raw mut self.copies).write(0); (&raw mut self.moves).write(0); } - pub unsafe fn copy_from(&mut self, o: *const Tracked) { +} +impl CopyConstructibleUnsafe for Tracked { + unsafe fn copy_constructor(&mut self, o: *const Tracked) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } - pub unsafe fn move_from(&mut self, o: *mut Tracked) { +} +impl MoveConstructibleUnsafe for Tracked { + unsafe fn move_constructor(&mut self, o: *mut Tracked) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); @@ -39,7 +53,7 @@ impl Clone for Tracked { fn clone(&self) -> Self { unsafe { let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, self as *const Tracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Tracked); __v } } @@ -54,7 +68,7 @@ impl Holder { pub unsafe fn construct_1(&mut self, x: *mut Tracked) { (&raw mut self.t).write({ let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, { x }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { x }); __v }); } @@ -63,25 +77,35 @@ impl Holder { pub unsafe fn construct_2(&mut self, x: *mut Tracked) { (&raw mut self.t).write({ let mut __v: Tracked = ::zero_init(); - Tracked::move_from(&mut __v, { x }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { x }); __v }); } } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, )] #[cpp_from(Tracked, construct_1, mut_ptr)] #[cpp_from_move(Tracked, construct_2, ptr)] pub struct Holder { pub t: Tracked, } -impl Holder { - pub unsafe fn move_from(&mut self, _a0: *mut Holder) { +impl MoveConstructibleUnsafe for Holder { + unsafe fn move_constructor(&mut self, _a0: *mut Holder) { (&raw mut self.t).write({ let mut __v: Tracked = ::zero_init(); - Tracked::move_from(&mut __v, { &mut (*_a0).t }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).t }); __v }); } diff --git a/tests/unit/out/unsafe/forward_decltype.rs b/tests/unit/out/unsafe/forward_decltype.rs index cc34376dd2..35cdfddfe4 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -10,7 +10,17 @@ pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Tracked { pub v: i32, @@ -23,12 +33,16 @@ impl Tracked { (&raw mut self.copies).write(0); (&raw mut self.moves).write(0); } - pub unsafe fn copy_from(&mut self, o: *const Tracked) { +} +impl CopyConstructibleUnsafe for Tracked { + unsafe fn copy_constructor(&mut self, o: *const Tracked) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } - pub unsafe fn move_from(&mut self, o: *mut Tracked) { +} +impl MoveConstructibleUnsafe for Tracked { + unsafe fn move_constructor(&mut self, o: *mut Tracked) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); @@ -39,7 +53,7 @@ impl Clone for Tracked { fn clone(&self) -> Self { unsafe { let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, self as *const Tracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Tracked); __v } } diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index 561432313b..7a6a29b33c 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -12,7 +12,17 @@ pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Tracked { pub v: i32, @@ -25,12 +35,16 @@ impl Tracked { (&raw mut self.copies).write(0); (&raw mut self.moves).write(0); } - pub unsafe fn copy_from(&mut self, o: *const Tracked) { +} +impl CopyConstructibleUnsafe for Tracked { + unsafe fn copy_constructor(&mut self, o: *const Tracked) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } - pub unsafe fn move_from(&mut self, o: *mut Tracked) { +} +impl MoveConstructibleUnsafe for Tracked { + unsafe fn move_constructor(&mut self, o: *mut Tracked) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); @@ -41,7 +55,7 @@ impl Clone for Tracked { fn clone(&self) -> Self { unsafe { let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, self as *const Tracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Tracked); __v } } @@ -61,7 +75,7 @@ pub unsafe fn chosen_overload_3(_a0: *mut i32) -> Overload { pub unsafe fn copy_or_move_into_param_4(mut t: Tracked) -> Tracked { return { let mut __v: Tracked = ::zero_init(); - Tracked::move_from(&mut __v, { &mut t }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut t }); __v }; } @@ -91,7 +105,7 @@ unsafe fn main_0() -> i32 { let mut moved: Tracked = (unsafe { copy_or_move_into_param_4({ let mut __v: Tracked = ::zero_init(); - Tracked::move_from(&mut __v, { &mut b }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut b }); __v }) }); @@ -107,7 +121,7 @@ unsafe fn main_0() -> i32 { let mut copied: Tracked = (unsafe { copy_or_move_into_param_4({ let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, { &c }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); __v }) }); diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index 95c39c0261..b1caea64b6 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -12,7 +12,17 @@ pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Tracked { pub v: i32, @@ -25,12 +35,16 @@ impl Tracked { (&raw mut self.copies).write(0); (&raw mut self.moves).write(0); } - pub unsafe fn copy_from(&mut self, o: *const Tracked) { +} +impl CopyConstructibleUnsafe for Tracked { + unsafe fn copy_constructor(&mut self, o: *const Tracked) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } - pub unsafe fn move_from(&mut self, o: *mut Tracked) { +} +impl MoveConstructibleUnsafe for Tracked { + unsafe fn move_constructor(&mut self, o: *mut Tracked) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); @@ -41,7 +55,7 @@ impl Clone for Tracked { fn clone(&self) -> Self { unsafe { let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, self as *const Tracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Tracked); __v } } @@ -96,32 +110,43 @@ impl Pair { pub unsafe fn construct(&mut self, x: *mut Tracked, y: *mut Tracked) { (&raw mut self.a).write({ let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, { x }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { x }); __v }); (&raw mut self.b).write({ let mut __v: Tracked = ::zero_init(); - Tracked::move_from(&mut __v, { y }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { y }); __v }); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] pub struct Pair { pub a: Tracked, pub b: Tracked, } -impl Pair { - pub unsafe fn move_from(&mut self, _a0: *mut Pair) { +impl MoveConstructibleUnsafe for Pair { + unsafe fn move_constructor(&mut self, _a0: *mut Pair) { (&raw mut self.a).write({ let mut __v: Tracked = ::zero_init(); - Tracked::move_from(&mut __v, { &mut (*_a0).a }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).a }); __v }); (&raw mut self.b).write({ let mut __v: Tracked = ::zero_init(); - Tracked::move_from(&mut __v, { &mut (*_a0).b }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).b }); __v }); } diff --git a/tests/unit/out/unsafe/friend.rs b/tests/unit/out/unsafe/friend.rs index 0f563e6240..2cf436a218 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -19,7 +19,16 @@ pub unsafe fn scaled_3(v: *const V, mut k: f64) -> f64 { return (((*v).x as f64) * (k)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct V { pub x: i32, } @@ -33,7 +42,16 @@ pub unsafe fn get_4(w: *const W_int_) -> i32 { return (*w).x; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct W_int_ { pub x: i32, } @@ -41,12 +59,30 @@ pub unsafe fn get_5(w: *const W_long_) -> i64 { return (*w).x; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct W_long_ { pub x: i64, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 e3925aa83c..c8b7a2de0a 100644 --- a/tests/unit/out/unsafe/function_overloading.rs +++ b/tests/unit/out/unsafe/function_overloading.rs @@ -22,7 +22,16 @@ pub unsafe fn bar_4(x: *mut i32) -> i32 { return (*x); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Foo {} impl Foo { pub unsafe fn foo_1(&self) {} diff --git a/tests/unit/out/unsafe/global_call_temporaries.rs b/tests/unit/out/unsafe/global_call_temporaries.rs index d256027f66..7dec1b2bac 100644 --- a/tests/unit/out/unsafe/global_call_temporaries.rs +++ b/tests/unit/out/unsafe/global_call_temporaries.rs @@ -77,7 +77,16 @@ pub static mut call_assigned_6: std::cell::LazyCell = std::cell::LazyCell:: } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 774dfa61f5..fcc5912e85 100644 --- a/tests/unit/out/unsafe/global_init_side_effect.rs +++ b/tests/unit/out/unsafe/global_init_side_effect.rs @@ -8,7 +8,17 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct S {} impl S { diff --git a/tests/unit/out/unsafe/global_non_const_init.rs b/tests/unit/out/unsafe/global_non_const_init.rs index ca5bbaf708..beb3c2869a 100644 --- a/tests/unit/out/unsafe/global_non_const_init.rs +++ b/tests/unit/out/unsafe/global_non_const_init.rs @@ -28,7 +28,9 @@ pub static mut depends_on_call_6: std::cell::LazyCell = std::cell::LazyCell ((*std::cell::LazyCell::force_mut(&mut *&raw mut from_call_5)) + (1)) }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Ctor { pub v: i32, } @@ -81,7 +83,16 @@ pub static mut inline_member_11: std::cell::LazyCell = std::cell::LazyCell } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Holder {} pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { (unsafe { next_0() }) }); @@ -99,7 +110,9 @@ static mut local_ctor_14: std::cell::LazyCell = std::cell::LazyCell::new(| } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Singleton { pub hits: i32, } diff --git a/tests/unit/out/unsafe/global_pointers.rs b/tests/unit/out/unsafe/global_pointers.rs index 383073d278..c2a842b5a2 100644 --- a/tests/unit/out/unsafe/global_pointers.rs +++ b/tests/unit/out/unsafe/global_pointers.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Entry { pub name: *const libc::c_char, pub p: *mut i32, diff --git a/tests/unit/out/unsafe/global_without_initializer.rs b/tests/unit/out/unsafe/global_without_initializer.rs index fcf308d00a..b79958bf2d 100644 --- a/tests/unit/out/unsafe/global_without_initializer.rs +++ b/tests/unit/out/unsafe/global_without_initializer.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 f16513aa2b..9101602a1a 100644 --- a/tests/unit/out/unsafe/goto_aggregate_default.rs +++ b/tests/unit/out/unsafe/goto_aggregate_default.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Point { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/goto_cleanup.rs b/tests/unit/out/unsafe/goto_cleanup.rs index 23f9c2bf84..2712123684 100644 --- a/tests/unit/out/unsafe/goto_cleanup.rs +++ b/tests/unit/out/unsafe/goto_cleanup.rs @@ -77,7 +77,16 @@ pub unsafe fn from_switch_2(mut n: i32) -> i32 { panic!("ub: non-void function does not return a value") } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 a0401b093c..61ba808320 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct MinHeapNode { pub data: libc::c_char, pub freq: i32, @@ -40,7 +49,7 @@ pub unsafe fn Swap_0(a: *mut MinHeapNode, b: *mut MinHeapNode) { }; } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct MinHeap { pub size: i32, pub capacity: i32, @@ -234,14 +243,18 @@ impl MinHeap { } } } - pub unsafe fn move_from(&mut self, _a0: *mut MinHeap) { +} +impl MoveConstructibleUnsafe for MinHeap { + unsafe fn move_constructor(&mut self, _a0: *mut MinHeap) { (&raw mut self.size).write((*_a0).size); (&raw mut self.capacity).write((*_a0).capacity); (&raw mut self.arr).write((*_a0).arr.take()); (&raw mut self.next).write((*_a0).next); (&raw mut self.alloc).write((*_a0).alloc.take()); } - pub unsafe fn move_assign(&mut self, _a0: *mut MinHeap) -> *mut MinHeap { +} +impl MoveAssignableUnsafe for MinHeap { + unsafe fn move_assign(&mut self, _a0: *mut MinHeap) -> *mut MinHeap { self.size = (*_a0).size; self.capacity = (*_a0).capacity; { 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 1957ce4a35..a5a31f3f8c 100644 --- a/tests/unit/out/unsafe/immutable-deref-on-func-call.rs +++ b/tests/unit/out/unsafe/immutable-deref-on-func-call.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 75493d1304..ba3999f8da 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -8,16 +8,26 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Holder { pub v: Vec, } -impl Holder { - pub unsafe fn move_from(&mut self, _a0: *mut Holder) { +impl MoveConstructibleUnsafe for Holder { + unsafe fn move_constructor(&mut self, _a0: *mut Holder) { (&raw mut self.v).write(std::mem::take(&mut (*_a0).v)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { +} +impl MoveAssignableUnsafe for Holder { + unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { { self.v = std::mem::take(&mut (*_a0).v); }; diff --git a/tests/unit/out/unsafe/in_class_field_initializer.rs b/tests/unit/out/unsafe/in_class_field_initializer.rs index 7e89b20108..765346e6e6 100644 --- a/tests/unit/out/unsafe/in_class_field_initializer.rs +++ b/tests/unit/out/unsafe/in_class_field_initializer.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Inner { pub x: i32, pub y: i32, @@ -18,7 +20,9 @@ impl Default for Inner { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct S { pub a: i32, pub b: libc::c_char, @@ -38,7 +42,9 @@ impl Default for S { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Boxed_int_ { pub v: i32, pub tag: i32, diff --git a/tests/unit/out/unsafe/init.rs b/tests/unit/out/unsafe/init.rs index 76e510a3d2..725246c345 100644 --- a/tests/unit/out/unsafe/init.rs +++ b/tests/unit/out/unsafe/init.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 a25486b0e7..72295a1bee 100644 --- a/tests/unit/out/unsafe/init_list.rs +++ b/tests/unit/out/unsafe/init_list.rs @@ -8,13 +8,24 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn f_0(mut list: Vec) {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub a: i32, pub b: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Holder { pub p: Pair, } @@ -37,7 +48,9 @@ pub unsafe fn sum_1(p: *const Pair) -> i32 { return (((*p).a) + ((*p).b)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Seven { pub v: i32, } diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index aa743542bc..cc1ebc032a 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -8,22 +8,32 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Elem { pub id: i32, pub hist: [i32; 4], pub coeffs: Vec, } -impl Elem { - pub unsafe fn move_from(&mut self, _a0: *mut Elem) { +impl MoveConstructibleUnsafe for Elem { + unsafe fn move_constructor(&mut self, _a0: *mut Elem) { (&raw mut self.id).write((*_a0).id); (&raw mut self.hist).write(std::array::from_fn::<_, 4, _>(|__i: usize| { (*_a0).hist[(__i)] })); (&raw mut self.coeffs).write(std::mem::take(&mut (*_a0).coeffs)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Elem) -> *mut Elem { +} +impl MoveAssignableUnsafe for Elem { + unsafe fn move_assign(&mut self, _a0: *mut Elem) -> *mut Elem { self.id = (*_a0).id; { let mut __tmp_0 = { ((&mut self.hist as *mut [i32; 4]) as *mut ::libc::c_void) }; @@ -40,7 +50,16 @@ impl Elem { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, +)] pub struct State { pub count: i32, pub grid: [[i32; 3]; 2], @@ -48,8 +67,8 @@ pub struct State { pub elems: Vec, pub rows: Vec>, } -impl State { - pub unsafe fn move_from(&mut self, _a0: *mut State) { +impl MoveConstructibleUnsafe for State { + unsafe fn move_constructor(&mut self, _a0: *mut State) { (&raw mut self.count).write((*_a0).count); (&raw mut self.grid).write(std::array::from_fn::<_, 2, _>(|__i: usize| { std::array::from_fn::<_, 3, _>(|__i2: usize| (*_a0).grid[(__i)][(__i2)]) @@ -58,7 +77,9 @@ impl State { (&raw mut self.elems).write(std::mem::take(&mut (*_a0).elems)); (&raw mut self.rows).write(std::mem::take(&mut (*_a0).rows)); } - pub unsafe fn move_assign(&mut self, _a0: *mut State) -> *mut State { +} +impl MoveAssignableUnsafe for State { + unsafe fn move_assign(&mut self, _a0: *mut State) -> *mut State { self.count = (*_a0).count; { let mut __tmp_2 = { ((&mut self.grid as *mut [[i32; 3]; 2]) as *mut ::libc::c_void) }; @@ -71,7 +92,7 @@ impl State { }; { for __i in 0..3 { - *&mut self.arr[__i] = (*&mut (&mut (*_a0)).arr[__i]); + self.arr[__i].move_assign(&mut (&mut (*_a0)).arr[__i]); } }; { @@ -152,28 +173,32 @@ pub static mut moves_3: std::cell::LazyCell = std::cell::LazyCell::new(|| u pub static mut copy_assigns_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut move_assigns_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive( - VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CopyAssignUnsafe, MoveAssignUnsafe, -)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe)] pub struct Counted { pub v: i32, } -impl Counted { - pub unsafe fn copy_from(&mut self, o: *const Counted) { +impl CopyConstructibleUnsafe for Counted { + unsafe fn copy_constructor(&mut self, o: *const Counted) { (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)).prefix_inc(); } - pub unsafe fn move_from(&mut self, o: *mut Counted) { +} +impl MoveConstructibleUnsafe for Counted { + unsafe fn move_constructor(&mut self, o: *mut Counted) { (&raw mut self.v).write((*o).v); (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, o: *const Counted) -> *mut Counted { +} +impl CopyAssignableUnsafe for Counted { + unsafe fn copy_assign(&mut self, o: *const Counted) -> *mut Counted { self.v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_assigns_4)).prefix_inc(); return &mut (*(self as *mut Counted)); } - pub unsafe fn move_assign(&mut self, o: *mut Counted) -> *mut Counted { +} +impl MoveAssignableUnsafe for Counted { + unsafe fn move_assign(&mut self, o: *mut Counted) -> *mut Counted { self.v = (*o).v; (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_5)).prefix_inc(); @@ -184,7 +209,7 @@ impl Clone for Counted { fn clone(&self) -> Self { unsafe { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, self as *const Counted); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Counted); __v } } @@ -268,7 +293,7 @@ unsafe fn main_0() -> i32 { ); let mut moved: State = { let mut __v: State = ::zero_init(); - State::move_from(&mut __v, { &mut t }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut t }); __v }; assert!( @@ -278,7 +303,7 @@ unsafe fn main_0() -> i32 { assert!((((moved.elems.len()) == (4_usize)) && (t.elems.is_empty())) && (t.rows.is_empty())); assert!(((moved.arr[(1_usize)]) == (7)) && ((t.arr[(1_usize)]) == (7))); let mut assigned: State = ::default(); - (unsafe { State::move_assign(&mut assigned, &mut moved) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut assigned, &mut moved) }); assert!( ((assigned.grid[(0) as usize][(0) as usize]) == (100)) && ((assigned.grid[(1) as usize][(1) as usize]) == (4)) @@ -289,8 +314,14 @@ unsafe fn main_0() -> i32 { assert!(((assigned.arr[(1_usize)]) == (7)) && ((moved.arr[(1_usize)]) == (7))); let mut ca: [Counted; 3] = std::array::from_fn::<_, 3, _>(|_| ::default()); ca[(1_usize)].v = 5; - let mut cb: [Counted; 3] = - std::array::from_fn(|__i| ::move_ctor(&mut ca[__i])); + let mut cb: [Counted; 3] = { + let mut __v = std::mem::MaybeUninit::<[Counted; 3]>::uninit(); + let __p = __v.as_mut_ptr() as *mut Counted; + for __i in 0..3 { + (*__p.add(__i)).move_constructor(&mut ca[__i]); + } + __v.assume_init() + }; assert!( ((((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (3)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) @@ -307,7 +338,7 @@ unsafe fn main_0() -> i32 { cc[(2_usize)].v = 8; { for __i in 0..3 { - (*&mut cb[__i]).copy_assign(&cc[__i]); + cb[__i].copy_assign(&cc[__i]); } }; assert!( @@ -317,7 +348,7 @@ unsafe fn main_0() -> i32 { ); { for __i in 0..3 { - (*&mut ca[__i]).move_assign(&mut cb[__i]); + ca[__i].move_assign(&mut cb[__i]); } }; assert!( @@ -335,13 +366,19 @@ unsafe fn main_0() -> i32 { let __a1 = 1; va[(0_usize)].push(__a1) }; - let mut vb: [Vec; 2] = - std::array::from_fn(|__i| as MoveCtorUnsafe>::move_ctor(&mut va[__i])); + let mut vb: [Vec; 2] = { + let mut __v = std::mem::MaybeUninit::<[Vec; 2]>::uninit(); + let __p = __v.as_mut_ptr() as *mut Vec; + for __i in 0..2 { + (*__p.add(__i)).move_constructor(&mut va[__i]); + } + __v.assume_init() + }; assert!(((vb[(0_usize)].len()) == (1_usize)) && (va[(0_usize)].is_empty())); let mut vc: [Vec; 2] = std::array::from_fn::<_, 2, _>(|_| Default::default()); { for __i in 0..2 { - *&mut vc[__i] = as MoveCtorUnsafe>::move_ctor(&mut vb[__i]); + vc[__i].move_assign(&mut vb[__i]); } }; assert!(((vc[(0_usize)].len()) == (1_usize)) && (vb[(0_usize)].is_empty())); diff --git a/tests/unit/out/unsafe/kruskal.rs b/tests/unit/out/unsafe/kruskal.rs index 5dc49ca0bf..76ae5d42e0 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Edge { pub u: i32, pub v: i32, @@ -164,7 +173,7 @@ pub unsafe fn quicksort_1(arr: *mut Option>, mut start: i32, mut end (unsafe { quicksort_1(arr, ((p) + (1)), end) }); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct DisjointSet { pub rank: Option>, pub parent: Option>, @@ -274,12 +283,16 @@ impl DisjointSet { + (1)); } } - pub unsafe fn move_from(&mut self, _a0: *mut DisjointSet) { +} +impl MoveConstructibleUnsafe for DisjointSet { + unsafe fn move_constructor(&mut self, _a0: *mut DisjointSet) { (&raw mut self.rank).write((*_a0).rank.take()); (&raw mut self.parent).write((*_a0).parent.take()); (&raw mut self.n).write((*_a0).n); } - pub unsafe fn move_assign(&mut self, _a0: *mut DisjointSet) -> *mut DisjointSet { +} +impl MoveAssignableUnsafe for DisjointSet { + unsafe fn move_assign(&mut self, _a0: *mut DisjointSet) -> *mut DisjointSet { { self.rank = (*_a0).rank.take(); }; @@ -291,19 +304,21 @@ impl DisjointSet { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct Graph { pub edges: Option>, pub V: i32, pub E: i32, } -impl Graph { - pub unsafe fn move_from(&mut self, _a0: *mut Graph) { +impl MoveConstructibleUnsafe for Graph { + unsafe fn move_constructor(&mut self, _a0: *mut Graph) { (&raw mut self.edges).write((*_a0).edges.take()); (&raw mut self.V).write((*_a0).V); (&raw mut self.E).write((*_a0).E); } - pub unsafe fn move_assign(&mut self, _a0: *mut Graph) -> *mut Graph { +} +impl MoveAssignableUnsafe for Graph { + unsafe fn move_assign(&mut self, _a0: *mut Graph) -> *mut Graph { { self.edges = (*_a0).edges.take(); }; diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index 3dada1c532..f7a11ca47a 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -7,12 +7,12 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { pub f: FnPtr, } -impl Guard__lambda_at_lambda_as_field_cpp_34_13__ { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_34_13__ { + unsafe fn destroy(&mut self) { (unsafe { self.f.call() }); } } @@ -28,17 +28,17 @@ impl Default for Guard__lambda_at_lambda_as_field_cpp_34_13__ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { pub f: FnPtr, } -impl Guard__lambda_at_lambda_as_field_cpp_45_13__ { - pub unsafe fn destructor(&mut self) { +impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_45_13__ { + unsafe fn destroy(&mut self) { (unsafe { self.f.call() }); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe)] pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { pub f: FnPtr i32>, pub calls: i32, @@ -64,7 +64,9 @@ impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { pub f: FnPtr i32>, pub calls: i32, @@ -76,7 +78,7 @@ impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe)] #[cpp_from(FnPtr i32 > , construct, value)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { pub f: FnPtr i32>, @@ -87,7 +89,9 @@ impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { (&raw mut self.f).write(f.copy_from()); (&raw mut self.moves).write(0); } - pub unsafe fn move_from(&mut self, o: *mut Moving__lambda_at_lambda_as_field_cpp_64_12__) { +} +impl MoveConstructibleUnsafe for Moving__lambda_at_lambda_as_field_cpp_64_12__ { + unsafe fn move_constructor(&mut self, o: *mut Moving__lambda_at_lambda_as_field_cpp_64_12__) { (&raw mut self.f).write((*o).f.move_from()); (&raw mut self.moves).write((((*o).moves) + (1))); } @@ -133,7 +137,7 @@ unsafe fn main_0() -> i32 { }), }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_0)) == (0))); } @@ -163,7 +167,7 @@ unsafe fn main_0() -> i32 { ), }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!(((cleaned) == (0))); } @@ -214,7 +218,7 @@ unsafe fn main_0() -> i32 { let mut m2: Moving__lambda_at_lambda_as_field_cpp_64_12__ = { let mut __v: Moving__lambda_at_lambda_as_field_cpp_64_12__ = ::zero_init(); - Moving__lambda_at_lambda_as_field_cpp_64_12__::move_from(&mut __v, { &mut m }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut m }); __v }; assert!(((unsafe { m2.f.call(3,) }) == (6))); diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index 96a97ceea8..fbe1ed3d28 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.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(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, +)] pub struct Counted { pub copies: i32, pub moves: i32, @@ -17,11 +25,15 @@ impl Counted { (&raw mut self.copies).write(0); (&raw mut self.moves).write(0); } - pub unsafe fn copy_from(&mut self, o: *const Counted) { +} +impl CopyConstructibleUnsafe for Counted { + unsafe fn copy_constructor(&mut self, o: *const Counted) { (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } - pub unsafe fn move_from(&mut self, o: *mut Counted) { +} +impl MoveConstructibleUnsafe for Counted { + unsafe fn move_constructor(&mut self, o: *mut Counted) { (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); } @@ -30,7 +42,7 @@ impl Clone for Counted { fn clone(&self) -> Self { unsafe { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, self as *const Counted); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Counted); __v } } @@ -48,13 +60,26 @@ impl Default for Counted { } pub static mut drops_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, DestructibleUnsafe)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, +)] pub struct Dropped {} impl Dropped { pub unsafe fn construct(&mut self) {} - pub unsafe fn copy_from(&mut self, _a0: *const Dropped) {} - pub unsafe fn move_from(&mut self, _a0: *mut Dropped) {} - pub unsafe fn destructor(&mut self) { +} +impl CopyConstructibleUnsafe for Dropped { + unsafe fn copy_constructor(&mut self, _a0: *const Dropped) {} +} +impl MoveConstructibleUnsafe for Dropped { + unsafe fn move_constructor(&mut self, _a0: *mut Dropped) {} +} +impl DestructibleUnsafe for Dropped { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)).postfix_inc(); } } @@ -62,7 +87,7 @@ impl Clone for Dropped { fn clone(&self) -> Self { unsafe { let mut __v: Dropped = ::zero_init(); - Dropped::copy_from(&mut __v, self as *const Dropped); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Dropped); __v } } @@ -94,7 +119,7 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, { &c }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); __v }; }, @@ -113,14 +138,14 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, { &c }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); __v }; }, || -> Counted { return { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, { &c }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); __v }; } @@ -138,7 +163,7 @@ unsafe fn main_0() -> i32 { { let arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|__i: usize| { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, { &arr[(__i)] }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &arr[(__i)] }); __v }); }, @@ -163,11 +188,11 @@ unsafe fn main_0() -> i32 { || {} ); let _dtor_m = std::mem::DropGuard::new(&raw mut m, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut m2: FnPtr = m.move_from(); let _dtor_m2 = std::mem::DropGuard::new(&raw mut m2, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (2))); @@ -183,11 +208,11 @@ unsafe fn main_0() -> i32 { || {} ); let _dtor_k = std::mem::DropGuard::new(&raw mut k, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut k2: FnPtr = k.copy_from(); let _dtor_k2 = std::mem::DropGuard::new(&raw mut k2, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (4))); @@ -203,7 +228,7 @@ unsafe fn main_0() -> i32 { || {} ); let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut outer: FnPtr = lambda_unsafe!( { @@ -212,7 +237,7 @@ unsafe fn main_0() -> i32 { || {} ); let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (6))); diff --git a/tests/unit/out/unsafe/lambda_capture_ref.rs b/tests/unit/out/unsafe/lambda_capture_ref.rs index 3d87b57384..1685860930 100644 --- a/tests/unit/out/unsafe/lambda_capture_ref.rs +++ b/tests/unit/out/unsafe/lambda_capture_ref.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/lambda_capture_star_this.rs b/tests/unit/out/unsafe/lambda_capture_star_this.rs index d35f3f26d7..dae883e98c 100644 --- a/tests/unit/out/unsafe/lambda_capture_star_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_star_this.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 324c3fdfce..5aa1013497 100644 --- a/tests/unit/out/unsafe/lambda_capture_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_this.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub n: i32, pub step: i32, diff --git a/tests/unit/out/unsafe/lambda_capture_value.rs b/tests/unit/out/unsafe/lambda_capture_value.rs index 72d0840e72..b6083ad486 100644 --- a/tests/unit/out/unsafe/lambda_capture_value.rs +++ b/tests/unit/out/unsafe/lambda_capture_value.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/lambda_decltype_type.rs b/tests/unit/out/unsafe/lambda_decltype_type.rs index 8687ec472c..9ea037c436 100644 --- a/tests/unit/out/unsafe/lambda_decltype_type.rs +++ b/tests/unit/out/unsafe/lambda_decltype_type.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { pub items: [i32; 4], pub size: i32, @@ -45,7 +45,7 @@ impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { pub items: [i32; 4], pub size: i32, diff --git a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs b/tests/unit/out/unsafe/lambda_generic_explicit_args.rs index 299ff8311f..76d3641c9a 100644 --- a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs +++ b/tests/unit/out/unsafe/lambda_generic_explicit_args.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 08b7779573..5b07f0316b 100644 --- a/tests/unit/out/unsafe/lambda_immediate_init.rs +++ b/tests/unit/out/unsafe/lambda_immediate_init.rs @@ -10,7 +10,9 @@ pub unsafe fn pick_0(mut x: i32) -> i32 { return x; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct S { pub j: i32, pub k: i32, diff --git a/tests/unit/out/unsafe/lambda_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index 24919581ed..5002c46ca7 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -7,9 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, DestructibleUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct Owner { pub p: *mut i32, @@ -18,24 +16,14 @@ impl Owner { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.p).write((Box::leak(Box::new(v)) as *mut i32)); } - pub unsafe fn move_from(&mut self, o: *mut Owner) { - (&raw mut self.p).write((*o).p); - (*o).p = std::ptr::null_mut(); - } - pub unsafe fn destructor(&mut self) { - { - let __p = self.p; - if !__p.is_null() { - ::std::mem::drop(Box::from_raw(__p)) - } - }; - } pub unsafe fn take(&mut self) -> FnPtr i32> { return lambda_unsafe!( { let self_: Owner = { let mut __v: Owner = ::zero_init(); - Owner::move_from(&mut __v, { &mut (*(self as *mut Owner)) }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { + &mut (*(self as *mut Owner)) + }); __v }; }, @@ -45,6 +33,22 @@ impl Owner { ); } } +impl MoveConstructibleUnsafe for Owner { + unsafe fn move_constructor(&mut self, o: *mut Owner) { + (&raw mut self.p).write((*o).p); + (*o).p = std::ptr::null_mut(); + } +} +impl DestructibleUnsafe for Owner { + unsafe fn destroy(&mut self) { + { + let __p = self.p; + if !__p.is_null() { + ::std::mem::drop(Box::from_raw(__p)) + } + }; + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -58,13 +62,13 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut f: FnPtr i32> = lambda_unsafe!( { let h: Owner = { let mut __v: Owner = ::zero_init(); - Owner::move_from(&mut __v, { &mut o }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut o }); __v }; }, @@ -73,13 +77,13 @@ unsafe fn main_0() -> i32 { } ); let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!((o.p).is_null()); assert!(((unsafe { f.call() }) == (5))); let mut g: FnPtr i32> = f.move_from(); let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!(((unsafe { g.call() }) == (5))); let mut total: i32 = 0; @@ -98,7 +102,7 @@ unsafe fn main_0() -> i32 { } ); let _dtor_consume = std::mem::DropGuard::new(&raw mut consume, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); (unsafe { consume.call() }); (unsafe { consume.call() }); @@ -109,11 +113,11 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_o2 = std::mem::DropGuard::new(&raw mut o2, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut t: FnPtr i32> = (unsafe { Owner::take(&mut o2) }); let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!((o2.p).is_null()); assert!(((unsafe { t.call() }) == (9))); diff --git a/tests/unit/out/unsafe/lambda_nested.rs b/tests/unit/out/unsafe/lambda_nested.rs index fc5e249862..2a114684a1 100644 --- a/tests/unit/out/unsafe/lambda_nested.rs +++ b/tests/unit/out/unsafe/lambda_nested.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 00c32d0d0d..3509967e9d 100644 --- a/tests/unit/out/unsafe/lambda_static_local.rs +++ b/tests/unit/out/unsafe/lambda_static_local.rs @@ -68,7 +68,16 @@ static mut n_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { static mut calls_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); static mut calls_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct P_4 { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/libc_struct_without_default.rs b/tests/unit/out/unsafe/libc_struct_without_default.rs index 6467e8c51f..b549b89754 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -7,20 +7,31 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, +)] pub struct UserDefined { pub a: [i32; 1], pub v: Vec, } -impl UserDefined { - pub unsafe fn move_from(&mut self, _a0: *mut UserDefined) { +impl MoveConstructibleUnsafe for UserDefined { + unsafe fn move_constructor(&mut self, _a0: *mut UserDefined) { (&raw mut self.a).write((*_a0).a.clone()); (&raw mut self.v).write(std::mem::take(&mut (*_a0).v)); } - pub unsafe fn move_assign(&mut self, _a0: *mut UserDefined) -> *mut UserDefined { +} +impl MoveAssignableUnsafe for UserDefined { + unsafe fn move_assign(&mut self, _a0: *mut UserDefined) -> *mut UserDefined { { for __i in 0..1 { - *&mut self.a[__i] = (*&mut (&mut (*_a0)).a[__i]); + self.a[__i].move_assign(&mut (&mut (*_a0)).a[__i]); } }; { @@ -40,7 +51,9 @@ impl Default for UserDefined { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct FieldIsLibcType { pub addr: libc::sockaddr, } diff --git a/tests/unit/out/unsafe/linked_list.rs b/tests/unit/out/unsafe/linked_list.rs index 211ccf73ed..371dd6530f 100644 --- a/tests/unit/out/unsafe/linked_list.rs +++ b/tests/unit/out/unsafe/linked_list.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Node { pub val: i32, pub next: *mut Node, diff --git a/tests/unit/out/unsafe/local_anon_struct_collision.rs b/tests/unit/out/unsafe/local_anon_struct_collision.rs index 97456f247e..b144e4e780 100644 --- a/tests/unit/out/unsafe/local_anon_struct_collision.rs +++ b/tests/unit/out/unsafe/local_anon_struct_collision.rs @@ -13,7 +13,16 @@ pub unsafe fn first_0() -> i32 { return ((p.x) + (p.y)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_1 { pub x: i32, pub y: i32, @@ -25,7 +34,16 @@ pub unsafe fn second_2() -> i32 { return (((q.a) + (q.b)) as i32); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_3 { pub a: i64, pub b: i64, diff --git a/tests/unit/out/unsafe/local_record_template.rs b/tests/unit/out/unsafe/local_record_template.rs index 6e8b5cc30d..79539375cd 100644 --- a/tests/unit/out/unsafe/local_record_template.rs +++ b/tests/unit/out/unsafe/local_record_template.rs @@ -30,12 +30,30 @@ pub unsafe fn wrap_10(mut v: i64) -> i32 { return (unsafe { get_6(l) }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Local_5 { pub x: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Local_7 { pub x: i64, } @@ -44,7 +62,16 @@ pub unsafe fn other_11() -> i32 { return ((unsafe { get_0(l) }) + (l.y as i32)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Local_1 { pub x: i64, pub y: i64, @@ -65,7 +92,16 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 53348c3337..dbbd091e90 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -13,7 +13,9 @@ pub unsafe fn bar_1(x: *mut u32) { (*x) = (*x).wrapping_add(1_u32); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Point { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 6c24884584..72eaf9eb27 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -10,7 +10,17 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut made_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Key { pub k: i32, @@ -19,17 +29,21 @@ impl Key { pub unsafe fn construct(&mut self, mut k: i32) { (&raw mut self.k).write(k); } - pub unsafe fn copy_from(&mut self, o: *const Key) { + pub unsafe fn operator_lt(&self, o: *const Key) -> bool { + return ((self.k) < ((*o).k)); + } +} +impl CopyConstructibleUnsafe for Key { + unsafe fn copy_constructor(&mut self, o: *const Key) { (&raw mut self.k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } - pub unsafe fn move_from(&mut self, o: *mut Key) { +} +impl MoveConstructibleUnsafe for Key { + unsafe fn move_constructor(&mut self, o: *mut Key) { (&raw mut self.k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); } - pub unsafe fn operator_lt(&self, o: *const Key) -> bool { - return ((self.k) < ((*o).k)); - } } impl std::cmp::Ord for Key { fn cmp(&self, other: &Self) -> std::cmp::Ordering { @@ -62,7 +76,7 @@ impl Clone for Key { fn clone(&self) -> Self { unsafe { let mut __v: Key = ::zero_init(); - Key::copy_from(&mut __v, self as *const Key); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Key); __v } } diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index 7f46f2cfa0..824fd3e5e7 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -9,7 +9,16 @@ use std::rc::Rc; pub static mut default_constructions_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Key { pub order: i32, pub identity: i32, @@ -45,7 +54,9 @@ pub unsafe fn operator_eq_2(a: *const Key, b: *const Key) -> bool { return (((*a).identity) == ((*b).identity)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Mapped { pub value: i32, } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 6ac3acbe5a..124713c4ee 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -11,7 +11,16 @@ pub static mut made_1: std::cell::LazyCell = std::cell::LazyCell::new(|| un pub static mut copies_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moves_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, +)] #[cpp_from(i32, construct_1, value)] pub struct Item { pub value: i32, @@ -24,11 +33,15 @@ impl Item { (&raw mut self.value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); } - pub unsafe fn copy_from(&mut self, other: *const Item) { +} +impl CopyConstructibleUnsafe for Item { + unsafe fn copy_constructor(&mut self, other: *const Item) { (&raw mut self.value).write((*other).value); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)).prefix_inc(); } - pub unsafe fn move_from(&mut self, other: *mut Item) { +} +impl MoveConstructibleUnsafe for Item { + unsafe fn move_constructor(&mut self, other: *mut Item) { (&raw mut self.value).write((*other).value); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); (*other).value = -1_i32; @@ -38,7 +51,7 @@ impl Clone for Item { fn clone(&self) -> Self { unsafe { let mut __v: Item = ::zero_init(); - Item::copy_from(&mut __v, self as *const Item); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Item); __v } } @@ -59,7 +72,9 @@ pub unsafe fn argument_4(item: *mut Item) -> *mut Item { return item; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct RefItem { pub value: i32, } @@ -271,7 +286,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_6,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::copy_from(&mut __v, { __tmp_6 }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { __tmp_6 }); __v }), }; @@ -287,7 +302,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_7,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::move_from(&mut __v, { __tmp_7 }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { __tmp_7 }); __v }), }; @@ -304,7 +319,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_8,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::copy_from(&mut __v, { __tmp_8 }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { __tmp_8 }); __v }), }; @@ -321,7 +336,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_9,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::move_from(&mut __v, { __tmp_9 }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { __tmp_9 }); __v }), }; @@ -399,7 +414,7 @@ unsafe fn main_0() -> i32 { { (__tmp_12,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::move_from(&mut __v, { __tmp_12 }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { __tmp_12 }); __v }), } @@ -426,7 +441,7 @@ unsafe fn main_0() -> i32 { { (__tmp_14,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::move_from(&mut __v, { __tmp_14 }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { __tmp_14 }); __v }), } diff --git a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs index 3543262da1..a5ba9bb38f 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -9,7 +9,9 @@ use std::rc::Rc; pub static mut made_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut visits_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Item { pub value: i32, } @@ -47,7 +49,9 @@ pub unsafe fn place_3(n: *mut i32) -> *mut i32 { pub static mut temporary_calls_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Temporary { pub n: i32, pub data: [i32; 2], @@ -71,7 +75,16 @@ impl Default for Temporary { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Nested { pub inner: Temporary, } @@ -86,7 +99,7 @@ pub unsafe fn make_nested_6() -> Nested { return ::default(); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe)] pub struct Owner { pub ptr: Option>, } @@ -104,10 +117,14 @@ impl Owner { })) .n; } - pub unsafe fn move_from(&mut self, _a0: *mut Owner) { +} +impl MoveConstructibleUnsafe for Owner { + unsafe fn move_constructor(&mut self, _a0: *mut Owner) { (&raw mut self.ptr).write((*_a0).ptr.take()); } - pub unsafe fn move_assign(&mut self, _a0: *mut Owner) -> *mut Owner { +} +impl MoveAssignableUnsafe for Owner { + unsafe fn move_assign(&mut self, _a0: *mut Owner) -> *mut Owner { { self.ptr = (*_a0).ptr.take(); }; @@ -126,7 +143,7 @@ impl Default for Owner { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] pub struct Noncopy { pub n: i32, } @@ -136,7 +153,16 @@ impl Default for Noncopy { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, +)] #[cpp_from(i32, construct_1, ptr)] pub struct Held { pub ptr: *const i32, diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index ba4bdc0a23..04d843a1e7 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -17,7 +17,15 @@ pub unsafe fn pick_3(mut i: i32) -> *mut i32 { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut xs_1))[(i) as usize]; } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + MovableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Bag { pub n: i32, @@ -26,11 +34,15 @@ impl Bag { pub unsafe fn construct(&mut self, mut n: i32) { (&raw mut self.n).write(n); } - pub unsafe fn copy_from(&mut self, o: *const Bag) { +} +impl CopyConstructibleUnsafe for Bag { + unsafe fn copy_constructor(&mut self, o: *const Bag) { (&raw mut self.n).write((*o).n); (*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, _a0: *const Bag) -> *mut Bag { +} +impl CopyAssignableUnsafe for Bag { + unsafe fn copy_assign(&mut self, _a0: *const Bag) -> *mut Bag { self.n = (*_a0).n; return &mut (*(self as *mut Bag)); } @@ -66,7 +78,7 @@ impl Clone for Bag { fn clone(&self) -> Self { unsafe { let mut __v: Bag = ::zero_init(); - Bag::copy_from(&mut __v, self as *const Bag); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Bag); __v } } diff --git a/tests/unit/out/unsafe/memcpy_struct_bytes.rs b/tests/unit/out/unsafe/memcpy_struct_bytes.rs index 1e1546550b..e8fd1940fd 100644 --- a/tests/unit/out/unsafe/memcpy_struct_bytes.rs +++ b/tests/unit/out/unsafe/memcpy_struct_bytes.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct point { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/memcpy_struct_layouts.rs b/tests/unit/out/unsafe/memcpy_struct_layouts.rs index e8b124bb5a..6ed39f84e4 100644 --- a/tests/unit/out/unsafe/memcpy_struct_layouts.rs +++ b/tests/unit/out/unsafe/memcpy_struct_layouts.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct packed { pub a: i32, pub b: libc::c_char, @@ -15,26 +24,62 @@ pub struct packed { pub d: i16, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct reordered { pub a: libc::c_char, pub b: i32, pub c: libc::c_char, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct tail { pub a: libc::c_char, pub b: f64, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct nested { pub t: tail, pub c: libc::c_char, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct array { pub name: [libc::c_char; 3], pub x: i32, diff --git a/tests/unit/out/unsafe/memcpy_struct_struct.rs b/tests/unit/out/unsafe/memcpy_struct_struct.rs index aa5d26b764..d58f77c503 100644 --- a/tests/unit/out/unsafe/memcpy_struct_struct.rs +++ b/tests/unit/out/unsafe/memcpy_struct_struct.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Entry { pub bits: u8, pub value: u16, diff --git a/tests/unit/out/unsafe/memset_struct_tail.rs b/tests/unit/out/unsafe/memset_struct_tail.rs index a15533127c..84ea69f2e4 100644 --- a/tests/unit/out/unsafe/memset_struct_tail.rs +++ b/tests/unit/out/unsafe/memset_struct_tail.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub keep: i32, pub a: i32, diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index 14fa537b99..28aef3b3a6 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -8,7 +8,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, MoveAssignUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, Default, )] #[cpp_from(i32, construct, value)] pub struct MoveOnly { @@ -18,11 +18,15 @@ impl MoveOnly { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn move_from(&mut self, o: *mut MoveOnly) { +} +impl MoveConstructibleUnsafe for MoveOnly { + unsafe fn move_constructor(&mut self, o: *mut MoveOnly) { (&raw mut self.v).write((*o).v); (*o).v = 0; } - pub unsafe fn move_assign(&mut self, o: *mut MoveOnly) -> *mut MoveOnly { +} +impl MoveAssignableUnsafe for MoveOnly { + unsafe fn move_assign(&mut self, o: *mut MoveOnly) -> *mut MoveOnly { if ((self as *mut MoveOnly) == (o)) { return &mut (*(self as *mut MoveOnly)); } @@ -32,7 +36,7 @@ impl MoveOnly { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] pub struct ConstMoveAssign { pub mark: i32, } @@ -68,7 +72,7 @@ pub unsafe fn make_0(mut v: i32) -> MoveOnly { }; return { let mut __v: MoveOnly = ::zero_init(); - MoveOnly::move_from(&mut __v, { &mut m }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut m }); __v }; } @@ -94,7 +98,7 @@ unsafe fn main_0() -> i32 { MoveOnly::construct(&mut __v, { 3 }); __v }; - (unsafe { MoveOnly::move_assign(&mut a, &mut b) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut a, &mut b) }); assert!(((a.v) == (2))); assert!(((b.v) == (0))); (unsafe { @@ -103,12 +107,12 @@ unsafe fn main_0() -> i32 { MoveOnly::construct(&mut __v, { 3 }); __v }; - MoveOnly::move_assign(&mut b, &mut _o) + MoveAssignableUnsafe::move_assign(&mut b, &mut _o) }); (unsafe { - MoveOnly::move_assign( + MoveAssignableUnsafe::move_assign( &mut c, - &mut (*(unsafe { MoveOnly::move_assign(&mut a, &mut b) })), + &mut (*(unsafe { MoveAssignableUnsafe::move_assign(&mut a, &mut b) })), ) }); assert!((((b.v) == (0)) && ((a.v) == (0))) && ((c.v) == (3))); @@ -118,17 +122,17 @@ unsafe fn main_0() -> i32 { MoveOnly::construct(&mut __v, { 5 }); __v }; - MoveOnly::move_assign(&mut a, &mut _o) + MoveAssignableUnsafe::move_assign(&mut a, &mut _o) }); assert!(((a.v) == (5))); (unsafe { let mut _o: MoveOnly = (unsafe { make_0(6) }); - MoveOnly::move_assign(&mut a, &mut _o) + MoveAssignableUnsafe::move_assign(&mut a, &mut _o) }); assert!(((a.v) == (6))); (unsafe { let _o: *mut MoveOnly = &mut a; - MoveOnly::move_assign(&mut a, _o) + MoveAssignableUnsafe::move_assign(&mut a, _o) }); assert!(((a.v) == (6))); let mut vec_: Vec = Vec::new(); @@ -145,7 +149,7 @@ unsafe fn main_0() -> i32 { MoveOnly::construct(&mut __v, { 8 }); __v }; - (unsafe { MoveOnly::move_assign(&mut vec_[(0_usize)], &mut d) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut vec_[(0_usize)], &mut d) }); assert!(((vec_[(0_usize)].v) == (8))); assert!(((d.v) == (0))); let mut m: ConstMoveAssign = { diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index d86400308c..334a41f233 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct MoveOnly { pub v: i32, @@ -16,13 +16,15 @@ impl MoveOnly { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn move_from(&mut self, o: *mut MoveOnly) { +} +impl MoveConstructibleUnsafe for MoveOnly { + unsafe fn move_constructor(&mut self, o: *mut MoveOnly) { (&raw mut self.v).write((*o).v); (*o).v = 0; } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] pub struct ConstMove { pub mark: i32, } @@ -49,7 +51,17 @@ impl Default for ConstMove { } } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct ThrowingMove { pub v: i32, @@ -62,12 +74,16 @@ impl ThrowingMove { (&raw mut self.copies).write(0); (&raw mut self.moves).write(0); } - pub unsafe fn copy_from(&mut self, o: *const ThrowingMove) { +} +impl CopyConstructibleUnsafe for ThrowingMove { + unsafe fn copy_constructor(&mut self, o: *const ThrowingMove) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } - pub unsafe fn move_from(&mut self, o: *mut ThrowingMove) { +} +impl MoveConstructibleUnsafe for ThrowingMove { + unsafe fn move_constructor(&mut self, o: *mut ThrowingMove) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); @@ -78,13 +94,23 @@ impl Clone for ThrowingMove { fn clone(&self) -> Self { unsafe { let mut __v: ThrowingMove = ::zero_init(); - ThrowingMove::copy_from(&mut __v, self as *const ThrowingMove); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const ThrowingMove); __v } } } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct NoexceptMove { pub v: i32, @@ -97,12 +123,16 @@ impl NoexceptMove { (&raw mut self.copies).write(0); (&raw mut self.moves).write(0); } - pub unsafe fn copy_from(&mut self, o: *const NoexceptMove) { +} +impl CopyConstructibleUnsafe for NoexceptMove { + unsafe fn copy_constructor(&mut self, o: *const NoexceptMove) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } - pub unsafe fn move_from(&mut self, o: *mut NoexceptMove) { +} +impl MoveConstructibleUnsafe for NoexceptMove { + unsafe fn move_constructor(&mut self, o: *mut NoexceptMove) { (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); @@ -113,7 +143,7 @@ impl Clone for NoexceptMove { fn clone(&self) -> Self { unsafe { let mut __v: NoexceptMove = ::zero_init(); - NoexceptMove::copy_from(&mut __v, self as *const NoexceptMove); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const NoexceptMove); __v } } @@ -129,7 +159,7 @@ pub unsafe fn make_1(mut v: i32) -> MoveOnly { }; return { let mut __v: MoveOnly = ::zero_init(); - MoveOnly::move_from(&mut __v, { &mut m }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut m }); __v }; } @@ -147,21 +177,21 @@ unsafe fn main_0() -> i32 { }; let mut b: MoveOnly = { let mut __v: MoveOnly = ::zero_init(); - MoveOnly::move_from(&mut __v, { &mut a }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut a }); __v }; assert!(((b.v) == (1))); assert!(((a.v) == (0))); let mut c: MoveOnly = { let mut __v: MoveOnly = ::zero_init(); - MoveOnly::move_from(&mut __v, { &mut b }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut b }); __v }; assert!(((c.v) == (1))); assert!(((b.v) == (0))); let mut d: MoveOnly = { let mut __v: MoveOnly = ::zero_init(); - MoveOnly::move_from(&mut __v, { &mut c }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut c }); __v }; assert!(((d.v) == (1))); @@ -181,7 +211,7 @@ unsafe fn main_0() -> i32 { ((unsafe { by_value_0({ let mut __v: MoveOnly = ::zero_init(); - MoveOnly::move_from(&mut __v, { &mut e }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut e }); __v }) }) == (5)) @@ -204,7 +234,7 @@ unsafe fn main_0() -> i32 { { let __a1 = { let mut __v: MoveOnly = ::zero_init(); - MoveOnly::move_from(&mut __v, { &mut f }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut f }); __v }; vec_.push(__a1) @@ -240,7 +270,7 @@ unsafe fn main_0() -> i32 { }; let mut t1: ThrowingMove = { let mut __v: ThrowingMove = ::zero_init(); - ThrowingMove::copy_from(&mut __v, { &t }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &t }); __v }; assert!(((t1.v) == (1))); @@ -254,7 +284,7 @@ unsafe fn main_0() -> i32 { }; let mut n1: NoexceptMove = { let mut __v: NoexceptMove = ::zero_init(); - NoexceptMove::move_from(&mut __v, { &mut n }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut n }); __v }; assert!(((n1.v) == (2))); @@ -268,7 +298,7 @@ unsafe fn main_0() -> i32 { }; let mut g1: MoveOnly = { let mut __v: MoveOnly = ::zero_init(); - MoveOnly::move_from(&mut __v, { &mut g }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut g }); __v }; assert!(((g1.v) == (3))); diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index 4430228e22..729785a2af 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Chain { pub v: i32, @@ -16,13 +26,6 @@ impl Chain { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, o: *const Chain) { - (&raw mut self.v).write((((*o).v) + (100))); - } - pub unsafe fn move_from(&mut self, o: *mut Chain) { - (&raw mut self.v).write((((*o).v) + (1))); - (*o).v = 0; - } pub unsafe fn add_4(&mut self, mut n: i32) -> *mut Chain { self.v += n; return &mut (*(self as *mut Chain)); @@ -34,14 +37,14 @@ impl Chain { pub unsafe fn take(&mut self) -> Chain { return { let mut __v: Chain = ::zero_init(); - Chain::move_from(&mut __v, { &mut (*(self as *mut Chain)) }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*(self as *mut Chain)) }); __v }; } pub unsafe fn copy(&self) -> Chain { return { let mut __v: Chain = ::zero_init(); - Chain::copy_from(&mut __v, { &(*(self as *const Chain)) }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &(*(self as *const Chain)) }); __v }; } @@ -49,11 +52,22 @@ impl Chain { return &mut (*(self as *mut Chain)); } } +impl CopyConstructibleUnsafe for Chain { + unsafe fn copy_constructor(&mut self, o: *const Chain) { + (&raw mut self.v).write((((*o).v) + (100))); + } +} +impl MoveConstructibleUnsafe for Chain { + unsafe fn move_constructor(&mut self, o: *mut Chain) { + (&raw mut self.v).write((((*o).v) + (1))); + (*o).v = 0; + } +} impl Clone for Chain { fn clone(&self) -> Self { unsafe { let mut __v: Chain = ::zero_init(); - Chain::copy_from(&mut __v, self as *const Chain); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Chain); __v } } @@ -82,7 +96,7 @@ unsafe fn main_0() -> i32 { }; let mut b: Chain = { let mut __v: Chain = ::zero_init(); - Chain::move_from(&mut __v, { + MoveConstructibleUnsafe::move_constructor(&mut __v, { (unsafe { Chain::add_5(&mut (*(unsafe { Chain::add_5(&mut b0, 1) })), 1) }) }); __v @@ -107,7 +121,9 @@ unsafe fn main_0() -> i32 { ((unsafe { consume_0({ let mut __v: Chain = ::zero_init(); - Chain::move_from(&mut __v, { (unsafe { Chain::self_(&mut g) }) }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { + (unsafe { Chain::self_(&mut g) }) + }); __v }) }) == (21)) diff --git a/tests/unit/out/unsafe/nested_structs.rs b/tests/unit/out/unsafe/nested_structs.rs index d8c41c8069..176d47dca7 100644 --- a/tests/unit/out/unsafe/nested_structs.rs +++ b/tests/unit/out/unsafe/nested_structs.rs @@ -7,34 +7,88 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Level0_Level1_1_Level2_1_Level3_1 { pub x1: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Level0_Level1_1_Level2_1_Level3_2 { pub x1: i32, pub x2: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Level0_Level1_1_Level2_1 { pub x1: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Level0_Level1_1 { pub x1: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Level0_Level1_2 { pub x1: i32, pub x2: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Level0 {} pub fn main() { unsafe { diff --git a/tests/unit/out/unsafe/new.rs b/tests/unit/out/unsafe/new.rs index 5731da5eae..fffe780a13 100644 --- a/tests/unit/out/unsafe/new.rs +++ b/tests/unit/out/unsafe/new.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/new_bst.rs b/tests/unit/out/unsafe/new_bst.rs index 9ea5e7195c..34e337a77f 100644 --- a/tests/unit/out/unsafe/new_bst.rs +++ b/tests/unit/out/unsafe/new_bst.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct node_t { pub left: *mut node_t, pub right: *mut node_t, diff --git a/tests/unit/out/unsafe/new_struct.rs b/tests/unit/out/unsafe/new_struct.rs index 89e8da7bff..1ef439b45e 100644 --- a/tests/unit/out/unsafe/new_struct.rs +++ b/tests/unit/out/unsafe/new_struct.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub x: i32, pub y: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Triple { pub a: i32, pub b: i32, diff --git a/tests/unit/out/unsafe/nttp_distinct_specializations.rs b/tests/unit/out/unsafe/nttp_distinct_specializations.rs index 2052ce4e57..3b054d4c42 100644 --- a/tests/unit/out/unsafe/nttp_distinct_specializations.rs +++ b/tests/unit/out/unsafe/nttp_distinct_specializations.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S_2_ { pub v: i32, pub w: i32, @@ -18,7 +27,16 @@ impl S_2_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S_1_ { pub v: i32, } @@ -28,7 +46,16 @@ impl S_1_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 0128737ecf..733562f72d 100644 --- a/tests/unit/out/unsafe/offsetof.rs +++ b/tests/unit/out/unsafe/offsetof.rs @@ -7,14 +7,25 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Layout { pub a: u8, pub b: u32, pub c: u16, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] 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 ad48def68c..e83c379a67 100644 --- a/tests/unit/out/unsafe/opaque_forward_decl.rs +++ b/tests/unit/out/unsafe/opaque_forward_decl.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct container { pub p: *mut opaque, pub x: i32, diff --git a/tests/unit/out/unsafe/opaque_record_copy.rs b/tests/unit/out/unsafe/opaque_record_copy.rs index 0e0276abc2..339738a10d 100644 --- a/tests/unit/out/unsafe/opaque_record_copy.rs +++ b/tests/unit/out/unsafe/opaque_record_copy.rs @@ -7,10 +7,28 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Probe {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Wrapper_Probe_ { pub base_: Probe, pub tag: i32, diff --git a/tests/unit/out/unsafe/opaque_then_defined.rs b/tests/unit/out/unsafe/opaque_then_defined.rs index 23cd9f91cc..6cbb61093d 100644 --- a/tests/unit/out/unsafe/opaque_then_defined.rs +++ b/tests/unit/out/unsafe/opaque_then_defined.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct list { pub head: *mut node, pub size: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct node { pub value: i32, pub next: *mut node, diff --git a/tests/unit/out/unsafe/operator_arithmetic_free.rs b/tests/unit/out/unsafe/operator_arithmetic_free.rs index 7e49ca33fd..897ff4c9a1 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_free.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_free.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 7c3c8e8486..b05bb0adab 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_member.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_member.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 8594a0b335..97df16f7a3 100644 --- a/tests/unit/out/unsafe/operator_bitwise_free.rs +++ b/tests/unit/out/unsafe/operator_bitwise_free.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 5659930911..a220c433db 100644 --- a/tests/unit/out/unsafe/operator_bitwise_member.rs +++ b/tests/unit/out/unsafe/operator_bitwise_member.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 90ade9a4bb..0eb9295006 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Eq { pub a: i32, pub b: i32, @@ -25,7 +34,16 @@ impl std::cmp::PartialEq for Eq { } impl std::cmp::Eq for Eq {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Cmp { pub a: i32, pub b: i32, @@ -70,7 +88,16 @@ impl std::cmp::PartialEq for Cmp { } impl std::cmp::Eq for Cmp {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Both { pub a: i32, } @@ -106,7 +133,16 @@ impl std::cmp::PartialEq for Both { } impl std::cmp::Eq for Both {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct OrdOnly { pub a: i32, } @@ -139,7 +175,16 @@ impl std::cmp::PartialEq for OrdOnly { } impl std::cmp::Eq for OrdOnly {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub x: i32, } @@ -175,7 +220,16 @@ impl std::cmp::PartialEq for Inner { } impl std::cmp::Eq for Inner {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer { pub i: Inner, pub y: i32, @@ -224,7 +278,16 @@ impl std::cmp::PartialEq for Outer { } impl std::cmp::Eq for Outer {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Secondary { pub a: i32, } @@ -271,7 +334,16 @@ impl std::cmp::PartialEq for Secondary { } impl std::cmp::Eq for Secondary {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 f01d77b248..8ea736c45d 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub v: i32, } @@ -60,7 +69,16 @@ pub unsafe fn operator_lt_7(mut a: i32, b: *const S) -> bool { return ((a) < ((*b).v)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 a31f1cfc20..ec6e818099 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 f1588054e9..042b17fc02 100644 --- a/tests/unit/out/unsafe/operator_comparison_mixed.rs +++ b/tests/unit/out/unsafe/operator_comparison_mixed.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 8be2263ce3..f65487b612 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct X { pub v: i32, } @@ -54,12 +63,30 @@ pub unsafe fn operator_ge_5(mut a: X, mut b: X) -> i32 { return if ((a.v) >= (b.v)) { 7 } else { 0 }; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Result { pub r: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Custom { pub v: i32, } @@ -71,7 +98,16 @@ impl Custom { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Mixed { pub v: i32, } @@ -113,7 +149,17 @@ impl std::cmp::PartialEq for Mixed { } impl std::cmp::Eq for Mixed {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_into(bool, to_bool)] pub struct MyBool { pub value: bool, @@ -127,7 +173,16 @@ impl MyBool { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Boolish { pub v: i32, } @@ -181,7 +236,7 @@ pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { }; } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_into(bool, to_bool)] pub struct RefBool { pub value: bool, @@ -202,7 +257,16 @@ pub static mut ref_true_8: std::cell::LazyCell = std::cell::LazyCell::n } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 36c5023eae..ffdc06d91e 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -13,7 +13,7 @@ pub unsafe fn operator_lt_1(x: *const S, y: *const S) -> bool { return (((*x).data_) < ((*y).data_)); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct S { data_: i32, @@ -22,7 +22,9 @@ impl S { pub unsafe fn construct(&mut self, mut data: i32) { (&raw mut self.data_).write(data); } - pub unsafe fn move_from(&mut self, _a0: *mut S) { +} +impl MoveConstructibleUnsafe for S { + unsafe fn move_constructor(&mut self, _a0: *mut S) { (&raw mut self.data_).write((*_a0).data_); } } diff --git a/tests/unit/out/unsafe/operator_compound_assignment_free.rs b/tests/unit/out/unsafe/operator_compound_assignment_free.rs index 2996a6581b..483871891e 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_free.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_free.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 610a63b2a7..91febb12b4 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_member.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_member.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 905d24a0b7..7799dce798 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -10,7 +10,16 @@ pub unsafe fn operator_eq_0(_a0: *const Defaulted, _a1: *const Defaulted) -> boo return (((*_a0).a) == ((*_a1).a)) && (((*_a0).b) == ((*_a1).b)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Defaulted { pub a: i32, pub b: i32, @@ -37,7 +46,16 @@ pub unsafe fn operator_eq_2(_a0: *const DefaultedOrd, _a1: *const DefaultedOrd) return (((*_a0).a) == ((*_a1).a)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct DefaultedOrd { pub a: i32, } @@ -69,7 +87,16 @@ pub unsafe fn operator_add_5(x: *const Inline, y: *const Inline) -> Inline { }; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inline { pub a: i32, } @@ -98,7 +125,16 @@ impl std::cmp::PartialEq for Inline { } impl std::cmp::Eq for Inline {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct OutOfLine { pub a: i32, } @@ -127,7 +163,16 @@ pub unsafe fn operator_eq_10(x: *const Tmpl_int_, y: *const Tmpl_long_) -> bool return (((*x).v as i64) == ((*y).v)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Tmpl_int_ { pub v: i32, } @@ -156,7 +201,16 @@ impl std::cmp::PartialEq for Tmpl_int_ { } impl std::cmp::Eq for Tmpl_int_ {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Tmpl_long_ { pub v: i64, } @@ -167,7 +221,16 @@ pub unsafe fn operator_eq_11( return (((*_a0).v) == ((*_a1).v)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 714d01103a..ba57f1cc2f 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/operator_logical_free.rs b/tests/unit/out/unsafe/operator_logical_free.rs index e888dc8141..0ae987db8a 100644 --- a/tests/unit/out/unsafe/operator_logical_free.rs +++ b/tests/unit/out/unsafe/operator_logical_free.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 e7029ceab2..6657800073 100644 --- a/tests/unit/out/unsafe/operator_logical_member.rs +++ b/tests/unit/out/unsafe/operator_logical_member.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 ce8fa2513e..2d63c460e4 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_free.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_free.rs @@ -7,12 +7,30 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub x: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub data: [i32; 3], pub inner: Inner, diff --git a/tests/unit/out/unsafe/operator_member_pointer_member.rs b/tests/unit/out/unsafe/operator_member_pointer_member.rs index 90c64cba8e..2310c2c8a1 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_member.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_member.rs @@ -7,12 +7,30 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub x: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Table {} impl Table { pub unsafe fn operator_index(mut i: i32) -> *mut i32 { @@ -22,7 +40,16 @@ impl Table { 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub data: [i32; 3], pub inner: Inner, diff --git a/tests/unit/out/unsafe/operator_other_free.rs b/tests/unit/out/unsafe/operator_other_free.rs index 6ef8081373..ebcd624688 100644 --- a/tests/unit/out/unsafe/operator_other_free.rs +++ b/tests/unit/out/unsafe/operator_other_free.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 3d412fc229..1b6bd43fb8 100644 --- a/tests/unit/out/unsafe/operator_other_member.rs +++ b/tests/unit/out/unsafe/operator_other_member.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Static {} impl Static { pub unsafe fn operator_call(mut a: i32, mut b: i32) -> i32 { @@ -15,7 +24,17 @@ impl Static { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_into(i32, to_i32)] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/operator_overloads.rs b/tests/unit/out/unsafe/operator_overloads.rs index 2d6ab5e58d..363ea990d4 100644 --- a/tests/unit/out/unsafe/operator_overloads.rs +++ b/tests/unit/out/unsafe/operator_overloads.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 dd0e64f6d5..8504bc5024 100644 --- a/tests/unit/out/unsafe/operator_qualifiers.rs +++ b/tests/unit/out/unsafe/operator_qualifiers.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 7d742a4677..f2671b3d7e 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 6ab10c49d0..b5b860a20d 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Lt { pub v: i32, } @@ -44,7 +53,16 @@ impl std::cmp::PartialEq for Lt { } impl std::cmp::Eq for Lt {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Eq { pub v: i32, } @@ -60,7 +78,16 @@ impl std::cmp::PartialEq for Eq { } impl std::cmp::Eq for Eq {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Cmp { pub v: i32, } @@ -89,7 +116,16 @@ impl std::cmp::PartialEq for Cmp { } impl std::cmp::Eq for Cmp {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Free { pub v: i32, } @@ -124,7 +160,16 @@ pub unsafe fn operator_eq_1(a: *const Free, b: *const Free) -> bool { return (((*a).v) == ((*b).v)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 0c23dd1cce..c9317a9a21 100644 --- a/tests/unit/out/unsafe/overload_mangling.rs +++ b/tests/unit/out/unsafe/overload_mangling.rs @@ -16,7 +16,16 @@ pub unsafe fn twice_2(mut n: i32) -> i32 { return ((n) * (2)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Access_S_ {} impl Access_S_ { pub unsafe fn get_1(&mut self, mut p: *mut S) -> i32 { @@ -33,7 +42,16 @@ impl Access_S_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub base: i32, } @@ -107,7 +125,16 @@ impl S { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Box_ { pub v: i32, } diff --git a/tests/unit/out/unsafe/pair_converting_construction.rs b/tests/unit/out/unsafe/pair_converting_construction.rs index d7372c6d86..62ae92a309 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.rs @@ -7,7 +7,17 @@ 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, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Celsius { pub degrees: i32, @@ -18,7 +28,17 @@ impl Celsius { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_into(i32, to_i32)] pub struct Meters { pub value: i32, @@ -29,7 +49,17 @@ impl Meters { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(Celsius, construct, ptr)] pub struct Label { pub id: i32, @@ -40,7 +70,17 @@ impl Label { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(Celsius, construct_1, ptr)] #[cpp_from_move(Celsius, construct_2, ptr)] pub struct Owner { @@ -58,7 +98,17 @@ impl Owner { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(Celsius, construct, value)] pub struct Holder { pub value: i32, @@ -69,7 +119,16 @@ impl Holder { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, +)] #[cpp_from(i32, construct, value)] pub struct Fallback { pub value: i32, @@ -91,12 +150,31 @@ impl Default for Fallback { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Counter { pub hits: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(Counter, construct, mut_ptr)] pub struct Observer { pub seen: i32, @@ -113,13 +191,33 @@ impl Tag { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(Celsius, construct, ptr)] pub struct Tag { pub code: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(*const libc::c_char , construct, value)] pub struct Name { pub len: i32, diff --git a/tests/unit/out/unsafe/pod.rs b/tests/unit/out/unsafe/pod.rs index e406666f6e..9ee5ea9f79 100644 --- a/tests/unit/out/unsafe/pod.rs +++ b/tests/unit/out/unsafe/pod.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct POD { pub x1: i32, pub x2: i32, diff --git a/tests/unit/out/unsafe/pointer_array.rs b/tests/unit/out/unsafe/pointer_array.rs index 0f91664e48..fa1f3cc073 100644 --- a/tests/unit/out/unsafe/pointer_array.rs +++ b/tests/unit/out/unsafe/pointer_array.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 8112e83a98..be4c591924 100644 --- a/tests/unit/out/unsafe/pointers.rs +++ b/tests/unit/out/unsafe/pointers.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Test { pub x: i32, } diff --git a/tests/unit/out/unsafe/polymorphism.rs b/tests/unit/out/unsafe/polymorphism.rs index da9d32dbe7..5cd87101e7 100644 --- a/tests/unit/out/unsafe/polymorphism.rs +++ b/tests/unit/out/unsafe/polymorphism.rs @@ -10,10 +10,28 @@ pub unsafe trait Animal { unsafe fn bark(&self) -> bool; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Dog {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Cat {} impl Cat { unsafe fn meow(&self) -> bool { diff --git a/tests/unit/out/unsafe/ptr_cast_init.rs b/tests/unit/out/unsafe/ptr_cast_init.rs index 18960f6967..b2e14fe6b1 100644 --- a/tests/unit/out/unsafe/ptr_cast_init.rs +++ b/tests/unit/out/unsafe/ptr_cast_init.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct header { pub tag: i32, pub size: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 a885c7dc7e..097e56f511 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -7,30 +7,58 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Chunk { pub data: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Writer { pub output: *mut Vec, pub chunk: Chunk, } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct JPEGData { pub com_data: Vec>, pub app_data: Vec>, } -impl JPEGData { - pub unsafe fn move_from(&mut self, _a0: *mut JPEGData) { +impl MoveConstructibleUnsafe for JPEGData { + unsafe fn move_constructor(&mut self, _a0: *mut JPEGData) { (&raw mut self.com_data).write(std::mem::take(&mut (*_a0).com_data)); (&raw mut self.app_data).write(std::mem::take(&mut (*_a0).app_data)); } - pub unsafe fn move_assign(&mut self, _a0: *mut JPEGData) -> *mut JPEGData { +} +impl MoveAssignableUnsafe for JPEGData { + unsafe fn move_assign(&mut self, _a0: *mut JPEGData) -> *mut JPEGData { { self.com_data = std::mem::take(&mut (*_a0).com_data); }; @@ -106,7 +134,16 @@ pub unsafe fn self_ref_push_6(mut comps: *mut Vec) { }; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, +)] #[cpp_from(i32, construct_1, value)] pub struct Pair { pub first: i32, @@ -211,18 +248,28 @@ pub unsafe fn emplace_ref_self_read_13(values: *mut Vec) -> *mut i64 { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Bytes { pub v: Vec>, pub b: [u8; 3], } -impl Bytes { - pub unsafe fn move_from(&mut self, _a0: *mut Bytes) { +impl MoveConstructibleUnsafe for Bytes { + unsafe fn move_constructor(&mut self, _a0: *mut Bytes) { (&raw mut self.v).write(std::mem::take(&mut (*_a0).v)); (&raw mut self.b).write(std::array::from_fn::<_, 3, _>(|__i: usize| (*_a0).b[(__i)])); } - pub unsafe fn move_assign(&mut self, _a0: *mut Bytes) -> *mut Bytes { +} +impl MoveAssignableUnsafe for Bytes { + unsafe fn move_assign(&mut self, _a0: *mut Bytes) -> *mut Bytes { { self.v = std::mem::take(&mut (*_a0).v); }; @@ -251,7 +298,16 @@ pub unsafe fn emplace_from_element_14(mut v: *mut Vec>) { }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Plain { pub a: i32, pub b: [f64; 2], @@ -266,7 +322,16 @@ pub unsafe fn emplace_plain_15(mut v: *mut Vec) { 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Counted { pub seen: usize, } diff --git a/tests/unit/out/unsafe/random.rs b/tests/unit/out/unsafe/random.rs index 2971074173..eab06ff22a 100644 --- a/tests/unit/out/unsafe/random.rs +++ b/tests/unit/out/unsafe/random.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub x: i32, pub y: i32, @@ -41,7 +50,16 @@ pub unsafe fn zero_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 4fa29de55c..9f3e3ed9fd 100644 --- a/tests/unit/out/unsafe/reference_wrapper.rs +++ b/tests/unit/out/unsafe/reference_wrapper.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Point { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/references.rs b/tests/unit/out/unsafe/references.rs index 709dca3817..af6126c6a7 100644 --- a/tests/unit/out/unsafe/references.rs +++ b/tests/unit/out/unsafe/references.rs @@ -7,14 +7,32 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub x: i32, pub y: i32, pub arr: [i32; 2], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 45a5ae3708..2f7fd2c9dc 100644 --- a/tests/unit/out/unsafe/refs_as_args.rs +++ b/tests/unit/out/unsafe/refs_as_args.rs @@ -18,7 +18,16 @@ pub unsafe fn more_refs_0(mut x1: i32, mut x2: i32, r1: *mut i32, r2: *const i32 (*r1) = (*rx2); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 45d8e80e36..fa19cfabc8 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs @@ -7,19 +7,46 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub x: i32, pub y: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct W { pub h: i32, pub arr: [S; 3], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct P { pub a: *mut i32, pub arr: [*mut i32; 3], diff --git a/tests/unit/out/unsafe/reinterpret_cast_struct.rs b/tests/unit/out/unsafe/reinterpret_cast_struct.rs index b348cf519b..795706815f 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_struct.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_struct.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Point { pub x: i32, pub y: 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 a29b90dea5..98b5c7d4f7 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_struct_to_struct.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_struct_to_struct.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Point { pub x: u32, pub y: u32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub first: u32, pub second: u32, diff --git a/tests/unit/out/unsafe/reserved_keywords.rs b/tests/unit/out/unsafe/reserved_keywords.rs index e4634df776..2a022c5622 100644 --- a/tests/unit/out/unsafe/reserved_keywords.rs +++ b/tests/unit/out/unsafe/reserved_keywords.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub as_: i32, pub async_: i32, @@ -49,12 +58,30 @@ pub struct S { pub vec_: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct type_ { pub v: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 143c456492..1f16547898 100644 --- a/tests/unit/out/unsafe/return_move.rs +++ b/tests/unit/out/unsafe/return_move.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct node { pub value: i32, pub next: *mut node, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct pair_t { pub a: i32, pub n: *mut node, diff --git a/tests/unit/out/unsafe/rule_of_five.rs b/tests/unit/out/unsafe/rule_of_five.rs index 0745283e1b..cb1ce53e1c 100644 --- a/tests/unit/out/unsafe/rule_of_five.rs +++ b/tests/unit/out/unsafe/rule_of_five.rs @@ -10,17 +10,7 @@ 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, - MoveCtorUnsafe, - CppFromUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, - DestructibleUnsafe, - Default, -)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, SwappableUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct Buffer { pub data: [i32; 4], @@ -41,10 +31,14 @@ impl Buffer { } (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for Buffer { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_dec(); } - pub unsafe fn copy_from(&mut self, o: *const Buffer) { +} +impl CopyConstructibleUnsafe for Buffer { + unsafe fn copy_constructor(&mut self, o: *const Buffer) { (&raw mut self.data).write([0_i32; 4]); (&raw mut self.size).write((*o).size); { @@ -59,7 +53,9 @@ impl Buffer { (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); } - pub unsafe fn move_from(&mut self, o: *mut Buffer) { +} +impl MoveConstructibleUnsafe for Buffer { + unsafe fn move_constructor(&mut self, o: *mut Buffer) { (&raw mut self.data).write([0_i32; 4]); (&raw mut self.size).write((*o).size); { @@ -76,7 +72,9 @@ impl Buffer { (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, o: *const Buffer) -> *mut Buffer { +} +impl CopyAssignableUnsafe for Buffer { + unsafe fn copy_assign(&mut self, o: *const Buffer) -> *mut Buffer { if (((self as *mut Buffer).cast_const()) == (o)) { return &mut (*(self as *mut Buffer)); } @@ -93,7 +91,9 @@ impl Buffer { (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); return &mut (*(self as *mut Buffer)); } - pub unsafe fn move_assign(&mut self, o: *mut Buffer) -> *mut Buffer { +} +impl MoveAssignableUnsafe for Buffer { + unsafe fn move_assign(&mut self, o: *mut Buffer) -> *mut Buffer { if ((self as *mut Buffer) == (o)) { return &mut (*(self as *mut Buffer)); } @@ -117,7 +117,7 @@ impl Clone for Buffer { fn clone(&self) -> Self { unsafe { let mut __v: Buffer = ::zero_init(); - Buffer::copy_from(&mut __v, self as *const Buffer); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Buffer); __v } } @@ -129,11 +129,11 @@ pub unsafe fn make_3(mut size: i32) -> Buffer { __v }; let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); return { let mut __v: Buffer = ::zero_init(); - Buffer::move_from(&mut __v, { &mut b }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut b }); __v }; } @@ -151,15 +151,15 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut b: Buffer = { let mut __v: Buffer = ::zero_init(); - Buffer::copy_from(&mut __v, { &a }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &a }); __v }; let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (2)) @@ -170,11 +170,11 @@ unsafe fn main_0() -> i32 { assert!(((a.data[(0) as usize]) == (0))); let mut c: Buffer = { let mut __v: Buffer = ::zero_init(); - Buffer::move_from(&mut __v, { &mut a }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut a }); __v }; let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (3)) @@ -184,24 +184,24 @@ unsafe fn main_0() -> i32 { assert!(((c.size) == (4)) && ((c.data[(3) as usize]) == (3))); let mut d: Buffer = (unsafe { make_3(2) }); let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!( ((d.size) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (2)) ); - (unsafe { Buffer::copy_assign(&mut d, &b) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut d, &b) }); assert!( (((d.size) == (4)) && ((d.data[(0) as usize]) == (100))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (2)) ); - (unsafe { Buffer::move_assign(&mut d, &mut c) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut d, &mut c) }); assert!( (((d.data[(0) as usize]) == (0)) && ((c.size) == (0))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (3)) ); (unsafe { let _o: *mut Buffer = &mut d; - Buffer::move_assign(&mut d, _o) + MoveAssignableUnsafe::move_assign(&mut d, _o) }); assert!( ((d.size) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (3)) diff --git a/tests/unit/out/unsafe/rule_of_three.rs b/tests/unit/out/unsafe/rule_of_three.rs index c54d92ae60..34ff42dd06 100644 --- a/tests/unit/out/unsafe/rule_of_three.rs +++ b/tests/unit/out/unsafe/rule_of_three.rs @@ -9,15 +9,7 @@ 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, - CopyAssignUnsafe, - DestructibleUnsafe, - Default, -)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, MovableUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct Buffer { pub data: [i32; 4], @@ -38,10 +30,14 @@ impl Buffer { } (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for Buffer { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_dec(); } - pub unsafe fn copy_from(&mut self, o: *const Buffer) { +} +impl CopyConstructibleUnsafe for Buffer { + unsafe fn copy_constructor(&mut self, o: *const Buffer) { (&raw mut self.data).write([0_i32; 4]); (&raw mut self.size).write((*o).size); { @@ -56,7 +52,9 @@ impl Buffer { (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, o: *const Buffer) -> *mut Buffer { +} +impl CopyAssignableUnsafe for Buffer { + unsafe fn copy_assign(&mut self, o: *const Buffer) -> *mut Buffer { if (((self as *mut Buffer).cast_const()) == (o)) { return &mut (*(self as *mut Buffer)); } @@ -78,7 +76,7 @@ impl Clone for Buffer { fn clone(&self) -> Self { unsafe { let mut __v: Buffer = ::zero_init(); - Buffer::copy_from(&mut __v, self as *const Buffer); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Buffer); __v } } @@ -110,15 +108,15 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut b: Buffer = { let mut __v: Buffer = ::zero_init(); - Buffer::copy_from(&mut __v, { &a }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &a }); __v }; let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (2)) @@ -132,9 +130,9 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); - (unsafe { Buffer::copy_assign(&mut c, &a) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut c, &a) }); assert!(((c.size) == (4)) && ((c.data[(3) as usize]) == (3))); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (3)) @@ -142,25 +140,25 @@ unsafe fn main_0() -> i32 { ); (unsafe { let _o: *const Buffer = &c; - Buffer::copy_assign(&mut c, _o) + CopyAssignableUnsafe::copy_assign(&mut c, _o) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (2))); assert!(((unsafe { sum_2(&a,) }) == (6))); assert!(((unsafe { sum_2(&b,) }) == (106))); let mut d: Buffer = { let mut __v: Buffer = ::zero_init(); - Buffer::copy_from(&mut __v, { &a }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &a }); __v }; let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (3)) ); assert!(((a.size) == (4)) && ((a.data[(3) as usize]) == (3))); - (unsafe { Buffer::copy_assign(&mut d, &b) }); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut d, &b) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (4))); assert!(((b.data[(0) as usize]) == (100)) && ((d.data[(0) as usize]) == (100))); } diff --git a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs index 8dbae5240c..c5e110fb42 100644 --- a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs +++ b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs @@ -13,9 +13,10 @@ pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u VaArg, FnPtrArg, ZeroInitializationUnsafe, - MoveCtorUnsafe, CppFromUnsafe, - CopyAssignUnsafe, + DestructibleUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, Default, )] #[cpp_from(i32, construct, value)] @@ -26,15 +27,21 @@ impl Elem { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, o: *const Elem) { +} +impl CopyConstructibleUnsafe for Elem { + unsafe fn copy_constructor(&mut self, o: *const Elem) { (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } - pub unsafe fn move_from(&mut self, o: *mut Elem) { +} +impl MoveConstructibleUnsafe for Elem { + unsafe fn move_constructor(&mut self, o: *mut Elem) { (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, _a0: *const Elem) -> *mut Elem { +} +impl CopyAssignableUnsafe for Elem { + unsafe fn copy_assign(&mut self, _a0: *const Elem) -> *mut Elem { self.v = (*_a0).v; return &mut (*(self as *mut Elem)); } @@ -43,7 +50,7 @@ impl Clone for Elem { fn clone(&self) -> Self { unsafe { let mut __v: Elem = ::zero_init(); - Elem::copy_from(&mut __v, self as *const Elem); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Elem); __v } } @@ -76,7 +83,7 @@ unsafe fn main_0() -> i32 { as usize; UnsafeRandomAccessIterator::Vec(v.insert_mut(pos, { let mut __v: Elem = ::zero_init(); - Elem::move_from(&mut __v, { &mut a }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut a }); __v })) }; diff --git a/tests/unit/out/unsafe/rvalue_struct.rs b/tests/unit/out/unsafe/rvalue_struct.rs index ab46e9daef..9dc4a5dc38 100644 --- a/tests/unit/out/unsafe/rvalue_struct.rs +++ b/tests/unit/out/unsafe/rvalue_struct.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub a: i32, pub b: i32, diff --git a/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs b/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs index c28c9079f0..757edd3664 100644 --- a/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs +++ b/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 bba35fcbfa..9b6fe56f36 100644 --- a/tests/unit/out/unsafe/self_referencing_initializer.rs +++ b/tests/unit/out/unsafe/self_referencing_initializer.rs @@ -7,18 +7,38 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct list_head { pub next: *mut list_head, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct node { pub value: i32, pub value_ptr: *mut i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct node_with_defaults { pub next: *mut node_with_defaults, pub value: i32, diff --git a/tests/unit/out/unsafe/size_t_static_member.rs b/tests/unit/out/unsafe/size_t_static_member.rs index 58dd977872..0b70647185 100644 --- a/tests/unit/out/unsafe/size_t_static_member.rs +++ b/tests/unit/out/unsafe/size_t_static_member.rs @@ -8,12 +8,30 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Table_char_ {} pub fn main() { unsafe { diff --git a/tests/unit/out/unsafe/size_t_template_param.rs b/tests/unit/out/unsafe/size_t_template_param.rs index 1712711678..e20a098cfb 100644 --- a/tests/unit/out/unsafe/size_t_template_param.rs +++ b/tests/unit/out/unsafe/size_t_template_param.rs @@ -11,7 +11,17 @@ pub unsafe fn array_ref_0(a: *mut [u64; 3]) -> u64 { return (*a)[((3_u64 as u64).wrapping_sub(1_u64)) as usize]; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(*const u64 , construct, value)] pub struct PtrCtor_unsigned_long_ { pub v: u64, @@ -22,7 +32,17 @@ impl PtrCtor_unsigned_long_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(u64, construct, ptr)] pub struct RefCtor_unsigned_long_ { pub v: u64, diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index 99ca033251..95f7ffc5eb 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -9,13 +9,7 @@ use std::rc::Rc; pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - VaArg, - FnPtrArg, - ZeroInitializationUnsafe, - MoveCtorUnsafe, - CppFromUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, + VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, )] #[cpp_from(i32, construct_1, value)] pub struct Tracked { @@ -28,19 +22,27 @@ impl Tracked { pub unsafe fn construct_1(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, o: *const Tracked) { +} +impl CopyConstructibleUnsafe for Tracked { + unsafe fn copy_constructor(&mut self, o: *const Tracked) { (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } - pub unsafe fn move_from(&mut self, o: *mut Tracked) { +} +impl MoveConstructibleUnsafe for Tracked { + unsafe fn move_constructor(&mut self, o: *mut Tracked) { (&raw mut self.v).write((*o).v); } - pub unsafe fn copy_assign(&mut self, o: *const Tracked) -> *mut Tracked { +} +impl CopyAssignableUnsafe for Tracked { + unsafe fn copy_assign(&mut self, o: *const Tracked) -> *mut Tracked { self.v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*(self as *mut Tracked)); } - pub unsafe fn move_assign(&mut self, o: *mut Tracked) -> *mut Tracked { +} +impl MoveAssignableUnsafe for Tracked { + unsafe fn move_assign(&mut self, o: *mut Tracked) -> *mut Tracked { self.v = (*o).v; return &mut (*(self as *mut Tracked)); } @@ -76,7 +78,7 @@ impl Clone for Tracked { fn clone(&self) -> Self { unsafe { let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, self as *const Tracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Tracked); __v } } @@ -100,7 +102,7 @@ pub unsafe fn greater_2(a: *const Tracked, b: *const Tracked) -> bool { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, MoveAssignUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, Default, )] #[cpp_from(i32, construct, value)] pub struct MoveOnly { @@ -110,10 +112,14 @@ impl MoveOnly { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn move_from(&mut self, _a0: *mut MoveOnly) { +} +impl MoveConstructibleUnsafe for MoveOnly { + unsafe fn move_constructor(&mut self, _a0: *mut MoveOnly) { (&raw mut self.v).write((*_a0).v); } - pub unsafe fn move_assign(&mut self, _a0: *mut MoveOnly) -> *mut MoveOnly { +} +impl MoveAssignableUnsafe for MoveOnly { + unsafe fn move_assign(&mut self, _a0: *mut MoveOnly) -> *mut MoveOnly { self.v = (*_a0).v; return &mut (*(self as *mut MoveOnly)); } @@ -150,16 +156,26 @@ pub unsafe fn operator_lt_3(a: *const MoveOnly, b: *const MoveOnly) -> bool { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Bag { pub items: Vec, } -impl Bag { - pub unsafe fn move_from(&mut self, _a0: *mut Bag) { +impl MoveConstructibleUnsafe for Bag { + unsafe fn move_constructor(&mut self, _a0: *mut Bag) { (&raw mut self.items).write(std::mem::take(&mut (*_a0).items)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Bag) -> *mut Bag { +} +impl MoveAssignableUnsafe for Bag { + unsafe fn move_assign(&mut self, _a0: *mut Bag) -> *mut Bag { { self.items = std::mem::take(&mut (*_a0).items); }; diff --git a/tests/unit/out/unsafe/static_local.rs b/tests/unit/out/unsafe/static_local.rs index 50fd4588f8..b466c9f317 100644 --- a/tests/unit/out/unsafe/static_local.rs +++ b/tests/unit/out/unsafe/static_local.rs @@ -22,7 +22,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S_8 {} impl S_8 { pub unsafe fn get(&self) -> i32 { diff --git a/tests/unit/out/unsafe/static_var_in_class.rs b/tests/unit/out/unsafe/static_var_in_class.rs index e7586525f7..de33e44eb5 100644 --- a/tests/unit/out/unsafe/static_var_in_class.rs +++ b/tests/unit/out/unsafe/static_var_in_class.rs @@ -8,7 +8,16 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct C {} impl C { pub unsafe fn get(&mut self) -> i32 { @@ -19,7 +28,16 @@ pub static mut inner_const_1: std::cell::LazyCell = std::cell::LazyCell::ne pub type anon_3 = u32; pub const anon_3_kValue: anon_3 = 3; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S {} impl S { pub unsafe fn f() -> i32 { diff --git a/tests/unit/out/unsafe/stdcopy.rs b/tests/unit/out/unsafe/stdcopy.rs index ab9b47b775..4a0b3d3449 100644 --- a/tests/unit/out/unsafe/stdcopy.rs +++ b/tests/unit/out/unsafe/stdcopy.rs @@ -7,7 +7,17 @@ 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, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Degrees { pub value: i32, diff --git a/tests/unit/out/unsafe/strdup.rs b/tests/unit/out/unsafe/strdup.rs index 351bd03515..3eb8a6b96e 100644 --- a/tests/unit/out/unsafe/strdup.rs +++ b/tests/unit/out/unsafe/strdup.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 c0821ba4e1..0c5d83689c 100644 --- a/tests/unit/out/unsafe/string_literal_ptr_init.rs +++ b/tests/unit/out/unsafe/string_literal_ptr_init.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct label { pub name: *const libc::c_char, pub probe: Option i32>, diff --git a/tests/unit/out/unsafe/string_substr.rs b/tests/unit/out/unsafe/string_substr.rs index b8ab2533a5..932647e8a4 100644 --- a/tests/unit/out/unsafe/string_substr.rs +++ b/tests/unit/out/unsafe/string_substr.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 862bde13fd..2e5488765e 100644 --- a/tests/unit/out/unsafe/struct_2d_array_field.rs +++ b/tests/unit/out/unsafe/struct_2d_array_field.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct table { pub rows: [[libc::c_char; 10]; 3], pub count: usize, diff --git a/tests/unit/out/unsafe/struct_ctor.rs b/tests/unit/out/unsafe/struct_ctor.rs index 812b350c7c..d8b4510ff5 100644 --- a/tests/unit/out/unsafe/struct_ctor.rs +++ b/tests/unit/out/unsafe/struct_ctor.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct StructWithCtor { x1_: i32, x2_: i32, @@ -30,7 +39,17 @@ pub unsafe fn foo_0(x: *mut i32) -> *mut i32 { return x; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Value_ { pub v: i32, @@ -41,7 +60,9 @@ impl Value_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Ptr_ { pub v1: Value_, pub v2: Value_, diff --git a/tests/unit/out/unsafe/struct_default_ctor.rs b/tests/unit/out/unsafe/struct_default_ctor.rs index e55c02d7e2..c02baa62a2 100644 --- a/tests/unit/out/unsafe/struct_default_ctor.rs +++ b/tests/unit/out/unsafe/struct_default_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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct S { pub a: i32, pub b: bool, @@ -30,19 +32,39 @@ impl Default for S { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Declared { pub v: i32, } impl Declared {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Holder { pub items: [S; 2], } pub static mut kInit_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct FromStatic { pub v: i32, } diff --git a/tests/unit/out/unsafe/struct_member_array_adjacency.rs b/tests/unit/out/unsafe/struct_member_array_adjacency.rs index d989b19db8..019d55c669 100644 --- a/tests/unit/out/unsafe/struct_member_array_adjacency.rs +++ b/tests/unit/out/unsafe/struct_member_array_adjacency.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct pair { pub a: [i32; 4], pub b: [i32; 4], diff --git a/tests/unit/out/unsafe/struct_ptr.rs b/tests/unit/out/unsafe/struct_ptr.rs index 8857f43498..3cdf384bb2 100644 --- a/tests/unit/out/unsafe/struct_ptr.rs +++ b/tests/unit/out/unsafe/struct_ptr.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 bbac1d8016..42fb42ce66 100644 --- a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs @@ -8,7 +8,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, Default)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MovableUnsafe, Default)] pub struct Counted { pub x: i32, pub y: i32, @@ -18,12 +18,16 @@ impl Counted { (&raw mut self.x).write(x); (&raw mut self.y).write(y); } - pub unsafe fn copy_from(&mut self, other: *const Counted) { +} +impl CopyConstructibleUnsafe for Counted { + unsafe fn copy_constructor(&mut self, other: *const Counted) { (&raw mut self.x).write((((*other).x) * (2))); (&raw mut self.y).write((((*other).y) * (2))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, _a0: *const Counted) -> *mut Counted { +} +impl CopyAssignableUnsafe for Counted { + unsafe fn copy_assign(&mut self, _a0: *const Counted) -> *mut Counted { self.x = (*_a0).x; self.y = (*_a0).y; return &mut (*(self as *mut Counted)); @@ -33,7 +37,7 @@ impl Clone for Counted { fn clone(&self) -> Self { unsafe { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, self as *const Counted); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Counted); __v } } @@ -59,7 +63,7 @@ unsafe fn main_0() -> i32 { }; let mut __decomp_2: Counted = { let mut __v: Counted = ::zero_init(); - Counted::copy_from(&mut __v, { &s }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &s }); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); diff --git a/tests/unit/out/unsafe/structured_binding_element_ctor.rs b/tests/unit/out/unsafe/structured_binding_element_ctor.rs index ec6a6f9fc9..02cd72c6ee 100644 --- a/tests/unit/out/unsafe/structured_binding_element_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_element_ctor.rs @@ -9,7 +9,17 @@ use std::rc::Rc; pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Elem { pub v: i32, @@ -18,11 +28,15 @@ impl Elem { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, other: *const Elem) { +} +impl CopyConstructibleUnsafe for Elem { + unsafe fn copy_constructor(&mut self, other: *const Elem) { (&raw mut self.v).write((((*other).v) + (100))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } - pub unsafe fn move_from(&mut self, other: *mut Elem) { +} +impl MoveConstructibleUnsafe for Elem { + unsafe fn move_constructor(&mut self, other: *mut Elem) { (&raw mut self.v).write((((*other).v) + (1000))); (*other).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); @@ -32,27 +46,38 @@ impl Clone for Elem { fn clone(&self) -> Self { unsafe { let mut __v: Elem = ::zero_init(); - Elem::copy_from(&mut __v, self as *const Elem); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Elem); __v } } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] pub struct Two { pub a: Elem, pub b: Elem, } -impl Two { - pub unsafe fn move_from(&mut self, _a0: *mut Two) { +impl MoveConstructibleUnsafe for Two { + unsafe fn move_constructor(&mut self, _a0: *mut Two) { (&raw mut self.a).write({ let mut __v: Elem = ::zero_init(); - Elem::move_from(&mut __v, { &mut (*_a0).a }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).a }); __v }); (&raw mut self.b).write({ let mut __v: Elem = ::zero_init(); - Elem::move_from(&mut __v, { &mut (*_a0).b }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).b }); __v }); } @@ -104,7 +129,7 @@ unsafe fn main_0() -> i32 { assert!(((t.a.v) == (50))); let mut __decomp_5: Two = { let mut __v: Two = ::zero_init(); - Two::move_from(&mut __v, { &mut t }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut t }); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == ((base_moves) + (2)))); diff --git a/tests/unit/out/unsafe/structured_binding_move_ctor.rs b/tests/unit/out/unsafe/structured_binding_move_ctor.rs index 399d57d9ef..0d554ad015 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -9,7 +9,16 @@ use std::rc::Rc; pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, + Default, +)] pub struct Movable { pub x: i32, pub y: i32, @@ -19,12 +28,16 @@ impl Movable { (&raw mut self.x).write(x); (&raw mut self.y).write(y); } - pub unsafe fn copy_from(&mut self, other: *const Movable) { +} +impl CopyConstructibleUnsafe for Movable { + unsafe fn copy_constructor(&mut self, other: *const Movable) { (&raw mut self.x).write((*other).x); (&raw mut self.y).write((*other).y); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } - pub unsafe fn move_from(&mut self, other: *mut Movable) { +} +impl MoveConstructibleUnsafe for Movable { + unsafe fn move_constructor(&mut self, other: *mut Movable) { (&raw mut self.x).write((*other).x); (&raw mut self.y).write((*other).y); (*other).x = 0; @@ -36,14 +49,22 @@ impl Clone for Movable { fn clone(&self) -> Self { unsafe { let mut __v: Movable = ::zero_init(); - Movable::copy_from(&mut __v, self as *const Movable); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Movable); __v } } } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Holder { pub xs: Vec, @@ -56,11 +77,15 @@ impl Holder { ys: std::mem::take(&mut self.ys), }; } - pub unsafe fn move_from(&mut self, _a0: *mut Holder) { +} +impl MoveConstructibleUnsafe for Holder { + unsafe fn move_constructor(&mut self, _a0: *mut Holder) { (&raw mut self.xs).write(std::mem::take(&mut (*_a0).xs)); (&raw mut self.ys).write(std::mem::take(&mut (*_a0).ys)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { +} +impl MoveAssignableUnsafe for Holder { + unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { { self.xs = std::mem::take(&mut (*_a0).xs); }; @@ -84,7 +109,7 @@ unsafe fn main_0() -> i32 { }; let mut __decomp_2: Movable = { let mut __v: Movable = ::zero_init(); - Movable::move_from(&mut __v, { &mut m }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut m }); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (1))); diff --git a/tests/unit/out/unsafe/structured_binding_range_for.rs b/tests/unit/out/unsafe/structured_binding_range_for.rs index dbadfe57a2..fc845b2d96 100644 --- a/tests/unit/out/unsafe/structured_binding_range_for.rs +++ b/tests/unit/out/unsafe/structured_binding_range_for.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub first: i32, pub second: i32, diff --git a/tests/unit/out/unsafe/structured_binding_ref.rs b/tests/unit/out/unsafe/structured_binding_ref.rs index e2d3b5c4d3..86de454fa1 100644 --- a/tests/unit/out/unsafe/structured_binding_ref.rs +++ b/tests/unit/out/unsafe/structured_binding_ref.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Triple { pub a: i32, pub b: bool, diff --git a/tests/unit/out/unsafe/structured_binding_trivial.rs b/tests/unit/out/unsafe/structured_binding_trivial.rs index 0aeb2330ef..e295e8c2fe 100644 --- a/tests/unit/out/unsafe/structured_binding_trivial.rs +++ b/tests/unit/out/unsafe/structured_binding_trivial.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub first: i32, pub second: i32, diff --git a/tests/unit/out/unsafe/swap_malloc.rs b/tests/unit/out/unsafe/swap_malloc.rs index 9a58e43bed..651cd66930 100644 --- a/tests/unit/out/unsafe/swap_malloc.rs +++ b/tests/unit/out/unsafe/swap_malloc.rs @@ -19,41 +19,73 @@ unsafe fn main_0() -> i32 { (*buf.offset((0) as isize)) = 1; (*buf.offset((1) as isize)) = 2; (*buf.offset((2) as isize)) = 3; - cpp_swap_unsafe!(buf.offset((0) as isize), buf.offset((2) as isize)); + { + let __a: *mut i32 = buf.offset((0) as isize); + let __b: *mut i32 = buf.offset((2) as isize); + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!( (((*buf.offset((0) as isize)) == (3)) && ((*buf.offset((1) as isize)) == (2))) && ((*buf.offset((2) as isize)) == (1)) ); - cpp_swap_unsafe!(buf.offset((1) as isize), buf.offset((1) as isize)); + { + let __a: *mut i32 = buf.offset((1) as isize); + let __b: *mut i32 = buf.offset((1) as isize); + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((*buf.offset((1) as isize)) == (2))); let mut local: i32 = 4; - cpp_swap_unsafe!(buf.offset((1) as isize), &mut local); + { + let __a: *mut i32 = buf.offset((1) as isize); + let __b: *mut i32 = &mut local; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((*buf.offset((1) as isize)) == (4)) && ((local) == (2))); let mut other: *mut i32 = ((libcc2rs::malloc_unsafe(::std::mem::size_of::())) as *mut i32); (*other) = 5; - cpp_swap_unsafe!(buf, other); + { + let __a: *mut i32 = buf; + let __b: *mut i32 = other; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((*buf.offset((0) as isize)) == (5)) && ((*other) == (3))); let mut bytes: *mut u8 = (buf as *mut u8); (*bytes.offset((0) as isize)) = 170_u8; (*bytes.offset((4) as isize)) = 187_u8; - cpp_swap_unsafe!(bytes.offset((0) as isize), bytes.offset((4) as isize)); + { + let __a: *mut u8 = bytes.offset((0) as isize); + let __b: *mut u8 = bytes.offset((4) as isize); + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!( (((*bytes.offset((0) as isize)) as i32) == (187)) && (((*bytes.offset((4) as isize)) as i32) == (170)) ); let mut words: [u32; 2] = [16909060_u32, 84281096_u32]; let mut halves: *mut u16 = (words.as_mut_ptr() as *mut u16); - cpp_swap_unsafe!(halves.offset((0) as isize), halves.offset((3) as isize)); + { + let __a: *mut u16 = halves.offset((0) as isize); + let __b: *mut u16 = halves.offset((3) as isize); + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((words[(0) as usize]) == (16909574_u32)) && ((words[(1) as usize]) == (50595592_u32))); let mut s1: i32 = 1; let mut s2: i32 = 2; let mut sp: *mut i32 = (&mut s1 as *mut i32); let mut sq: *mut i32 = (&mut s2 as *mut i32); - cpp_swap_unsafe!(&mut sp, &mut sq); + { + let __a: *mut *mut i32 = &mut sp; + let __b: *mut *mut i32 = &mut sq; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((sp) == (&mut s2 as *mut i32)) && ((sq) == (&mut s1 as *mut i32))); assert!(((s1) == (1)) && ((s2) == (2))); let mut null_ptr: *mut i32 = std::ptr::null_mut(); - cpp_swap_unsafe!(&mut null_ptr, &mut sp); + { + let __a: *mut *mut i32 = &mut null_ptr; + let __b: *mut *mut i32 = &mut sp; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((null_ptr) == (&mut s2 as *mut i32)) && ((sp).is_null())); libcc2rs::free_unsafe((other as *mut ::libc::c_void)); libcc2rs::free_unsafe((buf as *mut ::libc::c_void)); diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index f824eb7c11..d70df0d482 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -9,13 +9,7 @@ use std::rc::Rc; pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - VaArg, - FnPtrArg, - ZeroInitializationUnsafe, - MoveCtorUnsafe, - CppFromUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, + VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, )] #[cpp_from(i32, construct_1, value)] pub struct Tracked { @@ -28,19 +22,27 @@ impl Tracked { pub unsafe fn construct_1(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, o: *const Tracked) { +} +impl CopyConstructibleUnsafe for Tracked { + unsafe fn copy_constructor(&mut self, o: *const Tracked) { (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } - pub unsafe fn move_from(&mut self, o: *mut Tracked) { +} +impl MoveConstructibleUnsafe for Tracked { + unsafe fn move_constructor(&mut self, o: *mut Tracked) { (&raw mut self.v).write((*o).v); } - pub unsafe fn copy_assign(&mut self, o: *const Tracked) -> *mut Tracked { +} +impl CopyAssignableUnsafe for Tracked { + unsafe fn copy_assign(&mut self, o: *const Tracked) -> *mut Tracked { self.v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*(self as *mut Tracked)); } - pub unsafe fn move_assign(&mut self, o: *mut Tracked) -> *mut Tracked { +} +impl MoveAssignableUnsafe for Tracked { + unsafe fn move_assign(&mut self, o: *mut Tracked) -> *mut Tracked { self.v = (*o).v; return &mut (*(self as *mut Tracked)); } @@ -49,7 +51,7 @@ impl Clone for Tracked { fn clone(&self) -> Self { unsafe { let mut __v: Tracked = ::zero_init(); - Tracked::copy_from(&mut __v, self as *const Tracked); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Tracked); __v } } @@ -71,47 +73,51 @@ impl Default for Tracked { VaArg, FnPtrArg, ZeroInitializationUnsafe, - MoveCtorUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + SwappableUnsafe, Default, )] pub struct Pair { pub x: Tracked, pub y: Tracked, } -impl Pair { - pub unsafe fn move_from(&mut self, _a0: *mut Pair) { +impl MoveConstructibleUnsafe for Pair { + unsafe fn move_constructor(&mut self, _a0: *mut Pair) { (&raw mut self.x).write({ let mut __v: Tracked = ::zero_init(); - Tracked::move_from(&mut __v, { &mut (*_a0).x }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).x }); __v }); (&raw mut self.y).write({ let mut __v: Tracked = ::zero_init(); - Tracked::move_from(&mut __v, { &mut (*_a0).y }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).y }); __v }); } - pub unsafe fn copy_assign(&mut self, _a0: *const Pair) -> *mut Pair { +} +impl CopyAssignableUnsafe for Pair { + unsafe fn copy_assign(&mut self, _a0: *const Pair) -> *mut Pair { (unsafe { let _o: *const Tracked = &(*_a0).x; - Tracked::copy_assign(&mut self.x, _o) + CopyAssignableUnsafe::copy_assign(&mut self.x, _o) }); (unsafe { let _o: *const Tracked = &(*_a0).y; - Tracked::copy_assign(&mut self.y, _o) + CopyAssignableUnsafe::copy_assign(&mut self.y, _o) }); return &mut (*(self as *mut Pair)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Pair) -> *mut Pair { +} +impl MoveAssignableUnsafe for Pair { + unsafe fn move_assign(&mut self, _a0: *mut Pair) -> *mut Pair { (unsafe { let _o: *mut Tracked = &mut (*_a0).x; - Tracked::move_assign(&mut self.x, _o) + MoveAssignableUnsafe::move_assign(&mut self.x, _o) }); (unsafe { let _o: *mut Tracked = &mut (*_a0).y; - Tracked::move_assign(&mut self.y, _o) + MoveAssignableUnsafe::move_assign(&mut self.y, _o) }); return &mut (*(self as *mut Pair)); } @@ -122,36 +128,38 @@ impl Pair { VaArg, FnPtrArg, ZeroInitializationUnsafe, - MoveCtorUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + SwappableUnsafe, Default, )] pub struct Arrays { pub a: [Tracked; 2], pub b: [Tracked; 2], } -impl Arrays { - pub unsafe fn move_from(&mut self, _a0: *mut Arrays) { +impl MoveConstructibleUnsafe for Arrays { + unsafe fn move_constructor(&mut self, _a0: *mut Arrays) { (&raw mut self.a).write(std::array::from_fn::<_, 2, _>(|__i: usize| { let mut __v: Tracked = ::zero_init(); - Tracked::move_from(&mut __v, { &mut (*_a0).a[(__i)] }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).a[(__i)] }); __v })); (&raw mut self.b).write(std::array::from_fn::<_, 2, _>(|__i: usize| { let mut __v: Tracked = ::zero_init(); - Tracked::move_from(&mut __v, { &mut (*_a0).b[(__i)] }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).b[(__i)] }); __v })); } - pub unsafe fn copy_assign(&mut self, _a0: *const Arrays) -> *mut Arrays { +} +impl CopyAssignableUnsafe for Arrays { + unsafe fn copy_assign(&mut self, _a0: *const Arrays) -> *mut Arrays { { let mut __i0: usize = 0_usize; 'loop_: while ((__i0) != (2_usize)) { 'for_body: { (unsafe { let _o: *const Tracked = &(*_a0).a[(__i0)]; - Tracked::copy_assign(&mut self.a[(__i0)], _o) + CopyAssignableUnsafe::copy_assign(&mut self.a[(__i0)], _o) }); } __i0.prefix_inc(); @@ -163,7 +171,7 @@ impl Arrays { 'for_body: { (unsafe { let _o: *const Tracked = &(*_a0).b[(__i0)]; - Tracked::copy_assign(&mut self.b[(__i0)], _o) + CopyAssignableUnsafe::copy_assign(&mut self.b[(__i0)], _o) }); } __i0.prefix_inc(); @@ -171,14 +179,16 @@ impl Arrays { } return &mut (*(self as *mut Arrays)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Arrays) -> *mut Arrays { +} +impl MoveAssignableUnsafe for Arrays { + unsafe fn move_assign(&mut self, _a0: *mut Arrays) -> *mut Arrays { { let mut __i0: usize = 0_usize; 'loop_: while ((__i0) != (2_usize)) { 'for_body: { (unsafe { let _o: *mut Tracked = &mut (*_a0).a[(__i0)]; - Tracked::move_assign(&mut self.a[(__i0)], _o) + MoveAssignableUnsafe::move_assign(&mut self.a[(__i0)], _o) }); } __i0.prefix_inc(); @@ -190,7 +200,7 @@ impl Arrays { 'for_body: { (unsafe { let _o: *mut Tracked = &mut (*_a0).b[(__i0)]; - Tracked::move_assign(&mut self.b[(__i0)], _o) + MoveAssignableUnsafe::move_assign(&mut self.b[(__i0)], _o) }); } __i0.prefix_inc(); @@ -204,15 +214,7 @@ pub static mut copy_only_copies_1: std::cell::LazyCell = pub static mut copy_only_dtors_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive( - VaArg, - FnPtrArg, - ZeroInitializationUnsafe, - CppFromUnsafe, - CopyAssignUnsafe, - DestructibleUnsafe, - Default, -)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, MovableUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct CopyOnly { pub v: i32, @@ -221,14 +223,20 @@ impl CopyOnly { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, o: *const CopyOnly) { +} +impl CopyConstructibleUnsafe for CopyOnly { + unsafe fn copy_constructor(&mut self, o: *const CopyOnly) { (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)).prefix_inc(); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for CopyOnly { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_dtors_2)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, o: *const CopyOnly) -> *mut CopyOnly { +} +impl CopyAssignableUnsafe for CopyOnly { + unsafe fn copy_assign(&mut self, o: *const CopyOnly) -> *mut CopyOnly { self.v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)).prefix_inc(); return &mut (*(self as *mut CopyOnly)); @@ -238,53 +246,49 @@ impl Clone for CopyOnly { fn clone(&self) -> Self { unsafe { let mut __v: CopyOnly = ::zero_init(); - CopyOnly::copy_from(&mut __v, self as *const CopyOnly); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const CopyOnly); __v } } } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, )] pub struct CopyOnlyPair { pub x: CopyOnly, pub y: CopyOnly, } -impl CopyOnlyPair { - pub unsafe fn copy_assign(&mut self, _a0: *const CopyOnlyPair) -> *mut CopyOnlyPair { +impl CopyAssignableUnsafe for CopyOnlyPair { + unsafe fn copy_assign(&mut self, _a0: *const CopyOnlyPair) -> *mut CopyOnlyPair { (unsafe { let _o: *const CopyOnly = &(*_a0).x; - CopyOnly::copy_assign(&mut self.x, _o) + CopyAssignableUnsafe::copy_assign(&mut self.x, _o) }); (unsafe { let _o: *const CopyOnly = &(*_a0).y; - CopyOnly::copy_assign(&mut self.y, _o) + CopyAssignableUnsafe::copy_assign(&mut self.y, _o) }); return &mut (*(self as *mut CopyOnlyPair)); } } -impl CopyOnlyPair { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.y); - DestructibleUnsafe::destroy(&raw mut self.x); +impl DestructibleUnsafe for CopyOnlyPair { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.y); + DestructibleUnsafe::destroy(&mut self.x); } } pub static mut moves_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); 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, - MoveCtorUnsafe, - CppFromUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, - DestructibleUnsafe, - Default, -)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, SwappableUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct Moved { pub v: i32, @@ -293,27 +297,37 @@ impl Moved { pub unsafe fn construct(&mut self, mut v: i32) { (&raw mut self.v).write(v); } - pub unsafe fn copy_from(&mut self, o: *const Moved) { +} +impl CopyConstructibleUnsafe for Moved { + unsafe fn copy_constructor(&mut self, o: *const Moved) { (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } - pub unsafe fn move_from(&mut self, o: *mut Moved) { +} +impl MoveConstructibleUnsafe for Moved { + unsafe fn move_constructor(&mut self, o: *mut Moved) { (&raw mut self.v).write((*o).v); (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); } - pub unsafe fn copy_assign(&mut self, o: *const Moved) -> *mut Moved { +} +impl CopyAssignableUnsafe for Moved { + unsafe fn copy_assign(&mut self, o: *const Moved) -> *mut Moved { self.v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*(self as *mut Moved)); } - pub unsafe fn move_assign(&mut self, o: *mut Moved) -> *mut Moved { +} +impl MoveAssignableUnsafe for Moved { + unsafe fn move_assign(&mut self, o: *mut Moved) -> *mut Moved { self.v = (*o).v; (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)).prefix_inc(); return &mut (*(self as *mut Moved)); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for Moved { + unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)).prefix_inc(); } } @@ -321,7 +335,7 @@ impl Clone for Moved { fn clone(&self) -> Self { unsafe { let mut __v: Moved = ::zero_init(); - Moved::copy_from(&mut __v, self as *const Moved); + CopyConstructibleUnsafe::copy_constructor(&mut __v, self as *const Moved); __v } } @@ -332,56 +346,58 @@ impl Clone for Moved { VaArg, FnPtrArg, ZeroInitializationUnsafe, - MoveCtorUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, - DestructibleUnsafe, + CopyConstructibleUnsafe, + SwappableUnsafe, Default, )] pub struct MovedPair { pub x: Moved, pub y: Moved, } -impl MovedPair { - pub unsafe fn move_from(&mut self, _a0: *mut MovedPair) { +impl MoveConstructibleUnsafe for MovedPair { + unsafe fn move_constructor(&mut self, _a0: *mut MovedPair) { (&raw mut self.x).write({ let mut __v: Moved = ::zero_init(); - Moved::move_from(&mut __v, { &mut (*_a0).x }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).x }); __v }); (&raw mut self.y).write({ let mut __v: Moved = ::zero_init(); - Moved::move_from(&mut __v, { &mut (*_a0).y }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).y }); __v }); } - pub unsafe fn copy_assign(&mut self, _a0: *const MovedPair) -> *mut MovedPair { +} +impl CopyAssignableUnsafe for MovedPair { + unsafe fn copy_assign(&mut self, _a0: *const MovedPair) -> *mut MovedPair { (unsafe { let _o: *const Moved = &(*_a0).x; - Moved::copy_assign(&mut self.x, _o) + CopyAssignableUnsafe::copy_assign(&mut self.x, _o) }); (unsafe { let _o: *const Moved = &(*_a0).y; - Moved::copy_assign(&mut self.y, _o) + CopyAssignableUnsafe::copy_assign(&mut self.y, _o) }); return &mut (*(self as *mut MovedPair)); } - pub unsafe fn move_assign(&mut self, _a0: *mut MovedPair) -> *mut MovedPair { +} +impl MoveAssignableUnsafe for MovedPair { + unsafe fn move_assign(&mut self, _a0: *mut MovedPair) -> *mut MovedPair { (unsafe { let _o: *mut Moved = &mut (*_a0).x; - Moved::move_assign(&mut self.x, _o) + MoveAssignableUnsafe::move_assign(&mut self.x, _o) }); (unsafe { let _o: *mut Moved = &mut (*_a0).y; - Moved::move_assign(&mut self.y, _o) + MoveAssignableUnsafe::move_assign(&mut self.y, _o) }); return &mut (*(self as *mut MovedPair)); } } -impl MovedPair { - pub unsafe fn destructor(&mut self) { - DestructibleUnsafe::destroy(&raw mut self.y); - DestructibleUnsafe::destroy(&raw mut self.x); +impl DestructibleUnsafe for MovedPair { + unsafe fn destroy(&mut self) { + DestructibleUnsafe::destroy(&mut self.y); + DestructibleUnsafe::destroy(&mut self.x); } } pub unsafe fn swapped_once_6() -> bool { @@ -398,15 +414,17 @@ pub unsafe fn swapped_once_6() -> bool { return ok; } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct Owner { pub p: Option>, } -impl Owner { - pub unsafe fn move_from(&mut self, _a0: *mut Owner) { +impl MoveConstructibleUnsafe for Owner { + unsafe fn move_constructor(&mut self, _a0: *mut Owner) { (&raw mut self.p).write((*_a0).p.take()); } - pub unsafe fn move_assign(&mut self, _a0: *mut Owner) -> *mut Owner { +} +impl MoveAssignableUnsafe for Owner { + unsafe fn move_assign(&mut self, _a0: *mut Owner) -> *mut Owner { { self.p = (*_a0).p.take(); }; @@ -430,7 +448,11 @@ unsafe fn main_0() -> i32 { Tracked::construct_1(&mut __v, { 2 }); __v }; - cpp_swap_unsafe!(&mut a, &mut b); + { + let __a: *mut Tracked = &mut a; + let __b: *mut Tracked = &mut b; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((a.v) == (2)) && ((b.v) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut m1: UnsafeMap = UnsafeMap::new(); @@ -440,7 +462,7 @@ unsafe fn main_0() -> i32 { Tracked::construct_1(&mut __v, { 10 }); __v }; - Tracked::move_assign( + MoveAssignableUnsafe::move_assign( &mut (*m1.subscript_move(&mut 1, |__k| cpp_move_unsafe!(__k), || ::default())), &mut _o, ) @@ -451,7 +473,7 @@ unsafe fn main_0() -> i32 { Tracked::construct_1(&mut __v, { 20 }); __v }; - Tracked::move_assign( + MoveAssignableUnsafe::move_assign( &mut (*m1.subscript_move(&mut 2, |__k| cpp_move_unsafe!(__k), || ::default())), &mut _o, ) @@ -463,16 +485,19 @@ unsafe fn main_0() -> i32 { Tracked::construct_1(&mut __v, { 30 }); __v }; - Tracked::move_assign( + MoveAssignableUnsafe::move_assign( &mut (*m2.subscript_move(&mut 3, |__k| cpp_move_unsafe!(__k), || ::default())), &mut _o, ) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); - cpp_swap_unsafe!( - &mut (*m1.subscript_move(&mut 1, |__k| cpp_move_unsafe!(__k), || ::default())), - &mut (*m1.subscript_move(&mut 2, |__k| cpp_move_unsafe!(__k), || ::default())) - ); + { + let __a: *mut Tracked = + &mut (*m1.subscript_move(&mut 1, |__k| cpp_move_unsafe!(__k), || ::default())); + let __b: *mut Tracked = + &mut (*m1.subscript_move(&mut 2, |__k| cpp_move_unsafe!(__k), || ::default())); + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!( (((*m1.subscript_move(&mut 1, |__k| cpp_move_unsafe!(__k), || ::default())).v) == (20)) @@ -484,7 +509,11 @@ unsafe fn main_0() -> i32 { .v) == (10)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); - cpp_swap_unsafe!(&mut m1, &mut m2); + { + let __a: *mut UnsafeMap = &mut m1; + let __b: *mut UnsafeMap = &mut m2; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!( ((m1.len()) == (1_usize)) && (((*m1.subscript_move( @@ -527,9 +556,17 @@ unsafe fn main_0() -> i32 { __v }, ]; - cpp_swap_unsafe!(&mut arr[(0) as usize], &mut arr[(2) as usize]); + { + let __a: *mut Tracked = &mut arr[(0) as usize]; + let __b: *mut Tracked = &mut arr[(2) as usize]; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((arr[(0) as usize].v) == (3)) && ((arr[(2) as usize].v) == (1))); - cpp_swap_unsafe!(&mut arr[(1) as usize], &mut arr[(1) as usize]); + { + let __a: *mut Tracked = &mut arr[(1) as usize]; + let __b: *mut Tracked = &mut arr[(1) as usize]; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((arr[(1) as usize].v) == (2))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut vec_: Vec = Vec::new(); @@ -543,7 +580,11 @@ unsafe fn main_0() -> i32 { Tracked::construct_1(&mut __v, { 5 }); __v }); - cpp_swap_unsafe!(&mut vec_[(0_usize)], &mut vec_[(1_usize)]); + { + let __a: *mut Tracked = &mut vec_[(0_usize)]; + let __b: *mut Tracked = &mut vec_[(1_usize)]; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((vec_[(0_usize)].v) == (5)) && ((vec_[(1_usize)].v) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut pairs: [Pair; 2] = [ @@ -584,22 +625,46 @@ unsafe fn main_0() -> i32 { __v }, }; - cpp_swap_unsafe!(&mut pairs[(0) as usize].x, &mut p.y); + { + let __a: *mut Tracked = &mut pairs[(0) as usize].x; + let __b: *mut Tracked = &mut p.y; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((pairs[(0) as usize].x.v) == (11)) && ((p.y.v) == (6))); - cpp_swap_unsafe!(&mut pairs[(0) as usize], &mut pairs[(1) as usize]); + { + let __a: *mut Pair = &mut pairs[(0) as usize]; + let __b: *mut Pair = &mut pairs[(1) as usize]; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((pairs[(0) as usize].x.v) == (8)) && ((pairs[(1) as usize].x.v) == (11))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); - cpp_swap_unsafe!(&mut p.x, &mut p.y); + { + let __a: *mut Tracked = &mut p.x; + let __b: *mut Tracked = &mut p.y; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((p.x.v) == (6)) && ((p.y.v) == (10))); - cpp_swap_unsafe!(&mut pairs[(0) as usize].x, &mut pairs[(1) as usize].y); + { + let __a: *mut Tracked = &mut pairs[(0) as usize].x; + let __b: *mut Tracked = &mut pairs[(1) as usize].y; + SwappableUnsafe::swap(&mut *__a, __b) + }; 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(); arrays.a[(0) as usize].v = 1; arrays.b[(1) as usize].v = 2; - cpp_swap_unsafe!(&mut arrays.a[(0) as usize], &mut arrays.b[(1) as usize]); + { + let __a: *mut Tracked = &mut arrays.a[(0) as usize]; + let __b: *mut Tracked = &mut arrays.b[(1) as usize]; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((arrays.a[(0) as usize].v) == (2)) && ((arrays.b[(1) as usize].v) == (1))); - cpp_swap_unsafe!(&mut arrays.a[(0) as usize], &mut arrays.a[(1) as usize]); + { + let __a: *mut Tracked = &mut arrays.a[(0) as usize]; + let __b: *mut Tracked = &mut arrays.a[(1) as usize]; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((arrays.a[(0) as usize].v) == (0)) && ((arrays.a[(1) as usize].v) == (2))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut grid: Vec> = Vec::from_fn(2_usize, |_| Default::default()); @@ -618,12 +683,17 @@ unsafe fn main_0() -> i32 { Tracked::construct_1(&mut __v, { 3 }); __v }); - cpp_swap_unsafe!( - &mut grid[(0_usize)][(1_usize)], - &mut grid[(1_usize)][(0_usize)] - ); + { + let __a: *mut Tracked = &mut grid[(0_usize)][(1_usize)]; + let __b: *mut Tracked = &mut grid[(1_usize)][(0_usize)]; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((grid[(0_usize)][(1_usize)].v) == (3)) && ((grid[(1_usize)][(0_usize)].v) == (2))); - cpp_swap_unsafe!(&mut grid[(0_usize)], &mut grid[(1_usize)]); + { + let __a: *mut Vec = &mut grid[(0_usize)]; + let __b: *mut Vec = &mut grid[(1_usize)]; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((grid[(0_usize)].len()) == (1_usize)) && ((grid[(0_usize)][(0_usize)].v) == (2))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut maps: [UnsafeMap; 2] = @@ -634,7 +704,7 @@ unsafe fn main_0() -> i32 { Tracked::construct_1(&mut __v, { 1 }); __v }; - Tracked::move_assign( + MoveAssignableUnsafe::move_assign( &mut (*maps[(0) as usize].subscript_move( &mut 1, |__k| cpp_move_unsafe!(__k), @@ -649,7 +719,7 @@ unsafe fn main_0() -> i32 { Tracked::construct_1(&mut __v, { 2 }); __v }; - Tracked::move_assign( + MoveAssignableUnsafe::move_assign( &mut (*maps[(1) as usize].subscript_move( &mut 2, |__k| cpp_move_unsafe!(__k), @@ -658,7 +728,11 @@ unsafe fn main_0() -> i32 { &mut _o, ) }); - cpp_swap_unsafe!(&mut maps[(0) as usize], &mut maps[(1) as usize]); + { + let __a: *mut UnsafeMap = &mut maps[(0) as usize]; + let __b: *mut UnsafeMap = &mut maps[(1) as usize]; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!( ((maps[(0) as usize].len()) == (1_usize)) && (((*maps[(0) as usize].subscript_move( @@ -684,7 +758,7 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_c1 = std::mem::DropGuard::new(&raw mut c1, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut c2: CopyOnly = { let mut __v: CopyOnly = ::zero_init(); @@ -692,9 +766,13 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_c2 = std::mem::DropGuard::new(&raw mut c2, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); - cpp_swap_unsafe!(&mut c1, &mut c2); + { + let __a: *mut CopyOnly = &mut c1; + let __b: *mut CopyOnly = &mut c2; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((c1.v) == (2)) && ((c2.v) == (1))); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)) == (3)) @@ -713,9 +791,13 @@ unsafe fn main_0() -> i32 { }, }; let _dtor_cp = std::mem::DropGuard::new(&raw mut cp, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); - cpp_swap_unsafe!(&mut cp.x, &mut cp.y); + { + let __a: *mut CopyOnly = &mut cp.x; + let __b: *mut CopyOnly = &mut cp.y; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((cp.x.v) == (4)) && ((cp.y.v) == (3))); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)) == (6)) @@ -733,7 +815,11 @@ unsafe fn main_0() -> i32 { __v }, ]; - cpp_swap_unsafe!(&mut carr[(0) as usize], &mut carr[(1) as usize]); + { + let __a: *mut CopyOnly = &mut carr[(0) as usize]; + let __b: *mut CopyOnly = &mut carr[(1) as usize]; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((carr[(0) as usize].v) == (6)) && ((carr[(1) as usize].v) == (5))); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)) == (9)) @@ -745,7 +831,7 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_mv1 = std::mem::DropGuard::new(&raw mut mv1, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut mv2: Moved = { let mut __v: Moved = ::zero_init(); @@ -753,9 +839,13 @@ unsafe fn main_0() -> i32 { __v }; let _dtor_mv2 = std::mem::DropGuard::new(&raw mut mv2, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); - cpp_swap_unsafe!(&mut mv1, &mut mv2); + { + let __a: *mut Moved = &mut mv1; + let __b: *mut Moved = &mut mv2; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((mv1.v) == (2)) && ((mv2.v) == (1))); assert!((unsafe { swapped_once_6() })); let mut mp: MovedPair = MovedPair { @@ -771,9 +861,13 @@ unsafe fn main_0() -> i32 { }, }; let _dtor_mp = std::mem::DropGuard::new(&raw mut mp, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); - cpp_swap_unsafe!(&mut mp.x, &mut mp.y); + { + let __a: *mut Moved = &mut mp.x; + let __b: *mut Moved = &mut mp.y; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((mp.x.v) == (4)) && ((mp.y.v) == (3))); assert!((unsafe { swapped_once_6() })); let mut marr: [Moved; 2] = [ @@ -788,10 +882,18 @@ unsafe fn main_0() -> i32 { __v }, ]; - cpp_swap_unsafe!(&mut marr[(0) as usize], &mut marr[(1) as usize]); + { + let __a: *mut Moved = &mut marr[(0) as usize]; + let __b: *mut Moved = &mut marr[(1) as usize]; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((marr[(0) as usize].v) == (6)) && ((marr[(1) as usize].v) == (5))); assert!((unsafe { swapped_once_6() })); - cpp_swap_unsafe!(&mut mv1, &mut mv1); + { + let __a: *mut Moved = &mut mv1; + let __b: *mut Moved = &mut mv1; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!(((mv1.v) == (2))); assert!((unsafe { swapped_once_6() })); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); @@ -801,7 +903,11 @@ unsafe fn main_0() -> i32 { let mut o2: Owner = Owner { p: Some(Box::new(2)), }; - cpp_swap_unsafe!(&mut o1, &mut o2); + { + let __a: *mut Owner = &mut o1; + let __b: *mut Owner = &mut o2; + SwappableUnsafe::swap(&mut *__a, __b) + }; assert!( ((*o1 .p diff --git a/tests/unit/out/unsafe/tag_vs_identifier_collision.rs b/tests/unit/out/unsafe/tag_vs_identifier_collision.rs index f42c07b866..0a102a8f47 100644 --- a/tests/unit/out/unsafe/tag_vs_identifier_collision.rs +++ b/tests/unit/out/unsafe/tag_vs_identifier_collision.rs @@ -11,19 +11,39 @@ 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; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct widget { pub id: i32, pub mode: widget_enum, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct point_struct { pub x: i32, pub y: i32, } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union point { pub whole: i32, pub half: i16, @@ -34,7 +54,9 @@ impl Default for point { } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union slot_union { pub i: i32, pub u: u32, @@ -48,17 +70,44 @@ pub type slot = u32; pub const slot_SLOT_A: slot = 0; pub const slot_SLOT_B: slot = 1; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub tag_field: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer { pub field: Inner, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 a7643f888b..95c9bfd0b5 100644 --- a/tests/unit/out/unsafe/template_default_arg.rs +++ b/tests/unit/out/unsafe/template_default_arg.rs @@ -7,7 +7,16 @@ 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, CppFromUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, +)] #[cpp_from(i32, construct_1, value)] pub struct A { pub v: i32, @@ -32,7 +41,9 @@ impl Default for A { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct B { pub v: i32, } @@ -53,7 +64,17 @@ impl Default for B { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct NoDefault { pub v: i32, @@ -76,7 +97,17 @@ pub unsafe fn always_given_3(mut x: NoDefault) -> i32 { return x.v; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct S_NoDefault_ { pub v: i32, diff --git a/tests/unit/out/unsafe/template_static_member.rs b/tests/unit/out/unsafe/template_static_member.rs index f608130a07..efa4c745bc 100644 --- a/tests/unit/out/unsafe/template_static_member.rs +++ b/tests/unit/out/unsafe/template_static_member.rs @@ -8,27 +8,72 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Range_int_ {} pub static mut lo_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { (-2_i32 as i64) }); pub static mut hi_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 2_i64 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Range_long_ {} pub fn main() { unsafe { diff --git a/tests/unit/out/unsafe/temporary_field_addr.rs b/tests/unit/out/unsafe/temporary_field_addr.rs index 6f3be4b293..fa1bbe7181 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -8,16 +8,26 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Inner { pub values: Vec, } -impl Inner { - pub unsafe fn move_from(&mut self, _a0: *mut Inner) { +impl MoveConstructibleUnsafe for Inner { + unsafe fn move_constructor(&mut self, _a0: *mut Inner) { (&raw mut self.values).write(std::mem::take(&mut (*_a0).values)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Inner) -> *mut Inner { +} +impl MoveAssignableUnsafe for Inner { + unsafe fn move_assign(&mut self, _a0: *mut Inner) -> *mut Inner { { self.values = std::mem::take(&mut (*_a0).values); }; @@ -26,32 +36,42 @@ impl Inner { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Outer { pub values: Vec, pub inner: Inner, pub name: [libc::c_char; 8], } -impl Outer { - pub unsafe fn move_from(&mut self, _a0: *mut Outer) { +impl MoveConstructibleUnsafe for Outer { + unsafe fn move_constructor(&mut self, _a0: *mut Outer) { (&raw mut self.values).write(std::mem::take(&mut (*_a0).values)); (&raw mut self.inner).write({ let mut __v: Inner = ::zero_init(); - Inner::move_from(&mut __v, { &mut (*_a0).inner }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).inner }); __v }); (&raw mut self.name).write(std::array::from_fn::<_, 8, _>(|__i: usize| { (*_a0).name[(__i)] })); } - pub unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { +} +impl MoveAssignableUnsafe for Outer { + unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { { self.values = std::mem::take(&mut (*_a0).values); }; (unsafe { let _arg0: *mut Inner = &mut (*_a0).inner; - Inner::move_assign(&mut self.inner, _arg0) + MoveAssignableUnsafe::move_assign(&mut self.inner, _arg0) }); { let mut __tmp_0 = diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index 333b326277..448aadef5e 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -8,16 +8,26 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Outer { pub values: Vec, } -impl Outer { - pub unsafe fn move_from(&mut self, _a0: *mut Outer) { +impl MoveConstructibleUnsafe for Outer { + unsafe fn move_constructor(&mut self, _a0: *mut Outer) { (&raw mut self.values).write(std::mem::take(&mut (*_a0).values)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { +} +impl MoveAssignableUnsafe for Outer { + unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { { self.values = std::mem::take(&mut (*_a0).values); }; @@ -30,7 +40,17 @@ pub unsafe fn make_0() -> Outer { }; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(Vec , construct, ptr)] pub struct H { pub last: i32, diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index c9d4edf8b5..9a2671bde2 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -8,16 +8,26 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Inner { pub values: Vec, } -impl Inner { - pub unsafe fn move_from(&mut self, _a0: *mut Inner) { +impl MoveConstructibleUnsafe for Inner { + unsafe fn move_constructor(&mut self, _a0: *mut Inner) { (&raw mut self.values).write(std::mem::take(&mut (*_a0).values)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Inner) -> *mut Inner { +} +impl MoveAssignableUnsafe for Inner { + unsafe fn move_assign(&mut self, _a0: *mut Inner) -> *mut Inner { { self.values = std::mem::take(&mut (*_a0).values); }; @@ -26,28 +36,38 @@ impl Inner { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Outer { pub values: Vec, pub inner: Inner, } -impl Outer { - pub unsafe fn move_from(&mut self, _a0: *mut Outer) { +impl MoveConstructibleUnsafe for Outer { + unsafe fn move_constructor(&mut self, _a0: *mut Outer) { (&raw mut self.values).write(std::mem::take(&mut (*_a0).values)); (&raw mut self.inner).write({ let mut __v: Inner = ::zero_init(); - Inner::move_from(&mut __v, { &mut (*_a0).inner }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*_a0).inner }); __v }); } - pub unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { +} +impl MoveAssignableUnsafe for Outer { + unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { { self.values = std::mem::take(&mut (*_a0).values); }; (unsafe { let _arg0: *mut Inner = &mut (*_a0).inner; - Inner::move_assign(&mut self.inner, _arg0) + MoveAssignableUnsafe::move_assign(&mut self.inner, _arg0) }); return &mut (*(self as *mut Outer)); } diff --git a/tests/unit/out/unsafe/this.rs b/tests/unit/out/unsafe/this.rs index 6685cbb12b..99d47f6dd3 100644 --- a/tests/unit/out/unsafe/this.rs +++ b/tests/unit/out/unsafe/this.rs @@ -7,7 +7,17 @@ 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, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct_1, value)] pub struct S { pub a_: i32, @@ -101,7 +111,17 @@ pub unsafe fn bump_0(mut p: *mut S) { (*p).a_.postfix_inc(); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct D { pub a_: i32, diff --git a/tests/unit/out/unsafe/typedef-anon-struct.rs b/tests/unit/out/unsafe/typedef-anon-struct.rs index 4bf4e7dbac..9809d326d9 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -7,23 +7,42 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer_RunInfo { pub block_idx: i32, pub num_extra_zero_runs: i32, } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Outer { pub runs: Vec, } -impl Outer { - pub unsafe fn move_from(&mut self, _a0: *mut Outer) { +impl MoveConstructibleUnsafe for Outer { + unsafe fn move_constructor(&mut self, _a0: *mut Outer) { (&raw mut self.runs).write(std::mem::take(&mut (*_a0).runs)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { +} +impl MoveAssignableUnsafe for Outer { + unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { { self.runs = std::mem::take(&mut (*_a0).runs); }; 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 f9706e575d..9e636e2ad0 100644 --- a/tests/unit/out/unsafe/unary_expr_or_type_trait.rs +++ b/tests/unit/out/unsafe/unary_expr_or_type_trait.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C, align(16))] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub c: libc::c_char, pub x: i64, diff --git a/tests/unit/out/unsafe/unboxed_locals.rs b/tests/unit/out/unsafe/unboxed_locals.rs index 26765ab651..bdaa13d7f4 100644 --- a/tests/unit/out/unsafe/unboxed_locals.rs +++ b/tests/unit/out/unsafe/unboxed_locals.rs @@ -13,7 +13,16 @@ pub unsafe fn inc_1(r: *mut i32) { (*r).prefix_inc(); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub first: i32, pub second: i32, @@ -51,7 +60,9 @@ pub unsafe trait Shape { unsafe fn scale(&mut self, factor: i32) -> i32; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, 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 ffc5ae1f61..b2ff9a2a4a 100644 --- a/tests/unit/out/unsafe/unboxed_records.rs +++ b/tests/unit/out/unsafe/unboxed_records.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub a: i32, pub b: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Cookie { pub x: i32, pub data: *mut i32, @@ -22,7 +40,9 @@ pub struct Cookie { pub arr: [i32; 4], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub struct Counter { pub n: i32, } diff --git a/tests/unit/out/unsafe/union_addrof_external.rs b/tests/unit/out/unsafe/union_addrof_external.rs index ce86efb8a0..583405c164 100644 --- a/tests/unit/out/unsafe/union_addrof_external.rs +++ b/tests/unit/out/unsafe/union_addrof_external.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct record { pub code: u16, pub lo: u16, @@ -15,7 +24,9 @@ pub struct record { pub pad: [libc::c_char; 8], } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_0 { pub h: record, pub raw_: [libc::c_char; 128], @@ -26,7 +37,16 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 033ee69b95..5e3631b289 100644 --- a/tests/unit/out/unsafe/union_basic.rs +++ b/tests/unit/out/unsafe/union_basic.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(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union basic { pub i: i32, pub f: f32, @@ -18,7 +20,9 @@ impl Default for basic { } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union empty { __empty: u8, } @@ -28,7 +32,9 @@ impl Default for empty { } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union underscores { pub __: i32, pub ___: f64, @@ -91,7 +97,9 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] 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 41e760b27a..95cbe7c41b 100644 --- a/tests/unit/out/unsafe/union_cross_arm_cast.rs +++ b/tests/unit/out/unsafe/union_cross_arm_cast.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct shape_a { pub code: u16, pub pad: [libc::c_char; 14], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct shape_b { pub code: u16, pub lo: u16, @@ -22,7 +40,9 @@ pub struct shape_b { pub tail: u32, } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_0 { pub a: shape_a, pub b: shape_b, @@ -34,7 +54,16 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Container { pub len: u32, pub u: anon_0, diff --git a/tests/unit/out/unsafe/union_field_alignment.rs b/tests/unit/out/unsafe/union_field_alignment.rs index b5d7319f40..b5eabbc966 100644 --- a/tests/unit/out/unsafe/union_field_alignment.rs +++ b/tests/unit/out/unsafe/union_field_alignment.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(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_0 { pub bytes: [u8; 1], pub aligner: *mut ::libc::c_void, @@ -18,7 +20,16 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct node { pub next: *mut node, pub x: anon_0, diff --git a/tests/unit/out/unsafe/union_flex_array_member.rs b/tests/unit/out/unsafe/union_flex_array_member.rs index 7a9fbe5437..036b79f72e 100644 --- a/tests/unit/out/unsafe/union_flex_array_member.rs +++ b/tests/unit/out/unsafe/union_flex_array_member.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(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_0 { pub bytes: [u8; 1], pub aligner: *mut ::libc::c_void, @@ -18,7 +20,16 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct node { pub len: usize, pub pos: usize, diff --git a/tests/unit/out/unsafe/union_memset_memcpy.rs b/tests/unit/out/unsafe/union_memset_memcpy.rs index 1f163c6dae..863410f1d5 100644 --- a/tests/unit/out/unsafe/union_memset_memcpy.rs +++ b/tests/unit/out/unsafe/union_memset_memcpy.rs @@ -7,13 +7,31 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct shape_a { pub code: u16, pub pad: [libc::c_char; 14], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct shape_b { pub code: u16, pub lo: u16, @@ -21,7 +39,9 @@ pub struct shape_b { pub fill: [libc::c_char; 8], } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_0 { pub a: shape_a, pub b: shape_b, @@ -33,7 +53,16 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 390e7c0e14..da8865c764 100644 --- a/tests/unit/out/unsafe/union_nested.rs +++ b/tests/unit/out/unsafe/union_nested.rs @@ -7,13 +7,24 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct record { pub code: u16, pub pad: [libc::c_char; 14], } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_0 { pub h: record, pub raw_: [libc::c_char; 128], @@ -24,12 +35,23 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct inner { pub view: anon_0, } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_1 { pub h: record, pub nested: inner, @@ -40,7 +62,16 @@ impl Default for anon_1 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Outer { pub kind: i32, pub level: i32, diff --git a/tests/unit/out/unsafe/union_pointer_pun_address.rs b/tests/unit/out/unsafe/union_pointer_pun_address.rs index 0afe442843..e5dc87af40 100644 --- a/tests/unit/out/unsafe/union_pointer_pun_address.rs +++ b/tests/unit/out/unsafe/union_pointer_pun_address.rs @@ -7,12 +7,30 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct node_a { pub n: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct node_b { pub data: *mut ::libc::c_void, pub next: *mut node_b, @@ -32,7 +50,9 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] 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 d0bf2b5109..55c72a4cf7 100644 --- a/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs +++ b/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs @@ -21,7 +21,9 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] 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 295c852b76..f1e97f226b 100644 --- a/tests/unit/out/unsafe/union_struct_dual_use.rs +++ b/tests/unit/out/unsafe/union_struct_dual_use.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub a: i32, pub b: i32, @@ -16,7 +25,9 @@ pub unsafe fn sum_inner_0(mut i: *mut Inner) -> i32 { return (((*i).a) + ((*i).b)); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_1 { pub inner: Inner, pub raw_: [libc::c_char; 16], @@ -27,7 +38,16 @@ impl Default for anon_1 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 650409ef66..680550d074 100644 --- a/tests/unit/out/unsafe/union_tagged_many_arms.rs +++ b/tests/unit/out/unsafe/union_tagged_many_arms.rs @@ -13,7 +13,9 @@ 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)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_0 { pub text: *const libc::c_char, pub handle: *mut ::libc::c_void, @@ -27,7 +29,16 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Slot { pub tag: Tag_enum, pub payload: anon_0, diff --git a/tests/unit/out/unsafe/union_tagged_simple.rs b/tests/unit/out/unsafe/union_tagged_simple.rs index 520b857b71..3bca5d919b 100644 --- a/tests/unit/out/unsafe/union_tagged_simple.rs +++ b/tests/unit/out/unsafe/union_tagged_simple.rs @@ -10,7 +10,9 @@ 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)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_0 { pub obj: *mut ::libc::c_void, pub code: i32, @@ -21,7 +23,16 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Event { pub kind: Kind_enum, pub handle: *mut ::libc::c_void, diff --git a/tests/unit/out/unsafe/union_tagged_struct_arms.rs b/tests/unit/out/unsafe/union_tagged_struct_arms.rs index 4f592783e7..c361a1f66d 100644 --- a/tests/unit/out/unsafe/union_tagged_struct_arms.rs +++ b/tests/unit/out/unsafe/union_tagged_struct_arms.rs @@ -11,14 +11,32 @@ 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; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_1 { pub items: *mut *mut libc::c_char, pub count: i64, pub cursor: i64, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_2 { pub lo: i32, pub hi: i32, @@ -26,7 +44,16 @@ pub struct anon_2 { pub step: u8, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct anon_3 { pub lo: i64, pub hi: i64, @@ -35,7 +62,9 @@ pub struct anon_3 { pub width: i32, } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_0 { pub list: anon_1, pub letters: anon_2, @@ -47,7 +76,16 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Branch { pub choice: Choice_enum, pub index: i32, 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 840d919779..551333dd54 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,9 @@ 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)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] pub union anon_0 { pub text: *const libc::c_char, pub handle: *mut ::libc::c_void, @@ -24,7 +26,16 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Sink { pub width: Width_enum, pub out: anon_0, diff --git a/tests/unit/out/unsafe/unique_ptr.rs b/tests/unit/out/unsafe/unique_ptr.rs index d5e859edbb..d735d89549 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct SafePointer { pub ptr: Option>, } @@ -19,10 +19,14 @@ impl SafePointer { .map_or(::std::ptr::null_mut(), |v| v as *const i32 as *mut i32)) .prefix_inc(); } - pub unsafe fn move_from(&mut self, _a0: *mut SafePointer) { +} +impl MoveConstructibleUnsafe for SafePointer { + unsafe fn move_constructor(&mut self, _a0: *mut SafePointer) { (&raw mut self.ptr).write((*_a0).ptr.take()); } - pub unsafe fn move_assign(&mut self, _a0: *mut SafePointer) -> *mut SafePointer { +} +impl MoveAssignableUnsafe for SafePointer { + unsafe fn move_assign(&mut self, _a0: *mut SafePointer) -> *mut SafePointer { { self.ptr = (*_a0).ptr.take(); }; @@ -30,7 +34,16 @@ impl SafePointer { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Pair { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/unique_ptr_const_deref.rs b/tests/unit/out/unsafe/unique_ptr_const_deref.rs index c562a90046..efbfe8a11b 100644 --- a/tests/unit/out/unsafe/unique_ptr_const_deref.rs +++ b/tests/unit/out/unsafe/unique_ptr_const_deref.rs @@ -7,15 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct Holder { pub val: Option>, } -impl Holder { - pub unsafe fn move_from(&mut self, _a0: *mut Holder) { +impl MoveConstructibleUnsafe for Holder { + unsafe fn move_constructor(&mut self, _a0: *mut Holder) { (&raw mut self.val).write((*_a0).val.take()); } - pub unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { +} +impl MoveAssignableUnsafe for Holder { + unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { { self.val = (*_a0).val.take(); }; diff --git a/tests/unit/out/unsafe/unique_ptr_field_reset.rs b/tests/unit/out/unsafe/unique_ptr_field_reset.rs index cfbc406e42..ffeb336c96 100644 --- a/tests/unit/out/unsafe/unique_ptr_field_reset.rs +++ b/tests/unit/out/unsafe/unique_ptr_field_reset.rs @@ -7,12 +7,21 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Data { pub v: i32, } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct Holder { pub data: Option>, pub n: i32, @@ -28,11 +37,15 @@ impl Holder { } }; } - pub unsafe fn move_from(&mut self, _a0: *mut Holder) { +} +impl MoveConstructibleUnsafe for Holder { + unsafe fn move_constructor(&mut self, _a0: *mut Holder) { (&raw mut self.data).write((*_a0).data.take()); (&raw mut self.n).write((*_a0).n); } - pub unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { +} +impl MoveAssignableUnsafe for Holder { + unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { { self.data = (*_a0).data.take(); }; diff --git a/tests/unit/out/unsafe/unique_ptr_nested.rs b/tests/unit/out/unsafe/unique_ptr_nested.rs index 70bdf6bfb6..0ffcf9c17e 100644 --- a/tests/unit/out/unsafe/unique_ptr_nested.rs +++ b/tests/unit/out/unsafe/unique_ptr_nested.rs @@ -7,21 +7,32 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Inner { pub x: i32, pub y: i32, } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct Outer { pub inner: Option>, } -impl Outer { - pub unsafe fn move_from(&mut self, _a0: *mut Outer) { +impl MoveConstructibleUnsafe for Outer { + unsafe fn move_constructor(&mut self, _a0: *mut Outer) { (&raw mut self.inner).write((*_a0).inner.take()); } - pub unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { +} +impl MoveAssignableUnsafe for Outer { + unsafe fn move_assign(&mut self, _a0: *mut Outer) -> *mut Outer { { self.inner = (*_a0).inner.take(); }; diff --git a/tests/unit/out/unsafe/unique_ptr_struct.rs b/tests/unit/out/unsafe/unique_ptr_struct.rs index f42266cd30..4cd3a36d1f 100644 --- a/tests/unit/out/unsafe/unique_ptr_struct.rs +++ b/tests/unit/out/unsafe/unique_ptr_struct.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Point { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/va_arg_mixed_types.rs b/tests/unit/out/unsafe/va_arg_mixed_types.rs index 207efc9868..e25e9b87f5 100644 --- a/tests/unit/out/unsafe/va_arg_mixed_types.rs +++ b/tests/unit/out/unsafe/va_arg_mixed_types.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct pair { pub a: i32, pub b: 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 cdabfbe70b..17717a61e9 100644 --- a/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct node { pub data: i32, pub next: *mut node, diff --git a/tests/unit/out/unsafe/va_arg_struct_ctx.rs b/tests/unit/out/unsafe/va_arg_struct_ctx.rs index ce5ac254c4..f14ad832d4 100644 --- a/tests/unit/out/unsafe/va_arg_struct_ctx.rs +++ b/tests/unit/out/unsafe/va_arg_struct_ctx.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct context { pub verbose: i32, pub last_error: i32, @@ -24,7 +33,9 @@ pub unsafe fn set_error_0( } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive( + Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, +)] 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 c544bf2b55..bf9c3ae583 100644 --- a/tests/unit/out/unsafe/va_arg_void_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_void_ptr.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct registry { pub slot: *mut ::libc::c_void, pub level: i64, diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs index 8bbb36df0e..b74f5dff58 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -15,7 +15,7 @@ pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { __v }; let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { - DestructibleUnsafe::destroy(__p) + DestructibleUnsafe::destroy(&mut *__p) }); let mut total: i32 = 0; { @@ -31,7 +31,7 @@ pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default, + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, )] #[cpp_from(*const VaArg , construct, mut_ptr)] pub struct Guard_1 { @@ -43,7 +43,9 @@ impl Guard_1 { (&raw mut self.ap).write(val); (&raw mut self.active).write(true); } - pub unsafe fn destructor(&mut self) { +} +impl DestructibleUnsafe for Guard_1 { + unsafe fn destroy(&mut self) { if self.active {} } } @@ -66,7 +68,16 @@ pub unsafe fn sum_ptr_2(mut n: i32, __args: Box<[VaArg]>) -> i32 { return total; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + 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 3589f5dbd7..7672f5eb13 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -7,25 +7,44 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct S { pub x: i32, } pub unsafe fn copy_0(mut copy_vector: Vec) {} #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Foo { pub a: Vec, pub b: Vec, } -impl Foo { - pub unsafe fn move_from(&mut self, _a0: *mut Foo) { +impl MoveConstructibleUnsafe for Foo { + unsafe fn move_constructor(&mut self, _a0: *mut Foo) { (&raw mut self.a).write(std::mem::take(&mut (*_a0).a)); (&raw mut self.b).write(std::mem::take(&mut (*_a0).b)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Foo) -> *mut Foo { +} +impl MoveAssignableUnsafe for Foo { + unsafe fn move_assign(&mut self, _a0: *mut Foo) -> *mut Foo { { self.a = std::mem::take(&mut (*_a0).a); }; diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index fdb50df128..fef414e705 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -7,7 +7,17 @@ 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, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Degrees { pub value: i32, @@ -18,7 +28,17 @@ impl Degrees { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] #[cpp_into(i64, to_i64)] pub struct Reading { pub raw_: i32, diff --git a/tests/unit/out/unsafe/vector_subscript_direct.rs b/tests/unit/out/unsafe/vector_subscript_direct.rs index c8fd3d8523..e0e15e8862 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Point { pub x: i32, pub y: i32, @@ -19,18 +28,28 @@ impl Point { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct Holder { pub values: Vec, pub points: Vec, } -impl Holder { - pub unsafe fn move_from(&mut self, _a0: *mut Holder) { +impl MoveConstructibleUnsafe for Holder { + unsafe fn move_constructor(&mut self, _a0: *mut Holder) { (&raw mut self.values).write(std::mem::take(&mut (*_a0).values)); (&raw mut self.points).write(std::mem::take(&mut (*_a0).points)); } - pub unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { +} +impl MoveAssignableUnsafe for Holder { + unsafe fn move_assign(&mut self, _a0: *mut Holder) -> *mut Holder { { self.values = std::mem::take(&mut (*_a0).values); }; diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index b35e468262..50ea8fd8a7 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -7,7 +7,16 @@ 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, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct TestAllocator_int_ {} impl TestAllocator_int_ { pub unsafe fn allocate(&mut self, mut n: usize) -> *mut i32 { @@ -27,7 +36,16 @@ impl TestAllocator_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct TestAllocator_double_ {} impl TestAllocator_double_ { pub unsafe fn allocate(&mut self, mut n: usize) -> *mut f64 { diff --git a/tests/unit/out/unsafe/void_cast.rs b/tests/unit/out/unsafe/void_cast.rs index ac603b501f..c07411af9a 100644 --- a/tests/unit/out/unsafe/void_cast.rs +++ b/tests/unit/out/unsafe/void_cast.rs @@ -9,16 +9,26 @@ use std::rc::Rc; pub unsafe fn unused_param_0(mut x: i32) {} #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + SwappableUnsafe, + Default, )] pub struct NonTrivial { pub data: Vec, } -impl NonTrivial { - pub unsafe fn move_from(&mut self, _a0: *mut NonTrivial) { +impl MoveConstructibleUnsafe for NonTrivial { + unsafe fn move_constructor(&mut self, _a0: *mut NonTrivial) { (&raw mut self.data).write(std::mem::take(&mut (*_a0).data)); } - pub unsafe fn move_assign(&mut self, _a0: *mut NonTrivial) -> *mut NonTrivial { +} +impl MoveAssignableUnsafe for NonTrivial { + unsafe fn move_assign(&mut self, _a0: *mut NonTrivial) -> *mut NonTrivial { { self.data = std::mem::take(&mut (*_a0).data); }; @@ -34,20 +44,31 @@ pub unsafe fn bump_and_return_4() -> i32 { return (*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_counter_3)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + Default, +)] pub struct Holder { pub field: i32, } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, Default)] pub struct NonCopyable { pub value: Option>, } -impl NonCopyable { - pub unsafe fn move_from(&mut self, _a0: *mut NonCopyable) { +impl MoveConstructibleUnsafe for NonCopyable { + unsafe fn move_constructor(&mut self, _a0: *mut NonCopyable) { (&raw mut self.value).write((*_a0).value.take()); } - pub unsafe fn move_assign(&mut self, _a0: *mut NonCopyable) -> *mut NonCopyable { +} +impl MoveAssignableUnsafe for NonCopyable { + unsafe fn move_assign(&mut self, _a0: *mut NonCopyable) -> *mut NonCopyable { { self.value = (*_a0).value.take(); };