diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 9765771a79..5fdb80b985 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1007,18 +1007,48 @@ 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; + } + 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); + ConvertCopyOrMoveTraitImpls(decl, IsEmittableMethod); if (GetUserDefinedDestructor(decl) || !HasFieldsNeedingDestruction(decl)) { return; @@ -1168,6 +1198,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); } @@ -1191,6 +1225,9 @@ std::string Converter::GetMethodName(const clang::CXXMethodDecl *decl) { if (clang::isa(decl)) { return kDestructorName; } + if (auto *trait = GetRecordTrait(decl)) { + return trait->method; + } if (const char *name = GetCopyOrMoveName(decl); name && CanUseCopyOrMoveName(decl, name)) { return name; @@ -1227,7 +1264,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 +1297,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 +1318,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 +2496,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 +3951,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; } @@ -4440,6 +4486,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 +5013,10 @@ 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"}; + AddCopyAndMoveDerives(decl, union_attrs); + return union_attrs; } std::vector struct_attrs; @@ -4983,27 +5035,17 @@ 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)) { struct_attrs.emplace_back("DestructibleUnsafe"); } + AddCopyAndMoveDerives(decl, struct_attrs); + if (RecordDerivesDefault(decl)) { struct_attrs.emplace_back("Default"); } @@ -5248,7 +5290,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; @@ -5512,6 +5554,30 @@ void Converter::AddCloneTrait(const clang::RecordDecl *decl) { TakePlacementValue())); } +void Converter::AddCopyAndMoveDerives(const clang::RecordDecl *decl, + std::vector &attrs) { + if (!decl->isUnion() && !RecordImplementsClone(decl)) { + return; + } + auto *cxx = clang::dyn_cast(decl); + auto implements = [&](const RecordTrait *trait) { + return cxx && llvm::any_of(cxx->methods(), [&](auto *method) { + return GetRecordTrait(method) == trait; + }); + }; + const RecordTrait *traits[] = {&kCopyConstructible, &kMoveConstructible, + &kCopyAssignable, &kMoveAssignable}; + if (llvm::none_of(traits, implements)) { + attrs.emplace_back(GetCopyOrMoveTraitName(kCopyable)); + return; + } + for (const auto *trait : traits) { + if (!implements(trait)) { + attrs.emplace_back(GetCopyOrMoveTraitName(*trait)); + } + } +} + bool Converter::RecordImplementsClone(const clang::RecordDecl *decl) { return HasDefaultedCopyConstructor(decl) || GetUserDefinedCopyConstructor(decl) != nullptr; @@ -6458,39 +6524,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 +6563,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..4878f06c41 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -358,17 +358,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 +885,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 *)); diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 4672d9e507..a04dc69e55 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -602,6 +602,43 @@ 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 IsConvertedConstructor(ctor) && ctor->hasBody(); + } + return method->isCopyAssignmentOperator() + ? IsTranslatedCopyAssignment(method) + : IsTranslatedMoveAssignment(method); +} + +const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { + method = method->getCanonicalDecl(); + const char *name = GetCopyOrMoveName(method); + if (!name || method->isDeleted() || method->isVirtual() || + !CanUseCopyOrMoveName(method, name) || !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); @@ -730,7 +767,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); }); }); } @@ -742,11 +779,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) { @@ -770,7 +818,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"); }); } diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index da432b5929..40f277d331 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -105,6 +105,24 @@ 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; +}; + +inline constexpr RecordTrait kCopyConstructible{ + "CopyConstructible", "CopyConstructibleUnsafe", "copy_constructor"}; +inline constexpr RecordTrait kMoveConstructible{ + "MoveConstructible", "MoveConstructibleUnsafe", "move_constructor"}; +inline constexpr RecordTrait kCopyAssignable{ + "CopyAssignable", "CopyAssignableUnsafe", "copy_assign"}; +inline constexpr RecordTrait kMoveAssignable{ + "MoveAssignable", "MoveAssignableUnsafe", "move_assign"}; +inline constexpr RecordTrait kCopyable{"Copyable", "CopyableUnsafe", nullptr}; + +const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method); + bool IsUserDefinedCopyConstructor(const clang::CXXConstructorDecl *ctor); bool IsConvertibleCopyOrMoveConstructor(const clang::CXXConstructorDecl *ctor); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 9bc5a22253..e3864a0cff 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"; @@ -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; } @@ -2326,7 +2328,9 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { std::vector attrs; if (decl->isUnion()) { - return {"VaArg", "FnPtrArg"}; + std::vector union_attrs = {"VaArg", "FnPtrArg"}; + AddCopyAndMoveDerives(decl, union_attrs); + return union_attrs; } if (RecordDerivesCopyTrait(decl)) { @@ -2348,27 +2352,17 @@ 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)) { 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) { @@ -3597,6 +3577,16 @@ bool ConverterRefCount::ShouldConvertMethod(const clang::CXXMethodDecl *decl) { 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,6 +3756,7 @@ void ConverterRefCount::ConvertCXXRecordMethods(clang::CXXRecordDecl *decl) { ConvertMethodOnPtr(method); } }); + ConvertCopyOrMoveTraitImpls(decl, IsEmittableMethod); if (!GetUserDefinedDestructor(decl) && HasFieldsNeedingDestruction(decl)) { MethodsOnPtrFor(decl).trait.body += @@ -3774,20 +3776,26 @@ ConverterRefCount::DestroyMembers(const clang::CXXRecordDecl *decl) { 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 +3827,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/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..92ec57ac20 --- /dev/null +++ b/libcc2rs-macros/src/constructor.rs @@ -0,0 +1,91 @@ +// 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)); + quote!(#(#impls)*).into() +} + +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/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(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(CopyAssignUnsafe)] -pub fn derive_copy_assign_unsafe(input: TokenStream) -> TokenStream { - assign::expand(input, "copy", true) +#[proc_macro_derive(MoveConstructibleUnsafe)] +pub fn derive_move_constructible_unsafe(input: TokenStream) -> TokenStream { + constructor::expand(input, "move", false, true) } -#[proc_macro_derive(MoveAssign)] -pub fn derive_move_assign(input: TokenStream) -> TokenStream { - assign::expand(input, "move", false) +#[proc_macro_derive(MoveAssignable)] +pub fn derive_move_assignable(input: TokenStream) -> TokenStream { + constructor::expand(input, "move", true, false) } -#[proc_macro_derive(MoveAssignUnsafe)] -pub fn derive_move_assign_unsafe(input: TokenStream) -> TokenStream { - assign::expand(input, "move", true) +#[proc_macro_derive(MoveAssignableUnsafe)] +pub fn derive_move_assignable_unsafe(input: TokenStream) -> TokenStream { + constructor::expand(input, "move", true, true) } // #[derive(Destructible)] 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..6db6c7c344 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,119 +20,15 @@ #![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)]. @@ -187,7 +83,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 +118,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 } } @@ -310,7 +200,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 +232,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() + } } } diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs new file mode 100644 index 0000000000..a278670bae --- /dev/null +++ b/libcc2rs/src/constructor.rs @@ -0,0 +1,384 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +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; +} + +// std::copyable, without swappable. +pub trait Copyable: + CopyConstructible + MoveConstructible + CopyAssignable + MoveAssignable +{ +} + +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; +} + +// std::copyable, without swappable. +pub trait CopyableUnsafe: + CopyConstructibleUnsafe + MoveConstructibleUnsafe + CopyAssignableUnsafe + MoveAssignableUnsafe +{ +} + +impl< + T: CopyConstructibleUnsafe + MoveConstructibleUnsafe + CopyAssignableUnsafe + MoveAssignableUnsafe, +> 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 + } + } + )*}; +} +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 + } + } + )*}; +} +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 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 + } +} + +// C arrays, element by element. +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 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..e86fdd58ec 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, MoveAssignable, MoveAssignableUnsafe, MoveConstructible, + MoveConstructibleUnsafe, }; mod cmp; @@ -68,8 +72,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 +111,9 @@ mod format; pub use format::*; pub use libcc2rs_macros::{ - ByteRepr, CopyAssign, CopyAssignUnsafe, CppFrom, CppFromUnsafe, Destructible, - DestructibleUnsafe, FnPtrArg, MoveAssign, MoveAssignUnsafe, MoveCtor, MoveCtorUnsafe, Record, + ByteRepr, CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, + Copyable, CopyableUnsafe, CppFrom, CppFromUnsafe, Destructible, DestructibleUnsafe, FnPtrArg, + MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, Record, VaArg, ZeroInitialization, ZeroInitializationUnsafe, goto, goto_block, lambda, lambda_unsafe, switch, }; diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index bd7eeb4ef7..b3b0d16111 100644 --- a/libcc2rs/src/swap.rs +++ b/libcc2rs/src/swap.rs @@ -10,13 +10,13 @@ // `(&&&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 made with the move constructor (MoveConstructible), +// or else with the copy constructor (Clone); +// - a value is assigned with the move assignment operator (MoveAssignable), +// or else with the copy assignment operator (CopyAssignable), as C++ +// copies the types without one; the other types are assigned as a whole, +// by moving the value with the move constructor (MoveConstructible), 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. @@ -31,10 +31,12 @@ use std::cell::RefCell; use std::rc::Rc; -use crate::capture::{ - CopyAssign, CopyAssignUnsafe, Destructible, DestructibleUnsafe, MoveAssign, MoveAssignUnsafe, - MoveCtor, MoveCtorUnsafe, +use crate::capture::{Destructible, DestructibleUnsafe}; +use crate::constructor::{ + CopyAssignable, CopyAssignableUnsafe, MoveAssignable, MoveAssignableUnsafe, MoveConstructible, + MoveConstructibleUnsafe, }; +use crate::initialization::ZeroInitialization; use crate::rc::{AsPointer, Ptr, Value}; use crate::reinterpret::ByteRepr; @@ -108,14 +110,17 @@ 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),*) => { + ($wrapper:ident, $ptr:ty, $none:ident, $($tr:ident: $bty:ty: $bound:ident for $recv:ty),*) => { pub struct $wrapper<'a, T>(pub &'a $ptr); $( pub trait $tr { fn trivial(self) -> bool; } - impl $tr for $recv { + impl $tr for $recv + where + $bty: $bound, + { fn trivial(self) -> bool { false } @@ -135,17 +140,17 @@ macro_rules! trivial { } trivial!(Trivial, Ptr, HasNone, - HasMoveCtor: MoveCtor for &&&&&Trivial<'_, T>, - HasMoveAssign: MoveAssign for &&&&Trivial<'_, T>, - HasCopyAssign: CopyAssign for &&&Trivial<'_, T>, - HasDestructor: Destructible for &&Trivial<'_, T> + HasMoveCtor: T: MoveConstructible for &&&&&Trivial<'_, T>, + HasMoveAssign: T: MoveAssignable for &&&&Trivial<'_, T>, + HasCopyAssign: T: CopyAssignable for &&&Trivial<'_, T>, + HasDestructor: T: 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> + HasMoveCtorUnsafe: T: MoveConstructibleUnsafe for &&&&&TrivialUnsafe<'_, T>, + HasMoveAssignUnsafe: T: MoveAssignableUnsafe for &&&&TrivialUnsafe<'_, T>, + HasCopyAssignUnsafe: T: CopyAssignableUnsafe for &&&TrivialUnsafe<'_, T>, + HasDestructorUnsafe: T: DestructibleUnsafe for &&TrivialUnsafe<'_, T> ); #[cold] @@ -187,6 +192,20 @@ pub fn pointer(value: &Value) -> Ptr { as AsPointer>::as_pointer(value) } +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() +} + +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() + } +} + pub struct Construct<'a, T>(pub &'a Ptr); pub trait ConstructMove { @@ -201,9 +220,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) } } @@ -242,21 +261,21 @@ pub trait AssignNone { fn assign(self); } -impl AssignMove for &&&&&Assign<'_, T> { +impl AssignMove for &&&&&Assign<'_, T> { fn assign(self) { - T::move_assign(self.0, self.1.clone()) + T::move_assign(self.0, self.1.clone()); } } -impl AssignCopy for &&&&Assign<'_, T> { +impl AssignCopy for &&&&Assign<'_, T> { fn assign(self) { - T::copy_assign(self.0, self.1.clone()) + T::copy_assign(self.0, self.1.clone()); } } -impl AssignMoveCtor for &&&Assign<'_, T> { +impl AssignMoveCtor for &&&Assign<'_, T> { fn assign(self) { - self.0.write(T::move_ctor(self.1.clone())) + self.0.write(move_constructed(self.1)) } } @@ -306,9 +325,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) } } } @@ -346,21 +365,21 @@ pub trait AssignNoneUnsafe { unsafe fn assign(self); } -impl AssignMoveUnsafe for &&&&&AssignUnsafe { +impl AssignMoveUnsafe for &&&&&AssignUnsafe { unsafe fn assign(self) { - unsafe { T::move_assign(self.0, self.1) } + unsafe { (*self.0).move_assign(self.1) }; } } -impl AssignCopyUnsafe for &&&&AssignUnsafe { +impl AssignCopyUnsafe for &&&&AssignUnsafe { unsafe fn assign(self) { - unsafe { T::copy_assign(self.0, self.1) } + unsafe { (*self.0).copy_assign(self.1) }; } } -impl AssignMoveCtorUnsafe for &&&AssignUnsafe { +impl AssignMoveCtorUnsafe for &&&AssignUnsafe { unsafe fn assign(self) { - unsafe { *self.0 = T::move_ctor(self.1) } + unsafe { *self.0 = move_constructed_unsafe(self.1) } } } 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..4d028d63d1 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, 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)] #[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..5d687f470a 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, 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)] #[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..79f247441c 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, Ptr, Record, ZeroInitialization}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable)] #[byte_size(4)] pub struct InAddr { #[offset(0)] pub s_addr: u32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable)] #[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..a8fea2c040 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, Ptr, Record, Sockaddr, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable)] #[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..f48bb17add 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, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable)] #[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..27577246d9 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, Ptr, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable)] #[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..de31634b63 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; + +#[derive(Clone, Default, Copyable)] pub struct CFdSet { fds: BTreeSet, } diff --git a/rules/socket/shim.rs b/rules/socket/shim.rs index 47ef06c5f9..f8e2c21a91 100644 --- a/rules/socket/shim.rs +++ b/rules/socket/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, CChar, In6Addr, InAddr, Ptr, Record, ZeroInitialization}; +use crate::{ByteRepr, CChar, Copyable, 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)] #[byte_size(16)] pub struct Sockaddr { #[offset(0)] @@ -15,7 +15,7 @@ pub struct Sockaddr { pub sa_data: Box<[i8]>, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable)] #[byte_size(16)] pub struct SockaddrIn { #[offset(0)] @@ -30,7 +30,7 @@ pub struct SockaddrIn { pub sin_zero: Box<[u8]>, } -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable)] #[byte_size(28)] pub struct SockaddrIn6 { #[offset(0)] @@ -45,7 +45,7 @@ pub struct SockaddrIn6 { pub sin6_scope_id: u32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable)] #[byte_size(110)] pub struct SockaddrUn { #[offset(0)] @@ -56,7 +56,7 @@ pub struct SockaddrUn { pub sun_path: Box<[i8]>, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable)] #[byte_size(128)] pub struct SockaddrStorage { #[offset(0)] @@ -397,3 +397,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..93cedc72e4 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, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ZeroInitialization)] +#[derive(Clone, Default, Record, ZeroInitialization, Copyable)] // 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..1ae3b751f8 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, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, Copyable)] #[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)] #[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..be2a7004f5 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, Ptr, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization, Copyable)] #[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)] #[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)] #[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..52b15597cc 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -1,4 +1,43 @@ // 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, 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 + } +} 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..9f220ef70d 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,7 @@ 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 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..21f1c830fb 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,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 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..699e27548a 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)] #[cpp_from(i32, construct, value)] #[byte_size(32)] pub struct S { @@ -18,13 +18,42 @@ 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, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct T { @@ -32,6 +61,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 +105,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 +114,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 +132,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..d866cb761e 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 @@ -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, MoveAssignUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct S { pub v: Vec, @@ -20,11 +18,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 +43,13 @@ impl S { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + Default, )] pub struct T { pub v: Vec, @@ -50,10 +58,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 +103,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 +112,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..4a3a726bf4 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,7 @@ 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(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..efead5d19f 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,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 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..d9ef3a6a15 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,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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..f35c10253b 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,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 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 025f1e0e89..30e932a145 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,7 +6,7 @@ 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)] @@ -15,13 +15,13 @@ pub struct S { 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, 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, Copyable, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] 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 a99bc9436a..c961f6a2aa 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, } @@ -20,13 +20,13 @@ 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, 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, CopyableUnsafe, Default)] pub struct Pair { pub first: i32, pub second: i32, diff --git a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs index a43e8c01ad..d65154a999 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,7 @@ 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, 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..bbd20e2f44 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,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)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..d635b41804 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,16 @@ 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, + Destructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +53,25 @@ 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 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,7 +87,9 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -94,7 +117,7 @@ thread_local!( __static }; ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct HasInlineMembers {} impl HasInlineMembers { @@ -151,20 +174,14 @@ impl AssertsDtorCountAtExitImpl for 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(); } @@ -174,10 +191,6 @@ impl LifetimeTrackedImpl for Ptr { }); (*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..c18fa079b7 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,14 @@ 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, + DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,10 +39,6 @@ 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) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } @@ -43,7 +46,15 @@ impl LifetimeTracked { (*(&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 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(); + } +} +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 +63,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,7 +80,9 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -107,7 +120,7 @@ pub static mut shared_5: std::cell::LazyCell = } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct HasInlineMembers {} impl HasInlineMembers { pub unsafe fn instance() -> *mut LifetimeTracked { 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..91adfc3d29 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,16 @@ 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, + Destructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +53,25 @@ 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 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() } } @@ -79,7 +100,7 @@ thread_local!( __static }; ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct HasStaticMember_int_ {} thread_local!( @@ -95,7 +116,7 @@ thread_local!( __static }; ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct HasStaticMember_long_ {} pub fn main() { @@ -124,20 +145,14 @@ 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(); } @@ -147,10 +162,6 @@ impl LifetimeTrackedImpl for Ptr { }); (*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..4f186b611c 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,14 @@ 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, + DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,10 +39,6 @@ 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) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } @@ -43,7 +46,15 @@ impl LifetimeTracked { (*(&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 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(); + } +} +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 +63,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 } } @@ -85,7 +96,7 @@ pub static mut member_4: std::cell::LazyCell = } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct HasStaticMember_int_ {} pub static mut member_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { @@ -104,7 +115,7 @@ pub static mut member_5: std::cell::LazyCell = } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..e3a1c2cb55 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,16 @@ 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, + Destructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +53,25 @@ 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 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,7 +87,9 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -156,7 +179,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct S_14 {} pub fn count_18() -> i32 { @@ -187,7 +210,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct S_21 {} pub trait AssertsDtorCountAtExitImpl { @@ -200,20 +223,14 @@ impl AssertsDtorCountAtExitImpl for 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(); } @@ -223,10 +240,6 @@ impl LifetimeTrackedImpl for Ptr { }); (*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..02f5ab322c 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,14 @@ 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, + DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,10 +39,6 @@ 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) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } @@ -43,7 +46,15 @@ impl LifetimeTracked { (*(&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 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(); + } +} +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 +63,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,7 +80,9 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -168,7 +181,7 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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()); @@ -199,7 +212,7 @@ 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, 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..5ff70ca6cf 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,16 @@ 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, + Destructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +53,25 @@ 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 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,7 +87,9 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -129,20 +152,14 @@ impl AssertsDtorCountAtExitImpl for 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(); } @@ -152,10 +169,6 @@ impl LifetimeTrackedImpl for Ptr { }); (*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..75e079fc7e 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,14 @@ 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, + DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,10 +39,6 @@ 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) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } @@ -43,7 +46,15 @@ impl LifetimeTracked { (*(&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 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(); + } +} +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 +63,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,7 +80,9 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct AssertsDtorCountAtExit { pub expected: i32, } 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..5109c0cba1 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,16 @@ 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, + Destructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +53,25 @@ 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 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,7 +87,9 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -124,20 +147,14 @@ impl AssertsDtorCountAtExitImpl for 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(); } @@ -147,10 +164,6 @@ impl LifetimeTrackedImpl for Ptr { }); (*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..131c993dfb 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,14 @@ 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, + DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,10 +39,6 @@ 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) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } @@ -43,7 +46,15 @@ impl LifetimeTracked { (*(&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 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(); + } +} +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 +63,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,7 +80,9 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct AssertsDtorCountAtExit { pub expected: i32, } 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..8792a2984b 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,16 @@ 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, + Destructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +53,25 @@ 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 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 +87,15 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] pub expected: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct X {} thread_local!( @@ -142,20 +165,14 @@ impl AssertsDtorCountAtExitImpl for 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(); } @@ -165,10 +182,6 @@ impl LifetimeTrackedImpl for Ptr { }); (*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..f950e9629f 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,14 @@ 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, + DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,10 +39,6 @@ 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) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } @@ -43,7 +46,15 @@ impl LifetimeTracked { (*(&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 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(); + } +} +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 +63,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,7 +80,9 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -79,7 +92,7 @@ impl AssertsDtorCountAtExit { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct X {} impl X { pub unsafe fn h(&mut self, mut cond: bool, mut p: Option) { 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..c08331cec2 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,16 @@ 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, + Destructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +53,25 @@ 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 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,7 +87,9 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -135,20 +158,14 @@ impl AssertsDtorCountAtExitImpl for 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(); } @@ -158,10 +175,6 @@ impl LifetimeTrackedImpl for Ptr { }); (*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..3fbb41d125 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,14 @@ 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, + DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,10 +39,6 @@ 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) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } @@ -43,7 +46,15 @@ impl LifetimeTracked { (*(&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 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(); + } +} +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 +63,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,7 +80,9 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct AssertsDtorCountAtExit { pub expected: i32, } 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..7a2a6eb8a7 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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct anon_13 { #[offset(0)] @@ -67,7 +67,7 @@ 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, Copyable)] #[byte_size(4)] pub struct Record_19 { #[offset(0)] @@ -103,7 +103,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct Tally_31 {} thread_local!( @@ -115,7 +115,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct p5_members_of_class_with_external_linkage_Ledger {} pub fn test_36() { @@ -183,7 +183,7 @@ 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, Copyable)] #[byte_size(4)] pub struct Entry_52 { #[offset(0)] @@ -194,7 +194,7 @@ 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, Copyable)] #[byte_size(8)] pub struct Entry_54 { #[offset(0)] @@ -266,7 +266,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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct anon_62 { #[offset(0)] @@ -304,7 +304,7 @@ 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, Copyable)] #[byte_size(16)] pub struct Record_65 { #[offset(0)] @@ -348,7 +348,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct Tally_67 {} thread_local!( @@ -390,7 +390,7 @@ 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, 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..e1cf93455f 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,7 @@ pub unsafe fn test_11() { ); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union anon_13 { pub whole: i32, pub fraction: f32, @@ -60,7 +60,7 @@ 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, CopyableUnsafe)] pub struct Record_19 { pub id: i32, } @@ -93,7 +93,7 @@ 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, CopyableUnsafe, Default)] pub struct Tally_31 {} impl Tally_31 { pub unsafe fn add(&mut self, mut amount: i32) -> i32 { @@ -109,7 +109,7 @@ 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, 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 +171,7 @@ 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, CopyableUnsafe)] pub struct Entry_52 { pub key: i32, } @@ -181,7 +181,7 @@ impl Default for Entry_52 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct Entry_54 { pub key: i32, pub value: i32, @@ -243,7 +243,7 @@ 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, CopyableUnsafe)] pub union anon_62 { pub whole: i32, pub fraction: f32, @@ -266,7 +266,7 @@ 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, CopyableUnsafe)] pub struct Record_65 { pub id: i64, pub extra: i32, @@ -303,7 +303,7 @@ 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, CopyableUnsafe, Default)] pub struct Tally_67 {} impl Tally_67 { pub unsafe fn add(&mut self, mut amount: i32) -> i32 { @@ -341,7 +341,7 @@ 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, 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..36abd03dda 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,16 @@ 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, + Destructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +53,25 @@ 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 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,7 +96,9 @@ 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, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] @@ -329,20 +352,14 @@ 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(); } @@ -352,10 +369,6 @@ impl LifetimeTrackedImpl for Ptr { }); (*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; 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..d935f2bb45 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,7 @@ 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, Copyable)] #[byte_size(4)] pub struct p1_member_hides_namespace_variable_HasBalance { #[offset(0)] @@ -45,7 +45,7 @@ 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, 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..ee9602fff9 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,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, CppFrom, Default)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, 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..f8ed232a0a 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,7 @@ pub fn test_0() { } assert!((level == 5)); } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct p1_own_address_in_initializer_SelfLinked { #[offset(0)] @@ -73,7 +73,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, 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..1e1bb61730 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,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} pub fn test_5() { @@ -72,7 +72,7 @@ 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, 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 +88,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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_8 { #[offset(0)] @@ -114,7 +114,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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_9 { #[offset(0)] @@ -137,7 +137,7 @@ impl Default for anon_9 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { #[offset(0)] @@ -173,7 +173,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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_11 { #[offset(0)] @@ -196,7 +196,7 @@ impl Default for anon_11 { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(8)] pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { #[offset(0)] @@ -240,7 +240,7 @@ 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, Copyable)] #[byte_size(4)] pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { #[offset(0)] @@ -282,7 +282,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} pub fn test_18() { @@ -320,7 +320,7 @@ 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, Copyable)] #[byte_size(8)] pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { #[offset(0)] @@ -367,7 +367,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} pub fn test_22() { @@ -397,14 +397,14 @@ 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, 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, Copyable, Default)] #[byte_size(1)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DefinesFriend {} pub fn test_25() { @@ -436,7 +436,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct p4_2_class_and_function_share_name_Reading { #[offset(0)] @@ -454,7 +454,7 @@ 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, 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..0a7c19133a 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,14 @@ 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, + DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,10 +39,6 @@ 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) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } @@ -43,7 +46,15 @@ impl LifetimeTracked { (*(&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 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(); + } +} +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 +63,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 +85,9 @@ 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, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { pub value: i32, } 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..0817e8c856 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,7 @@ 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, CopyableUnsafe)] pub struct p1_member_hides_namespace_variable_HasBalance { pub balance: i32, } @@ -46,7 +46,7 @@ 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, 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..a604ce0621 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,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, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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..4896ad24fa 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,7 @@ pub unsafe fn test_0() { assert!(((level) == (5))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct p1_own_address_in_initializer_SelfLinked { pub next: *mut p1_own_address_in_initializer_SelfLinked, pub value: i32, @@ -72,7 +72,7 @@ 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, 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..ae5fdc3d18 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,7 @@ 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, 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 +69,7 @@ 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, 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 +85,7 @@ 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, CopyableUnsafe)] pub union anon_8 { pub namespace_count: i32, pub namespace_ratio: f64, @@ -98,7 +98,7 @@ 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, CopyableUnsafe)] pub union anon_9 { pub member_count: i32, pub member_ratio: f64, @@ -109,7 +109,7 @@ impl Default for anon_9 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { pub tag: i32, pub anon_9: anon_9, @@ -146,7 +146,7 @@ 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, CopyableUnsafe)] pub union anon_11 { pub block_count: i32, pub block_ratio: f64, @@ -157,7 +157,7 @@ impl Default for anon_11 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { pub plain_calls: i32, pub const_calls: i32, @@ -205,7 +205,7 @@ 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, CopyableUnsafe)] pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { pub base: i32, } @@ -257,7 +257,7 @@ 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, 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 +297,7 @@ 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, CopyableUnsafe)] pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { pub plain_calls: i32, pub const_calls: i32, @@ -353,7 +353,7 @@ 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, 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 +392,14 @@ 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, 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, 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 +428,7 @@ 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, CopyableUnsafe, Default)] pub struct p4_2_class_and_function_share_name_Reading { pub value: i32, } @@ -445,7 +445,7 @@ 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, 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..01cb6f518d 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,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, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct Tracker { #[offset(0)] 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..1b43ddf073 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,24 @@ 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, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct Tracker { #[offset(0)] pub tag: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, 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)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct TriviallyDestructible { #[offset(0)] @@ -107,7 +111,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct p3_reverse_completion_order_WithStaticMember {} thread_local!( 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..6de1b46967 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,9 @@ 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, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Tracker { pub tag: i32, } 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..fe201bbee7 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,9 @@ 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, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Tracker { pub tag: i32, } @@ -24,7 +26,9 @@ impl Tracker { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct HoldsTracker { pub member: Tracker, } @@ -34,7 +38,7 @@ impl HoldsTracker { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct TriviallyDestructible { pub value: i32, } @@ -132,7 +136,7 @@ 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, CopyableUnsafe, Default)] pub struct p3_reverse_completion_order_WithStaticMember {} pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { diff --git a/tests/std/basic/basic.types/out/refcount/basic.types.general.rs b/tests/std/basic/basic.types/out/refcount/basic.types.general.rs index d50e4c91c2..fcb58faacc 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,7 @@ 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(8)] pub struct p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { #[offset(0)] @@ -69,7 +69,7 @@ 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, 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..e07c4f58a9 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,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 p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { pub first: i32, pub second: i32, @@ -76,7 +76,7 @@ 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, 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 201482e23f..8f4be2f93d 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -9,7 +9,17 @@ 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, + MoveConstructible, + MoveAssignable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct HasConstexprCtor { @@ -21,12 +31,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 +64,16 @@ 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, + Destructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -68,13 +99,25 @@ 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 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 +276,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} pub fn test_11() { @@ -285,7 +328,7 @@ pub fn test_14() { 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() })); }, @@ -326,7 +369,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 +377,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 +400,17 @@ 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, + MoveConstructible, + MoveAssignable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(8)] pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { @@ -366,6 +419,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 +450,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 +472,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 +485,17 @@ 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, + Destructible, + CopyConstructible, + MoveConstructible, + MoveAssignable, + Default, )] #[byte_size(8)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { @@ -429,6 +506,16 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[byte_size(4)] pub b: LifetimeTracked, } +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( @@ -462,7 +549,16 @@ 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, + Destructible, + CopyConstructible, + MoveConstructible, + MoveAssignable, )] #[byte_size(8)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { @@ -472,6 +568,16 @@ pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(4)] pub n: i32, } +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 { { @@ -501,7 +607,17 @@ 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, + Destructible, + CopyConstructible, + MoveConstructible, + MoveAssignable, + Default, )] #[byte_size(4)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { @@ -509,6 +625,15 @@ pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[byte_size(4)] pub x: LifetimeTracked, } +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( @@ -548,7 +673,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 { @@ -620,7 +745,7 @@ 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, Copyable)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { @@ -639,7 +764,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { #[offset(0)] @@ -786,38 +911,22 @@ impl p4_1_pure_virtual_without_definition_HasPureVirtual } 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(); } @@ -827,18 +936,9 @@ impl LifetimeTrackedImpl for Ptr { }); (*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,38 +947,13 @@ 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)); @@ -886,10 +961,6 @@ impl p6_unevaluated_binding_needs_no_capture_HasTwoMembersImpl } 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 @@ -907,24 +978,12 @@ 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 @@ -937,13 +996,6 @@ 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)); } diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 624bd9f248..4c5c5e576e 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, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + 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,14 @@ 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, + DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct LifetimeTracked { pub uses: i32, } @@ -64,10 +83,6 @@ 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) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)).prefix_inc(); - } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)).prefix_inc(); } @@ -75,7 +90,15 @@ impl LifetimeTracked { (*(&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 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(); + } +} +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 +107,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 +247,7 @@ 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, 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 = @@ -279,7 +302,7 @@ pub unsafe fn test_14() { { let r: LifetimeTracked = { let mut __v: LifetimeTracked = ::zero_init(); - LifetimeTracked::copy_from(&mut __v, { r }); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { r }); __v }; }, @@ -320,14 +343,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 +371,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, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { pub value: i32, @@ -359,7 +390,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 +400,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 +416,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 +436,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,24 +450,32 @@ pub unsafe fn test_19() { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + 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 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)); } @@ -474,7 +517,14 @@ pub unsafe fn test_20() { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, )] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { pub x: LifetimeTracked, @@ -493,13 +543,15 @@ impl p7_member_access_captures_this_HasMemberUsedInLambda { } ); } - pub unsafe fn copy_assign( +} +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)); @@ -539,7 +591,15 @@ pub unsafe fn test_22() { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, DestructibleUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + Default, )] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { pub x: LifetimeTracked, @@ -552,13 +612,15 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } }); } - pub unsafe fn copy_assign( +} +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)); } @@ -604,7 +666,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) { @@ -674,7 +736,7 @@ 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, CopyableUnsafe)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { pub unsafe fn construct(&mut self) { @@ -694,7 +756,7 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } 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..b187800cb2 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,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, CppFrom, Default)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, 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..4929dcb8a8 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,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, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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..ae1a474f86 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,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, CppFrom, Default)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, 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..70ea5595a8 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,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, CppFrom, Default)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, 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..5d05bfa9d7 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,9 @@ 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, 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..55c1c91a29 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,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, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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..4a2c5bcd44 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, 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..8bb6cd8454 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, 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..bf08ba06f5 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,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct p1_allocation_function_is_static_Allocates {} impl p1_allocation_function_is_static_Allocates { @@ -46,7 +46,7 @@ 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, 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..ca7835a283 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,7 @@ 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, Copyable)] #[byte_size(4)] pub struct p7_1_function_body_names_later_member_HasLaterMembers { #[offset(0)] @@ -43,7 +43,7 @@ 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, 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..fcde99ecea 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,7 @@ 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, 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 +42,7 @@ 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, 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..df4dbfc5a9 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,7 @@ 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, CopyableUnsafe)] pub struct p7_1_function_body_names_later_member_HasLaterMembers { pub stock: i32, } @@ -46,7 +46,7 @@ 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, 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..073853a966 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,7 @@ 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(8)] pub struct p6_2_zero_initialized_padding_Padded { #[offset(0)] @@ -14,7 +14,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct p6_2_zero_initialized_padding_TailPadded { #[offset(0)] @@ -22,7 +22,7 @@ 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, 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..8421d91e0f 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,7 @@ 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(8)] pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { #[offset(0)] @@ -14,7 +14,7 @@ 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, Copyable)] #[byte_size(8)] pub struct p6_1_zero_initialized_pointer_to_member_HoldsSelector { #[offset(0)] @@ -111,7 +111,7 @@ 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, Copyable, Default)] #[byte_size(24)] pub struct p6_2_zero_initialized_class_Inner { #[offset(0)] @@ -122,7 +122,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, Copyable)] #[byte_size(96)] pub struct p6_2_zero_initialized_class_Outer { #[offset(0)] @@ -193,7 +193,7 @@ pub fn test_15() { ({ check_14((heap_outer).clone()) }); heap_outer.delete(); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct p6_3_zero_initialized_union_Number { #[offset(0)] @@ -230,7 +230,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct p6_4_zero_initialized_array_Pair { #[offset(0)] @@ -334,7 +334,7 @@ pub fn test_21() { } heap_numbers.delete(); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(8)] pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { #[offset(0)] @@ -352,7 +352,7 @@ 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, Copyable)] #[byte_size(4)] pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { #[offset(0)] @@ -374,7 +374,7 @@ 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, 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..a6a85380b8 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,19 @@ 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 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, 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, 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..fcf1ba56e1 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,13 @@ 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 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, CopyableUnsafe)] pub struct p6_1_zero_initialized_pointer_to_member_HoldsSelector { pub selector: isize, } @@ -107,14 +107,14 @@ pub unsafe fn test_12() { } static mut counter_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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 +166,7 @@ pub unsafe fn test_15() { }; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union p6_3_zero_initialized_union_Number { pub integer: i32, pub bytes: [libc::c_char; 8], @@ -185,7 +185,7 @@ 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, CopyableUnsafe, Default)] pub struct p6_4_zero_initialized_array_Pair { pub first: i32, pub second: i32, @@ -275,7 +275,7 @@ pub unsafe fn test_21() { }; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { pub zeroed: i32, pub five: i32, @@ -291,7 +291,7 @@ 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, CopyableUnsafe)] pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } @@ -313,7 +313,7 @@ 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, 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..1f60d2d998 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,7 @@ 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(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..23dabaad45 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,7 @@ 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, Copyable)] #[byte_size(4)] pub struct p9_static_member_hides_namespace_variable_HasStaticStep { #[offset(0)] @@ -105,7 +105,7 @@ 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, Copyable)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Widget { @@ -132,7 +132,7 @@ 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, Copyable)] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Account { #[offset(0)] @@ -221,7 +221,7 @@ 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, 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..15c1da0e95 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, Copyable)] #[byte_size(16)] pub struct p2_pointer_to_array_member_HasIntArray { #[offset(0)] @@ -40,7 +40,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct p2_pointer_to_data_member_HasTwoInts { #[offset(0)] @@ -68,7 +68,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct p2_pointer_to_member_of_incomplete_class_CompletedLater { #[offset(0)] @@ -97,7 +97,7 @@ pub fn test_3() { == 4) ); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { #[offset(0)] @@ -105,7 +105,7 @@ 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, 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..dafd53c5da 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,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 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..8aa3fc10ac 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,7 @@ 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, CopyableUnsafe)] pub struct p9_static_member_hides_namespace_variable_HasStaticStep { pub total: i32, } @@ -105,7 +105,7 @@ 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, CopyableUnsafe)] #[cpp_from(i32, construct, value)] pub struct p9_evaluated_each_time_called_Widget { pub id: i32, @@ -133,7 +133,7 @@ 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, CopyableUnsafe)] pub struct p9_evaluated_each_time_called_Account { pub balance: i32, } @@ -227,7 +227,7 @@ 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, 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..78bf32a7f7 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,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 p2_pointer_to_array_member_HasIntArray { pub before: i32, pub elements: [i32; 3], @@ -38,7 +38,7 @@ pub unsafe fn test_0() { assert!(((obj.before) == (1))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct p2_pointer_to_data_member_HasTwoInts { pub first: i32, pub second: i32, @@ -76,7 +76,7 @@ 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, CopyableUnsafe, Default)] pub struct p2_pointer_to_member_of_incomplete_class_CompletedLater { pub first: i32, pub second: i32, @@ -100,13 +100,13 @@ pub unsafe fn test_3() { ); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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..3a5df9abe2 100644 --- a/tests/std/expr/conv/out/refcount/conv.mem.rs +++ b/tests/std/expr/conv/out/refcount/conv.mem.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..675732b6f3 100644 --- a/tests/std/expr/conv/out/unsafe/conv.mem.rs +++ b/tests/std/expr/conv/out/unsafe/conv.mem.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 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..68bab18c4e 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,7 @@ 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 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..199dcabddb 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,7 @@ 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(8)] pub struct HasTwoInts { #[offset(0)] @@ -14,7 +14,7 @@ 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, 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..9834be37ee 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,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct p10_null_converts_to_null_HasTwoInts { #[offset(0)] @@ -24,7 +24,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct p10_null_converts_to_null_HasChar { #[offset(0)] @@ -35,7 +35,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct p10_2_data_member_round_trip_HasTwoInts { #[offset(0)] @@ -43,7 +43,7 @@ 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, 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..6d39cbb0c3 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,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 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..5eb7bdf714 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,13 @@ 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 HasTwoInts { pub first: i32, pub second: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..77b5d79023 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,13 @@ pub unsafe fn test_0() { assert!(((*(*converted)) == (7))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct p10_null_converts_to_null_HasChar { pub character: libc::c_char, } @@ -33,13 +33,13 @@ pub unsafe fn test_1() { assert!(((converted) == -1_isize)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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..43d4cdf940 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,7 @@ 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 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..8277652549 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,7 @@ 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, 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 +30,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { #[offset(0)] @@ -46,7 +46,7 @@ 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, 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..c8520e28d3 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,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 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..977d637a64 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,7 @@ 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, 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 +28,7 @@ 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, CopyableUnsafe, Default)] pub struct p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { pub base: i32, } @@ -54,7 +54,7 @@ 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, 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..c5145264e2 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,7 @@ 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(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..54e5467a3e 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,7 @@ 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(8)] pub struct p4_1_both_null_HasTwoInts { #[offset(0)] @@ -20,7 +20,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct p4_2_one_null_HasTwoInts { #[offset(0)] @@ -36,7 +36,7 @@ pub fn test_1() { assert!((null_pm != first_pm)); assert!(!(null_pm == first_pm)); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct p4_5_members_of_same_union_HasTwoIntMembers { #[offset(0)] @@ -65,7 +65,7 @@ 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, 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..3654cc940e 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,7 @@ 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(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..66d2f5d2ab 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,7 @@ 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(8)] pub struct p3_arrow_star_HasTwoInts { #[offset(0)] @@ -27,7 +27,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct p4_object_expression_sequenced_first_HasValue { #[offset(0)] @@ -69,7 +69,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { #[offset(0)] @@ -98,9 +98,27 @@ 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, CopyAssignable, MoveAssignable, 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 +127,43 @@ 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, + CopyConstructible, + CopyAssignable, + MoveAssignable, + 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 +174,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 +186,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 +206,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..a207449eed 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,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 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..fc445d96e9 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,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 p4_1_both_null_HasTwoInts { pub first: i32, pub second: i32, @@ -19,7 +19,7 @@ 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, CopyableUnsafe, Default)] pub struct p4_2_one_null_HasTwoInts { pub first: i32, pub second: i32, @@ -33,7 +33,7 @@ pub unsafe fn test_1() { assert!(!((null_pm) == (first_pm))); } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union p4_5_members_of_same_union_HasTwoIntMembers { pub first: i32, pub second: i32, @@ -50,7 +50,7 @@ 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, 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..f3aaaccb69 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,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 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..b680038629 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,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 p3_arrow_star_HasTwoInts { pub first: i32, pub second: i32, @@ -31,7 +31,7 @@ pub unsafe fn test_0() { ); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct p4_object_expression_sequenced_first_HasValue { pub value: i32, } @@ -65,7 +65,7 @@ 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, CopyableUnsafe, Default)] pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { pub first: i32, pub second: i32, @@ -94,16 +94,20 @@ 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, CopyAssignableUnsafe, MoveAssignableUnsafe, 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 +119,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 +128,28 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + 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 +162,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 +174,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..8d61468a61 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,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, CppFrom)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable)] #[cpp_from(i32, construct, value)] #[byte_size(16)] pub struct p1_default_member_initializer_names_object_Holder { @@ -31,7 +31,9 @@ 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, 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..6de1136fa9 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,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, CppFromUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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 +37,9 @@ 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, 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..4f55762821 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,10 @@ 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(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, Copyable)] #[byte_size(4)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { #[offset(0)] @@ -43,7 +43,7 @@ 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, 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..f75b0a720d 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,10 @@ 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 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, CopyableUnsafe)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { pub id: i32, } @@ -30,7 +30,7 @@ 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, 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..1ab5178144 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,16 @@ 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, + Destructible, + Copyable, + Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -64,7 +73,16 @@ 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, + Destructible, + Copyable, + Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] 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..b04d834948 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,14 @@ 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, + DestructibleUnsafe, + CopyableUnsafe, + Default, )] #[cpp_from(i32, construct, value)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { @@ -64,7 +71,14 @@ 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, + DestructibleUnsafe, + CopyableUnsafe, + Default, )] #[cpp_from(i32, construct, value)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { 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..32a097febb 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,16 @@ 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, + Destructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +53,25 @@ 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 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() } } @@ -200,20 +221,14 @@ 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(); } @@ -223,10 +238,6 @@ impl LifetimeTrackedImpl for Ptr { }); (*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..28564c4d23 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,16 @@ 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, + Destructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -44,13 +53,25 @@ 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 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 +97,16 @@ 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, + Destructible, + Copyable, + Default, )] #[cpp_into(i32, to_i32)] #[byte_size(4)] @@ -207,20 +237,14 @@ 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(); } @@ -230,10 +254,6 @@ impl LifetimeTrackedImpl for Ptr { }); (*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; 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..1e279040bc 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,14 @@ 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, + DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,10 +39,6 @@ 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) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } @@ -43,7 +46,15 @@ impl LifetimeTracked { (*(&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 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(); + } +} +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 +63,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 } } 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..c26c7f6dbe 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,14 @@ 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, + DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct LifetimeTracked { pub uses: i32, } @@ -32,10 +39,6 @@ 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) { - (&raw mut self.uses).write(0); - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } @@ -43,7 +46,15 @@ impl LifetimeTracked { (*(&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 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(); + } +} +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 +63,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 +86,14 @@ 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, + DestructibleUnsafe, + CopyableUnsafe, + Default, )] #[cpp_into(i32, to_i32)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { diff --git a/tests/std/temp/out/refcount/temp.type.rs b/tests/std/temp/out/refcount/temp.type.rs index ea929ef43c..fafd43ca48 100644 --- a/tests/std/temp/out/refcount/temp.type.rs +++ b/tests/std/temp/out/refcount/temp.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct p2_6_pointer_to_member_argument_HasTwoInts { #[offset(0)] @@ -17,21 +17,21 @@ 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, 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, 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, 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..06a61aadc3 100644 --- a/tests/std/temp/out/unsafe/temp.type.rs +++ b/tests/std/temp/out/unsafe/temp.type.rs @@ -7,24 +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, 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, 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, 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, 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..62151af01c 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,7 @@ 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, Copyable)] #[byte_size(4)] pub struct p2_reference_does_not_instantiate_Member { #[offset(0)] @@ -17,13 +17,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, 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 +47,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..05a30a775d 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,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)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct p2_reference_does_not_instantiate_Member { pub value: i32, } @@ -25,12 +25,12 @@ impl Default for p2_reference_does_not_instantiate_Member { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, 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..548fe4723f 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -14,13 +14,34 @@ 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, + CopyAssignable, + MoveAssignable, + 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 +50,37 @@ 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, + CopyConstructible, + CopyAssignable, + MoveAssignable, +)] #[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 +99,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 +107,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 +119,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, 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 +150,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 +176,9 @@ pub fn test_4() { }) ); } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssignable, MoveAssignable, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct p10_forward_in_template_A { @@ -140,6 +189,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 +214,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 +227,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 +235,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 +253,34 @@ 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, + CopyAssignable, + MoveAssignable, + 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 +290,38 @@ 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, + CopyAssignable, + MoveAssignable, + 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 +331,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 +347,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 +362,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 +381,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 +388,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..1aba0e1ce8 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -12,7 +12,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct p9_move_trivially_copyable_Point { #[offset(0)] @@ -43,13 +43,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, 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 +66,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 +82,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 +102,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..6fc2ef179c 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,7 @@ 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 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..ea83ca0084 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -15,7 +15,15 @@ pub unsafe fn test_0() { assert!(((value) == (2))); } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct p6_forward_like_Movable { pub value: i32, @@ -24,10 +32,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 +48,32 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, +)] 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 +94,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 +113,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, Default)] #[cpp_from(i32, construct, value)] pub struct p9_move_Movable { pub value: i32, @@ -99,7 +122,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 +146,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 +171,14 @@ pub unsafe fn test_4() { ); } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, +)] #[cpp_from(i32, construct, value)] pub struct p10_forward_in_template_A { pub value: i32, @@ -159,12 +191,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 +211,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 +227,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 +252,15 @@ pub unsafe fn test_7() { assert!(((a.value) == (0))); } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct p11_move_if_noexcept_NoexceptMove { pub value: i32, @@ -225,10 +269,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 +286,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 +295,15 @@ impl Clone for p11_move_if_noexcept_NoexceptMove { } } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct p11_move_if_noexcept_ThrowingMove { pub value: i32, @@ -256,10 +312,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 +329,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 +347,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 +360,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..293c399b79 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -13,7 +13,7 @@ pub unsafe fn test_0() { assert!(((source) == (1))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct p9_move_trivially_copyable_Point { pub x: i32, pub y: i32, @@ -42,7 +42,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, Default)] #[cpp_from(i32, construct, value)] pub struct p10_move_constructor_A { pub value: i32, @@ -51,7 +51,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 +66,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 +80,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..d55c5c52eb 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,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 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..bced5e5085 100644 --- a/tests/ub/out/refcount/ctor_ref_member.rs +++ b/tests/ub/out/refcount/ctor_ref_member.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, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, 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..24795e940a 100644 --- a/tests/ub/out/refcount/self_referencing_initializer.rs +++ b/tests/ub/out/refcount/self_referencing_initializer.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..ecffc37d20 100644 --- a/tests/ub/out/refcount/ub6.rs +++ b/tests/ub/out/refcount/ub6.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..40356b74ef 100644 --- a/tests/ub/out/unsafe/ctor_ref_member.rs +++ b/tests/ub/out/unsafe/ctor_ref_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, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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..91d0ca7546 100644 --- a/tests/ub/out/unsafe/self_referencing_initializer.rs +++ b/tests/ub/out/unsafe/self_referencing_initializer.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 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..e5d176dd96 100644 --- a/tests/ub/out/unsafe/ub6.rs +++ b/tests/ub/out/unsafe/ub6.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 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..af231c3e50 100644 --- a/tests/unit/out/refcount/05_new.rs +++ b/tests/unit/out/refcount/05_new.rs @@ -6,10 +6,10 @@ 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(1)] pub struct A {} -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..3386a00e03 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct GraphNode { #[offset(0)] @@ -15,7 +15,7 @@ pub struct GraphNode { #[byte_size(8)] pub next: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct Graph { #[offset(0)] @@ -24,7 +24,7 @@ pub struct Graph { #[byte_size(8)] pub adj: Ptr>, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -40,10 +40,10 @@ impl Default for Partial { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct Declared {} -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..7281147b84 100644 --- a/tests/unit/out/refcount/addr_of_global.rs +++ b/tests/unit/out/refcount/addr_of_global.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 Inner { #[offset(0)] pub value: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..e5ef6a069f 100644 --- a/tests/unit/out/refcount/anonymous-struct.rs +++ b/tests/unit/out/refcount/anonymous-struct.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Outer_Named { #[offset(0)] @@ -14,7 +14,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -22,7 +22,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct anon_1 { #[offset(0)] @@ -30,7 +30,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct anon_2 { #[offset(0)] @@ -38,19 +38,19 @@ 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, 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, 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, Copyable, Default)] #[byte_size(12)] pub struct anon_3 { #[offset(0)] @@ -62,7 +62,7 @@ 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, Copyable, Default)] #[byte_size(44)] pub struct Outer { #[offset(0)] @@ -126,7 +126,7 @@ fn main_0() -> i32 { ); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..a7c5bbf4e5 100644 --- a/tests/unit/out/refcount/anonymous-struct_c.rs +++ b/tests/unit/out/refcount/anonymous-struct_c.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Named { #[offset(0)] @@ -14,7 +14,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -22,7 +22,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct anon_1 { #[offset(0)] @@ -30,7 +30,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct anon_2 { #[offset(0)] @@ -38,19 +38,19 @@ 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, 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, 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, Copyable, Default)] #[byte_size(12)] pub struct anon_3 { #[offset(0)] @@ -62,7 +62,7 @@ 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, Copyable, Default)] #[byte_size(44)] pub struct Outer { #[offset(0)] @@ -132,7 +132,7 @@ fn main_0() -> i32 { ); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..e9bd25cbfd 100644 --- a/tests/unit/out/refcount/anonymous_enum.rs +++ b/tests/unit/out/refcount/anonymous_enum.rs @@ -12,7 +12,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -24,7 +24,7 @@ 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, 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..b136e41810 100644 --- a/tests/unit/out/refcount/anonymous_enum_c.rs +++ b/tests/unit/out/refcount/anonymous_enum_c.rs @@ -12,7 +12,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -24,7 +24,7 @@ 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, 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..f75be0b727 100644 --- a/tests/unit/out/refcount/any.rs +++ b/tests/unit/out/refcount/any.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..10578fb74b 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, Copyable)] #[byte_size(20)] pub struct S { #[offset(0)] @@ -38,7 +38,7 @@ thread_local!( buf: Box::new([0; 4]), })); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..8e9d6138f2 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, 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..2209aae2d9 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_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, MoveCtor, MoveAssign)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyConstructible, CopyAssignable, +)] #[byte_size(32)] pub struct NonCopy { #[offset(0)] @@ -15,6 +17,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 +60,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..386c7d3c6e 100644 --- a/tests/unit/out/refcount/array_reference.rs +++ b/tests/unit/out/refcount/array_reference.rs @@ -59,7 +59,7 @@ 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, 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..e4a43f07c3 100644 --- a/tests/unit/out/refcount/as_const.rs +++ b/tests/unit/out/refcount/as_const.rs @@ -9,7 +9,7 @@ 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, 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..5bb95da148 100644 --- a/tests/unit/out/refcount/assign_rhs_first.rs +++ b/tests/unit/out/refcount/assign_rhs_first.rs @@ -15,7 +15,7 @@ pub fn advance_1() -> i32 { }); return 10; } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..ba6986b900 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -810,21 +810,21 @@ pub fn test_reference_members_9() { (*other.borrow()) ); } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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, 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, Copyable, Default)] #[byte_size(8)] pub struct Slot_10 { #[offset(0)] @@ -889,7 +889,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Holder_12 { #[offset(0)] @@ -923,7 +923,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Node_14 { #[offset(0)] @@ -1020,26 +1020,26 @@ 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, 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, 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, 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, Copyable, Default)] #[byte_size(8)] pub struct Slot_20 { #[offset(0)] @@ -1081,13 +1081,13 @@ 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, 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, Copyable, Default)] #[byte_size(4)] pub struct GlobalRecord { #[offset(0)] @@ -1328,13 +1328,13 @@ 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, 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, Copyable, Default)] #[byte_size(8)] pub struct Link_33 { #[offset(0)] @@ -1345,7 +1345,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct IndexedBinding {} pub fn test_binding_35() { @@ -1580,7 +1580,7 @@ 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, Copyable, Default)] #[byte_size(12)] pub struct IndexedMember { #[offset(0)] @@ -1941,7 +1941,7 @@ thread_local!( scoped_values_52.with(|v| v.decay()), ]))); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct PointerSelector { #[offset(0)] @@ -2143,7 +2143,15 @@ 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, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct Counts_59 { @@ -2151,7 +2159,20 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Pair_60 { #[offset(0)] @@ -2462,13 +2483,13 @@ fn main_0() -> i32 { ); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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, Copyable)] #[byte_size(12)] pub struct Owner_63 { #[offset(0)] @@ -2488,21 +2509,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..1ffff7cdf6 100644 --- a/tests/unit/out/refcount/bounded_struct_ptr.rs +++ b/tests/unit/out/refcount/bounded_struct_ptr.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..d88c6ddcbc 100644 --- a/tests/unit/out/refcount/bst.rs +++ b/tests/unit/out/refcount/bst.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..97422e04f7 100644 --- a/tests/unit/out/refcount/c_struct.rs +++ b/tests/unit/out/refcount/c_struct.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -14,7 +14,7 @@ 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, Copyable, Default)] #[byte_size(16)] pub struct Line { #[offset(0)] @@ -24,7 +24,7 @@ pub struct Line { #[byte_size(8)] pub end: Point, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct Node { #[offset(0)] @@ -37,7 +37,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -45,7 +45,7 @@ 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, 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..68f15593a2 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -10,7 +10,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -18,14 +18,14 @@ 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, 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, Copyable)] #[byte_size(40)] pub struct Grid { #[offset(0)] @@ -53,7 +53,15 @@ impl Default for Grid { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(32)] pub struct Bag { @@ -63,6 +71,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 +539,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..69633bbe6a 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, 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..897acfc8a1 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -14,7 +14,7 @@ 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, Copyable, Default)] #[byte_size(16)] pub struct Route { #[offset(0)] @@ -23,7 +23,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Counter { #[offset(0)] @@ -36,7 +36,7 @@ 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, 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..574eafcca9 100644 --- a/tests/unit/out/refcount/class_template_lazy_member.rs +++ b/tests/unit/out/refcount/class_template_lazy_member.rs @@ -6,32 +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, 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, 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, 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, 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, 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..d1090687b1 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct MyContainer_int_ { @@ -15,8 +23,29 @@ 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, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct MyContainer_char_ { @@ -24,8 +53,29 @@ 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, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct MyContainer_float_ { @@ -33,7 +83,20 @@ 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, Copyable, Default)] #[byte_size(2)] pub struct Boxed_short_ { #[offset(0)] @@ -44,7 +107,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct Boxed_int_ { #[offset(0)] @@ -55,7 +118,7 @@ impl Boxed_int_ { return (v + v); } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Boxed_long_ { #[offset(0)] @@ -66,7 +129,7 @@ impl Boxed_long_ { return (v + v); } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Outer_int__Inner_int_ { #[offset(0)] @@ -74,13 +137,13 @@ 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, 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, Copyable, Default)] #[byte_size(16)] pub struct Outer_long__Inner_int_ { #[offset(0)] @@ -88,7 +151,7 @@ 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, Copyable, Default)] #[byte_size(16)] pub struct Outer_long__Inner_char_ { #[offset(0)] @@ -96,13 +159,13 @@ 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, 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, Copyable, Default)] #[byte_size(4)] pub struct Elem { #[offset(0)] @@ -228,8 +291,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 +315,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 +325,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 +349,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 +359,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 +383,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..dea8feaf5d 100644 --- a/tests/unit/out/refcount/clone_vs_move.rs +++ b/tests/unit/out/refcount/clone_vs_move.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 Bar { #[offset(0)] pub w: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(40)] pub struct Foo { #[offset(0)] @@ -44,7 +44,7 @@ impl Default for Foo { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..87ebed0964 100644 --- a/tests/unit/out/refcount/comma_operator.rs +++ b/tests/unit/out/refcount/comma_operator.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..f2be8f7538 100644 --- a/tests/unit/out/refcount/complex_function.rs +++ b/tests/unit/out/refcount/complex_function.rs @@ -15,27 +15,27 @@ 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, 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, 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, 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, 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..879af437ad 100644 --- a/tests/unit/out/refcount/compound_assign_paren.rs +++ b/tests/unit/out/refcount/compound_assign_paren.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..2d507aa650 100644 --- a/tests/unit/out/refcount/concepts.rs +++ b/tests/unit/out/refcount/concepts.rs @@ -11,7 +11,7 @@ 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, 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..74308900e4 100644 --- a/tests/unit/out/refcount/constexpr_function.rs +++ b/tests/unit/out/refcount/constexpr_function.rs @@ -21,7 +21,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct Flag { #[offset(0)] @@ -44,7 +44,7 @@ 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, 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..7aa38b1d0e 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -10,7 +10,16 @@ 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, + Destructible, + Copyable, + Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -18,7 +27,7 @@ pub struct S { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable)] #[cpp_from(i32, construct_1, value)] #[byte_size(8)] pub struct Point { diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index ce9e3647ea..8bbd973b9f 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.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, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + MoveAssignable, + Default, +)] #[byte_size(32)] pub struct Holder { #[offset(0)] @@ -16,6 +27,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 +149,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..2967e9456e 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(32)] pub struct S { @@ -17,6 +25,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 +76,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..0b415e49e2 100644 --- a/tests/unit/out/refcount/conversion_operator_same_translation.rs +++ b/tests/unit/out/refcount/conversion_operator_same_translation.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, CppFrom, Default)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, +)] #[cpp_into(i8, to_i8)] #[cpp_into(u8, to_u8)] #[byte_size(4)] @@ -14,7 +16,9 @@ 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, 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..732fa7620b 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -9,7 +9,16 @@ 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, + MoveConstructible, + MoveAssignable, + Default, +)] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -17,6 +26,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 +49,11 @@ 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, Copyable)] #[byte_size(4)] pub struct NonConstAssign { #[offset(0)] @@ -46,12 +71,29 @@ impl Default for NonConstAssign { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + MoveConstructible, + MoveAssignable, +)] #[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 +105,17 @@ impl Default for RefQualified { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(24)] pub struct Holder { #[offset(0)] @@ -74,6 +126,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 +161,54 @@ 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, + MoveConstructible, + MoveAssignable, + 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, + CopyConstructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(12)] pub struct HasCopyCounted { #[offset(0)] @@ -115,6 +219,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 +262,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 +281,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 +311,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 +358,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 +379,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 +396,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 +436,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 +447,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 +473,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..936178be85 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -9,27 +9,64 @@ 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, + MoveConstructible, + MoveAssignable, + 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, + CopyConstructible, + MoveConstructible, + MoveAssignable, +)] #[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 +88,54 @@ impl Default for NonConst { } } } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + MoveConstructible, + MoveAssignable, + 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, + CopyConstructible, + MoveConstructible, + MoveAssignable, +)] #[byte_size(12)] pub struct Holder { #[offset(0)] @@ -77,6 +146,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 +169,138 @@ impl Default for Holder { } } } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + CopyAssignable, + MoveAssignable, + 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, + CopyConstructible, + CopyAssignable, + MoveAssignable, + 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, + MoveConstructible, + MoveAssignable, + 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, MoveConstructible, MoveAssignable, +)] #[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 +325,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 +341,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 +360,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 +383,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 +426,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 +440,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 +451,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 +481,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 +498,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 +535,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..dc141e2405 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, 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, + Destructible, + CopyAssignable, + MoveAssignable, +)] #[cpp_from(i32, construct, value)] #[byte_size(16)] pub struct Explicit { @@ -31,7 +42,7 @@ impl Default for Explicit { { ::zero_init() } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(16)] pub struct Implicit { #[offset(0)] @@ -63,9 +74,8 @@ impl Default for Implicit { ZeroInitialization, VaArg, FnPtrArg, - MoveCtor, CppFrom, - MoveAssign, + CopyAssignable, Default, )] #[cpp_from(i32, construct, value)] @@ -74,35 +84,59 @@ pub struct DefaultCopyUserMove { #[offset(0)] pub v: i32, } -#[derive( - Record, - ByteRepr, - ZeroInitialization, - VaArg, - FnPtrArg, - MoveCtor, - CppFrom, - CopyAssign, - MoveAssign, - Default, -)] +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, CppFrom, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] 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)] #[cpp_from(i32, construct, value)] #[byte_size(64)] pub struct Buffer { @@ -119,12 +153,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)] #[byte_size(48)] pub struct Owner { #[offset(0)] @@ -140,6 +201,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,7 +242,15 @@ impl Default for Owner { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct Copyable { @@ -161,17 +258,20 @@ pub struct Copyable { #[byte_size(24)] pub data: Vec, } -#[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - MoveCtor, - CppFrom, - MoveAssign, - Destructible, - Default, -)] +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, Destructible, Default)] #[cpp_from(i32, construct, value)] #[byte_size(32)] pub struct Holder { @@ -185,6 +285,24 @@ 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(); + } +} 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) })) @@ -293,7 +411,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 +428,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 +439,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 +461,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 +471,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 +486,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 +511,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 +520,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 +549,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 +566,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 +585,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) @@ -491,7 +611,7 @@ fn main_0() -> i32 { }; 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 = @@ -508,7 +628,7 @@ fn main_0() -> i32 { })); let _dtor_h3 = std::mem::DropGuard::new(h3.clone(), |__p| Destructible::destroy(__p.as_pointer())); - ({ HolderImpl::move_assign(&h3.as_pointer(), h2.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 +639,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,63 +651,14 @@ 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); @@ -605,8 +674,6 @@ impl ExplicitImpl for Ptr { } 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 { @@ -619,78 +686,16 @@ 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 c5e1620098..c1f1497609 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -6,21 +6,45 @@ 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, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] 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)] #[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 { { @@ -49,7 +73,7 @@ impl Default for Immovable { } } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Default)] #[byte_size(8)] pub struct Container { #[offset(0)] @@ -58,13 +82,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, 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 +137,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 +153,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,38 +178,19 @@ 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 }); - } - 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(); - } -} pub trait ImmovableImpl { fn construct(&self); } @@ -166,58 +201,21 @@ 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_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..1c772ee03e 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, 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, 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, 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..5f2473d1cf 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -12,7 +12,7 @@ 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, Copyable)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Bar { @@ -58,7 +58,7 @@ 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, 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..dbab9f5808 100644 --- a/tests/unit/out/refcount/default_in_statics.rs +++ b/tests/unit/out/refcount/default_in_statics.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct Inner { #[offset(0)] @@ -15,7 +15,7 @@ pub struct Inner { #[byte_size(8)] pub name: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(88)] pub struct Outer { #[offset(0)] @@ -61,7 +61,7 @@ impl Default for Outer { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..10231c0604 100644 --- a/tests/unit/out/refcount/delete_array_order.rs +++ b/tests/unit/out/refcount/delete_array_order.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, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(16)] pub struct Element { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index 4ac2b27a80..43cfaeecfb 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -9,31 +9,39 @@ 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, Destructible, Copyable, Default, +)] #[byte_size(1)] pub struct S {} -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, 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)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, 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)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(1)] pub struct Outer { #[offset(0)] #[byte_size(1)] pub m: Middle, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(3)] pub struct ArrayMember { #[offset(0)] @@ -50,26 +58,34 @@ impl Default for ArrayMember { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, 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)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(1)] pub struct Templated_char_ { #[offset(0)] pub v: i8, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct Templated_int_ { #[offset(0)] pub v: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct Copied { #[offset(0)] @@ -82,13 +98,17 @@ 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, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct Tagged { #[offset(0)] pub tag: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(20)] pub struct Ordered { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index ee4c0cc0cb..b43afdf342 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -12,7 +12,9 @@ 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, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -27,7 +29,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index 382cd76114..d575fec9a1 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -12,13 +12,17 @@ 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, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct S { #[offset(0)] pub v: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, 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/doubly_linked_list.rs b/tests/unit/out/refcount/doubly_linked_list.rs index 827ab5b981..6f8fee4e55 100644 --- a/tests/unit/out/refcount/doubly_linked_list.rs +++ b/tests/unit/out/refcount/doubly_linked_list.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(24)] pub struct Node { #[offset(0)] diff --git a/tests/unit/out/refcount/enum_default_in_static.rs b/tests/unit/out/refcount/enum_default_in_static.rs index bbfeeb0727..59f594d25d 100644 --- a/tests/unit/out/refcount/enum_default_in_static.rs +++ b/tests/unit/out/refcount/enum_default_in_static.rs @@ -10,7 +10,7 @@ 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, 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..ef653721a9 100644 --- a/tests/unit/out/refcount/enum_int_interop.rs +++ b/tests/unit/out/refcount/enum_int_interop.rs @@ -19,7 +19,7 @@ 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, 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..ea4d1f5b82 100644 --- a/tests/unit/out/refcount/enum_int_interop_c.rs +++ b/tests/unit/out/refcount/enum_int_interop_c.rs @@ -19,7 +19,7 @@ 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, 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..3abf11fce9 100644 --- a/tests/unit/out/refcount/enum_underlying_type.rs +++ b/tests/unit/out/refcount/enum_underlying_type.rs @@ -25,7 +25,7 @@ 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, 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..c85afbfb5b 100644 --- a/tests/unit/out/refcount/exprs.rs +++ b/tests/unit/out/refcount/exprs.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 X { #[offset(0)] pub x: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..bb87bb2b8b 100644 --- a/tests/unit/out/refcount/fft.rs +++ b/tests/unit/out/refcount/fft.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..db3e1c1fc0 100644 --- a/tests/unit/out/refcount/field_aliasing.rs +++ b/tests/unit/out/refcount/field_aliasing.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct In { #[offset(0)] @@ -14,7 +14,7 @@ pub struct In { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(32)] pub struct S { #[offset(0)] @@ -41,7 +41,7 @@ impl Default for S { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..14e0f76246 100644 --- a/tests/unit/out/refcount/field_array_elem_ptr.rs +++ b/tests/unit/out/refcount/field_array_elem_ptr.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -14,7 +14,7 @@ pub struct Point { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..85bc8c30f8 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -6,13 +6,15 @@ 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 Counter { #[offset(0)] pub n: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyConstructible, CopyAssignable, +)] #[byte_size(40)] pub struct S { #[offset(0)] @@ -28,6 +30,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 +144,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..7b50ae3260 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, Copyable)] #[byte_size(12)] pub struct Inner { #[offset(0)] @@ -26,7 +26,7 @@ impl Default for Inner { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Header { #[offset(0)] @@ -34,7 +34,9 @@ pub struct Header { #[offset(4)] pub size: i16, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyConstructible, CopyAssignable, +)] #[byte_size(104)] pub struct Outer { #[offset(0)] @@ -57,6 +59,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 +249,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 +268,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..169801a381 100644 --- a/tests/unit/out/refcount/field_pointers_malloced_struct.rs +++ b/tests/unit/out/refcount/field_pointers_malloced_struct.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..a2acb2693c 100644 --- a/tests/unit/out/refcount/field_reinterpret_write_through.rs +++ b/tests/unit/out/refcount/field_reinterpret_write_through.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct In { #[offset(0)] @@ -14,7 +14,7 @@ pub struct In { #[offset(4)] pub b: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..0bbb72b2dd 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..985618301b 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,7 @@ 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 In { #[offset(0)] @@ -14,7 +14,7 @@ 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, 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..e6e7ab310b 100644 --- a/tests/unit/out/refcount/first_member_downcast.rs +++ b/tests/unit/out/refcount/first_member_downcast.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 base { #[offset(0)] pub kind: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..39b1d1818b 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, 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..adaf0560a2 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, Copyable)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -26,7 +26,7 @@ impl Default for S { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct E { #[offset(0)] @@ -34,7 +34,7 @@ pub struct E { #[offset(4)] pub w: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..b530cfe295 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -28,7 +28,9 @@ 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, 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..25418a6675 100644 --- a/tests/unit/out/refcount/fn_ptr_cast.rs +++ b/tests/unit/out/refcount/fn_ptr_cast.rs @@ -24,7 +24,7 @@ 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, 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..53aef0e58e 100644 --- a/tests/unit/out/refcount/fn_ptr_stable_sort.rs +++ b/tests/unit/out/refcount/fn_ptr_stable_sort.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..27637f8686 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct Handler { #[offset(0)] @@ -21,7 +21,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct S {} impl S { @@ -35,13 +35,19 @@ impl S { return (x + 3); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, 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 +103,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 +114,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..f9f96308ba 100644 --- a/tests/unit/out/refcount/fn_ptr_typedef_cast.rs +++ b/tests/unit/out/refcount/fn_ptr_typedef_cast.rs @@ -18,7 +18,7 @@ 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, 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..92d68b3f1a 100644 --- a/tests/unit/out/refcount/fn_ptr_vtable.rs +++ b/tests/unit/out/refcount/fn_ptr_vtable.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..402c5dbe88 100644 --- a/tests/unit/out/refcount/fn_ref.rs +++ b/tests/unit/out/refcount/fn_ref.rs @@ -21,7 +21,7 @@ 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, 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..4d1665e304 100644 --- a/tests/unit/out/refcount/for_body_destructor.rs +++ b/tests/unit/out/refcount/for_body_destructor.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, Destructible, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, +)] #[byte_size(4)] pub struct Guard { #[offset(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..9ccc0f98d5 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(32)] pub struct S { @@ -17,6 +25,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 +59,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..0f8a80dc04 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -9,7 +9,17 @@ 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, + CopyAssignable, + MoveAssignable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct Tracked { @@ -20,6 +30,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 +53,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 +64,17 @@ 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, + CopyConstructible, + CopyAssignable, + MoveAssignable, + Default, )] #[cpp_from(Tracked, construct_1, mut_ptr)] #[cpp_from_move(Tracked, construct_2, ptr)] @@ -49,6 +84,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 +191,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 +217,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..aae635d2da 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -9,7 +9,17 @@ 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, + CopyAssignable, + MoveAssignable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct Tracked { @@ -20,6 +30,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 +53,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 +147,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 +154,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..8697e9569d 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -11,7 +11,17 @@ 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, + CopyAssignable, + MoveAssignable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct Tracked { @@ -22,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 { @@ -30,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() } } @@ -50,7 +75,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 +105,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 +121,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 +144,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 +151,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..650b06e1d8 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -11,7 +11,17 @@ 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, + CopyAssignable, + MoveAssignable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct Tracked { @@ -22,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 { @@ -30,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() } } @@ -82,7 +107,18 @@ pub fn forward_pack_7( }; return digits; } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + MoveAssignable, + Default, +)] #[byte_size(24)] pub struct Pair { #[offset(0)] @@ -92,6 +128,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 +216,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 +240,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..80aa6a46a9 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -18,7 +18,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct V { #[offset(0)] @@ -32,7 +32,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct W_int_ { #[offset(0)] @@ -41,13 +41,13 @@ 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, 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, 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..f37fe4ffdf 100644 --- a/tests/unit/out/refcount/function_overloading.rs +++ b/tests/unit/out/refcount/function_overloading.rs @@ -21,7 +21,7 @@ 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, 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..bc4213a4e8 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -94,7 +94,7 @@ thread_local!( }) })); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..36d7010c2a 100644 --- a/tests/unit/out/refcount/global_init_side_effect.rs +++ b/tests/unit/out/refcount/global_init_side_effect.rs @@ -9,7 +9,9 @@ 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, 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..6a0e7051cd 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -32,7 +32,7 @@ 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, Copyable)] #[byte_size(4)] pub struct Ctor { #[offset(0)] @@ -77,7 +77,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct Holder {} thread_local!( @@ -96,7 +96,7 @@ 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, 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..c22c5fdaef 100644 --- a/tests/unit/out/refcount/global_pointers.rs +++ b/tests/unit/out/refcount/global_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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..4a0ec06bc3 100644 --- a/tests/unit/out/refcount/global_without_initializer.rs +++ b/tests/unit/out/refcount/global_without_initializer.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(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)] diff --git a/tests/unit/out/refcount/goto_aggregate_default.rs b/tests/unit/out/refcount/goto_aggregate_default.rs index 0449ac8471..f52b28148b 100644 --- a/tests/unit/out/refcount/goto_aggregate_default.rs +++ b/tests/unit/out/refcount/goto_aggregate_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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..b0a4f649f0 100644 --- a/tests/unit/out/refcount/goto_cleanup.rs +++ b/tests/unit/out/refcount/goto_cleanup.rs @@ -76,7 +76,7 @@ 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, 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..d06efedd84 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(24)] pub struct MinHeapNode { #[offset(0)] @@ -40,7 +40,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, Default)] #[byte_size(32)] pub struct MinHeap { #[offset(0)] @@ -56,6 +56,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 +302,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 +467,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..8e7778a4cd 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,7 @@ 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 Item { #[offset(0)] diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index 46b99638a5..a50366e9ae 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct Holder { @@ -15,6 +23,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 +85,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..fc563b7534 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -19,7 +19,7 @@ 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, Copyable)] #[byte_size(24)] pub struct S { #[offset(0)] @@ -45,7 +45,7 @@ impl Default for S { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..dfa79e5525 100644 --- a/tests/unit/out/refcount/init.rs +++ b/tests/unit/out/refcount/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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..5d90c0d7d7 100644 --- a/tests/unit/out/refcount/init_list.rs +++ b/tests/unit/out/refcount/init_list.rs @@ -9,7 +9,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -17,7 +17,7 @@ pub struct Pair { #[offset(4)] pub b: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(8)] pub struct Holder { #[offset(0)] @@ -36,7 +36,7 @@ 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, 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..7ba51f59d0 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.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, MoveCtor, MoveAssign)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyConstructible, CopyAssignable, +)] #[byte_size(48)] pub struct Elem { #[offset(0)] @@ -19,6 +21,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 +55,9 @@ impl Default for Elem { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyConstructible, CopyAssignable, +)] #[byte_size(88)] pub struct State { #[offset(0)] @@ -50,6 +77,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 +204,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)] #[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 +371,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 +391,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 +422,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 +448,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 +462,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 +484,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 +505,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 +520,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..e9eb65658a 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct Edge { #[offset(0)] @@ -99,7 +99,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, Default)] #[byte_size(24)] pub struct DisjointSet { #[offset(0)] @@ -111,7 +111,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, Default)] #[byte_size(16)] pub struct Graph { #[offset(0)] @@ -122,6 +144,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 +275,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 +385,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..b065f29b68 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_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, Destructible)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] #[byte_size(1)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { #[offset(0)] @@ -24,14 +24,16 @@ 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, Destructible, 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)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { #[offset(0)] @@ -54,7 +56,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { #[offset(0)] @@ -63,7 +65,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)] #[cpp_from(FnPtr i32 > , construct, value)] #[byte_size(8)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { @@ -73,6 +75,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() } @@ -212,9 +220,7 @@ 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) })); @@ -265,7 +271,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 +280,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..eabfded09f 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.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, VaArg, FnPtrArg, MoveCtor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssignable, MoveAssignable)] #[byte_size(8)] pub struct Counted { #[offset(0)] @@ -14,6 +14,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 +33,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 +51,29 @@ 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, + Destructible, + CopyAssignable, + MoveAssignable, +)] #[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 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 +102,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 +122,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 +151,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() }), ))); @@ -204,33 +233,19 @@ fn main_0() -> i32 { } 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(); } diff --git a/tests/unit/out/refcount/lambda_capture_ref.rs b/tests/unit/out/refcount/lambda_capture_ref.rs index 6ececc76f2..822709ca3a 100644 --- a/tests/unit/out/refcount/lambda_capture_ref.rs +++ b/tests/unit/out/refcount/lambda_capture_ref.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..419ef201b5 100644 --- a/tests/unit/out/refcount/lambda_capture_star_this.rs +++ b/tests/unit/out/refcount/lambda_capture_star_this.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(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)] diff --git a/tests/unit/out/refcount/lambda_capture_this.rs b/tests/unit/out/refcount/lambda_capture_this.rs index 66a24ed128..e8e3f1acb4 100644 --- a/tests/unit/out/refcount/lambda_capture_this.rs +++ b/tests/unit/out/refcount/lambda_capture_this.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..4bf6b69796 100644 --- a/tests/unit/out/refcount/lambda_capture_value.rs +++ b/tests/unit/out/refcount/lambda_capture_value.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..2174dc0d37 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, 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, 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..492948022b 100644 --- a/tests/unit/out/refcount/lambda_generic_explicit_args.rs +++ b/tests/unit/out/refcount/lambda_generic_explicit_args.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..21ea249a7d 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -9,7 +9,7 @@ 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, 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..f43bde7dcf 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, Destructible, Default)] #[cpp_from(i32, construct, value)] #[byte_size(8)] pub struct Owner { @@ -16,6 +14,12 @@ 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()); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -32,7 +36,7 @@ fn main_0() -> i32 { { 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() })); }, @@ -89,7 +93,6 @@ fn main_0() -> i32 { } pub trait OwnerImpl { fn construct(&self, v: i32); - fn move_from(&self, o: Ptr); fn destructor(&self); fn take(&self) -> FnPtr i32>; } @@ -97,10 +100,6 @@ 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(); } @@ -109,7 +108,7 @@ impl OwnerImpl for Ptr { { 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..7af0641263 100644 --- a/tests/unit/out/refcount/lambda_nested.rs +++ b/tests/unit/out/refcount/lambda_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(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)] diff --git a/tests/unit/out/refcount/lambda_static_local.rs b/tests/unit/out/refcount/lambda_static_local.rs index 7015e7960a..be19023729 100644 --- a/tests/unit/out/refcount/lambda_static_local.rs +++ b/tests/unit/out/refcount/lambda_static_local.rs @@ -78,7 +78,7 @@ 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, 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..4f43e49bf5 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.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, MoveCtor, MoveAssign)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyConstructible, CopyAssignable, +)] #[byte_size(32)] pub struct UserDefined { #[offset(0)] @@ -17,6 +19,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 +63,7 @@ impl Default for UserDefined { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(16)] pub struct FieldIsLibcType { #[offset(0)] @@ -77,34 +113,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..4bfdb59e58 100644 --- a/tests/unit/out/refcount/linked_list.rs +++ b/tests/unit/out/refcount/linked_list.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..e8293dbd61 100644 --- a/tests/unit/out/refcount/local_anon_struct_collision.rs +++ b/tests/unit/out/refcount/local_anon_struct_collision.rs @@ -12,7 +12,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct anon_1 { #[offset(0)] @@ -26,7 +26,7 @@ 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, 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..8a9e2dab20 100644 --- a/tests/unit/out/refcount/local_record_template.rs +++ b/tests/unit/out/refcount/local_record_template.rs @@ -29,13 +29,13 @@ 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, 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, Copyable, Default)] #[byte_size(8)] pub struct Local_7 { #[offset(0)] @@ -45,7 +45,7 @@ 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, Copyable, Default)] #[byte_size(16)] pub struct Local_1 { #[offset(0)] @@ -66,7 +66,7 @@ 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, 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..16636ffb66 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -12,7 +12,7 @@ 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, 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..5293c73cd8 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -15,13 +15,35 @@ 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, + CopyAssignable, + MoveAssignable, + 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 +59,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 +308,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..1c4806b26d 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -9,7 +9,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Key { #[offset(0)] @@ -33,7 +33,7 @@ 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, 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..a8d53a87a9 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -18,20 +18,35 @@ 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, CopyAssignable, MoveAssignable, +)] #[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 +65,7 @@ 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, Copyable)] #[byte_size(4)] pub struct RefItem { #[offset(0)] @@ -369,7 +384,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 +425,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 +465,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 +507,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 +665,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 +711,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 +753,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 +762,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..bd512e532c 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -12,7 +12,7 @@ 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, Copyable)] #[byte_size(4)] pub struct Item { #[offset(0)] @@ -42,7 +42,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, Copyable)] #[byte_size(12)] pub struct Temporary { #[offset(0)] @@ -63,7 +63,7 @@ impl Default for Temporary { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(12)] pub struct Nested { #[offset(0)] @@ -80,13 +80,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)] #[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 { { @@ -109,7 +123,7 @@ impl Default for Noncopy { { Noncopy { n: 5 } } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable)] #[cpp_from(i32, construct_1, ptr)] #[byte_size(8)] pub struct Held { @@ -2434,8 +2448,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 +2460,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..fc268c3828 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -20,13 +20,35 @@ 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, + MoveConstructible, + MoveAssignable, + 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 +64,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 +229,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..46d437bba3 100644 --- a/tests/unit/out/refcount/memcpy_struct_bytes.rs +++ b/tests/unit/out/refcount/memcpy_struct_bytes.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..f0c1557b78 100644 --- a/tests/unit/out/refcount/memcpy_struct_layouts.rs +++ b/tests/unit/out/refcount/memcpy_struct_layouts.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct packed { #[offset(0)] @@ -18,7 +18,7 @@ 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, Copyable, Default)] #[byte_size(12)] pub struct reordered { #[offset(0)] @@ -28,7 +28,7 @@ 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, Copyable, Default)] #[byte_size(16)] pub struct tail { #[offset(0)] @@ -36,7 +36,7 @@ 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, Copyable, Default)] #[byte_size(24)] pub struct nested { #[offset(0)] @@ -45,7 +45,7 @@ pub struct nested { #[offset(16)] pub c: i8, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..f7755f6d7e 100644 --- a/tests/unit/out/refcount/memcpy_struct_struct.rs +++ b/tests/unit/out/refcount/memcpy_struct_struct.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..3fe22a8794 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, 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..ecb69ffc79 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -6,15 +6,29 @@ 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, Default, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub v: i32, } +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)] #[byte_size(4)] pub struct ConstMoveAssign { @@ -41,7 +55,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 +79,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 +88,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 +105,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 +129,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 +178,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..1d99b35f0c 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -6,13 +6,19 @@ 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, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub v: i32, } +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)] #[byte_size(4)] pub struct ConstMove { @@ -30,7 +36,17 @@ impl Default for ConstMove { } } } -#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + CopyAssignable, + MoveAssignable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct ThrowingMove { @@ -41,6 +57,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 +80,21 @@ 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, + CopyAssignable, + MoveAssignable, + Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(12)] pub struct NoexceptMove { @@ -64,6 +105,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 +128,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 +143,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 +159,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 +193,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 +216,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 +252,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 +266,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 +280,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 +305,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 +320,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 +330,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..ec4ac6b5e7 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -6,18 +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, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + CopyAssignable, + MoveAssignable, + 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 +64,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 +94,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 +112,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 +122,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 +137,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..25772e1e11 100644 --- a/tests/unit/out/refcount/nested_structs.rs +++ b/tests/unit/out/refcount/nested_structs.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 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, Copyable, Default)] #[byte_size(8)] pub struct Level0_Level1_1_Level2_1_Level3_2 { #[offset(0)] @@ -20,19 +20,19 @@ 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, 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, 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, Copyable, Default)] #[byte_size(8)] pub struct Level0_Level1_2 { #[offset(0)] @@ -40,7 +40,7 @@ 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, 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..b3ed2b3137 100644 --- a/tests/unit/out/refcount/new.rs +++ b/tests/unit/out/refcount/new.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..7f599d18c1 100644 --- a/tests/unit/out/refcount/new_bst.rs +++ b/tests/unit/out/refcount/new_bst.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..07c06ee90a 100644 --- a/tests/unit/out/refcount/new_struct.rs +++ b/tests/unit/out/refcount/new_struct.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -14,7 +14,7 @@ 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, 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..ba84d59bcb 100644 --- a/tests/unit/out/refcount/nttp_distinct_specializations.rs +++ b/tests/unit/out/refcount/nttp_distinct_specializations.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct S_2_ { #[offset(0)] @@ -14,13 +14,13 @@ 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, 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, 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..e15b51c545 100644 --- a/tests/unit/out/refcount/offsetof.rs +++ b/tests/unit/out/refcount/offsetof.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(12)] pub struct Layout { #[offset(0)] @@ -16,7 +16,7 @@ pub struct Layout { #[offset(8)] pub c: u16, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..6d98671f7c 100644 --- a/tests/unit/out/refcount/opaque_forward_decl.rs +++ b/tests/unit/out/refcount/opaque_forward_decl.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..582ae62cd0 100644 --- a/tests/unit/out/refcount/opaque_record_copy.rs +++ b/tests/unit/out/refcount/opaque_record_copy.rs @@ -6,10 +6,10 @@ 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(1)] pub struct Probe {} -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..cc73a24de7 100644 --- a/tests/unit/out/refcount/opaque_then_defined.rs +++ b/tests/unit/out/refcount/opaque_then_defined.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct list { #[offset(0)] @@ -15,7 +15,7 @@ pub struct list { #[offset(8)] pub size: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..ac76f23327 100644 --- a/tests/unit/out/refcount/operator_arithmetic_free.rs +++ b/tests/unit/out/refcount/operator_arithmetic_free.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(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)] diff --git a/tests/unit/out/refcount/operator_arithmetic_member.rs b/tests/unit/out/refcount/operator_arithmetic_member.rs index eaacebd799..7ef07f17a9 100644 --- a/tests/unit/out/refcount/operator_arithmetic_member.rs +++ b/tests/unit/out/refcount/operator_arithmetic_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(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)] diff --git a/tests/unit/out/refcount/operator_bitwise_free.rs b/tests/unit/out/refcount/operator_bitwise_free.rs index 63f57d0d91..98fb3a69fd 100644 --- a/tests/unit/out/refcount/operator_bitwise_free.rs +++ b/tests/unit/out/refcount/operator_bitwise_free.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(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)] diff --git a/tests/unit/out/refcount/operator_bitwise_member.rs b/tests/unit/out/refcount/operator_bitwise_member.rs index 45aba391cb..ddf3703aa6 100644 --- a/tests/unit/out/refcount/operator_bitwise_member.rs +++ b/tests/unit/out/refcount/operator_bitwise_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(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)] diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index ecf6df1e15..255d63070b 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Eq { #[offset(0)] @@ -19,7 +19,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Cmp { #[offset(0)] @@ -37,7 +37,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct Both { #[offset(0)] @@ -53,7 +53,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct OrdOnly { #[offset(0)] @@ -69,7 +69,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct Inner { #[offset(0)] @@ -85,7 +85,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Outer { #[offset(0)] @@ -104,7 +104,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct Secondary { #[offset(0)] @@ -120,7 +120,7 @@ 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, 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..88031e2d09 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.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(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)] @@ -46,7 +46,7 @@ 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, 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..bf7d127387 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_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(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)] diff --git a/tests/unit/out/refcount/operator_comparison_mixed.rs b/tests/unit/out/refcount/operator_comparison_mixed.rs index d4cc7e01d0..223a953ab9 100644 --- a/tests/unit/out/refcount/operator_comparison_mixed.rs +++ b/tests/unit/out/refcount/operator_comparison_mixed.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(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)] diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 455f1ffdc5..2089962407 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct X { #[offset(0)] @@ -40,19 +40,19 @@ 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, 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, 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, Copyable, Default)] #[byte_size(4)] pub struct Mixed { #[offset(0)] @@ -68,14 +68,16 @@ 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, 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, Copyable, Default)] #[byte_size(4)] pub struct Boolish { #[offset(0)] @@ -125,7 +127,7 @@ 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, 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..ca82519550 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, 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..bc0b01c00e 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_free.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_free.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(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)] diff --git a/tests/unit/out/refcount/operator_compound_assignment_member.rs b/tests/unit/out/refcount/operator_compound_assignment_member.rs index 3cfb3136fc..9ca22ec6e9 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_member.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_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(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)] diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index 57ea87a36f..415a566ce9 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -10,7 +10,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Defaulted { #[offset(0)] @@ -38,7 +38,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct DefaultedOrd { #[offset(0)] @@ -65,7 +65,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct Inline { #[offset(0)] @@ -81,7 +81,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct OutOfLine { #[offset(0)] @@ -107,7 +107,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct Tmpl_int_ { #[offset(0)] @@ -123,7 +123,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Tmpl_long_ { #[offset(0)] @@ -132,7 +132,7 @@ 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, 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..8855ee962f 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..17b37fd64b 100644 --- a/tests/unit/out/refcount/operator_logical_free.rs +++ b/tests/unit/out/refcount/operator_logical_free.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(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)] diff --git a/tests/unit/out/refcount/operator_logical_member.rs b/tests/unit/out/refcount/operator_logical_member.rs index 7db68dd321..e648cb7fb6 100644 --- a/tests/unit/out/refcount/operator_logical_member.rs +++ b/tests/unit/out/refcount/operator_logical_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(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)] diff --git a/tests/unit/out/refcount/operator_member_pointer_free.rs b/tests/unit/out/refcount/operator_member_pointer_free.rs index 0a7ee74641..d87578ecb9 100644 --- a/tests/unit/out/refcount/operator_member_pointer_free.rs +++ b/tests/unit/out/refcount/operator_member_pointer_free.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 Inner { #[offset(0)] pub x: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..1e85a8e90f 100644 --- a/tests/unit/out/refcount/operator_member_pointer_member.rs +++ b/tests/unit/out/refcount/operator_member_pointer_member.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 Inner { #[offset(0)] pub x: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct Table {} impl Table { @@ -23,7 +23,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, 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..e03adf9161 100644 --- a/tests/unit/out/refcount/operator_other_free.rs +++ b/tests/unit/out/refcount/operator_other_free.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(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)] diff --git a/tests/unit/out/refcount/operator_other_member.rs b/tests/unit/out/refcount/operator_other_member.rs index 3b627eea25..03269a4298 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(1)] pub struct Static {} impl Static { @@ -14,7 +14,9 @@ impl Static { return (a * b); } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, 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..de5e30139e 100644 --- a/tests/unit/out/refcount/operator_overloads.rs +++ b/tests/unit/out/refcount/operator_overloads.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(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)] diff --git a/tests/unit/out/refcount/operator_qualifiers.rs b/tests/unit/out/refcount/operator_qualifiers.rs index 6bf6f81a61..363da1beb3 100644 --- a/tests/unit/out/refcount/operator_qualifiers.rs +++ b/tests/unit/out/refcount/operator_qualifiers.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(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)] diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 9298036a09..d297d888bc 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.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(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)] diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 8b372ebfe5..3559c0352f 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(4)] pub struct Lt { #[offset(0)] @@ -22,7 +22,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct Eq { #[offset(0)] @@ -33,7 +33,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct Cmp { #[offset(0)] @@ -49,7 +49,7 @@ 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, Copyable, Default)] #[byte_size(4)] pub struct Free { #[offset(0)] @@ -71,7 +71,7 @@ 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, 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..884fb41d4b 100644 --- a/tests/unit/out/refcount/overload_mangling.rs +++ b/tests/unit/out/refcount/overload_mangling.rs @@ -19,16 +19,16 @@ 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, 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, 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, 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..ede9e4b4cf 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -6,28 +6,36 @@ 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, 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, 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, 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, Copyable, Default, +)] #[cpp_from(Celsius, construct_1, ptr)] #[cpp_from_move(Celsius, construct_2, ptr)] #[byte_size(8)] @@ -37,14 +45,16 @@ 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, 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, Copyable)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Fallback { @@ -62,27 +72,33 @@ impl Default for Fallback { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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, 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, 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, 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..f4965c8e34 100644 --- a/tests/unit/out/refcount/pod.rs +++ b/tests/unit/out/refcount/pod.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..229ca5e981 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, 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..fec0a64206 100644 --- a/tests/unit/out/refcount/pointers.rs +++ b/tests/unit/out/refcount/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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..a4e8c874de 100644 --- a/tests/unit/out/refcount/polymorphism.rs +++ b/tests/unit/out/refcount/polymorphism.rs @@ -9,10 +9,10 @@ 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, 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, 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..fefcae70b3 100644 --- a/tests/unit/out/refcount/ptr_cast_init.rs +++ b/tests/unit/out/refcount/ptr_cast_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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct header { #[offset(0)] @@ -14,7 +14,7 @@ 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, 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..e02afffab9 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.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 Chunk { #[offset(0)] pub data: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct Writer { #[offset(0)] @@ -23,7 +23,15 @@ pub struct Writer { pub chunk: Chunk, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(48)] pub struct JPEGData { @@ -34,6 +42,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 +133,7 @@ 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, Copyable)] #[cpp_from(i32, construct_1, value)] #[byte_size(8)] pub struct Pair { @@ -277,7 +302,9 @@ 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, CopyConstructible, CopyAssignable, +)] #[byte_size(32)] pub struct Bytes { #[offset(0)] @@ -288,6 +315,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 +364,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, Copyable)] #[byte_size(24)] pub struct Plain { #[offset(0)] @@ -349,7 +397,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Counted { #[offset(0)] @@ -606,29 +654,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 +667,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..771ff49e92 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, Copyable)] #[byte_size(72)] pub struct Pair { #[offset(0)] @@ -51,7 +51,7 @@ 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, 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..eb1b3f6726 100644 --- a/tests/unit/out/refcount/reference_wrapper.rs +++ b/tests/unit/out/refcount/reference_wrapper.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..ce04a50816 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, Copyable)] #[byte_size(16)] pub struct Pair { #[offset(0)] @@ -29,7 +29,7 @@ impl Default for Pair { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..622077c6ae 100644 --- a/tests/unit/out/refcount/refs_as_args.rs +++ b/tests/unit/out/refcount/refs_as_args.rs @@ -30,7 +30,7 @@ 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, 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..2c4c8b88e2 100644 --- a/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs +++ b/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -14,7 +14,7 @@ pub struct S { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(28)] pub struct W { #[offset(0)] @@ -34,7 +34,7 @@ impl Default for W { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..294f2de046 100644 --- a/tests/unit/out/refcount/reinterpret_cast_struct.rs +++ b/tests/unit/out/refcount/reinterpret_cast_struct.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..f4c6f98c50 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,7 @@ 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(8)] pub struct Point { #[offset(0)] @@ -14,7 +14,7 @@ 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, 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..5eaf9015dd 100644 --- a/tests/unit/out/refcount/reserved_keywords.rs +++ b/tests/unit/out/refcount/reserved_keywords.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(152)] pub struct S { #[offset(0)] @@ -86,13 +86,13 @@ 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, 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, 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..89d308e9c1 100644 --- a/tests/unit/out/refcount/return_move.rs +++ b/tests/unit/out/refcount/return_move.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct node { #[offset(0)] @@ -15,7 +15,7 @@ pub struct node { #[byte_size(8)] pub next: Ptr, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..18f775d606 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, Destructible)] #[cpp_from(i32, construct, value)] #[byte_size(20)] pub struct Buffer { @@ -37,6 +26,82 @@ pub struct Buffer { #[offset(16)] pub size: i32, } +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 +109,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() } } @@ -63,7 +128,7 @@ pub fn make_3(mut size: i32) -> Buffer { 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() }; } @@ -82,7 +147,7 @@ fn main_0() -> i32 { 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 = @@ -95,7 +160,7 @@ 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 = @@ -112,18 +177,18 @@ fn main_0() -> i32 { let _dtor_d = 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)); @@ -132,10 +197,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) { @@ -155,74 +216,6 @@ impl BufferImpl for Ptr { 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..832f39f4c7 100644 --- a/tests/unit/out/refcount/rule_of_three.rs +++ b/tests/unit/out/refcount/rule_of_three.rs @@ -13,7 +13,15 @@ thread_local!( pub static copies_1: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Destructible, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Destructible, + MoveConstructible, + MoveAssignable, )] #[cpp_from(i32, construct, value)] #[byte_size(20)] @@ -25,6 +33,42 @@ pub struct Buffer { #[offset(16)] pub size: i32, } +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 +76,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() } } @@ -69,7 +113,7 @@ fn main_0() -> i32 { 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 = @@ -84,18 +128,18 @@ fn main_0() -> i32 { })); let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); - ({ BufferImpl::copy_assign(&c.as_pointer(), a.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 = @@ -104,7 +148,7 @@ fn main_0() -> i32 { 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) @@ -117,8 +161,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) { @@ -138,38 +180,6 @@ impl BufferImpl for Ptr { 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..936f98ecff 100644 --- a/tests/unit/out/refcount/rvalue_rule_arg_move.rs +++ b/tests/unit/out/refcount/rvalue_rule_arg_move.rs @@ -13,7 +13,7 @@ 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, MoveAssignable, Default, )] #[cpp_from(i32, construct, value)] #[byte_size(4)] @@ -21,11 +21,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 +73,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 +98,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..cae6d63f58 100644 --- a/tests/unit/out/refcount/rvalue_struct.rs +++ b/tests/unit/out/refcount/rvalue_struct.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..5c66392ca3 100644 --- a/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs +++ b/tests/unit/out/refcount/scalar_builtin_construct_destruct.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..d4a60f4798 100644 --- a/tests/unit/out/refcount/self_referencing_initializer.rs +++ b/tests/unit/out/refcount/self_referencing_initializer.rs @@ -6,14 +6,14 @@ 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, 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, Copyable, Default)] #[byte_size(16)] pub struct node { #[offset(0)] @@ -22,7 +22,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, 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..7c5e1d52b7 100644 --- a/tests/unit/out/refcount/size_t_static_member.rs +++ b/tests/unit/out/refcount/size_t_static_member.rs @@ -9,13 +9,13 @@ 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, 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, 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..d17cae2aab 100644 --- a/tests/unit/out/refcount/size_t_template_param.rs +++ b/tests/unit/out/refcount/size_t_template_param.rs @@ -10,14 +10,18 @@ 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, 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, 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..022db88dcf 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -9,15 +9,37 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); -#[derive( - Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign, -)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] #[cpp_from(i32, construct_1, value)] #[byte_size(4)] 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 +55,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() } } @@ -54,15 +76,24 @@ pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { 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, -)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, construct, value)] #[byte_size(4)] 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 +109,15 @@ 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, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct Bag { @@ -86,6 +125,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 +603,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 +622,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..4501711810 100644 --- a/tests/unit/out/refcount/static_local.rs +++ b/tests/unit/out/refcount/static_local.rs @@ -33,7 +33,7 @@ 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, 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..ffc512cf90 100644 --- a/tests/unit/out/refcount/static_var_in_class.rs +++ b/tests/unit/out/refcount/static_var_in_class.rs @@ -9,7 +9,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct C {} thread_local!( @@ -17,7 +17,7 @@ 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, 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..9dbccf6d00 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.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, CppFrom, Default)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, 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..7caf4818ea 100644 --- a/tests/unit/out/refcount/strdup.rs +++ b/tests/unit/out/refcount/strdup.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..3b4142ca28 100644 --- a/tests/unit/out/refcount/string_literal_ptr_init.rs +++ b/tests/unit/out/refcount/string_literal_ptr_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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..11850d446c 100644 --- a/tests/unit/out/refcount/string_substr.rs +++ b/tests/unit/out/refcount/string_substr.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..3d1f30235f 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, 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..1170386126 100644 --- a/tests/unit/out/refcount/struct_ctor.rs +++ b/tests/unit/out/refcount/struct_ctor.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct StructWithCtor { #[offset(0)] @@ -17,14 +17,16 @@ 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, 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, 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..5c9b995f00 100644 --- a/tests/unit/out/refcount/struct_default_ctor.rs +++ b/tests/unit/out/refcount/struct_default_ctor.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -25,13 +25,13 @@ impl Default for S { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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, Copyable)] #[byte_size(16)] pub struct Holder { #[offset(0)] @@ -51,7 +51,7 @@ 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, 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..15478370e1 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, 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..2507420182 100644 --- a/tests/unit/out/refcount/struct_ptr.rs +++ b/tests/unit/out/refcount/struct_ptr.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..d90ef8dcc9 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -9,7 +9,16 @@ 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, + MoveConstructible, + MoveAssignable, + Default, +)] #[byte_size(8)] pub struct Counted { #[offset(0)] @@ -17,6 +26,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 +47,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 +70,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 +91,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..c23cccac6d 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -12,22 +12,56 @@ 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, + CopyAssignable, + MoveAssignable, + 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, + CopyConstructible, + CopyAssignable, + MoveAssignable, + Default, +)] #[byte_size(8)] pub struct Two { #[offset(0)] @@ -37,6 +71,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 +130,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 +169,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..9caeed5b80 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -12,7 +12,9 @@ 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, CopyAssignable, MoveAssignable, Default, +)] #[byte_size(8)] pub struct Movable { #[offset(0)] @@ -20,6 +22,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 +45,20 @@ 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, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(48)] pub struct Holder { @@ -43,6 +69,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 +98,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 +123,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 +131,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..eb06fdb8d5 100644 --- a/tests/unit/out/refcount/structured_binding_range_for.rs +++ b/tests/unit/out/refcount/structured_binding_range_for.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..b010b6d55f 100644 --- a/tests/unit/out/refcount/structured_binding_ref.rs +++ b/tests/unit/out/refcount/structured_binding_ref.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..ee0f7e0e40 100644 --- a/tests/unit/out/refcount/structured_binding_trivial.rs +++ b/tests/unit/out/refcount/structured_binding_trivial.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 1cecae8b63..a6b2494d1f 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -9,20 +9,42 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); -#[derive( - Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign, -)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] #[cpp_from(i32, construct_1, value)] #[byte_size(4)] 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() } } @@ -38,16 +60,7 @@ impl Default for Tracked { } } #[derive( - Clone, - Record, - ByteRepr, - ZeroInitialization, - VaArg, - FnPtrArg, - MoveCtor, - CopyAssign, - MoveAssign, - Default, + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyConstructible, Default, )] #[byte_size(8)] pub struct Pair { @@ -58,9 +71,35 @@ pub struct Pair { #[byte_size(4)] pub y: Tracked, } -#[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CopyAssign, MoveAssign, -)] +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, CopyConstructible)] #[byte_size(16)] pub struct Arrays { #[offset(0)] @@ -72,6 +111,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 { { @@ -99,8 +222,9 @@ thread_local!( VaArg, FnPtrArg, CppFrom, - CopyAssign, Destructible, + MoveConstructible, + MoveAssignable, Default, )] #[cpp_from(i32, construct, value)] @@ -109,16 +233,39 @@ 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 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, + Destructible, + CopyConstructible, + MoveConstructible, + MoveAssignable, + Default, )] #[byte_size(8)] pub struct CopyOnlyPair { @@ -129,6 +276,13 @@ 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(); + } +} thread_local!( pub static moves_3: Value = Rc::new(RefCell::new(0)); ); @@ -138,30 +292,46 @@ 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, Destructible, 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 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 +342,8 @@ impl Clone for Moved { ZeroInitialization, VaArg, FnPtrArg, - MoveCtor, - CopyAssign, - MoveAssign, Destructible, + CopyConstructible, Default, )] #[byte_size(8)] @@ -187,6 +355,34 @@ 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(); + } +} 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 +400,27 @@ pub fn swapped_once_6() -> bool { }); return ok; } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, 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()); @@ -236,7 +446,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 +467,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 +489,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,) => { ({ @@ -585,7 +795,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 +816,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,) => { ({ @@ -789,120 +999,22 @@ fn main_0() -> i32 { ); 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)); @@ -910,126 +1022,28 @@ impl CopyOnlyPairImpl for Ptr { } 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 +1052,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..f6c95bbcba 100644 --- a/tests/unit/out/refcount/tag_vs_identifier_collision.rs +++ b/tests/unit/out/refcount/tag_vs_identifier_collision.rs @@ -10,7 +10,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct widget { #[offset(0)] @@ -18,7 +18,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct point_struct { #[offset(0)] @@ -26,7 +26,7 @@ pub struct point_struct { #[offset(4)] pub y: i32, } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct point { #[offset(0)] @@ -49,7 +49,7 @@ impl Default for point { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct slot_union { #[offset(0)] @@ -75,20 +75,20 @@ 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, 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, 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, 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..475548c202 100644 --- a/tests/unit/out/refcount/template_default_arg.rs +++ b/tests/unit/out/refcount/template_default_arg.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable)] #[cpp_from(i32, construct_1, value)] #[byte_size(4)] pub struct A { @@ -24,7 +24,7 @@ impl Default for A { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(4)] pub struct B { #[offset(0)] @@ -41,7 +41,9 @@ impl Default for B { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, +)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct NoDefault { @@ -60,7 +62,9 @@ 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, 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..31a1749c3d 100644 --- a/tests/unit/out/refcount/template_static_member.rs +++ b/tests/unit/out/refcount/template_static_member.rs @@ -9,19 +9,19 @@ 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, 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, 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, Copyable, Default)] #[byte_size(1)] pub struct Static_long_ {} thread_local!( @@ -30,7 +30,7 @@ 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, Copyable, Default)] #[byte_size(1)] pub struct Range_int_ {} thread_local!( @@ -39,7 +39,7 @@ 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, 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..bb868bef2a 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct Inner { @@ -15,7 +23,22 @@ 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, CopyConstructible, CopyAssignable, +)] #[byte_size(56)] pub struct Outer { #[offset(0)] @@ -29,6 +52,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 +176,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..363bae465e 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct Outer { @@ -15,12 +23,27 @@ 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, Copyable, Default, +)] #[cpp_from(Vec , construct, ptr)] #[byte_size(4)] pub struct H { @@ -52,19 +75,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..f459f09cda 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -7,7 +7,15 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct Inner { @@ -15,8 +23,29 @@ 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, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(48)] pub struct Outer { @@ -27,6 +56,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 +106,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..f2be93cf13 100644 --- a/tests/unit/out/refcount/this.rs +++ b/tests/unit/out/refcount/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, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, +)] #[cpp_from(i32, construct_1, value)] #[byte_size(16)] pub struct S { @@ -19,7 +21,9 @@ 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, 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..891abd6e5a 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Outer_RunInfo { #[offset(0)] @@ -15,7 +15,15 @@ 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, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct Outer { @@ -23,6 +31,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 +62,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..2dc363d144 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,7 @@ 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(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..03a468c059 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -14,7 +14,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -54,7 +54,7 @@ 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, 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..602a77a6a7 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -14,7 +14,7 @@ pub struct Inner { #[offset(4)] pub b: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] #[byte_size(48)] pub struct Cookie { #[offset(0)] @@ -46,7 +46,7 @@ impl Default for Cookie { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..0f205401f5 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, 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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(128)] pub struct anon_0 { #[offset(0)] @@ -55,7 +55,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..56840e48e1 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, 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, 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, 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, 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..0064139fbe 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, 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, 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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(64)] pub struct anon_0 { #[offset(0)] @@ -81,7 +81,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..03e61b7d6a 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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -29,7 +29,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..739650bfac 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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -29,7 +29,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..f5fc86650f 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, 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, 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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(256)] pub struct anon_0 { #[offset(0)] @@ -78,7 +78,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..4e9624725f 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, 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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(128)] pub struct anon_0 { #[offset(0)] @@ -49,14 +49,14 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(128)] pub struct anon_1 { #[offset(0)] @@ -79,7 +79,7 @@ impl Default for anon_1 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..00cce6bf99 100644 --- a/tests/unit/out/refcount/union_pointer_pun_address.rs +++ b/tests/unit/out/refcount/union_pointer_pun_address.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 node_a { #[offset(0)] pub n: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(16)] pub struct node_b { #[offset(0)] @@ -34,7 +34,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, 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..ddda9d5544 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, 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..e417665f5c 100644 --- a/tests/unit/out/refcount/union_struct_dual_use.rs +++ b/tests/unit/out/refcount/union_struct_dual_use.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -17,7 +17,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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(16)] pub struct anon_1 { #[offset(0)] @@ -40,7 +40,7 @@ impl Default for anon_1 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..9f2ad0c864 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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -44,7 +44,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..cc96e94435 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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -32,7 +32,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..4fab46abac 100644 --- a/tests/unit/out/refcount/union_tagged_struct_arms.rs +++ b/tests/unit/out/refcount/union_tagged_struct_arms.rs @@ -10,7 +10,7 @@ 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, Copyable, Default)] #[byte_size(24)] pub struct anon_1 { #[offset(0)] @@ -21,7 +21,7 @@ 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, Copyable, Default)] #[byte_size(16)] pub struct anon_2 { #[offset(0)] @@ -33,7 +33,7 @@ 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, Copyable, Default)] #[byte_size(40)] pub struct anon_3 { #[offset(0)] @@ -47,7 +47,7 @@ pub struct anon_3 { #[offset(32)] pub width: i32, } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[derive(VaArg, FnPtrArg, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(40)] pub struct anon_0 { #[offset(0)] @@ -73,7 +73,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..e2a805fc54 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, Copyable, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -39,7 +39,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..ba07ffd8fc 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -6,14 +6,28 @@ 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, 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, Copyable, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -228,8 +242,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 +252,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..87955a0a1e 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, 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..e1c2d7a06a 100644 --- a/tests/unit/out/refcount/unique_ptr_field_reset.rs +++ b/tests/unit/out/refcount/unique_ptr_field_reset.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 Data { #[offset(0)] pub v: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Default)] #[byte_size(16)] pub struct Holder { #[offset(0)] @@ -21,6 +21,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 +76,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 +84,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..f27cd620e4 100644 --- a/tests/unit/out/refcount/unique_ptr_nested.rs +++ b/tests/unit/out/refcount/unique_ptr_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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -14,13 +14,27 @@ pub struct Inner { #[offset(4)] pub y: i32, } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, 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 +62,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..6bb65fda88 100644 --- a/tests/unit/out/refcount/unique_ptr_struct.rs +++ b/tests/unit/out/refcount/unique_ptr_struct.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..71f7e9978b 100644 --- a/tests/unit/out/refcount/va_arg_mixed_types.rs +++ b/tests/unit/out/refcount/va_arg_mixed_types.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..1982bb15fb 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,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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..53276f195b 100644 --- a/tests/unit/out/refcount/va_arg_struct_ctx.rs +++ b/tests/unit/out/refcount/va_arg_struct_ctx.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct context { #[offset(0)] @@ -23,7 +23,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, 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..7a5b9ab5a3 100644 --- a/tests/unit/out/refcount/va_arg_void_ptr.rs +++ b/tests/unit/out/refcount/va_arg_void_ptr.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, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..4dec257d9d 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -31,7 +31,16 @@ 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, + Destructible, + Copyable, + Default, )] #[cpp_from(Ptr , construct, mut_ptr)] #[byte_size(16)] @@ -62,7 +71,7 @@ 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, Copyable, Default)] #[byte_size(8)] pub struct Cursor_3 { #[offset(0)] diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 8d9bbcd66e..bcac7061a5 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.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(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)] @@ -14,7 +14,15 @@ 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, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(48)] pub struct Foo { @@ -25,6 +33,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 +635,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..81a328fc08 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] +#[derive( + Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, 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, 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..383e269e33 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.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(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -15,7 +15,15 @@ pub struct Point { pub y: i32, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(48)] pub struct Holder { @@ -26,6 +34,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 +158,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..9ef0bb4357 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -6,10 +6,10 @@ 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(1)] pub struct TestAllocator_int_ {} -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, 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..b9594ddfc7 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -8,7 +8,15 @@ 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, + CopyConstructible, + CopyAssignable, + Default, )] #[byte_size(24)] pub struct NonTrivial { @@ -16,6 +24,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 +46,33 @@ 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, 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, 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 +132,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..2bdfba5038 100644 --- a/tests/unit/out/unsafe/05_new.rs +++ b/tests/unit/out/unsafe/05_new.rs @@ -7,10 +7,10 @@ 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 A {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..114b5a2b4c 100644 --- a/tests/unit/out/unsafe/10_struct.rs +++ b/tests/unit/out/unsafe/10_struct.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct Graph { pub V: u32, pub adj: *mut *mut GraphNode, @@ -31,7 +31,7 @@ impl Graph { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct Partial { pub p: *mut i32, } @@ -50,11 +50,11 @@ impl Default for Partial { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Declared {} impl Declared {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..d41f2d6634 100644 --- a/tests/unit/out/unsafe/addr_of_global.rs +++ b/tests/unit/out/unsafe/addr_of_global.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Inner { pub value: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..ce9a32f506 100644 --- a/tests/unit/out/unsafe/anonymous-struct.rs +++ b/tests/unit/out/unsafe/anonymous-struct.rs @@ -7,48 +7,48 @@ 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 Outer_Named { pub a: i32, pub b: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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, 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, CopyableUnsafe, Default)] pub struct anon_4 { pub j: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct anon_5 { pub k: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct Outer { pub named: Outer_Named, pub anonymous_named_0: anon_0, @@ -104,7 +104,7 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..c25e1d0e40 100644 --- a/tests/unit/out/unsafe/anonymous-struct_c.rs +++ b/tests/unit/out/unsafe/anonymous-struct_c.rs @@ -7,48 +7,48 @@ 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 Named { pub a: i32, pub b: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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, 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, CopyableUnsafe, Default)] pub struct anon_4 { pub j: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct anon_5 { pub k: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct Outer { pub named: Named, pub anon0: anon_0, @@ -110,7 +110,7 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..89ab511c88 100644 --- a/tests/unit/out/unsafe/anonymous_enum.rs +++ b/tests/unit/out/unsafe/anonymous_enum.rs @@ -13,7 +13,7 @@ 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, CopyableUnsafe, Default)] pub struct S { pub a: i32, } @@ -24,7 +24,7 @@ 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, 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..8d0154ceac 100644 --- a/tests/unit/out/unsafe/anonymous_enum_c.rs +++ b/tests/unit/out/unsafe/anonymous_enum_c.rs @@ -13,7 +13,7 @@ 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, CopyableUnsafe, Default)] pub struct S { pub a: i32, } @@ -24,7 +24,7 @@ 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, 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..bbdfe08b1c 100644 --- a/tests/unit/out/unsafe/any.rs +++ b/tests/unit/out/unsafe/any.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 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..a63c6e47d7 100644 --- a/tests/unit/out/unsafe/array_const_init.rs +++ b/tests/unit/out/unsafe/array_const_init.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 head: i32, pub tail: [i32; 3], @@ -21,7 +21,7 @@ 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, 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..5fb6cc8586 100644 --- a/tests/unit/out/unsafe/array_field_addr.rs +++ b/tests/unit/out/unsafe/array_field_addr.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 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..770659061b 100644 --- a/tests/unit/out/unsafe/array_of_noncopy_struct.rs +++ b/tests/unit/out/unsafe/array_of_noncopy_struct.rs @@ -7,17 +7,21 @@ 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, CopyConstructibleUnsafe, CopyAssignableUnsafe, +)] 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..d1ea821a1b 100644 --- a/tests/unit/out/unsafe/array_reference.rs +++ b/tests/unit/out/unsafe/array_reference.rs @@ -57,7 +57,7 @@ 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, 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..9224dea60b 100644 --- a/tests/unit/out/unsafe/as_const.rs +++ b/tests/unit/out/unsafe/as_const.rs @@ -10,7 +10,7 @@ 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, 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..8f63ae9fbe 100644 --- a/tests/unit/out/unsafe/assign_rhs_first.rs +++ b/tests/unit/out/unsafe/assign_rhs_first.rs @@ -13,7 +13,7 @@ pub unsafe fn advance_1() -> i32 { return 10; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..1610f8c14b 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -836,17 +836,17 @@ pub unsafe fn test_reference_members_9() { }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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, CopyableUnsafe, Default)] pub struct Slot_10 { pub value: *mut i32, } @@ -895,7 +895,7 @@ pub unsafe fn test_pointer_elements_11() { }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Holder_12 { pub p: *mut i32, } @@ -921,7 +921,7 @@ pub unsafe fn test_reference_pointer_13() { }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Node_14 { pub link: *mut *mut Node_14, } @@ -994,22 +994,22 @@ pub unsafe fn test_reference_subfields_18() { }); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Index_16 { pub value: u32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct Index_19 { pub value: i16, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Slot_20 { pub ref_: *mut Index_19, } @@ -1049,12 +1049,12 @@ 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, CopyableUnsafe, Default)] pub struct GlobalRecord_Inner { pub value: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct GlobalRecord { pub inner: GlobalRecord_Inner, } @@ -1320,19 +1320,19 @@ 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, CopyableUnsafe, Default)] pub struct Record_32 { pub value: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct IndexedBinding {} impl IndexedBinding { pub unsafe fn get_1_0(&mut self) -> *mut u32 { @@ -1551,7 +1551,7 @@ 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, CopyableUnsafe, Default)] pub struct IndexedMember { pub key: i32, pub value: u32, @@ -1810,7 +1810,7 @@ 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, CopyableUnsafe, Default)] pub struct PointerSelector { pub ptr: *mut u32, } @@ -1967,16 +1967,24 @@ pub unsafe fn test_stable_containers_58() { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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 +1992,7 @@ impl Counts_59 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Pair_60 { pub u: u32, pub f: i32, @@ -2286,12 +2294,12 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Index_62 { pub value: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..4a4610166f 100644 --- a/tests/unit/out/unsafe/bounded_struct_ptr.rs +++ b/tests/unit/out/unsafe/bounded_struct_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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..cf8ab546c4 100644 --- a/tests/unit/out/unsafe/bst.rs +++ b/tests/unit/out/unsafe/bst.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 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..ee060c757b 100644 --- a/tests/unit/out/unsafe/c_struct.rs +++ b/tests/unit/out/unsafe/c_struct.rs @@ -7,19 +7,19 @@ 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 Point { pub x: i32, pub y: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct Node { pub value: i32, pub next: *mut Node, @@ -29,13 +29,13 @@ 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, 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, 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..fddc6b454f 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -11,18 +11,18 @@ 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, 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, 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, CopyableUnsafe, Default)] pub struct Grid { pub h: i32, pub row: [i32; 3], @@ -30,18 +30,26 @@ pub struct Grid { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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..df2d7a704a 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,7 @@ 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, 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..26b36aab5b 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.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 Pair { pub first: i32, pub second: i32, @@ -42,7 +42,7 @@ impl Pair { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Route { pub path: Pair, pub cost: f64, @@ -55,7 +55,7 @@ impl Route { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Counter { pub v: i32, pub calls: i32, @@ -77,7 +77,7 @@ 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, 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..9ceceb005a 100644 --- a/tests/unit/out/unsafe/class_template_lazy_member.rs +++ b/tests/unit/out/unsafe/class_template_lazy_member.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Point { pub x: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Box_int_ { pub val: i32, } @@ -22,7 +22,7 @@ impl Box_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Box_Point_ { pub val: Point, } @@ -32,7 +32,7 @@ impl Box_Point_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Deduced_int_ { pub val: i32, } @@ -42,7 +42,7 @@ impl Deduced_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..07e3a74d9e 100644 --- a/tests/unit/out/unsafe/class_templates.rs +++ b/tests/unit/out/unsafe/class_templates.rs @@ -8,7 +8,13 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + Default, )] pub struct MyContainer_int_ { vec_: Vec, @@ -36,10 +42,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 +58,13 @@ impl MyContainer_int_ { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + Default, )] pub struct MyContainer_char_ { vec_: Vec, @@ -76,10 +92,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 +108,13 @@ impl MyContainer_char_ { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + Default, )] pub struct MyContainer_float_ { vec_: Vec, @@ -116,10 +142,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 +157,7 @@ impl MyContainer_float_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Boxed_short_ { pub value: i16, } @@ -140,7 +170,7 @@ impl Boxed_short_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Boxed_int_ { pub value: i32, } @@ -153,7 +183,7 @@ impl Boxed_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Boxed_long_ { pub value: i64, } @@ -166,7 +196,7 @@ impl Boxed_long_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Outer_int__Inner_int_ { pub t: i32, pub u: i32, @@ -177,7 +207,7 @@ impl Outer_int__Inner_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Outer_int_ { pub v: i32, } @@ -187,7 +217,7 @@ impl Outer_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Outer_long__Inner_int_ { pub t: i64, pub u: i32, @@ -198,7 +228,7 @@ impl Outer_long__Inner_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Outer_long__Inner_char_ { pub t: i64, pub u: libc::c_char, @@ -209,7 +239,7 @@ impl Outer_long__Inner_char_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Outer_long_ { pub v: i64, } @@ -219,7 +249,7 @@ impl Outer_long_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..7dd801b0df 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Bar { pub w: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Foo { pub x: i32, pub y: *mut i32, @@ -21,7 +21,7 @@ pub struct Foo { pub bar: Bar, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..9985a3a795 100644 --- a/tests/unit/out/unsafe/comma_operator.rs +++ b/tests/unit/out/unsafe/comma_operator.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 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..66e04458d2 100644 --- a/tests/unit/out/unsafe/complex_function.rs +++ b/tests/unit/out/unsafe/complex_function.rs @@ -16,12 +16,12 @@ 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, CopyableUnsafe, Default)] pub struct X1 { pub v: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct X2 { pub v: *mut X1, } @@ -31,7 +31,7 @@ impl X2 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct X3 { pub v: *mut X2, } @@ -41,7 +41,7 @@ impl X3 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..b68a5e1f7a 100644 --- a/tests/unit/out/unsafe/compound_assign_paren.rs +++ b/tests/unit/out/unsafe/compound_assign_paren.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 Item { pub flags: u8, } diff --git a/tests/unit/out/unsafe/concepts.rs b/tests/unit/out/unsafe/concepts.rs index 3e71e246ce..a4de38cac7 100644 --- a/tests/unit/out/unsafe/concepts.rs +++ b/tests/unit/out/unsafe/concepts.rs @@ -12,7 +12,7 @@ const _: () = assert!( "sizeof(int) == 4" ); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..e970188f44 100644 --- a/tests/unit/out/unsafe/constexpr_function.rs +++ b/tests/unit/out/unsafe/constexpr_function.rs @@ -22,7 +22,7 @@ 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, CopyableUnsafe, Default)] pub struct Flag { pub v: i32, } @@ -48,7 +48,7 @@ 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, 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..2a0a5c70a0 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -9,7 +9,14 @@ 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, + DestructibleUnsafe, + CopyableUnsafe, + Default, )] #[cpp_from(i32, construct, value)] pub struct S { @@ -35,7 +42,7 @@ impl S { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe)] #[cpp_from(i32, construct_1, value)] pub struct Point { pub x: i32, diff --git a/tests/unit/out/unsafe/container_element_receiver.rs b/tests/unit/out/unsafe/container_element_receiver.rs index c6755e8cdb..02ff73af59 100644 --- a/tests/unit/out/unsafe/container_element_receiver.rs +++ b/tests/unit/out/unsafe/container_element_receiver.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(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + 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..64d0b37510 100644 --- a/tests/unit/out/unsafe/container_field_addr.rs +++ b/tests/unit/out/unsafe/container_field_addr.rs @@ -8,18 +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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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..e5c551acfb 100644 --- a/tests/unit/out/unsafe/conversion_operator_same_translation.rs +++ b/tests/unit/out/unsafe/conversion_operator_same_translation.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, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, +)] #[cpp_into(libc::c_char, to_libcc_char)] #[cpp_into(u8, to_u8)] pub struct S { @@ -22,7 +24,9 @@ impl S { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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..cd9957e9ed 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -8,7 +8,14 @@ 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, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + Default, +)] pub struct Partial { pub v: i32, pub keep: i32, @@ -18,11 +25,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 +46,13 @@ 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, CopyableUnsafe)] pub struct NonConstAssign { pub mark: i32, } @@ -70,7 +81,16 @@ impl Default for NonConstAssign { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] pub struct RefQualified { pub mark: i32, } @@ -78,7 +98,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 +117,25 @@ impl Default for RefQualified { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + 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 +143,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 +154,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, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct CopyCounted { pub v: i32, @@ -132,11 +171,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 +188,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, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + 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 +248,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 +270,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 +300,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 +339,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 +360,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 +374,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 +414,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..d0b6f03e98 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, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + 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, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] 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, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + 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, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + 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,15 @@ impl Holder { } } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Box_int_ { pub val: i32, @@ -136,10 +186,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 +201,44 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + 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, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct OutOfLine { pub v: i32, @@ -176,11 +247,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 +264,26 @@ 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, MoveConstructibleUnsafe, MoveAssignableUnsafe, +)] 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 +292,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 +316,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 +334,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 +353,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 +376,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 +420,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 +434,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 +445,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 +475,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..f1a65bb058 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -7,13 +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, CopyableUnsafe, Default)] pub struct Inner { pub x: i32, } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, )] #[cpp_from(i32, construct, value)] pub struct Explicit { @@ -30,7 +38,7 @@ impl Explicit { pub unsafe fn destructor(&mut self) {} } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Implicit { pub v: i32, pub inner: Inner, @@ -43,9 +51,8 @@ pub struct Implicit { VaArg, FnPtrArg, ZeroInitializationUnsafe, - MoveCtorUnsafe, CppFromUnsafe, - MoveAssignUnsafe, + CopyAssignableUnsafe, Default, )] #[cpp_from(i32, construct, value)] @@ -56,27 +63,22 @@ 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)); } } #[repr(C)] -#[derive( - VaArg, - FnPtrArg, - ZeroInitializationUnsafe, - MoveCtorUnsafe, - CppFromUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, - Default, -)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct UserCopyDefaultMove { pub v: i32, @@ -85,23 +87,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,15 +114,13 @@ 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, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct Buffer { pub data: Vec, @@ -137,7 +139,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 +149,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 +171,15 @@ impl Buffer { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, 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 +187,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 +210,24 @@ impl Owner { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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 +235,7 @@ impl Copyable { } } #[repr(C)] -#[derive( - FnPtrArg, - ZeroInitializationUnsafe, - MoveCtorUnsafe, - CppFromUnsafe, - MoveAssignUnsafe, - DestructibleUnsafe, - Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct Holder { pub inner: Inner, @@ -244,12 +252,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(); { @@ -369,7 +381,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 +396,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 +405,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 +424,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 +434,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 +446,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 +459,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 +468,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 +496,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 +516,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 +539,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(); @@ -553,7 +565,7 @@ 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 { @@ -580,7 +592,7 @@ unsafe fn main_0() -> i32 { let _dtor_h3 = std::mem::DropGuard::new(&raw mut h3, |__p| unsafe { DestructibleUnsafe::destroy(__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..b113919eb2 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.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, MoveAssignUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct NoCopy { pub v: i32, @@ -18,18 +16,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)] pub struct PrivateCopy { pub v: i32, } @@ -37,11 +39,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)); @@ -80,39 +86,43 @@ impl Default for Immovable { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, 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, 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 +149,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 +165,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,14 +190,14 @@ 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))); diff --git a/tests/unit/out/unsafe/default.rs b/tests/unit/out/unsafe/default.rs index 05fd21467a..ad506ea844 100644 --- a/tests/unit/out/unsafe/default.rs +++ b/tests/unit/out/unsafe/default.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 Pointers { pub x1: *mut i32, pub x2: *const i32, @@ -16,7 +16,7 @@ pub struct Pointers { pub x5: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct SmallArrays { pub a: [i32; 32], pub f: Option i32>, @@ -24,7 +24,7 @@ pub struct SmallArrays { pub p: [Pointers; 2], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..3eb7e63b4d 100644 --- a/tests/unit/out/unsafe/default_function_arguments.rs +++ b/tests/unit/out/unsafe/default_function_arguments.rs @@ -13,7 +13,7 @@ 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, CopyableUnsafe)] #[cpp_from(i32, construct, value)] pub struct Bar { pub v: i32, @@ -61,7 +61,7 @@ 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, 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..43f63ebb35 100644 --- a/tests/unit/out/unsafe/default_in_statics.rs +++ b/tests/unit/out/unsafe/default_in_statics.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct Outer { pub p1: *mut i32, pub p2: *const i32, @@ -25,7 +25,7 @@ pub struct Outer { pub fn_: Option i32>, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..b0a32d21ed 100644 --- a/tests/unit/out/unsafe/delete_array_order.rs +++ b/tests/unit/out/unsafe/delete_array_order.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(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Element { pub id: i64, pub value: i64, diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index 9d957882a6..058b1ada33 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -8,7 +8,9 @@ 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, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct S {} impl S { pub unsafe fn destructor(&mut self) { @@ -16,7 +18,9 @@ impl S { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Defaulted { pub s: S, } @@ -26,7 +30,9 @@ impl Defaulted { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Middle { pub s: S, } @@ -36,7 +42,9 @@ impl Middle { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Outer { pub m: Middle, } @@ -46,7 +54,9 @@ impl Outer { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct ArrayMember { pub items: [S; 3], } @@ -56,7 +66,9 @@ impl ArrayMember { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct EmptyBody { pub s: S, } @@ -66,7 +78,9 @@ impl EmptyBody { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Templated_char_ { pub v: libc::c_char, } @@ -78,7 +92,9 @@ impl Templated_char_ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Templated_int_ { pub v: i32, } @@ -90,7 +106,9 @@ impl Templated_int_ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Copied { pub v: i32, } @@ -103,7 +121,9 @@ 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, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Tagged { pub tag: i32, } @@ -115,7 +135,9 @@ impl Tagged { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Ordered { pub first: Tagged, pub dummy1: i32, diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index 6dc8046c61..f6d5e8ee8f 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -9,7 +9,9 @@ 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, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct S { pub v: i32, } @@ -27,7 +29,7 @@ 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, CopyableUnsafe, Default)] pub struct Holder { pub v: i32, } diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index fa79b0547c..f92b55aabd 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -9,7 +9,9 @@ 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, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct S { pub v: i32, } @@ -23,7 +25,9 @@ impl S { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Outer { pub inner: S, pub w: i32, diff --git a/tests/unit/out/unsafe/doubly_linked_list.rs b/tests/unit/out/unsafe/doubly_linked_list.rs index 912cdbf0ca..5280f20795 100644 --- a/tests/unit/out/unsafe/doubly_linked_list.rs +++ b/tests/unit/out/unsafe/doubly_linked_list.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 Node { pub val: i32, pub next: *mut Node, diff --git a/tests/unit/out/unsafe/enum_default_in_static.rs b/tests/unit/out/unsafe/enum_default_in_static.rs index 472094aeb9..2940999348 100644 --- a/tests/unit/out/unsafe/enum_default_in_static.rs +++ b/tests/unit/out/unsafe/enum_default_in_static.rs @@ -11,7 +11,7 @@ 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, 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..fb5cc1e834 100644 --- a/tests/unit/out/unsafe/enum_int_interop.rs +++ b/tests/unit/out/unsafe/enum_int_interop.rs @@ -20,7 +20,7 @@ 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, 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..a14c64b644 100644 --- a/tests/unit/out/unsafe/enum_int_interop_c.rs +++ b/tests/unit/out/unsafe/enum_int_interop_c.rs @@ -20,7 +20,7 @@ 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, 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..596209959f 100644 --- a/tests/unit/out/unsafe/enum_underlying_type.rs +++ b/tests/unit/out/unsafe/enum_underlying_type.rs @@ -26,7 +26,7 @@ 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, 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..d0790bd8e8 100644 --- a/tests/unit/out/unsafe/exprs.rs +++ b/tests/unit/out/unsafe/exprs.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct X { pub x: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..5274c507c8 100644 --- a/tests/unit/out/unsafe/fft.rs +++ b/tests/unit/out/unsafe/fft.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 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..fa7e7ba4b8 100644 --- a/tests/unit/out/unsafe/field_aliasing.rs +++ b/tests/unit/out/unsafe/field_aliasing.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct S { pub in_: In, pub total: i32, @@ -21,7 +21,7 @@ pub struct S { pub arr: [i32; 4], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..70b02a0bcf 100644 --- a/tests/unit/out/unsafe/field_array_elem_ptr.rs +++ b/tests/unit/out/unsafe/field_array_elem_ptr.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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..c47aac6d61 100644 --- a/tests/unit/out/unsafe/field_method_receiver.rs +++ b/tests/unit/out/unsafe/field_method_receiver.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 Counter { pub n: i32, } @@ -28,7 +28,13 @@ impl Counter { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + Default, )] pub struct S { pub tag: i32, @@ -43,7 +49,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 +59,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..c8de3a976e 100644 --- a/tests/unit/out/unsafe/field_pointers.rs +++ b/tests/unit/out/unsafe/field_pointers.rs @@ -7,20 +7,26 @@ 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 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, 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + Default, )] pub struct Outer { pub x: i32, @@ -43,7 +49,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 +63,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..58aed9d303 100644 --- a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs +++ b/tests/unit/out/unsafe/field_pointers_malloced_struct.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 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..eea33efa9d 100644 --- a/tests/unit/out/unsafe/field_reinterpret_write_through.rs +++ b/tests/unit/out/unsafe/field_reinterpret_write_through.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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..a4a9d612c7 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.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 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..3d6f3035b6 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,13 @@ 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 In { pub a: i16, pub b: i16, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..146a537085 100644 --- a/tests/unit/out/unsafe/first_member_downcast.rs +++ b/tests/unit/out/unsafe/first_member_downcast.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct base { pub kind: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..de36f3fd61 100644 --- a/tests/unit/out/unsafe/flex_array_member_incomplete.rs +++ b/tests/unit/out/unsafe/flex_array_member_incomplete.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)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..f4555e0a20 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,19 @@ 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 n: i32, pub name: [libc::c_char; 1], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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..f087600d19 100644 --- a/tests/unit/out/unsafe/fn_ptr.rs +++ b/tests/unit/out/unsafe/fn_ptr.rs @@ -32,7 +32,9 @@ 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, 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..e8e701d467 100644 --- a/tests/unit/out/unsafe/fn_ptr_cast.rs +++ b/tests/unit/out/unsafe/fn_ptr_cast.rs @@ -30,7 +30,7 @@ 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, 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..f5c540051e 100644 --- a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs +++ b/tests/unit/out/unsafe/fn_ptr_stable_sort.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 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..bbb90e045f 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.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 Handler { pub tag: i32, pub cb: Option i32>, @@ -19,7 +19,7 @@ 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, CopyableUnsafe, Default)] pub struct S {} impl S { pub unsafe fn pick_1(mut x: i32) -> i32 { @@ -33,7 +33,7 @@ impl S { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct MoveOnly { pub data_: i32, @@ -42,14 +42,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 +104,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..5107f3d8d2 100644 --- a/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs +++ b/tests/unit/out/unsafe/fn_ptr_typedef_cast.rs @@ -19,7 +19,7 @@ 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, 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..c7726a2ee2 100644 --- a/tests/unit/out/unsafe/fn_ptr_vtable.rs +++ b/tests/unit/out/unsafe/fn_ptr_vtable.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 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..dec5e0e1a9 100644 --- a/tests/unit/out/unsafe/fn_ref.rs +++ b/tests/unit/out/unsafe/fn_ref.rs @@ -22,7 +22,7 @@ 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, 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..f87d25e391 100644 --- a/tests/unit/out/unsafe/for_body_destructor.rs +++ b/tests/unit/out/unsafe/for_body_destructor.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(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, Default)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Guard { pub digit: i32, } diff --git a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs index f7ca6d019e..24771dd454 100644 --- a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs @@ -8,18 +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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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..a13777820c 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -10,7 +10,15 @@ 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, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Tracked { pub v: i32, @@ -23,12 +31,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 +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 } } @@ -54,7 +66,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 +75,33 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + 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..b9dd263cfb 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -10,7 +10,15 @@ 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, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Tracked { pub v: i32, @@ -23,12 +31,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 +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 } } diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index 561432313b..8f32ba673b 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -12,7 +12,15 @@ 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, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Tracked { pub v: i32, @@ -25,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))); @@ -41,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 } } @@ -61,7 +73,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 +103,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 +119,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..8dd3c3084a 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -12,7 +12,15 @@ 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, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Tracked { pub v: i32, @@ -25,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))); @@ -41,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 } } @@ -96,32 +108,41 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + 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..029ebec7a3 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -19,7 +19,7 @@ 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, CopyableUnsafe, Default)] pub struct V { pub x: i32, } @@ -33,7 +33,7 @@ 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, CopyableUnsafe, Default)] pub struct W_int_ { pub x: i32, } @@ -41,12 +41,12 @@ 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, CopyableUnsafe, Default)] pub struct W_long_ { pub x: i64, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..ec290da254 100644 --- a/tests/unit/out/unsafe/function_overloading.rs +++ b/tests/unit/out/unsafe/function_overloading.rs @@ -22,7 +22,7 @@ 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, 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..72a57be569 100644 --- a/tests/unit/out/unsafe/global_call_temporaries.rs +++ b/tests/unit/out/unsafe/global_call_temporaries.rs @@ -77,7 +77,7 @@ 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, 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..9efbc0fe4c 100644 --- a/tests/unit/out/unsafe/global_init_side_effect.rs +++ b/tests/unit/out/unsafe/global_init_side_effect.rs @@ -8,7 +8,9 @@ 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, 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..876b7a78f5 100644 --- a/tests/unit/out/unsafe/global_non_const_init.rs +++ b/tests/unit/out/unsafe/global_non_const_init.rs @@ -28,7 +28,7 @@ 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, CopyableUnsafe)] pub struct Ctor { pub v: i32, } @@ -81,7 +81,7 @@ 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, CopyableUnsafe, Default)] pub struct Holder {} pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { (unsafe { next_0() }) }); @@ -99,7 +99,7 @@ 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, 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..c81efa7c72 100644 --- a/tests/unit/out/unsafe/global_pointers.rs +++ b/tests/unit/out/unsafe/global_pointers.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 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..a5382f5365 100644 --- a/tests/unit/out/unsafe/global_without_initializer.rs +++ b/tests/unit/out/unsafe/global_without_initializer.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 a: i32, } diff --git a/tests/unit/out/unsafe/goto_aggregate_default.rs b/tests/unit/out/unsafe/goto_aggregate_default.rs index f16513aa2b..49e0323437 100644 --- a/tests/unit/out/unsafe/goto_aggregate_default.rs +++ b/tests/unit/out/unsafe/goto_aggregate_default.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 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..545f2f4266 100644 --- a/tests/unit/out/unsafe/goto_cleanup.rs +++ b/tests/unit/out/unsafe/goto_cleanup.rs @@ -77,7 +77,7 @@ 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, 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..a063be99f0 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.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 MinHeapNode { pub data: libc::c_char, pub freq: i32, @@ -40,7 +40,7 @@ pub unsafe fn Swap_0(a: *mut MinHeapNode, b: *mut MinHeapNode) { }; } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, Default)] pub struct MinHeap { pub size: i32, pub capacity: i32, @@ -234,14 +234,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..b37d046705 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,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 Item { pub value: i32, } diff --git a/tests/unit/out/unsafe/implicit_autoref.rs b/tests/unit/out/unsafe/implicit_autoref.rs index 75493d1304..7ce5cc0cfb 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -8,16 +8,24 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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..34899a2f44 100644 --- a/tests/unit/out/unsafe/in_class_field_initializer.rs +++ b/tests/unit/out/unsafe/in_class_field_initializer.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)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct Inner { pub x: i32, pub y: i32, @@ -18,7 +18,7 @@ impl Default for Inner { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct S { pub a: i32, pub b: libc::c_char, @@ -38,7 +38,7 @@ impl Default for S { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..0a2e3caa48 100644 --- a/tests/unit/out/unsafe/init.rs +++ b/tests/unit/out/unsafe/init.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 X { pub x: i32, } diff --git a/tests/unit/out/unsafe/init_list.rs b/tests/unit/out/unsafe/init_list.rs index a25486b0e7..ba5f5d2858 100644 --- a/tests/unit/out/unsafe/init_list.rs +++ b/tests/unit/out/unsafe/init_list.rs @@ -8,13 +8,13 @@ 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, 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, CopyableUnsafe)] pub struct Holder { pub p: Pair, } @@ -37,7 +37,7 @@ 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, 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..46da544ecd 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -8,22 +8,30 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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 +48,9 @@ impl Elem { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyConstructibleUnsafe, CopyAssignableUnsafe, +)] pub struct State { pub count: i32, pub grid: [[i32; 3]; 2], @@ -48,8 +58,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 +68,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 +83,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 +164,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)] 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 +200,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 +284,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 +294,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 +305,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 +329,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 +339,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 +357,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..f014467304 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.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 Edge { pub u: i32, pub v: i32, @@ -164,7 +164,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, Default)] pub struct DisjointSet { pub rank: Option>, pub parent: Option>, @@ -274,12 +274,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 +295,21 @@ impl DisjointSet { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, 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..4dc83e2b13 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.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)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { pub f: FnPtr, } @@ -28,7 +28,9 @@ 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, DestructibleUnsafe, CopyableUnsafe, Default, +)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { pub f: FnPtr, } @@ -38,7 +40,7 @@ impl Guard__lambda_at_lambda_as_field_cpp_45_13__ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { pub f: FnPtr i32>, pub calls: i32, @@ -64,7 +66,7 @@ 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, 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)] #[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))); } @@ -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..c1ec2bcc50 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_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(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyAssignableUnsafe, MoveAssignableUnsafe)] pub struct Counted { pub copies: i32, pub moves: i32, @@ -17,11 +17,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 +34,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,21 +52,32 @@ 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, + DestructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, +)] 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) { (*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)).postfix_inc(); } } +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 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 +109,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 +128,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 +153,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 }); }, diff --git a/tests/unit/out/unsafe/lambda_capture_ref.rs b/tests/unit/out/unsafe/lambda_capture_ref.rs index 3d87b57384..646dda93c0 100644 --- a/tests/unit/out/unsafe/lambda_capture_ref.rs +++ b/tests/unit/out/unsafe/lambda_capture_ref.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 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..efc3851767 100644 --- a/tests/unit/out/unsafe/lambda_capture_star_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_star_this.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 n: i32, } diff --git a/tests/unit/out/unsafe/lambda_capture_this.rs b/tests/unit/out/unsafe/lambda_capture_this.rs index 324c3fdfce..74046c957e 100644 --- a/tests/unit/out/unsafe/lambda_capture_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_this.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 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..d78b853af5 100644 --- a/tests/unit/out/unsafe/lambda_capture_value.rs +++ b/tests/unit/out/unsafe/lambda_capture_value.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 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..078d4dd483 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, 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, 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..dec74038d0 100644 --- a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs +++ b/tests/unit/out/unsafe/lambda_generic_explicit_args.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 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..342add8bf7 100644 --- a/tests/unit/out/unsafe/lambda_immediate_init.rs +++ b/tests/unit/out/unsafe/lambda_immediate_init.rs @@ -10,7 +10,7 @@ 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, 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..a380ac74ac 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, DestructibleUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct Owner { pub p: *mut i32, @@ -18,10 +16,6 @@ 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; @@ -35,7 +29,9 @@ impl Owner { { 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 +41,12 @@ 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(); + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -64,7 +66,7 @@ unsafe fn main_0() -> i32 { { let h: Owner = { let mut __v: Owner = ::zero_init(); - Owner::move_from(&mut __v, { &mut o }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut o }); __v }; }, diff --git a/tests/unit/out/unsafe/lambda_nested.rs b/tests/unit/out/unsafe/lambda_nested.rs index fc5e249862..932e1103c5 100644 --- a/tests/unit/out/unsafe/lambda_nested.rs +++ b/tests/unit/out/unsafe/lambda_nested.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, } diff --git a/tests/unit/out/unsafe/lambda_static_local.rs b/tests/unit/out/unsafe/lambda_static_local.rs index 00c32d0d0d..76ed07741d 100644 --- a/tests/unit/out/unsafe/lambda_static_local.rs +++ b/tests/unit/out/unsafe/lambda_static_local.rs @@ -68,7 +68,7 @@ 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, 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..7fc9b5cb94 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -7,20 +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, MoveAssignUnsafe)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyConstructibleUnsafe, CopyAssignableUnsafe, +)] 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 +44,7 @@ impl Default for UserDefined { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..938989483e 100644 --- a/tests/unit/out/unsafe/linked_list.rs +++ b/tests/unit/out/unsafe/linked_list.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 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..2ae16f433a 100644 --- a/tests/unit/out/unsafe/local_anon_struct_collision.rs +++ b/tests/unit/out/unsafe/local_anon_struct_collision.rs @@ -13,7 +13,7 @@ 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, CopyableUnsafe, Default)] pub struct anon_1 { pub x: i32, pub y: i32, @@ -25,7 +25,7 @@ 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, 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..d8281d97a4 100644 --- a/tests/unit/out/unsafe/local_record_template.rs +++ b/tests/unit/out/unsafe/local_record_template.rs @@ -30,12 +30,12 @@ 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, CopyableUnsafe, Default)] pub struct Local_5 { pub x: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Local_7 { pub x: i64, } @@ -44,7 +44,7 @@ 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, CopyableUnsafe, Default)] pub struct Local_1 { pub x: i64, pub y: i64, @@ -65,7 +65,7 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..0830442c08 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -13,7 +13,7 @@ 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, 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..eb907962e3 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -10,7 +10,15 @@ 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, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Key { pub k: i32, @@ -19,17 +27,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 +74,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..b4c6ba0046 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -9,7 +9,7 @@ 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, CopyableUnsafe, Default)] pub struct Key { pub order: i32, pub identity: i32, @@ -45,7 +45,7 @@ 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, 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..2b4249ee8e 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -11,7 +11,14 @@ 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, + CopyAssignableUnsafe, + MoveAssignableUnsafe, +)] #[cpp_from(i32, construct_1, value)] pub struct Item { pub value: i32, @@ -24,11 +31,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 +49,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 +70,7 @@ 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, CopyableUnsafe)] pub struct RefItem { pub value: i32, } @@ -271,7 +282,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 +298,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 +315,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 +332,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 +410,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 +437,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..fbdc18a77f 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -9,7 +9,7 @@ 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, CopyableUnsafe)] pub struct Item { pub value: i32, } @@ -47,7 +47,7 @@ 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, CopyableUnsafe)] pub struct Temporary { pub n: i32, pub data: [i32; 2], @@ -71,7 +71,7 @@ impl Default for Temporary { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Nested { pub inner: Temporary, } @@ -86,7 +86,7 @@ pub unsafe fn make_nested_6() -> Nested { return ::default(); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe)] pub struct Owner { pub ptr: Option>, } @@ -104,10 +104,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(); }; @@ -136,7 +140,7 @@ impl Default for Noncopy { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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..4bc1060e1e 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, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + 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..29a4e51722 100644 --- a/tests/unit/out/unsafe/memcpy_struct_bytes.rs +++ b/tests/unit/out/unsafe/memcpy_struct_bytes.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 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..bdb981b111 100644 --- a/tests/unit/out/unsafe/memcpy_struct_layouts.rs +++ b/tests/unit/out/unsafe/memcpy_struct_layouts.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 packed { pub a: i32, pub b: libc::c_char, @@ -15,26 +15,26 @@ pub struct packed { pub d: i16, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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, 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, 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..899ce32932 100644 --- a/tests/unit/out/unsafe/memcpy_struct_struct.rs +++ b/tests/unit/out/unsafe/memcpy_struct_struct.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 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..26edaf197e 100644 --- a/tests/unit/out/unsafe/memset_struct_tail.rs +++ b/tests/unit/out/unsafe/memset_struct_tail.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 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..ad32567771 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.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, MoveAssignUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct MoveOnly { pub v: i32, @@ -18,11 +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; } - 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)); } @@ -68,7 +70,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 +96,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 +105,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 +120,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 +147,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..7001eee52d 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, Default)] #[cpp_from(i32, construct, value)] pub struct MoveOnly { pub v: i32, @@ -16,7 +16,9 @@ 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; } @@ -49,7 +51,15 @@ impl Default for ConstMove { } } #[repr(C)] -#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct ThrowingMove { pub v: i32, @@ -62,12 +72,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 +92,21 @@ 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, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct NoexceptMove { pub v: i32, @@ -97,12 +119,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 +139,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 +155,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 +173,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 +207,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 +230,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 +266,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 +280,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 +294,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..d64961f6f7 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.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, CppFromUnsafe, Default)] +#[derive( + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Chain { pub v: i32, @@ -16,13 +24,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 +35,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 +50,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 +94,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 +119,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..c5801dfb00 100644 --- a/tests/unit/out/unsafe/nested_structs.rs +++ b/tests/unit/out/unsafe/nested_structs.rs @@ -7,34 +7,34 @@ 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 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, 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, 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, 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, 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, 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..88c99c4898 100644 --- a/tests/unit/out/unsafe/new.rs +++ b/tests/unit/out/unsafe/new.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 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..dab8706519 100644 --- a/tests/unit/out/unsafe/new_bst.rs +++ b/tests/unit/out/unsafe/new_bst.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 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..e17a949aba 100644 --- a/tests/unit/out/unsafe/new_struct.rs +++ b/tests/unit/out/unsafe/new_struct.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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..f22b0557e3 100644 --- a/tests/unit/out/unsafe/nttp_distinct_specializations.rs +++ b/tests/unit/out/unsafe/nttp_distinct_specializations.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_2_ { pub v: i32, pub w: i32, @@ -18,7 +18,7 @@ impl S_2_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct S_1_ { pub v: i32, } @@ -28,7 +28,7 @@ impl S_1_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..8c90e8e5ff 100644 --- a/tests/unit/out/unsafe/offsetof.rs +++ b/tests/unit/out/unsafe/offsetof.rs @@ -7,14 +7,14 @@ 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 Layout { pub a: u8, pub b: u32, pub c: u16, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..9c96c1fa9e 100644 --- a/tests/unit/out/unsafe/opaque_forward_decl.rs +++ b/tests/unit/out/unsafe/opaque_forward_decl.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 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..f1f2d924ae 100644 --- a/tests/unit/out/unsafe/opaque_record_copy.rs +++ b/tests/unit/out/unsafe/opaque_record_copy.rs @@ -7,10 +7,10 @@ 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 Probe {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..d18e9a85b2 100644 --- a/tests/unit/out/unsafe/opaque_then_defined.rs +++ b/tests/unit/out/unsafe/opaque_then_defined.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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..a5a133ae98 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_free.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_free.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, } diff --git a/tests/unit/out/unsafe/operator_arithmetic_member.rs b/tests/unit/out/unsafe/operator_arithmetic_member.rs index 7c3c8e8486..d789a36122 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_member.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_member.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, } diff --git a/tests/unit/out/unsafe/operator_bitwise_free.rs b/tests/unit/out/unsafe/operator_bitwise_free.rs index 8594a0b335..2c6875c304 100644 --- a/tests/unit/out/unsafe/operator_bitwise_free.rs +++ b/tests/unit/out/unsafe/operator_bitwise_free.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: u32, } diff --git a/tests/unit/out/unsafe/operator_bitwise_member.rs b/tests/unit/out/unsafe/operator_bitwise_member.rs index 5659930911..3f7f52e7b2 100644 --- a/tests/unit/out/unsafe/operator_bitwise_member.rs +++ b/tests/unit/out/unsafe/operator_bitwise_member.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: u32, } diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index 90ade9a4bb..cdbc526fae 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.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 Eq { pub a: i32, pub b: i32, @@ -25,7 +25,7 @@ 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, CopyableUnsafe, Default)] pub struct Cmp { pub a: i32, pub b: i32, @@ -70,7 +70,7 @@ 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, CopyableUnsafe, Default)] pub struct Both { pub a: i32, } @@ -106,7 +106,7 @@ 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, CopyableUnsafe, Default)] pub struct OrdOnly { pub a: i32, } @@ -139,7 +139,7 @@ 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, CopyableUnsafe, Default)] pub struct Inner { pub x: i32, } @@ -175,7 +175,7 @@ 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, CopyableUnsafe, Default)] pub struct Outer { pub i: Inner, pub y: i32, @@ -224,7 +224,7 @@ 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, CopyableUnsafe, Default)] pub struct Secondary { pub a: i32, } @@ -271,7 +271,7 @@ 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, 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..4f141f8951 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.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, } @@ -60,7 +60,7 @@ 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, 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..d2f1a02589 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.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, } diff --git a/tests/unit/out/unsafe/operator_comparison_mixed.rs b/tests/unit/out/unsafe/operator_comparison_mixed.rs index f1588054e9..8b9759f676 100644 --- a/tests/unit/out/unsafe/operator_comparison_mixed.rs +++ b/tests/unit/out/unsafe/operator_comparison_mixed.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, } diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index 8be2263ce3..b62679c9ac 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.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 X { pub v: i32, } @@ -54,12 +54,12 @@ 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, CopyableUnsafe, Default)] pub struct Result { pub r: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Custom { pub v: i32, } @@ -71,7 +71,7 @@ impl Custom { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Mixed { pub v: i32, } @@ -113,7 +113,9 @@ 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, CopyableUnsafe, Default, +)] #[cpp_into(bool, to_bool)] pub struct MyBool { pub value: bool, @@ -127,7 +129,7 @@ impl MyBool { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Boolish { pub v: i32, } @@ -202,7 +204,7 @@ 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, 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..8d446736a8 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, 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..0824c9924d 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_free.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_free.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: 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..100e10f5a3 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_member.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_member.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: u32, } diff --git a/tests/unit/out/unsafe/operator_friend.rs b/tests/unit/out/unsafe/operator_friend.rs index 905d24a0b7..3ba64a4c45 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -10,7 +10,7 @@ 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, CopyableUnsafe, Default)] pub struct Defaulted { pub a: i32, pub b: i32, @@ -37,7 +37,7 @@ 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, CopyableUnsafe, Default)] pub struct DefaultedOrd { pub a: i32, } @@ -69,7 +69,7 @@ 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, CopyableUnsafe, Default)] pub struct Inline { pub a: i32, } @@ -98,7 +98,7 @@ 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, CopyableUnsafe, Default)] pub struct OutOfLine { pub a: i32, } @@ -127,7 +127,7 @@ 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, CopyableUnsafe, Default)] pub struct Tmpl_int_ { pub v: i32, } @@ -156,7 +156,7 @@ 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, CopyableUnsafe, Default)] pub struct Tmpl_long_ { pub v: i64, } @@ -167,7 +167,7 @@ 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, 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..5970de3eac 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.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 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..e816bd7626 100644 --- a/tests/unit/out/unsafe/operator_logical_free.rs +++ b/tests/unit/out/unsafe/operator_logical_free.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, } diff --git a/tests/unit/out/unsafe/operator_logical_member.rs b/tests/unit/out/unsafe/operator_logical_member.rs index e7029ceab2..41cff80dbb 100644 --- a/tests/unit/out/unsafe/operator_logical_member.rs +++ b/tests/unit/out/unsafe/operator_logical_member.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, } diff --git a/tests/unit/out/unsafe/operator_member_pointer_free.rs b/tests/unit/out/unsafe/operator_member_pointer_free.rs index ce8fa2513e..878bcffe6a 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_free.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_free.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Inner { pub x: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..1fe5fcb357 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_member.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_member.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Inner { pub x: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Table {} impl Table { pub unsafe fn operator_index(mut i: i32) -> *mut i32 { @@ -22,7 +22,7 @@ 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, 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..3954e1ceba 100644 --- a/tests/unit/out/unsafe/operator_other_free.rs +++ b/tests/unit/out/unsafe/operator_other_free.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, } diff --git a/tests/unit/out/unsafe/operator_other_member.rs b/tests/unit/out/unsafe/operator_other_member.rs index 3d412fc229..d1651da5ac 100644 --- a/tests/unit/out/unsafe/operator_other_member.rs +++ b/tests/unit/out/unsafe/operator_other_member.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 Static {} impl Static { pub unsafe fn operator_call(mut a: i32, mut b: i32) -> i32 { @@ -15,7 +15,9 @@ impl Static { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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..1d47d6c67d 100644 --- a/tests/unit/out/unsafe/operator_overloads.rs +++ b/tests/unit/out/unsafe/operator_overloads.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, } diff --git a/tests/unit/out/unsafe/operator_qualifiers.rs b/tests/unit/out/unsafe/operator_qualifiers.rs index dd0e64f6d5..d35c4227aa 100644 --- a/tests/unit/out/unsafe/operator_qualifiers.rs +++ b/tests/unit/out/unsafe/operator_qualifiers.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, } diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index 7d742a4677..73d7da6018 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.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, } diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index 6ab10c49d0..e7acf1bc3c 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.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 Lt { pub v: i32, } @@ -44,7 +44,7 @@ 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, CopyableUnsafe, Default)] pub struct Eq { pub v: i32, } @@ -60,7 +60,7 @@ 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, CopyableUnsafe, Default)] pub struct Cmp { pub v: i32, } @@ -89,7 +89,7 @@ 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, CopyableUnsafe, Default)] pub struct Free { pub v: i32, } @@ -124,7 +124,7 @@ 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, 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..8517c5b99e 100644 --- a/tests/unit/out/unsafe/overload_mangling.rs +++ b/tests/unit/out/unsafe/overload_mangling.rs @@ -16,7 +16,7 @@ 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, CopyableUnsafe, Default)] pub struct Access_S_ {} impl Access_S_ { pub unsafe fn get_1(&mut self, mut p: *mut S) -> i32 { @@ -33,7 +33,7 @@ impl Access_S_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct S { pub base: i32, } @@ -107,7 +107,7 @@ impl S { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..ec693a708e 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.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, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, +)] #[cpp_from(i32, construct, value)] pub struct Celsius { pub degrees: i32, @@ -18,7 +20,9 @@ impl Celsius { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, +)] #[cpp_into(i32, to_i32)] pub struct Meters { pub value: i32, @@ -29,7 +33,9 @@ impl Meters { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, +)] #[cpp_from(Celsius, construct, ptr)] pub struct Label { pub id: i32, @@ -40,7 +46,9 @@ impl Label { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, +)] #[cpp_from(Celsius, construct_1, ptr)] #[cpp_from_move(Celsius, construct_2, ptr)] pub struct Owner { @@ -58,7 +66,9 @@ impl Owner { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, +)] #[cpp_from(Celsius, construct, value)] pub struct Holder { pub value: i32, @@ -69,7 +79,7 @@ impl Holder { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe)] #[cpp_from(i32, construct, value)] pub struct Fallback { pub value: i32, @@ -91,12 +101,14 @@ impl Default for Fallback { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default, +)] #[cpp_from(Counter, construct, mut_ptr)] pub struct Observer { pub seen: i32, @@ -113,13 +125,17 @@ impl Tag { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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, 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..34689f2c9c 100644 --- a/tests/unit/out/unsafe/pod.rs +++ b/tests/unit/out/unsafe/pod.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 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..c88b6d8f81 100644 --- a/tests/unit/out/unsafe/pointer_array.rs +++ b/tests/unit/out/unsafe/pointer_array.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 StackArray { pub arr: [*mut i32; 3], } diff --git a/tests/unit/out/unsafe/pointers.rs b/tests/unit/out/unsafe/pointers.rs index 8112e83a98..43e868fa8a 100644 --- a/tests/unit/out/unsafe/pointers.rs +++ b/tests/unit/out/unsafe/pointers.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 Test { pub x: i32, } diff --git a/tests/unit/out/unsafe/polymorphism.rs b/tests/unit/out/unsafe/polymorphism.rs index da9d32dbe7..9ce091d5f3 100644 --- a/tests/unit/out/unsafe/polymorphism.rs +++ b/tests/unit/out/unsafe/polymorphism.rs @@ -10,10 +10,10 @@ pub unsafe trait Animal { unsafe fn bark(&self) -> bool; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Dog {} #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..2d9b922bff 100644 --- a/tests/unit/out/unsafe/ptr_cast_init.rs +++ b/tests/unit/out/unsafe/ptr_cast_init.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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..5a2ddf98f5 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -7,30 +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, CopyableUnsafe, Default)] pub struct Chunk { pub data: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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 +114,7 @@ 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, CopyableUnsafe)] #[cpp_from(i32, construct_1, value)] pub struct Pair { pub first: i32, @@ -211,18 +219,26 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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 +267,7 @@ 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, CopyableUnsafe, Default)] pub struct Plain { pub a: i32, pub b: [f64; 2], @@ -266,7 +282,7 @@ 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, 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..fc319c167a 100644 --- a/tests/unit/out/unsafe/random.rs +++ b/tests/unit/out/unsafe/random.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 Pair { pub x: i32, pub y: i32, @@ -41,7 +41,7 @@ pub unsafe fn zero_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..d57fa6cbd6 100644 --- a/tests/unit/out/unsafe/reference_wrapper.rs +++ b/tests/unit/out/unsafe/reference_wrapper.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 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..a0dee4bba9 100644 --- a/tests/unit/out/unsafe/references.rs +++ b/tests/unit/out/unsafe/references.rs @@ -7,14 +7,14 @@ 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 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, 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..d956f72b7e 100644 --- a/tests/unit/out/unsafe/refs_as_args.rs +++ b/tests/unit/out/unsafe/refs_as_args.rs @@ -18,7 +18,7 @@ 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, 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..94b2dd39a3 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_ptr_cmp.rs @@ -7,19 +7,19 @@ 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 x: i32, pub y: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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..5b4a26a03b 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_struct.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_struct.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 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..c66149ba7f 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,13 @@ 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 Point { pub x: u32, pub y: u32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..33cc38b036 100644 --- a/tests/unit/out/unsafe/reserved_keywords.rs +++ b/tests/unit/out/unsafe/reserved_keywords.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 as_: i32, pub async_: i32, @@ -49,12 +49,12 @@ pub struct S { pub vec_: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct type_ { pub v: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..108c676409 100644 --- a/tests/unit/out/unsafe/return_move.rs +++ b/tests/unit/out/unsafe/return_move.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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..e6785642ba 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, DestructibleUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct Buffer { pub data: [i32; 4], @@ -44,7 +34,9 @@ impl Buffer { pub unsafe fn destructor(&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 +51,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 +70,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 +89,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 +115,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 } } @@ -133,7 +131,7 @@ pub unsafe fn make_3(mut size: i32) -> Buffer { }); return { let mut __v: Buffer = ::zero_init(); - Buffer::move_from(&mut __v, { &mut b }); + MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut b }); __v }; } @@ -155,7 +153,7 @@ unsafe fn main_0() -> i32 { }); 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 { @@ -170,7 +168,7 @@ 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 { @@ -189,19 +187,19 @@ unsafe fn main_0() -> i32 { 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..206cabd63b 100644 --- a/tests/unit/out/unsafe/rule_of_three.rs +++ b/tests/unit/out/unsafe/rule_of_three.rs @@ -14,8 +14,9 @@ pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - CopyAssignUnsafe, DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, Default, )] #[cpp_from(i32, construct, value)] @@ -41,7 +42,9 @@ impl Buffer { pub unsafe fn destructor(&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 +59,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 +83,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 } } @@ -114,7 +119,7 @@ unsafe fn main_0() -> i32 { }); 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 { @@ -134,7 +139,7 @@ unsafe fn main_0() -> i32 { let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { DestructibleUnsafe::destroy(__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,14 +147,14 @@ 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 { @@ -160,7 +165,7 @@ unsafe fn main_0() -> i32 { && ((*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..6f148213b5 100644 --- a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs +++ b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs @@ -10,13 +10,7 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - VaArg, - FnPtrArg, - ZeroInitializationUnsafe, - MoveCtorUnsafe, - CppFromUnsafe, - CopyAssignUnsafe, - Default, + VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, MoveAssignableUnsafe, Default, )] #[cpp_from(i32, construct, value)] pub struct Elem { @@ -26,15 +20,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 +43,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 +76,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..f399667614 100644 --- a/tests/unit/out/unsafe/rvalue_struct.rs +++ b/tests/unit/out/unsafe/rvalue_struct.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 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..df7502a789 100644 --- a/tests/unit/out/unsafe/scalar_builtin_construct_destruct.rs +++ b/tests/unit/out/unsafe/scalar_builtin_construct_destruct.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 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..18e3907031 100644 --- a/tests/unit/out/unsafe/self_referencing_initializer.rs +++ b/tests/unit/out/unsafe/self_referencing_initializer.rs @@ -7,18 +7,18 @@ 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 list_head { pub next: *mut list_head, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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..f14939a058 100644 --- a/tests/unit/out/unsafe/size_t_static_member.rs +++ b/tests/unit/out/unsafe/size_t_static_member.rs @@ -8,12 +8,12 @@ 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, 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, 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..603d6c8597 100644 --- a/tests/unit/out/unsafe/size_t_template_param.rs +++ b/tests/unit/out/unsafe/size_t_template_param.rs @@ -11,7 +11,9 @@ 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, CopyableUnsafe, Default, +)] #[cpp_from(*const u64 , construct, value)] pub struct PtrCtor_unsigned_long_ { pub v: u64, @@ -22,7 +24,9 @@ impl PtrCtor_unsigned_long_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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..2cf3500828 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -8,15 +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, - MoveCtorUnsafe, - CppFromUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, -)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe)] #[cpp_from(i32, construct_1, value)] pub struct Tracked { pub v: i32, @@ -28,19 +20,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 +76,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 } } @@ -99,9 +99,7 @@ pub unsafe fn greater_2(a: *const Tracked, b: *const Tracked) -> bool { return (((*a).v) > ((*b).v)); } #[repr(C)] -#[derive( - FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, CppFromUnsafe, MoveAssignUnsafe, Default, -)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct MoveOnly { pub v: i32, @@ -110,10 +108,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 +152,24 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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..cc490e3768 100644 --- a/tests/unit/out/unsafe/static_local.rs +++ b/tests/unit/out/unsafe/static_local.rs @@ -22,7 +22,7 @@ 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, 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..7f5023a8ea 100644 --- a/tests/unit/out/unsafe/static_var_in_class.rs +++ b/tests/unit/out/unsafe/static_var_in_class.rs @@ -8,7 +8,7 @@ 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, CopyableUnsafe, Default)] pub struct C {} impl C { pub unsafe fn get(&mut self) -> i32 { @@ -19,7 +19,7 @@ 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, 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..8cef708dc0 100644 --- a/tests/unit/out/unsafe/stdcopy.rs +++ b/tests/unit/out/unsafe/stdcopy.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, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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..0d10b728da 100644 --- a/tests/unit/out/unsafe/strdup.rs +++ b/tests/unit/out/unsafe/strdup.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 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..3288ac7036 100644 --- a/tests/unit/out/unsafe/string_literal_ptr_init.rs +++ b/tests/unit/out/unsafe/string_literal_ptr_init.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 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..0c76c958c8 100644 --- a/tests/unit/out/unsafe/string_substr.rs +++ b/tests/unit/out/unsafe/string_substr.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 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..f27e9b7151 100644 --- a/tests/unit/out/unsafe/struct_2d_array_field.rs +++ b/tests/unit/out/unsafe/struct_2d_array_field.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 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..48b6b0eed0 100644 --- a/tests/unit/out/unsafe/struct_ctor.rs +++ b/tests/unit/out/unsafe/struct_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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct StructWithCtor { x1_: i32, x2_: i32, @@ -30,7 +30,9 @@ 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, CopyableUnsafe, Default, +)] #[cpp_from(i32, construct, value)] pub struct Value_ { pub v: i32, @@ -41,7 +43,7 @@ impl Value_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..c3e8fddcac 100644 --- a/tests/unit/out/unsafe/struct_default_ctor.rs +++ b/tests/unit/out/unsafe/struct_default_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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct S { pub a: i32, pub b: bool, @@ -30,19 +30,19 @@ impl Default for S { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, 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, 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..277b27a2d3 100644 --- a/tests/unit/out/unsafe/struct_member_array_adjacency.rs +++ b/tests/unit/out/unsafe/struct_member_array_adjacency.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 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..fc1c71b81a 100644 --- a/tests/unit/out/unsafe/struct_ptr.rs +++ b/tests/unit/out/unsafe/struct_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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..daf0cc190b 100644 --- a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs @@ -8,7 +8,14 @@ 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, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + Default, +)] pub struct Counted { pub x: i32, pub y: i32, @@ -18,12 +25,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 +44,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 +70,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..f2925d8dd8 100644 --- a/tests/unit/out/unsafe/structured_binding_element_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_element_ctor.rs @@ -9,7 +9,15 @@ 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, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + Default, +)] #[cpp_from(i32, construct, value)] pub struct Elem { pub v: i32, @@ -18,11 +26,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 +44,36 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + MoveAssignableUnsafe, + 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 +125,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..24ebdad87d 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -9,7 +9,9 @@ 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, CopyAssignableUnsafe, MoveAssignableUnsafe, Default, +)] pub struct Movable { pub x: i32, pub y: i32, @@ -19,12 +21,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 +42,20 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + Default, )] pub struct Holder { pub xs: Vec, @@ -56,11 +68,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 +100,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..ae669cc725 100644 --- a/tests/unit/out/unsafe/structured_binding_range_for.rs +++ b/tests/unit/out/unsafe/structured_binding_range_for.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 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..44c820232f 100644 --- a/tests/unit/out/unsafe/structured_binding_ref.rs +++ b/tests/unit/out/unsafe/structured_binding_ref.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 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..c095ef628e 100644 --- a/tests/unit/out/unsafe/structured_binding_trivial.rs +++ b/tests/unit/out/unsafe/structured_binding_trivial.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 Pair { pub first: i32, pub second: i32, diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index f824eb7c11..81f972290b 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -8,15 +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, - MoveCtorUnsafe, - CppFromUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, -)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe)] #[cpp_from(i32, construct_1, value)] pub struct Tracked { pub v: i32, @@ -28,19 +20,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 +49,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 } } @@ -66,92 +66,80 @@ impl Default for Tracked { } } #[repr(C)] -#[derive( - Clone, - VaArg, - FnPtrArg, - ZeroInitializationUnsafe, - MoveCtorUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, - Default, -)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyConstructibleUnsafe, 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)); } } #[repr(C)] -#[derive( - Clone, - VaArg, - FnPtrArg, - ZeroInitializationUnsafe, - MoveCtorUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, - Default, -)] +#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyConstructibleUnsafe, 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 +151,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 +159,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 +180,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(); @@ -209,8 +199,9 @@ pub static mut copy_only_dtors_2: std::cell::LazyCell = FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, - CopyAssignUnsafe, DestructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, Default, )] #[cpp_from(i32, construct, value)] @@ -221,14 +212,18 @@ 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) { - (&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) { (*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 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(); + } +} +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,28 +233,36 @@ 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, + DestructibleUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + 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)); } @@ -274,17 +277,7 @@ pub static mut moves_3: std::cell::LazyCell = std::cell::LazyCell::new(|| u pub static mut move_assigns_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moved_dtors_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive( - VaArg, - FnPtrArg, - ZeroInitializationUnsafe, - MoveCtorUnsafe, - CppFromUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, - DestructibleUnsafe, - Default, -)] +#[derive(VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, construct, value)] pub struct Moved { pub v: i32, @@ -293,35 +286,43 @@ 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) { + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)).prefix_inc(); + } +} +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) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)).prefix_inc(); - } } 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,48 +333,50 @@ impl Clone for Moved { VaArg, FnPtrArg, ZeroInitializationUnsafe, - MoveCtorUnsafe, - CopyAssignUnsafe, - MoveAssignUnsafe, DestructibleUnsafe, + CopyConstructibleUnsafe, 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)); } @@ -398,15 +401,17 @@ pub unsafe fn swapped_once_6() -> bool { return ok; } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, 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(); }; @@ -440,7 +445,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 +456,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,7 +468,7 @@ 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, ) @@ -634,7 +639,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 +654,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), diff --git a/tests/unit/out/unsafe/tag_vs_identifier_collision.rs b/tests/unit/out/unsafe/tag_vs_identifier_collision.rs index f42c07b866..891720e11b 100644 --- a/tests/unit/out/unsafe/tag_vs_identifier_collision.rs +++ b/tests/unit/out/unsafe/tag_vs_identifier_collision.rs @@ -11,19 +11,19 @@ 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, 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, 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, CopyableUnsafe)] pub union point { pub whole: i32, pub half: i16, @@ -34,7 +34,7 @@ impl Default for point { } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union slot_union { pub i: i32, pub u: u32, @@ -48,17 +48,17 @@ 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, CopyableUnsafe, Default)] pub struct Inner { pub tag_field: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Outer { pub field: Inner, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..45e17aaae5 100644 --- a/tests/unit/out/unsafe/template_default_arg.rs +++ b/tests/unit/out/unsafe/template_default_arg.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, CppFromUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe)] #[cpp_from(i32, construct_1, value)] pub struct A { pub v: i32, @@ -32,7 +32,7 @@ impl Default for A { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub struct B { pub v: i32, } @@ -53,7 +53,9 @@ impl Default for B { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, +)] #[cpp_from(i32, construct, value)] pub struct NoDefault { pub v: i32, @@ -76,7 +78,9 @@ 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, 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..0db609551f 100644 --- a/tests/unit/out/unsafe/template_static_member.rs +++ b/tests/unit/out/unsafe/template_static_member.rs @@ -8,27 +8,27 @@ 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, 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, 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, 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, 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, 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..3caba06085 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -8,16 +8,24 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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 +34,40 @@ impl Inner { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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..0e0f710774 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -8,16 +8,24 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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 +38,9 @@ pub unsafe fn make_0() -> Outer { }; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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..67cee7bea9 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -8,16 +8,24 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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 +34,36 @@ impl Inner { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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..19b8a849a4 100644 --- a/tests/unit/out/unsafe/this.rs +++ b/tests/unit/out/unsafe/this.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, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, +)] #[cpp_from(i32, construct_1, value)] pub struct S { pub a_: i32, @@ -101,7 +103,9 @@ 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, 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..b37a5be404 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -7,23 +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, 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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..15783857d2 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,7 @@ 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, 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..6e43286da6 100644 --- a/tests/unit/out/unsafe/unboxed_locals.rs +++ b/tests/unit/out/unsafe/unboxed_locals.rs @@ -13,7 +13,7 @@ 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, CopyableUnsafe, Default)] pub struct Pair { pub first: i32, pub second: i32, @@ -51,7 +51,7 @@ 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, 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..a075e8bc84 100644 --- a/tests/unit/out/unsafe/unboxed_records.rs +++ b/tests/unit/out/unsafe/unboxed_records.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct Cookie { pub x: i32, pub data: *mut i32, @@ -22,7 +22,7 @@ pub struct Cookie { pub arr: [i32; 4], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..e528547503 100644 --- a/tests/unit/out/unsafe/union_addrof_external.rs +++ b/tests/unit/out/unsafe/union_addrof_external.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 record { pub code: u16, pub lo: u16, @@ -15,7 +15,7 @@ pub struct record { pub pad: [libc::c_char; 8], } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union anon_0 { pub h: record, pub raw_: [libc::c_char; 128], @@ -26,7 +26,7 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..bad81ff98b 100644 --- a/tests/unit/out/unsafe/union_basic.rs +++ b/tests/unit/out/unsafe/union_basic.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, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union basic { pub i: i32, pub f: f32, @@ -18,7 +18,7 @@ impl Default for basic { } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union empty { __empty: u8, } @@ -28,7 +28,7 @@ impl Default for empty { } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union underscores { pub __: i32, pub ___: f64, @@ -91,7 +91,7 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, 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..66cb544d2b 100644 --- a/tests/unit/out/unsafe/union_cross_arm_cast.rs +++ b/tests/unit/out/unsafe/union_cross_arm_cast.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct shape_b { pub code: u16, pub lo: u16, @@ -22,7 +22,7 @@ pub struct shape_b { pub tail: u32, } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union anon_0 { pub a: shape_a, pub b: shape_b, @@ -34,7 +34,7 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..9ccd73525a 100644 --- a/tests/unit/out/unsafe/union_field_alignment.rs +++ b/tests/unit/out/unsafe/union_field_alignment.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, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union anon_0 { pub bytes: [u8; 1], pub aligner: *mut ::libc::c_void, @@ -18,7 +18,7 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..cfd32ac686 100644 --- a/tests/unit/out/unsafe/union_flex_array_member.rs +++ b/tests/unit/out/unsafe/union_flex_array_member.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, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union anon_0 { pub bytes: [u8; 1], pub aligner: *mut ::libc::c_void, @@ -18,7 +18,7 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..f1159bfaec 100644 --- a/tests/unit/out/unsafe/union_memset_memcpy.rs +++ b/tests/unit/out/unsafe/union_memset_memcpy.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe, Default)] pub struct shape_b { pub code: u16, pub lo: u16, @@ -21,7 +21,7 @@ pub struct shape_b { pub fill: [libc::c_char; 8], } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union anon_0 { pub a: shape_a, pub b: shape_b, @@ -33,7 +33,7 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..c4ed21041c 100644 --- a/tests/unit/out/unsafe/union_nested.rs +++ b/tests/unit/out/unsafe/union_nested.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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, CopyableUnsafe)] pub union anon_0 { pub h: record, pub raw_: [libc::c_char; 128], @@ -24,12 +24,12 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct inner { pub view: anon_0, } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union anon_1 { pub h: record, pub nested: inner, @@ -40,7 +40,7 @@ impl Default for anon_1 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..5077027082 100644 --- a/tests/unit/out/unsafe/union_pointer_pun_address.rs +++ b/tests/unit/out/unsafe/union_pointer_pun_address.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct node_a { pub n: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct node_b { pub data: *mut ::libc::c_void, pub next: *mut node_b, @@ -32,7 +32,7 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, 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..9d90cadf05 100644 --- a/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs +++ b/tests/unit/out/unsafe/union_pointer_pun_writethrough.rs @@ -21,7 +21,7 @@ unsafe fn main_0() -> i32 { return 0; } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, 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..06895c1dbb 100644 --- a/tests/unit/out/unsafe/union_struct_dual_use.rs +++ b/tests/unit/out/unsafe/union_struct_dual_use.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 Inner { pub a: i32, pub b: i32, @@ -16,7 +16,7 @@ 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, CopyableUnsafe)] pub union anon_1 { pub inner: Inner, pub raw_: [libc::c_char; 16], @@ -27,7 +27,7 @@ impl Default for anon_1 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..6bdb7e38e4 100644 --- a/tests/unit/out/unsafe/union_tagged_many_arms.rs +++ b/tests/unit/out/unsafe/union_tagged_many_arms.rs @@ -13,7 +13,7 @@ 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, CopyableUnsafe)] pub union anon_0 { pub text: *const libc::c_char, pub handle: *mut ::libc::c_void, @@ -27,7 +27,7 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..0b26fca50a 100644 --- a/tests/unit/out/unsafe/union_tagged_simple.rs +++ b/tests/unit/out/unsafe/union_tagged_simple.rs @@ -10,7 +10,7 @@ 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, CopyableUnsafe)] pub union anon_0 { pub obj: *mut ::libc::c_void, pub code: i32, @@ -21,7 +21,7 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..604c7bf25d 100644 --- a/tests/unit/out/unsafe/union_tagged_struct_arms.rs +++ b/tests/unit/out/unsafe/union_tagged_struct_arms.rs @@ -11,14 +11,14 @@ 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, 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, CopyableUnsafe, Default)] pub struct anon_2 { pub lo: i32, pub hi: i32, @@ -26,7 +26,7 @@ pub struct anon_2 { pub step: u8, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct anon_3 { pub lo: i64, pub hi: i64, @@ -35,7 +35,7 @@ pub struct anon_3 { pub width: i32, } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, CopyableUnsafe)] pub union anon_0 { pub list: anon_1, pub letters: anon_2, @@ -47,7 +47,7 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..0f1ec7bf1a 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,7 @@ 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, CopyableUnsafe)] pub union anon_0 { pub text: *const libc::c_char, pub handle: *mut ::libc::c_void, @@ -24,7 +24,7 @@ impl Default for anon_0 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..d0b8fca75e 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, 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,7 @@ impl SafePointer { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..53e417efaa 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, 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..a6da20a903 100644 --- a/tests/unit/out/unsafe/unique_ptr_field_reset.rs +++ b/tests/unit/out/unsafe/unique_ptr_field_reset.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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] pub struct Data { pub v: i32, } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, Default)] pub struct Holder { pub data: Option>, pub n: i32, @@ -28,11 +28,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..9a60f9563d 100644 --- a/tests/unit/out/unsafe/unique_ptr_nested.rs +++ b/tests/unit/out/unsafe/unique_ptr_nested.rs @@ -7,21 +7,23 @@ 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 Inner { pub x: i32, pub y: i32, } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, 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..89f55ddbe5 100644 --- a/tests/unit/out/unsafe/unique_ptr_struct.rs +++ b/tests/unit/out/unsafe/unique_ptr_struct.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 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..a576ddf435 100644 --- a/tests/unit/out/unsafe/va_arg_mixed_types.rs +++ b/tests/unit/out/unsafe/va_arg_mixed_types.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 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..a7acfb87fd 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,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 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..3b03e14b09 100644 --- a/tests/unit/out/unsafe/va_arg_struct_ctx.rs +++ b/tests/unit/out/unsafe/va_arg_struct_ctx.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 context { pub verbose: i32, pub last_error: i32, @@ -24,7 +24,7 @@ pub unsafe fn set_error_0( } } #[repr(C)] -#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe)] +#[derive(Copy, Clone, FnPtrArg, VaArg, ZeroInitializationUnsafe, 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..9244c8aecb 100644 --- a/tests/unit/out/unsafe/va_arg_void_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_void_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(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..8121920242 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -31,7 +31,14 @@ 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, + DestructibleUnsafe, + CopyableUnsafe, + Default, )] #[cpp_from(*const VaArg , construct, mut_ptr)] pub struct Guard_1 { @@ -66,7 +73,7 @@ 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, 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..f168f2ec0e 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -7,25 +7,33 @@ 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 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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..babc06d04c 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_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, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, +)] #[cpp_from(i32, construct, value)] pub struct Degrees { pub value: i32, @@ -18,7 +20,9 @@ impl Degrees { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, Default)] +#[derive( + Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, 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..cea364392f 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.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 Point { pub x: i32, pub y: i32, @@ -19,18 +19,26 @@ impl Point { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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..8b9361a9c1 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.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 TestAllocator_int_ {} impl TestAllocator_int_ { pub unsafe fn allocate(&mut self, mut n: usize) -> *mut i32 { @@ -27,7 +27,7 @@ impl TestAllocator_int_ { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, Default)] +#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, 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..b86a24832a 100644 --- a/tests/unit/out/unsafe/void_cast.rs +++ b/tests/unit/out/unsafe/void_cast.rs @@ -9,16 +9,24 @@ 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, + CopyConstructibleUnsafe, + CopyAssignableUnsafe, + 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 +42,22 @@ 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, CopyableUnsafe, Default)] pub struct Holder { pub field: i32, } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, 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(); };