diff --git a/CMakeLists.txt b/CMakeLists.txt index bebc404d8e..e799f20dcb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,8 @@ find_program(RUFF NAMES ruff) file(GLOB_RECURSE ALL_CXX_SOURCES cpp2rust/*.cpp cpp2rust/*.h rules/*.cpp rules/*.c rules/*.h tests/*.cpp tests/*.c) +file(GLOB_RECURSE RULE_RUST_SOURCES rules/*/*.rs) + set(PYTHON_SOURCES ${PROJECT_SOURCE_DIR}/tests/lit/lit/formats/Cpp2RustTest.py) # `clippy --fix` downgrades -Dwarnings errors back to warnings, and manifest @@ -109,6 +111,7 @@ set(CLIPPY_ENV CARGO_BUILD_WARNINGS=deny) add_custom_target("format" COMMAND ${CLANG_FORMAT} -i ${ALL_CXX_SOURCES} COMMAND cargo +${RUST_STABLE_VERSION} fmt --manifest-path ${PROJECT_SOURCE_DIR}/rules/Cargo.toml + COMMAND rustfmt +${RUST_STABLE_VERSION} --edition 2024 ${RULE_RUST_SOURCES} COMMAND cargo +${RUST_NIGHTLY_VERSION} fmt --manifest-path ${PROJECT_SOURCE_DIR}/rule-preprocessor/Cargo.toml COMMAND cargo +${RUST_STABLE_VERSION} fmt --manifest-path ${PROJECT_SOURCE_DIR}/libcc2rs/Cargo.toml COMMAND cargo +${RUST_STABLE_VERSION} fmt --manifest-path ${PROJECT_SOURCE_DIR}/libcc2rs-macros/Cargo.toml diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index eae697d31c..fa688b9c02 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -128,7 +129,8 @@ void Converter::EmitUndefinedRecordTraits(Model model, std::string &out) { out += std::format( "impl {} for {} {{ {} {{ unreachable!(\"{}::{} is never defined\") " "}} }}\n", - spelling.name, record, spelling.signature, record, trait->method); + spelling.constructor ? spelling.constructor : spelling.name, record, + spelling.signature, record, trait->method); } } } @@ -177,10 +179,13 @@ void Converter::EmitGlobalInits(Model model, std::string &out) { void Converter::EmitOpaqueRecords(Model model, std::string &out) { record_decls_.ForEachUndefined([&](const std::string &name) { if (model == Model::kRefCount) { - out += "#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)]"; + out += "#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg, " + "ZeroInitialization, Destructible, Conversions)]"; out += "#[byte_size(1)]"; } else { - out += "#[derive(Clone, Copy, Default, VaArg, FnPtrArg)]"; + out += "#[derive(Clone, Copy, Default, VaArg, FnPtrArg, " + "ZeroInitializationUnsafe, DestructibleUnsafe, " + "ConversionsUnsafe)]"; } out += "pub struct "; out += name; @@ -468,7 +473,8 @@ Converter::ConvertFunctionPointerType(const clang::FunctionProtoType *proto) { result += ','; } for (auto p_ty : proto->param_types()) { - result += ToString(GetPassedParamType(ctx_, p_ty)); + result += + UsesReturnSlot(p_ty) ? GetParameterObjectType(p_ty) : ToString(p_ty); result += ','; } if (proto->isVariadic()) { @@ -755,6 +761,10 @@ bool Converter::ConvertVarDeclSkipInit(clang::VarDecl *decl) { StrCat(keyword::kMut); } StrCat(name, token::kColon); + if (clang::isa(decl) && UsesReturnSlot(decl->getType())) { + StrCat(GetParameterObjectType(decl->getType())); + return true; + } { PushLazyType lazy(*this, IsGlobalVar(decl) && LazyStaticInit()); Convert(qual_type); @@ -1131,7 +1141,7 @@ void Converter::EmitRustStructOrUnion(clang::RecordDecl *decl) { } EmitDerives(decl); if (auto *cxx = clang::dyn_cast(decl)) { - EmitConversionAttrs(cxx); + EmitConversionsAttrs(cxx); } EmitByteSizeAttr(decl); @@ -1187,6 +1197,9 @@ void Converter::AddAssignmentTraits(const clang::CXXRecordDecl *decl) { record_name, GetReferenceMarker(trait == &kMoveAssignable), arg)); arg = GetReturnSlotArg(GetPlacementReceiver("__o")); + if (UsesReturnSlot(param_type)) { + arg = std::format("{}::bind({})", GetParameterObjectMarker(), arg); + } } StrCat(std::format("{}::{}({}, {});", GetUFCSName(method), GetMethodName(method), spelling.receiver, arg), @@ -1200,20 +1213,22 @@ Converter::GetAssignmentTraitSignature(const RecordTrait &trait) const { trait.method, GetCopyOrMoveSourceType(trait)); } -std::string Converter::GetCopyOrMoveSourceType(const RecordTrait &trait) const { +std::string Converter::GetCopyOrMoveSourceType(const RecordTrait &trait, + std::string_view self) const { if (&trait == &kMoveConstructible || &trait == &kMoveAssignable) { - return std::format("{}", GetReferenceMarker(true)); + return std::format("{}<{}>", GetReferenceMarker(true), self); } - return std::format("{}>", GetReferenceMarker(false)); + return std::format("{}>", GetReferenceMarker(false), self); } void Converter::ConvertTemplateInstantiatedCtors(clang::CXXRecordDecl *decl) { for (auto c : GetTemplateInstantiatedCtors(decl)) { - if (!decl_ids_.contains(GetID(c))) { - StrCat(keyword::kImpl, GetRecordName(decl)); - PushBrace brace(*this); - VisitCXXMethodDecl(c); + if (decl_ids_.contains(GetID(c))) { + continue; } + StrCat(keyword::kImpl, GetRecordName(decl)); + PushBrace brace(*this); + VisitCXXMethodDecl(c); } } @@ -1232,7 +1247,7 @@ void Converter::ConvertCopyOrMoveTraitImpls( const clang::CXXRecordDecl *decl, bool (*predicate)(clang::CXXMethodDecl *)) { ForEachMethod(decl, [&](clang::CXXMethodDecl *method) { - if (predicate(method) && GetRecordTrait(method) && + if (predicate(method) && GetMethodTrait(method) && !IsDerivedCopyOrMove(method)) { VisitCXXMethodDecl(method); } @@ -1313,47 +1328,6 @@ void Converter::EmitDerives(const clang::RecordDecl *decl) { } } -void Converter::EmitConversionAttrs(clang::CXXRecordDecl *decl) { - std::unordered_set from_types; - ForEachConvertingConstructor(decl, [&](clang::CXXConstructorDecl *ctor) { - auto *param = ctor->getParamDecl(0); - auto type = param->getType(); - if (ctx_.hasSameUnqualifiedType(type.getNonReferenceType(), - ctx_.getCanonicalTagType(decl)) && - RecordImplementsClone(decl)) { - return; - } - auto source = - GetUnboxedTypeAsString(type.getNonReferenceType().getUnqualifiedType()); - bool is_move = type->isRValueReferenceType(); - if (!from_types.insert(source + (is_move ? "&&" : "")).second) { - return; - } - const char *kind = - !type->isReferenceType() ? "value" - : is_move || type.getNonReferenceType().isConstQualified() ? "ptr" - : "mut_ptr"; - StrCat(std::format("#[{}({}, {}, {})]", - is_move ? "cpp_from_move" : "cpp_from", source, - GetCtorName(ctor), kind)); - }); - std::unordered_set into_types; - ForEachMethod(decl, [&](clang::CXXMethodDecl *method) { - if (!IsImplicitConversionOperator(method)) { - return; - } - auto *conversion = clang::cast(method); - auto target = GetUnboxedTypeAsString( - conversion->getConversionType().getUnqualifiedType()); - if (!into_types.insert(target).second) { - return; - } - StrCat(std::format("#[cpp_into({}, {}{})]", target, - GetMethodName(conversion), - conversion->isConst() ? "" : ", mut_ptr")); - }); -} - void Converter::EmitReprC(clang::RecordDecl *decl) { if (decl->hasAttr()) { StrCat(std::format("#[repr(C, align({}))]", @@ -1432,7 +1406,7 @@ bool Converter::VisitCXXMethodDecl(clang::CXXMethodDecl *decl) { } ScopedValue push_fn(curr_function_, decl); - if (auto *trait = GetRecordTrait(decl)) { + if (auto *trait = GetMethodTrait(decl)) { ConvertCopyOrMoveTraitImpl(decl, *trait); return false; } @@ -1456,9 +1430,12 @@ bool Converter::ConvertOutOfLineMethod(clang::CXXMethodDecl *decl) { } std::string Converter::GetMethodName(const clang::CXXMethodDecl *decl) { - if (auto *trait = GetRecordTrait(decl)) { + if (auto *trait = GetMethodTrait(decl)) { return trait->method; } + if (auto method = GetInitMethod(decl)) { + return *method; + } if (clang::isa(decl)) { return kDestructorName; } @@ -1471,14 +1448,14 @@ std::string Converter::GetMethodName(const clang::CXXMethodDecl *decl) { } if (auto *conversion = clang::dyn_cast(decl)) { auto name = GetConversionName(conversion); - bool shared = - llvm::any_of(conversion->getParent()->methods(), - [&](const clang::CXXMethodDecl *method) { - auto *other = - clang::dyn_cast(method); - return other && other != conversion && - GetConversionName(other) == name; - }); + bool shared = llvm::any_of( + conversion->getParent()->methods(), + [&](const clang::CXXMethodDecl *method) { + auto *other = clang::dyn_cast(method); + return other && + other->getCanonicalDecl() != conversion->getCanonicalDecl() && + GetConversionName(other) == name; + }); return shared ? name + std::format("_{}", GetMethodIndex(conversion)) : name; } @@ -1498,9 +1475,9 @@ bool Converter::ConvertCXXMethodDecl(clang::CXXMethodDecl *decl) { return VisitCXXConstructorDecl(ctor); } - if (!GetRecordTrait(decl) && - (decl->isStatic() || - (!decl->isVirtual() && !decl->getParent()->isAbstract()))) { + bool is_trait = GetMethodTrait(decl); + if (!is_trait && (decl->isStatic() || + (!decl->isVirtual() && !decl->getParent()->isAbstract()))) { StrCat(AccessSpecifierAsString(decl->getAccess())); } StrCat(keyword_unsafe_, keyword::kFn, GetMethodName(decl)); @@ -1532,8 +1509,8 @@ std::string Converter::GetSelfMaybeWithMut(const clang::CXXMethodDecl *decl) { } std::string Converter::GetCtorName(clang::CXXConstructorDecl *decl) { - if (auto *trait = GetRecordTrait(decl)) { - return trait->method; + if (auto method = GetInitMethod(decl)) { + return *method; } if (decl->isCopyOrMoveConstructor()) { if (const char *name = GetCopyOrMoveName(decl); @@ -1548,14 +1525,12 @@ std::string Converter::GetCtorName(clang::CXXConstructorDecl *decl) { } bool Converter::VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl) { - if (!IsConvertedConstructor(decl)) { + if (!IsConvertedConstructor(decl) || IsDerivedCopyOrMove(decl)) { return false; } ScopedValue push_fn(curr_function_, decl); - if (!GetRecordTrait(decl)) { - StrCat(AccessSpecifierAsString(decl->getAccess())); - } + StrCat(AccessSpecifierAsString(decl->getAccess())); StrCat(keyword_unsafe_, keyword::kFn, GetCtorName(decl)); { PushParen paren(*this); @@ -1788,11 +1763,12 @@ bool Converter::VisitReturnStmt(clang::ReturnStmt *stmt) { ScopedValue return_value(return_value_, stmt->getRetValue()); auto return_type = curr_function_->getReturnType(); if (auto *value = stmt->getRetValue(); value && UsesReturnSlot(return_type)) { + std::string_view slot = "__return"; if (auto *construct = GetPlacementInitializer(value)) { - ConstructInPlace(value, construct, GetReturnSlotReceiver()); + ConstructInPlace(value, construct, GetReturnSlotReceiver(slot)); } else { HoistMaterializedTempBindings hoist_temps(*this); - StrCat("__return.write"); + StrCat(slot, ".write"); { PushParen paren(*this); ConvertVarInit(return_type, value); @@ -2774,7 +2750,12 @@ void Converter::EmitArgList(const CallInfo &info) { StrCat(ca.param_name); break; case Kind::Materialized: - StrCat(ca.ref_temp_name); + if (UsesReturnSlot(ca.param_type)) { + StrCat(std::format("{}::bind({})", GetParameterObjectMarker(), + ca.ref_temp_name)); + } else { + StrCat(ca.ref_temp_name); + } break; case Kind::Inline: { StrCat(ConvertArg(info.expr, @@ -4934,6 +4915,8 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) { block.emplace(*this); StrCat(CreatePlacementStorage(GetRecordName(ctor->getParent()))); } + bool is_derived = IsDerivedCopyOrMove(ctor); + bool is_init = is_derived || GetInitMethod(ctor).has_value(); std::string args; for (unsigned i = 0; i < ctor->getNumParams(); ++i) { assert(i < expr->getNumArgs()); @@ -4944,38 +4927,40 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) { auto converted = ConvertArg(expr, [&] { auto type = ctor->getParamDecl(i)->getType(); if (UsesReturnSlot(type)) { - StrCat(EmitMaterializedTempBinding(type, arg)); + StrCat(std::format("{}::bind({})", GetParameterObjectMarker(), + EmitMaterializedTempBinding(type, arg))); } else { ConvertVarInit(type, arg); } }); + if (auto type = ctor->getParamDecl(i)->getType(); + is_init && IsReferenceToObject(type)) { + converted = std::format("{}::bind({})", + GetReferenceMarker(type->isRValueReferenceType()), + converted); + } else if (is_init && UsesPointerMarker(type)) { + converted = std::format("{}::bind({})", GetPointerMarker(), converted); + } args += std::format("{}{}", i ? ", " : "", converted); } - // The copy and move constructors are picked by the type of the source. - auto *trait = GetRecordTrait(ctor); - bool from_source = - trait == &kCopyConstructible || trait == &kMoveConstructible; - if (from_source) { - args = std::format("{}::bind({})", - GetReferenceMarker(trait == &kMoveConstructible), args); - } if (in_place && in_place_.object_tail && hoist_temps.empty() && - full_expression_temporaries_->empty()) { + full_expression_temporaries_->empty() && !is_derived) { auto record_name = GetRecordName(ctor->getParent()); - if (from_source) { - in_place_.object_tail->emplace(std::format("{}, {}", record_name, args)); - } else if (auto name = GetCtorName(ctor); name == kConstructName) { + if (auto name = GetCtorName(ctor); name == kConstructName) { in_place_.object_tail->emplace(std::format("{}({})", record_name, args)); - } else if (trait != &kDefaultConstructible) { + } else { in_place_.object_tail->emplace( std::format("{}::{}({})", record_name, name, args)); - } else { - in_place_.object_tail->emplace(record_name); } return; } auto path = - std::format("{}::{}", GetConstructorPath(ctor), GetCtorName(ctor)); + is_derived + ? std::format("<{} as {}>::{}", GetRecordName(ctor->getParent()), + GetRecordTraitSpelling(*GetRecordTrait(ctor)).name, + GetRecordTrait(ctor)->method) + : std::format("{}::{}", GetRecordName(ctor->getParent()), + GetCtorName(ctor)); StrCat(std::format("{}({}{}{})", path, in_place ? in_place_.receiver : GetPlacementReceiver(), args.empty() ? "" : ", ", args)); @@ -5054,18 +5039,11 @@ const char *Converter::GetConstructorSelf() const { return "this: *mut Self"; } const char *Converter::GetConstructorWrite() const { return "this.write"; } -std::string -Converter::GetConstructorPath(const clang::CXXConstructorDecl *ctor) const { - if (auto *trait = GetRecordTrait(ctor)) { - return GetCopyOrMoveTraitName(*trait); - } - return GetRecordName(ctor->getParent()); -} - std::string Converter::CreatePlacementStorage(const std::string &record_name, std::string_view name) const { - return std::format("let mut {1}: {0} = <{0}>::zero_init();", record_name, - name); + return std::format( + "let mut {1}: {0} = ZeroInitializationUnsafe::zero_init();", record_name, + name); } std::string Converter::GetPlacementReceiver(std::string_view name) const { @@ -5084,7 +5062,9 @@ bool Converter::CanConstructVarInPlace(const clang::VarDecl *decl) const { const char *Converter::TakePlacementValue() const { return "__v"; } -const char *Converter::GetReturnSlotReceiver() const { return "__return"; } +std::string Converter::GetReturnSlotReceiver(std::string_view slot) const { + return std::string(slot); +} std::string Converter::GetReturnSlotArg(std::string_view receiver) const { return std::string(receiver); @@ -5649,10 +5629,6 @@ Converter::GetStructAttributes(const clang::RecordDecl *decl) { struct_attrs.emplace_back("FnPtrArg"); struct_attrs.emplace_back("ZeroInitializationUnsafe"); - if (HasImplicitConversions(decl)) { - struct_attrs.emplace_back("CppFromUnsafe"); - } - AddSpecialMemberDerives(decl, struct_attrs); if (RecordDerivesDefault(decl)) { @@ -5853,20 +5829,58 @@ void Converter::ConvertFunctionParameters(clang::FunctionDecl *decl) { if (UsesReturnSlot(decl->getReturnType())) { StrCat(GetReturnSlotParam(decl->getReturnType())); } + if (clang::isa(decl) && GetInitMethod(decl)) { + ScopedValue in_formals(in_function_formals_, true); + for (auto *param : DefinitionParameters(decl)) { + auto name = GetNamedDeclAsString(param); + auto type = GetConvertedVarType(param); + bool is_mut = + NeedsMut(param, type, name) && !UsesPointerMarker(param->getType()); + StrCat(std::format("{}{}: {},", is_mut ? "mut " : "", name, + GetConstructorArgType(param))); + } + return; + } if (auto *source = GetCopyOrMoveSource(decl)) { - StrCat(GetNamedDeclAsString(source), token::kColon, - GetReferenceMarkerAsString(source->getType()), token::kComma); + StrCat(std::format("{}: {},", GetNamedDeclAsString(source), + GetReferenceMarkerAsString(source->getType()))); return; } ConvertParamList(DefinitionParameters(decl), decl->isVariadic()); } void Converter::EmitFunctionPreamble(clang::FunctionDecl *decl) { - if (auto *source = GetCopyOrMoveSource(decl)) { + for (auto *param : DefinitionParameters(decl)) { + if (UsesReturnSlot(param->getType())) { + auto name = GetNamedDeclAsString(param); + StrCat(std::format( + "let {} = {};", name, + GetReferredObjectPointer(name, GetConvertedVarType(param)))); + } + } + if (!GetMethodTrait(decl) && !GetInitMethod(decl)) { + return; + } + if (auto *source = GetCopyOrMoveSource(decl); + source && !clang::isa(decl)) { auto name = GetNamedDeclAsString(source); StrCat(std::format("let {} = {};", name, GetReferredObjectPointer(name, source->getType()))); } + if (clang::isa(decl)) { + for (auto *param : DefinitionParameters(decl)) { + auto type = param->getType(); + auto name = GetNamedDeclAsString(param); + if (IsReferenceToObject(type)) { + StrCat(std::format("let {} = {};", name, + GetReferredObjectPointer(name, type))); + } else if (UsesPointerMarker(type)) { + bool is_mut = NeedsMut(param, GetConvertedVarType(param), name); + StrCat(std::format("let {}{} = {};", is_mut ? "mut " : "", name, + GetReferredObjectPointer(name, type))); + } + } + } } std::string Converter::GetReferredObjectPointer(std::string_view reference, @@ -5931,7 +5945,7 @@ void Converter::ConvertCXXMethodDecls( bool (*predicate)(clang::CXXMethodDecl *)) { bool first = true; auto convert_method = [&](clang::CXXMethodDecl *method) { - if (predicate(method) && !GetRecordTrait(method)) { + if (predicate(method) && !GetMethodTrait(method)) { if (first) { StrCat(signature, token::kOpenCurlyBracket); first = false; @@ -6355,14 +6369,17 @@ Converter::MakeDefaultConstructExpr(const clang::CXXRecordDecl *decl, void Converter::AddDefaultConstructibleTrait(const clang::CXXRecordDecl *decl, clang::CXXConstructorDecl *ctor) { const auto &spelling = GetRecordTraitSpelling(kDefaultConstructible); - StrCat(keyword::kImpl, spelling.name, "for", GetRecordName(decl)); - PushBrace impl_brace(*this); - StrCat(spelling.signature); - PushBrace fn_brace(*this); - StrCat(keyword_unsafe_); - PushBrace unsafe_brace(*this); - auto *construct = MakeDefaultConstructExpr(decl, ctor); - ConstructInPlace(construct, construct, spelling.receiver); + auto record = GetRecordName(decl); + StrCat(keyword::kImpl, spelling.constructor, "for", record); + { + PushBrace impl_brace(*this); + StrCat(spelling.signature); + PushBrace fn_brace(*this); + StrCat(keyword_unsafe_); + PushBrace unsafe_brace(*this); + auto *construct = MakeDefaultConstructExpr(decl, ctor); + ConstructInPlace(construct, construct, spelling.receiver); + } } void Converter::EmitDefaultImpl(const clang::RecordDecl *decl, @@ -7268,33 +7285,141 @@ std::vector Converter::ArgsToEvaluateFirst( return first; } -bool Converter::IsReferenceToObject(clang::QualType type) const { - if (!type->isReferenceType()) { - return false; +std::string Converter::GetCvObjectAsString(clang::QualType object) { + auto spelling = GetUnboxedTypeAsString(object.getUnqualifiedType()); + if (object.isVolatileQualified()) { + spelling = std::format("Volatile<{}>", spelling); + } + if (object.isConstQualified()) { + spelling = std::format("Const<{}>", spelling); } - auto pointee = type->getPointeeType(); - auto *record = pointee->getAsCXXRecordDecl(); - return !pointee->isFunctionType() && !pointee->isArrayType() && - !(record && IsAbstractUserClass(record)); + return spelling; } std::string Converter::GetReferenceMarkerAsString(clang::QualType type) { - auto pointee = type->getPointeeType(); - auto object = GetUnboxedTypeAsString(pointee.getUnqualifiedType()); - if (pointee.isVolatileQualified()) { - object = std::format("Volatile<{}>", object); - } - if (pointee.isConstQualified()) { - object = std::format("Const<{}>", object); - } return std::format("{}<{}>", - GetReferenceMarker(type->isRValueReferenceType()), object); + GetReferenceMarker(type->isRValueReferenceType()), + GetCvObjectAsString(type->getPointeeType())); +} + +std::string Converter::GetPointerMarkerAsString(clang::QualType type) { + return std::format("{}<{}>", GetPointerMarker(), + GetCvObjectAsString(type->getPointeeType())); } const char *Converter::GetReferenceMarker(bool is_rvalue) const { return is_rvalue ? "RvalueRefUnsafe" : "LvalueRefUnsafe"; } +const char *Converter::GetParameterObjectMarker() const { + return "ParameterObjectUnsafe"; +} + +const char *Converter::GetPointerMarker() const { return "PointerUnsafe"; } + +std::string Converter::GetParameterObjectType(clang::QualType type) { + return std::format("{}<{}>", GetParameterObjectMarker(), + GetUnboxedTypeAsString(type.getUnqualifiedType())); +} + +void Converter::EmitConversionsAttrs(const clang::CXXRecordDecl *decl) { + if (!HasConversionsTable(ctx_.getCanonicalTagType(decl))) { + return; + } + StrCat(std::format("#[derive({})]", GetConversionsTrait())); + std::vector ctors; + for (auto *ctor : decl->ctors()) { + ctors.push_back(ctor); + } + for (auto *ctor : + GetTemplateInstantiatedCtors(const_cast(decl))) { + ctors.push_back(ctor); + } + std::vector specials; + if (HasConstructor(decl, false)) { + specials.push_back("copy"); + } + if (HasConstructor(decl, true)) { + specials.push_back("move"); + } + if (!specials.empty()) { + StrCat(std::format("#[conversions({})]", llvm::join(specials, ", "))); + } + auto record = GetRecordName(decl); + std::unordered_set arg_types; + for (auto *ctor : ctors) { + auto method = GetInitMethod(ctor); + if (!method || !IsEmittedConstructor(ctor)) { + continue; + } + if (!llvm::all_of(ctor->parameters(), [](auto *param) { + auto type = param->getType(); + return HasConversionsTable(type) && + !type.getNonReferenceType().isVolatileQualified(); + })) { + continue; + } + std::vector types; + for (auto *param : ctor->parameters()) { + types.push_back(GetConstructorArgType(param)); + } + [[maybe_unused]] bool is_unique = + arg_types.insert(llvm::join(types, ",")).second; + assert(is_unique && "two constructors take the same Rust arguments"); + std::vector params{*method}; + if (ctor->isExplicit()) { + params.push_back("explicit"); + } + params.insert(params.end(), types.begin(), types.end()); + if (auto *trait = GetRecordTrait(ctor)) { + converted_record_traits_.emplace(record, trait->refcount.name); + } + StrCat(std::format("#[constructor({})]", llvm::join(params, ", "))); + } + for (auto *candidate : decl->methods()) { + auto *conversion = clang::dyn_cast(candidate); + if (!conversion || !IsTableConversionFunction(conversion) || + !IsEmittableMethod(conversion) || !conversion->isDefined()) { + continue; + } + auto to = conversion->getConversionType(); + auto object = ctx_.getQualifiedType(ctx_.getCanonicalTagType(decl), + conversion->getMethodQualifiers()); + StrCat(std::format("#[conversion_function({}, {}, {}{}{})]", + GetMethodName(conversion), + GetReferenceMarkerAsString( + conversion->getRefQualifier() == clang::RQ_RValue + ? ctx_.getRValueReferenceType(object) + : ctx_.getLValueReferenceType(object)), + GetUnboxedTypeAsString(to.getUnqualifiedType()), + conversion->isExplicit() ? ", explicit" : "", + UsesReturnSlot(to) ? ", return_slot" : "")); + } +} + +const char *Converter::GetConversionsTrait() const { + return "ConversionsUnsafe"; +} + +std::string Converter::GetConstructorArgType(const clang::ParmVarDecl *param) { + ScopedValue in_formals(in_function_formals_, true); + auto type = param->getType(); + if (UsesReturnSlot(type)) { + return GetParameterObjectType(type); + } + if (IsReferenceToObject(type)) { + return GetReferenceMarkerAsString(type); + } + if (UsesPointerMarker(type)) { + return GetPointerMarkerAsString(type); + } + return GetParamTypeAsString(param); +} + +std::string Converter::GetParamTypeAsString(const clang::ParmVarDecl *param) { + return ToString(GetConvertedVarType(param)); +} + bool Converter::ReturnsPointerToArg(clang::Expr *) { return false; } std::string Converter::ConvertPointerToArg(clang::Expr *, std::string_view) { @@ -7312,7 +7437,13 @@ std::string Converter::ConvertIRFragment( if (auto *t = std::get_if(&frag)) { result += t->text; } else if (auto *g = std::get_if(&frag)) { - result += GetTemplateArgumentAsString(bindings[g->n - 1]); + if (g->n <= bindings.size()) { + result += GetTemplateArgumentAsString(bindings[g->n - 1]); + } else { + assert(expr && "unbound generic outside an expression rule"); + result += GetTemplateArgumentAsString(clang::TemplateArgument( + RuleRegistry::GetGenericType(ctx_, expr, g->n))); + } } else if (auto *ph = std::get_if(&frag)) { assert(expr && "placeholder outside an expression rule"); auto arg_idx = ph->n; @@ -7409,45 +7540,11 @@ std::string Converter::ConvertGenericCall( assert(call_args.empty() && "default_constructed takes no arguments"); return GetUnboxedDefaultAsString(type); } - if (call.method == "cpp_from" || call.method == "cpp_from_move") { - assert(call_args.size() == 1 && "cpp_from takes one argument"); - return ConvertConversion( - type, RuleRegistry::GetConversionSourceType(ctx_, expr, call.generic), - call.method == "cpp_from_move", call_args[0]); - } + return std::format("<{}>::{}({})", GetUnboxedTypeAsString(type), call.method, llvm::join(call_args, ", ")); } -std::string Converter::ConvertConversion(clang::QualType to, - clang::QualType from, bool is_move, - const std::string &ptr) { - if (to->isArithmeticType() && from->isArithmeticType()) { - auto value = DerefPtrExpr(ptr, from); - if (ctx_.hasSameUnqualifiedType(to, from)) { - return value; - } - if (to->isBooleanType()) { - return std::format("({} != {})", value, - from->isFloatingType() ? "0.0" : "0"); - } - if (from->isBooleanType() && to->isFloatingType()) { - return std::format("({} as u8 as {})", value, GetUnsafeTypeAsString(to)); - } - return std::format("({} as {})", value, GetUnsafeTypeAsString(to)); - } - if (is_move && ctx_.hasSameUnqualifiedType(to, from)) { - return ConvertMoveThroughPointer(to, ptr); - } - return std::format("<{} as {}<{}>>::{}({})", GetUnboxedTypeAsString(to), - GetConversionTraitName(), GetUnboxedTypeAsString(from), - is_move ? "cpp_from_move" : "cpp_from", ptr); -} - -const char *Converter::GetConversionTraitName() const { - return "CppFromUnsafe"; -} - 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 0f54173255..44dbc79de1 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -101,12 +101,28 @@ class Converter : public clang::RecursiveASTVisitor { std::string GetTemplateArgumentAsString(const clang::TemplateArgument &arg); - bool IsReferenceToObject(clang::QualType type) const; - std::string GetReferenceMarkerAsString(clang::QualType type); virtual const char *GetReferenceMarker(bool is_rvalue) const; + virtual const char *GetParameterObjectMarker() const; + + virtual const char *GetPointerMarker() const; + + std::string GetPointerMarkerAsString(clang::QualType type); + + std::string GetCvObjectAsString(clang::QualType object); + + std::string GetParameterObjectType(clang::QualType type); + + void EmitConversionsAttrs(const clang::CXXRecordDecl *decl); + + virtual const char *GetConversionsTrait() const; + + std::string GetConstructorArgType(const clang::ParmVarDecl *param); + + virtual std::string GetParamTypeAsString(const clang::ParmVarDecl *param); + virtual std::string CollapseReference(std::string_view result, clang::QualType referred, bool is_place); @@ -197,8 +213,6 @@ class Converter : public clang::RecursiveASTVisitor { void EmitReprC(clang::RecordDecl *decl); void EmitDerives(const clang::RecordDecl *decl); - void EmitConversionAttrs(clang::CXXRecordDecl *decl); - virtual void EmitRustUnion(clang::RecordDecl *decl); virtual bool EmitsReprCForRecords() const { return true; } @@ -273,9 +287,6 @@ class Converter : public clang::RecursiveASTVisitor { virtual const char *GetConstructorWrite() const; - virtual std::string - GetConstructorPath(const clang::CXXConstructorDecl *ctor) const; - // A variable named name that holds zero-initialized storage for a record, // in which a constructor constructs the record. virtual std::string @@ -298,7 +309,7 @@ class Converter : public clang::RecursiveASTVisitor { virtual const char *TakePlacementValue() const; - virtual const char *GetReturnSlotReceiver() const; + virtual std::string GetReturnSlotReceiver(std::string_view slot) const; virtual std::string GetReturnSlotArg(std::string_view receiver) const; @@ -396,11 +407,6 @@ class Converter : public clang::RecursiveASTVisitor { clang::Expr *expr, llvm::ArrayRef args, TempMaterializationCtx *ctx); - std::string ConvertConversion(clang::QualType to, clang::QualType from, - bool is_move, const std::string &ptr); - - virtual const char *GetConversionTraitName() const; - virtual const RecordTraitSpelling & GetRecordTraitSpelling(const RecordTrait &trait) const; @@ -1024,7 +1030,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual std::string GetAssignmentTraitSignature(const RecordTrait &trait) const; - std::string GetCopyOrMoveSourceType(const RecordTrait &trait) const; + std::string GetCopyOrMoveSourceType(const RecordTrait &trait, + std::string_view self = "Self") const; virtual void AddDefaultTraitForUnion(const clang::RecordDecl *decl); @@ -1236,6 +1243,7 @@ class Converter : public clang::RecursiveASTVisitor { bool in_function_formals_ = false; std::string ufcs_receiver_; + bool in_const_initializer_ = false; bool constant_evaluated_ = false; std::optional autoref_mut_; diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 444884f2d5..88fc850a5f 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -871,12 +871,12 @@ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { : nullptr; } const char *name = GetCopyOrMoveName(method); + auto *ctor = clang::dyn_cast(method); if (!name || method->isDeleted() || method->isVirtual() || - !CanUseCopyOrMoveName(method, name) || + (!ctor && !CanUseCopyOrMoveName(method, name)) || (!IsUserWrittenMember(method) && !IsTranslatedSpecialMember(method))) { return nullptr; } - auto *ctor = clang::dyn_cast(method); if (!ctor && !method->getReturnType()->isLValueReferenceType()) { return nullptr; } @@ -896,6 +896,18 @@ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { return is_copy ? &kCopyAssignable : &kMoveAssignable; } +bool IsConstructibleFromConstructor(const clang::FunctionDecl *decl) { + auto *ctor = clang::dyn_cast_or_null(decl); + if (!ctor || ctor->isDeleted() || ctor->isVariadic() || + ctor->getNumParams() == 0 || GetRecordTrait(ctor)) { + return false; + } + auto *record = ctor->getParent(); + return IsUserDefinedDecl(record) && !record->isLambda() && + !record->isAbstract() && !record->isDependentContext() && + !record->isUnion(); +} + const clang::ParmVarDecl *GetCopyOrMoveSource(const clang::FunctionDecl *decl) { auto *method = clang::dyn_cast(decl); auto *trait = method ? GetRecordTrait(method) : nullptr; @@ -1029,23 +1041,22 @@ bool MovesRuleArg(clang::Expr *expr, unsigned arg_idx, clang::Expr *arg, return moved && !clang::isa(arg); } -static bool -IsImplicitConvertingConstructor(const clang::CXXConstructorDecl *ctor) { +static bool IsOneArgumentConstructor(const clang::CXXConstructorDecl *ctor) { return !ctor->isCopyOrMoveConstructor() && !ctor->isImplicit() && !ctor->isDeleted() && ctor->hasBody() && ctor->getNumParams() == 1 && - ctor->isConvertingConstructor(/*AllowExplicit=*/false); + ctor->isConvertingConstructor(/*AllowExplicit=*/true); } void ForEachConvertingConstructor( clang::CXXRecordDecl *decl, llvm::function_ref fn) { for (auto *ctor : decl->ctors()) { - if (IsImplicitConvertingConstructor(ctor)) { + if (IsOneArgumentConstructor(ctor)) { fn(ctor); } } for (auto *ctor : GetTemplateInstantiatedCtors(decl)) { - if (IsImplicitConvertingConstructor(ctor)) { + if (IsOneArgumentConstructor(ctor)) { fn(ctor); } } @@ -1487,6 +1498,103 @@ unsigned GetCtorIndex(clang::CXXConstructorDecl *ctor) { return static_cast(std::distance(vec.begin(), it) + 1); } +const RecordTrait *GetMethodTrait(const clang::FunctionDecl *decl) { + auto *method = clang::dyn_cast_or_null(decl); + return method && !clang::isa(method) + ? GetRecordTrait(method) + : nullptr; +} + +bool IsReferenceToObject(clang::QualType type) { + if (!type->isReferenceType()) { + return false; + } + auto pointee = type->getPointeeType(); + auto *record = pointee->getAsCXXRecordDecl(); + return !pointee->isFunctionType() && !pointee->isArrayType() && + !IsVaListType(pointee) && !(record && IsAbstractUserClass(record)); +} + +bool HasConversionsTable(clang::QualType type) { + if (IsVaListType(type.getNonReferenceType())) { + return false; + } + type = type.getNonReferenceType().getCanonicalType(); + if (type->isArithmeticType() && !type->isEnumeralType()) { + return true; + } + if (type->isPointerType()) { + return HasConversionsTable(type->getPointeeType()); + } + auto *record = type->getAsCXXRecordDecl(); + return record && record->isCompleteDefinition() && + IsUserDefinedDecl(record) && !record->isLambda() && + !record->isAbstract() && !record->isUnion() && + !record->isDependentContext(); +} + +bool UsesPointerMarker(clang::QualType type) { + return type->isPointerType() && HasConversionsTable(type) && + !type->getPointeeType().isVolatileQualified(); +} + +bool IsTableConversionFunction(const clang::CXXConversionDecl *conversion) { + auto *record = conversion->getParent(); + auto type = conversion->getConversionType(); + return IsUserDefinedDecl(record) && !record->isLambda() && + !record->isDependentContext() && !IsAbstractUserClass(record) && + !conversion->isDeleted() && !conversion->isVirtual() && + !type->isReferenceType() && HasConversionsTable(type) && + !conversion->getMethodQualifiers().hasVolatile(); +} + +std::optional GetInitMethod(const clang::FunctionDecl *decl) { + auto *ctor = clang::dyn_cast_or_null(decl); + if (!ctor || IsDerivedCopyOrMove(ctor) || + (!GetRecordTrait(ctor) && !IsConstructibleFromConstructor(ctor))) { + return std::nullopt; + } + if (ctor->getPrimaryTemplate()) { + return std::format( + "constructor_{}_{}", GetDeclaredCtorIndex(ctor), + GetCtorIndex(const_cast(ctor))); + } + return std::format("constructor_{}", GetDeclaredCtorIndex(ctor)); +} + +bool IsEmittedConstructor(clang::CXXConstructorDecl *ctor) { + return IsEmittableMethod(ctor) && IsConvertedConstructor(ctor) && + !IsDerivedCopyOrMove(ctor) && ctor->isDefined(); +} + +unsigned GetDeclaredCtorIndex(const clang::CXXConstructorDecl *ctor) { + const clang::Decl *target = ctor->getCanonicalDecl(); + if (auto *tmpl = ctor->getPrimaryTemplate()) { + target = tmpl->getCanonicalDecl(); + } + unsigned declared = 0; + for (auto *decl : ctor->getParent()->decls()) { + if (decl->isImplicit()) { + continue; + } + auto *templated = decl; + if (auto *tmpl = clang::dyn_cast(decl)) { + templated = tmpl->getTemplatedDecl(); + } + if (!clang::isa(templated)) { + continue; + } + ++declared; + if (decl->getCanonicalDecl() == target) { + return declared; + } + } + if (ctor->isDefaultConstructor()) { + return declared + 1; + } + return declared + (ctor->isCopyConstructor() ? 2 : 3); +} + clang::CXXConstructorDecl * GetUserDefinedDefaultConstructor(const clang::CXXRecordDecl *decl) { for (auto c : decl->ctors()) { @@ -3222,4 +3330,21 @@ const char *GetConstCastSuffix(clang::QualType to, clang::QualType from) { return to.isConstQualified() ? ".cast_const()" : ".cast_mut()"; } +bool HasConstructor(const clang::CXXRecordDecl *decl, bool is_move) { + if (is_move ? decl->needsImplicitMoveConstructor() + : decl->needsImplicitCopyConstructor()) { + return is_move ? !decl->defaultedMoveConstructorIsDeleted() + : !decl->defaultedCopyConstructorIsDeleted(); + } + return llvm::any_of(decl->ctors(), [&](auto *ctor) { + if (ctor->isDeleted()) { + return false; + } + unsigned quals = 0; + return is_move ? ctor->isMoveConstructor() + : ctor->isCopyConstructor(quals) && + (quals & clang::Qualifiers::Const); + }); +} + } // namespace cpp2rust diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index f1e1851fbb..51b08bcb1c 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -109,6 +109,7 @@ struct RecordTraitSpelling { const char *name; const char *signature = nullptr; const char *receiver = nullptr; + const char *constructor = nullptr; }; struct RecordTrait { @@ -119,27 +120,28 @@ struct RecordTrait { inline constexpr RecordTrait kDefaultConstructible{ "default_constructor", - {"DefaultConstructible", "fn default_constructor(this: Ptr)", - "this.clone()"}, + {"DefaultConstructible", "fn constructor(this: Ptr, _: ())", + "this.clone()", "Constructor<()>"}, {"DefaultConstructibleUnsafe", - "unsafe fn default_constructor(this: *mut Self)", "this"}}; + "unsafe fn constructor(this: *mut Self, _: ())", "this", + "ConstructorUnsafe<()>"}}; inline constexpr RecordTrait kCopyConstructible{ "copy_constructor", {"CopyConstructible", - "fn copy_constructor(this: Ptr, _: LvalueRef>)", - "this.clone()"}, + "fn constructor(this: Ptr, _: (LvalueRef>,))", + "this.clone()", "Constructor<(LvalueRef>,)>"}, {"CopyConstructibleUnsafe", - "unsafe fn copy_constructor(this: *mut Self, _: " - "LvalueRefUnsafe>)", - "this"}}; + "unsafe fn constructor(this: *mut Self, _: " + "(LvalueRefUnsafe>,))", + "this", "ConstructorUnsafe<(LvalueRefUnsafe>,)>"}}; inline constexpr RecordTrait kMoveConstructible{ "move_constructor", {"MoveConstructible", - "fn move_constructor(this: Ptr, _: RvalueRef)", - "this.clone()"}, + "fn constructor(this: Ptr, _: (RvalueRef,))", "this.clone()", + "Constructor<(RvalueRef,)>"}, {"MoveConstructibleUnsafe", - "unsafe fn move_constructor(this: *mut Self, _: RvalueRefUnsafe)", - "this"}}; + "unsafe fn constructor(this: *mut Self, _: (RvalueRefUnsafe,))", + "this", "ConstructorUnsafe<(RvalueRefUnsafe,)>"}}; inline constexpr RecordTrait kCopyAssignable{ "copy_assign", {"CopyAssignable", @@ -236,6 +238,10 @@ inline constexpr RecordTrait kMemberwise{ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method); +const RecordTrait *GetMethodTrait(const clang::FunctionDecl *decl); + +bool IsConstructibleFromConstructor(const clang::FunctionDecl *decl); + const clang::ParmVarDecl *GetCopyOrMoveSource(const clang::FunctionDecl *decl); const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn); @@ -396,6 +402,20 @@ unsigned GetNumberOfConvertingCtors(clang::CXXRecordDecl *decl); unsigned GetCtorIndex(clang::CXXConstructorDecl *ctor); +unsigned GetDeclaredCtorIndex(const clang::CXXConstructorDecl *ctor); + +bool IsReferenceToObject(clang::QualType type); + +bool HasConversionsTable(clang::QualType type); + +bool UsesPointerMarker(clang::QualType type); + +std::optional GetInitMethod(const clang::FunctionDecl *decl); + +bool IsTableConversionFunction(const clang::CXXConversionDecl *conversion); + +bool IsEmittedConstructor(clang::CXXConstructorDecl *ctor); + clang::CXXConstructorDecl * GetUserDefinedDefaultConstructor(const clang::CXXRecordDecl *decl); @@ -664,4 +684,6 @@ void ReplaceAll(std::string &str, std::string_view from, std::string_view to); // their constness differs, or nullptr if it doesn't. const char *GetConstCastSuffix(clang::QualType to, clang::QualType from); +bool HasConstructor(const clang::CXXRecordDecl *decl, bool is_move); + } // namespace cpp2rust diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index d11751a3e4..3435b57a9b 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -318,6 +318,12 @@ const char *ConverterRefCount::GetReferenceMarker(bool is_rvalue) const { return is_rvalue ? "RvalueRef" : "LvalueRef"; } +const char *ConverterRefCount::GetParameterObjectMarker() const { + return "ParameterObject"; +} + +const char *ConverterRefCount::GetPointerMarker() const { return "Pointer"; } + std::string ConverterRefCount::CollapseReference(std::string_view result, clang::QualType, bool) { return std::format("{}.with(|__r| __r.as_pointer())", result); @@ -651,11 +657,11 @@ ConverterRefCount::GetComparisonArg(const clang::ParmVarDecl *param, if (IsTriviallyCopyable(decl)) { return std::format("{}.read()", value); } - return std::format("{{ {} {}::{}({}, LvalueRef::bind({}.clone())); {} }}", - CreatePlacementStorage(GetRecordName(decl)), - GetCopyOrMoveTraitName(kCopyConstructible), - kCopyConstructible.method, GetPlacementReceiver(), value, - TakePlacementValue()); + auto record = GetRecordName(decl); + return std::format("{{ {} <{} as CopyConstructible>::copy_constructor({}, " + "LvalueRef::bind({}.clone())); {} }}", + CreatePlacementStorage(record), record, + GetPlacementReceiver(), value, TakePlacementValue()); } std::string ConverterRefCount::GetComparisonResultReceiver( @@ -857,6 +863,10 @@ bool ConverterRefCount::VisitFieldDecl(clang::FieldDecl *decl) { return Converter::VisitFieldDecl(decl); } +const char *ConverterRefCount::GetConversionsTrait() const { + return "Conversions"; +} + std::string ConverterRefCount::GetReferredObjectPointer(std::string_view reference, clang::QualType) { @@ -2334,10 +2344,6 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { } attrs.emplace_back("FnPtrArg"); - if (HasImplicitConversions(decl)) { - attrs.emplace_back("CppFrom"); - } - AddSpecialMemberDerives(decl, attrs); if (RecordDerivesDefault(decl)) { @@ -2346,10 +2352,6 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { return attrs; } -const char *ConverterRefCount::GetConversionTraitName() const { - return "CppFrom"; -} - const RecordTraitSpelling & ConverterRefCount::GetRecordTraitSpelling(const RecordTrait &trait) const { return trait.refcount; @@ -3561,7 +3563,7 @@ bool ConverterRefCount::ShouldConvertMethod(const clang::CXXMethodDecl *decl) { bool ConverterRefCount::ReceivesThis() const { auto *method = clang::dyn_cast_or_null(curr_function_); - return method && GetRecordTrait(method); + return method && (GetMethodTrait(method) || GetInitMethod(method)); } const char *ConverterRefCount::SelfName() const { @@ -3663,9 +3665,9 @@ const char *ConverterRefCount::GetConstructorWrite() const { std::string ConverterRefCount::CreatePlacementStorage(const std::string &record_name, std::string_view name) const { - return std::format( - "let {1}: Value<{0}> = Rc::new(RefCell::new(<{0}>::zero_init()));", - record_name, name); + return std::format("let {1}: Value<{0}> = " + "Rc::new(RefCell::new(ZeroInitialization::zero_init()));", + record_name, name); } std::string @@ -3692,8 +3694,9 @@ const char *ConverterRefCount::TakePlacementValue() const { return "Rc::try_unwrap(__v).ok().unwrap().into_inner()"; } -const char *ConverterRefCount::GetReturnSlotReceiver() const { - return "__return.clone()"; +std::string +ConverterRefCount::GetReturnSlotReceiver(std::string_view slot) const { + return std::format("{}.clone()", slot); } std::string @@ -3701,6 +3704,12 @@ ConverterRefCount::GetReturnSlotArg(std::string_view receiver) const { return std::format("Ptr::clone(&{})", receiver); } +std::string +ConverterRefCount::GetParamTypeAsString(const clang::ParmVarDecl *param) { + PushConversionKind push(*this, VarConversionKind(param)); + return ToString(GetConvertedVarType(param)); +} + bool ConverterRefCount::VisitCXXThisExpr( [[maybe_unused]] clang::CXXThisExpr *expr) { if (auto field = AsLambdaCaptureThis(curr_function_)) { diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 2777cf53b2..b65cd7cfbd 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -31,6 +31,10 @@ class ConverterRefCount final : public Converter { const char *GetReferenceMarker(bool is_rvalue) const override; + const char *GetParameterObjectMarker() const override; + + const char *GetPointerMarker() const override; + std::string CollapseReference(std::string_view result, clang::QualType referred, bool is_place) override; @@ -116,7 +120,11 @@ class ConverterRefCount final : public Converter { const char *TakePlacementValue() const override; - const char *GetReturnSlotReceiver() const override; + std::string GetReturnSlotReceiver(std::string_view slot) const override; + + const char *GetConversionsTrait() const override; + + std::string GetParamTypeAsString(const clang::ParmVarDecl *param) override; std::string GetReturnSlotArg(std::string_view receiver) const override; @@ -527,8 +535,6 @@ class ConverterRefCount final : public Converter { std::string DerefPtrExpr(std::string_view ptr_expr, clang::QualType pointee_type) override; - const char *GetConversionTraitName() const override; - const RecordTraitSpelling & GetRecordTraitSpelling(const RecordTrait &trait) const override; diff --git a/cpp2rust/converter/rules/registry.cpp b/cpp2rust/converter/rules/registry.cpp index 583961c19c..59007006ee 100644 --- a/cpp2rust/converter/rules/registry.cpp +++ b/cpp2rust/converter/rules/registry.cpp @@ -464,19 +464,6 @@ clang::QualType GetGenericType(clang::ASTContext &ctx, const clang::Expr *expr, return iteratorElementType(ctx, GetGenericType(ctx, expr, iterator)); } -clang::QualType GetConversionSourceType(clang::ASTContext &ctx, - const clang::Expr *expr, unsigned to) { - auto rule = Search(ctx, expr).first; - assert(rule && "expression must have a translation rule"); - for (const auto &bound : rule->generics.at(to - 1)) { - if (bound.trait_name == "CppFrom" || bound.trait_name == "CppFromUnsafe") { - assert(bound.args.size() == 1 && "CppFrom takes one generic"); - return GetGenericType(ctx, expr, bound.args[0]); - } - } - llvm::report_fatal_error("converted generic has no CppFrom bound"); -} - clang::QualType GetInitType(clang::ASTContext &ctx, const clang::Expr *expr) { auto match = findExpr(expr); assert(match.rule_decl && "expression must have a translation rule"); diff --git a/cpp2rust/converter/rules/registry.h b/cpp2rust/converter/rules/registry.h index c035aa8da7..293ec7fa4f 100644 --- a/cpp2rust/converter/rules/registry.h +++ b/cpp2rust/converter/rules/registry.h @@ -47,9 +47,6 @@ std::string InitAliasName(Model model, const std::string &name); clang::QualType GetGenericType(clang::ASTContext &ctx, const clang::Expr *expr, unsigned n); -clang::QualType GetConversionSourceType(clang::ASTContext &ctx, - const clang::Expr *expr, unsigned to); - bool HasExprRule(const clang::FunctionDecl *decl); bool IsLibcPassthrough(clang::ASTContext &ctx, const clang::Expr *expr); bool ReturnsPointer(clang::ASTContext &ctx, const clang::Expr *expr); diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index 0b66dc0cd7..eec3c20f48 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -54,8 +54,8 @@ pub fn expand_default_constructible(input: TokenStream, is_unsafe: bool) -> Toke let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); if is_unsafe { quote! { - impl #impl_generics ::libcc2rs::DefaultConstructibleUnsafe for #name #ty_generics #where_clause { - unsafe fn default_constructor(this: *mut Self) { + impl #impl_generics ::libcc2rs::ConstructorUnsafe<()> for #name #ty_generics #where_clause { + unsafe fn constructor(this: *mut Self, _: ()) { unsafe { ::std::ptr::write( this, @@ -67,8 +67,8 @@ pub fn expand_default_constructible(input: TokenStream, is_unsafe: bool) -> Toke } } else { quote! { - impl #impl_generics ::libcc2rs::DefaultConstructible for #name #ty_generics #where_clause { - fn default_constructor(this: ::libcc2rs::Ptr) { + impl #impl_generics ::libcc2rs::Constructor<()> for #name #ty_generics #where_clause { + fn constructor(this: ::libcc2rs::Ptr, _: ()) { this.write(::zero_init()); } } @@ -143,7 +143,15 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - } else { quote!(::libcc2rs::LvalueRefUnsafe<::libcc2rs::Const>) }; - let body = if is_move { + let body = if is_move && !is_assign { + quote!(unsafe { + >, + )>>::constructor( + this, (::libcc2rs::LvalueRefUnsafe::bind(src.as_ptr()),) + ) + }) + } else if is_move { quote!(unsafe { ::libcc2rs::#copy_trait::#copy_method( this, @@ -163,6 +171,15 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - } else { quote!() }; + if !is_assign { + return quote! { + impl #impl_generics ::libcc2rs::ConstructorUnsafe<(#src_ty,)> for #name #ty_generics #where_clause { + unsafe fn constructor(this: *mut Self, (src,): (#src_ty,)) { + #body + } + } + }; + } quote! { impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause { unsafe fn #method(this: *mut Self, src: #src_ty) #ret { @@ -181,7 +198,14 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - } else { quote!(::libcc2rs::LvalueRef<::libcc2rs::Const>) }; - let body = if is_move { + let body = if is_move && !is_assign { + quote!(>, + )>>::constructor( + this, + (::libcc2rs::LvalueRef::bind(src.as_pointer()),), + )) + } else if is_move { quote!(::libcc2rs::#copy_trait::#copy_method( this, ::libcc2rs::LvalueRef::bind(src.as_pointer()), @@ -194,38 +218,20 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - } else { quote!(this.write(src.as_pointer().with(::clone));) }; - // The copy of a type with Clone is a clone, and its move is its copy. - let copied = match (is_move, is_assign) { - (false, false) => Some(quote! { - fn copied(src: ::libcc2rs::Ptr) -> Self { - src.with(::clone) - } - - fn copied_elems(src: &::libcc2rs::Ptr>) -> Vec { - src.with(|elems| elems.clone()) - } - - fn push_copied(v: &::libcc2rs::Ptr>, src: ::libcc2rs::Ptr) { - let value = src.with(::clone); - v.with_mut(|elems| elems.push(value)); - } - }), - (true, false) => Some(quote! { - fn push_moved(v: &::libcc2rs::Ptr>, src: ::libcc2rs::Ptr) - where - Self: ::libcc2rs::ZeroInitialization + ::libcc2rs::ByteRepr, - { - ::push_copied(v, src) + if !is_assign { + return quote! { + impl #impl_generics ::libcc2rs::Constructor<(#src_ty,)> for #name #ty_generics #where_clause { + fn constructor(this: ::libcc2rs::Ptr, (src,): (#src_ty,)) { + #body + } } - }), - _ => None, - }; + }; + } quote! { impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause { fn #method(this: ::libcc2rs::Ptr, src: #src_ty) #ret { #body } - #copied } } } @@ -349,6 +355,7 @@ fn impl_memberwise( .to_compile_error(); }; let members: Vec<_> = data.fields.members().collect(); + let field_types: Vec<_> = data.fields.iter().map(|field| &field.ty).collect(); let name = &input.ident; let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); let is_move = op == "move"; @@ -389,6 +396,29 @@ fn impl_memberwise( } else { (quote!(), quote!()) }; + if !is_assign { + let field_src = |ty: &syn::Type| { + if is_move { + quote!(::libcc2rs::RvalueRefUnsafe<#ty>) + } else { + quote!(::libcc2rs::LvalueRefUnsafe<::libcc2rs::Const<#ty>>) + } + }; + let field_srcs: Vec<_> = field_types.iter().map(|ty| field_src(ty)).collect(); + return quote! { + impl #impl_generics ::libcc2rs::ConstructorUnsafe<(#src_ty,)> for #name #ty_generics #where_clause { + unsafe fn constructor(this: *mut Self, (src,): (#src_ty,)) { + let src = src.#object(); + #(unsafe { + <#field_types as ::libcc2rs::ConstructorUnsafe<(#field_srcs,)>>::constructor( + &raw mut (*this).#members, + (#marker::bind(#src_field (*src).#members),), + ) + };)* + } + } + }; + } return quote! { impl #impl_generics #tr for #name #ty_generics #where_clause { unsafe fn #method(this: *mut Self, src: #src_ty) #ret { @@ -417,6 +447,29 @@ fn impl_memberwise( } else { (quote!(), quote!()) }; + if !is_assign { + let field_srcs: Vec<_> = field_types + .iter() + .map(|ty| { + if is_move { + quote!(::libcc2rs::RvalueRef<#ty>) + } else { + quote!(::libcc2rs::LvalueRef<::libcc2rs::Const<#ty>>) + } + }) + .collect(); + return quote! { + impl #impl_generics ::libcc2rs::Constructor<(#src_ty,)> for #name #ty_generics #where_clause { + fn constructor(this: ::libcc2rs::Ptr, (src,): (#src_ty,)) { + let src = src.as_pointer(); + #(<#field_types as ::libcc2rs::Constructor<(#field_srcs,)>>::constructor( + ::libcc2rs::field_ptr!(this, #members), + (#marker::bind(::libcc2rs::field_ptr!(src, #members)),), + );)* + } + } + }; + } quote! { impl #impl_generics #tr for #name #ty_generics #where_clause { fn #method(this: ::libcc2rs::Ptr, src: #src_ty) #ret { diff --git a/libcc2rs-macros/src/conversions.rs b/libcc2rs-macros/src/conversions.rs new file mode 100644 index 0000000000..e4d9a800f8 --- /dev/null +++ b/libcc2rs-macros/src/conversions.rs @@ -0,0 +1,297 @@ +// 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::parse::{Parse, ParseStream}; +use syn::punctuated::Punctuated; +use syn::{DeriveInput, Ident, Token, Type, parse_macro_input}; + +// #[derive(Conversions)] +// #[conversions(copy, move)] +// #[constructor(constructor_1, explicit, LvalueRef>)] // explicit S(const W &) +// #[constructor(constructor_2, i32, LvalueRef, ParameterObject)] // S(int, T &, U) +// #[conversion_function(to_i32, LvalueRef>, i32)] // operator int() const +// #[conversion_function(to_t, LvalueRef, T, return_slot)] // operator T() +// pub struct S { ... } +// +// Implements libcc2rs::overload::Conversions for S, the table of its +// constructors and conversion functions, each naming the inherent method that +// holds its body, which libcc2rs resolves initializations against at run time. +// Each constructor also implements Constructor for its arguments, by calling +// its method, such that the copy, move and default constructors implement +// CopyConstructible, MoveConstructible and DefaultConstructible. copy and move +// say that S is copy or move constructible. Parameters, and the object +// parameter of a conversion function, are their Rust types, whose Parameter +// impls say how they are passed. A conversion function is an ordinary method, +// which returns its result, or writes it through its return slot with +// return_slot. ConversionsUnsafe is the same for the unsafe model. + +struct Constructor { + method: Ident, + is_explicit: bool, + params: Vec, +} + +impl Parse for Constructor { + fn parse(input: ParseStream) -> syn::Result { + let method = input.parse()?; + let mut is_explicit = false; + if input.parse::>()?.is_some() + && input.peek(Ident) + && input.fork().parse::()? == "explicit" + { + input.parse::()?; + is_explicit = true; + input.parse::>()?; + } + let params = Punctuated::::parse_terminated(input)?; + Ok(Constructor { + method, + is_explicit, + params: params.into_iter().collect(), + }) + } +} + +struct ConversionFunction { + method: Ident, + object: Type, + to: Type, + is_explicit: bool, + return_slot: bool, +} + +impl Parse for ConversionFunction { + fn parse(input: ParseStream) -> syn::Result { + let method = input.parse()?; + input.parse::()?; + let object = input.parse()?; + input.parse::()?; + let to = input.parse()?; + let (mut is_explicit, mut return_slot) = (false, false); + while input.parse::>()?.is_some() { + let flag: Ident = input.parse()?; + if flag == "explicit" { + is_explicit = true; + } else if flag == "return_slot" { + return_slot = true; + } else { + return Err(syn::Error::new( + flag.span(), + "expected `explicit` or `return_slot`", + )); + } + } + Ok(ConversionFunction { + method, + object, + to, + is_explicit, + return_slot, + }) + } +} + +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 self_ty = quote!(#name #ty_generics); + + let mut constructors = Vec::new(); + let mut functions = Vec::new(); + let (mut copy, mut moves) = (false, false); + for attr in &input.attrs { + let result = if attr.path().is_ident("constructor") { + attr.parse_args::() + .map(|c| constructors.push(c)) + } else if attr.path().is_ident("conversion_function") { + attr.parse_args::() + .map(|f| functions.push(f)) + } else if attr.path().is_ident("conversions") { + attr.parse_nested_meta(|meta| { + if meta.path.is_ident("copy") { + copy = true; + } else if meta.path.is_ident("move") { + moves = true; + } else { + return Err(meta.error("expected `copy` or `move`")); + } + Ok(()) + }) + } else { + Ok(()) + }; + if let Err(err) = result { + return err.to_compile_error().into(); + } + } + + let (trait_name, parameter, table_ty, cast, ptr_ty, arg) = if is_unsafe { + ( + quote!(::libcc2rs::overload::ConversionsUnsafe), + quote!(::libcc2rs::overload::ParameterUnsafe), + quote!(::libcc2rs::overload::Table<*mut ::std::ffi::c_void>), + format_ident!("cast"), + quote!(*mut Self), + quote!(args), + ) + } else { + ( + quote!(::libcc2rs::overload::Conversions), + quote!(::libcc2rs::overload::Parameter), + quote!(::libcc2rs::overload::Table<::libcc2rs::AnyPtr>), + format_ident!("downcast"), + quote!(::libcc2rs::Ptr), + quote!(&args), + ) + }; + let suffix = if is_unsafe { "Unsafe" } else { "" }; + let constructor = format_ident!("Constructor{}", suffix); + let copy_trait = format_ident!("CopyConstructible{}", suffix); + let move_trait = format_ident!("MoveConstructible{}", suffix); + let fn_kw = if is_unsafe { + quote!(unsafe fn) + } else { + quote!(fn) + }; + let table_of = |ty: &TokenStream2| quote!(<#ty as #trait_name>::table); + let param_of = |ty: &Type| quote!(<#ty as #parameter>::param()); + let bind = |ty: &Type, i: usize| quote!(<#ty as #parameter>::bind(#arg[#i])); + + let candidates = constructors.iter().map(|ctor| { + let method = &ctor.method; + let params = ctor.params.iter().map(param_of); + let values = ctor.params.iter().enumerate().map(|(i, ty)| bind(ty, i)); + let is_explicit = ctor.is_explicit; + quote! { + ::libcc2rs::overload::Candidate { + params: vec![#(#params),*], + is_explicit: #is_explicit, + result: None, + call: |to, args| { + #[allow(unused_unsafe)] + unsafe { <#self_ty>::#method(to.#cast::<#self_ty>(), #(#values),*) } + }, + } + } + }); + + let conversions = functions.iter().map(|function| { + let method = &function.method; + let to = &function.to; + let param = param_of(&function.object); + let result = table_of("e!(#to)); + let is_explicit = function.is_explicit; + let this = quote!(args[0].#cast::<#self_ty>()); + let to_ptr = quote!(to.#cast::<#to>()); + let body = if function.return_slot { + quote!(<#self_ty>::#method(#this, #to_ptr)) + } else { + quote!(#to_ptr.write(<#self_ty>::#method(#this))) + }; + quote! { + ::libcc2rs::overload::Candidate { + params: vec![#param], + is_explicit: #is_explicit, + result: Some(#result), + call: |to, args| { + #[allow(unused_unsafe)] + unsafe { #body } + }, + } + } + }); + + let impls = constructors.iter().map(|ctor| { + let method = &ctor.method; + let types = &ctor.params; + let names: Vec<_> = (0..types.len()).map(|i| format_ident!("a{}", i)).collect(); + quote! { + impl #impl_generics ::libcc2rs::#constructor<(#(#types,)*)> for #self_ty #where_clause { + #fn_kw constructor(this: #ptr_ty, (#(#names,)*): (#(#types,)*)) { + #[allow(unused_unsafe)] + unsafe { <#self_ty>::#method(this, #(#names),*) } + } + } + } + }); + + let lvalue_ref = format_ident!("LvalueRef{}", suffix); + let rvalue_ref = format_ident!("RvalueRef{}", suffix); + let copy_ref = quote!(::libcc2rs::#lvalue_ref<::libcc2rs::Const<#self_ty>>); + let move_ref = quote!(::libcc2rs::#rvalue_ref<#self_ty>); + let special = |trait_: &Ident, method: &str, reference: &TokenStream2, exists: bool| { + if !exists { + let message = format!("{} has no {}", name, method); + return quote!(|_, _| panic!(#message)); + } + let method = format_ident!("{}", method); + quote! { + |dst, src| { + #[allow(unused_unsafe)] + unsafe { + <#self_ty as ::libcc2rs::#trait_>::#method( + dst.#cast::<#self_ty>(), + <#reference>::bind(src.#cast::<#self_ty>()), + ) + } + } + } + }; + let copy_fn = special(©_trait, "copy_constructor", ©_ref, copy); + let move_fn = if moves { + special(&move_trait, "move_constructor", &move_ref, true) + } else { + special(©_trait, "copy_constructor", ©_ref, copy) + }; + let (storage, release) = if is_unsafe { + ( + quote!(|| ::std::boxed::Box::into_raw(::std::boxed::Box::new(unsafe { + <#self_ty as ::libcc2rs::ZeroInitializationUnsafe>::zero_init() + })) + .cast()), + quote!(|ptr| unsafe { + ::libcc2rs::DestructibleUnsafe::destroy(ptr.cast::<#self_ty>()); + drop(::std::boxed::Box::from_raw(ptr.cast::<#self_ty>())) + }), + ) + } else { + ( + quote!(|| ::libcc2rs::Ptr::alloc( + <#self_ty as ::libcc2rs::ZeroInitialization>::zero_init() + ) + .to_any()), + quote!(|ptr| { + let object = ptr.downcast::<#self_ty>(); + ::libcc2rs::Destructible::destroy(object.clone()); + object.delete() + }), + ) + }; + + let label = name.to_string(); + quote! { + #(#impls)* + + impl #impl_generics #trait_name for #self_ty #where_clause { + fn table() -> #table_ty { + ::libcc2rs::overload::Table { + id: ::std::any::TypeId::of::<#self_ty>(), + name: #label, + arithmetic: None, + storage: #storage, + release: #release, + copy: #copy_fn, + move_from: #move_fn, + constructors: vec![#(#candidates),*], + conversion_functions: vec![#(#conversions),*], + qualification_of: None, + } + } + } + } + .into() +} diff --git a/libcc2rs-macros/src/cpp_from.rs b/libcc2rs-macros/src/cpp_from.rs deleted file mode 100644 index 0f3d39bd1d..0000000000 --- a/libcc2rs-macros/src/cpp_from.rs +++ /dev/null @@ -1,198 +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 proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use syn::parse::{Parse, ParseStream}; -use syn::{DeriveInput, Ident, Token, Type, parse_macro_input}; - -// #[derive(CppFrom)] -// #[cpp_from(i32, new, value)] // S(int) -// #[cpp_from(T, new_2, ptr)] // S(const T &) -// #[cpp_from(T, new_3, mut_ptr)] // S(T &) -// #[cpp_from_move(T, new_4, ptr)] // S(T &&) -// #[cpp_into(i32, to_i32)] // operator int() const -// #[cpp_into(i64, to_i64, mut_ptr)] // operator long() -// pub struct S { ... } -// -// Implements libcc2rs::CppFrom for S with each converting constructor -// of S, and libcc2rs::CppFrom for each type S converts to with a -// conversion operator, such that the rules convert values as C++ does -// implicitly. `value` passes the pointee to the constructor, `ptr` the -// pointer and `mut_ptr` a mutable pointer. CppFromUnsafe is the same for the -// unsafe model. - -#[derive(Clone, Copy)] -enum Kind { - Value, - Ptr, - MutPtr, -} - -struct Conversion { - ty: Type, - method: Ident, - kind: Kind, -} - -impl Parse for Conversion { - fn parse(input: ParseStream) -> syn::Result { - let ty = input.parse()?; - input.parse::()?; - let method = input.parse()?; - let mut kind = Kind::Ptr; - if input.peek(Token![,]) { - input.parse::()?; - let spelled: Ident = input.parse()?; - kind = match spelled.to_string().as_str() { - "value" => Kind::Value, - "ptr" => Kind::Ptr, - "mut_ptr" => Kind::MutPtr, - _ => { - return Err(syn::Error::new( - spelled.span(), - "expected `value`, `ptr` or `mut_ptr`", - )); - } - }; - } - Ok(Conversion { ty, method, kind }) - } -} - -#[derive(Default)] -struct Source { - from: Option, - from_move: Option, -} - -fn ctor_call( - name: &Ident, - conversion: &Conversion, - is_unsafe: bool, - is_move: bool, -) -> TokenStream2 { - let method = &conversion.method; - let arg = match (conversion.kind, is_unsafe) { - (Kind::Value, true) => quote!((*src).clone()), - (Kind::Value, false) => quote!(::libcc2rs::copy_constructed(src)), - (Kind::MutPtr, true) if !is_move => quote!(src.cast_mut()), - (Kind::Ptr | Kind::MutPtr, _) => quote!(src), - }; - crate::initialization::construct(is_unsafe, name, method, arg) -} - -fn method(is_unsafe: bool, signature: TokenStream2, body: TokenStream2) -> TokenStream2 { - if is_unsafe { - quote! { unsafe #signature { unsafe { #body } } } - } else { - quote! { #signature { #body } } - } -} - -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 mut sources: Vec<(String, Source)> = Vec::new(); - let mut intos: Vec = Vec::new(); - for attr in &input.attrs { - let Some(attr_name) = attr.path().get_ident().map(ToString::to_string) else { - continue; - }; - let is_move = match attr_name.as_str() { - "cpp_from" => false, - "cpp_from_move" => true, - "cpp_into" => { - intos.push(attr.parse_args().expect("cpp_into(Type, method)")); - continue; - } - _ => continue, - }; - let conversion: Conversion = attr - .parse_args() - .expect("cpp_from(Type, method, value|ptr|mut_ptr)"); - let ty = &conversion.ty; - let key = quote!(#ty).to_string(); - let source = match sources.iter().position(|(k, _)| *k == key) { - Some(i) => &mut sources[i].1, - None => { - sources.push((key.clone(), Source::default())); - &mut sources.last_mut().unwrap().1 - } - }; - let slot = if is_move { - &mut source.from_move - } else { - &mut source.from - }; - assert!(slot.is_none(), "two conversions from {key}"); - *slot = Some(conversion); - } - - let tr = if is_unsafe { - quote!(::libcc2rs::CppFromUnsafe) - } else { - quote!(::libcc2rs::CppFrom) - }; - let pointer = |ty: &Type, is_mut: bool| { - if is_unsafe && is_mut { - quote!(*mut #ty) - } else if is_unsafe { - quote!(*const #ty) - } else { - quote!(::libcc2rs::Ptr<#ty>) - } - }; - - let from_impls = sources.iter().map(|(_, source)| { - let any = source.from.as_ref().or(source.from_move.as_ref()).unwrap(); - let ty = &any.ty; - let src = pointer(ty, false); - let from_body = match &source.from { - Some(conversion) => ctor_call(name, conversion, is_unsafe, false), - None => quote!(unreachable!("no conversion from an lvalue")), - }; - let from_fn = method(is_unsafe, quote!(fn cpp_from(src: #src) -> Self), from_body); - let move_fn = source.from_move.as_ref().map(|conversion| { - let src = pointer(ty, true); - method( - is_unsafe, - quote!(fn cpp_from_move(src: #src) -> Self), - ctor_call(name, conversion, is_unsafe, true), - ) - }); - quote! { - impl #impl_generics #tr<#ty> for #name #ty_generics #where_clause { - #from_fn - #move_fn - } - } - }); - - let into_impls = intos.iter().map(|conversion| { - let ty = &conversion.ty; - let op = &conversion.method; - let self_ty = quote!(#name #ty_generics); - let src = pointer(&syn::parse_quote!(#self_ty), false); - let body = if is_unsafe && matches!(conversion.kind, Kind::MutPtr) { - quote!(#name::#op(src.cast_mut())) - } else { - quote!(#name::#op(src)) - }; - let from_fn = method(is_unsafe, quote!(fn cpp_from(src: #src) -> Self), body); - quote! { - impl #impl_generics #tr<#self_ty> for #ty #where_clause { - #from_fn - } - } - }); - - quote! { - #(#from_impls)* - #(#into_impls)* - } - .into() -} diff --git a/libcc2rs-macros/src/initialization.rs b/libcc2rs-macros/src/initialization.rs index cc7eb3c7cf..91381d7acf 100644 --- a/libcc2rs-macros/src/initialization.rs +++ b/libcc2rs-macros/src/initialization.rs @@ -5,7 +5,7 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::quote; use syn::punctuated::Punctuated; -use syn::{Data, DeriveInput, Expr, Field, Fields, Ident, Index, Token, parse_macro_input}; +use syn::{Data, DeriveInput, Expr, Field, Fields, Index, Token, parse_macro_input}; // The zero-initialized value of `field`. An array, whose length is // not part of its type, has one array_len argument per dimension. @@ -68,26 +68,3 @@ pub fn expand_unsafe(input: TokenStream) -> TokenStream { } .into() } - -pub(crate) fn construct( - is_unsafe: bool, - name: &Ident, - method: &Ident, - args: TokenStream2, -) -> TokenStream2 { - if is_unsafe { - quote! {{ - let mut __v: Self = ::zero_init(); - #name::#method(&raw mut __v, #args); - __v - }} - } else { - quote! {{ - let __v: ::libcc2rs::Value = ::std::rc::Rc::new(::std::cell::RefCell::new( - ::zero_init(), - )); - #name::#method(::libcc2rs::AsPointer::as_pointer(&__v), #args); - ::std::rc::Rc::try_unwrap(__v).ok().unwrap().into_inner() - }} - } -} diff --git a/libcc2rs-macros/src/lib.rs b/libcc2rs-macros/src/lib.rs index 1c2779d9a9..4c2bebaf7f 100644 --- a/libcc2rs-macros/src/lib.rs +++ b/libcc2rs-macros/src/lib.rs @@ -6,7 +6,7 @@ use proc_macro::TokenStream; mod assign; mod byte_repr; mod constructor; -mod cpp_from; +mod conversions; mod destructor; mod fn_ptr_arg; mod goto; @@ -338,6 +338,19 @@ pub fn derive_default_initializable_unsafe(input: TokenStream) -> TokenStream { impls } +#[proc_macro_derive(Conversions, attributes(conversions, constructor, conversion_function))] +pub fn derive_conversions(input: TokenStream) -> TokenStream { + conversions::expand(input, false) +} + +#[proc_macro_derive( + ConversionsUnsafe, + attributes(conversions, constructor, conversion_function) +)] +pub fn derive_conversions_unsafe(input: TokenStream) -> TokenStream { + conversions::expand(input, true) +} + #[proc_macro_derive(Destructible, attributes(destroy))] pub fn derive_destructible(input: TokenStream) -> TokenStream { destructor::expand(input, false) @@ -348,13 +361,6 @@ pub fn derive_destructible_unsafe(input: TokenStream) -> TokenStream { destructor::expand(input, true) } -// #[derive(CppFrom)] -// #[cpp_from(i32, new, value)] -// #[cpp_into(i32, to_i32)] -// pub struct S { ... } -// -// Encodes the C++ converting construction and conversion operators in rules. - #[proc_macro_derive(PartiallyOrderedWith, attributes(three_way))] pub fn derive_partially_ordered_with(input: TokenStream) -> TokenStream { partially_ordered::expand(input, false) @@ -364,13 +370,3 @@ pub fn derive_partially_ordered_with(input: TokenStream) -> TokenStream { pub fn derive_partially_ordered_with_unsafe(input: TokenStream) -> TokenStream { partially_ordered::expand(input, true) } - -#[proc_macro_derive(CppFrom, attributes(cpp_from, cpp_from_move, cpp_into))] -pub fn derive_cpp_from(input: TokenStream) -> TokenStream { - cpp_from::expand(input, false) -} - -#[proc_macro_derive(CppFromUnsafe, attributes(cpp_from, cpp_from_move, cpp_into))] -pub fn derive_cpp_from_unsafe(input: TokenStream) -> TokenStream { - cpp_from::expand(input, true) -} diff --git a/libcc2rs-macros/tests/ui/reference_binding.stderr b/libcc2rs-macros/tests/ui/reference_binding.stderr index 2199d97ce9..d01738ce64 100644 --- a/libcc2rs-macros/tests/ui/reference_binding.stderr +++ b/libcc2rs-macros/tests/ui/reference_binding.stderr @@ -1,110 +1,110 @@ -error[E0277]: the trait bound `LvalueRef: From>>` is not satisfied +error[E0277]: the trait bound `libcc2rs::LvalueRef: From>>` is not satisfied --> tests/ui/reference_binding.rs:7:7 | 7 | r.into() - | ^^^^ the trait `From>>` is not implemented for `LvalueRef` + | ^^^^ the trait `From>>` is not implemented for `libcc2rs::LvalueRef` | = help: the following other types implement trait `From`: - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>>` - `LvalueRef>>` implements `From>` - `LvalueRef>>` implements `From>>` - `LvalueRef>>` implements `From>>` - = note: required for `LvalueRef>` to implement `Into>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>` + `libcc2rs::LvalueRef>>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>>` + = note: required for `libcc2rs::LvalueRef>` to implement `Into>` -error[E0277]: the trait bound `LvalueRef: From>>` is not satisfied +error[E0277]: the trait bound `libcc2rs::LvalueRef: From>>` is not satisfied --> tests/ui/reference_binding.rs:11:7 | 11 | r.into() - | ^^^^ the trait `From>>` is not implemented for `LvalueRef` + | ^^^^ the trait `From>>` is not implemented for `libcc2rs::LvalueRef` | = help: the following other types implement trait `From`: - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>>` - `LvalueRef>>` implements `From>` - `LvalueRef>>` implements `From>>` - `LvalueRef>>` implements `From>>` - = note: required for `LvalueRef>` to implement `Into>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>` + `libcc2rs::LvalueRef>>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>>` + = note: required for `libcc2rs::LvalueRef>` to implement `Into>` -error[E0277]: the trait bound `LvalueRef>: From>>>` is not satisfied +error[E0277]: the trait bound `libcc2rs::LvalueRef>: From>>>` is not satisfied --> tests/ui/reference_binding.rs:15:7 | 15 | r.into() - | ^^^^ the trait `From>>>` is not implemented for `LvalueRef>` + | ^^^^ the trait `From>>>` is not implemented for `libcc2rs::LvalueRef>` | = help: the following other types implement trait `From`: - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>>` - `LvalueRef>>` implements `From>` - `LvalueRef>>` implements `From>>` - `LvalueRef>>` implements `From>>` - = note: required for `LvalueRef>>` to implement `Into>>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>` + `libcc2rs::LvalueRef>>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>>` + = note: required for `libcc2rs::LvalueRef>>` to implement `Into>>` -error[E0277]: the trait bound `RvalueRef: From>>` is not satisfied +error[E0277]: the trait bound `libcc2rs::RvalueRef: From>>` is not satisfied --> tests/ui/reference_binding.rs:19:7 | 19 | r.into() - | ^^^^ the trait `From>>` is not implemented for `RvalueRef` + | ^^^^ the trait `From>>` is not implemented for `libcc2rs::RvalueRef` | = help: the following other types implement trait `From`: - `RvalueRef>` implements `From>` - `RvalueRef>` implements `From>` - `RvalueRef>>` implements `From>` - `RvalueRef>>` implements `From>>` - `RvalueRef>>` implements `From>>` - = note: required for `RvalueRef>` to implement `Into>` + `libcc2rs::RvalueRef>` implements `From>` + `libcc2rs::RvalueRef>` implements `From>` + `libcc2rs::RvalueRef>>` implements `From>` + `libcc2rs::RvalueRef>>` implements `From>>` + `libcc2rs::RvalueRef>>` implements `From>>` + = note: required for `libcc2rs::RvalueRef>` to implement `Into>` -error[E0277]: the trait bound `RvalueRef: From>` is not satisfied +error[E0277]: the trait bound `libcc2rs::RvalueRef: From>` is not satisfied --> tests/ui/reference_binding.rs:23:7 | 23 | r.into() - | ^^^^ the trait `From>` is not implemented for `RvalueRef` + | ^^^^ the trait `From>` is not implemented for `libcc2rs::RvalueRef` | = help: the following other types implement trait `From`: - `RvalueRef>` implements `From>` - `RvalueRef>` implements `From>` - `RvalueRef>>` implements `From>` - `RvalueRef>>` implements `From>>` - `RvalueRef>>` implements `From>>` - = note: required for `LvalueRef` to implement `Into>` + `libcc2rs::RvalueRef>` implements `From>` + `libcc2rs::RvalueRef>` implements `From>` + `libcc2rs::RvalueRef>>` implements `From>` + `libcc2rs::RvalueRef>>` implements `From>>` + `libcc2rs::RvalueRef>>` implements `From>>` + = note: required for `libcc2rs::LvalueRef` to implement `Into>` -error[E0277]: the trait bound `LvalueRef: From>` is not satisfied +error[E0277]: the trait bound `libcc2rs::LvalueRef: From>` is not satisfied --> tests/ui/reference_binding.rs:27:7 | 27 | r.into() - | ^^^^ the trait `From>` is not implemented for `LvalueRef` + | ^^^^ the trait `From>` is not implemented for `libcc2rs::LvalueRef` | = help: the following other types implement trait `From`: - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>>` - `LvalueRef>>` implements `From>` - `LvalueRef>>` implements `From>>` - `LvalueRef>>` implements `From>>` - = note: required for `RvalueRef` to implement `Into>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>` + `libcc2rs::LvalueRef>>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>>` + = note: required for `libcc2rs::RvalueRef` to implement `Into>` -error[E0277]: the trait bound `LvalueRef>>: From>` is not satisfied +error[E0277]: the trait bound `libcc2rs::LvalueRef>>: From>` is not satisfied --> tests/ui/reference_binding.rs:33:7 | 33 | r.into() - | ^^^^ the trait `From>` is not implemented for `LvalueRef>>` + | ^^^^ the trait `From>` is not implemented for `libcc2rs::LvalueRef>>` | = help: the following other types implement trait `From`: - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>` - `LvalueRef>` implements `From>>` - `LvalueRef>>` implements `From>` - `LvalueRef>>` implements `From>>` - `LvalueRef>>` implements `From>>` - = note: required for `RvalueRef` to implement `Into>>>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>` + `libcc2rs::LvalueRef>>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>>` + = note: required for `libcc2rs::RvalueRef` to implement `Into>>>` error[E0277]: the trait bound `LvalueRefUnsafe: From>>` is not satisfied --> tests/ui/reference_binding.rs:37:7 diff --git a/libcc2rs/src/capture.rs b/libcc2rs/src/capture.rs index 205736033d..a0cbaea9a4 100644 --- a/libcc2rs/src/capture.rs +++ b/libcc2rs/src/capture.rs @@ -94,9 +94,11 @@ pub trait CopyLambda { impl CopyLambda>> for &&&Capture<'_, Value>> { fn copy_capture(&self) -> Value> { let dst: Value> = Rc::new(RefCell::new(FnPtr::zero_init())); - CopyConstructible::copy_constructor( + as crate::Constructor<(crate::LvalueRef>>,)>>::constructor( AsPointer::>::as_pointer(&dst), - crate::LvalueRef::bind(AsPointer::>::as_pointer(self.0)), + (crate::LvalueRef::bind(AsPointer::>::as_pointer( + self.0, + )),), ); dst } @@ -126,9 +128,9 @@ pub trait CopyCtor { impl CopyCtor> for &Capture<'_, Value> { fn copy_capture(&self) -> Value { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - T::copy_constructor( + >,)>>::constructor( AsPointer::::as_pointer(&dst), - crate::LvalueRef::bind(AsPointer::::as_pointer(self.0)), + (crate::LvalueRef::bind(AsPointer::::as_pointer(self.0)),), ); dst } @@ -151,9 +153,9 @@ pub trait MoveWithCtor { impl MoveWithCtor> for &&Capture<'_, Value> { fn move_capture(&self) -> Value { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - T::move_constructor( + ,)>>::constructor( AsPointer::::as_pointer(&dst), - crate::RvalueRef::bind(AsPointer::::as_pointer(self.0)), + (crate::RvalueRef::bind(AsPointer::::as_pointer(self.0)),), ); dst } @@ -228,9 +230,11 @@ impl CopyLambdaUnsafe> for &&&CaptureUnsafe> { unsafe fn copy_capture(&self) -> FnPtr { let mut dst = std::mem::MaybeUninit::>::uninit(); unsafe { - CopyConstructibleUnsafe::copy_constructor( - dst.as_mut_ptr(), - crate::LvalueRefUnsafe::bind(self.0), + as crate::ConstructorUnsafe<( + crate::LvalueRefUnsafe>>, + )>>::constructor( + &mut *dst.as_mut_ptr(), + (crate::LvalueRefUnsafe::bind(self.0),), ); dst.assume_init() } @@ -255,7 +259,7 @@ impl CopyCtorUnsafe for &CaptureUnsafe { unsafe fn copy_capture(&self) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - T::copy_constructor(dst.as_mut_ptr(), crate::LvalueRefUnsafe::bind(self.0)); + >,)>>::constructor(&mut *dst.as_mut_ptr(), (crate::LvalueRefUnsafe::bind(self.0),)); dst.assume_init() } } @@ -279,7 +283,10 @@ impl MoveWithCtorUnsafe for &&CaptureUnsafe { unsafe fn move_capture(&self) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - T::move_constructor(dst.as_mut_ptr(), crate::RvalueRefUnsafe::bind(self.0)); + ,)>>::constructor( + &mut *dst.as_mut_ptr(), + (crate::RvalueRefUnsafe::bind(self.0),), + ); dst.assume_init() } } diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index 231b9f4bef..2fcbe074f7 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -4,15 +4,18 @@ use crate::capture::{ Destructible, DestructibleUnsafe, TriviallyDestructible, TriviallyDestructibleUnsafe, }; +use crate::conversion::{Constructor, ConstructorUnsafe}; use crate::fn_ptr::{FnPtr, FnSig}; use crate::initialization::ZeroInitialization; use crate::rc::{AsPointer, Ptr, Value}; -use crate::reference::{Const, LvalueRef, RvalueRef}; +use crate::reference::{Const, LvalueRef, LvalueRefUnsafe, RvalueRef, RvalueRefUnsafe}; use crate::reinterpret::ByteRepr; use crate::void::AnyPtr; -pub trait DefaultConstructible: Sized { - fn default_constructor(this: Ptr); +pub trait DefaultConstructible: Constructor<()> + Sized { + fn default_constructor(this: Ptr) { + >::constructor(this, ()) + } // TODO: remove default_constructed. fn default_constructed() -> Self @@ -20,14 +23,19 @@ pub trait DefaultConstructible: Sized { Self: ZeroInitialization, { let dst: Value = std::rc::Rc::new(std::cell::RefCell::new(Self::zero_init())); - Self::default_constructor(AsPointer::::as_pointer(&dst)); + Self::constructor(AsPointer::::as_pointer(&dst), ()); std::rc::Rc::try_unwrap(dst).ok().unwrap().into_inner() } } -pub trait MoveConstructible: ByteRepr + Sized { - fn move_constructor(this: Ptr, src: RvalueRef); +impl> DefaultConstructible for T {} + +pub trait MoveConstructible: Constructor<(RvalueRef,)> + ByteRepr + Sized { + fn move_constructor(this: Ptr, src: RvalueRef) { + ,)>>::constructor(this, (src,)) + } + // TODO: remove me. // Pushes to the vector that v points to an element that the move // constructor constructs in place from src. A type that moves by Clone, or // by take, pushes the moved value. @@ -39,17 +47,25 @@ pub trait MoveConstructible: ByteRepr + Sized { elems.push(Self::zero_init()); elems.len() - 1 }); - Self::move_constructor(v.decay().offset(i), RvalueRef::bind(src)); + ,)>>::constructor( + v.decay().offset(i), + (RvalueRef::bind(src),), + ); } } +impl,)> + ByteRepr> MoveConstructible for T {} + pub trait TriviallyMoveConstructible: MoveConstructible { fn trivial_move(src: &mut Self) -> Self; } -pub trait CopyConstructible: MoveConstructible { - fn copy_constructor(this: Ptr, src: LvalueRef>); +pub trait CopyConstructible: MoveConstructible + Constructor<(LvalueRef>,)> { + fn copy_constructor(this: Ptr, src: LvalueRef>) { + >,)>>::constructor(this, (src,)) + } + // TODO: remove me. // A copy of the value that src points to, made by the copy constructor, // which a type with Clone clones. fn copied(src: Ptr) -> Self @@ -59,6 +75,7 @@ pub trait CopyConstructible: MoveConstructible { crate::swap::copy_constructed_in_storage(src) } + // TODO: remove me. // Pushes to the vector that v points to an element that the copy // constructor constructs in place from src. A type with Clone pushes a // clone. @@ -70,9 +87,13 @@ pub trait CopyConstructible: MoveConstructible { elems.push(Self::zero_init()); elems.len() - 1 }); - Self::copy_constructor(v.decay().offset(i), LvalueRef::bind(src)); + >,)>>::constructor( + v.decay().offset(i), + (LvalueRef::bind(src),), + ); } + // TODO: remove me. // A copy of the elements of the vector that src points to, made by the // copy constructor, which a type with Clone clones. fn copied_elems(src: &Ptr>) -> Vec @@ -85,6 +106,8 @@ pub trait CopyConstructible: MoveConstructible { } } +impl>,)>> CopyConstructible for T {} + pub trait TriviallyCopyConstructible: CopyConstructible { fn trivial_copy(src: &Self) -> Self; } @@ -138,34 +161,50 @@ impl< { } -pub trait DefaultConstructibleUnsafe { +pub trait DefaultConstructibleUnsafe: ConstructorUnsafe<()> + Sized { /// # Safety - /// `self` must be valid for writes. - unsafe fn default_constructor(this: *mut Self); + /// `this` is storage for an object. + unsafe fn default_constructor(this: *mut Self) { + unsafe { >::constructor(this, ()) } + } // TODO: remove default_constructed. - fn default_constructed() -> Self - where - Self: Sized, - { + fn default_constructed() -> Self { let mut dst = std::mem::MaybeUninit::::zeroed(); unsafe { - Self::default_constructor(dst.as_mut_ptr()); + Self::constructor(dst.as_mut_ptr(), ()); dst.assume_init() } } } -pub trait MoveConstructibleUnsafe: Sized { +impl> DefaultConstructibleUnsafe for T {} + +pub trait MoveConstructibleUnsafe: ConstructorUnsafe<(RvalueRefUnsafe,)> + Sized { /// # Safety - /// `src` must point to a live value. - unsafe fn move_constructor(this: *mut Self, src: crate::RvalueRefUnsafe); + /// `this` is storage for an object, and `src` refers to a live object. + unsafe fn move_constructor(this: *mut Self, src: RvalueRefUnsafe) { + unsafe { ,)>>::constructor(this, (src,)) } + } } -pub trait CopyConstructibleUnsafe: MoveConstructibleUnsafe { +impl,)>> MoveConstructibleUnsafe for T {} + +pub trait CopyConstructibleUnsafe: + MoveConstructibleUnsafe + ConstructorUnsafe<(LvalueRefUnsafe>,)> +{ /// # Safety - /// `src` must point to a live value. - unsafe fn copy_constructor(this: *mut Self, src: crate::LvalueRefUnsafe>); + /// `this` is storage for an object, and `src` refers to a live object. + unsafe fn copy_constructor(this: *mut Self, src: LvalueRefUnsafe>) { + unsafe { + >,)>>::constructor(this, (src,)) + } + } +} + +impl>,)>> + CopyConstructibleUnsafe for T +{ } pub trait TriviallyMoveConstructibleUnsafe: MoveConstructibleUnsafe { @@ -244,29 +283,58 @@ impl< { } -macro_rules! impl_copy_by_clone { +macro_rules! impl_copy_construct_by_clone { ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( - impl<$($param),*> $crate::CopyConstructible for $ty + impl<$($param),*> $crate::Constructor<($crate::LvalueRef<$crate::Const>,)> for $ty where $ty: Clone + $crate::ByteRepr, { - fn copy_constructor(this: $crate::Ptr, src: $crate::LvalueRef<$crate::Const>) { + fn constructor(this: $crate::Ptr, (src,): ($crate::LvalueRef<$crate::Const>,)) { this.write(src.as_pointer().with(Self::clone)); } +} - fn copied(src: $crate::Ptr) -> Self { - src.with(Self::clone) + impl<$($param),*> $crate::ConstructorUnsafe<($crate::LvalueRefUnsafe<$crate::Const>,)> for $ty + where + $ty: Clone, + { + unsafe fn constructor(this: *mut Self, (src,): ($crate::LvalueRefUnsafe<$crate::Const>,)) { + let src = src.as_const_ptr(); + unsafe { std::ptr::write(this, (*src).clone()) } } +} + )*}; +} +pub(crate) use impl_copy_construct_by_clone; - fn copied_elems(src: &$crate::Ptr>) -> Vec { - src.with(|elems| elems.clone()) +macro_rules! impl_move_construct_by_clone { + ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( + impl<$($param),*> $crate::Constructor<($crate::RvalueRef,)> for $ty + where + $ty: Clone + $crate::ByteRepr, + { + fn constructor(this: $crate::Ptr, (src,): ($crate::RvalueRef,)) { + this.write(src.as_pointer().with(Self::clone)); } +} - fn push_copied(v: &$crate::Ptr>, src: $crate::Ptr) { - let value = src.with(Self::clone); - v.with_mut(|elems| elems.push(value)); + impl<$($param),*> $crate::ConstructorUnsafe<($crate::RvalueRefUnsafe,)> for $ty + where + $ty: Clone, + { + unsafe fn constructor(this: *mut Self, (src,): ($crate::RvalueRefUnsafe,)) { + let src = src.as_ptr(); + unsafe { std::ptr::write(this, (*src).clone()) } } - } +} + )*}; +} +pub(crate) use impl_move_construct_by_clone; + +macro_rules! impl_copy_by_clone { + ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( + + impl<$($param),*> $crate::CopyAssignable for $ty where @@ -278,15 +346,7 @@ macro_rules! impl_copy_by_clone { } } - impl<$($param),*> $crate::CopyConstructibleUnsafe for $ty - where - $ty: Clone, - { - unsafe fn copy_constructor(this: *mut Self, src: $crate::LvalueRefUnsafe<$crate::Const>) { - let src = src.as_const_ptr(); - unsafe { std::ptr::write(this, (*src).clone()) } - } - } + impl<$($param),*> $crate::CopyAssignableUnsafe for $ty where @@ -304,19 +364,8 @@ 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::RvalueRef) { - this.write(src.as_pointer().with(Self::clone)); - } - fn push_moved(v: &$crate::Ptr>, src: $crate::Ptr) { - let value = src.with(Self::clone); - v.with_mut(|elems| elems.push(value)); - } - } + impl<$($param),*> $crate::MoveAssignable for $ty where @@ -328,15 +377,7 @@ macro_rules! impl_move_by_clone { } } - impl<$($param),*> $crate::MoveConstructibleUnsafe for $ty - where - $ty: Clone, - { - unsafe fn move_constructor(this: *mut Self, src: $crate::RvalueRefUnsafe) { - let src = src.as_ptr(); - unsafe { std::ptr::write(this, (*src).clone()) } - } - } + impl<$($param),*> $crate::MoveAssignableUnsafe for $ty where @@ -446,6 +487,8 @@ pub(crate) use impl_trivially_copyable_by_clone; macro_rules! impl_trivial_copy_move { ($(<$($param:ident),*> $ty:ty),* $(,)?) => { + $crate::constructor::impl_copy_construct_by_clone!($(<$($param),*> $ty),*); + $crate::constructor::impl_move_construct_by_clone!($(<$($param),*> $ty),*); $crate::constructor::impl_copy_by_clone!($(<$($param),*> $ty),*); $crate::constructor::impl_move_by_clone!($(<$($param),*> $ty),*); $crate::constructor::impl_trivially_copyable_by_clone!($(<$($param),*> $ty),*); @@ -459,20 +502,16 @@ 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 + impl<$($param),*> $crate::Constructor<($crate::RvalueRef,)> for $ty where $ty: Default + $crate::ByteRepr, { - fn move_constructor(this: $crate::Ptr, src: $crate::RvalueRef) { + fn constructor(this: $crate::Ptr, (src,): ($crate::RvalueRef,)) { let value = src.as_pointer().with_mut(std::mem::take); this.with_mut(|dst| *dst = value); } +} - fn push_moved(v: &$crate::Ptr>, src: $crate::Ptr) { - let value = src.with_mut(std::mem::take); - v.with_mut(|elems| elems.push(value)); - } - } impl<$($param),*> $crate::MoveAssignable for $ty where @@ -485,15 +524,16 @@ macro_rules! impl_move_by_take { } } - impl<$($param),*> $crate::MoveConstructibleUnsafe for $ty + impl<$($param),*> $crate::ConstructorUnsafe<($crate::RvalueRefUnsafe,)> for $ty where $ty: Default, { - unsafe fn move_constructor(this: *mut Self, src: $crate::RvalueRefUnsafe) { + unsafe fn constructor(this: *mut Self, (src,): ($crate::RvalueRefUnsafe,)) { let src = src.as_ptr(); unsafe { std::ptr::write(this, std::mem::take(&mut *src)) } } - } +} + impl<$($param),*> $crate::MoveAssignableUnsafe for $ty where @@ -526,11 +566,12 @@ pub(crate) use impl_move_by_take; macro_rules! impl_default_by_zeroed { ($($ty:ty),* $(,)?) => {$( - impl $crate::DefaultConstructibleUnsafe for $ty { - unsafe fn default_constructor(this: *mut Self) { + impl $crate::ConstructorUnsafe<()> for $ty { + unsafe fn constructor(this: *mut Self, _: ()) { unsafe { std::ptr::write(this, std::mem::zeroed()) } } - } +} + impl $crate::TriviallyDefaultConstructibleUnsafe for $ty {} )*}; @@ -539,25 +580,27 @@ pub(crate) use impl_default_by_zeroed; macro_rules! impl_trivially_default_constructible { ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( - impl<$($param),*> DefaultConstructible for $ty + impl<$($param),*> Constructor<()> for $ty where $ty: Default + ByteRepr, { - fn default_constructor(this: Ptr) { + fn constructor(this: Ptr, _: ()) { this.write(Self::default()); } - } +} + impl<$($param),*> TriviallyDefaultConstructible for $ty where $ty: Default + ByteRepr {} - impl<$($param),*> DefaultConstructibleUnsafe for $ty + impl<$($param),*> ConstructorUnsafe<()> for $ty where $ty: Default, { - unsafe fn default_constructor(this: *mut Self) { + unsafe fn constructor(this: *mut Self, _: ()) { unsafe { std::ptr::write(this, Self::default()) } } - } +} + impl<$($param),*> TriviallyDefaultConstructibleUnsafe for $ty where $ty: Default {} )*}; @@ -599,45 +642,44 @@ impl TriviallyDefaultConstructibleUnsafe for *mut T {} impl TriviallyDefaultConstructibleUnsafe for *const T {} -impl DefaultConstructible for FnPtr { - fn default_constructor(this: Ptr) { +impl Constructor<()> for FnPtr { + fn constructor(this: Ptr, _: ()) { this.with_mut(|dst| *dst = ::zero_init()); } } -impl DefaultConstructibleUnsafe for FnPtr { - unsafe fn default_constructor(this: *mut Self) { +impl ConstructorUnsafe<()> for FnPtr { + unsafe fn constructor(this: *mut Self, _: ()) { unsafe { std::ptr::write(this, ::zero_init()) } } } -impl DefaultConstructible for Box<[T]> { - fn default_constructor(this: Ptr) { +impl Constructor<()> for Box<[T]> { + fn constructor(this: Ptr, _: ()) { let len = this.with(|elems| elems.len()); let dst = this.decay(); for i in 0..len { - T::default_constructor(dst.offset(i)); + >::constructor(dst.offset(i), ()); } } } -impl DefaultConstructibleUnsafe for [T; N] { - unsafe fn default_constructor(this: *mut Self) { - let this = this as *mut T; - for i in 0..N { - unsafe { T::default_constructor(this.add(i)) } +impl ConstructorUnsafe<()> for [T; N] { + unsafe fn constructor(this: *mut Self, _: ()) { + for elem in unsafe { (*this).iter_mut() } { + unsafe { >::constructor(elem, ()) } } } } -impl DefaultConstructibleUnsafe for *mut T { - unsafe fn default_constructor(this: *mut Self) { +impl ConstructorUnsafe<()> for *mut T { + unsafe fn constructor(this: *mut Self, _: ()) { unsafe { std::ptr::write(this, std::ptr::null_mut()) } } } -impl DefaultConstructibleUnsafe for *const T { - unsafe fn default_constructor(this: *mut Self) { +impl ConstructorUnsafe<()> for *const T { + unsafe fn constructor(this: *mut Self, _: ()) { unsafe { std::ptr::write(this, std::ptr::null()) } } } @@ -668,6 +710,8 @@ impl_trivial_copy_move!( Ptr, *mut T, *const T); // TODO: copy and move a pair memberwise, with the copy and move members of // A and B, and then remove Clone from LvalueRef and RvalueRef. +impl_copy_construct_by_clone!( (A, B)); +impl_move_construct_by_clone!( (A, B)); impl_copy_by_clone!( (A, B)); impl_move_by_clone!( (A, B)); @@ -745,13 +789,15 @@ where { } -impl Destructible for (A, B) { +// TODO: destroy the members; this destructor does nothing. +impl Destructible for (A, B) { fn destroy(_this: Ptr) {} } impl TriviallyDestructible for (A, B) {} -impl DestructibleUnsafe for (A, B) { +// TODO: destroy the members; this destructor does nothing. +impl DestructibleUnsafe for (A, B) { unsafe fn destroy(_this: *mut Self) {} } @@ -760,8 +806,8 @@ impl TriviallyDe { } -impl MoveConstructible for FnPtr { - fn move_constructor(this: Ptr, src: RvalueRef) { +impl Constructor<(RvalueRef,)> for FnPtr { + fn constructor(this: Ptr, (src,): (RvalueRef,)) { let value = src.as_pointer().with(FnPtr::move_from); this.with_mut(|dst| *dst = value); } @@ -773,8 +819,8 @@ impl TriviallyMoveConstructible for FnPtr { } } -impl CopyConstructible for FnPtr { - fn copy_constructor(this: Ptr, src: LvalueRef>) { +impl Constructor<(LvalueRef>,)> for FnPtr { + fn constructor(this: Ptr, (src,): (LvalueRef>,)) { let value = src.as_pointer().with(FnPtr::copy_from); this.with_mut(|dst| *dst = value); } @@ -788,8 +834,8 @@ impl TriviallyCopyConstructible for FnPtr { impl MoveAssignable for FnPtr { fn move_assign(this: Ptr, src: RvalueRef) -> Ptr { - ::move_constructor(this.clone(), src); - this + ,)>>::constructor(this.clone(), (src,)); + this.clone() } } @@ -797,8 +843,8 @@ impl TriviallyMoveAssignable for FnPtr {} impl CopyAssignable for FnPtr { fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { - ::copy_constructor(this.clone(), src); - this + >,)>>::constructor(this.clone(), (src,)); + this.clone() } } @@ -816,15 +862,15 @@ impl SwappableUnsafe for FnPtr { } } -impl MoveConstructibleUnsafe for FnPtr { - unsafe fn move_constructor(this: *mut Self, src: crate::RvalueRefUnsafe) { +impl ConstructorUnsafe<(RvalueRefUnsafe,)> for FnPtr { + unsafe fn constructor(this: *mut Self, (src,): (crate::RvalueRefUnsafe,)) { let src = src.as_ptr(); unsafe { std::ptr::write(this, (*src).move_from()) } } } -impl CopyConstructibleUnsafe for FnPtr { - unsafe fn copy_constructor(this: *mut Self, src: crate::LvalueRefUnsafe>) { +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for FnPtr { + unsafe fn constructor(this: *mut Self, (src,): (crate::LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); unsafe { std::ptr::write(this, (*src).copy_from()) } } @@ -891,10 +937,12 @@ fn assign_elems( this.clone() } -impl MoveConstructible for Box<[T]> { - fn move_constructor(this: Ptr, src: RvalueRef) { +impl Constructor<(RvalueRef,)> + for Box<[T]> +{ + fn constructor(this: Ptr, (src,): (RvalueRef,)) { construct_elems(&this, &src.as_pointer(), |dst, src| { - T::move_constructor(dst, RvalueRef::bind(src)) + ,)>>::constructor(dst, (RvalueRef::bind(src),)) }); } } @@ -907,10 +955,12 @@ impl TriviallyMov } } -impl CopyConstructible for Box<[T]> { - fn copy_constructor(this: Ptr, src: LvalueRef>) { +impl Constructor<(LvalueRef>,)> + for Box<[T]> +{ + fn constructor(this: Ptr, (src,): (LvalueRef>,)) { construct_elems(&this, &src.as_pointer(), |dst, src| { - T::copy_constructor(dst, LvalueRef::bind(src)) + >,)>>::constructor(dst, (LvalueRef::bind(src),)) }); } } @@ -963,24 +1013,36 @@ impl SwappableUnsafe for [T; N] { } } -impl MoveConstructibleUnsafe for [T; N] { - unsafe fn move_constructor(this: *mut Self, src: crate::RvalueRefUnsafe) { +impl ConstructorUnsafe<(RvalueRefUnsafe,)> + for [T; N] +{ + unsafe fn constructor(this: *mut Self, (src,): (crate::RvalueRefUnsafe,)) { let src = src.as_ptr(); let src = src as *mut T; - let this = this as *mut T; - for i in 0..N { - unsafe { T::move_constructor(this.add(i), crate::RvalueRefUnsafe::bind(src.add(i))) } + for (i, elem) in unsafe { (*this).iter_mut() }.enumerate() { + unsafe { + ,)>>::constructor( + elem, + (RvalueRefUnsafe::bind(src.add(i)),), + ) + } } } } -impl CopyConstructibleUnsafe for [T; N] { - unsafe fn copy_constructor(this: *mut Self, src: crate::LvalueRefUnsafe>) { +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> + for [T; N] +{ + unsafe fn constructor(this: *mut Self, (src,): (crate::LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); let src = src as *const T; - let this = this as *mut T; - for i in 0..N { - unsafe { T::copy_constructor(this.add(i), crate::LvalueRefUnsafe::bind(src.add(i))) } + for (i, elem) in unsafe { (*this).iter_mut() }.enumerate() { + unsafe { + >,)>>::constructor( + elem, + (LvalueRefUnsafe::bind(src.add(i)),), + ) + } } } } @@ -1007,9 +1069,8 @@ impl MoveAssignableUnsafe for [T; N] { unsafe fn move_assign(this: *mut Self, src: crate::RvalueRefUnsafe) -> *mut Self { let src = src.as_ptr(); let src = src as *mut T; - let dst = this as *mut T; - for i in 0..N { - unsafe { T::move_assign(dst.add(i), crate::RvalueRefUnsafe::bind(src.add(i))) }; + for (i, elem) in unsafe { (*this).iter_mut() }.enumerate() { + unsafe { T::move_assign(elem, crate::RvalueRefUnsafe::bind(src.add(i))) }; } this } @@ -1022,9 +1083,8 @@ impl CopyAssignableUnsafe for [T; N] { ) -> *mut Self { let src = src.as_const_ptr(); let src = src as *const T; - let dst = this as *mut T; - for i in 0..N { - unsafe { T::copy_assign(dst.add(i), crate::LvalueRefUnsafe::bind(src.add(i))) }; + for (i, elem) in unsafe { (*this).iter_mut() }.enumerate() { + unsafe { T::copy_assign(elem, crate::LvalueRefUnsafe::bind(src.add(i))) }; } this } diff --git a/libcc2rs/src/conversion.rs b/libcc2rs/src/conversion.rs index c8e9ae87c9..3fc3fd5640 100644 --- a/libcc2rs/src/conversion.rs +++ b/libcc2rs/src/conversion.rs @@ -1,47 +1,17 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +use crate::capture::{Destructible, DestructibleUnsafe}; use crate::rc::Ptr; -pub trait CppFrom: Sized { - fn cpp_from(src: Ptr) -> Self; - - fn cpp_from_move(src: Ptr) -> Self { - Self::cpp_from(src) - } +pub trait Constructor: Destructible { + fn constructor(this: Ptr, args: Args); } -pub trait CppFromUnsafe: Sized { - /// # Safety - /// `src` must point to a live value. - unsafe fn cpp_from(src: *const S) -> Self; - +pub trait ConstructorUnsafe: DestructibleUnsafe { /// # Safety - /// `src` must point to a live value. - unsafe fn cpp_from_move(src: *mut S) -> Self { - unsafe { Self::cpp_from(src) } - } -} - -// The construction of a T from a T, by its copy or move constructor. -impl CppFrom for T { - fn cpp_from(src: Ptr) -> T { - crate::copy_constructed(src) - } - - fn cpp_from_move(src: Ptr) -> T { - crate::move_constructed(&src) - } -} - -impl CppFromUnsafe for T { - unsafe fn cpp_from(src: *const T) -> T { - unsafe { crate::copy_constructed_unsafe(src) } - } - - unsafe fn cpp_from_move(src: *mut T) -> T { - unsafe { crate::move_constructed_unsafe(src) } - } + /// `self` is storage for an object, and `args` refer to live objects. + unsafe fn constructor(this: *mut Self, args: Args); } #[macro_export] diff --git a/libcc2rs/src/fn_ptr_arg.rs b/libcc2rs/src/fn_ptr_arg.rs index 7295e67798..98dd6d47a1 100644 --- a/libcc2rs/src/fn_ptr_arg.rs +++ b/libcc2rs/src/fn_ptr_arg.rs @@ -104,6 +104,16 @@ impl FnPtrArg for Ptr { } } +impl FnPtrArg for crate::ParameterObject { + #[inline] + fn to_repr(self) -> ArgRepr { + self.as_pointer().to_repr() + } + fn from_repr(r: ArgRepr) -> Self { + Self::bind(Ptr::from_repr(r)) + } +} + impl FnPtrArg for AnyPtr { #[inline] fn to_repr(self) -> ArgRepr { @@ -129,6 +139,16 @@ impl FnPtrArg for Box<[VaArg]> { } } +impl FnPtrArg for crate::ParameterObjectUnsafe { + #[inline] + fn to_repr(self) -> ArgRepr { + self.as_ptr().to_repr() + } + fn from_repr(r: ArgRepr) -> Self { + Self::bind(<*mut T>::from_repr(r)) + } +} + impl FnPtrArg for *mut T { #[inline] fn to_repr(self) -> ArgRepr { diff --git a/libcc2rs/src/initialization.rs b/libcc2rs/src/initialization.rs index a6eb1f4e2c..926f4a0197 100644 --- a/libcc2rs/src/initialization.rs +++ b/libcc2rs/src/initialization.rs @@ -48,6 +48,66 @@ impl_zero_init!( f64, ); +macro_rules! impl_zero_init_unsafe_by_default { + ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( + impl<$($param),*> ZeroInitializationUnsafe for $ty { + #[inline] + unsafe fn zero_init() -> Self { + Default::default() + } + } + )*}; +} + +impl_zero_init_unsafe_by_default!( + <> (), + <> bool, + <> u8, + <> i8, + <> u16, + <> i16, + <> u32, + <> i32, + <> u64, + <> i64, + <> u128, + <> i128, + <> usize, + <> isize, + <> f32, + <> f64, + Vec, + Option, +); + +impl ZeroInitializationUnsafe for (A, B) { + #[inline] + unsafe fn zero_init() -> Self { + unsafe { (A::zero_init(), B::zero_init()) } + } +} + +impl ZeroInitializationUnsafe for *mut T { + #[inline] + unsafe fn zero_init() -> Self { + std::ptr::null_mut() + } +} + +impl ZeroInitializationUnsafe for *const T { + #[inline] + unsafe fn zero_init() -> Self { + std::ptr::null() + } +} + +impl ZeroInitialization for std::cmp::Ordering { + #[inline] + fn zero_init() -> Self { + std::cmp::Ordering::Equal + } +} + impl ZeroInitialization for Option { #[inline] fn zero_init() -> Self { diff --git a/libcc2rs/src/lib.rs b/libcc2rs/src/lib.rs index db2b0cbc10..171a021a11 100644 --- a/libcc2rs/src/lib.rs +++ b/libcc2rs/src/lib.rs @@ -65,7 +65,12 @@ mod reference; pub use reference::*; mod conversion; -pub use conversion::{CppFrom, CppFromUnsafe}; +pub mod overload; +pub use conversion::{Constructor, ConstructorUnsafe}; +pub use overload::{ + ConstructibleFrom, ConstructibleFromUnsafe, Conversions, ConversionsUnsafe, ConvertibleTo, + ConvertibleToUnsafe, +}; mod initialization; pub use initialization::{ZeroInitialization, ZeroInitializationUnsafe}; @@ -132,8 +137,8 @@ mod format; pub use format::*; pub use libcc2rs_macros::{ - ByteRepr, CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, - Copyable, CopyableUnsafe, CppFrom, CppFromUnsafe, DefaultConstructible, + ByteRepr, Conversions, ConversionsUnsafe, CopyAssignable, CopyAssignableUnsafe, + CopyConstructible, CopyConstructibleUnsafe, Copyable, CopyableUnsafe, DefaultConstructible, DefaultConstructibleUnsafe, DefaultInitializable, DefaultInitializableUnsafe, Destructible, DestructibleUnsafe, FnPtrArg, Memberwise, MemberwiseUnsafe, Movable, MovableUnsafe, MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, diff --git a/libcc2rs/src/object.rs b/libcc2rs/src/object.rs index f5fc220642..e1eb58bc6a 100644 --- a/libcc2rs/src/object.rs +++ b/libcc2rs/src/object.rs @@ -153,7 +153,7 @@ macro_rules! object { }; ($name:ident, $ty:ty, LvalueRef::bind($src:expr)) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); - $crate::CopyConstructible::copy_constructor( + <$ty as $crate::CopyConstructible>::copy_constructor( $crate::AsPointer::<$ty>::as_pointer(&$name), $crate::LvalueRef::bind($src), ); @@ -169,7 +169,7 @@ macro_rules! object { }; ($name:ident, $ty:ty) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); - $crate::DefaultConstructible::default_constructor( + <$ty as $crate::DefaultConstructible>::default_constructor( $crate::AsPointer::<$ty>::as_pointer(&$name), ); $crate::object!(@guard $name); @@ -206,7 +206,7 @@ macro_rules! object_unsafe { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - $crate::CopyConstructibleUnsafe::copy_constructor( + <$ty as $crate::CopyConstructibleUnsafe>::copy_constructor( &raw mut $name, $crate::LvalueRefUnsafe::bind::<$ty>($src), ) @@ -217,7 +217,7 @@ macro_rules! object_unsafe { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - $crate::MoveConstructibleUnsafe::move_constructor( + <$ty as $crate::MoveConstructibleUnsafe>::move_constructor( &raw mut $name, $crate::RvalueRefUnsafe::bind::<$ty>($src), ) @@ -228,7 +228,7 @@ macro_rules! object_unsafe { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - $crate::DefaultConstructibleUnsafe::default_constructor(&raw mut $name) + <$ty as $crate::DefaultConstructibleUnsafe>::default_constructor(&raw mut $name) }; $crate::object_unsafe!(@guard $name); }; diff --git a/libcc2rs/src/overload.rs b/libcc2rs/src/overload.rs new file mode 100644 index 0000000000..64ec858b70 --- /dev/null +++ b/libcc2rs/src/overload.rs @@ -0,0 +1,1463 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// Overload resolution for initialization ([over.match.ctor], [over.match.copy], +// [over.match.conv], [over.best.ics], [over.ics.rank], [over.match.best]), done +// at run time over the constructors and conversion functions that each type +// lists in its table, such that generic code initializes objects of types it +// does not know as C++ does. + +use std::any::TypeId; +use std::cmp::Ordering; +use std::ffi::c_void; + +use crate::initialization::ZeroInitializationUnsafe as _; +use crate::rc::Ptr; +use crate::reference::{ + Const, LvalueRef, LvalueRefUnsafe, ParameterObject, ParameterObjectUnsafe, Pointer, + PointerUnsafe, RvalueRef, RvalueRefUnsafe, +}; +use crate::reinterpret::ByteRepr; +use crate::void::AnyPtr; + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum Arithmetic { + Bool, + Signed(u32), + Unsigned(u32), + Float(u32), +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum Passing { + Value, + LvalueRef, + ConstLvalueRef, + RvalueRef, +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum Category { + Lvalue, + ConstLvalue, + Rvalue, +} + +pub trait Erased: Clone + 'static { + fn read(&self) -> T; + + fn write(&self, value: T); +} + +pub trait Arithmetical: ByteRepr + crate::TriviallyCopyable + Copy + 'static {} + +impl Erased for AnyPtr { + fn read(&self) -> T { + self.downcast::().read() + } + + fn write(&self, value: T) { + self.downcast::().write(value) + } +} + +impl Erased for *mut c_void { + fn read(&self) -> T { + unsafe { self.cast::().read() } + } + + fn write(&self, value: T) { + unsafe { self.cast::().write(value) } + } +} + +pub struct Param

{ + pub table: fn() -> Table

, + pub passing: Passing, +} + +pub struct Candidate

{ + pub params: Vec>, + pub is_explicit: bool, + pub result: Option Table

>, + pub call: fn(to: P, args: &[P]), +} + +pub struct Table

{ + pub id: TypeId, + pub name: &'static str, + pub arithmetic: Option, + pub storage: fn() -> P, + pub release: fn(P), + pub copy: fn(dst: P, src: P), + pub move_from: fn(dst: P, src: P), + pub constructors: Vec>, + pub conversion_functions: Vec>, + // The type whose objects convert to this type by a qualification + // conversion ([conv.qual]). + pub qualification_of: Option, +} + +pub trait Conversions: ByteRepr + Sized + 'static { + fn table() -> Table; +} + +pub trait ConversionsUnsafe: Sized + 'static { + fn table() -> Table<*mut c_void>; +} + +pub trait ConstructibleFrom: Sized { + fn construct(this: Ptr, args: Args); +} + +impl ConstructibleFrom for T { + fn construct(this: Ptr, args: Args) { + initialize(&T::table(), this.to_any(), &args.as_args(), true); + } +} + +pub trait ConvertibleTo: Sized { + fn convert(self, to: Ptr); +} + +impl ConvertibleTo for From { + fn convert(self, to: Ptr) { + initialize(&To::table(), to.to_any(), &[self.as_arg()], false); + } +} + +pub trait ConstructibleFromUnsafe: Sized { + /// # Safety + /// `this` is storage for an object, and `args` refer to live objects. + unsafe fn construct(this: *mut Self, args: Args); +} + +impl ConstructibleFromUnsafe for T { + unsafe fn construct(this: *mut T, args: Args) { + initialize(&T::table(), this.cast(), &args.as_args(), true); + } +} + +pub trait ConvertibleToUnsafe: Sized { + /// # Safety + /// `to` is storage for an object, and `self` refers to a live object. + unsafe fn convert(self, to: *mut To); +} + +impl ConvertibleToUnsafe for From { + unsafe fn convert(self, to: *mut To) { + initialize(&To::table(), to.cast(), &[self.as_arg()], false); + } +} + +pub trait AsArg { + fn as_arg(&self) -> Arg; +} + +impl AsArg for LvalueRef { + fn as_arg(&self) -> Arg { + Arg::lvalue(self.as_pointer()) + } +} + +impl AsArg for LvalueRef> { + fn as_arg(&self) -> Arg { + Arg::const_lvalue(self.as_pointer()) + } +} + +impl AsArg for RvalueRef { + fn as_arg(&self) -> Arg { + Arg::rvalue(self.as_pointer()) + } +} + +pub trait AsArgUnsafe { + fn as_arg(&self) -> Arg<*mut c_void>; +} + +impl AsArgUnsafe for LvalueRefUnsafe { + fn as_arg(&self) -> Arg<*mut c_void> { + Arg::lvalue_unsafe(self.as_ptr()) + } +} + +impl AsArgUnsafe for LvalueRefUnsafe> { + fn as_arg(&self) -> Arg<*mut c_void> { + Arg::const_lvalue_unsafe(self.as_const_ptr()) + } +} + +impl AsArgUnsafe for RvalueRefUnsafe { + fn as_arg(&self) -> Arg<*mut c_void> { + Arg::rvalue_unsafe(self.as_ptr()) + } +} + +pub trait Parameter: Sized { + fn param() -> Param; + + fn bind(object: &AnyPtr) -> Self; +} + +impl Parameter for T { + fn param() -> Param { + Param { + table: T::table, + passing: Passing::Value, + } + } + + fn bind(object: &AnyPtr) -> Self { + object.downcast::().read() + } +} + +impl Parameter for ParameterObject { + fn param() -> Param { + Param { + table: T::table, + passing: Passing::Value, + } + } + + fn bind(object: &AnyPtr) -> Self { + ParameterObject::bind(object.downcast::()) + } +} + +impl Parameter for LvalueRef { + fn param() -> Param { + Param { + table: T::table, + passing: Passing::LvalueRef, + } + } + + fn bind(object: &AnyPtr) -> Self { + LvalueRef::bind(object.downcast::()) + } +} + +impl Parameter for LvalueRef> { + fn param() -> Param { + Param { + table: T::table, + passing: Passing::ConstLvalueRef, + } + } + + fn bind(object: &AnyPtr) -> Self { + LvalueRef::bind(object.downcast::()) + } +} + +impl Parameter for RvalueRef { + fn param() -> Param { + Param { + table: T::table, + passing: Passing::RvalueRef, + } + } + + fn bind(object: &AnyPtr) -> Self { + RvalueRef::bind(object.downcast::()) + } +} + +impl Parameter for RvalueRef> { + fn param() -> Param { + Param { + table: T::table, + passing: Passing::RvalueRef, + } + } + + fn bind(object: &AnyPtr) -> Self { + RvalueRef::bind(object.downcast::()) + } +} + +impl Parameter for Pointer +where + Ptr: Conversions, +{ + fn param() -> Param { + Param { + table: as Conversions>::table, + passing: Passing::Value, + } + } + + fn bind(object: &AnyPtr) -> Self { + Pointer::bind(object.downcast::>().read()) + } +} + +fn const_pointer_table() -> Table +where + Ptr: Conversions, +{ + Table { + id: TypeId::of::>>(), + name: "Ptr", + qualification_of: Some(TypeId::of::>()), + .. as Conversions>::table() + } +} + +impl Parameter for Pointer> +where + Ptr: Conversions, +{ + fn param() -> Param { + Param { + table: const_pointer_table::, + passing: Passing::Value, + } + } + + fn bind(object: &AnyPtr) -> Self { + Pointer::bind(object.downcast::>().read()) + } +} + +pub trait ParameterUnsafe: Sized { + fn param() -> Param<*mut c_void>; + + /// # Safety + /// `object` points to a live object of the parameter's table type. + unsafe fn bind(object: *mut c_void) -> Self; +} + +impl ParameterUnsafe for T { + fn param() -> Param<*mut c_void> { + Param { + table: T::table, + passing: Passing::Value, + } + } + + unsafe fn bind(object: *mut c_void) -> Self { + unsafe { object.cast::().read() } + } +} + +impl ParameterUnsafe for ParameterObjectUnsafe { + fn param() -> Param<*mut c_void> { + Param { + table: T::table, + passing: Passing::Value, + } + } + + unsafe fn bind(object: *mut c_void) -> Self { + ParameterObjectUnsafe::bind(object.cast::()) + } +} + +impl ParameterUnsafe for PointerUnsafe { + fn param() -> Param<*mut c_void> { + Param { + table: <*mut T as ConversionsUnsafe>::table, + passing: Passing::Value, + } + } + + unsafe fn bind(object: *mut c_void) -> Self { + PointerUnsafe::bind(unsafe { object.cast::<*mut T>().read() }) + } +} + +impl ParameterUnsafe for PointerUnsafe> { + fn param() -> Param<*mut c_void> { + Param { + table: <*const T as ConversionsUnsafe>::table, + passing: Passing::Value, + } + } + + unsafe fn bind(object: *mut c_void) -> Self { + PointerUnsafe::bind(unsafe { object.cast::<*const T>().read() }) + } +} + +impl ParameterUnsafe for LvalueRefUnsafe { + fn param() -> Param<*mut c_void> { + Param { + table: T::table, + passing: Passing::LvalueRef, + } + } + + unsafe fn bind(object: *mut c_void) -> Self { + LvalueRefUnsafe::bind(object.cast::()) + } +} + +impl ParameterUnsafe for LvalueRefUnsafe> { + fn param() -> Param<*mut c_void> { + Param { + table: T::table, + passing: Passing::ConstLvalueRef, + } + } + + unsafe fn bind(object: *mut c_void) -> Self { + LvalueRefUnsafe::bind(object.cast::()) + } +} + +impl ParameterUnsafe for RvalueRefUnsafe { + fn param() -> Param<*mut c_void> { + Param { + table: T::table, + passing: Passing::RvalueRef, + } + } + + unsafe fn bind(object: *mut c_void) -> Self { + RvalueRefUnsafe::bind(object.cast::()) + } +} + +impl ParameterUnsafe for RvalueRefUnsafe> { + fn param() -> Param<*mut c_void> { + Param { + table: T::table, + passing: Passing::RvalueRef, + } + } + + unsafe fn bind(object: *mut c_void) -> Self { + RvalueRefUnsafe::bind(object.cast::()) + } +} + +pub trait ArgList { + fn as_args(&self) -> Vec>; +} + +pub trait ArgListUnsafe { + fn as_args(&self) -> Vec>; +} + +macro_rules! arg_list { + ($($name:ident),*) => { + impl<$($name: AsArg),*> ArgList for ($($name,)*) { + #[allow(non_snake_case, clippy::vec_init_then_push)] + fn as_args(&self) -> Vec> { + let ($($name,)*) = self; + vec![$($name.as_arg()),*] + } + } + + impl<$($name: AsArgUnsafe),*> ArgListUnsafe for ($($name,)*) { + #[allow(non_snake_case, clippy::vec_init_then_push)] + fn as_args(&self) -> Vec> { + let ($($name,)*) = self; + vec![$($name.as_arg()),*] + } + } + }; +} + +arg_list!(); +arg_list!(A); +arg_list!(A, B); +arg_list!(A, B, C); +arg_list!(A, B, C, D); +arg_list!(A, B, C, D, E); +arg_list!(A, B, C, D, E, F); + +pub struct Arg

{ + pub table: fn() -> Table

, + pub category: Category, + pub ptr: P, +} + +impl Arg<*mut c_void> { + pub fn lvalue_unsafe(ptr: *mut T) -> Self { + Self::new_unsafe(ptr, Category::Lvalue) + } + + pub fn const_lvalue_unsafe(ptr: *const T) -> Self { + Self::new_unsafe(ptr.cast_mut(), Category::ConstLvalue) + } + + pub fn rvalue_unsafe(ptr: *mut T) -> Self { + Self::new_unsafe(ptr, Category::Rvalue) + } + + fn new_unsafe(ptr: *mut T, category: Category) -> Self { + Arg { + table: T::table, + category, + ptr: ptr.cast(), + } + } +} + +impl Arg { + pub fn lvalue(ptr: Ptr) -> Self { + Self::new(ptr, Category::Lvalue) + } + + pub fn const_lvalue(ptr: Ptr) -> Self { + Self::new(ptr, Category::ConstLvalue) + } + + pub fn rvalue(ptr: Ptr) -> Self { + Self::new(ptr, Category::Rvalue) + } + + fn new(ptr: Ptr, category: Category) -> Self { + Arg { + table: T::table, + category, + ptr: ptr.to_any(), + } + } +} + +// The rank of a standard conversion sequence ([over.ics.scs]/3). +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)] +enum Rank { + Exact, + Promotion, + Conversion, +} + +#[derive(Clone, Copy, Debug)] +struct Standard { + rank: Rank, + converts: bool, + qualifies: bool, + binds_rvalue_ref: bool, + binds_to_const: bool, +} + +impl Standard { + fn identity() -> Self { + Standard { + rank: Rank::Exact, + converts: false, + qualifies: false, + binds_rvalue_ref: false, + binds_to_const: false, + } + } +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +enum UserFunction { + Constructor(usize), + ConversionFunction(usize), +} + +// An implicit conversion sequence ([over.best.ics]). +#[derive(Clone, Copy, Debug)] +enum Sequence { + Standard(Standard), + User { + function: UserFunction, + after: Standard, + }, +} + +fn promotes(from: Arithmetic, to: Arithmetic) -> bool { + use Arithmetic::*; + match (from, to) { + (Bool, Signed(32)) => true, + (Signed(bits), Signed(32)) | (Unsigned(bits), Signed(32)) => bits < 32, + (Float(32), Float(64)) => true, + _ => false, + } +} + +// The standard conversion from an object of type from to one of type to, if +// there is one ([conv]). +fn standard(from: &Table

, to: &Table

) -> Option { + if from.id == to.id { + return Some(Standard::identity()); + } + if to.qualification_of == Some(from.id) { + return Some(Standard { + qualifies: true, + ..Standard::identity() + }); + } + let (from_kind, to_kind) = (from.arithmetic?, to.arithmetic?); + Some(Standard { + rank: if promotes(from_kind, to_kind) { + Rank::Promotion + } else { + Rank::Conversion + }, + converts: true, + qualifies: false, + binds_rvalue_ref: false, + binds_to_const: false, + }) +} + +// The binding of a parameter to the result of a standard conversion of an +// argument of the given category ([dcl.init.ref]/5). +fn bind(mut standard: Standard, category: Category, passing: Passing) -> Option { + match passing { + Passing::Value => {} + Passing::LvalueRef => { + if standard.converts || category != Category::Lvalue { + return None; + } + } + Passing::ConstLvalueRef => standard.binds_to_const = category != Category::ConstLvalue, + Passing::RvalueRef => { + if !standard.converts && category != Category::Rvalue { + return None; + } + standard.binds_rvalue_ref = true; + } + } + Some(standard) +} + +// The conversion sequence that initializes a parameter from an argument +// ([over.best.ics]); only standard conversions if standard_only +// ([over.best.ics]/4). +fn parameter_sequence( + arg: &Table

, + category: Category, + param: &Param

, + standard_only: bool, +) -> Option { + let target = (param.table)(); + if let Some(standard) = standard(arg, &target).and_then(|s| bind(s, category, param.passing)) { + return Some(Sequence::Standard(standard)); + } + if standard_only || param.passing == Passing::LvalueRef { + return None; + } + user_sequence(arg, category, &target, false) +} + +// The best user-defined conversion from an object of type arg to one of type +// target ([over.match.copy], [over.match.conv]). +fn user_sequence( + arg: &Table

, + category: Category, + target: &Table

, + allow_explicit: bool, +) -> Option { + let mut viable: Vec<(Sequence, Vec)> = Vec::new(); + for (index, ctor) in target.constructors.iter().enumerate() { + if ctor.params.len() != 1 || (ctor.is_explicit && !allow_explicit) { + continue; + } + if let Some(first) = parameter_sequence(arg, category, &ctor.params[0], true) { + let sequence = Sequence::User { + function: UserFunction::Constructor(index), + after: Standard::identity(), + }; + viable.push((sequence, vec![first])); + } + } + for (index, function) in arg.conversion_functions.iter().enumerate() { + if function.is_explicit && !allow_explicit { + continue; + } + let Some(first) = parameter_sequence(arg, category, &function.params[0], true) else { + continue; + }; + let result = (function.result.expect("a conversion function has a result"))(); + if let Some(after) = standard(&result, target) { + let sequence = Sequence::User { + function: UserFunction::ConversionFunction(index), + after, + }; + viable.push((sequence, vec![first])); + } + } + // [over.match.best]/2.2: in a user-defined conversion, the better second + // standard conversion to the target. + let tiebreak = |a: &Sequence, b: &Sequence| match (a, b) { + (Sequence::User { after: a, .. }, Sequence::User { after: b, .. }) => { + compare_standard(a, b) + } + _ => Ordering::Equal, + }; + best(&viable, tiebreak).map(|index| viable[index].0) +} + +fn compare_standard(a: &Standard, b: &Standard) -> Ordering { + a.rank + .cmp(&b.rank) + // [over.ics.rank]/3.2.1: the identity is a proper subsequence of a + // qualification conversion. + .then(a.qualifies.cmp(&b.qualifies)) + // [over.ics.rank]/3.2.3: an rvalue binds better to an rvalue reference. + .then(b.binds_rvalue_ref.cmp(&a.binds_rvalue_ref)) + // [over.ics.rank]/3.2.6: to a reference to the less cv-qualified type. + .then(a.binds_to_const.cmp(&b.binds_to_const)) +} + +// The order of two implicit conversion sequences, Less when a is better +// ([over.ics.rank]); None when they are indistinguishable. +fn compare(a: &Sequence, b: &Sequence) -> Option { + match (a, b) { + (Sequence::Standard(a), Sequence::Standard(b)) => Some(compare_standard(a, b)), + (Sequence::Standard(_), Sequence::User { .. }) => Some(Ordering::Less), + (Sequence::User { .. }, Sequence::Standard(_)) => Some(Ordering::Greater), + ( + Sequence::User { + function: fa, + after: aa, + }, + Sequence::User { + function: fb, + after: ab, + }, + ) => (fa == fb).then(|| compare_standard(aa, ab)), + } +} + +// The best viable candidate ([over.match.best]/2): at least as good for every +// argument and better for one, or, when every argument is as good, better by +// tiebreak. +fn best(viable: &[(T, Vec)], tiebreak: impl Fn(&T, &T) -> Ordering) -> Option { + let better = |i: usize, j: usize| { + let mut strictly = false; + for (a, b) in viable[i].1.iter().zip(&viable[j].1) { + match compare(a, b) { + Some(Ordering::Less) => strictly = true, + Some(Ordering::Equal) => {} + _ => return false, + } + } + strictly || tiebreak(&viable[i].0, &viable[j].0) == Ordering::Less + }; + (0..viable.len()).find(|&i| (0..viable.len()).all(|j| i == j || better(i, j))) +} + +fn initialize(target: &Table

, to: P, args: &[Arg

], is_direct: bool) { + let sources: Vec> = args.iter().map(|arg| (arg.table)()).collect(); + let is_class = target.arithmetic.is_none(); + // A class object from arguments, or from an object of its class, is + // constructed by the best constructor ([over.match.ctor]). + if is_class && (is_direct || sources[0].id == target.id) { + #[derive(Clone, Copy)] + enum Constructor { + Copy, + Move, + Listed(usize), + } + let mut viable: Vec<(Constructor, Vec)> = Vec::new(); + let declares = |passings: &[Passing]| { + target.constructors.iter().any(|ctor| { + ctor.params.len() == 1 + && passings.contains(&ctor.params[0].passing) + && (ctor.params[0].table)().id == target.id + }) + }; + if args.len() == 1 && sources[0].id == target.id { + let identity = Standard::identity(); + if !declares(&[Passing::LvalueRef, Passing::ConstLvalueRef]) { + viable.push(( + Constructor::Copy, + vec![Sequence::Standard(Standard { + binds_to_const: args[0].category != Category::ConstLvalue, + ..identity + })], + )); + } + if args[0].category == Category::Rvalue && !declares(&[Passing::RvalueRef]) { + viable.push(( + Constructor::Move, + vec![Sequence::Standard(Standard { + binds_rvalue_ref: true, + ..identity + })], + )); + } + } + for (index, ctor) in target.constructors.iter().enumerate() { + if ctor.params.len() != args.len() || (ctor.is_explicit && !is_direct) { + continue; + } + let sequences: Option> = args + .iter() + .zip(&sources) + .zip(&ctor.params) + .map(|((arg, source), param)| { + parameter_sequence(source, arg.category, param, false) + }) + .collect(); + if let Some(sequences) = sequences { + viable.push((Constructor::Listed(index), sequences)); + } + } + let chosen = best(&viable, |_, _| Ordering::Equal).unwrap_or_else(|| { + panic!("no unique constructor of {} for the arguments", target.name) + }); + let (constructor, sequences) = &viable[chosen]; + match constructor { + Constructor::Copy => (target.copy)(to, args[0].ptr.clone()), + Constructor::Move => (target.move_from)(to, args[0].ptr.clone()), + Constructor::Listed(index) => { + call_with(&target.constructors[*index], to, args, sequences) + } + } + return; + } + assert!( + args.len() == 1, + "{} is initialized from one value", + target.name + ); + let (arg, source) = (&args[0], &sources[0]); + // A standard conversion, else a user-defined conversion by a converting + // constructor or a conversion function ([over.match.copy], + // [over.match.conv]). + if let Some(standard) = standard(source, target) { + if standard.converts { + convert_arithmetic(source, arg.ptr.clone(), target, to); + } else { + (target.copy)(to, arg.ptr.clone()); + } + return; + } + let sequence = user_sequence(source, arg.category, target, is_direct) + .unwrap_or_else(|| panic!("no conversion from {} to {}", source.name, target.name)); + run_user(source, arg, target, to, &sequence); +} + +fn call_with(ctor: &Candidate

, to: P, args: &[Arg

], sequences: &[Sequence]) { + let mut temporaries: Vec<(Table

, P)> = Vec::new(); + let pointers: Vec

= args + .iter() + .zip(&ctor.params) + .zip(sequences) + .map(|((arg, param), sequence)| { + let target = (param.table)(); + let source = (arg.table)(); + let converts = match sequence { + Sequence::Standard(standard) => standard.converts, + Sequence::User { .. } => true, + }; + if !converts && param.passing != Passing::Value { + return arg.ptr.clone(); + } + let temporary = (target.storage)(); + match sequence { + Sequence::Standard(standard) if standard.converts => { + convert_arithmetic(&source, arg.ptr.clone(), &target, temporary.clone()) + } + Sequence::Standard(_) if arg.category == Category::Rvalue => { + (target.move_from)(temporary.clone(), arg.ptr.clone()) + } + Sequence::Standard(_) => (target.copy)(temporary.clone(), arg.ptr.clone()), + Sequence::User { .. } => { + run_user(&source, arg, &target, temporary.clone(), sequence) + } + } + temporaries.push((target, temporary.clone())); + temporary + }) + .collect(); + (ctor.call)(to, &pointers); + for (table, temporary) in temporaries { + (table.release)(temporary); + } +} + +fn run_user( + source: &Table

, + arg: &Arg

, + target: &Table

, + to: P, + sequence: &Sequence, +) { + let Sequence::User { function, after } = sequence else { + unreachable!("not a user-defined conversion") + }; + match function { + UserFunction::Constructor(index) => { + let ctor = &target.constructors[*index]; + let first = parameter_sequence(source, arg.category, &ctor.params[0], true) + .expect("the constructor was viable"); + call_with(ctor, to, std::slice::from_ref(arg), &[first]); + } + UserFunction::ConversionFunction(index) => { + let function = &source.conversion_functions[*index]; + if !after.converts { + (function.call)(to, std::slice::from_ref(&arg.ptr)); + return; + } + let result = (function.result.expect("a conversion function has a result"))(); + let value = (result.storage)(); + (function.call)(value.clone(), std::slice::from_ref(&arg.ptr)); + convert_arithmetic(&result, value.clone(), target, to); + (result.release)(value); + } + } +} + +fn read_arithmetic(from: &Table

, src: &P) -> (f64, i128) { + macro_rules! read { + ($($ty:ty),*) => { + $( + if from.id == TypeId::of::<$ty>() { + let value: $ty = Erased::read(src); + return (value as f64, value as i128); + } + )* + }; + } + if from.id == TypeId::of::() { + let value: bool = Erased::read(src); + return (value as u8 as f64, value as i128); + } + read!( + i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize, f32, f64 + ); + unreachable!("{} is not an arithmetic type", from.name) +} + +// The arithmetic conversion of the value that src points to, written to dst +// ([conv.integral], [conv.fpint], [conv.double], [conv.bool]). +fn convert_arithmetic(from: &Table

, src: P, to: &Table

, dst: P) { + let (float, integer) = read_arithmetic(from, &src); + let is_float = matches!(from.arithmetic, Some(Arithmetic::Float(_))); + macro_rules! write { + ($($ty:ty),*) => { + $( + if to.id == TypeId::of::<$ty>() { + let value = if is_float { float as $ty } else { integer as $ty }; + Erased::write::<$ty>(&dst, value); + return; + } + )* + }; + } + if to.id == TypeId::of::() { + let value = if is_float { float != 0.0 } else { integer != 0 }; + Erased::write::(&dst, value); + return; + } + write!( + i8, + u8, + i16, u16, i32, u32, i64, u64, i128, u128, isize, usize, f32, f64 + ); + unreachable!("{} is not an arithmetic type", to.name) +} + +macro_rules! arithmetic_conversions { + ($($ty:ty => $kind:expr),* $(,)?) => {$( + impl Arithmetical for $ty {} + + impl Conversions for $ty { + fn table() -> Table { + Table { + id: TypeId::of::<$ty>(), + name: stringify!($ty), + arithmetic: Some($kind), + storage: || Ptr::alloc(<$ty>::default()).to_any(), + release: |ptr| ptr.downcast::<$ty>().delete(), + copy: |dst, src| Erased::write(&dst, Erased::read::<$ty>(&src)), + move_from: |dst, src| Erased::write(&dst, Erased::read::<$ty>(&src)), + constructors: Vec::new(), + conversion_functions: Vec::new(), + qualification_of: None, + } + } + } + + impl ConversionsUnsafe for $ty { + fn table() -> Table<*mut c_void> { + Table { + id: TypeId::of::<$ty>(), + name: stringify!($ty), + arithmetic: Some($kind), + storage: || Box::into_raw(Box::<$ty>::default()).cast(), + release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::<$ty>()) }), + copy: |dst, src| Erased::write(&dst, Erased::read::<$ty>(&src)), + move_from: |dst, src| Erased::write(&dst, Erased::read::<$ty>(&src)), + constructors: Vec::new(), + conversion_functions: Vec::new(), + qualification_of: None, + } + } + } + )*}; +} + +arithmetic_conversions!( + bool => Arithmetic::Bool, + i8 => Arithmetic::Signed(8), + u8 => Arithmetic::Unsigned(8), + i16 => Arithmetic::Signed(16), + u16 => Arithmetic::Unsigned(16), + i32 => Arithmetic::Signed(32), + u32 => Arithmetic::Unsigned(32), + i64 => Arithmetic::Signed(64), + u64 => Arithmetic::Unsigned(64), + i128 => Arithmetic::Signed(128), + u128 => Arithmetic::Unsigned(128), + isize => Arithmetic::Signed(64), + usize => Arithmetic::Unsigned(64), + f32 => Arithmetic::Float(32), + f64 => Arithmetic::Float(64), +); + +impl Conversions for Ptr +where + Ptr: ByteRepr + crate::TriviallyCopyable, +{ + fn table() -> Table { + Table { + id: TypeId::of::>(), + name: "Ptr", + arithmetic: None, + storage: || Ptr::alloc(Ptr::::null()).to_any(), + release: |ptr| ptr.downcast::>().delete(), + copy: |dst, src| { + dst.downcast::>() + .write(src.downcast::>().read()) + }, + move_from: |dst, src| { + dst.downcast::>() + .write(src.downcast::>().read()) + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + qualification_of: None, + } + } +} + +impl Conversions for Vec +where + Vec: ByteRepr, +{ + fn table() -> Table { + Table { + id: TypeId::of::>(), + name: "Vec", + arithmetic: None, + storage: || Ptr::alloc(Vec::::new()).to_any(), + release: |ptr| ptr.downcast::>().delete(), + copy: |dst, src| { + let (dst, src) = (dst.downcast::>(), src.downcast::>()); + let len = src.with(|elems| elems.len()); + dst.with_mut(|elems| *elems = (0..len).map(|_| T::zero_init()).collect()); + let element = T::table(); + for i in 0..len { + (element.copy)( + dst.decay().offset(i).to_any(), + src.decay().offset(i).to_any(), + ); + } + }, + move_from: |dst, src| { + let value = src.downcast::>().with_mut(std::mem::take); + dst.downcast::>().with_mut(|elems| *elems = value); + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + qualification_of: None, + } + } +} + +impl Conversions for (crate::rc::Value, crate::rc::Value) +where + A: Conversions + crate::ZeroInitialization, + B: Conversions + crate::ZeroInitialization, + (crate::rc::Value, crate::rc::Value): ByteRepr, +{ + fn table() -> Table { + type Pair = (crate::rc::Value, crate::rc::Value); + fn members(ptr: &AnyPtr) -> (AnyPtr, AnyPtr) { + use crate::rc::AsPointer; + ptr.downcast::>() + .with(|pair| (pair.0.as_pointer().to_any(), pair.1.as_pointer().to_any())) + } + Table { + id: TypeId::of::>(), + name: "pair", + arithmetic: None, + storage: || { + Ptr::alloc(( + std::rc::Rc::new(std::cell::RefCell::new(A::zero_init())), + std::rc::Rc::new(std::cell::RefCell::new(B::zero_init())), + )) + .to_any() + }, + release: |ptr| ptr.downcast::>().delete(), + copy: |dst, src| { + let ((d0, d1), (s0, s1)) = (members::(&dst), members::(&src)); + (A::table().copy)(d0, s0); + (B::table().copy)(d1, s1); + }, + move_from: |dst, src| { + let ((d0, d1), (s0, s1)) = (members::(&dst), members::(&src)); + (A::table().move_from)(d0, s0); + (B::table().move_from)(d1, s1); + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + qualification_of: None, + } + } +} + +impl Conversions for Option> +where + Option>: ByteRepr, +{ + fn table() -> Table { + type Owner = Option>; + Table { + id: TypeId::of::>(), + name: "unique_ptr", + arithmetic: None, + storage: || Ptr::alloc(Owner::::None).to_any(), + release: |ptr| ptr.downcast::>().delete(), + copy: |_, _| panic!("unique_ptr is not copy constructible"), + move_from: |dst, src| { + let value = src.downcast::>().with_mut(Option::take); + dst.downcast::>().with_mut(|owner| *owner = value); + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + qualification_of: None, + } + } +} + +impl ConversionsUnsafe for Option> { + fn table() -> Table<*mut c_void> { + Table { + id: TypeId::of::>>(), + name: "unique_ptr", + arithmetic: None, + storage: || Box::into_raw(Box::new(Option::>::None)).cast(), + release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::>>()) }), + copy: |_, _| panic!("unique_ptr is not copy constructible"), + move_from: |dst, src| unsafe { + dst.cast::>>() + .write((*src.cast::>>()).take()) + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + qualification_of: None, + } + } +} + +impl ConversionsUnsafe for *mut T { + fn table() -> Table<*mut c_void> { + raw_pointer_table::<*mut T>("*mut", None) + } +} + +impl ConversionsUnsafe for *const T { + fn table() -> Table<*mut c_void> { + raw_pointer_table::<*const T>("*const", Some(TypeId::of::<*mut T>())) + } +} + +fn raw_pointer_table( + name: &'static str, + qualification_of: Option, +) -> Table<*mut c_void> { + Table { + id: TypeId::of::(), + name, + arithmetic: None, + storage: || Box::into_raw(Box::::default()).cast(), + release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::()) }), + copy: |dst, src| unsafe { dst.cast::().write(src.cast::().read()) }, + move_from: |dst, src| unsafe { dst.cast::().write(src.cast::().read()) }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + qualification_of, + } +} + +impl ConversionsUnsafe for Vec { + fn table() -> Table<*mut c_void> { + Table { + id: TypeId::of::>(), + name: "Vec", + arithmetic: None, + storage: || Box::into_raw(Box::>::default()).cast(), + release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::>()) }), + copy: |dst, src| unsafe { + let (dst, src) = (dst.cast::>(), src.cast::>()); + let len = (*src).len(); + dst.write((0..len).map(|_| T::zero_init()).collect()); + let element = T::table(); + for i in 0..len { + (element.copy)( + (*dst).as_mut_ptr().add(i).cast(), + (*src).as_mut_ptr().add(i).cast(), + ); + } + }, + move_from: |dst, src| unsafe { + dst.cast::>() + .write(std::mem::take(&mut *src.cast::>())) + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + qualification_of: None, + } + } +} + +impl ConversionsUnsafe for (A, B) +where + A: ConversionsUnsafe + crate::ZeroInitializationUnsafe, + B: ConversionsUnsafe + crate::ZeroInitializationUnsafe, +{ + fn table() -> Table<*mut c_void> { + Table { + id: TypeId::of::<(A, B)>(), + name: "pair", + arithmetic: None, + storage: || Box::into_raw(Box::new(unsafe { <(A, B)>::zero_init() })).cast(), + release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::<(A, B)>()) }), + copy: |dst, src| unsafe { + let (dst, src) = (dst.cast::<(A, B)>(), src.cast::<(A, B)>()); + (A::table().copy)((&raw mut (*dst).0).cast(), (&raw mut (*src).0).cast()); + (B::table().copy)((&raw mut (*dst).1).cast(), (&raw mut (*src).1).cast()); + }, + move_from: |dst, src| unsafe { + let (dst, src) = (dst.cast::<(A, B)>(), src.cast::<(A, B)>()); + (A::table().move_from)((&raw mut (*dst).0).cast(), (&raw mut (*src).0).cast()); + (B::table().move_from)((&raw mut (*dst).1).cast(), (&raw mut (*src).1).cast()); + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + qualification_of: None, + } + } +} + +#[cfg(test)] +mod tests { + use std::cell::RefCell; + use std::rc::Rc; + + use super::*; + use crate::rc::{AsPointer, Value}; + + fn construct_with(to: Ptr, args: &[Arg]) { + initialize(&T::table(), to.to_any(), args, true); + } + + fn convert_with(to: Ptr, arg: Arg) { + initialize(&T::table(), to.to_any(), &[arg], false); + } + + #[allow(dead_code)] + unsafe fn construct_with_unsafe(to: *mut T, args: &[Arg<*mut c_void>]) { + initialize(&T::table(), to.cast(), args, true); + } + + unsafe fn convert_with_unsafe(to: *mut T, arg: Arg<*mut c_void>) { + initialize(&T::table(), to.cast(), &[arg], false); + } + + fn object(value: T) -> Value { + Rc::new(RefCell::new(value)) + } + + #[test] + fn arithmetic_copy_initialization() { + let from = object(7_i32); + let to = object(0_i64); + convert_with(to.as_pointer(), Arg::const_lvalue(from.as_pointer())); + assert_eq!(*to.borrow(), 7); + let flag = object(false); + convert_with(flag.as_pointer(), Arg::rvalue(object(2.5_f64).as_pointer())); + assert!(*flag.borrow()); + } + + #[derive(Clone, Default)] + struct Ratio(i32, i32); + + impl ByteRepr for Ratio {} + + impl Conversions for Ratio { + fn table() -> Table { + Table { + id: TypeId::of::(), + name: "Ratio", + arithmetic: None, + storage: || Ptr::alloc(Ratio::default()).to_any(), + release: |ptr| ptr.downcast::().delete(), + copy: |dst, src| { + dst.downcast::() + .write(src.downcast::().with(Ratio::clone)) + }, + move_from: |dst, src| { + dst.downcast::() + .write(src.downcast::().with(Ratio::clone)) + }, + constructors: Vec::new(), + conversion_functions: vec![ + Candidate { + params: vec![Param { + table: ::table, + passing: Passing::ConstLvalueRef, + }], + is_explicit: false, + result: Some(::table), + call: |to, args| { + let ratio = args[0].downcast::().with(Ratio::clone); + to.downcast::().write(ratio.0 / ratio.1) + }, + }, + Candidate { + params: vec![Param { + table: ::table, + passing: Passing::ConstLvalueRef, + }], + is_explicit: false, + result: Some(::table), + call: |to, args| { + let ratio = args[0].downcast::().with(Ratio::clone); + to.downcast::() + .write(ratio.0 as f64 / ratio.1 as f64 + 0.5) + }, + }, + ], + qualification_of: None, + } + } + } + + #[derive(Clone, Default)] + struct Meters(i64); + + impl ByteRepr for Meters {} + + impl Conversions for Meters { + fn table() -> Table { + Table { + id: TypeId::of::(), + name: "Meters", + arithmetic: None, + storage: || Ptr::alloc(Meters::default()).to_any(), + release: |ptr| ptr.downcast::().delete(), + copy: |dst, src| { + dst.downcast::() + .write(src.downcast::().with(Meters::clone)) + }, + move_from: |dst, src| { + dst.downcast::() + .write(src.downcast::().with(Meters::clone)) + }, + constructors: vec![ + Candidate { + params: vec![Param { + table: ::table, + passing: Passing::Value, + }], + is_explicit: false, + result: None, + call: |to, args| { + let value = args[0].downcast::().read(); + to.downcast::().write(Meters(value)) + }, + }, + Candidate { + params: vec![Param { + table: ::table, + passing: Passing::Value, + }], + is_explicit: true, + result: None, + call: |to, args| { + let value = args[0].downcast::().read(); + to.downcast::().write(Meters(value as i64 * 1000)) + }, + }, + ], + conversion_functions: Vec::new(), + qualification_of: None, + } + } + } + + #[test] + fn exact_conversion_function_is_chosen() { + let ratio = object(Ratio(9, 2)); + let to = object(0_i32); + convert_with(to.as_pointer(), Arg::const_lvalue(ratio.as_pointer())); + assert_eq!(*to.borrow(), 4); + let to = object(0.0_f64); + convert_with(to.as_pointer(), Arg::const_lvalue(ratio.as_pointer())); + assert_eq!(*to.borrow(), 5.0); + } + + #[test] + #[should_panic(expected = "no conversion from Ratio to i64")] + fn conversions_of_equal_rank_are_ambiguous() { + let ratio = object(Ratio(9, 2)); + convert_with( + object(0_i64).as_pointer(), + Arg::const_lvalue(ratio.as_pointer()), + ); + } + + #[test] + fn copy_initialization_skips_explicit_constructors() { + let meters = object(Meters(0)); + convert_with( + meters.as_pointer(), + Arg::rvalue(object(2.0_f64).as_pointer()), + ); + assert_eq!(meters.borrow().0, 2); + construct_with( + meters.as_pointer(), + &[Arg::rvalue(object(2.0_f64).as_pointer())], + ); + assert_eq!(meters.borrow().0, 2000); + } + + #[test] + fn arithmetic_copy_initialization_unsafe() { + let mut from = 300_i32; + let mut to = 0_u8; + unsafe { convert_with_unsafe(&raw mut to, Arg::const_lvalue_unsafe(&raw const from)) }; + assert_eq!(to, 44); + let mut pair = (0_i64, 0.0_f64); + let mut source = (3_i64, 1.5_f64); + unsafe { convert_with_unsafe(&raw mut pair, Arg::lvalue_unsafe(&raw mut source)) }; + assert_eq!(pair, (3, 1.5)); + from += 1; + let _ = from; + } + + #[test] + fn promotion_ranks_above_conversion() { + let promote = Standard { + rank: Rank::Promotion, + converts: true, + qualifies: false, + binds_rvalue_ref: false, + binds_to_const: false, + }; + let conversion = Standard { + rank: Rank::Conversion, + ..promote + }; + assert_eq!(compare_standard(&promote, &conversion), Ordering::Less); + assert!(promotes(Arithmetic::Signed(16), Arithmetic::Signed(32))); + assert!(!promotes(Arithmetic::Signed(32), Arithmetic::Signed(64))); + } +} diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs index 91cd69c53f..182e238984 100644 --- a/libcc2rs/src/reference.rs +++ b/libcc2rs/src/reference.rs @@ -8,10 +8,10 @@ use crate::capture::{ Destructible, DestructibleUnsafe, TriviallyDestructible, TriviallyDestructibleUnsafe, }; use crate::constructor::{ - CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, - MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, Swappable, + CopyAssignable, CopyAssignableUnsafe, MoveAssignable, MoveAssignableUnsafe, Swappable, SwappableUnsafe, }; +use crate::conversion::{Constructor, ConstructorUnsafe}; use crate::rc::Ptr; use crate::reinterpret::ByteRepr; @@ -88,20 +88,20 @@ macro_rules! reference { } } - impl MoveConstructible for $name + impl Constructor<(RvalueRef,)> for $name where T::Object: ByteRepr, { - fn move_constructor(this: Ptr, src: RvalueRef) { + fn constructor(this: Ptr, (src,): (RvalueRef,)) { this.write(src.as_pointer().with(Self::clone)); } } - impl CopyConstructible for $name + impl Constructor<(LvalueRef>,)> for $name where T::Object: ByteRepr, { - fn copy_constructor(this: Ptr, src: LvalueRef>) { + fn constructor(this: Ptr, (src,): (LvalueRef>,)) { this.write(src.as_pointer().with(Self::clone)); } } @@ -229,21 +229,28 @@ macro_rules! reference_unsafe { } } + impl crate::ZeroInitializationUnsafe for $name { + #[inline] + unsafe fn zero_init() -> Self { + Self(std::ptr::null_mut(), PhantomData) + } + } + impl fmt::Debug for $name { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } - impl MoveConstructibleUnsafe for $name { - unsafe fn move_constructor(this: *mut Self, src: RvalueRefUnsafe) { + impl ConstructorUnsafe<(RvalueRefUnsafe,)> for $name { + unsafe fn constructor(this: *mut Self, (src,): (RvalueRefUnsafe,)) { let src = src.as_ptr(); unsafe { std::ptr::write(this, *src) } } } - impl CopyConstructibleUnsafe for $name { - unsafe fn copy_constructor(this: *mut Self, src: LvalueRefUnsafe>) { + impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for $name { + unsafe fn constructor(this: *mut Self, (src,): (LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); unsafe { std::ptr::write(this, *src) } } @@ -296,6 +303,83 @@ macro_rules! reference_unsafe { reference_unsafe!(LvalueRefUnsafe); reference_unsafe!(RvalueRefUnsafe); +pub struct Pointer(Ptr); + +impl Pointer { + #[inline] + pub fn bind(ptr: Ptr) -> Self { + Self(ptr) + } + + #[inline] + pub fn as_pointer(&self) -> Ptr { + self.0.clone() + } +} + +pub trait CvUnsafe { + type Object; +} + +impl CvUnsafe for T { + type Object = T; +} + +impl CvUnsafe for Const { + type Object = T; +} + +pub struct PointerUnsafe(*mut T::Object); + +impl PointerUnsafe { + #[inline] + pub fn bind(ptr: *const T::Object) -> Self { + Self(ptr.cast_mut()) + } + + #[inline] + pub fn as_ptr(&self) -> *mut T::Object { + self.0 + } +} + +pub struct ParameterObject(Ptr); + +impl ParameterObject { + #[inline] + pub fn bind(ptr: Ptr) -> Self { + Self(ptr) + } + + #[inline] + pub fn as_pointer(&self) -> Ptr { + self.0.clone() + } +} + +pub struct ParameterObjectUnsafe(*mut T); + +impl ParameterObjectUnsafe { + #[inline] + pub fn bind(ptr: *mut T) -> Self { + Self(ptr) + } + + #[inline] + pub fn as_ptr(&self) -> *mut T { + self.0 + } +} + +impl Clone for ParameterObjectUnsafe { + #[inline] + fn clone(&self) -> Self { + *self + } +} + +impl Copy for ParameterObjectUnsafe {} + impl CopyAssignableUnsafe for LvalueRefUnsafe { unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { let src = src.as_const_ptr(); diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index 2d5d2559a3..860566dcf2 100644 --- a/libcc2rs/src/swap.rs +++ b/libcc2rs/src/swap.rs @@ -50,7 +50,10 @@ pub fn pointer(value: &Value) -> Ptr { pub fn move_constructed(src: &Ptr) -> T { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - T::move_constructor(pointer(&dst), crate::RvalueRef::bind(src.clone())); + ,)>>::constructor( + pointer(&dst), + (crate::RvalueRef::bind(src.clone()),), + ); Rc::try_unwrap(dst).ok().unwrap().into_inner() } @@ -64,7 +67,10 @@ pub(crate) fn copy_constructed_in_storage, ) -> T { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - T::copy_constructor(pointer(&dst), crate::LvalueRef::bind(src)); + >,)>>::constructor( + pointer(&dst), + (crate::LvalueRef::bind(src),), + ); Rc::try_unwrap(dst).ok().unwrap().into_inner() } @@ -73,7 +79,10 @@ pub(crate) fn copy_constructed_in_storage(src: *const T) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - T::copy_constructor(dst.as_mut_ptr(), crate::LvalueRefUnsafe::bind(src)); + >,)>>::constructor( + &mut *dst.as_mut_ptr(), + (crate::LvalueRefUnsafe::bind(src),), + ); dst.assume_init() } } @@ -81,7 +90,10 @@ pub unsafe fn copy_constructed_unsafe(src: *const T) pub unsafe fn move_constructed_unsafe(src: *mut T) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - T::move_constructor(dst.as_mut_ptr(), crate::RvalueRefUnsafe::bind(src)); + ,)>>::constructor( + &mut *dst.as_mut_ptr(), + (crate::RvalueRefUnsafe::bind(src),), + ); dst.assume_init() } } @@ -156,7 +168,10 @@ where { let storage: Value = Rc::new(RefCell::new(T::zero_init())); let tmp = AsPointer::::as_pointer(&storage); - T::move_constructor(tmp.clone(), crate::RvalueRef::bind(this.clone())); + ,)>>::constructor( + tmp.clone(), + (crate::RvalueRef::bind(this.clone()),), + ); T::move_assign(this, crate::RvalueRef::bind(other.clone())); T::move_assign(other.clone(), crate::RvalueRef::bind(tmp.clone())); T::destroy(tmp.clone()); @@ -170,9 +185,9 @@ where { let mut tmp = MaybeUninit::::uninit(); unsafe { - MoveConstructibleUnsafe::move_constructor( + ,)>>::constructor( tmp.as_mut_ptr(), - crate::RvalueRefUnsafe::bind(this), + (crate::RvalueRefUnsafe::bind(this),), ); MoveAssignableUnsafe::move_assign(this, crate::RvalueRefUnsafe::bind(other)); MoveAssignableUnsafe::move_assign(other, crate::RvalueRefUnsafe::bind(tmp.as_mut_ptr())); diff --git a/libcc2rs/src/void.rs b/libcc2rs/src/void.rs index 6a737d9af9..e5dba00b77 100644 --- a/libcc2rs/src/void.rs +++ b/libcc2rs/src/void.rs @@ -132,6 +132,14 @@ impl AnyPtr { pub fn is_null(&self) -> bool { self.ptr.is_null() } + + pub fn downcast(&self) -> Ptr { + self.ptr + .as_any() + .downcast_ref::>() + .unwrap_or_else(|| panic!("not a pointer to {}", std::any::type_name::())) + .clone() + } } impl PartialEq for AnyPtr { diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index 6eab5b34a9..a3bd5599ab 100644 --- a/rule-preprocessor/src/syntactic.rs +++ b/rule-preprocessor/src/syntactic.rs @@ -286,6 +286,14 @@ impl<'a> FragmentCtx<'a> { self.pending_close_parens -= 1; return; } + match token.kind() { + SyntaxKind::COMMENT => return, + SyntaxKind::WHITESPACE if token.text().contains('\n') => { + self.text_buf.push(' '); + return; + } + _ => {} + } if token.kind() == SyntaxKind::IDENT { if let Some(param) = self.params.iter().find(|p| p.name == token.text()) { if param.is_va_args { diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index f12026761c..f5fde68c92 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -17,24 +17,43 @@ fn f2< T1: CppInputIterator, T2: CppIterator, T3: ByteRepr, - T4: CppFrom + ByteRepr, + T4: MoveAssignable + ZeroInitialization, >( a0: T1, a1: T1, a2: T2, -) -> T2 { +) -> T2 +where + LvalueRef: ConvertibleTo, +{ let __first: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); let mut __out = a2; - while ::not_equal(__first.as_pointer(), __last.as_pointer()) { - __out.iter_deref().write(T4::cpp_from(__first.borrow().iter_deref())); + while ::not_equal(__first.as_pointer(), __last.as_pointer()) + { + object!(__value, T4, |__this| ConvertibleTo::convert( + LvalueRef::::bind(__first.borrow().iter_deref()), + __this + )); + MoveAssignable::move_assign( + __out.iter_deref(), + RvalueRef::::bind(__value.as_pointer()), + ); __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out } -fn f3, T2: WeaklyEqualityComparableWith, T3: WeaklyEqualityComparableWith>(a0: T1, a1: T1, a2: Ptr) -> T1 { +fn f3< + T1: CppInputIterator, + T2: WeaklyEqualityComparableWith, + T3: WeaklyEqualityComparableWith, +>( + a0: T1, + a1: T1, + a2: Ptr, +) -> T1 { let __it: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); while ::not_equal(__it.as_pointer(), __last.as_pointer()) @@ -71,7 +90,10 @@ fn f8, T2: LessThanComparable>(a0: T1, a1: T1) -> T1 { let mut __best = __it.borrow().clone(); if ::not_equal(__it.as_pointer(), __last.as_pointer()) { __it.borrow_mut().iter_inc(); - while ::not_equal(__it.as_pointer(), __last.as_pointer()) { + while ::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { if LessThanComparable::less(__best.iter_deref(), __it.borrow().iter_deref()) { __best = __it.borrow().clone(); } @@ -85,7 +107,10 @@ fn f9(a0: Ptr, a1: Ptr) { Swappable::swap(a0, a1) } -fn f10, T2: WeaklyEqualityComparableWith + TriviallyCopyable + ByteRepr>( +fn f10< + T1: CppInputIterator, + T2: WeaklyEqualityComparableWith + TriviallyCopyable + ByteRepr, +>( a0: T1, a1: T1, ) -> T1 { @@ -96,10 +121,18 @@ fn f10, T2: WeaklyEqualityComparableWith + Triviall } else { let mut __write = __it.borrow().clone(); __it.borrow_mut().iter_inc(); - while ::not_equal(__it.as_pointer(), __last.as_pointer()) { - if !WeaklyEqualityComparableWith::equal(__write.iter_deref(), __it.borrow().iter_deref()) { + while ::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { + if !WeaklyEqualityComparableWith::equal( + __write.iter_deref(), + __it.borrow().iter_deref(), + ) { __write.iter_inc(); - __write.iter_deref().write(__it.borrow().iter_deref().read()); + __write + .iter_deref() + .write(__it.borrow().iter_deref().read()); } __it.borrow_mut().iter_inc(); } @@ -151,11 +184,19 @@ where } fn f16(a0: Ptr, a1: Ptr) -> Ptr { - if LessThanComparable::less(a1.clone(), a0.clone()) { a1 } else { a0 } + if LessThanComparable::less(a1.clone(), a0.clone()) { + a1 + } else { + a0 + } } fn f17(a0: Ptr, a1: Ptr) -> Ptr { - if LessThanComparable::less(a0.clone(), a1.clone()) { a1 } else { a0 } + if LessThanComparable::less(a0.clone(), a1.clone()) { + a1 + } else { + a0 + } } fn f18, T2: Swappable>(a0: T1, a1: T1) { diff --git a/rules/algorithm/tgt_unsafe.rs b/rules/algorithm/tgt_unsafe.rs index 67d6dfcf75..9eee9d415a 100644 --- a/rules/algorithm/tgt_unsafe.rs +++ b/rules/algorithm/tgt_unsafe.rs @@ -27,24 +27,49 @@ unsafe fn f1, T2: LessThanComparableUnsafe } } -unsafe fn f2, T2: UnsafeCppIterator, T3, T4: CppFromUnsafe>( +unsafe fn f2< + T1: UnsafeCppInputIterator, + T2: UnsafeCppIterator, + T3, + T4: ZeroInitializationUnsafe + MoveAssignableUnsafe, +>( a0: T1, a1: T1, a2: T2, -) -> T2 { +) -> T2 +where + LvalueRefUnsafe: ConvertibleToUnsafe, +{ let mut __first = a0; let mut __out = a2; while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &a1) { - *__out.iter_deref() = T4::cpp_from(__first.iter_deref()); + object_unsafe!(__value, T4, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::::bind(__first.iter_deref()), + __this + )); + MoveAssignableUnsafe::move_assign( + __out.iter_deref(), + RvalueRefUnsafe::::bind(&raw mut __value), + ); __first.iter_inc(); __out.iter_inc(); } __out } -unsafe fn f3, T2: WeaklyEqualityComparableWithUnsafe, T3: WeaklyEqualityComparableWithUnsafe>(a0: T1, a1: T1, a2: T2) -> T1 { +unsafe fn f3< + T1: UnsafeCppInputIterator, + T2: WeaklyEqualityComparableWithUnsafe, + T3: WeaklyEqualityComparableWithUnsafe, +>( + a0: T1, + a1: T1, + a2: T2, +) -> T1 { let mut __it = a0; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &a2) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &a2) + { __it.iter_inc(); } __it @@ -82,7 +107,10 @@ unsafe fn f8, T2: LessThanComparableUnsafe>(a0: T let mut __it = a0; __it.iter_inc(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { - if LessThanComparableUnsafe::less(__best.iter_deref() as *const _, __it.iter_deref() as *const _) { + if LessThanComparableUnsafe::less( + __best.iter_deref() as *const _, + __it.iter_deref() as *const _, + ) { __best = __it.clone(); } __it.iter_inc(); @@ -97,7 +125,13 @@ unsafe fn f9(a0: *mut T1, a1: *mut T1) { SwappableUnsafe::swap(&mut *__a, __b) } -unsafe fn f10, T2: WeaklyEqualityComparableWithUnsafe + Clone>(a0: T1, a1: T1) -> T1 { +unsafe fn f10< + T1: UnsafeCppInputIterator, + T2: WeaklyEqualityComparableWithUnsafe + Clone, +>( + a0: T1, + a1: T1, +) -> T1 { if WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) { a1 } else { @@ -105,7 +139,8 @@ unsafe fn f10, T2: WeaklyEqualityComparableWithUn let mut __it = a0; __it.iter_inc(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { - if !WeaklyEqualityComparableWithUnsafe::equal(&*__write.iter_deref(), __it.iter_deref()) { + if !WeaklyEqualityComparableWithUnsafe::equal(&*__write.iter_deref(), __it.iter_deref()) + { __write.iter_inc(); *__write.iter_deref() = (*__it.iter_deref()).clone(); } @@ -159,13 +194,21 @@ where unsafe fn f16(a0: *const T1, a1: *const T1) -> *const T1 { let __a: *const _ = a0; let __b: *const _ = a1; - if LessThanComparableUnsafe::less(__b, __a) { __b } else { __a } + if LessThanComparableUnsafe::less(__b, __a) { + __b + } else { + __a + } } unsafe fn f17(a0: *const T1, a1: *const T1) -> *const T1 { let __a: *const _ = a0; let __b: *const _ = a1; - if LessThanComparableUnsafe::less(__a, __b) { __b } else { __a } + if LessThanComparableUnsafe::less(__a, __b) { + __b + } else { + __a + } } unsafe fn f18, T2: SwappableUnsafe>(a0: T1, a1: T1) { diff --git a/rules/any/tgt_refcount.rs b/rules/any/tgt_refcount.rs index ce69df1430..aa95dfe02f 100644 --- a/rules/any/tgt_refcount.rs +++ b/rules/any/tgt_refcount.rs @@ -21,7 +21,10 @@ fn f8(a0: Option>) -> bool { a0.is_some() } -fn f14(a0: &mut Option>, init: cpp_type!("std::decay_t", T1)) -> Ptr { +fn f14( + a0: &mut Option>, + init: cpp_type!("std::decay_t", T1), +) -> Ptr { let __value: Value = Rc::new(RefCell::new(init)); let __ptr = __value.as_pointer(); *a0 = Some(__value); @@ -32,9 +35,11 @@ fn f19(a0: Ptr>>) -> Ptr { if a0.is_null() { Ptr::null() } else { - a0.with(|__a: &Option>| match __a.clone().map(|__r| __r.downcast::>()) { - Some(Ok(__v)) => __v.as_pointer(), - _ => Ptr::null(), + a0.with(|__a: &Option>| { + match __a.clone().map(|__r| __r.downcast::>()) { + Some(Ok(__v)) => __v.as_pointer(), + _ => Ptr::null(), + } }) } } diff --git a/rules/any/tgt_unsafe.rs b/rules/any/tgt_unsafe.rs index 180180cbdc..93c201aa9f 100644 --- a/rules/any/tgt_unsafe.rs +++ b/rules/any/tgt_unsafe.rs @@ -19,13 +19,20 @@ fn f8(a0: Option>) -> bool { a0.is_some() } -fn f14(a0: &mut Option>, init: cpp_type!("std::decay_t", T1)) -> &mut T1 { +fn f14( + a0: &mut Option>, + init: cpp_type!("std::decay_t", T1), +) -> &mut T1 { *a0 = Some(Box::new(init)); a0.as_mut().unwrap().downcast_mut::().unwrap() } unsafe fn f19(a0: *mut Option>) -> *mut T1 { - match a0.as_mut().and_then(|__a| __a.as_mut()).and_then(|__b| __b.downcast_mut::()) { + match a0 + .as_mut() + .and_then(|__a| __a.as_mut()) + .and_then(|__b| __b.downcast_mut::()) + { Some(__v) => __v as *mut T1, None => std::ptr::null_mut(), } diff --git a/rules/array/tgt_refcount.rs b/rules/array/tgt_refcount.rs index e2fe6e3b2c..1d05b8e527 100644 --- a/rules/array/tgt_refcount.rs +++ b/rules/array/tgt_refcount.rs @@ -6,7 +6,9 @@ use std::cell::RefCell; use std::rc::Rc; fn t1() -> Box<[T1]> { - Box::<[T1]>::from(std::array::from_fn::<_, T2, _>(|_| ::default_constructed())) + Box::<[T1]>::from(std::array::from_fn::<_, T2, _>(|_| { + ::default_constructed() + })) } fn t4() -> Ptr { @@ -32,11 +34,12 @@ fn f3(a0: Ptr) -> Ptr { fn f4( a0: Ptr, ) -> Box<[T1]> { - let __v: Value> = - Rc::new(RefCell::new((0..T2).map(|_| T1::zero_init()).collect())); + let __v: Value> = Rc::new(RefCell::new( + (0..T2).map(|_| ZeroInitialization::zero_init()).collect(), + )); let __p: Ptr = __v.decay(); for __i in 0..T2 { - MoveConstructible::move_constructor(__p.offset(__i), RvalueRef::bind(a0.offset(__i))); + Constructor::constructor(__p.offset(__i), (RvalueRef::::bind(a0.offset(__i)),)); } Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -52,7 +55,9 @@ fn f5( } fn f6(a0: Ptr) -> Box<[T1]> { - (0..T2).map(|__i| copy_constructed(a0.offset(__i))).collect() + (0..T2) + .map(|__i| copy_constructed(a0.offset(__i))) + .collect() } fn f7( diff --git a/rules/builtin/tgt_unsafe.rs b/rules/builtin/tgt_unsafe.rs index 5ea1c5389a..5c3dd1fe18 100644 --- a/rules/builtin/tgt_unsafe.rs +++ b/rules/builtin/tgt_unsafe.rs @@ -58,7 +58,9 @@ unsafe fn f14(a0: *mut u8, a1: *const u8, a2: usize) -> *mut u8 { a0 } -fn f15() { std::process::abort() } +fn f15() { + std::process::abort() +} fn f16(a0: u64) -> i32 { a0.leading_zeros() as i32 diff --git a/rules/deque/tgt_unsafe.rs b/rules/deque/tgt_unsafe.rs index 6cbe7d4254..f912228be0 100644 --- a/rules/deque/tgt_unsafe.rs +++ b/rules/deque/tgt_unsafe.rs @@ -58,7 +58,10 @@ unsafe fn f9(a0: &mut Vec) -> Vec { move_constructed_unsafe(&mut *a0) } -unsafe fn f10<'a, T1: CopyConstructibleUnsafe>(a0: &'a mut Vec, a1: *const Vec) -> &'a mut Vec { +unsafe fn f10<'a, T1: CopyConstructibleUnsafe>( + a0: &'a mut Vec, + a1: *const Vec, +) -> &'a mut Vec { CopyAssignableUnsafe::copy_assign(&raw mut *a0, LvalueRefUnsafe::bind(a1)); a0 } diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index 55a4ffcaed..4f15125eb3 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -185,29 +185,42 @@ macro_rules! uninhabited_iterator { } } - impl crate::MoveConstructible for $name { - fn move_constructor(_: Ptr, src: crate::RvalueRef) { + impl crate::Constructor<(crate::RvalueRef,)> for $name { + fn constructor(_: Ptr, (src,): (crate::RvalueRef,)) { src.as_pointer().with(|it| it.never()) } } - impl crate::CopyConstructible for $name { - fn copy_constructor(_: Ptr, src: crate::LvalueRef>) { + impl crate::Constructor<(crate::LvalueRef>,)> for $name { + fn constructor(_: Ptr, (src,): (crate::LvalueRef>,)) { src.as_pointer().with(|it| it.never()) } } - impl crate::MoveConstructibleUnsafe for $name { - unsafe fn move_constructor(_: *mut Self, src: crate::RvalueRefUnsafe) { + impl crate::ConstructorUnsafe<(crate::RvalueRefUnsafe,)> for $name { + unsafe fn constructor(_: *mut Self, (src,): (crate::RvalueRefUnsafe,)) { unsafe { (*src.as_ptr()).never() } } } - impl crate::CopyConstructibleUnsafe for $name { - unsafe fn copy_constructor(_: *mut Self, src: crate::LvalueRefUnsafe>) { + impl crate::ConstructorUnsafe<(crate::LvalueRefUnsafe>,)> + for $name + { + unsafe fn constructor( + _: *mut Self, + (src,): (crate::LvalueRefUnsafe>,), + ) { unsafe { (*src.as_const_ptr()).never() } } } + + impl crate::Destructible for $name { + fn destroy(_: Ptr) {} + } + + impl crate::DestructibleUnsafe for $name { + unsafe fn destroy(_: *mut Self) {} + } }; } diff --git a/rules/iterator_category/tgt_refcount.rs b/rules/iterator_category/tgt_refcount.rs index ee6d7bb7ea..71e13deeba 100644 --- a/rules/iterator_category/tgt_refcount.rs +++ b/rules/iterator_category/tgt_refcount.rs @@ -135,6 +135,13 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { a0 } -fn f27 + WeaklyEqualityComparableWith, T2: CppInputIterator + WeaklyEqualityComparableWith, T3>(a0: Ptr, a1: Ptr) -> bool { +fn f27< + T1: CppInputIterator + WeaklyEqualityComparableWith, + T2: CppInputIterator + WeaklyEqualityComparableWith, + T3, +>( + a0: Ptr, + a1: Ptr, +) -> bool { WeaklyEqualityComparableWith::equal(a0, a1) } diff --git a/rules/iterator_category/tgt_unsafe.rs b/rules/iterator_category/tgt_unsafe.rs index 9e13b027fb..aadacbf262 100644 --- a/rules/iterator_category/tgt_unsafe.rs +++ b/rules/iterator_category/tgt_unsafe.rs @@ -135,6 +135,13 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { a0 } -unsafe fn f27 + WeaklyEqualityComparableWithUnsafe, T2: UnsafeCppInputIterator + WeaklyEqualityComparableWithUnsafe, T3>(a0: T1, a1: T2) -> bool { +unsafe fn f27< + T1: UnsafeCppInputIterator + WeaklyEqualityComparableWithUnsafe, + T2: UnsafeCppInputIterator + WeaklyEqualityComparableWithUnsafe, + T3, +>( + a0: T1, + a1: T2, +) -> bool { WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) } diff --git a/rules/map/shim.rs b/rules/map/shim.rs index 9529c345e0..e77027f1dc 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -8,10 +8,11 @@ use std::ops::Bound; use std::rc::{Rc, Weak}; use crate::{ - AsPointer, BidirectionalIterator, ByteRepr, Const, CopyAssignable, CopyAssignableUnsafe, - CopyConstructible, CopyConstructibleUnsafe, LessThanComparable, LessThanComparableUnsafe, - LvalueRef, LvalueRefUnsafe, Ptr, UnsafeBidirectionalIterator, Value, ZeroInitialization, - copy_constructed, copy_constructed_unsafe, cpp_cmp, + AsPointer, BidirectionalIterator, ByteRepr, Const, Constructor, ConstructorUnsafe, + CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, + LessThanComparable, LessThanComparableUnsafe, LvalueRef, LvalueRefUnsafe, Ptr, + UnsafeBidirectionalIterator, Value, ZeroInitialization, copy_constructed, + copy_constructed_unsafe, cpp_cmp, }; impl ByteRepr for BTreeMap {} @@ -110,15 +111,21 @@ impl ByteRepr for Map {} // A map is copied by copying its keys and values, each with its copy // constructor. -impl CopyConstructible for Map, Value)> +impl Constructor<(LvalueRef>,)> for Map, Value)> where K: LessThanComparable + CopyConstructible + ZeroInitialization + 'static, V: CopyConstructible + ZeroInitialization + 'static, { - fn copy_constructor(this: Ptr, src: LvalueRef>) { + fn constructor(this: Ptr, (src,): (LvalueRef>,)) { this.write(Self::copied(src.as_pointer())); } +} +impl Map, Value)> +where + K: LessThanComparable + CopyConstructible + ZeroInitialization + 'static, + V: CopyConstructible + ZeroInitialization + 'static, +{ fn copied(src: Ptr) -> Self { let mut map = Self::default(); let mut prev = map.header.clone(); @@ -457,9 +464,9 @@ impl - CopyConstructibleUnsafe for UnsafeMap + ConstructorUnsafe<(LvalueRefUnsafe>,)> for UnsafeMap { - unsafe fn copy_constructor(this: *mut Self, src: LvalueRefUnsafe>) { + unsafe fn constructor(this: *mut Self, (src,): (LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); unsafe { std::ptr::write(this, (*src).copied()) } } @@ -668,8 +675,39 @@ impl UnsafeMap { } crate::constructor::impl_copy_by_clone!( BTreeMap); +crate::constructor::impl_copy_construct_by_clone!( BTreeMap); crate::constructor::impl_move_by_take!( BTreeMap, Map, UnsafeMap, ); + +// TODO: destroy the elements; this destructor does nothing. +impl crate::Destructible for BTreeMap { + fn destroy(_this: Ptr) {} +} + +// TODO: destroy the elements; this destructor does nothing. +impl crate::DestructibleUnsafe for BTreeMap { + unsafe fn destroy(_this: *mut Self) {} +} + +// TODO: destroy the elements; this destructor does nothing. +impl crate::Destructible for Map { + fn destroy(_this: Ptr) {} +} + +// TODO: destroy the elements; this destructor does nothing. +impl crate::DestructibleUnsafe for Map { + unsafe fn destroy(_this: *mut Self) {} +} + +// TODO: destroy the elements; this destructor does nothing. +impl crate::Destructible for UnsafeMap { + fn destroy(_this: Ptr) {} +} + +// TODO: destroy the elements; this destructor does nothing. +impl crate::DestructibleUnsafe for UnsafeMap { + unsafe fn destroy(_this: *mut Self) {} +} diff --git a/rules/map/tgt_refcount.rs b/rules/map/tgt_refcount.rs index e8f419967e..ceafc9f103 100644 --- a/rules/map/tgt_refcount.rs +++ b/rules/map/tgt_refcount.rs @@ -9,7 +9,10 @@ fn t1() -> Map, Value)> { Map::new() } -fn f1( +fn f1< + T1: LessThanComparable + ZeroInitialization + CopyConstructible + 'static, + T2: DefaultConstructible + ZeroInitialization + 'static, +>( a0: &mut Map, Value)>, a1: Ptr, ) -> Ptr { @@ -31,13 +34,19 @@ fn f5() -> Map, Value)> { Map::new() } -fn f6( +fn f6< + T1: LessThanComparable + CopyConstructible + ZeroInitialization + 'static, + T2: CopyConstructible + ZeroInitialization + 'static, +>( a0: Ptr, Value)>>, ) -> Map, Value)> { copy_constructed(a0) } -fn f7(a0: &mut Map, Value)>, a1: Ptr) -> Ptr { +fn f7( + a0: &mut Map, Value)>, + a1: Ptr, +) -> Ptr { a0.get(&a1).expect("out of range!").borrow().1.as_pointer() } @@ -48,35 +57,55 @@ fn f8::default_constructed()) } -fn f9(a0: Ptr, Value)>>) -> BidirectionalIterator<(Value, Value)> { +fn f9( + a0: Ptr, Value)>>, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.end()) } -fn f10(a0: Ptr, Value)>>, a1: Ptr) -> BidirectionalIterator<(Value, Value)> { +fn f10( + a0: Ptr, Value)>>, + a1: Ptr, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.find(&a1)) } -fn f12(a0: Ptr, Value)>>) -> BidirectionalIterator<(Value, Value)> { +fn f12( + a0: Ptr, Value)>>, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.begin()) } -fn f14(a0: Ptr, Value)>>) -> BidirectionalIterator<(Value, Value)> { +fn f14( + a0: Ptr, Value)>>, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.end()) } -fn f15(a0: &mut Map, Value)>, a1: Ptr) -> Ptr { +fn f15( + a0: &mut Map, Value)>, + a1: Ptr, +) -> Ptr { a0.get(&a1).expect("out of range!").borrow().1.as_pointer() } -fn f17(a0: Ptr, Value)>>, a1: Ptr) -> BidirectionalIterator<(Value, Value)> { +fn f17( + a0: Ptr, Value)>>, + a1: Ptr, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.find(&a1)) } -fn f24(a0: Ptr, Value)>>) -> Map, Value)> { +fn f24( + a0: Ptr, Value)>>, +) -> Map, Value)> { a0.with_mut(|__m: &mut Map, Value)>| std::mem::take(__m)) } -fn f25<'a, T1: 'static, T2: 'static>(a0: &'a mut Map, Value)>, a1: Ptr, Value)>>) -> &'a mut Map, Value)> +fn f25<'a, T1: 'static, T2: 'static>( + a0: &'a mut Map, Value)>, + a1: Ptr, Value)>>, +) -> &'a mut Map, Value)> where Map, Value)>: MoveConstructible + ZeroInitialization, { @@ -84,7 +113,10 @@ where a0 } -fn f26( +fn f26< + T1: LessThanComparable + CopyConstructible + ZeroInitialization + 'static, + T2: CopyConstructible + ZeroInitialization + 'static, +>( a0: &mut Map, Value)>, a1: Ptr, Value)>>, ) -> &mut Map, Value)> { @@ -99,26 +131,43 @@ fn f27( Map::erase(a0, &a1) } -fn f28(a0: Ptr, Value)>>, a1: Ptr) -> usize { +fn f28( + a0: Ptr, Value)>>, + a1: Ptr, +) -> usize { Map::erase_key(a0, &a1) } -fn f29(a0: Ptr, Value)>>) -> BidirectionalIterator<(Value, Value)> { +fn f29( + a0: Ptr, Value)>>, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.begin()) } fn f67( a0: Ptr, Value)>>, - init: cpp_type!("typename std::map::value_type", (Value, Value)), -) -> (Value, Value)>>, Value) { + init: cpp_type!( + "typename std::map::value_type", + (Value, Value) + ), +) -> ( + Value, Value)>>, + Value, +) { let (__it, __inserted) = Map::emplace(a0, &init.0.as_pointer(), || init); - (Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted))) + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) } fn f68( a0: Ptr, Value)>>, a1: BidirectionalIterator<(Value, Value)>, - init: cpp_type!("typename std::map::value_type", (Value, Value)), + init: cpp_type!( + "typename std::map::value_type", + (Value, Value) + ), ) -> BidirectionalIterator<(Value, Value)> { let _ = a1; Map::emplace(a0, &init.0.as_pointer(), || init).0 @@ -128,9 +177,18 @@ fn f73, Value)>>, a1: Ptr, init: T2, -) -> (Value, Value)>>, Value) { +) -> ( + Value, Value)>>, + Value, +) { let (__it, __inserted) = Map::emplace(a0, &a1, || { - (Rc::new(RefCell::new(copy_constructed(a1.clone()))), Rc::new(RefCell::new(init))) + ( + Rc::new(RefCell::new(copy_constructed(a1.clone()))), + Rc::new(RefCell::new(init)), + ) }); - (Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted))) + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) } diff --git a/rules/map/tgt_unsafe.rs b/rules/map/tgt_unsafe.rs index e3194d1e71..e235a8b549 100644 --- a/rules/map/tgt_unsafe.rs +++ b/rules/map/tgt_unsafe.rs @@ -19,7 +19,13 @@ fn t6() -> T2 { unimplemented!() } -unsafe fn f1(a0: &mut UnsafeMap, a1: T1) -> &mut T2 { +unsafe fn f1< + T1: LessThanComparableUnsafe + CopyConstructibleUnsafe, + T2: DefaultConstructibleUnsafe, +>( + a0: &mut UnsafeMap, + a1: T1, +) -> &mut T2 { &mut (*a0.subscript(&a1, || ::default_constructed())) } @@ -27,7 +33,10 @@ fn f2(a0: UnsafeMap) -> usize { a0.len() } -fn f3(a0: &mut UnsafeMap, a1: UnsafeBidirectionalIterator<(T1, T2)>) -> UnsafeBidirectionalIterator<(T1, T2)> { +fn f3( + a0: &mut UnsafeMap, + a1: UnsafeBidirectionalIterator<(T1, T2)>, +) -> UnsafeBidirectionalIterator<(T1, T2)> { a0.erase(&a1) } @@ -35,23 +44,41 @@ fn f5() -> UnsafeMap { UnsafeMap::new() } -unsafe fn f6(a0: *const UnsafeMap) -> UnsafeMap { +unsafe fn f6< + T1: LessThanComparableUnsafe + CopyConstructibleUnsafe, + T2: CopyConstructibleUnsafe, +>( + a0: *const UnsafeMap, +) -> UnsafeMap { copy_constructed_unsafe(a0) } -unsafe fn f7(a0: &mut UnsafeMap, a1: T1) -> *const T2 { +unsafe fn f7( + a0: &mut UnsafeMap, + a1: T1, +) -> *const T2 { &raw const (*a0.get(&a1).expect("out of range!")).1 } -unsafe fn f8(a0: &mut UnsafeMap, a1: *mut T1) -> &mut T2 { - &mut (*a0.subscript_move(a1, |__k| cpp_move_unsafe!(__k), || ::default_constructed())) +unsafe fn f8( + a0: &mut UnsafeMap, + a1: *mut T1, +) -> &mut T2 { + &mut (*a0.subscript_move( + a1, + |__k| cpp_move_unsafe!(__k), + || ::default_constructed(), + )) } fn f9(a0: UnsafeMap) -> UnsafeBidirectionalIterator<(T1, T2)> { a0.end() } -fn f10(a0: &mut UnsafeMap, a1: T1) -> UnsafeBidirectionalIterator<(T1, T2)> { +fn f10( + a0: &mut UnsafeMap, + a1: T1, +) -> UnsafeBidirectionalIterator<(T1, T2)> { a0.find(&a1) } @@ -63,11 +90,17 @@ fn f14(a0: &mut UnsafeMap) -> UnsafeBidirectionalIterator< a0.end() } -unsafe fn f15(a0: &mut UnsafeMap, a1: T1) -> *const T2 { +unsafe fn f15( + a0: &mut UnsafeMap, + a1: T1, +) -> *const T2 { &raw const (*a0.get(&a1).expect("out of range!")).1 } -fn f17(a0: UnsafeMap, a1: T1) -> UnsafeBidirectionalIterator<(T1, T2)> { +fn f17( + a0: UnsafeMap, + a1: T1, +) -> UnsafeBidirectionalIterator<(T1, T2)> { a0.find(&a1) } @@ -75,12 +108,22 @@ unsafe fn f24(a0: &mut UnsafeMap) -> UnsafeMap(a0: &'a mut UnsafeMap, a1: &mut UnsafeMap) -> &'a mut UnsafeMap { +unsafe fn f25<'a, T1, T2>( + a0: &'a mut UnsafeMap, + a1: &mut UnsafeMap, +) -> &'a mut UnsafeMap { *a0 = move_constructed_unsafe(&mut *a1); a0 } -unsafe fn f26<'a, T1: LessThanComparableUnsafe + CopyConstructibleUnsafe, T2: CopyConstructibleUnsafe>(a0: &'a mut UnsafeMap, a1: *const UnsafeMap) -> &'a mut UnsafeMap { +unsafe fn f26< + 'a, + T1: LessThanComparableUnsafe + CopyConstructibleUnsafe, + T2: CopyConstructibleUnsafe, +>( + a0: &'a mut UnsafeMap, + a1: *const UnsafeMap, +) -> &'a mut UnsafeMap { CopyAssignableUnsafe::copy_assign(&raw mut *a0, LvalueRefUnsafe::bind(a1)); a0 } diff --git a/rules/pair/src_cxx23.cpp b/rules/pair/src_cxx23.cpp new file mode 100644 index 0000000000..fed3a15a2c --- /dev/null +++ b/rules/pair/src_cxx23.cpp @@ -0,0 +1,13 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include +#include + +template < + typename T1, typename T2, typename T3, typename T4, + typename = typename std::enable_if::value && + std::is_same::value)>::type> +std::pair f34(std::pair &a0) { + return std::pair(a0); +} diff --git a/rules/pair/tgt_refcount.rs b/rules/pair/tgt_refcount.rs index 91712d0c89..1cbd23af3e 100644 --- a/rules/pair/tgt_refcount.rs +++ b/rules/pair/tgt_refcount.rs @@ -5,7 +5,10 @@ use libcc2rs::*; use std::cell::RefCell; use std::rc::Rc; -fn t1() -> (Value, Value) { +fn t1< + T1: DefaultConstructible + ZeroInitialization, + T2: DefaultConstructible + ZeroInitialization, +>() -> (Value, Value) { ( Rc::new(RefCell::new(::default_constructed())), Rc::new(RefCell::new(::default_constructed())), @@ -66,94 +69,213 @@ fn f16(a0: (Value, Value)) -> Value { a0.0 } -fn f17(a0: (Value, Value)) -> Ptr<<(T2, T3) as TupleElement>::Type> +fn f17( + a0: (Value, Value), +) -> Ptr<<(T2, T3) as TupleElement>::Type> where (T2, T3): TupleElementValue, Value)>, { a0.get_value::().as_pointer() } -fn f19(a0: (Value, Value)) -> Ptr<<(T2, T3) as TupleElement>::Type> +fn f19( + a0: (Value, Value), +) -> Ptr<<(T2, T3) as TupleElement>::Type> where (T2, T3): TupleElementValue, Value)>, { a0.get_value::().as_pointer() } -fn f21(a0: (Value, Value)) -> Ptr<<(T2, T3) as TupleElement>::Type> +fn f21( + a0: (Value, Value), +) -> Ptr<<(T2, T3) as TupleElement>::Type> where (T2, T3): TupleElementValue, Value)>, { a0.get_value::().as_pointer() } -fn f23, T2: CppFrom, T3, T4>( +fn f23< + T1: ConstructibleFrom<(RvalueRef,)> + ZeroInitialization + MoveConstructible, + T2: ConstructibleFrom<(RvalueRef,)> + ZeroInitialization + MoveConstructible, + T3: ByteRepr, + T4: ByteRepr, +>( a0: &mut (Value, Value), ) -> (Value, Value) { + object!(__first, T1, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind(a0.0.as_pointer()),) + )); + object!(__second, T2, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind(a0.1.as_pointer()),) + )); ( - Rc::new(RefCell::new(T1::cpp_from_move(a0.0.as_pointer()))), - Rc::new(RefCell::new(T2::cpp_from_move(a0.1.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), ) } -fn f24, T2: CppFrom, T3, T4>( +fn f24< + T1: ConstructibleFrom<(LvalueRef>,)> + ZeroInitialization + MoveConstructible, + T2: ConstructibleFrom<(LvalueRef>,)> + ZeroInitialization + MoveConstructible, + T3: ByteRepr, + T4: ByteRepr, +>( a0: (Value, Value), ) -> (Value, Value) { + object!(__first, T1, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind(a0.0.as_pointer()),) + )); + object!(__second, T2, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind(a0.1.as_pointer()),) + )); ( - Rc::new(RefCell::new(T1::cpp_from(a0.0.as_pointer()))), - Rc::new(RefCell::new(T2::cpp_from(a0.1.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), ) } -fn f25 + ByteRepr, T2: CppFrom + ByteRepr, T3, T4>( +fn f25< + T1: ZeroInitialization + MoveAssignable, + T2: ZeroInitialization + MoveAssignable, + T3: ByteRepr, + T4: ByteRepr, +>( a0: &mut (Value, Value), a1: (Value, Value), -) -> &mut (Value, Value) { - let __first = T1::cpp_from(a1.0.as_pointer()); - let __second = T2::cpp_from(a1.1.as_pointer()); - *a0.0.borrow_mut() = __first; - *a0.1.borrow_mut() = __second; +) -> &mut (Value, Value) +where + LvalueRef>: ConvertibleTo, + LvalueRef>: ConvertibleTo, +{ + object!(__first, T1, |__this| ConvertibleTo::convert( + LvalueRef::>::bind(a1.0.as_pointer()), + __this + )); + object!(__second, T2, |__this| ConvertibleTo::convert( + LvalueRef::>::bind(a1.1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + a0.0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + a0.1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); a0 } -fn f26<'a, T1: CppFrom + ByteRepr, T2: CppFrom + ByteRepr, T3, T4>( +fn f26< + 'a, + T1: ZeroInitialization + MoveAssignable, + T2: ZeroInitialization + MoveAssignable, + T3: ByteRepr, + T4: ByteRepr, +>( a0: &'a mut (Value, Value), a1: &mut (Value, Value), -) -> &'a mut (Value, Value) { - let __first = T1::cpp_from_move(a1.0.as_pointer()); - let __second = T2::cpp_from_move(a1.1.as_pointer()); - *a0.0.borrow_mut() = __first; - *a0.1.borrow_mut() = __second; +) -> &'a mut (Value, Value) +where + RvalueRef: ConvertibleTo, + RvalueRef: ConvertibleTo, +{ + object!(__first, T1, |__this| ConvertibleTo::convert( + RvalueRef::::bind(a1.0.as_pointer()), + __this + )); + object!(__second, T2, |__this| ConvertibleTo::convert( + RvalueRef::::bind(a1.1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + a0.0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + a0.1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); a0 } -fn f27(a0: (Value, Value)) -> Ptr<<(T2, T3) as TupleElement>::Type> +fn f27( + a0: (Value, Value), +) -> Ptr<<(T2, T3) as TupleElement>::Type> where (T2, T3): TupleElementValue, Value)>, { a0.get_value::().as_pointer() } -fn f28, T2: WeaklyEqualityComparableWith>(a0: (Value, Value), a1: (Value, Value)) -> bool { - !(WeaklyEqualityComparableWith::equal(a0.0.as_pointer(), a1.0.as_pointer()) && WeaklyEqualityComparableWith::equal(a0.1.as_pointer(), a1.1.as_pointer())) +fn f28, T2: WeaklyEqualityComparableWith>( + a0: (Value, Value), + a1: (Value, Value), +) -> bool { + !(WeaklyEqualityComparableWith::equal(a0.0.as_pointer(), a1.0.as_pointer()) + && WeaklyEqualityComparableWith::equal(a0.1.as_pointer(), a1.1.as_pointer())) +} + +fn f34< + T1: ConstructibleFrom<(LvalueRef,)> + ZeroInitialization + MoveConstructible, + T2: ConstructibleFrom<(LvalueRef,)> + ZeroInitialization + MoveConstructible, + T3: ByteRepr, + T4: ByteRepr, +>( + a0: &mut (Value, Value), +) -> (Value, Value) { + object!(__first, T1, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::::bind(a0.0.as_pointer()),) + )); + object!(__second, T2, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::::bind(a0.1.as_pointer()),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) } -fn f29(a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>) -> bool { +fn f29( + a0: Ptr<(Value, Value)>, + a1: Ptr<(Value, Value)>, +) -> bool { LessThanComparable::less(a0, a1) } -fn f30(a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>) -> bool { +fn f30( + a0: Ptr<(Value, Value)>, + a1: Ptr<(Value, Value)>, +) -> bool { !LessThanComparable::less(a1, a0) } -fn f31(a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>) -> bool { +fn f31( + a0: Ptr<(Value, Value)>, + a1: Ptr<(Value, Value)>, +) -> bool { LessThanComparable::less(a1, a0) } -fn f32(a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>) -> bool { +fn f32( + a0: Ptr<(Value, Value)>, + a1: Ptr<(Value, Value)>, +) -> bool { !LessThanComparable::less(a0, a1) } -fn f33, T2: WeaklyEqualityComparableWith>(a0: (Value, Value), a1: (Value, Value)) -> bool { - WeaklyEqualityComparableWith::equal(a0.0.as_pointer(), a1.0.as_pointer()) && WeaklyEqualityComparableWith::equal(a0.1.as_pointer(), a1.1.as_pointer()) +fn f33, T2: WeaklyEqualityComparableWith>( + a0: (Value, Value), + a1: (Value, Value), +) -> bool { + WeaklyEqualityComparableWith::equal(a0.0.as_pointer(), a1.0.as_pointer()) + && WeaklyEqualityComparableWith::equal(a0.1.as_pointer(), a1.1.as_pointer()) } diff --git a/rules/pair/tgt_unsafe.rs b/rules/pair/tgt_unsafe.rs index cac4001e53..0a41887c0e 100644 --- a/rules/pair/tgt_unsafe.rs +++ b/rules/pair/tgt_unsafe.rs @@ -15,8 +15,13 @@ fn t3() -> T2 { unimplemented!() } -unsafe fn f2(a0: *const (T1, T2)) -> (T1, T2) { - (copy_constructed_unsafe(&raw const (*a0).0), copy_constructed_unsafe(&raw const (*a0).1)) +unsafe fn f2( + a0: *const (T1, T2), +) -> (T1, T2) { + ( + copy_constructed_unsafe(&raw const (*a0).0), + copy_constructed_unsafe(&raw const (*a0).1), + ) } fn f7(a0: T1, a1: T2) -> (T1, T2) { (a0, a1) @@ -32,13 +37,19 @@ unsafe fn f12(a0: &mut (T1, T2)) -> (T1, T2) { (cpp_move_unsafe!(&mut a0.0), cpp_move_unsafe!(&mut a0.1)) } -unsafe fn f13<'a, T1: CopyAssignableUnsafe, T2: CopyAssignableUnsafe>(a0: &'a mut (T1, T2), a1: *const (T1, T2)) -> &'a mut (T1, T2) { +unsafe fn f13<'a, T1: CopyAssignableUnsafe, T2: CopyAssignableUnsafe>( + a0: &'a mut (T1, T2), + a1: *const (T1, T2), +) -> &'a mut (T1, T2) { assign_unsafe!(a0.0 = (*a1).0); assign_unsafe!(a0.1 = (*a1).1); a0 } -unsafe fn f14<'a, T1: MoveAssignableUnsafe, T2: MoveAssignableUnsafe>(a0: &'a mut (T1, T2), a1: &mut (T1, T2)) -> &'a mut (T1, T2) { +unsafe fn f14<'a, T1: MoveAssignableUnsafe, T2: MoveAssignableUnsafe>( + a0: &'a mut (T1, T2), + a1: &mut (T1, T2), +) -> &'a mut (T1, T2) { assign_unsafe!(a0.0 = RvalueRefUnsafe(a1.0)); assign_unsafe!(a0.1 = RvalueRefUnsafe(a1.1)); a0 @@ -73,21 +84,115 @@ where &mut *a0.get_mut::() } -unsafe fn f23, T2: CppFromUnsafe, T3, T4>(a0: &mut (T3, T4)) -> (T1, T2) { - (T1::cpp_from_move(&mut a0.0), T2::cpp_from_move(&mut a0.1)) +unsafe fn f23< + T1: ConstructibleFromUnsafe<(RvalueRefUnsafe,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T2: ConstructibleFromUnsafe<(RvalueRefUnsafe,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T3, + T4, +>( + a0: &mut (T3, T4), +) -> (T1, T2) { + object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut a0.0),) + )); + object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut a0.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) } -unsafe fn f24, T2: CppFromUnsafe, T3, T4>(a0: &(T3, T4)) -> (T1, T2) { - (T1::cpp_from(&a0.0), T2::cpp_from(&a0.1)) +unsafe fn f24< + T1: ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T2: ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T3, + T4, +>( + a0: &(T3, T4), +) -> (T1, T2) { + object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const a0.0),) + )); + object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const a0.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) } -unsafe fn f25<'a, T1: CppFromUnsafe, T2: CppFromUnsafe, T3, T4>(a0: &'a mut (T1, T2), a1: &(T3, T4)) -> &'a mut (T1, T2) { - *a0 = (T1::cpp_from(&a1.0), T2::cpp_from(&a1.1)); +unsafe fn f25< + 'a, + T1: ZeroInitializationUnsafe + MoveAssignableUnsafe, + T2: ZeroInitializationUnsafe + MoveAssignableUnsafe, + T3, + T4, +>( + a0: &'a mut (T1, T2), + a1: &(T3, T4), +) -> &'a mut (T1, T2) +where + LvalueRefUnsafe>: ConvertibleToUnsafe, + LvalueRefUnsafe>: ConvertibleToUnsafe, +{ + object_unsafe!(__first, T1, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const a1.0), + __this + )); + object_unsafe!(__second, T2, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const a1.1), + __this + )); + MoveAssignableUnsafe::move_assign(&raw mut a0.0, RvalueRefUnsafe::::bind(&raw mut __first)); + MoveAssignableUnsafe::move_assign( + &raw mut a0.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); a0 } -unsafe fn f26<'a, T1: CppFromUnsafe, T2: CppFromUnsafe, T3, T4>(a0: &'a mut (T1, T2), a1: &mut (T3, T4)) -> &'a mut (T1, T2) { - *a0 = (T1::cpp_from_move(&mut a1.0), T2::cpp_from_move(&mut a1.1)); +unsafe fn f26< + 'a, + T1: ZeroInitializationUnsafe + MoveAssignableUnsafe, + T2: ZeroInitializationUnsafe + MoveAssignableUnsafe, + T3, + T4, +>( + a0: &'a mut (T1, T2), + a1: &mut (T3, T4), +) -> &'a mut (T1, T2) +where + RvalueRefUnsafe: ConvertibleToUnsafe, + RvalueRefUnsafe: ConvertibleToUnsafe, +{ + object_unsafe!(__first, T1, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut a1.0), + __this + )); + object_unsafe!(__second, T2, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut a1.1), + __this + )); + MoveAssignableUnsafe::move_assign(&raw mut a0.0, RvalueRefUnsafe::::bind(&raw mut __first)); + MoveAssignableUnsafe::move_assign( + &raw mut a0.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); a0 } @@ -98,26 +203,78 @@ where &*a0.get::() } -unsafe fn f28, T2: WeaklyEqualityComparableWithUnsafe>(a0: (T1, T2), a1: (T1, T2)) -> bool { - !(WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1)) +unsafe fn f28< + T1: WeaklyEqualityComparableWithUnsafe, + T2: WeaklyEqualityComparableWithUnsafe, +>( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { + !(WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) + && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1)) } -unsafe fn f29(a0: (T1, T2), a1: (T1, T2)) -> bool { +unsafe fn f29( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { LessThanComparableUnsafe::less(&a0, &a1) } -unsafe fn f30(a0: (T1, T2), a1: (T1, T2)) -> bool { +unsafe fn f30( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { !LessThanComparableUnsafe::less(&a1, &a0) } -unsafe fn f31(a0: (T1, T2), a1: (T1, T2)) -> bool { +unsafe fn f31( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { LessThanComparableUnsafe::less(&a1, &a0) } -unsafe fn f32(a0: (T1, T2), a1: (T1, T2)) -> bool { +unsafe fn f32( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { !LessThanComparableUnsafe::less(&a0, &a1) } -unsafe fn f33, T2: WeaklyEqualityComparableWithUnsafe>(a0: (T1, T2), a1: (T1, T2)) -> bool { - WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1) +unsafe fn f33< + T1: WeaklyEqualityComparableWithUnsafe, + T2: WeaklyEqualityComparableWithUnsafe, +>( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { + WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) + && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1) +} + +unsafe fn f34< + T1: ConstructibleFromUnsafe<(LvalueRefUnsafe,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T2: ConstructibleFromUnsafe<(LvalueRefUnsafe,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T3, + T4, +>( + a0: &mut (T3, T4), +) -> (T1, T2) { + object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::::bind(&raw mut a0.0),) + )); + object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::::bind(&raw mut a0.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) } diff --git a/rules/string/tgt_refcount.rs b/rules/string/tgt_refcount.rs index 0bf2871b62..e935317108 100644 --- a/rules/string/tgt_refcount.rs +++ b/rules/string/tgt_refcount.rs @@ -132,7 +132,8 @@ fn f2(a0: Vec) -> usize { fn f8(a0: std::fs::File, a1: std::fs::File) -> Vec { use std::io::Read; let mut __bytes: Vec = Vec::new(); - (&a0).read_to_end(&mut __bytes) + (&a0) + .read_to_end(&mut __bytes) .expect("couldn't read the file"); __bytes.push(0); CChar::from_byte_vec(__bytes) diff --git a/rules/string/tgt_unsafe.rs b/rules/string/tgt_unsafe.rs index 74b4cc5cd5..bae4283701 100644 --- a/rules/string/tgt_unsafe.rs +++ b/rules/string/tgt_unsafe.rs @@ -46,7 +46,11 @@ unsafe fn f3(a0: Vec, a1: *const libc::c_char) -> Vec, a1: *mut libc::c_char, a2: usize) -> &mut Vec { +unsafe fn f4( + a0: &mut Vec, + a1: *mut libc::c_char, + a2: usize, +) -> &mut Vec { a0.splice(a0.len().saturating_sub(1)..a0.len(), { let mut v = ::std::slice::from_raw_parts(a1, a2).to_vec(); v.push(0); @@ -73,7 +77,8 @@ use std::io::Read; fn f8(a0: std::fs::File, a1: std::fs::File) -> Vec { let mut __bytes: Vec = Vec::new(); - (&a0).read_to_end(&mut __bytes) + (&a0) + .read_to_end(&mut __bytes) .expect("couldn't read the file"); let mut __buf: Vec = __bytes.iter().map(|&b| b as libc::c_char).collect(); __buf.push(0); @@ -108,10 +113,7 @@ unsafe fn f14( a3: *const libc::c_char, a4: usize, ) -> &mut Vec { - a0.splice( - a1..a1 + a2, - ::std::slice::from_raw_parts(a3, a4).to_vec(), - ); + a0.splice(a1..a1 + a2, ::std::slice::from_raw_parts(a3, a4).to_vec()); a0 } unsafe fn f15(a0: &mut Vec) -> UnsafeRandomAccessIterator { @@ -190,7 +192,10 @@ fn f29(a0: &mut Vec, a1: Vec) -> &mut Vec(a0: &'a mut Vec, a1: &mut Vec) -> &'a mut Vec { +unsafe fn f30<'a>( + a0: &'a mut Vec, + a1: &mut Vec, +) -> &'a mut Vec { *a0 = move_constructed_unsafe(&mut *a1); a0 } diff --git a/rules/unique_ptr/shim.rs b/rules/unique_ptr/shim.rs index 52653abb93..d58bd8c070 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -2,17 +2,27 @@ // Distributed under the MIT license that can be found in the LICENSE file. use crate::{ - ByteRepr, MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, - Ptr, RvalueRef, RvalueRefUnsafe, Swappable, SwappableUnsafe, Value, + ByteRepr, Constructor, ConstructorUnsafe, MoveAssignable, MoveAssignableUnsafe, Ptr, RvalueRef, + RvalueRefUnsafe, Swappable, SwappableUnsafe, Value, }; pub trait CppArray {} -impl MoveConstructible for Option> +// TODO: destroy the owned object; this destructor does nothing. +impl crate::Destructible for Option> { + fn destroy(_this: Ptr) {} +} + +// TODO: destroy the owned object; this destructor does nothing. +impl crate::DestructibleUnsafe for Option> { + unsafe fn destroy(_this: *mut Self) {} +} + +impl Constructor<(RvalueRef,)> for Option> where Self: ByteRepr, { - fn move_constructor(this: Ptr, src: RvalueRef) { + fn constructor(this: Ptr, (src,): (RvalueRef,)) { let value = src.as_pointer().with_mut(Option::take); this.with_mut(|dst| *dst = value); } @@ -29,8 +39,8 @@ where } } -impl MoveConstructibleUnsafe for Option> { - unsafe fn move_constructor(this: *mut Self, src: RvalueRefUnsafe) { +impl ConstructorUnsafe<(RvalueRefUnsafe,)> for Option> { + unsafe fn constructor(this: *mut Self, (src,): (RvalueRefUnsafe,)) { let src = src.as_ptr(); unsafe { std::ptr::write(this, (*src).take()) } } diff --git a/rules/unique_ptr/tgt_refcount.rs b/rules/unique_ptr/tgt_refcount.rs index 720613af41..77f04a8294 100644 --- a/rules/unique_ptr/tgt_refcount.rs +++ b/rules/unique_ptr/tgt_refcount.rs @@ -21,9 +21,13 @@ fn t4() -> Ptr { Ptr::null() } -fn f1, T2: DefaultConstructible + ZeroInitialization>(a0: usize) -> Option>> { +fn f1, T2: DefaultConstructible + ZeroInitialization>( + a0: usize, +) -> Option>> { Some(Rc::new(RefCell::new( - (0..a0).map(|_| ::default_constructed()).collect::>(), + (0..a0) + .map(|_| ::default_constructed()) + .collect::>(), ))) } @@ -79,7 +83,10 @@ fn f13(a0: &mut Option>>) -> Option>> { a0.take() } -fn f14<'a, T1>(a0: &'a mut Option>, a1: &mut Option>) -> &'a mut Option> { +fn f14<'a, T1>( + a0: &'a mut Option>, + a1: &mut Option>, +) -> &'a mut Option> { *a0 = a1.take(); a0 } diff --git a/rules/unique_ptr/tgt_unsafe.rs b/rules/unique_ptr/tgt_unsafe.rs index 890282930e..589ba13b50 100644 --- a/rules/unique_ptr/tgt_unsafe.rs +++ b/rules/unique_ptr/tgt_unsafe.rs @@ -20,7 +20,11 @@ fn t4() -> *mut T1 { } fn f1, T2: DefaultConstructibleUnsafe>(a0: usize) -> Option> { - Some((0..a0).map(|_| ::default_constructed()).collect::>()) + Some( + (0..a0) + .map(|_| ::default_constructed()) + .collect::>(), + ) } fn f2(a0: &mut Option>) -> *mut T1 { a0.as_deref_mut() diff --git a/rules/vector/shim.rs b/rules/vector/shim.rs index d37069e48b..c0da3b1770 100644 --- a/rules/vector/shim.rs +++ b/rules/vector/shim.rs @@ -2,9 +2,10 @@ // Distributed under the MIT license that can be found in the LICENSE file. use crate::{ - ArgRepr, ByteRepr, Const, CopyAssignable, CopyAssignableUnsafe, CopyConstructible, - CopyConstructibleUnsafe, FnPtrArg, LvalueRef, LvalueRefUnsafe, MoveConstructibleUnsafe, Ptr, - RvalueRefUnsafe, ZeroInitialization, copy_constructed_unsafe, record_from_repr, + ArgRepr, ByteRepr, Const, Constructor, ConstructorUnsafe, CopyAssignable, CopyAssignableUnsafe, + CopyConstructible, CopyConstructibleUnsafe, FnPtrArg, LvalueRef, LvalueRefUnsafe, + MoveConstructibleUnsafe, Ptr, RvalueRefUnsafe, ZeroInitialization, copy_constructed_unsafe, + record_from_repr, }; impl ByteRepr for Vec {} @@ -21,15 +22,23 @@ impl FnPtrArg for Vec { crate::constructor::impl_move_by_take!( Vec); +// TODO: destroy the elements; this destructor does nothing. +impl crate::Destructible for Vec { + fn destroy(_this: Ptr) {} +} + +// TODO: destroy the elements; this destructor does nothing. +impl crate::DestructibleUnsafe for Vec { + unsafe fn destroy(_this: *mut Self) {} +} + // A vector is copied by copying its elements, each with its copy constructor. -impl CopyConstructible for Vec { - fn copy_constructor(this: Ptr, src: LvalueRef>) { +impl Constructor<(LvalueRef>,)> + for Vec +{ + fn constructor(this: Ptr, (src,): (LvalueRef>,)) { this.write(T::copied_elems(&src.as_pointer())); } - - fn copied(src: Ptr) -> Self { - T::copied_elems(&src) - } } impl CopyAssignable for Vec { @@ -84,7 +93,10 @@ impl PushConstructedUnsafe for Vec { { unsafe { push_constructed(self, src.cast_mut(), |dst, src| { - T::copy_constructor(dst, LvalueRefUnsafe::bind(src)) + >,)>>::constructor( + dst, + (LvalueRefUnsafe::bind(src),), + ) }) } } @@ -95,7 +107,10 @@ impl PushConstructedUnsafe for Vec { { unsafe { push_constructed(self, src, |dst, src| { - T::move_constructor(dst, RvalueRefUnsafe::bind(src)) + ,)>>::constructor( + dst, + (RvalueRefUnsafe::bind(src),), + ) }) } } @@ -110,8 +125,8 @@ unsafe fn copied_elems_unsafe(src: *const Vec) -> } } -impl CopyConstructibleUnsafe for Vec { - unsafe fn copy_constructor(this: *mut Self, src: LvalueRefUnsafe>) { +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for Vec { + unsafe fn constructor(this: *mut Self, (src,): (LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); unsafe { std::ptr::write(this, copied_elems_unsafe(src)) } } diff --git a/rules/vector/tgt_refcount.rs b/rules/vector/tgt_refcount.rs index a374cf2cd8..57fb717d39 100644 --- a/rules/vector/tgt_refcount.rs +++ b/rules/vector/tgt_refcount.rs @@ -64,14 +64,17 @@ fn f73(a0: Ptr>, MoveConstructible::push_moved(&a0, a1) } - fn f76(a0: Ptr) -> RandomAccessIterator { a0.end() } // The source is read before the vector is borrowed, as it may be in the same // object. -fn f77(a0: &mut Vec, a1: RandomAccessIterator, a2: Ptr) -> RandomAccessIterator { +fn f77( + a0: &mut Vec, + a1: RandomAccessIterator, + a2: Ptr, +) -> RandomAccessIterator { let __a2 = move_constructed(&a2); a0.insert(a1.index(), __a2); a1 @@ -81,7 +84,11 @@ fn f78(a0: usize, a1: Ptr) -> Ve (0..a0).map(|_| copy_constructed(a1.clone())).collect() } -fn f79(a0: &mut Vec, a1: RandomAccessIterator, a2: Ptr) -> RandomAccessIterator { +fn f79( + a0: &mut Vec, + a1: RandomAccessIterator, + a2: Ptr, +) -> RandomAccessIterator { let __a2 = copy_constructed(a2); a0.insert(a1.index(), __a2); a1 @@ -91,15 +98,28 @@ fn f80(a0: Ptr>, CopyConstructible::push_copied(&a0, a1) } -fn f92, T2, T3: CppInputIterator, T4: ByteRepr>(a0: T3, a1: T3) -> Vec { - let mut __v = Vec::new(); +fn f92< + T1: ConstructibleFrom<(LvalueRef>,)> + ZeroInitialization + ByteRepr, + T2, + T3: CppInputIterator, + T4: ByteRepr, +>( + a0: T3, + a1: T3, +) -> Vec { + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); while ::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push(T1::cpp_from(__it.borrow().iter_deref())); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() } fn f93(a0: Ptr) -> Ptr { @@ -130,22 +150,35 @@ fn f99(a0: &Vec) -> &T1 { &a0[__n] } -fn f101 + ByteRepr, T2, T3: CppInputIterator, T4: ByteRepr>( +fn f101< + T1: ConstructibleFrom<(LvalueRef>,)> + ZeroInitialization + ByteRepr, + T2, + T3: CppInputIterator, + T4: ByteRepr, +>( a0: Ptr>, a1: RandomAccessIterator, a2: T3, a3: T3, ) -> RandomAccessIterator { let start_idx = a1.index(); - let mut temp_vec: Vec = Vec::new(); + let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value = Rc::new(RefCell::new(a2)); let __last: Value = Rc::new(RefCell::new(a3)); while ::not_equal(__it.as_pointer(), __last.as_pointer()) { - temp_vec.push(T1::cpp_from(__it.borrow().iter_deref())); + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } a0.with_mut(|v: &mut Vec| { - v.splice(start_idx..start_idx, temp_vec); + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); }); a1 } @@ -181,14 +214,23 @@ where copy_constructed(a0) } -fn f115(a0: &mut Vec, a1: RandomAccessIterator, a2: usize, a3: Ptr) -> RandomAccessIterator { +fn f115( + a0: &mut Vec, + a1: RandomAccessIterator, + a2: usize, + a3: Ptr, +) -> RandomAccessIterator { let __off = a1.index(); let __copies: Vec = (0..a2).map(|_| copy_constructed(a3.clone())).collect(); a0.splice(__off..__off, __copies); a1 } -fn f116(a0: &mut Vec, a1: RandomAccessIterator, a2: Vec) -> RandomAccessIterator { +fn f116( + a0: &mut Vec, + a1: RandomAccessIterator, + a2: Vec, +) -> RandomAccessIterator { let __off = a1.index(); a0.splice(__off..__off, a2); a1 diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index b223a45645..505f41b0b7 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -126,7 +126,11 @@ fn f76(a0: &mut Vec) -> UnsafeRandomAccessIterator { } // The insertion may reallocate, so a1 may no longer point into a0. -unsafe fn f77(a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: *mut T1) -> UnsafeRandomAccessIterator { +unsafe fn f77( + a0: &mut Vec, + a1: UnsafeRandomAccessIterator, + a2: *mut T1, +) -> UnsafeRandomAccessIterator { let pos = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; UnsafeRandomAccessIterator::Vec(a0.insert_mut(pos, move_constructed_unsafe(&mut *a2))) } @@ -136,7 +140,11 @@ unsafe fn f78(a0: usize, a1: *const T1) -> Vec } // The insertion may reallocate, so a1 may no longer point into a0. -unsafe fn f79(a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: *const T1) -> UnsafeRandomAccessIterator { +unsafe fn f79( + a0: &mut Vec, + a1: UnsafeRandomAccessIterator, + a2: *const T1, +) -> UnsafeRandomAccessIterator { let pos = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; UnsafeRandomAccessIterator::Vec(a0.insert_mut(pos, copy_constructed_unsafe(a2))) } @@ -149,11 +157,23 @@ fn f91(a0: Vec) -> Vec { a0 } -unsafe fn f92, T2, T3: UnsafeCppInputIterator, T4>(a0: T3, a1: T3) -> Vec { - let mut __v = Vec::new(); +unsafe fn f92< + T1: ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + ZeroInitializationUnsafe, + T2, + T3: UnsafeCppInputIterator, + T4, +>( + a0: T3, + a1: T3, +) -> Vec { + let mut __v: Vec = Vec::new(); let mut __it = a0; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { - __v.push(T1::cpp_from(__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -184,17 +204,26 @@ fn f99(a0: &Vec) -> &T1 { &a0[__n] } -unsafe fn f101, T2, T3: UnsafeCppInputIterator, T4>( +unsafe fn f101< + T1: ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + ZeroInitializationUnsafe, + T2, + T3: UnsafeCppInputIterator, + T4, +>( a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: T3, a3: T3, ) -> UnsafeRandomAccessIterator { let __off = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; - let mut __tmp = Vec::new(); + let mut __tmp: Vec = Vec::new(); let mut __it = a2; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a3) { - __tmp.push(T1::cpp_from(__it.iter_deref())); + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } a0.splice(__off..__off, __tmp); @@ -221,7 +250,10 @@ fn f104(a0: Vec) -> UnsafeRandomAccessIterator { a0.end() } -unsafe fn f105<'a, T1: CopyConstructibleUnsafe>(a0: &'a mut Vec, a1: *const Vec) -> &'a mut Vec { +unsafe fn f105<'a, T1: CopyConstructibleUnsafe>( + a0: &'a mut Vec, + a1: *const Vec, +) -> &'a mut Vec { CopyAssignableUnsafe::copy_assign(&raw mut *a0, LvalueRefUnsafe::bind(a1)); a0 } @@ -246,13 +278,27 @@ fn f122(a0: &mut Vec, init: T1) { a0.push(init) } -unsafe fn f115(a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: usize, a3: *const T1) -> UnsafeRandomAccessIterator { +unsafe fn f115( + a0: &mut Vec, + a1: UnsafeRandomAccessIterator, + a2: usize, + a3: *const T1, +) -> UnsafeRandomAccessIterator { let __off = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; - a0.splice(__off..__off, (0..a2).map(|_| copy_constructed_unsafe(a3)).collect::>()); + a0.splice( + __off..__off, + (0..a2) + .map(|_| copy_constructed_unsafe(a3)) + .collect::>(), + ); UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr().add(__off)) } -unsafe fn f116(a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: Vec) -> UnsafeRandomAccessIterator { +unsafe fn f116( + a0: &mut Vec, + a1: UnsafeRandomAccessIterator, + a2: Vec, +) -> UnsafeRandomAccessIterator { let __off = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; a0.splice(__off..__off, a2); UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr().add(__off)) 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 5211876784..bc4ba39164 100644 --- a/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs +++ b/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs @@ -7,17 +7,12 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Swappable, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] #[byte_size(32)] pub struct S { #[offset(0)] @@ -29,7 +24,7 @@ pub struct S { pub n: Box<[i32]>, } impl S { - pub fn construct(this: Ptr, x: i32) { + pub fn constructor_1(this: Ptr, x: i32) { let x: Value = Rc::new(RefCell::new(x)); field!(this, v).write( (0..({ ((*x.borrow()) as usize) })) @@ -58,6 +53,9 @@ impl Default for S { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct T { #[offset(0)] @@ -68,9 +66,7 @@ impl T { pub fn size(this: Ptr) -> i32 { return (((*this.upgrade().deref()).v.len()) as i32); } -} -impl DefaultConstructible for T { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, v).write(Vec::new()); } } @@ -84,7 +80,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S(2)); + object!(s, S::constructor_1(2)); assert!((({ sum_0(s.as_pointer(),) }) == 7)); assert!((({ shuffle_1(3,) }) == 10)); let t: Value = Rc::new(RefCell::new(T { @@ -93,16 +89,24 @@ fn main_0() -> i32 { assert!((({ T::size(t.as_pointer(),) }) == 2)); return 0; } +impl S {} +impl T {} pub fn shuffle_1(mut x: i32) -> i32 { - object!(a, S(x)); - object!(b, S, RvalueRef::bind(a.as_pointer())); + object!(a, S::constructor_1(x)); + object!(b, S, |b| ::move_constructor( + b.clone(), + RvalueRef::bind(a.as_pointer()) + )); assert!(({ (*a.borrow()).v.is_empty() })); - object!(c, S(1)); + object!(c, S::constructor_1(1)); assign!(c = RvalueRef(b)); assert!(({ (*b.borrow()).v.is_empty() })); let t: Value = Rc::new(RefCell::new(T { v: Vec::from([1]) })); - object!(u, T, RvalueRef::bind(t.as_pointer())); - object!(w, T); + object!(u, T, |u| ::move_constructor( + u.clone(), + RvalueRef::bind(t.as_pointer()) + )); + object!(w, T::constructor_1()); assign!(w = RvalueRef(u)); assert!( ((({ T::size(t.as_pointer(),) }) == 0) && (({ T::size(u.as_pointer(),) }) == 0)) diff --git a/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs index 6c424bfeca..736e2c672a 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 @@ -10,20 +10,21 @@ use std::rc::Rc; #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] pub struct S { pub v: Vec, pub n: [i32; 2], } impl S { - pub unsafe fn construct(this: *mut Self, mut x: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { (&raw mut (*this).v).write(Vec::from_fn((x as usize), |_| { copy_constructed_unsafe(&mut x) })); @@ -43,6 +44,9 @@ impl S { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct T { pub v: Vec, } @@ -50,9 +54,7 @@ impl T { pub unsafe fn size(this: *const Self) -> i32 { return (((*this).v.len()) as i32); } -} -impl DefaultConstructibleUnsafe for T { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(Vec::new()); } } @@ -66,7 +68,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S(2)); + object_unsafe!(s, S::constructor_1(2)); assert!(((unsafe { sum_0(&s,) }) == (7))); assert!(((unsafe { shuffle_1(3,) }) == (10))); let mut t: T = T { @@ -75,16 +77,24 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { T::size(&raw const t,) }) == (2))); return 0; } +impl S {} +impl T {} pub unsafe fn shuffle_1(mut x: i32) -> i32 { - object_unsafe!(a, S(x)); - object_unsafe!(b, S, RvalueRefUnsafe::bind(&mut a)); + object_unsafe!(a, S::constructor_1(x)); + object_unsafe!(b, S, |b| ::move_constructor( + b, + RvalueRefUnsafe::bind(&mut a) + )); assert!(a.v.is_empty()); - object_unsafe!(c, S(1)); + object_unsafe!(c, S::constructor_1(1)); assign_unsafe!(c = RvalueRefUnsafe(b)); assert!(b.v.is_empty()); let mut t: T = T { v: Vec::from([1]) }; - object_unsafe!(u, T, RvalueRefUnsafe::bind(&mut t)); - object_unsafe!(w, T); + object_unsafe!(u, T, |u| ::move_constructor( + u, + RvalueRefUnsafe::bind(&mut t) + )); + object_unsafe!(w, T::constructor_1()); assign_unsafe!(w = RvalueRefUnsafe(u)); assert!( (((unsafe { T::size(&raw const t,) }) == (0)) diff --git a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs index e9c1329adc..1b1ac0deb3 100644 --- a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 45beae6e43..9b135af2e2 100644 --- a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 8bc86701b3..4f7fd71566 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 @@ -40,7 +40,9 @@ fn main_0() -> i32 { return 0; } pub fn touch_0(mut c: Ptr) {} -#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] +#[derive( + Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg, ZeroInitialization, Destructible, Conversions, +)] #[byte_size(1)] pub struct opaque; pub fn __cpp2rust_init_globals() {} 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 20929d6c0c..b5489afd25 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 @@ -38,6 +38,15 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn touch_0(mut c: *mut container) {} -#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] +#[derive( + Clone, + Copy, + Default, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + ConversionsUnsafe, +)] pub struct opaque; pub unsafe fn __cpp2rust_init_globals() {} 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 00e752b7cf..10e90ff48d 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 @@ -19,6 +19,8 @@ use std::rc::{Rc, Weak}; Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -29,7 +31,10 @@ impl S { return this.with(|__s| __s.v); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, +)] +#[conversions(copy, move)] #[byte_size(4)] pub struct M { #[offset(0)] @@ -50,7 +55,9 @@ pub trait Base { DefaultInitializable, Copyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Derived { #[offset(8)] @@ -68,7 +75,9 @@ impl Derived {} TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -84,18 +93,18 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S(1)); + object!(s, S::constructor_1(1)); assert!((({ S::get(s.as_pointer(),) }) == 1)); ({ S::set(s.as_pointer(), 4) }); assert!((({ S::get(s.as_pointer(),) }) == 4)); assert!((({ S::add(s.as_pointer(), 2,) }) == 6)); - object!(m, M(2)); - object!(n, M, RvalueRef::bind(m.as_pointer())); + object!(m, M::constructor_1(2)); + object!(n, M::constructor_2(RvalueRef::bind(m.as_pointer()))); assert!(({ (*n.borrow()).v } == 2)); - object!(c, M, LvalueRef::bind(n.as_pointer())); + object!(c, M::constructor_3(LvalueRef::bind(n.as_pointer()))); assert!(({ (*c.borrow()).v } == 3)); assert!((({ move_m_1(5,) }) == 5)); - object!(derived, Derived(3)); + object!(derived, Derived::constructor_1(3)); let mut base: PtrDyn = (derived.as_pointer()).to_dyn::(|w| w); assert!((({ (*base.upgrade().deref_mut()).apply(5,) }) == 15)); let pair: Value = Rc::new(RefCell::new(Pair { @@ -107,29 +116,25 @@ fn main_0() -> i32 { return 0; } impl S { - pub fn construct(this: Ptr, mut x: i32) { + pub fn constructor_1(this: Ptr, mut x: i32) { field!(this, v).write(x); } } impl M { - pub fn construct(this: Ptr, mut x: i32) { + pub fn constructor_1(this: Ptr, mut x: i32) { field!(this, v).write(x); } -} -impl MoveConstructible for M { - fn move_constructor(this: Ptr, _a0: RvalueRef) { + pub fn constructor_2(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); field!(this, v).write({ (*_a0.upgrade().deref()).v }); } -} -impl CopyConstructible for M { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_3(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 1)); } } impl Derived { - pub fn construct(this: Ptr, mut factor: i32) { + pub fn constructor_1(this: Ptr, mut factor: i32) { field!(this, factor).write(factor); } } @@ -151,15 +156,27 @@ impl S { } } impl M {} +impl M {} +impl M {} pub fn move_m_1(mut x: i32) -> i32 { - object!(m, M(x)); - object!(n, M, RvalueRef::bind(m.as_pointer())); + object!(m, M::constructor_1(x)); + object!(n, M::constructor_2(RvalueRef::bind(m.as_pointer()))); return { (*n.borrow()).v }; } impl Derived {} pub fn pair_sum_2(mut p: Ptr) -> i32 { return ({ p.with(|__s| __s.first) } + { p.with(|__s| __s.second) }); } +impl Constructor<(LvalueRef>,)> for M { + fn constructor(this: Ptr, _: (LvalueRef>,)) { + unreachable!("M::copy_constructor is never defined") + } +} +impl Constructor<(RvalueRef,)> for M { + fn constructor(this: Ptr, _: (RvalueRef,)) { + unreachable!("M::move_constructor is never defined") + } +} impl Base for Derived { fn apply(&mut self, mut x: i32) -> i32 { return ({ self.factor } * x); diff --git a/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs b/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs index 059056900a..51e50e971e 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 @@ -18,6 +18,8 @@ use std::rc::Rc; MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct S { pub v: i32, } @@ -27,7 +29,10 @@ impl S { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, +)] +#[conversions(copy, move)] pub struct M { pub v: i32, } @@ -45,7 +50,9 @@ pub unsafe trait Base { DefaultInitializableUnsafe, CopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Derived { pub factor: i32, } @@ -60,7 +67,9 @@ impl Derived {} TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pair { pub first: i32, pub second: i32, @@ -75,18 +84,18 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S(1)); + object_unsafe!(s, S::constructor_1(1)); assert!(((unsafe { S::get(&raw const s,) }) == (1))); (unsafe { S::set(&raw mut s, 4) }); assert!(((unsafe { S::get(&raw const s,) }) == (4))); assert!(((unsafe { S::add(&raw mut s, 2,) }) == (6))); - object_unsafe!(m, M(2)); - object_unsafe!(n, M, RvalueRefUnsafe::bind(&mut m)); + object_unsafe!(m, M::constructor_1(2)); + object_unsafe!(n, M::constructor_2(RvalueRefUnsafe::bind(&mut m))); assert!(((n.v) == (2))); - object_unsafe!(c, M, LvalueRefUnsafe::bind(&n)); + object_unsafe!(c, M::constructor_3(LvalueRefUnsafe::bind(&n))); assert!(((c.v) == (3))); assert!(((unsafe { move_m_1(5,) }) == (5))); - object_unsafe!(derived, Derived(3)); + object_unsafe!(derived, Derived::constructor_1(3)); let mut base: *mut dyn Base = (&mut derived as *mut Derived); assert!(((unsafe { (*base).apply(5,) }) == (15))); let mut pair: Pair = Pair { @@ -98,29 +107,25 @@ unsafe fn main_0() -> i32 { return 0; } impl S { - pub unsafe fn construct(this: *mut Self, mut x: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { (&raw mut (*this).v).write(x); } } impl M { - pub unsafe fn construct(this: *mut Self, mut x: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { (&raw mut (*this).v).write(x); } -} -impl MoveConstructibleUnsafe for M { - unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { + pub unsafe fn constructor_2(this: *mut Self, _a0: RvalueRefUnsafe) { let _a0 = (_a0.as_ptr() as *mut M); (&raw mut (*this).v).write((*_a0).v); } -} -impl CopyConstructibleUnsafe for M { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_3(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const M); (&raw mut (*this).v).write((((*o).v) + (1))); } } impl Derived { - pub unsafe fn construct(this: *mut Self, mut factor: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut factor: i32) { (&raw mut (*this).factor).write(factor); } } @@ -140,15 +145,27 @@ impl S { } } impl M {} +impl M {} +impl M {} pub unsafe fn move_m_1(mut x: i32) -> i32 { - object_unsafe!(m, M(x)); - object_unsafe!(n, M, RvalueRefUnsafe::bind(&mut m)); + object_unsafe!(m, M::constructor_1(x)); + object_unsafe!(n, M::constructor_2(RvalueRefUnsafe::bind(&mut m))); return n.v; } impl Derived {} pub unsafe fn pair_sum_2(mut p: *const Pair) -> i32 { return (((*p).first) + ((*p).second)); } +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for M { + unsafe fn constructor(this: *mut Self, _: (LvalueRefUnsafe>,)) { + unreachable!("M::copy_constructor is never defined") + } +} +impl ConstructorUnsafe<(RvalueRefUnsafe,)> for M { + unsafe fn constructor(this: *mut Self, _: (RvalueRefUnsafe,)) { + unreachable!("M::move_constructor is never defined") + } +} unsafe impl Base for Derived { unsafe fn apply(&mut self, x: i32) -> i32 { return ((self.factor) * (x)); 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 09b91429d0..f23fc96578 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,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct S_int_ { #[offset(0)] @@ -16,9 +28,7 @@ impl S_int_ { pub fn set(this: Ptr, mut v: i32) { field!(this, x).write(v); } -} -impl DefaultConstructible for S_int_ { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, x).write(0); } } @@ -32,7 +42,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(p, S_int_); + object!(p, S_int_::constructor_1()); ({ S_int_::set(p.as_pointer(), 3) }); assert!((({ f_0((p.as_pointer()),) }) == 3)); return 0; diff --git a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs index 71c5b881a5..4623ba404f 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,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S_int_ { pub x: i32, } @@ -15,9 +25,7 @@ impl S_int_ { pub unsafe fn set(this: *mut Self, mut v: i32) { (*this).x = v; } -} -impl DefaultConstructibleUnsafe for S_int_ { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).x).write(0); } } @@ -33,7 +41,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(p, S_int_); + object_unsafe!(p, S_int_::constructor_1()); (unsafe { S_int_::set(&raw mut p, 3) }); assert!(((unsafe { f_0((&mut p as *mut S_int_),) }) == (3))); return 0; diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index efa08bb605..66076fe075 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ impl LifetimeTracked { } }); } - pub fn use_(this: Ptr) { - field!(this, uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -113,8 +115,9 @@ thread_local!( thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -134,7 +137,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct HasInlineMembers {} impl HasInlineMembers { @@ -145,8 +150,9 @@ impl HasInlineMembers { thread_local!( static local_6: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 9d5edbf4fc..5949c7cd1a 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(this: *const Self) { - (*(&raw const (*this).uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } -} -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } } impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -95,8 +97,8 @@ pub static mut shared_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -115,7 +117,9 @@ pub static mut shared_5: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct HasInlineMembers {} impl HasInlineMembers { pub unsafe fn instance() -> *mut LifetimeTracked { @@ -125,8 +129,8 @@ impl HasInlineMembers { static mut local_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index f5e3f4f2bc..dc756f1f38 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ impl LifetimeTracked { } }); } - pub fn use_(this: Ptr) { - field!(this, uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -81,8 +81,9 @@ impl Destructible for LifetimeTracked { thread_local!( pub static member_4: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -102,14 +103,17 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct HasStaticMember_int_ {} thread_local!( pub static member_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -129,7 +133,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct HasStaticMember_long_ {} pub fn main() { 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 71eb9129c1..8752bcaa6e 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(this: *const Self) { - (*(&raw const (*this).uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } -} -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } } impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -63,8 +63,8 @@ pub static mut member_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -83,14 +83,16 @@ pub static mut member_4: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct HasStaticMember_int_ {} pub static mut member_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -109,7 +111,9 @@ pub static mut member_5: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 42f9c61e41..fda33c6c38 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ impl LifetimeTracked { } }); } - pub fn use_(this: Ptr) { - field!(this, uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -113,8 +115,9 @@ pub fn count_10() -> i32 { thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -129,8 +132,9 @@ thread_local!( thread_local!( static t_8: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -145,8 +149,9 @@ thread_local!( thread_local!( static t_11: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -196,7 +201,9 @@ fn main_0() -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct S_14 {} pub fn count_18() -> i32 { @@ -205,8 +212,9 @@ pub fn count_18() -> i32 { thread_local!( static t_19: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -238,7 +246,9 @@ pub fn b_count_local_15() -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct S_21 {} pub fn __cpp2rust_init_globals() { 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 e40f13ae30..fa90a916bb 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(this: *const Self) { - (*(&raw const (*this).uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } -} -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } } impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -93,8 +95,8 @@ pub unsafe fn count_10() -> i32 { static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -107,8 +109,8 @@ static mut n_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -121,8 +123,8 @@ static mut n_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { static mut t_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -172,7 +174,9 @@ unsafe fn main_0() -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S_14 {} pub unsafe fn count_18() -> i32 { return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut n_20)).prefix_inc()); @@ -180,8 +184,8 @@ pub unsafe fn count_18() -> i32 { static mut t_19: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -210,7 +214,9 @@ pub unsafe fn b_count_local_15() -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 318037e78f..43e47bff8e 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ impl LifetimeTracked { } }); } - pub fn use_(this: Ptr) { - field!(this, uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -107,8 +109,9 @@ pub fn instance_4() -> Ptr { thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 afc2b03b66..ffd360f654 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(this: *const Self) { - (*(&raw const (*this).uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } -} -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } } impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -87,8 +89,8 @@ pub unsafe fn instance_4() -> *mut LifetimeTracked { static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index cfbfc17551..3f1b9ff775 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ impl LifetimeTracked { } }); } - pub fn use_(this: Ptr) { - field!(this, uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -113,8 +115,9 @@ thread_local!( thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 890dc010a4..1066f6f244 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(this: *const Self) { - (*(&raw const (*this).uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } -} -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } } impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -95,8 +97,8 @@ pub static mut shared_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index 0b2af40577..ff87206292 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ impl LifetimeTracked { } }); } - pub fn use_(this: Ptr) { - field!(this, uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -112,7 +114,9 @@ impl Destructible for AssertsDtorCountAtExit { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct X {} impl X { @@ -135,8 +139,9 @@ impl X { thread_local!( static local_4: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 f0ccef5c69..347a2005ea 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(this: *const Self) { - (*(&raw const (*this).uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } -} -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } } impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -91,7 +93,9 @@ impl DestructibleUnsafe for AssertsDtorCountAtExit { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct X {} impl X { pub unsafe fn h(this: *mut Self, mut cond: bool, mut p: Option) { @@ -119,8 +123,8 @@ impl X { static mut local_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index 1881620397..877701844f 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ impl LifetimeTracked { } }); } - pub fn use_(this: Ptr) { - field!(this, uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -118,8 +120,9 @@ pub fn f_4(mut cond: bool, mut p: FnPtr) { thread_local!( static local_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 93cd43ae0b..b261789ee0 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(this: *const Self) { - (*(&raw const (*this).uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } -} -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } } impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -102,8 +104,8 @@ pub unsafe fn f_4(mut cond: bool, mut p: Option) { static mut local_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs index 9bcb8c525a..b8797e781b 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -75,14 +75,26 @@ 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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Record_19 { #[offset(0)] pub id: i32, } -impl DefaultConstructible for Record_19 { - fn default_constructor(this: Ptr) { +impl Record_19 { + pub fn constructor_1(this: Ptr) { field!(this, id).write(100); } } @@ -98,7 +110,7 @@ pub fn test_21() { assert!((({ bump_18() }) == 2)); assert!((({ bump_in_b_22() }) == 51)); assert!((counter_17.with(|rc| *rc.borrow()) == 2)); - object!(record, Record_19); + object!(record, Record_19::constructor_1()); assert!(({ (*record.borrow()).id } == 100)); assert!((({ record_id_in_b_23() }) == 200)); assert!((depth_20.with(|rc| *rc.borrow()) == 3)); @@ -127,7 +139,9 @@ pub fn test_29() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Tally_31 {} impl Tally_31 { @@ -156,7 +170,9 @@ pub fn test_33() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p5_members_of_class_with_external_linkage_Ledger {} pub fn test_36() { @@ -212,11 +228,11 @@ thread_local!( static count_48: Value = Rc::new(RefCell::new(1)); ); pub fn first_key_51() -> i32 { - object!(entry, Entry_52); + object!(entry, Entry_52::constructor_1()); return { (*entry.borrow()).key }; } pub fn second_key_plus_value_53() -> i32 { - object!(entry, Entry_54); + object!(entry, Entry_54::constructor_1()); return ({ (*entry.borrow()).key } + { (*entry.borrow()).value }); } pub fn test_55() { @@ -224,14 +240,26 @@ 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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Entry_52 { #[offset(0)] pub key: i32, } -impl DefaultConstructible for Entry_52 { - fn default_constructor(this: Ptr) { +impl Entry_52 { + pub fn constructor_1(this: Ptr) { field!(this, key).write(1); } } @@ -240,7 +268,19 @@ impl Default for Entry_52 { { Entry_52 { key: 1 } } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Entry_54 { #[offset(0)] @@ -248,8 +288,8 @@ pub struct Entry_54 { #[offset(4)] pub value: i32, } -impl DefaultConstructible for Entry_54 { - fn default_constructor(this: Ptr) { +impl Entry_54 { + pub fn constructor_1(this: Ptr) { field!(this, key).write(2); field!(this, value).write(30); } @@ -364,7 +404,19 @@ 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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(16)] pub struct Record_65 { #[offset(0)] @@ -372,8 +424,8 @@ pub struct Record_65 { #[offset(8)] pub extra: i32, } -impl DefaultConstructible for Record_65 { - fn default_constructor(this: Ptr) { +impl Record_65 { + pub fn constructor_1(this: Ptr) { field!(this, id).write(200_i64); field!(this, extra).write(1); } @@ -395,7 +447,7 @@ pub fn bump_in_b_22() -> i32 { return ({ bump_64() }); } pub fn record_id_in_b_23() -> i32 { - object!(record, Record_65); + object!(record, Record_65::constructor_1()); return ({ (*record.borrow()).id } as i32); } pub fn depth_in_b_24() -> i32 { @@ -425,7 +477,9 @@ pub fn raise_30(mut by: i32) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Tally_67 {} impl Tally_67 { @@ -470,17 +524,29 @@ thread_local!( static count_70: Value = Rc::new(RefCell::new(0)); ); pub fn key_in_b_56() -> i32 { - object!(entry, Entry_71); + object!(entry, Entry_71::constructor_1()); return ({ (*entry.borrow()).key } as i32); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Entry_71 { #[offset(0)] pub key: i64, } -impl DefaultConstructible for Entry_71 { - fn default_constructor(this: Ptr) { +impl Entry_71 { + pub fn constructor_1(this: Ptr) { field!(this, key).write(400_i64); } } diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs index 401a10dbee..ec942e8e60 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -68,12 +68,22 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Record_19 { pub id: i32, } -impl DefaultConstructibleUnsafe for Record_19 { - unsafe fn default_constructor(this: *mut Self) { +impl Record_19 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).id).write(100); } } @@ -87,7 +97,7 @@ pub unsafe fn test_21() { assert!(((unsafe { bump_18() }) == (2))); assert!(((unsafe { bump_in_b_22() }) == (51))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut counter_17)) == (2))); - object_unsafe!(record, Record_19); + object_unsafe!(record, Record_19::constructor_1()); assert!(((record.id) == (100))); assert!(((unsafe { record_id_in_b_23() }) == (200))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut depth_20)) == (3))); @@ -115,7 +125,9 @@ pub unsafe fn test_29() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Tally_31 {} impl Tally_31 { pub unsafe fn add(this: *mut Self, mut amount: i32) -> i32 { @@ -140,7 +152,9 @@ pub unsafe fn test_33() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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))); @@ -189,11 +203,11 @@ pub unsafe fn test_49() { static mut count_46: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); static mut count_48: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); pub unsafe fn first_key_51() -> i32 { - object_unsafe!(entry, Entry_52); + object_unsafe!(entry, Entry_52::constructor_1()); return entry.key; } pub unsafe fn second_key_plus_value_53() -> i32 { - object_unsafe!(entry, Entry_54); + object_unsafe!(entry, Entry_54::constructor_1()); return ((entry.key) + (entry.value)); } pub unsafe fn test_55() { @@ -202,12 +216,22 @@ pub unsafe fn test_55() { assert!(((unsafe { key_in_b_56() }) == (400))); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Entry_52 { pub key: i32, } -impl DefaultConstructibleUnsafe for Entry_52 { - unsafe fn default_constructor(this: *mut Self) { +impl Entry_52 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).key).write(1); } } @@ -217,13 +241,23 @@ impl Default for Entry_52 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Entry_54 { pub key: i32, pub value: i32, } -impl DefaultConstructibleUnsafe for Entry_54 { - unsafe fn default_constructor(this: *mut Self) { +impl Entry_54 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).key).write(2); (&raw mut (*this).value).write(30); } @@ -316,13 +350,23 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Record_65 { pub id: i64, pub extra: i32, } -impl DefaultConstructibleUnsafe for Record_65 { - unsafe fn default_constructor(this: *mut Self) { +impl Record_65 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).id).write(200_i64); (&raw mut (*this).extra).write(1); } @@ -342,7 +386,7 @@ pub unsafe fn bump_in_b_22() -> i32 { return (unsafe { bump_64() }); } pub unsafe fn record_id_in_b_23() -> i32 { - object_unsafe!(record, Record_65); + object_unsafe!(record, Record_65::constructor_1()); return (record.id as i32); } pub unsafe fn depth_in_b_24() -> i32 { @@ -368,7 +412,9 @@ pub unsafe fn raise_30(mut by: i32) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Tally_67 {} impl Tally_67 { pub unsafe fn add(this: *mut Self, mut amount: i32) -> i32 { @@ -402,16 +448,26 @@ pub unsafe fn next_in_b_50() -> i32 { } static mut count_70: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub unsafe fn key_in_b_56() -> i32 { - object_unsafe!(entry, Entry_71); + object_unsafe!(entry, Entry_71::constructor_1()); return (entry.key as i32); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Entry_71 { pub key: i64, } -impl DefaultConstructibleUnsafe for Entry_71 { - unsafe fn default_constructor(this: *mut Self) { +impl Entry_71 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).key).write(400_i64); } } diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs index 302b248269..48e633fe80 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ impl LifetimeTracked { } }); } - pub fn use_(this: Ptr) { - field!(this, uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -100,6 +100,9 @@ thread_local!( Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] @@ -177,13 +180,13 @@ pub fn test_8() { } pub fn test_9() { ({ LifetimeTracked::reset() }); - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); { let mut index: i32 = 0; 'loop_: while (index < 3) { 'for_body: { - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); } index.prefix_inc(); } @@ -191,13 +194,13 @@ pub fn test_9() { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 4)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 3)); if (ctorCount_0.with(|rc| *rc.borrow()) == 4) { - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 5)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 4)); if (ctorCount_0.with(|rc| *rc.borrow()) == 0) { } else { - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 6)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 5)); @@ -226,9 +229,9 @@ pub fn test_10() { } pub fn test_11() { ({ LifetimeTracked::reset() }); - object!(tracked, LifetimeTracked); + object!(tracked, LifetimeTracked::constructor_1()); { - object!(tracked, LifetimeTracked); + object!(tracked, LifetimeTracked::constructor_1()); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); ({ LifetimeTracked::use_(tracked.as_pointer()) }); assert!(({ (*tracked.borrow()).uses } == 1)); 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 af9f7a8896..166826eb34 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,19 @@ 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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p1_member_hides_namespace_variable_HasBalance { #[offset(0)] @@ -26,9 +38,7 @@ impl p1_member_hides_namespace_variable_HasBalance { balance_0.with(|rc| *rc.borrow_mut() += amount); return balance_0.with(|rc| *rc.borrow()); } -} -impl DefaultConstructible for p1_member_hides_namespace_variable_HasBalance { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, balance).write(7); } } @@ -38,7 +48,10 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { } } pub fn test_1() { - object!(object, p1_member_hides_namespace_variable_HasBalance); + object!( + object, + p1_member_hides_namespace_variable_HasBalance::constructor_1() + ); assert!( (({ p1_member_hides_namespace_variable_HasBalance::deposit(object.as_pointer(), 3,) }) == 10) @@ -56,14 +69,26 @@ pub fn test_1() { thread_local!( pub static initial_2: Value = Rc::new(RefCell::new(100)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { #[offset(0)] pub held: i32, } -impl DefaultConstructible for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - fn default_constructor(this: Ptr) { +impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + pub fn constructor_1(this: Ptr) { field!(this, held).write(1); } } @@ -91,7 +116,7 @@ pub fn test_5() { assert!((total_4.with(|rc| *rc.borrow()) == 7)); object!( object, - p1_out_of_class_definition_is_in_class_scope_HasStaticTotal + p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::constructor_1() ); assert!( (({ diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs index 51f3d0b9df..c20a931c54 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 @@ -14,19 +14,20 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { #[offset(0)] pub amount: i32, } impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { - pub fn construct(this: Ptr, mut amount: i32) { + pub fn constructor_1(this: Ptr, mut amount: i32) { field!(this, amount).write((amount + 1)); amount += 10; assert!((amount == 14)); @@ -39,7 +40,7 @@ impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { pub fn test_0() { object!( object, - p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter(4) + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::constructor_1(4) ); assert!(({ (*object.borrow()).amount } == 5)); assert!( 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 fcfaeefccc..2966ede095 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 @@ -28,7 +28,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct p1_own_address_in_initializer_SelfLinked { #[offset(0)] @@ -83,15 +85,19 @@ 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, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p9_func_declared_before_function_body_RecordsConstructorName { #[offset(0)] #[byte_size(8)] pub name: Ptr, } -impl DefaultConstructible for p9_func_declared_before_function_body_RecordsConstructorName { - fn default_constructor(this: Ptr) { +impl p9_func_declared_before_function_body_RecordsConstructorName { + pub fn constructor_1(this: Ptr) { field!(this, name).write(Ptr::::from_string_literal(b"RecordsConstructorName")); assert!( (this.with(|__s| __s.name.clone()) @@ -104,10 +110,10 @@ impl Default for p9_func_declared_before_function_body_RecordsConstructorName { { { let __v: Value = - Rc::new(RefCell::new( - ::zero_init(), - )); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_func_declared_before_function_body_RecordsConstructorName::constructor_1( + __v.as_pointer(), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -137,7 +143,7 @@ pub fn test_6() { assert!((({ plain_function_5() }) == ({ plain_function_5() }))); object!( object, - p9_func_declared_before_function_body_RecordsConstructorName + p9_func_declared_before_function_body_RecordsConstructorName::constructor_1() ); assert!( ({ 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 f2e8701287..af1207012a 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 @@ -55,7 +55,9 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum { @@ -97,7 +99,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p2_12_class_name_in_own_scope_HasStaticCounter {} impl p2_12_class_name_in_own_scope_HasStaticCounter { @@ -188,7 +192,9 @@ impl Default for anon_9 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { #[offset(0)] @@ -260,7 +266,19 @@ impl Default for anon_11 { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { #[offset(0)] @@ -281,9 +299,7 @@ impl p3_2_const_qualified_member_is_distinct_HasConstOverload { }); return 2; } -} -impl DefaultConstructible for p3_2_const_qualified_member_is_distinct_HasConstOverload { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, plain_calls).write(0); field!(this, const_calls).write(0); } @@ -301,7 +317,7 @@ impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { pub fn test_12() { object!( object, - p3_2_const_qualified_member_is_distinct_HasConstOverload + p3_2_const_qualified_member_is_distinct_HasConstOverload::constructor_1() ); let view: Ptr = object.as_pointer(); assert!( @@ -324,7 +340,19 @@ thread_local!( thread_local!( pub static rvalue_calls_14: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { #[offset(0)] @@ -342,11 +370,7 @@ impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverl (*rvalue_calls_14.with(Value::clone).borrow_mut()).prefix_inc(); return ((this.with(|__s| __s.base) + amount) + 100); } -} -impl DefaultConstructible - for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload -{ - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, base).write(10); } } @@ -360,10 +384,7 @@ impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplici } } pub fn test_15() { - object!( - object, - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload - ); + object!(object, p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1()); assert!( (({ p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::pick_1( @@ -375,10 +396,12 @@ pub fn test_15() { assert!((explicit_calls_13.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_14.with(|rc| *rc.borrow()) == 0)); { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_0: Value< + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload, + > = Rc::new(RefCell::new(ZeroInitialization::zero_init())); assert!( (({ - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( { DefaultConstructible::default_constructor(__tmp_0.as_pointer()) ; __tmp_0.as_pointer() } , 2 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( { p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1(__tmp_0.as_pointer()) ; __tmp_0.as_pointer() } , 2 , ) }) == 112) ) }; @@ -402,7 +425,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads { @@ -450,7 +475,19 @@ 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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { #[offset(0)] @@ -459,6 +496,10 @@ pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOv pub const_calls: i32, } impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + pub fn constructor_1(this: Ptr) { + field!(this, plain_calls).write(0); + field!(this, const_calls).write(0); + } pub fn get_1_int(this: Ptr, mut value: i32) -> i32 { field!(this, plain_calls).with_mut(|__v| { __v.prefix_inc(); @@ -472,14 +513,6 @@ impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload return (value + 2); } } -impl DefaultConstructible - for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload -{ - fn default_constructor(this: Ptr) { - field!(this, plain_calls).write(0); - field!(this, const_calls).write(0); - } -} impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { fn default() -> Self { { @@ -493,7 +526,8 @@ impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemp pub fn test_19() { object!( object, - p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::constructor_1( + ) ); let view: Ptr = object.as_pointer(); @@ -535,7 +569,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} impl p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads { @@ -586,7 +622,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DeclaresFriend {} pub fn shared_friend_24() -> i32 { @@ -604,7 +642,9 @@ pub fn shared_friend_24() -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DefinesFriend {} pub fn test_25() { @@ -647,7 +687,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p4_2_class_and_function_share_name_Reading { #[offset(0)] @@ -676,7 +718,9 @@ pub fn test_33() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 5d170897e2..ff10deb2a4 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(this: *const Self) { - (*(&raw const (*this).uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } -} -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } } impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -76,6 +76,9 @@ pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new( MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { pub value: i32, } @@ -149,13 +152,13 @@ pub unsafe fn test_8() { } pub unsafe fn test_9() { (unsafe { LifetimeTracked::reset() }); - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); { let mut index: i32 = 0; 'loop_: while ((index) < (3)) { 'for_body: { - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); } index.prefix_inc(); } @@ -163,13 +166,13 @@ pub unsafe fn test_9() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (3))); if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4)) { - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (4))); if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0)) { } else { - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (5))); @@ -194,9 +197,9 @@ pub unsafe fn test_10() { } pub unsafe fn test_11() { (unsafe { LifetimeTracked::reset() }); - object_unsafe!(tracked, LifetimeTracked); + object_unsafe!(tracked, LifetimeTracked::constructor_1()); { - object_unsafe!(tracked, LifetimeTracked); + object_unsafe!(tracked, LifetimeTracked::constructor_1()); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); (unsafe { LifetimeTracked::use_(&raw const tracked) }); assert!(((tracked.uses) == (1))); 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 074260bb41..d72be59edc 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,17 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p1_member_hides_namespace_variable_HasBalance { pub balance: i32, } @@ -21,9 +31,7 @@ impl p1_member_hides_namespace_variable_HasBalance { (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)) += amount; return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)); } -} -impl DefaultConstructibleUnsafe for p1_member_hides_namespace_variable_HasBalance { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).balance).write(7); } } @@ -33,7 +41,10 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { } } pub unsafe fn test_1() { - object_unsafe!(object, p1_member_hides_namespace_variable_HasBalance); + object_unsafe!( + object, + p1_member_hides_namespace_variable_HasBalance::constructor_1() + ); assert!( ((unsafe { p1_member_hides_namespace_variable_HasBalance::deposit(&raw mut object, 3,) }) == (10)) @@ -50,12 +61,22 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub held: i32, } -impl DefaultConstructibleUnsafe for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - unsafe fn default_constructor(this: *mut Self) { +impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).held).write(1); } } @@ -80,7 +101,7 @@ pub unsafe fn test_5() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_4)) == (7))); object_unsafe!( object, - p1_out_of_class_definition_is_in_class_scope_HasStaticTotal + p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::constructor_1() ); assert!( ((unsafe { 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 fab158ea2c..d3424bc960 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 @@ -13,17 +13,18 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { pub amount: i32, } impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { - pub unsafe fn construct(this: *mut Self, mut amount: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut amount: i32) { (&raw mut (*this).amount).write(((amount) + (1))); amount += 10; assert!(((amount) == (14))); @@ -36,7 +37,7 @@ impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { pub unsafe fn test_0() { object_unsafe!( object, - p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter(4) + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::constructor_1(4) ); assert!(((object.amount) == (5))); assert!( 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 c19845dfca..16559374a7 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 @@ -28,7 +28,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p1_own_address_in_initializer_SelfLinked { pub next: *mut p1_own_address_in_initializer_SelfLinked, pub value: i32, @@ -81,12 +83,22 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: *const libc::c_char, } -impl DefaultConstructibleUnsafe for p9_func_declared_before_function_body_RecordsConstructorName { - unsafe fn default_constructor(this: *mut Self) { +impl p9_func_declared_before_function_body_RecordsConstructorName { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).name).write(c"RecordsConstructorName".as_ptr()); assert!((((*this).name) == (c"RecordsConstructorName".as_ptr()))); } @@ -96,8 +108,10 @@ impl Default for p9_func_declared_before_function_body_RecordsConstructorName { unsafe { { let mut __v: p9_func_declared_before_function_body_RecordsConstructorName = - ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + ZeroInitializationUnsafe::zero_init(); + p9_func_declared_before_function_body_RecordsConstructorName::constructor_1( + &raw mut __v, + ); __v } } @@ -111,7 +125,7 @@ pub unsafe fn test_6() { assert!(((unsafe { plain_function_5() }) == (unsafe { plain_function_5() }))); object_unsafe!( object, - p9_func_declared_before_function_body_RecordsConstructorName + p9_func_declared_before_function_body_RecordsConstructorName::constructor_1() ); assert!(((libc::strcmp(object.name, c"RecordsConstructorName".as_ptr())) == (0))); let mut enclosing: *const libc::c_char = c"test".as_ptr(); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs index 55ac501b18..fd92c6ac36 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 @@ -51,7 +51,9 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum { pub unsafe fn scale(this: *const Self, mut count: i32) -> i32 { @@ -88,7 +90,9 @@ pub static mut count_6: std::cell::LazyCell = std::cell::LazyCell::new(|| u TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p2_12_class_name_in_own_scope_HasStaticCounter {} impl p2_12_class_name_in_own_scope_HasStaticCounter { pub unsafe fn bump() { @@ -153,7 +157,9 @@ impl Default for anon_9 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { pub tag: i32, pub anon_9: anon_9, @@ -211,7 +217,17 @@ impl Default for anon_11 { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { pub plain_calls: i32, pub const_calls: i32, @@ -225,9 +241,7 @@ impl p3_2_const_qualified_member_is_distinct_HasConstOverload { (*(&raw const (*this).const_calls).cast_mut()).prefix_inc(); return 2; } -} -impl DefaultConstructibleUnsafe for p3_2_const_qualified_member_is_distinct_HasConstOverload { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).plain_calls).write(0); (&raw mut (*this).const_calls).write(0); } @@ -245,7 +259,7 @@ impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { pub unsafe fn test_12() { object_unsafe!( object, - p3_2_const_qualified_member_is_distinct_HasConstOverload + p3_2_const_qualified_member_is_distinct_HasConstOverload::constructor_1() ); let view: *const p3_2_const_qualified_member_is_distinct_HasConstOverload = &object; assert!( @@ -268,7 +282,17 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { pub base: i32, } @@ -284,11 +308,7 @@ impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverl (*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_14)).prefix_inc(); return ((((*this).base) + (amount)) + (100)); } -} -impl DefaultConstructibleUnsafe - for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload -{ - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).base).write(10); } } @@ -302,10 +322,7 @@ impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplici } } pub unsafe fn test_15() { - object_unsafe!( - object, - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload - ); + object_unsafe!(object, p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1()); assert!( ((unsafe { p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::pick_1( @@ -317,10 +334,10 @@ pub unsafe fn test_15() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut explicit_calls_13)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_14)) == (0))); { - let mut __tmp_0: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = ::zero_init(); + let mut __tmp_0: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = ZeroInitializationUnsafe::zero_init(); assert!( ((unsafe { - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ DefaultConstructibleUnsafe::default_constructor(&raw mut __tmp_0) ; & mut __tmp_0 } ) , 2 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1(&raw mut __tmp_0) ; & mut __tmp_0 } ) , 2 , ) }) == (112)) ) }; @@ -341,7 +358,9 @@ pub static mut rvalue_calls_17: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads { pub unsafe fn get_1(this: *mut Self) -> i32 { @@ -381,12 +400,26 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { pub plain_calls: i32, pub const_calls: i32, } impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).plain_calls).write(0); + (&raw mut (*this).const_calls).write(0); + } pub unsafe fn get_1_int(this: *mut Self, mut value: i32) -> i32 { (*this).plain_calls.prefix_inc(); return ((value) + (1)); @@ -396,14 +429,6 @@ impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload return ((value) + (2)); } } -impl DefaultConstructibleUnsafe - for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload -{ - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).plain_calls).write(0); - (&raw mut (*this).const_calls).write(0); - } -} impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { fn default() -> Self { unsafe { @@ -417,7 +442,8 @@ impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemp pub unsafe fn test_19() { object_unsafe!( object, - p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::constructor_1( + ) ); let view: *const p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload = &object; @@ -456,7 +482,9 @@ pub static mut rvalue_calls_21: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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(this: *mut Self, mut value: i32) -> i32 { @@ -504,7 +532,9 @@ pub static mut friend_calls_23: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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(); @@ -520,7 +550,9 @@ pub unsafe fn shared_friend_24() -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DefinesFriend {} pub unsafe fn test_25() { assert!(((unsafe { shared_friend_24() }) == (7))); @@ -558,7 +590,9 @@ pub static mut function_calls_31: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p4_2_class_and_function_share_name_Reading { pub value: i32, } @@ -584,7 +618,9 @@ pub unsafe fn test_33() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 348c1b15be..17e7807749 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 @@ -19,13 +19,16 @@ use std::rc::{Rc, Weak}; Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, explicit, i32)] #[byte_size(4)] pub struct Tracker { #[offset(0)] pub tag: i32, } impl Tracker { - pub fn construct(this: Ptr, mut tag: i32) { + pub fn constructor_1(this: Ptr, mut tag: i32) { field!(this, tag).write(tag); printf!(b"construct %d\n", tag); } @@ -38,8 +41,8 @@ impl Destructible for Tracker { thread_local!( pub static global_0: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracker::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -52,14 +55,14 @@ pub fn exit_from_nested_call_1() { printf!(b"local static %d\n", { (*local_static_2.with(Value::clone).borrow()).tag }); - object!(automatic, Tracker(3)); + object!(automatic, Tracker::constructor_1(3)); libcc2rs::cpp2rust_exit(0); } thread_local!( static local_static_2: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracker::construct(__v.as_pointer(), 2); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 6b1d94835e..b55aea53a8 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 @@ -19,13 +19,16 @@ use std::rc::{Rc, Weak}; Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, explicit, i32)] #[byte_size(4)] pub struct Tracker { #[offset(0)] pub tag: i32, } impl Tracker { - pub fn construct(this: Ptr, mut tag: i32) { + pub fn constructor_1(this: Ptr, mut tag: i32) { field!(this, tag).write(tag); printf!(b"construct %d\n", tag); } @@ -52,6 +55,8 @@ impl Destructible for Tracker { Swappable, )] #[memberwise(move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct HoldsTracker { #[offset(0)] @@ -70,7 +75,9 @@ pub struct HoldsTracker { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct TriviallyDestructible { #[offset(0)] @@ -79,8 +86,8 @@ pub struct TriviallyDestructible { thread_local!( pub static global_0: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracker::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -98,8 +105,8 @@ pub fn test_3() { thread_local!( static never_constructed_2: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracker::construct(__v.as_pointer(), 100); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 100); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -114,8 +121,8 @@ pub fn local_static_during_global_init_4() -> Ptr { thread_local!( pub static before_6: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracker::construct(__v.as_pointer(), 2); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -127,8 +134,8 @@ thread_local!( thread_local!( pub static after_7: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracker::construct( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1( __v.as_pointer(), (({ local_static_during_global_init_4() }).with(|__s| __s.tag) + 1), ); @@ -144,8 +151,8 @@ thread_local!( pub static holder_8: Value = { let __static = Rc::new(RefCell::new(HoldsTracker { member: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracker::construct(__v.as_pointer(), 5); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); @@ -170,14 +177,16 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p3_reverse_completion_order_WithStaticMember {} thread_local!( pub static member_10: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracker::construct(__v.as_pointer(), 7); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -191,8 +200,9 @@ thread_local!( let __static = Rc::new(RefCell::new(lambda!( { let captured: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracker::construct(__v.as_pointer(), 8); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 8); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -223,8 +233,8 @@ pub fn test_14() { thread_local!( static during_init_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracker::construct(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -236,8 +246,8 @@ thread_local!( thread_local!( static during_main_13: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracker::construct(__v.as_pointer(), 9); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 1c893a7688..fa8939a70e 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 @@ -18,11 +18,14 @@ use std::rc::Rc; MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, explicit, i32)] pub struct Tracker { pub tag: i32, } impl Tracker { - pub unsafe fn construct(this: *mut Self, mut tag: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut tag: i32) { (&raw mut (*this).tag).write(tag); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); } @@ -40,8 +43,8 @@ impl DestructibleUnsafe for Tracker { pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - Tracker::construct(&raw mut __v, 1); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 1); __v }; libcc2rs::register_static_destructor(|| { @@ -57,14 +60,14 @@ pub unsafe fn exit_from_nested_call_1() { ((*std::cell::LazyCell::force_mut(&mut *&raw mut local_static_2)).tag), ) }); - object_unsafe!(automatic, Tracker(3)); + object_unsafe!(automatic, Tracker::constructor_1(3)); libcc2rs::cpp2rust_exit(0); } static mut local_static_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - Tracker::construct(&raw mut __v, 2); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 2); __v }; libcc2rs::register_static_destructor(|| { 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 19cda7aef8..47926e2396 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 @@ -18,11 +18,14 @@ use std::rc::Rc; MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, explicit, i32)] pub struct Tracker { pub tag: i32, } impl Tracker { - pub unsafe fn construct(this: *mut Self, mut tag: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut tag: i32) { (&raw mut (*this).tag).write(tag); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); } @@ -53,6 +56,8 @@ impl DestructibleUnsafe for Tracker { SwappableUnsafe, )] #[memberwise(move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct HoldsTracker { #[destroy] pub member: Tracker, @@ -67,15 +72,17 @@ pub struct HoldsTracker { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct TriviallyDestructible { pub value: i32, } pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - Tracker::construct(&raw mut __v, 1); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 1); __v }; libcc2rs::register_static_destructor(|| { @@ -100,8 +107,8 @@ static mut never_constructed_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - Tracker::construct(&raw mut __v, 100); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 100); __v }; libcc2rs::register_static_destructor(|| { @@ -118,8 +125,8 @@ pub unsafe fn local_static_during_global_init_4() -> *const Tracker { pub static mut before_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - Tracker::construct(&raw mut __v, 2); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 2); __v }; libcc2rs::register_static_destructor(|| { @@ -131,8 +138,8 @@ pub static mut before_6: std::cell::LazyCell = std::cell::LazyCell::new pub static mut after_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - Tracker::construct( + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1( &raw mut __v, (((*(unsafe { local_static_during_global_init_4() })).tag) + (1)), ); @@ -148,8 +155,8 @@ pub static mut holder_8: std::cell::LazyCell = std::cell::LazyCell { let __static = HoldsTracker { member: { - let mut __v: Tracker = ::zero_init(); - Tracker::construct(&raw mut __v, 5); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 5); __v }, }; @@ -171,13 +178,15 @@ pub static mut trivial_9: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p3_reverse_completion_order_WithStaticMember {} pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - Tracker::construct(&raw mut __v, 7); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 7); __v }; libcc2rs::register_static_destructor(|| { @@ -192,8 +201,8 @@ pub static mut capturing_11: std::cell::LazyCell i32>> = let __static = lambda_unsafe!( { let captured: Tracker = { - let mut __v: Tracker = ::zero_init(); - Tracker::construct(&raw mut __v, 8); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 8); __v }; }, @@ -237,8 +246,8 @@ pub unsafe fn test_14() { static mut during_init_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - Tracker::construct(&raw mut __v, 3); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 3); __v }; libcc2rs::register_static_destructor(|| { @@ -252,8 +261,8 @@ static mut during_init_5: std::cell::LazyCell = std::cell::LazyCell::ne static mut during_main_13: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - Tracker::construct(&raw mut __v, 9); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 9); __v }; libcc2rs::register_static_destructor(|| { 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 f3ae2ec709..62a94b610e 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 @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { #[offset(0)] @@ -91,7 +93,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 0f4f424119..b7ff0e156e 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 @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { pub first: i32, pub second: i32, @@ -94,7 +96,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 2b4fecaf95..4aa16c4365 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -14,7 +14,6 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -23,7 +22,10 @@ thread_local!( Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct HasConstexprCtor { #[offset(0)] @@ -33,12 +35,10 @@ impl HasConstexprCtor { pub fn reset() { copyCount_0.with(|rc| *rc.borrow_mut() = 0); } - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, m).write(v); } -} -impl CopyConstructible for HasConstexprCtor { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, m).write(o.with(|__s| __s.m)); (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); @@ -67,6 +67,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -91,25 +95,21 @@ impl LifetimeTracked { } }); } - pub fn use_(this: Ptr) { - field!(this, uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -121,14 +121,14 @@ pub fn test_5() { let mut arr: [HasConstexprCtor; 2] = [ { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 3); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 4); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]; @@ -138,14 +138,14 @@ pub fn test_5() { return [ { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 3); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 4); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ][(1) as usize] @@ -158,15 +158,15 @@ pub fn test_5() { } pub fn test_6() { ({ HasConstexprCtor::reset() }); - object!(k, HasConstexprCtor(5)); + object!(k, HasConstexprCtor::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { { return { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 5); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } .m @@ -179,8 +179,8 @@ pub fn test_6() { } pub fn test_7() { ({ HasConstexprCtor::reset() }); - object!(k1, HasConstexprCtor(7)); - object!(k2, HasConstexprCtor(9)); + object!(k1, HasConstexprCtor::constructor_1(7)); + object!(k2, HasConstexprCtor::constructor_1(9)); let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new( |mut b: bool| -> i32 { { @@ -188,15 +188,15 @@ pub fn test_7() { (if b { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 7); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } else { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 9); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }) @@ -215,7 +215,7 @@ thread_local!( ); pub fn test_9() { ({ HasConstexprCtor::reset() }); - object!(k, HasConstexprCtor(5)); + object!(k, HasConstexprCtor::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { { @@ -224,8 +224,8 @@ pub fn test_9() { (*left_8.with(Value::clone).borrow_mut()).prefix_inc(); { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 5); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -256,7 +256,9 @@ pub trait p4_1_pure_virtual_without_definition_HasPureVirtual { DefaultInitializable, Copyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} pub fn test_11() { @@ -271,8 +273,9 @@ pub fn test_11() { thread_local!( pub static global_12: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -295,14 +298,14 @@ pub fn test_13() { } pub fn test_14() { ({ LifetimeTracked::reset() }); - object!(t, LifetimeTracked); + object!(t, LifetimeTracked::constructor_1()); let r: Ptr = t.as_pointer(); let f: Value> = Rc::new(RefCell::new(lambda!( { let r: Value = Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(__v.as_pointer(), LvalueRef::bind((r).clone())); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_2(__v.as_pointer(), LvalueRef::bind((r).clone())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -333,21 +336,21 @@ pub fn test_15() { } pub fn test_16() { ({ HasConstexprCtor::reset() }); - object!(k, HasConstexprCtor(5)); + object!(k, HasConstexprCtor::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let k: Value = Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( - __v.as_pointer(), - LvalueRef::bind(k.as_pointer()), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_2(__v.as_pointer(), LvalueRef::bind(k.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || -> i32 { - object!(c, HasConstexprCtor, LvalueRef::bind(k.as_pointer())); + object!( + c, + HasConstexprCtor::constructor_2(LvalueRef::bind(k.as_pointer())) + ); return { (*c.borrow()).m }; } ))); @@ -373,7 +376,6 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -382,7 +384,10 @@ thread_local!( Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(8)] pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { #[offset(0)] @@ -391,13 +396,11 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { pub scratch: i32, } impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, value).write(v); field!(this, scratch).write(0); } -} -impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember { - fn copy_constructor( + pub fn constructor_2( this: Ptr, o: LvalueRef>, ) { @@ -408,16 +411,17 @@ impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember { } } pub fn test_19() { - object!(k, p5_2_mutable_subobject_is_odr_used_HasMutableMember(5)); + object!( + k, + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_1(5) + ); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let k: Value = Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new( - ::zero_init(), - )); - CopyConstructible::copy_constructor( + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_2( __v.as_pointer(), LvalueRef::bind(k.as_pointer()), ); @@ -434,6 +438,9 @@ pub fn test_19() { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[offset(0)] @@ -445,10 +452,10 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[destroy] pub b: LifetimeTracked, } -impl DefaultConstructible for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, a)); - DefaultConstructible::default_constructor(field_ptr!(this, b)); +impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + pub fn constructor_1(this: Ptr) { + LifetimeTracked::constructor_1(field_ptr!(this, a)); + LifetimeTracked::constructor_1(field_ptr!(this, b)); } } pub fn test_20() { @@ -457,14 +464,14 @@ pub fn test_20() { p6_unevaluated_binding_needs_no_capture_HasTwoMembers { a: { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, b: { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, }, @@ -485,6 +492,9 @@ pub fn test_20() { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(0)] @@ -507,16 +517,17 @@ impl p7_member_access_captures_this_HasMemberUsedInLambda { } ); } -} -impl DefaultConstructible for p7_member_access_captures_this_HasMemberUsedInLambda { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, x)); + pub fn constructor_1(this: Ptr) { + LifetimeTracked::constructor_1(field_ptr!(this, x)); field!(this, n).write(1); } } pub fn test_22() { ({ LifetimeTracked::reset() }); - object!(c, p7_member_access_captures_this_HasMemberUsedInLambda); + object!( + c, + p7_member_access_captures_this_HasMemberUsedInLambda::constructor_1() + ); let f: Value i32>> = Rc::new(RefCell::new( ({ p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(c.as_pointer()) }), )); @@ -530,6 +541,9 @@ pub fn test_22() { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[offset(0)] @@ -545,17 +559,15 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } }); } -} -impl DefaultConstructible for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, x)); + pub fn constructor_1(this: Ptr) { + LifetimeTracked::constructor_1(field_ptr!(this, x)); } } pub fn test_23() { ({ LifetimeTracked::reset() }); object!( c, - p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda + p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::constructor_1() ); let f: Value usize>> = Rc::new(RefCell::new( ({ p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(c.as_pointer()) }), @@ -599,10 +611,13 @@ thread_local!( Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} -impl DefaultConstructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - fn default_constructor(this: Ptr) { +impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + pub fn constructor_1(this: Ptr) { (*t_ctors_27.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -610,7 +625,7 @@ pub fn test_28() { let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(__p.clone()); + p9_destructor_not_potentially_invoked_HasUndefinedDestructor::constructor_1(__p.clone()); __p }; assert!(!((p).is_null())); @@ -631,13 +646,16 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { #[offset(0)] pub value: i32, } -impl DefaultConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn default_constructor(this: Ptr) { +impl p9_unused_copy_constructor_HasUndefinedCopyCtor { + pub fn constructor_1(this: Ptr) { field!(this, value).write(3); (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -646,10 +664,9 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { fn default() -> Self { { { - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -659,7 +676,10 @@ pub fn read_30(object: Ptr) -> return object.with(|__s| __s.value); } pub fn test_31() { - object!(a, p9_unused_copy_constructor_HasUndefinedCopyCtor); + object!( + a, + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1() + ); assert!((({ read_30(a.as_pointer(),) }) == 3)); assert!((ctor_calls_29.with(|rc| *rc.borrow()) == 1)); } @@ -677,11 +697,14 @@ thread_local!( Destructible, CopyConstructible, Movable, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} -impl DefaultConstructible for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn default_constructor(this: Ptr) { +impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + pub fn constructor_1(this: Ptr) { (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -690,10 +713,10 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { { { let __v: Value = - Rc::new(RefCell::new( - ::zero_init(), - )); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1( + __v.as_pointer(), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -710,26 +733,31 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { Destructible, Copyable, Default, + Conversions, )] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { #[offset(0)] #[byte_size(1)] pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } -impl DefaultConstructible for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, m)); +impl p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { + pub fn constructor_1(this: Ptr) { + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1(field_ptr!( + this, m + )); } } pub fn test_33() { object!( a, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); object!( b, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); assert!((m_ctors_32.with(|rc| *rc.borrow()) == 2)); } @@ -854,7 +882,9 @@ fn main_0() -> i32 { ({ test_51() }); return 0; } -#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] +#[derive( + Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg, ZeroInitialization, Destructible, Conversions, +)] #[byte_size(1)] pub struct p13_pointer_to_incomplete_class_X; impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { @@ -864,8 +894,8 @@ impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestruct ) } } -impl CopyConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn copy_constructor(this: Ptr, _: LvalueRef>) { +impl Constructor<(LvalueRef>,)> for p9_unused_copy_constructor_HasUndefinedCopyCtor { + fn constructor(this: Ptr, _: (LvalueRef>,)) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index a923657ccf..96d07ff20f 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -11,7 +11,6 @@ pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new( #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -20,7 +19,10 @@ pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new( Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct HasConstexprCtor { pub m: i32, } @@ -28,12 +30,10 @@ impl HasConstexprCtor { pub unsafe fn reset() { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) = 0; } - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).m).write(v); } -} -impl CopyConstructibleUnsafe for HasConstexprCtor { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const HasConstexprCtor); (&raw mut (*this).m).write((*o).m); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); @@ -53,6 +53,10 @@ pub static mut useCount_4: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -69,23 +73,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) }; } - pub unsafe fn use_(this: *const Self) { - (*(&raw const (*this).uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)).prefix_inc(); - } -} -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)).prefix_inc(); } -} -impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)).prefix_inc(); } + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)).prefix_inc(); + } } impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -96,13 +96,13 @@ pub unsafe fn test_5() { (unsafe { HasConstexprCtor::reset() }); let arr: [HasConstexprCtor; 2] = [ { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 3); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 3); __v }, { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 4); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 4); __v }, ]; @@ -110,13 +110,13 @@ pub unsafe fn test_5() { unsafe { return [ { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 3); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 3); __v }, { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 4); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 4); __v }, ][(1) as usize] @@ -129,12 +129,12 @@ pub unsafe fn test_5() { } pub unsafe fn test_6() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k, HasConstexprCtor(5)); + object_unsafe!(k, HasConstexprCtor::constructor_1(5)); let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { return { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 5); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 5); __v } .m; @@ -146,20 +146,20 @@ pub unsafe fn test_6() { } pub unsafe fn test_7() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k1, HasConstexprCtor(7)); - object_unsafe!(k2, HasConstexprCtor(9)); + object_unsafe!(k1, HasConstexprCtor::constructor_1(7)); + object_unsafe!(k2, HasConstexprCtor::constructor_1(9)); let mut f: FnPtr i32> = FnPtr:: i32>::new(|mut b: bool| -> i32 { unsafe { return (if b { { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 7); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 7); __v } } else { { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 9); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 9); __v } }) @@ -174,14 +174,14 @@ pub unsafe fn test_7() { pub static mut left_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); pub unsafe fn test_9() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k, HasConstexprCtor(5)); + object_unsafe!(k, HasConstexprCtor::constructor_1(5)); let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { return { (*std::cell::LazyCell::force_mut(&mut *&raw mut left_8)).prefix_inc(); { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 5); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 5); __v } } @@ -209,7 +209,9 @@ pub unsafe trait p4_1_pure_virtual_without_definition_HasPureVirtual { DefaultInitializableUnsafe, CopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} pub unsafe fn test_11() { let mut d: p4_1_pure_virtual_without_definition_OverridesPureVirtual = @@ -223,8 +225,8 @@ pub static mut global_12: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -253,13 +255,13 @@ pub unsafe fn test_13() { } pub unsafe fn test_14() { (unsafe { LifetimeTracked::reset() }); - object_unsafe!(t, LifetimeTracked); + object_unsafe!(t, LifetimeTracked::constructor_1()); let r: *mut LifetimeTracked = &mut t; let mut f: FnPtr = lambda_unsafe!( { let r: LifetimeTracked = { - let mut __v: LifetimeTracked = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(r)); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(r)); __v }; }, @@ -291,17 +293,20 @@ pub unsafe fn test_15() { } pub unsafe fn test_16() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k, HasConstexprCtor(5)); + object_unsafe!(k, HasConstexprCtor::constructor_1(5)); let mut f: FnPtr i32> = lambda_unsafe!( { let k: HasConstexprCtor = { - let mut __v: HasConstexprCtor = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&k)); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&k)); __v }; }, || -> i32 { - object_unsafe!(c, HasConstexprCtor, LvalueRefUnsafe::bind(&k)); + object_unsafe!( + c, + HasConstexprCtor::constructor_2(LvalueRefUnsafe::bind(&k)) + ); return c.m; } ); @@ -323,7 +328,6 @@ pub static mut copies_18: std::cell::LazyCell = std::cell::LazyCell::new(|| #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -332,19 +336,20 @@ pub static mut copies_18: std::cell::LazyCell = std::cell::LazyCell::new(|| Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { pub value: i32, pub scratch: i32, } impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).value).write(v); (&raw mut (*this).scratch).write(0); } -} -impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMember { - unsafe fn copy_constructor( + pub unsafe fn constructor_2( this: *mut Self, o: LvalueRefUnsafe>, ) { @@ -355,13 +360,19 @@ impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMe } } pub unsafe fn test_19() { - object_unsafe!(k, p5_2_mutable_subobject_is_odr_used_HasMutableMember(5)); + object_unsafe!( + k, + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_1(5) + ); let mut f: FnPtr i32> = lambda_unsafe!( { let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = { let mut __v: p5_2_mutable_subobject_is_odr_used_HasMutableMember = - ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&k)); + ZeroInitializationUnsafe::zero_init(); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_2( + &raw mut __v, + LvalueRefUnsafe::bind(&k), + ); __v }; }, @@ -378,16 +389,19 @@ pub unsafe fn test_19() { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[destroy] pub a: LifetimeTracked, #[destroy] pub b: LifetimeTracked, } -impl DefaultConstructibleUnsafe for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).a); - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).b); +impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + pub unsafe fn constructor_1(this: *mut Self) { + LifetimeTracked::constructor_1(&raw mut (*this).a); + LifetimeTracked::constructor_1(&raw mut (*this).b); } } pub unsafe fn test_20() { @@ -395,13 +409,13 @@ pub unsafe fn test_20() { let mut p: p6_unevaluated_binding_needs_no_capture_HasTwoMembers = p6_unevaluated_binding_needs_no_capture_HasTwoMembers { a: { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }, b: { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }, }; @@ -424,6 +438,9 @@ pub unsafe fn test_20() { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, @@ -441,16 +458,17 @@ impl p7_member_access_captures_this_HasMemberUsedInLambda { } ); } -} -impl DefaultConstructibleUnsafe for p7_member_access_captures_this_HasMemberUsedInLambda { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + pub unsafe fn constructor_1(this: *mut Self) { + LifetimeTracked::constructor_1(&raw mut (*this).x); (&raw mut (*this).n).write(1); } } pub unsafe fn test_22() { (unsafe { LifetimeTracked::reset() }); - object_unsafe!(c, p7_member_access_captures_this_HasMemberUsedInLambda); + object_unsafe!( + c, + p7_member_access_captures_this_HasMemberUsedInLambda::constructor_1() + ); let mut f: FnPtr i32> = (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&raw mut c) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); @@ -466,6 +484,9 @@ pub unsafe fn test_22() { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, @@ -478,17 +499,15 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } }); } -} -impl DefaultConstructibleUnsafe for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + pub unsafe fn constructor_1(this: *mut Self) { + LifetimeTracked::constructor_1(&raw mut (*this).x); } } pub unsafe fn test_23() { (unsafe { LifetimeTracked::reset() }); object_unsafe!( c, - p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda + p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::constructor_1() ); let mut f: FnPtr usize> = (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&raw mut c) }); @@ -529,9 +548,12 @@ pub static mut t_ctors_27: std::cell::LazyCell = std::cell::LazyCell::new(| MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} -impl DefaultConstructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - unsafe fn default_constructor(this: *mut Self) { +impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + pub unsafe fn constructor_1(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)).prefix_inc(); } } @@ -540,7 +562,7 @@ pub unsafe fn test_28() { let __p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = Box::leak( Box::new(::zero_init()), ); - DefaultConstructibleUnsafe::default_constructor(__p); + p9_destructor_not_potentially_invoked_HasUndefinedDestructor::constructor_1(__p); __p }; assert!(!((p).is_null())); @@ -559,11 +581,14 @@ pub static mut ctor_calls_29: std::cell::LazyCell = SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } -impl DefaultConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn default_constructor(this: *mut Self) { +impl p9_unused_copy_constructor_HasUndefinedCopyCtor { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(3); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)).prefix_inc(); } @@ -573,8 +598,8 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { unsafe { { let mut __v: p9_unused_copy_constructor_HasUndefinedCopyCtor = - ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + ZeroInitializationUnsafe::zero_init(); + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1(&raw mut __v); __v } } @@ -584,7 +609,10 @@ pub unsafe fn read_30(object: *const p9_unused_copy_constructor_HasUndefinedCopy return (*object).value; } pub unsafe fn test_31() { - object_unsafe!(a, p9_unused_copy_constructor_HasUndefinedCopyCtor); + object_unsafe!( + a, + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1() + ); assert!(((unsafe { read_30(&a,) }) == (3))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)) == (1))); } @@ -599,10 +627,13 @@ pub static mut m_ctors_32: std::cell::LazyCell = std::cell::LazyCell::new(| DestructibleUnsafe, CopyConstructibleUnsafe, MovableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} -impl DefaultConstructibleUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn default_constructor(this: *mut Self) { +impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + pub unsafe fn constructor_1(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)).prefix_inc(); } } @@ -611,8 +642,10 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { unsafe { { let mut __v: p9_unused_implicit_assignment_HasUndefinedCopyAssignment = - ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + ZeroInitializationUnsafe::zero_init(); + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1( + &raw mut __v, + ); __v } } @@ -628,25 +661,26 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { DestructibleUnsafe, CopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } -impl DefaultConstructibleUnsafe - for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment -{ - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).m); +impl p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { + pub unsafe fn constructor_1(this: *mut Self) { + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1(&raw mut (*this).m); } } pub unsafe fn test_33() { object_unsafe!( a, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); object_unsafe!( b, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)) == (2))); } @@ -759,7 +793,16 @@ unsafe fn main_0() -> i32 { (unsafe { test_51() }); return 0; } -#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] +#[derive( + Clone, + Copy, + Default, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + ConversionsUnsafe, +)] pub struct p13_pointer_to_incomplete_class_X; impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { unsafe fn destroy(this: *mut Self) { @@ -768,8 +811,10 @@ impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDe ) } } -impl CopyConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn copy_constructor(this: *mut Self, _: LvalueRefUnsafe>) { +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> + for p9_unused_copy_constructor_HasUndefinedCopyCtor +{ + unsafe fn constructor(this: *mut Self, _: (LvalueRefUnsafe>,)) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) diff --git a/tests/std/class/class.compare/out/refcount/class.spaceship.rs b/tests/std/class/class.compare/out/refcount/class.spaceship.rs index 22e6dc46f0..222558373f 100644 --- a/tests/std/class/class.compare/out/refcount/class.spaceship.rs +++ b/tests/std/class/class.compare/out/refcount/class.spaceship.rs @@ -20,6 +20,8 @@ use std::rc::{Rc, Weak}; PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(12)] pub struct p1_memberwise_in_declaration_order_Date { #[offset(0)] @@ -129,6 +131,8 @@ pub fn test_0() { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(16)] pub struct p2_common_comparison_category_Reading { #[offset(0)] @@ -217,6 +221,8 @@ pub fn test_1() { PartiallyOrderedWith, )] #[three_way(weak_ordering_from_user_operator_Fraction::operator_cmp)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct weak_ordering_from_user_operator_Fraction { #[offset(0)] @@ -340,6 +346,8 @@ pub fn test_2() { PartiallyOrderedWith, )] #[three_way(partial_ordering_from_user_operator_Interval::operator_cmp)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct partial_ordering_from_user_operator_Interval { #[offset(0)] diff --git a/tests/std/class/class.compare/out/unsafe/class.spaceship.rs b/tests/std/class/class.compare/out/unsafe/class.spaceship.rs index ce52094a51..38362beb7f 100644 --- a/tests/std/class/class.compare/out/unsafe/class.spaceship.rs +++ b/tests/std/class/class.compare/out/unsafe/class.spaceship.rs @@ -19,6 +19,8 @@ use std::rc::Rc; PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_memberwise_in_declaration_order_Date { pub year: i32, pub month: i32, @@ -129,6 +131,8 @@ pub unsafe fn test_0() { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p2_common_comparison_category_Reading { pub sensor: i32, pub value: f64, @@ -205,6 +209,8 @@ pub unsafe fn test_1() { PartiallyOrderedWithUnsafe, )] #[three_way(weak_ordering_from_user_operator_Fraction::operator_cmp)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct weak_ordering_from_user_operator_Fraction { pub numerator: i32, pub denominator: i32, @@ -313,6 +319,8 @@ pub unsafe fn test_2() { PartiallyOrderedWithUnsafe, )] #[three_way(partial_ordering_from_user_operator_Interval::operator_cmp)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct partial_ordering_from_user_operator_Interval { pub low: i32, pub high: i32, 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 2acd1ac802..e684057e0f 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 @@ -14,12 +14,13 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(8)] pub struct p13_3_member_reads_earlier_member_Pair { #[offset(0)] @@ -28,13 +29,16 @@ pub struct p13_3_member_reads_earlier_member_Pair { pub second: i32, } impl p13_3_member_reads_earlier_member_Pair { - pub fn construct(this: Ptr, mut first: i32) { + pub fn constructor_1(this: Ptr, mut first: i32) { field!(this, first).write(first); field!(this, second).write((this.with(|__s| __s.first) + 1)); } } pub fn test_0() { - object!(pair, p13_3_member_reads_earlier_member_Pair(5)); + object!( + pair, + p13_3_member_reads_earlier_member_Pair::constructor_1(5) + ); assert!(({ (*pair.borrow()).first } == 5)); assert!(({ (*pair.borrow()).second } == 6)); } 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 49daa0771f..89a481c297 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 @@ -13,24 +13,28 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct p13_3_member_reads_earlier_member_Pair { pub first: i32, pub second: i32, } impl p13_3_member_reads_earlier_member_Pair { - pub unsafe fn construct(this: *mut Self, mut first: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut first: i32) { (&raw mut (*this).first).write(first); (&raw mut (*this).second).write((((*this).first) + (1))); } } pub unsafe fn test_0() { - object_unsafe!(pair, p13_3_member_reads_earlier_member_Pair(5)); + object_unsafe!( + pair, + p13_3_member_reads_earlier_member_Pair::constructor_1(5) + ); assert!(((pair.first) == (5))); assert!(((pair.second) == (6))); } diff --git a/tests/std/class/class.mem/class.conv/class.conv.ctor.cpp b/tests/std/class/class.mem/class.conv/class.conv.ctor.cpp index ca0d542c43..fa63857a07 100644 --- a/tests/std/class/class.mem/class.conv/class.conv.ctor.cpp +++ b/tests/std/class/class.mem/class.conv/class.conv.ctor.cpp @@ -1,4 +1,5 @@ #include +#include // N4950 [class.conv.ctor]/1: A constructor that is not explicit (9.2.3) // specifies a conversion from the types of its parameters (if any) to the type @@ -17,7 +18,78 @@ void test() { } } // namespace p1_template_constructor_from_own_type +// N4950 [class.conv.ctor]/1: a constructor that is not explicit converts its +// argument implicitly, in copy-initialization and in the constructor of a +// pair from a pair of convertible types. +namespace p1_implicit_conversion_by_constructor { +struct Meters { + int value; + Meters(int v) : value(v) {} +}; + +void test() { + Meters m = 5; + assert(m.value == 5); + std::pair source{3, 4}; + std::pair copied(source); + assert(copied.first.value == 3 && copied.second == 4); + std::pair moved(std::pair{6, 7}); + assert(moved.first.value == 6 && moved.second == 7); +} +} // namespace p1_implicit_conversion_by_constructor + +// N4950 [class.conv.ctor]/2: an explicit constructor constructs objects just +// like a non-explicit one, but only where direct-initialization or a cast is +// used explicitly. +namespace p2_explicit_constructor { +struct Celsius { + int degrees; + explicit Celsius(int d) : degrees(d) {} +}; + +void test() { + Celsius direct(3); + assert(direct.degrees == 3); + Celsius cast = static_cast(4); + assert(cast.degrees == 4); + std::pair converted(std::pair{5, 6}); + assert(converted.first.degrees == 5 && converted.second == 6); +} +} // namespace p2_explicit_constructor + +// N4950 [class.conv.ctor]/2, [class.conv.fct]/2: for the same source, direct- +// initialization picks an explicit constructor of the target, while +// copy-initialization, where explicit constructors are not candidates, uses a +// conversion function of the source. +namespace p2_explicit_constructor_and_conversion_function { +struct Target; + +struct Source { + int value; + operator Target() const; +}; + +struct Target { + int from; + explicit Target(const Source &) : from(1) {} + Target(int f) : from(f) {} +}; + +Source::operator Target() const { return Target(2); } + +void test() { + Source source{0}; + Target direct(source); + assert(direct.from == 1); + Target copied = source; + assert(copied.from == 2); +} +} // namespace p2_explicit_constructor_and_conversion_function + int main() { p1_template_constructor_from_own_type::test(); + p1_implicit_conversion_by_constructor::test(); + p2_explicit_constructor::test(); + p2_explicit_constructor_and_conversion_function::test(); return 0; } diff --git a/tests/std/class/class.mem/class.conv/class.conv.fct.cpp b/tests/std/class/class.mem/class.conv/class.conv.fct.cpp index 4c083748a9..9b721ec476 100644 --- a/tests/std/class/class.mem/class.conv/class.conv.fct.cpp +++ b/tests/std/class/class.mem/class.conv/class.conv.fct.cpp @@ -1,4 +1,5 @@ #include +#include // N4950 [class.conv.fct]/2: A conversion function shall have no non-object // parameters and shall be a non-static member function of a class or class @@ -18,7 +19,63 @@ void test() { } } // namespace p2_non_const_conversion_function +// N4950 [class.conv.fct]/2: a conversion function is used implicitly, also +// where a pair converts its members. +namespace p2_implicit_conversion_function { +struct Ratio { + int numerator; + int denominator; + operator int() const { return numerator / denominator; } +}; + +void test() { + Ratio ratio{9, 3}; + int value = ratio; + assert(value == 3); + std::pair source{{8, 2}, {6, 3}}; + std::pair converted(source); + assert(converted.first == 4 && converted.second == 2); +} +} // namespace p2_implicit_conversion_function + +// N4950 [class.conv.fct]/2: an explicit conversion function is only used in +// direct-initialization, a cast or a contextual conversion to bool. +namespace p2_explicit_conversion_function { +struct Flag { + int value; + explicit operator bool() const { return value != 0; } +}; + +void test() { + Flag on{1}; + Flag off{0}; + assert(on); + assert(!off); + bool cast = static_cast(on); + assert(cast); +} +} // namespace p2_explicit_conversion_function + +// N4950 [class.conv.fct]/1, [dcl.init.ref]/5.1.2: a conversion function to an +// lvalue reference returns a reference that a reference binds to directly. +namespace p1_conversion_function_to_reference { +struct Holder { + int value; + operator int &() { return value; } +}; + +void test() { + Holder holder{1}; + int &ref = holder; + ref = 5; + assert(holder.value == 5); +} +} // namespace p1_conversion_function_to_reference + int main() { p2_non_const_conversion_function::test(); + p2_implicit_conversion_function::test(); + p2_explicit_conversion_function::test(); + p1_conversion_function_to_reference::test(); return 0; } 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 039b106303..7d5e62eabe 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 @@ -7,7 +7,11 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; impl p1_template_constructor_from_own_type_Probe { - pub fn construct_1(this: Ptr, u: Ptr) { + pub fn constructor_2_1( + this: Ptr, + u: LvalueRef, + ) { + let u = u.as_pointer(); field!(this, value).write((u.with(|__s| __s.value) + 1)); } } @@ -19,39 +23,310 @@ impl p1_template_constructor_from_own_type_Probe { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct_2, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2_1, LvalueRef)] #[byte_size(4)] pub struct p1_template_constructor_from_own_type_Probe { #[offset(0)] pub value: i32, } impl p1_template_constructor_from_own_type_Probe { - pub fn construct_2(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, value).write(v); } } pub fn test_0() { object!( probe, - p1_template_constructor_from_own_type_Probe::construct_2(22) + p1_template_constructor_from_own_type_Probe::constructor_1(22) ); object!( converted, - p1_template_constructor_from_own_type_Probe::construct_1(probe.as_pointer()) + p1_template_constructor_from_own_type_Probe::constructor_2_1(LvalueRef::bind( + probe.as_pointer() + )) ); assert!(({ (*converted.borrow()).value } == 23)); } +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[byte_size(4)] +pub struct p1_implicit_conversion_by_constructor_Meters { + #[offset(0)] + pub value: i32, +} +impl p1_implicit_conversion_by_constructor_Meters { + pub fn constructor_1(this: Ptr, mut v: i32) { + field!(this, value).write(v); + } +} +pub fn test_1() { + let mut m: p1_implicit_conversion_by_constructor_Meters = { + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p1_implicit_conversion_by_constructor_Meters::constructor_1(__v.as_pointer(), 5); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + assert!((m.value == 5)); + let source: Value<(Value, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(3)), + Rc::new(RefCell::new(4)), + ))); + let copied: Value<( + Value, + Value, + )> = Rc::new(RefCell::new({ + object!( + __first, + p1_implicit_conversion_by_constructor_Meters, + |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind( + (*source.borrow()).0.as_pointer() + ),) + ) + ); + object!(__second, i64, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind( + (*source.borrow()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + })); + assert!( + ({ + ({ (*(*copied.borrow()).0.borrow()).value } == 3) + && ((*(*copied.borrow()).1.borrow()) == 4_i64) + }) + ); + let moved: Value<( + Value, + Value, + )> = Rc::new(RefCell::new( + match (Rc::new(RefCell::new(( + Rc::new(RefCell::new(6)), + Rc::new(RefCell::new(7)), + ))) + .as_pointer(),) + { + (__tmp_0,) => { + object!( + __first, + p1_implicit_conversion_by_constructor_Meters, + |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_0.upgrade().deref()).0.as_pointer() + ),) + ) + ); + object!(__second, i64, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_0.upgrade().deref()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + } + }, + )); + assert!( + ({ + ({ (*(*moved.borrow()).0.borrow()).value } == 6) + && ((*(*moved.borrow()).1.borrow()) == 7_i64) + }) + ); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, i32)] +#[byte_size(4)] +pub struct p2_explicit_constructor_Celsius { + #[offset(0)] + pub degrees: i32, +} +impl p2_explicit_constructor_Celsius { + pub fn constructor_1(this: Ptr, mut d: i32) { + field!(this, degrees).write(d); + } +} +pub fn test_2() { + object!(direct, p2_explicit_constructor_Celsius::constructor_1(3)); + assert!(({ (*direct.borrow()).degrees } == 3)); + let mut cast: p2_explicit_constructor_Celsius = { + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_explicit_constructor_Celsius::constructor_1(__v.as_pointer(), 4); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + assert!((cast.degrees == 4)); + let converted: Value<(Value, Value)> = + Rc::new(RefCell::new( + match (Rc::new(RefCell::new(( + Rc::new(RefCell::new(5)), + Rc::new(RefCell::new(6)), + ))) + .as_pointer(),) + { + (__tmp_1,) => { + object!(__first, p2_explicit_constructor_Celsius, |__this| { + ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_1.upgrade().deref()).0.as_pointer(), + ),), + ) + }); + object!(__second, i32, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_1.upgrade().deref()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + } + }, + )); + assert!( + ({ + ({ (*(*converted.borrow()).0.borrow()).degrees } == 5) + && ((*(*converted.borrow()).1.borrow()) == 6) + }) + ); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[byte_size(4)] +pub struct p2_explicit_constructor_and_conversion_function_Source { + #[offset(0)] + pub value: i32, +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, LvalueRef>)] +#[constructor(constructor_2, i32)] +#[byte_size(4)] +pub struct p2_explicit_constructor_and_conversion_function_Target { + #[offset(0)] + pub from: i32, +} +impl p2_explicit_constructor_and_conversion_function_Target { + pub fn constructor_1( + this: Ptr, + _a0: LvalueRef>, + ) { + let _a0 = _a0.as_pointer(); + field!(this, from).write(1); + } + pub fn constructor_2(this: Ptr, mut f: i32) { + field!(this, from).write(f); + } +} +impl p2_explicit_constructor_and_conversion_function_Source { + pub fn to_p2_explicit_constructor_and_conversion_function_Target( + this: Ptr, + ) -> p2_explicit_constructor_and_conversion_function_Target { + return { + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_explicit_constructor_and_conversion_function_Target::constructor_2( + __v.as_pointer(), + 2, + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + } +} +pub fn test_3() { + let source: Value = Rc::new( + RefCell::new(p2_explicit_constructor_and_conversion_function_Source { value: 0 }), + ); + object!( + direct, + p2_explicit_constructor_and_conversion_function_Target::constructor_1(LvalueRef::bind( + source.as_pointer() + )) + ); + assert!(({ (*direct.borrow()).from } == 1)); + let mut copied: p2_explicit_constructor_and_conversion_function_Target = ({ + p2_explicit_constructor_and_conversion_function_Source :: to_p2_explicit_constructor_and_conversion_function_Target ( source .as_pointer() , ) + }); + assert!((copied.from == 2)); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { ({ test_0() }); + ({ test_1() }); + ({ test_2() }); + ({ test_3() }); return 0; } pub fn __cpp2rust_init_globals() {} 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 5a5238fcda..4c4224906a 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 @@ -14,12 +14,13 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, - CppFrom, TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_into(i64, to_i64, mut_ptr)] +#[conversions(copy, move)] +#[conversion_function(to_i64, LvalueRef, i64 )] #[byte_size(8)] pub struct p2_non_const_conversion_function_Gauge { #[offset(0)] @@ -40,12 +41,169 @@ pub fn test_0() { assert!((converted == 21_i64)); assert!(({ (*gauge.borrow()).value } == 21_i64)); } +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRef>, i32 )] +#[byte_size(8)] +pub struct p2_implicit_conversion_function_Ratio { + #[offset(0)] + pub numerator: i32, + #[offset(4)] + pub denominator: i32, +} +impl p2_implicit_conversion_function_Ratio { + pub fn to_i32(this: Ptr) -> i32 { + return (this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator)); + } +} +pub fn test_1() { + let ratio: Value = + Rc::new(RefCell::new(p2_implicit_conversion_function_Ratio { + numerator: 9, + denominator: 3, + })); + let mut value: i32 = ({ p2_implicit_conversion_function_Ratio::to_i32(ratio.as_pointer()) }); + assert!((value == 3)); + let source: Value<( + Value, + Value, + )> = Rc::new(RefCell::new(( + Rc::new(RefCell::new( + (p2_implicit_conversion_function_Ratio { + numerator: 8, + denominator: 2, + }), + )), + Rc::new(RefCell::new( + (p2_implicit_conversion_function_Ratio { + numerator: 6, + denominator: 3, + }), + )), + ))); + let converted: Value<(Value, Value)> = Rc::new(RefCell::new({ + object!(__first, i32, |__this| ConstructibleFrom::construct( + __this, + ( + LvalueRef::>::bind( + (*source.borrow()).0.as_pointer() + ), + ) + )); + object!(__second, i64, |__this| ConstructibleFrom::construct( + __this, + ( + LvalueRef::>::bind( + (*source.borrow()).1.as_pointer() + ), + ) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + })); + assert!( + ({ + ((*(*converted.borrow()).0.borrow()) == 4) + && ((*(*converted.borrow()).1.borrow()) == 2_i64) + }) + ); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] +#[byte_size(4)] +pub struct p2_explicit_conversion_function_Flag { + #[offset(0)] + pub value: i32, +} +impl p2_explicit_conversion_function_Flag { + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.value) != 0); + } +} +pub fn test_2() { + let on: Value = + Rc::new(RefCell::new(p2_explicit_conversion_function_Flag { + value: 1, + })); + let off: Value = + Rc::new(RefCell::new(p2_explicit_conversion_function_Flag { + value: 0, + })); + assert!(({ p2_explicit_conversion_function_Flag::to_bool(on.as_pointer(),) })); + assert!(!({ p2_explicit_conversion_function_Flag::to_bool(off.as_pointer(),) })); + let mut cast: bool = ({ p2_explicit_conversion_function_Flag::to_bool(on.as_pointer()) }); + assert!(cast); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[byte_size(4)] +pub struct p1_conversion_function_to_reference_Holder { + #[offset(0)] + pub value: i32, +} +impl p1_conversion_function_to_reference_Holder { + pub fn to_pmuti32(this: Ptr) -> Ptr { + return field_ptr!(this, value); + } +} +pub fn test_3() { + let holder: Value = + Rc::new(RefCell::new(p1_conversion_function_to_reference_Holder { + value: 1, + })); + let ref_: Ptr = + ({ p1_conversion_function_to_reference_Holder::to_pmuti32(holder.as_pointer()) }); + ref_.write(5); + assert!(({ (*holder.borrow()).value } == 5)); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { ({ test_0() }); + ({ test_1() }); + ({ test_2() }); + ({ test_3() }); return 0; } pub fn __cpp2rust_init_globals() {} 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 22ce4586f5..ec44ca2f4a 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 @@ -7,10 +7,11 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; impl p1_template_constructor_from_own_type_Probe { - pub unsafe fn construct_1( + pub unsafe fn constructor_2_1( this: *mut Self, - u: *mut p1_template_constructor_from_own_type_Probe, + u: LvalueRefUnsafe, ) { + let u = (u.as_ptr() as *mut p1_template_constructor_from_own_type_Probe); (&raw mut (*this).value).write((((*u).value) + (1))); } } @@ -21,31 +22,233 @@ impl p1_template_constructor_from_own_type_Probe { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct_2, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2_1, LvalueRefUnsafe)] pub struct p1_template_constructor_from_own_type_Probe { pub value: i32, } impl p1_template_constructor_from_own_type_Probe { - pub unsafe fn construct_2(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).value).write(v); } } pub unsafe fn test_0() { object_unsafe!( probe, - p1_template_constructor_from_own_type_Probe::construct_2(22) + p1_template_constructor_from_own_type_Probe::constructor_1(22) ); object_unsafe!( converted, - p1_template_constructor_from_own_type_Probe::construct_1(&mut probe) + p1_template_constructor_from_own_type_Probe::constructor_2_1(LvalueRefUnsafe::bind( + &mut probe + )) ); assert!(((converted.value) == (23))); } +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +pub struct p1_implicit_conversion_by_constructor_Meters { + pub value: i32, +} +impl p1_implicit_conversion_by_constructor_Meters { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); + } +} +pub unsafe fn test_1() { + let mut m: p1_implicit_conversion_by_constructor_Meters = { + let mut __v: p1_implicit_conversion_by_constructor_Meters = + ZeroInitializationUnsafe::zero_init(); + p1_implicit_conversion_by_constructor_Meters::constructor_1(&raw mut __v, 5); + __v + }; + assert!(((m.value) == (5))); + let mut source: (i32, i32) = (3, 4); + let mut copied: (p1_implicit_conversion_by_constructor_Meters, i64) = { + object_unsafe!( + __first, + p1_implicit_conversion_by_constructor_Meters, + |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const source.0),) + ) + ); + object_unsafe!(__second, i64, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const source.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + }; + assert!(((copied.0.value) == (3)) && ((copied.1) == (4_i64))); + let mut moved: (p1_implicit_conversion_by_constructor_Meters, i64) = + match ((&mut (6, 7) as *mut (i32, i32)),) { + (__tmp_0,) => { + object_unsafe!( + __first, + p1_implicit_conversion_by_constructor_Meters, + |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).0),) + ) + ); + object_unsafe!(__second, i64, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + } + }; + assert!(((moved.0.value) == (6)) && ((moved.1) == (7_i64))); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, i32)] +pub struct p2_explicit_constructor_Celsius { + pub degrees: i32, +} +impl p2_explicit_constructor_Celsius { + pub unsafe fn constructor_1(this: *mut Self, mut d: i32) { + (&raw mut (*this).degrees).write(d); + } +} +pub unsafe fn test_2() { + object_unsafe!(direct, p2_explicit_constructor_Celsius::constructor_1(3)); + assert!(((direct.degrees) == (3))); + let mut cast: p2_explicit_constructor_Celsius = { + let mut __v: p2_explicit_constructor_Celsius = ZeroInitializationUnsafe::zero_init(); + p2_explicit_constructor_Celsius::constructor_1(&raw mut __v, 4); + __v + }; + assert!(((cast.degrees) == (4))); + let mut converted: (p2_explicit_constructor_Celsius, i32) = + match ((&mut (5, 6) as *mut (i32, i32)),) { + (__tmp_1,) => { + object_unsafe!(__first, p2_explicit_constructor_Celsius, |__this| { + ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_1).0),), + ) + }); + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_1).1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + } + }; + assert!(((converted.0.degrees) == (5)) && ((converted.1) == (6))); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +pub struct p2_explicit_constructor_and_conversion_function_Source { + pub value: i32, +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, LvalueRefUnsafe>)] +#[constructor(constructor_2, i32)] +pub struct p2_explicit_constructor_and_conversion_function_Target { + pub from: i32, +} +impl p2_explicit_constructor_and_conversion_function_Target { + pub unsafe fn constructor_1( + this: *mut Self, + _a0: LvalueRefUnsafe>, + ) { + let _a0 = (_a0.as_ptr() as *const p2_explicit_constructor_and_conversion_function_Source); + (&raw mut (*this).from).write(1); + } + pub unsafe fn constructor_2(this: *mut Self, mut f: i32) { + (&raw mut (*this).from).write(f); + } +} +impl p2_explicit_constructor_and_conversion_function_Source { + pub unsafe fn to_p2_explicit_constructor_and_conversion_function_Target( + this: *const Self, + ) -> p2_explicit_constructor_and_conversion_function_Target { + return { + let mut __v: p2_explicit_constructor_and_conversion_function_Target = + ZeroInitializationUnsafe::zero_init(); + p2_explicit_constructor_and_conversion_function_Target::constructor_2(&raw mut __v, 2); + __v + }; + } +} +pub unsafe fn test_3() { + let mut source: p2_explicit_constructor_and_conversion_function_Source = + p2_explicit_constructor_and_conversion_function_Source { value: 0 }; + object_unsafe!( + direct, + p2_explicit_constructor_and_conversion_function_Target::constructor_1( + LvalueRefUnsafe::bind(&source) + ) + ); + assert!(((direct.from) == (1))); + let mut copied: p2_explicit_constructor_and_conversion_function_Target = (unsafe { + p2_explicit_constructor_and_conversion_function_Source :: to_p2_explicit_constructor_and_conversion_function_Target ( &raw const source , ) + }); + assert!(((copied.from) == (2))); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -54,6 +257,9 @@ pub fn main() { } unsafe fn main_0() -> i32 { (unsafe { test_0() }); + (unsafe { test_1() }); + (unsafe { test_2() }); + (unsafe { test_3() }); return 0; } pub unsafe fn __cpp2rust_init_globals() {} 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 ef93a9bc00..9aa229123c 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 @@ -13,12 +13,13 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_into(i64, to_i64, mut_ptr)] +#[conversions(copy, move)] +#[conversion_function(to_i64, LvalueRefUnsafe, i64 )] pub struct p2_non_const_conversion_function_Gauge { pub value: i64, } @@ -35,6 +36,131 @@ pub unsafe fn test_0() { assert!(((converted) == (21_i64))); assert!(((gauge.value) == (21_i64))); } +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] +pub struct p2_implicit_conversion_function_Ratio { + pub numerator: i32, + pub denominator: i32, +} +impl p2_implicit_conversion_function_Ratio { + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (((*this).numerator) / ((*this).denominator)); + } +} +pub unsafe fn test_1() { + let mut ratio: p2_implicit_conversion_function_Ratio = p2_implicit_conversion_function_Ratio { + numerator: 9, + denominator: 3, + }; + let mut value: i32 = + (unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const ratio) }); + assert!(((value) == (3))); + let mut source: ( + p2_implicit_conversion_function_Ratio, + p2_implicit_conversion_function_Ratio, + ) = ( + (p2_implicit_conversion_function_Ratio { + numerator: 8, + denominator: 2, + }), + (p2_implicit_conversion_function_Ratio { + numerator: 6, + denominator: 3, + }), + ); + let mut converted: (i32, i64) = { + object_unsafe!(__first, i32, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::< + Const, + >::bind(&raw const source.0),) + )); + object_unsafe!(__second, i64, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::< + Const, + >::bind(&raw const source.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + }; + assert!(((converted.0) == (4)) && ((converted.1) == (2_i64))); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] +pub struct p2_explicit_conversion_function_Flag { + pub value: i32, +} +impl p2_explicit_conversion_function_Flag { + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).value) != (0)); + } +} +pub unsafe fn test_2() { + let mut on: p2_explicit_conversion_function_Flag = + p2_explicit_conversion_function_Flag { value: 1 }; + let mut off: p2_explicit_conversion_function_Flag = + p2_explicit_conversion_function_Flag { value: 0 }; + assert!((unsafe { p2_explicit_conversion_function_Flag::to_bool(&raw const on,) })); + assert!(!(unsafe { p2_explicit_conversion_function_Flag::to_bool(&raw const off,) })); + let mut cast: bool = (unsafe { p2_explicit_conversion_function_Flag::to_bool(&raw const on) }); + assert!(cast); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +pub struct p1_conversion_function_to_reference_Holder { + pub value: i32, +} +impl p1_conversion_function_to_reference_Holder { + pub unsafe fn to_pmuti32(this: *mut Self) -> *mut i32 { + return &mut (*this).value; + } +} +pub unsafe fn test_3() { + let mut holder: p1_conversion_function_to_reference_Holder = + p1_conversion_function_to_reference_Holder { value: 1 }; + let ref_: *mut i32 = + (unsafe { p1_conversion_function_to_reference_Holder::to_pmuti32(&raw mut holder) }); + (*ref_) = 5; + assert!(((holder.value) == (5))); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -43,6 +169,9 @@ pub fn main() { } unsafe fn main_0() -> i32 { (unsafe { test_0() }); + (unsafe { test_1() }); + (unsafe { test_2() }); + (unsafe { test_3() }); return 0; } pub unsafe fn __cpp2rust_init_globals() {} 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 206493ac95..6f462ee343 100644 --- a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs @@ -7,24 +7,19 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { #[offset(0)] pub value: i32, } impl p11_defaulted_move_constructor_is_trivial_MoveOnly { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } } @@ -34,20 +29,21 @@ pub fn pass_0( let object: Value = Rc::new(RefCell::new(object)); return { - let __v: Value = Rc::new(RefCell::new( - ::zero_init(), - )); - MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(object.as_pointer())); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ::move_constructor( + __v.as_pointer(), + RvalueRef::bind(object.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn test_1() { let mut result: p11_defaulted_move_constructor_is_trivial_MoveOnly = ({ pass_0({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(__v.as_pointer(), 7); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p11_defaulted_move_constructor_is_trivial_MoveOnly::constructor_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }); 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 5a52ddae70..d59560429f 100644 --- a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs @@ -8,20 +8,17 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - CppFromUnsafe, - DefaultInitializableUnsafe, - MemberwiseUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { pub value: i32, } impl p11_defaulted_move_constructor_is_trivial_MoveOnly { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } } @@ -30,8 +27,8 @@ pub unsafe fn pass_0( ) -> p11_defaulted_move_constructor_is_trivial_MoveOnly { return { let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = - ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(&mut object)); + ZeroInitializationUnsafe::zero_init(); + ::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(& mut object )) ; __v }; } @@ -39,8 +36,8 @@ pub unsafe fn test_1() { let mut result: p11_defaulted_move_constructor_is_trivial_MoveOnly = (unsafe { pass_0({ let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = - ::zero_init(); - p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(&raw mut __v, 7); + ZeroInitializationUnsafe::zero_init(); + p11_defaulted_move_constructor_is_trivial_MoveOnly::constructor_1(&raw mut __v, 7); __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 472b787e90..b432d72898 100644 --- a/tests/std/class/class.mem/out/refcount/class.free.rs +++ b/tests/std/class/class.mem/out/refcount/class.free.rs @@ -20,7 +20,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p1_allocation_function_is_static_Allocates {} impl p1_allocation_function_is_static_Allocates { @@ -68,7 +70,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 d33d83e7b8..977c66d683 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,19 @@ 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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p7_1_function_body_names_later_member_HasLaterMembers { #[offset(0)] @@ -32,9 +44,7 @@ impl p7_1_function_body_names_later_member_HasLaterMembers { pub fn minimum(this: Ptr) -> i32 { return 2; } -} -impl DefaultConstructible for p7_1_function_body_names_later_member_HasLaterMembers { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, stock).write(9); } } @@ -46,7 +56,7 @@ impl Default for p7_1_function_body_names_later_member_HasLaterMembers { pub fn test_3() { object!( object, - p7_1_function_body_names_later_member_HasLaterMembers + p7_1_function_body_names_later_member_HasLaterMembers::constructor_1() ); assert!( (({ @@ -62,7 +72,19 @@ thread_local!( thread_local!( pub static step_5: Value = Rc::new(RefCell::new(4)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { #[offset(0)] @@ -75,9 +97,7 @@ impl p7_2_default_argument_names_later_member_HasLaterStaticStep { }; return this.with(|__s| __s.total); } -} -impl DefaultConstructible for p7_2_default_argument_names_later_member_HasLaterStaticStep { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, total).write(1); } } @@ -89,7 +109,7 @@ impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { pub fn test_6() { object!( object, - p7_2_default_argument_names_later_member_HasLaterStaticStep + p7_2_default_argument_names_later_member_HasLaterStaticStep::constructor_1() ); assert!( (({ 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 108af2684c..cc8588b0d2 100644 --- a/tests/std/class/class.mem/out/unsafe/class.free.rs +++ b/tests/std/class/class.mem/out/unsafe/class.free.rs @@ -17,7 +17,9 @@ pub static mut allocations_0: std::cell::LazyCell = std::cell::LazyCell::ne TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 { @@ -60,7 +62,9 @@ pub static mut deallocations_2: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 f67e1176e4..5eace88cf7 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,17 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p7_1_function_body_names_later_member_HasLaterMembers { pub stock: i32, } @@ -29,9 +39,7 @@ impl p7_1_function_body_names_later_member_HasLaterMembers { pub unsafe fn minimum(this: *const Self) -> i32 { return 2; } -} -impl DefaultConstructibleUnsafe for p7_1_function_body_names_later_member_HasLaterMembers { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).stock).write(9); } } @@ -43,7 +51,7 @@ impl Default for p7_1_function_body_names_later_member_HasLaterMembers { pub unsafe fn test_3() { object_unsafe!( object, - p7_1_function_body_names_later_member_HasLaterMembers + p7_1_function_body_names_later_member_HasLaterMembers::constructor_1() ); assert!( ((unsafe { @@ -56,7 +64,17 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { pub total: i32, } @@ -65,9 +83,7 @@ impl p7_2_default_argument_names_later_member_HasLaterStaticStep { (*this).total += amount; return (*this).total; } -} -impl DefaultConstructibleUnsafe for p7_2_default_argument_names_later_member_HasLaterStaticStep { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).total).write(1); } } @@ -79,7 +95,7 @@ impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { pub unsafe fn test_6() { object_unsafe!( object, - p7_2_default_argument_names_later_member_HasLaterStaticStep + p7_2_default_argument_names_later_member_HasLaterStaticStep::constructor_1() ); assert!( ((unsafe { diff --git a/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs b/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs index ac6ac28c57..36685a983f 100644 --- a/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs +++ b/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs @@ -20,7 +20,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_3_not_equal_Meters { #[offset(0)] @@ -55,7 +57,9 @@ pub fn test_1() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_2_reversed_operands_Meters { #[offset(0)] @@ -100,7 +104,9 @@ pub fn test_2() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_different_types_Meters { #[offset(0)] diff --git a/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs b/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs index 50ccf0d955..ac877077aa 100644 --- a/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs +++ b/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs @@ -26,7 +26,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_each_relation_is_an_operator_Score { #[offset(0)] @@ -70,6 +72,8 @@ pub fn test_3() { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_relations_from_three_way_Level { #[offset(0)] @@ -132,7 +136,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_operator_preferred_over_three_way_Level { #[offset(0)] diff --git a/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs b/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs index 527546e493..232ae81cb3 100644 --- a/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs +++ b/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs @@ -18,7 +18,9 @@ pub static mut not_equal_calls_0: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p1_3_not_equal_Meters { pub value: i32, } @@ -43,7 +45,9 @@ pub unsafe fn test_1() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p1_2_reversed_operands_Meters { pub value: i32, } @@ -84,7 +88,9 @@ pub unsafe fn test_2() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p1_different_types_Meters { pub value: i32, } diff --git a/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs b/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs index 7f1cfd2937..4afcb87738 100644 --- a/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs +++ b/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs @@ -22,7 +22,9 @@ pub static mut greater_equal_calls_2: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p1_each_relation_is_an_operator_Score { pub points: i32, } @@ -64,6 +66,8 @@ pub unsafe fn test_3() { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_relations_from_three_way_Level { pub depth: i32, } @@ -125,7 +129,9 @@ pub static mut greater_calls_5: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p1_operator_preferred_over_three_way_Level { pub depth: i32, } diff --git a/tests/std/concepts/concepts.lang/concept.constructible.cpp b/tests/std/concepts/concepts.lang/concept.constructible.cpp new file mode 100644 index 0000000000..f2d46c0d64 --- /dev/null +++ b/tests/std/concepts/concepts.lang/concept.constructible.cpp @@ -0,0 +1,56 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include +#include +#include + +// N4950 [concept.constructible]/1: constructible_from holds when a +// T can be direct-initialized from Args, whether the constructor is explicit +// or not, and from a conversion function of the argument. +namespace p1_constructible_from { +struct Meters { + int value; + explicit Meters(int v) : value(v) {} +}; + +struct Ratio { + int numerator; + int denominator; + explicit operator int() const { return numerator / denominator; } +}; + +static_assert(std::constructible_from); +static_assert(std::constructible_from); +static_assert(!std::constructible_from); + +void test() { + std::pair source{2, {9, 3}}; + std::pair converted(source); + assert(converted.first.value == 2 && converted.second == 3); +} +} // namespace p1_constructible_from + +// N4950 [concept.copyconstructible]/1: copy_constructible requires +// constructing a T from a T lvalue, a const T lvalue and a T rvalue. +namespace p1_copy_constructible { +struct NonConstCopy { + int value; + NonConstCopy(int v) : value(v) {} + NonConstCopy(NonConstCopy &other) : value(other.value + 1) {} +}; + +static_assert(std::constructible_from); +static_assert(!std::constructible_from); +static_assert(!std::copy_constructible); + +void test() { + NonConstCopy original(1); + NonConstCopy copy(original); + assert(copy.value == 2); +} +} // namespace p1_copy_constructible + +int main() { + p1_constructible_from::test(); + p1_copy_constructible::test(); + return 0; +} diff --git a/tests/std/concepts/concepts.lang/concept.convertible.cpp b/tests/std/concepts/concepts.lang/concept.convertible.cpp new file mode 100644 index 0000000000..7537adad03 --- /dev/null +++ b/tests/std/concepts/concepts.lang/concept.convertible.cpp @@ -0,0 +1,59 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include +#include +#include + +// N4950 [concept.convertible]/1: convertible_to holds when a From is +// implicitly converted to a To, by a non-explicit constructor of To or a +// non-explicit conversion function of From; an explicit one does not count. +namespace p1_convertible_to { +struct Meters { + int value; + Meters(int v) : value(v) {} +}; + +struct Celsius { + int degrees; + explicit Celsius(int d) : degrees(d) {} +}; + +struct Ratio { + int numerator; + int denominator; + operator int() const { return numerator / denominator; } +}; + +static_assert(std::convertible_to); +static_assert(!std::convertible_to); +static_assert(std::convertible_to); + +Meters to_meters(Meters meters) { return meters; } + +void test() { + Meters meters = to_meters(7); + assert(meters.value == 7); + Ratio ratio{8, 4}; + int value = ratio; + assert(value == 2); + std::pair converted = std::pair{3, {10, 5}}; + assert(converted.first.value == 3 && converted.second == 2); +} +} // namespace p1_convertible_to + +// N4950 [conv.prom]/1, [conv.integral]/1: an arithmetic type converts to +// another implicitly, by promotion or by an integral conversion. +namespace p1_arithmetic_conversion { +void test() { + std::pair source{1, 2}; + std::pair converted = source; + assert(converted.first == 1 && converted.second == 2); + std::pair flags = std::pair{3, 4}; + assert(flags.first && flags.second == 4.0); +} +} // namespace p1_arithmetic_conversion + +int main() { + p1_convertible_to::test(); + p1_arithmetic_conversion::test(); + return 0; +} diff --git a/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs b/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs new file mode 100644 index 0000000000..3d6901ad4e --- /dev/null +++ b/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs @@ -0,0 +1,157 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +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, + DefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, i32)] +#[byte_size(4)] +pub struct p1_constructible_from_Meters { + #[offset(0)] + pub value: i32, +} +impl p1_constructible_from_Meters { + pub fn constructor_1(this: Ptr, mut v: i32) { + field!(this, value).write(v); + } +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRef>, i32 , explicit)] +#[byte_size(8)] +pub struct p1_constructible_from_Ratio { + #[offset(0)] + pub numerator: i32, + #[offset(4)] + pub denominator: i32, +} +impl p1_constructible_from_Ratio { + pub fn to_i32(this: Ptr) -> i32 { + return (this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator)); + } +} +const _: () = assert!(true, "std::constructible_from"); +const _: () = assert!(true, "std::constructible_from"); +const _: () = assert!(!(false), "!std::constructible_from"); +pub fn test_0() { + let source: Value<(Value, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(2)), + Rc::new(RefCell::new( + (p1_constructible_from_Ratio { + numerator: 9, + denominator: 3, + }), + )), + ))); + let converted: Value<(Value, Value)> = + Rc::new(RefCell::new({ + object!(__first, p1_constructible_from_Meters, |__this| { + ConstructibleFrom::construct( + __this, + (LvalueRef::::bind((*source.borrow()).0.as_pointer()),), + ) + }); + object!(__second, i32, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::::bind( + (*source.borrow()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + })); + assert!( + ({ + ({ (*(*converted.borrow()).0.borrow()).value } == 2) + && ((*(*converted.borrow()).1.borrow()) == 3) + }) + ); +} +#[derive( + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + DefaultInitializable, + Memberwise, + MoveAssignable, + Default, +)] +#[memberwise(copy_assign)] +#[derive(Conversions)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef)] +#[byte_size(4)] +pub struct p1_copy_constructible_NonConstCopy { + #[offset(0)] + pub value: i32, +} +impl p1_copy_constructible_NonConstCopy { + pub fn constructor_1(this: Ptr, mut v: i32) { + field!(this, value).write(v); + } + pub fn constructor_2(this: Ptr, other: LvalueRef) { + let other = other.as_pointer(); + field!(this, value).write((other.with(|__s| __s.value) + 1)); + } +} +const _: () = assert!( + true, + "std::constructible_from" +); +const _: () = assert!( + !(false), + "!std::constructible_from" +); +const _: () = assert!(!(false), "!std::copy_constructible"); +pub fn test_1() { + object!( + original, + p1_copy_constructible_NonConstCopy::constructor_1(1) + ); + object!( + copy, + p1_copy_constructible_NonConstCopy::constructor_2(LvalueRef::bind(original.as_pointer())) + ); + assert!(({ (*copy.borrow()).value } == 2)); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_1() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs b/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs new file mode 100644 index 0000000000..08b66f6b78 --- /dev/null +++ b/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs @@ -0,0 +1,212 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +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, + DefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[byte_size(4)] +pub struct p1_convertible_to_Meters { + #[offset(0)] + pub value: i32, +} +impl p1_convertible_to_Meters { + pub fn constructor_1(this: Ptr, mut v: i32) { + field!(this, value).write(v); + } +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, i32)] +#[byte_size(4)] +pub struct p1_convertible_to_Celsius { + #[offset(0)] + pub degrees: i32, +} +impl p1_convertible_to_Celsius { + pub fn constructor_1(this: Ptr, mut d: i32) { + field!(this, degrees).write(d); + } +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRef>, i32 )] +#[byte_size(8)] +pub struct p1_convertible_to_Ratio { + #[offset(0)] + pub numerator: i32, + #[offset(4)] + pub denominator: i32, +} +impl p1_convertible_to_Ratio { + pub fn to_i32(this: Ptr) -> i32 { + return (this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator)); + } +} +const _: () = assert!(true, "std::convertible_to"); +const _: () = assert!(!(false), "!std::convertible_to"); +const _: () = assert!(true, "std::convertible_to"); +pub fn to_meters_0(mut meters: p1_convertible_to_Meters) -> p1_convertible_to_Meters { + return meters; +} +pub fn test_1() { + let mut meters: p1_convertible_to_Meters = ({ + to_meters_0({ + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p1_convertible_to_Meters::constructor_1(__v.as_pointer(), 7); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) + }); + assert!((meters.value == 7)); + let ratio: Value = Rc::new(RefCell::new(p1_convertible_to_Ratio { + numerator: 8, + denominator: 4, + })); + let mut value: i32 = ({ p1_convertible_to_Ratio::to_i32(ratio.as_pointer()) }); + assert!((value == 2)); + let converted: Value<(Value, Value)> = Rc::new(RefCell::new( + match (Rc::new(RefCell::new(( + Rc::new(RefCell::new(3)), + Rc::new(RefCell::new( + (p1_convertible_to_Ratio { + numerator: 10, + denominator: 5, + }), + )), + ))) + .as_pointer(),) + { + (__tmp_0,) => { + object!(__first, p1_convertible_to_Meters, |__this| { + ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_0.upgrade().deref()).0.as_pointer(), + ),), + ) + }); + object!(__second, i32, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_0.upgrade().deref()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + } + }, + )); + assert!( + ({ + ({ (*(*converted.borrow()).0.borrow()).value } == 3) + && ((*(*converted.borrow()).1.borrow()) == 2) + }) + ); +} +pub fn test_2() { + let source: Value<(Value, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(1)), + Rc::new(RefCell::new((2 as i16))), + ))); + let converted: Value<(Value, Value)> = Rc::new(RefCell::new({ + object!(__first, i64, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::::bind((*source.borrow()).0.as_pointer()),) + )); + object!(__second, i32, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::::bind((*source.borrow()).1.as_pointer()),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + })); + assert!( + ({ + ((*(*converted.borrow()).0.borrow()) == 1_i64) + && ((*(*converted.borrow()).1.borrow()) == 2) + }) + ); + let flags: Value<(Value, Value)> = Rc::new(RefCell::new( + match (Rc::new(RefCell::new(( + Rc::new(RefCell::new(3)), + Rc::new(RefCell::new(4)), + ))) + .as_pointer(),) + { + (__tmp_1,) => { + object!(__first, bool, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_1.upgrade().deref()).0.as_pointer() + ),) + )); + object!(__second, f64, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_1.upgrade().deref()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + } + }, + )); + assert!(({ (*(*flags.borrow()).0.borrow()) && ((*(*flags.borrow()).1.borrow()) == 4_f64) })); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_1() }); + ({ test_2() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs b/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs new file mode 100644 index 0000000000..8d18ed56ae --- /dev/null +++ b/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs @@ -0,0 +1,144 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, i32)] +pub struct p1_constructible_from_Meters { + pub value: i32, +} +impl p1_constructible_from_Meters { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); + } +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 , explicit)] +pub struct p1_constructible_from_Ratio { + pub numerator: i32, + pub denominator: i32, +} +impl p1_constructible_from_Ratio { + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (((*this).numerator) / ((*this).denominator)); + } +} +const _: () = assert!(true, "std::constructible_from"); +const _: () = assert!(true, "std::constructible_from"); +const _: () = assert!(!(false), "!std::constructible_from"); +pub unsafe fn test_0() { + let mut source: (i32, p1_constructible_from_Ratio) = ( + 2, + (p1_constructible_from_Ratio { + numerator: 9, + denominator: 3, + }), + ); + let mut converted: (p1_constructible_from_Meters, i32) = { + object_unsafe!(__first, p1_constructible_from_Meters, |__this| { + ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::::bind(&raw mut source.0),), + ) + }); + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::::bind( + &raw mut source.1 + ),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + }; + assert!(((converted.0.value) == (2)) && ((converted.1) == (3))); +} +#[repr(C)] +#[derive( + FnPtrArg, + ZeroInitializationUnsafe, + DefaultInitializableUnsafe, + MemberwiseUnsafe, + MoveAssignableUnsafe, + Default, +)] +#[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe)] +pub struct p1_copy_constructible_NonConstCopy { + pub value: i32, +} +impl p1_copy_constructible_NonConstCopy { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); + } + pub unsafe fn constructor_2( + this: *mut Self, + other: LvalueRefUnsafe, + ) { + let other = (other.as_ptr() as *mut p1_copy_constructible_NonConstCopy); + (&raw mut (*this).value).write((((*other).value) + (1))); + } +} +const _: () = assert!( + true, + "std::constructible_from" +); +const _: () = assert!( + !(false), + "!std::constructible_from" +); +const _: () = assert!(!(false), "!std::copy_constructible"); +pub unsafe fn test_1() { + object_unsafe!( + original, + p1_copy_constructible_NonConstCopy::constructor_1(1) + ); + object_unsafe!( + copy, + p1_copy_constructible_NonConstCopy::constructor_2(LvalueRefUnsafe::bind(&mut original)) + ); + assert!(((copy.value) == (2))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_0() }); + (unsafe { test_1() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs b/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs new file mode 100644 index 0000000000..3a19952892 --- /dev/null +++ b/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs @@ -0,0 +1,173 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +pub struct p1_convertible_to_Meters { + pub value: i32, +} +impl p1_convertible_to_Meters { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); + } +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, i32)] +pub struct p1_convertible_to_Celsius { + pub degrees: i32, +} +impl p1_convertible_to_Celsius { + pub unsafe fn constructor_1(this: *mut Self, mut d: i32) { + (&raw mut (*this).degrees).write(d); + } +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] +pub struct p1_convertible_to_Ratio { + pub numerator: i32, + pub denominator: i32, +} +impl p1_convertible_to_Ratio { + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (((*this).numerator) / ((*this).denominator)); + } +} +const _: () = assert!(true, "std::convertible_to"); +const _: () = assert!(!(false), "!std::convertible_to"); +const _: () = assert!(true, "std::convertible_to"); +pub unsafe fn to_meters_0(mut meters: p1_convertible_to_Meters) -> p1_convertible_to_Meters { + return meters; +} +pub unsafe fn test_1() { + let mut meters: p1_convertible_to_Meters = (unsafe { + to_meters_0({ + let mut __v: p1_convertible_to_Meters = ZeroInitializationUnsafe::zero_init(); + p1_convertible_to_Meters::constructor_1(&raw mut __v, 7); + __v + }) + }); + assert!(((meters.value) == (7))); + let mut ratio: p1_convertible_to_Ratio = p1_convertible_to_Ratio { + numerator: 8, + denominator: 4, + }; + let mut value: i32 = (unsafe { p1_convertible_to_Ratio::to_i32(&raw const ratio) }); + assert!(((value) == (2))); + let mut converted: (p1_convertible_to_Meters, i32) = match ((&mut ( + 3, + (p1_convertible_to_Ratio { + numerator: 10, + denominator: 5, + }), + ) + as *mut (i32, p1_convertible_to_Ratio)),) + { + (__tmp_0,) => { + object_unsafe!(__first, p1_convertible_to_Meters, |__this| { + ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).0),), + ) + }); + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind( + &raw mut (*__tmp_0).1 + ),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + } + }; + assert!(((converted.0.value) == (3)) && ((converted.1) == (2))); +} +pub unsafe fn test_2() { + let mut source: (i32, i16) = (1, (2 as i16)); + let mut converted: (i64, i32) = { + object_unsafe!(__first, i64, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::::bind(&raw mut source.0),) + )); + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::::bind(&raw mut source.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + }; + assert!(((converted.0) == (1_i64)) && ((converted.1) == (2))); + let mut flags: (bool, f64) = match ((&mut (3, 4) as *mut (i32, i32)),) { + (__tmp_1,) => { + object_unsafe!(__first, bool, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_1).0),) + )); + object_unsafe!(__second, f64, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_1).1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + } + }; + assert!((flags.0) && ((flags.1) == (4_f64))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_1() }); + (unsafe { test_2() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs b/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs new file mode 100644 index 0000000000..21121f5e06 --- /dev/null +++ b/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs @@ -0,0 +1,150 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +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, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRef>, i32 )] +#[byte_size(4)] +pub struct p38_insert_range_by_conversion_function_Ratio { + #[offset(0)] + pub num: i32, +} +impl p38_insert_range_by_conversion_function_Ratio { + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.num); + } +} +pub fn test_0() { + let ratios: Value> = + Rc::new(RefCell::new(Box::new([ + p38_insert_range_by_conversion_function_Ratio { num: 1 }, + p38_insert_range_by_conversion_function_Ratio { num: 2 }, + ]))); + let longs: Value> = Rc::new(RefCell::new(Vec::new())); + { + let mut __tmp_0 = { >::from(longs.decay().end()) }; + let start_idx = __tmp_0.index(); + let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); + let __it: Value> = + Rc::new(RefCell::new(ratios.decay())); + let __last: Value> = + Rc::new(RefCell::new(ratios.decay().offset((2) as isize))); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::< + Const, + >::bind(__it.borrow().iter_deref()),), + ); + __it.borrow_mut().iter_inc(); + } + longs.as_pointer().with_mut(|v: &mut Vec| { + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); + }); + (__tmp_0).clone() + }; + assert!(({ (*longs.borrow())[0_usize] } == 1_i64) && ({ (*longs.borrow())[1_usize] } == 2_i64)); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[conversion_function(to_i16, LvalueRef>, i16 )] +#[conversion_function(to_i64, LvalueRef>, i64 )] +#[byte_size(4)] +pub struct p38_insert_range_best_conversion_function_Level { + #[offset(0)] + pub raw_: i32, +} +impl p38_insert_range_best_conversion_function_Level { + pub fn to_i16(this: Ptr) -> i16 { + return (this.with(|__s| __s.raw_) as i16); + } + pub fn to_i64(this: Ptr) -> i64 { + return ((this.with(|__s| __s.raw_) as i64) * 100_i64); + } +} +pub fn test_1() { + let levels: Value> = + Rc::new(RefCell::new(Box::new([ + p38_insert_range_best_conversion_function_Level { raw_: 3 }, + p38_insert_range_best_conversion_function_Level { raw_: 4 }, + ]))); + let ints: Value> = Rc::new(RefCell::new(Vec::new())); + { + let mut __tmp_1 = { >::from(ints.decay().end()) }; + let start_idx = __tmp_1.index(); + let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); + let __it: Value> = + Rc::new(RefCell::new(levels.decay())); + let __last: Value> = + Rc::new(RefCell::new(levels.decay().offset((2) as isize))); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::< + Const, + >::bind(__it.borrow().iter_deref()),), + ); + __it.borrow_mut().iter_inc(); + } + ints.as_pointer().with_mut(|v: &mut Vec| { + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); + }); + (__tmp_1).clone() + }; + assert!(({ (*ints.borrow())[0_usize] } == 3) && ({ (*ints.borrow())[1_usize] } == 4)); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_1() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs b/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs new file mode 100644 index 0000000000..17cd966374 --- /dev/null +++ b/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs @@ -0,0 +1,124 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] +pub struct p38_insert_range_by_conversion_function_Ratio { + pub num: i32, +} +impl p38_insert_range_by_conversion_function_Ratio { + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).num; + } +} +pub unsafe fn test_0() { + let mut ratios: [p38_insert_range_by_conversion_function_Ratio; 2] = [ + p38_insert_range_by_conversion_function_Ratio { num: 1 }, + p38_insert_range_by_conversion_function_Ratio { num: 2 }, + ]; + let mut longs: Vec = Vec::new(); + { + let mut __tmp_0 = { >::from(longs.end()) }; + let mut __tmp_1 = { ratios.as_mut_ptr().offset((2) as isize) }; + let __off = + __tmp_0.iter_distance(&UnsafeRandomAccessIterator::Vec(longs.as_mut_ptr())) as usize; + let mut __tmp: Vec = Vec::new(); + let mut __it = ratios.as_mut_ptr(); + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::< + Const, + >::bind(__it.iter_deref()),), + ); + __it.iter_inc(); + } + longs.splice(__off..__off, __tmp); + UnsafeRandomAccessIterator::Vec(longs.as_mut_ptr().add(__off)) + }; + assert!(((longs[(0_usize)]) == (1_i64)) && ((longs[(1_usize)]) == (2_i64))); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[conversion_function(to_i16, LvalueRefUnsafe>, i16 )] +#[conversion_function(to_i64, LvalueRefUnsafe>, i64 )] +pub struct p38_insert_range_best_conversion_function_Level { + pub raw_: i32, +} +impl p38_insert_range_best_conversion_function_Level { + pub unsafe fn to_i16(this: *const Self) -> i16 { + return ((*this).raw_ as i16); + } + pub unsafe fn to_i64(this: *const Self) -> i64 { + return (((*this).raw_ as i64) * (100_i64)); + } +} +pub unsafe fn test_1() { + let mut levels: [p38_insert_range_best_conversion_function_Level; 2] = [ + p38_insert_range_best_conversion_function_Level { raw_: 3 }, + p38_insert_range_best_conversion_function_Level { raw_: 4 }, + ]; + let mut ints: Vec = Vec::new(); + { + let mut __tmp_2 = { >::from(ints.end()) }; + let mut __tmp_3 = { levels.as_mut_ptr().offset((2) as isize) }; + let __off = + __tmp_2.iter_distance(&UnsafeRandomAccessIterator::Vec(ints.as_mut_ptr())) as usize; + let mut __tmp: Vec = Vec::new(); + let mut __it = levels.as_mut_ptr(); + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::< + Const, + >::bind(__it.iter_deref()),), + ); + __it.iter_inc(); + } + ints.splice(__off..__off, __tmp); + UnsafeRandomAccessIterator::Vec(ints.as_mut_ptr().add(__off)) + }; + assert!(((ints[(0_usize)]) == (3)) && ((ints[(1_usize)]) == (4))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_0() }); + (unsafe { test_1() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/containers/container.requirements/sequence.reqmts.cpp b/tests/std/containers/container.requirements/sequence.reqmts.cpp new file mode 100644 index 0000000000..1ca4261f33 --- /dev/null +++ b/tests/std/containers/container.requirements/sequence.reqmts.cpp @@ -0,0 +1,40 @@ +#include +#include + +// N4950 [sequence.reqmts]/37-38: a.insert(p, i, j) requires T to be +// Cpp17EmplaceConstructible into X from *i, and inserts copies of the elements +// in [i, j) before p. +namespace p38_insert_range_by_conversion_function { +struct Ratio { + int num; + operator int() const { return num; } +}; + +void test() { + Ratio ratios[] = {{1}, {2}}; + std::vector longs; + longs.insert(longs.end(), ratios, ratios + 2); + assert(longs[0] == 1 && longs[1] == 2); +} +} // namespace p38_insert_range_by_conversion_function + +namespace p38_insert_range_best_conversion_function { +struct Level { + int raw; + operator short() const { return static_cast(raw); } + operator long() const { return raw * 100L; } +}; + +void test() { + Level levels[] = {{3}, {4}}; + std::vector ints; + ints.insert(ints.end(), levels, levels + 2); + assert(ints[0] == 3 && ints[1] == 4); +} +} // namespace p38_insert_range_best_conversion_function + +int main() { + p38_insert_range_by_conversion_function::test(); + p38_insert_range_best_conversion_function::test(); + return 0; +} 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 401c73ca69..7331d89a7f 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 @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p6_2_zero_initialized_padding_Padded { #[offset(0)] @@ -36,7 +38,9 @@ pub struct p6_2_zero_initialized_padding_Padded { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p6_2_zero_initialized_padding_TailPadded { #[offset(0)] @@ -55,7 +59,9 @@ pub struct p6_2_zero_initialized_padding_TailPadded { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 f960eaddcf..8cf6d61f92 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 @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { #[offset(0)] @@ -35,7 +37,9 @@ pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p6_1_zero_initialized_pointer_to_member_HoldsSelector { #[offset(0)] @@ -142,7 +146,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(24)] pub struct p6_2_zero_initialized_class_Inner { #[offset(0)] @@ -162,7 +168,9 @@ pub struct p6_2_zero_initialized_class_Inner { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(96)] pub struct p6_2_zero_initialized_class_Outer { #[offset(0)] @@ -289,7 +297,9 @@ pub fn test_17() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p6_4_zero_initialized_array_Pair { #[offset(0)] @@ -393,7 +403,19 @@ pub fn test_21() { } heap_numbers.delete(); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { #[offset(0)] @@ -401,8 +423,8 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { #[offset(4)] pub five: i32, } -impl DefaultConstructible for p9_1_2_zero_then_default_initialized_WithDefaultMember { - fn default_constructor(this: Ptr) { +impl p9_1_2_zero_then_default_initialized_WithDefaultMember { + pub fn constructor_1(this: Ptr) { field!(this, zeroed).write(0_i32); field!(this, five).write(5); } @@ -417,14 +439,26 @@ impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { #[offset(0)] pub untouched: i32, } -impl DefaultConstructible for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - fn default_constructor(this: Ptr) { +impl p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + pub fn constructor_1(this: Ptr) { field!(this, untouched).write(0_i32); } } @@ -433,18 +467,29 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { { { let __v: Value = - Rc::new(RefCell::new( - ::zero_init(), - )); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1( + __v.as_pointer(), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Default, + Conversions, )] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { #[offset(0)] @@ -453,22 +498,24 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { #[byte_size(4)] pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } -impl DefaultConstructible for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { - fn default_constructor(this: Ptr) { +impl p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + pub fn constructor_1(this: Ptr) { field!(this, number).write(0_i32); - DefaultConstructible::default_constructor(field_ptr!(this, member)); + p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1(field_ptr!( + this, member + )); } } pub fn test_22() { object!( value, - p9_1_2_zero_then_default_initialized_WithDefaultMember + p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1() ); assert!(({ (*value.borrow()).zeroed } == 0)); assert!(({ (*value.borrow()).five } == 5)); let mut heap: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(__p.clone()); + p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1(__p.clone()); __p }; assert!((heap.with(|__s| __s.zeroed) == 0)); @@ -476,14 +523,14 @@ pub fn test_22() { heap.delete(); object!( holder, - p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone + p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1() ); assert!(({ (*holder.borrow()).number } == 0)); assert!(({ (*holder.borrow()).member.untouched } == 0)); let mut heap_holder: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(__p.clone()); + p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1(__p.clone()); __p }; assert!((heap_holder.with(|__s| __s.number) == 0)); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs index a1876bad6b..ab9b8c59fa 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs @@ -25,7 +25,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p5_3_reference_to_rvalue_Counter { #[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 b57498b6cc..f19f44d2d9 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 @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p6_2_zero_initialized_padding_Padded { pub letter: libc::c_char, pub number: i32, @@ -31,7 +33,9 @@ pub struct p6_2_zero_initialized_padding_Padded { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p6_2_zero_initialized_padding_TailPadded { pub number: i32, pub letter: libc::c_char, @@ -46,7 +50,9 @@ pub struct p6_2_zero_initialized_padding_TailPadded { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 8b2c7d2d64..406fec871f 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 @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { pub first: i32, pub second: i32, @@ -30,7 +32,9 @@ pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p6_1_zero_initialized_pointer_to_member_HoldsSelector { pub selector: isize, } @@ -133,7 +137,9 @@ static mut counter_11: std::cell::LazyCell = std::cell::LazyCell::new(|| un TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p6_2_zero_initialized_class_Inner { pub number: i32, pub real: f64, @@ -149,7 +155,9 @@ pub struct p6_2_zero_initialized_class_Inner { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p6_2_zero_initialized_class_Outer { pub letter: libc::c_char, pub inner: p6_2_zero_initialized_class_Inner, @@ -237,7 +245,9 @@ pub unsafe fn test_17() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p6_4_zero_initialized_array_Pair { pub first: i32, pub second: i32, @@ -327,13 +337,23 @@ pub unsafe fn test_21() { }; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { pub zeroed: i32, pub five: i32, } -impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_WithDefaultMember { - unsafe fn default_constructor(this: *mut Self) { +impl p9_1_2_zero_then_default_initialized_WithDefaultMember { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).zeroed).write(0_i32); (&raw mut (*this).five).write(5); } @@ -349,12 +369,22 @@ impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } -impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - unsafe fn default_constructor(this: *mut Self) { +impl p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).untouched).write(0_i32); } } @@ -363,8 +393,8 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { unsafe { { let mut __v: p9_1_2_zero_then_default_initialized_LeavesMemberAlone = - ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + ZeroInitializationUnsafe::zero_init(); + p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1(&raw mut __v); __v } } @@ -372,22 +402,33 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub number: i32, pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } -impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { - unsafe fn default_constructor(this: *mut Self) { +impl p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).number).write(0_i32); - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).member); + p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1( + &raw mut (*this).member, + ); } } pub unsafe fn test_22() { object_unsafe!( value, - p9_1_2_zero_then_default_initialized_WithDefaultMember + p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1() ); assert!(((value.zeroed) == (0))); assert!(((value.five) == (5))); @@ -395,7 +436,7 @@ pub unsafe fn test_22() { let __p: *mut p9_1_2_zero_then_default_initialized_WithDefaultMember = Box::leak(Box::new( ::zero_init(), )); - DefaultConstructibleUnsafe::default_constructor(__p); + p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1(__p); __p }; assert!((((*heap).zeroed) == (0))); @@ -408,7 +449,7 @@ pub unsafe fn test_22() { }; object_unsafe!( holder, - p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone + p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1() ); assert!(((holder.number) == (0))); assert!(((holder.member.untouched) == (0))); @@ -416,7 +457,7 @@ pub unsafe fn test_22() { let __p: *mut p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = Box::leak( Box::new(::zero_init()), ); - DefaultConstructibleUnsafe::default_constructor(__p); + p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1(__p); __p }; assert!((((*heap_holder).number) == (0))); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs index 6ebabc94ac..fbdd2cce8f 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs @@ -24,7 +24,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p5_3_reference_to_rvalue_Counter { pub count: i32, } 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 a250ad10a8..54ff35794d 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 @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 16a6d8f105..bb0cbf37f5 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,19 @@ thread_local!( thread_local!( pub static step_10: Value = Rc::new(RefCell::new(4)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p9_static_member_hides_namespace_variable_HasStaticStep { #[offset(0)] @@ -67,9 +79,7 @@ impl p9_static_member_hides_namespace_variable_HasStaticStep { }; return this.with(|__s| __s.total); } -} -impl DefaultConstructible for p9_static_member_hides_namespace_variable_HasStaticStep { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, total).write(1); } } @@ -81,7 +91,7 @@ impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { pub fn test_11() { object!( object, - p9_static_member_hides_namespace_variable_HasStaticStep + p9_static_member_hides_namespace_variable_HasStaticStep::constructor_1() ); assert!( (({ @@ -117,23 +127,35 @@ pub fn combine_14(mut first: i32, mut second: i32) -> i32 { return ((first * 100) + second); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, TriviallyCopyable, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Widget { #[offset(0)] pub id: i32, } impl p9_evaluated_each_time_called_Widget { - pub fn construct(this: Ptr, mut id: i32) { + pub fn constructor_1(this: Ptr, mut id: i32) { field!(this, id).write(id); } } -impl DefaultConstructible for p9_evaluated_each_time_called_Widget { - fn default_constructor(this: Ptr) { +impl Constructor<()> for p9_evaluated_each_time_called_Widget { + fn constructor(this: Ptr, _: ()) { { - p9_evaluated_each_time_called_Widget::construct(this.clone(), ({ count_default_13() })); + p9_evaluated_each_time_called_Widget::constructor_1( + this.clone(), + ({ count_default_13() }), + ); } } } @@ -141,10 +163,9 @@ impl Default for p9_evaluated_each_time_called_Widget { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new( - ::zero_init(), - )); - p9_evaluated_each_time_called_Widget::construct( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_evaluated_each_time_called_Widget::constructor_1( __v.as_pointer(), ({ count_default_13() }), ); @@ -158,7 +179,19 @@ thread_local!( ); pub type anon_16 = u32; pub const anon_16_kBonus: anon_16 = 5; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Account { #[offset(0)] @@ -177,9 +210,7 @@ impl p9_evaluated_each_time_called_Account { pub fn set_base(mut value: i32) { base_15.with(|rc| *rc.borrow_mut() = value); } -} -impl DefaultConstructible for p9_evaluated_each_time_called_Account { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, balance).write(0); } } @@ -200,18 +231,21 @@ pub fn test_17() { assert!((defaults_evaluated_12.with(|rc| *rc.borrow()) == 3)); object!( a, - p9_evaluated_each_time_called_Widget(({ count_default_13() })) + p9_evaluated_each_time_called_Widget::constructor_1(({ count_default_13() })) ); - object!(b, p9_evaluated_each_time_called_Widget(40)); + object!(b, p9_evaluated_each_time_called_Widget::constructor_1(40)); object!( c, - p9_evaluated_each_time_called_Widget(({ count_default_13() })) + p9_evaluated_each_time_called_Widget::constructor_1(({ count_default_13() })) ); assert!(({ (*a.borrow()).id } == 4)); assert!(({ (*b.borrow()).id } == 40)); assert!(({ (*c.borrow()).id } == 5)); assert!((defaults_evaluated_12.with(|rc| *rc.borrow()) == 5)); - object!(account, p9_evaluated_each_time_called_Account); + object!( + account, + p9_evaluated_each_time_called_Account::constructor_1() + ); assert!( (({ p9_evaluated_each_time_called_Account::deposit( @@ -249,7 +283,9 @@ pub fn add_18(mut a: i32, mut b: i32) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 79fd5f7165..cdfc059fb1 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 @@ -15,7 +15,9 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct p2_pointer_to_array_member_HasIntArray { #[offset(0)] @@ -60,7 +62,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p2_pointer_to_data_member_HasTwoInts { #[offset(0)] @@ -99,7 +103,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p2_pointer_to_member_of_incomplete_class_CompletedLater { #[offset(0)] @@ -139,7 +145,9 @@ pub fn test_3() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { #[offset(0)] @@ -157,7 +165,9 @@ pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[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 b59c1fc2be..7fae15cd15 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 @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 8ba134d982..dd4664c7a7 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,17 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_static_member_hides_namespace_variable_HasStaticStep { pub total: i32, } @@ -63,9 +73,7 @@ impl p9_static_member_hides_namespace_variable_HasStaticStep { (*this).total += amount; return (*this).total; } -} -impl DefaultConstructibleUnsafe for p9_static_member_hides_namespace_variable_HasStaticStep { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).total).write(1); } } @@ -77,7 +85,7 @@ impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { pub unsafe fn test_11() { object_unsafe!( object, - p9_static_member_hides_namespace_variable_HasStaticStep + p9_static_member_hides_namespace_variable_HasStaticStep::constructor_1() ); assert!( ((unsafe { @@ -113,21 +121,31 @@ pub unsafe fn combine_14(mut first: i32, mut second: i32) -> i32 { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, TriviallyCopyableUnsafe, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct p9_evaluated_each_time_called_Widget { pub id: i32, } impl p9_evaluated_each_time_called_Widget { - pub unsafe fn construct(this: *mut Self, mut id: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut id: i32) { (&raw mut (*this).id).write(id); } } -impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Widget { - unsafe fn default_constructor(this: *mut Self) { +impl ConstructorUnsafe<()> for p9_evaluated_each_time_called_Widget { + unsafe fn constructor(this: *mut Self, _: ()) { unsafe { - p9_evaluated_each_time_called_Widget::construct(this, (unsafe { count_default_13() })); + p9_evaluated_each_time_called_Widget::constructor_1( + this, + (unsafe { count_default_13() }), + ); } } } @@ -136,8 +154,8 @@ impl Default for p9_evaluated_each_time_called_Widget { unsafe { { let mut __v: p9_evaluated_each_time_called_Widget = - ::zero_init(); - p9_evaluated_each_time_called_Widget::construct( + ZeroInitializationUnsafe::zero_init(); + p9_evaluated_each_time_called_Widget::constructor_1( &raw mut __v, (unsafe { count_default_13() }), ); @@ -150,7 +168,17 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_evaluated_each_time_called_Account { pub balance: i32, } @@ -165,9 +193,7 @@ impl p9_evaluated_each_time_called_Account { pub unsafe fn set_base(mut value: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut base_15)) = value; } -} -impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Account { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).balance).write(0); } } @@ -190,18 +216,21 @@ pub unsafe fn test_17() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut defaults_evaluated_12)) == (3))); object_unsafe!( a, - p9_evaluated_each_time_called_Widget((unsafe { count_default_13() })) + p9_evaluated_each_time_called_Widget::constructor_1((unsafe { count_default_13() })) ); - object_unsafe!(b, p9_evaluated_each_time_called_Widget(40)); + object_unsafe!(b, p9_evaluated_each_time_called_Widget::constructor_1(40)); object_unsafe!( c, - p9_evaluated_each_time_called_Widget((unsafe { count_default_13() })) + p9_evaluated_each_time_called_Widget::constructor_1((unsafe { count_default_13() })) ); assert!(((a.id) == (4))); assert!(((b.id) == (40))); assert!(((c.id) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut defaults_evaluated_12)) == (5))); - object_unsafe!(account, p9_evaluated_each_time_called_Account); + object_unsafe!( + account, + p9_evaluated_each_time_called_Account::constructor_1() + ); assert!( ((unsafe { p9_evaluated_each_time_called_Account::deposit( @@ -244,7 +273,9 @@ pub unsafe fn add_18(mut a: i32, mut b: i32) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 090bcf4650..2affbf260f 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 @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p2_pointer_to_array_member_HasIntArray { pub before: i32, pub elements: [i32; 3], @@ -56,7 +58,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p2_pointer_to_data_member_HasTwoInts { pub first: i32, pub second: i32, @@ -103,7 +107,9 @@ pub static mut pm_2: std::cell::LazyCell = std::cell::LazyCell::new(|| un TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p2_pointer_to_member_of_incomplete_class_CompletedLater { pub first: i32, pub second: i32, @@ -136,7 +142,9 @@ pub unsafe fn test_3() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { pub first: i32, pub second: i32, @@ -150,7 +158,9 @@ pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 0fe2dfc94d..96610506cd 100644 --- a/tests/std/expr/conv/out/refcount/conv.mem.rs +++ b/tests/std/expr/conv/out/refcount/conv.mem.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 ebb8082d3c..0bbbc0409d 100644 --- a/tests/std/expr/conv/out/unsafe/conv.mem.rs +++ b/tests/std/expr/conv/out/unsafe/conv.mem.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 7fad01af2b..901ad5a232 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 @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 21674a4b82..867b80578c 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 @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct HasTwoInts { #[offset(0)] @@ -36,7 +38,9 @@ pub struct HasTwoInts { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 07fc493b87..6cc22e6992 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 @@ -27,7 +27,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p10_null_converts_to_null_HasTwoInts { #[offset(0)] @@ -46,7 +48,9 @@ pub struct p10_null_converts_to_null_HasTwoInts { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p10_null_converts_to_null_HasChar { #[offset(0)] @@ -68,7 +72,9 @@ pub fn test_1() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p10_2_data_member_round_trip_HasTwoInts { #[offset(0)] @@ -87,7 +93,9 @@ pub struct p10_2_data_member_round_trip_HasTwoInts { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 021ce0d28b..3da9d84c0f 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 @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 ea41a007c1..bd21165242 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 @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct HasTwoInts { pub first: i32, pub second: i32, @@ -31,7 +33,9 @@ pub struct HasTwoInts { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 b6e8f87d23..d682c1bf4f 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 @@ -26,7 +26,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p10_null_converts_to_null_HasTwoInts { pub first: i32, pub second: i32, @@ -41,7 +43,9 @@ pub struct p10_null_converts_to_null_HasTwoInts { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p10_null_converts_to_null_HasChar { pub character: libc::c_char, } @@ -60,7 +64,9 @@ pub unsafe fn test_1() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p10_2_data_member_round_trip_HasTwoInts { pub first: i32, pub second: i32, @@ -75,7 +81,9 @@ pub struct p10_2_data_member_round_trip_HasTwoInts { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 6a56774ca1..70f4d9a972 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 @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 c02a9cd9a1..ed8f449014 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 @@ -23,7 +23,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p3_2_static_member_is_ordinary_pointer_HasStaticMembers {} impl p3_2_static_member_is_ordinary_pointer_HasStaticMembers { @@ -52,7 +54,9 @@ pub fn test_2() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { #[offset(0)] @@ -97,7 +101,9 @@ pub fn test_3() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 92dd5b993d..1f0d5fc05e 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 @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 47ba7f3017..020ce0f383 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 @@ -18,7 +18,9 @@ pub static mut calls_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p3_2_static_member_is_ordinary_pointer_HasStaticMembers {} impl p3_2_static_member_is_ordinary_pointer_HasStaticMembers { pub unsafe fn run() { @@ -46,7 +48,9 @@ pub unsafe fn test_2() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { pub base: i32, } @@ -81,7 +85,9 @@ pub unsafe fn test_3() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 947947aa82..1b589f0934 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.cond.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.cond.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 0b27916dfc..3116ba3f69 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.eq.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.eq.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p4_1_both_null_HasTwoInts { #[offset(0)] @@ -42,7 +44,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p4_2_one_null_HasTwoInts { #[offset(0)] @@ -106,7 +110,9 @@ pub fn test_2() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 f17758846e..0a5c201024 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 @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 a1888f1daf..2856256e52 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 @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p3_arrow_star_HasTwoInts { #[offset(0)] @@ -49,7 +51,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p4_object_expression_sequenced_first_HasValue { #[offset(0)] @@ -102,7 +106,9 @@ pub fn test_7() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { #[offset(0)] @@ -139,20 +145,22 @@ thread_local!( TriviallyDefaultConstructible, Destructible, Default, + Conversions, )] +#[conversions(copy, move)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[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( +impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { + pub fn constructor_2( this: Ptr, _a0: LvalueRef>, ) { let _a0 = _a0.as_pointer(); (*copyCount_9.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl MoveConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { - fn move_constructor( + pub fn constructor_3( this: Ptr, _a0: RvalueRef, ) { @@ -171,12 +179,15 @@ impl MoveConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMov Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(Conversions)] +#[conversions(copy, move)] #[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 p6_data_member_of_rvalue_is_xvalue_HoldsCounted {} pub fn test_11() { let mut pm: isize = (offset_of_field!(p6_data_member_of_rvalue_is_xvalue_HoldsCounted, member) as isize); @@ -185,21 +196,19 @@ pub fn test_11() { )); object!( from_lvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - LvalueRef::bind( + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_2(LvalueRef::bind( (holder.as_pointer()) .member::(pm) - ) + )) ); assert!((copyCount_9.with(|rc| *rc.borrow()) == 1)); assert!((moveCount_10.with(|rc| *rc.borrow()) == 0)); object!( from_xvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - RvalueRef::bind( + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_3(RvalueRef::bind( (holder.as_pointer()) .member::(pm) - ) + )) ); assert!((copyCount_9.with(|rc| *rc.borrow()) == 1)); assert!((moveCount_10.with(|rc| *rc.borrow()) == 1)); 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 7b98a029f5..eb160580db 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.cond.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.cond.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 07b22b6a6d..4d1a9f2eab 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.eq.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.eq.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p4_1_both_null_HasTwoInts { pub first: i32, pub second: i32, @@ -37,7 +39,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p4_2_one_null_HasTwoInts { pub first: i32, pub second: i32, @@ -85,7 +89,9 @@ pub unsafe fn test_2() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 5a6c15a91a..0d1cf85134 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 @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 1811b24dc4..a39ed60c79 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 @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p3_arrow_star_HasTwoInts { pub first: i32, pub second: i32, @@ -49,7 +51,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p4_object_expression_sequenced_first_HasValue { pub value: i32, } @@ -92,7 +96,9 @@ pub unsafe fn test_7() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { pub first: i32, pub second: i32, @@ -127,19 +133,21 @@ pub static mut moveCount_10: std::cell::LazyCell = std::cell::LazyCell::new TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} -impl CopyConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { - unsafe fn copy_constructor( +impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { + pub unsafe fn constructor_2( this: *mut Self, _a0: LvalueRefUnsafe>, ) { let _a0 = (_a0.as_ptr() as *const p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)).prefix_inc(); } -} -impl MoveConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { - unsafe fn move_constructor( + pub unsafe fn constructor_3( this: *mut Self, _a0: RvalueRefUnsafe, ) { @@ -157,9 +165,12 @@ impl MoveConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopies Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] 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 test_11() { let mut pm: isize = (::std::mem::offset_of!(p6_data_member_of_rvalue_is_xvalue_HoldsCounted, member) as isize); @@ -167,22 +178,24 @@ pub unsafe fn test_11() { ::default(); object_unsafe!( from_lvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - LvalueRefUnsafe::bind( - &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) - .wrapping_byte_offset(pm) - .cast::()) + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_2( + LvalueRefUnsafe::bind( + &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) + .wrapping_byte_offset(pm) + .cast::()) + ) ) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moveCount_10)) == (0))); object_unsafe!( from_xvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - RvalueRefUnsafe::bind( - &mut (*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) - .wrapping_byte_offset(pm) - .cast::()) + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_3( + RvalueRefUnsafe::bind( + &mut (*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) + .wrapping_byte_offset(pm) + .cast::()) + ) ) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)) == (1))); 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 5b0d9df9f2..aa155229ac 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 @@ -13,11 +13,12 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(16)] pub struct p1_default_member_initializer_names_object_Holder { #[offset(0)] @@ -27,7 +28,7 @@ pub struct p1_default_member_initializer_names_object_Holder { pub value: i32, } impl p1_default_member_initializer_names_object_Holder { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, self_).write((this).clone()); field!(this, value).write(value); assert!((this.with(|__s| __s.self_.clone()) == this)); @@ -40,7 +41,10 @@ impl Default for p1_default_member_initializer_names_object_Holder { } } pub fn test_0() { - object!(holder, p1_default_member_initializer_names_object_Holder(4)); + object!( + holder, + p1_default_member_initializer_names_object_Holder::constructor_1(4) + ); assert!(({ (*holder.borrow()).value } == 4)); } #[derive( @@ -50,12 +54,13 @@ pub fn test_0() { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(16)] pub struct p1_mem_initializer_names_object_Holder { #[offset(0)] @@ -65,7 +70,7 @@ pub struct p1_mem_initializer_names_object_Holder { pub value: i32, } impl p1_mem_initializer_names_object_Holder { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, self_).write((this).clone()); field!(this, value).write(value); assert!((this.with(|__s| __s.self_.clone()) == this)); @@ -76,7 +81,10 @@ impl p1_mem_initializer_names_object_Holder { } } pub fn test_1() { - object!(holder, p1_mem_initializer_names_object_Holder(4)); + object!( + holder, + p1_mem_initializer_names_object_Holder::constructor_1(4) + ); assert!(({ (*holder.borrow()).value } == 5)); } #[derive( @@ -89,7 +97,9 @@ pub fn test_1() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct p1_this_is_a_copy_of_the_pointer_Node { #[offset(0)] 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 9f76306c66..23e5e94649 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 @@ -13,17 +13,18 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct p1_default_member_initializer_names_object_Holder { pub self_: *mut p1_default_member_initializer_names_object_Holder, pub value: i32, } impl p1_default_member_initializer_names_object_Holder { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).self_).write(this); (&raw mut (*this).value).write(value); assert!((((*this).self_) == (this))); @@ -36,7 +37,10 @@ impl Default for p1_default_member_initializer_names_object_Holder { } } pub unsafe fn test_0() { - object_unsafe!(holder, p1_default_member_initializer_names_object_Holder(4)); + object_unsafe!( + holder, + p1_default_member_initializer_names_object_Holder::constructor_1(4) + ); assert!(((holder.value) == (4))); } #[repr(C)] @@ -46,18 +50,19 @@ pub unsafe fn test_0() { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct p1_mem_initializer_names_object_Holder { pub self_: *mut p1_mem_initializer_names_object_Holder, pub value: i32, } impl p1_mem_initializer_names_object_Holder { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).self_).write(this); (&raw mut (*this).value).write(value); assert!((((*this).self_) == (this))); @@ -66,7 +71,10 @@ impl p1_mem_initializer_names_object_Holder { } } pub unsafe fn test_1() { - object_unsafe!(holder, p1_mem_initializer_names_object_Holder(4)); + object_unsafe!( + holder, + p1_mem_initializer_names_object_Holder::constructor_1(4) + ); assert!(((holder.value) == (5))); } #[repr(C)] @@ -79,7 +87,9 @@ pub unsafe fn test_1() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p1_this_is_a_copy_of_the_pointer_Node { pub value: i32, pub next: *mut p1_this_is_a_copy_of_the_pointer_Node, 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 57f81a7b45..76311ce8ab 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 @@ -17,17 +17,31 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { #[offset(0)] pub id: i32, } -impl DefaultConstructible for p16_rebind_member_Alloc_std_pair_const_int__int__ { - fn default_constructor(this: Ptr) { +impl p16_rebind_member_Alloc_std_pair_const_int__int__ { + pub fn constructor_1(this: Ptr) { field!(this, id).write(0); } } @@ -70,7 +84,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 0f080d78b2..82820a63f9 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 @@ -16,15 +16,27 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { pub id: i32, } -impl DefaultConstructibleUnsafe for p16_rebind_member_Alloc_std_pair_const_int__int__ { - unsafe fn default_constructor(this: *mut Self) { +impl p16_rebind_member_Alloc_std_pair_const_int__int__ { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).id).write(0); } } @@ -67,7 +79,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs b/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs index 952225088d..b59ba33b07 100644 --- a/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs +++ b/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs @@ -20,7 +20,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct table29_member_operator_Version { #[offset(0)] @@ -179,7 +181,9 @@ pub fn test_1() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct table29_other_operator_shapes_Weight { #[offset(0)] @@ -206,7 +210,9 @@ impl LessThanComparable for table29_other_operator_shapes_Weight { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct table29_other_operator_shapes_Height { #[offset(0)] @@ -234,6 +240,8 @@ impl LessThanComparable for table29_other_operator_shapes_Height { PartiallyOrderedWith, )] #[three_way(table29_other_operator_shapes_Depth::operator_cmp)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct table29_other_operator_shapes_Depth { #[offset(0)] @@ -334,7 +342,9 @@ pub fn test_2() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct pairs_spec_p3_members_order_pairs_Rank { #[offset(0)] diff --git a/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs b/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs index 801b0f3a1e..e20798e882 100644 --- a/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs +++ b/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs @@ -17,7 +17,9 @@ pub static mut less_calls_0: std::cell::LazyCell = std::cell::LazyCell::new TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct table29_member_operator_Version { pub major: i32, pub minor: i32, @@ -137,7 +139,9 @@ pub unsafe fn test_1() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct table29_other_operator_shapes_Weight { pub grams: i32, } @@ -164,7 +168,9 @@ impl LessThanComparableUnsafe for table29_other_operator_shapes_Weight { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct table29_other_operator_shapes_Height { pub millimeters: i32, } @@ -189,6 +195,8 @@ impl LessThanComparableUnsafe for table29_other_operator_shapes_Height { PartiallyOrderedWithUnsafe, )] #[three_way(table29_other_operator_shapes_Depth::operator_cmp)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct table29_other_operator_shapes_Depth { pub millimeters: i32, } @@ -276,7 +284,9 @@ pub unsafe fn test_2() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct pairs_spec_p3_members_order_pairs_Rank { pub value: i32, } 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 5a09259fc5..0c674441d6 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 @@ -19,21 +19,23 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, Memberwise, CopyConstructible, Movable, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { #[offset(0)] pub value: i32, } impl p2_condition_variable_created_each_iteration_ConvertsToBool { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -52,7 +54,7 @@ pub fn test_2() { 'loop_: loop { object!( condition, - p2_condition_variable_created_each_iteration_ConvertsToBool(remaining) + p2_condition_variable_created_each_iteration_ConvertsToBool::constructor_1(remaining) ); if !({ p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool( @@ -84,21 +86,23 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, Memberwise, CopyConstructible, Movable, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { #[offset(0)] pub value: i32, } impl p2_continue_destroys_condition_variable_ConvertsToBool { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); (*ctorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -118,7 +122,7 @@ pub fn test_5() { 'loop_: loop { object!( condition, - p2_continue_destroys_condition_variable_ConvertsToBool(remaining) + p2_continue_destroys_condition_variable_ConvertsToBool::constructor_1(remaining) ); if !({ p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(condition.as_pointer()) 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 4a245a6df0..46f85800f5 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 @@ -14,19 +14,21 @@ pub static mut dtorCount_1: std::cell::LazyCell = std::cell::LazyCell::new( VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { pub value: i32, } impl p2_condition_variable_created_each_iteration_ConvertsToBool { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } @@ -45,7 +47,7 @@ pub unsafe fn test_2() { 'loop_: loop { object_unsafe!( condition, - p2_condition_variable_created_each_iteration_ConvertsToBool(remaining) + p2_condition_variable_created_each_iteration_ConvertsToBool::constructor_1(remaining) ); if !(unsafe { p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool( @@ -74,19 +76,21 @@ pub static mut dtorCount_4: std::cell::LazyCell = std::cell::LazyCell::new( VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { pub value: i32, } impl p2_continue_destroys_condition_variable_ConvertsToBool { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_3)).prefix_inc(); } @@ -106,7 +110,7 @@ pub unsafe fn test_5() { 'loop_: loop { object_unsafe!( condition, - p2_continue_destroys_condition_variable_ConvertsToBool(remaining) + p2_continue_destroys_condition_variable_ConvertsToBool::constructor_1(remaining) ); if !(unsafe { p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(&raw const condition) diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs index f25fdafd12..b08f0c88a1 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ impl LifetimeTracked { } }); } - pub fn use_(this: Ptr) { - field!(this, uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -88,7 +88,7 @@ pub fn test_6() { ({ LifetimeTracked::reset() }); let mut choice: i32 = 9; { - object!(guard, LifetimeTracked); + object!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 0; if (choice != 0) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -104,7 +104,7 @@ pub fn test_6() { assert!((else_runs_5.with(|rc| *rc.borrow()) == 1)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); { - object!(guard, LifetimeTracked); + object!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 4; if (choice != 0) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index 44809583da..0afa87e2a5 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ impl LifetimeTracked { } }); } - pub fn use_(this: Ptr) { - field!(this, uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -94,14 +94,15 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, - CppFrom, TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, )] #[memberwise(copy_assign)] -#[cpp_into(i32, to_i32)] +#[derive(Conversions)] +#[conversions(copy)] +#[conversion_function(to_i32, LvalueRef>, i32 )] #[byte_size(4)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { #[offset(0)] @@ -161,7 +162,7 @@ pub fn test_10() { ({ LifetimeTracked::reset() }); let mut selector: i32 = 9; { - object!(guard, LifetimeTracked); + object!(guard, LifetimeTracked::constructor_1()); let mut selector: i32 = 2; 'switch: { match { selector } { 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 d01b906459..304ec5b3d2 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(this: *const Self) { - (*(&raw const (*this).uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } -} -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } } impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -67,7 +67,7 @@ pub unsafe fn test_6() { (unsafe { LifetimeTracked::reset() }); let mut choice: i32 = 9; { - object_unsafe!(guard, LifetimeTracked); + object_unsafe!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 0; if (choice != 0) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); @@ -83,7 +83,7 @@ pub unsafe fn test_6() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); { - object_unsafe!(guard, LifetimeTracked); + object_unsafe!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 4; if (choice != 0) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); 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 c1521c990e..ca1db4dfaa 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(this: *const Self) { - (*(&raw const (*this).uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } -} -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } } impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -70,14 +70,15 @@ pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new( VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, )] #[memberwise(copy_assign)] -#[cpp_into(i32, to_i32)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { pub value: i32, } @@ -133,7 +134,7 @@ pub unsafe fn test_10() { (unsafe { LifetimeTracked::reset() }); let mut selector: i32 = 9; { - object_unsafe!(guard, LifetimeTracked); + object_unsafe!(guard, LifetimeTracked::constructor_1()); let mut selector: i32 = 2; 'switch: { match { selector } { diff --git a/tests/std/support/cmp/out/refcount/cmp.concept.rs b/tests/std/support/cmp/out/refcount/cmp.concept.rs index 928af2f6a4..c974b14ce7 100644 --- a/tests/std/support/cmp/out/refcount/cmp.concept.rs +++ b/tests/std/support/cmp/out/refcount/cmp.concept.rs @@ -20,6 +20,8 @@ use std::rc::{Rc, Weak}; PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct p1_defaulted_three_way_Version { #[offset(0)] @@ -114,6 +116,8 @@ thread_local!( PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_user_written_three_way_Money { #[offset(0)] @@ -176,6 +180,8 @@ pub fn test_2() { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct p1_weaker_category_Temperature { #[offset(0)] @@ -237,6 +243,8 @@ pub fn test_3() { PartiallyOrderedWith, )] #[three_way(p1_three_way_without_equality_Rank::operator_cmp)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_three_way_without_equality_Rank { #[offset(0)] diff --git a/tests/std/support/cmp/out/unsafe/cmp.concept.rs b/tests/std/support/cmp/out/unsafe/cmp.concept.rs index a199076f39..126c5aa0a9 100644 --- a/tests/std/support/cmp/out/unsafe/cmp.concept.rs +++ b/tests/std/support/cmp/out/unsafe/cmp.concept.rs @@ -19,6 +19,8 @@ use std::rc::Rc; PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_defaulted_three_way_Version { pub major: i32, pub minor: i32, @@ -103,6 +105,8 @@ pub static mut three_way_calls_1: std::cell::LazyCell = PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_user_written_three_way_Money { pub cents: i32, } @@ -168,6 +172,8 @@ pub unsafe fn test_2() { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_weaker_category_Temperature { pub degrees: f64, } @@ -221,6 +227,8 @@ pub unsafe fn test_3() { PartiallyOrderedWithUnsafe, )] #[three_way(p1_three_way_without_equality_Rank::operator_cmp)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_three_way_without_equality_Rank { pub value: i32, } diff --git a/tests/std/temp/out/refcount/temp.type.rs b/tests/std/temp/out/refcount/temp.type.rs index 5309ac5b21..4664d4c625 100644 --- a/tests/std/temp/out/refcount/temp.type.rs +++ b/tests/std/temp/out/refcount/temp.type.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p2_6_pointer_to_member_argument_HasTwoInts { #[offset(0)] @@ -39,7 +41,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_refp2_6_pointer_to_member_argument_HasTwoInts_first_ {} @@ -57,7 +61,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_refp2_6_pointer_to_member_argument_HasTwoInts_second_ {} @@ -75,7 +81,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 14eacf2404..38d9fb7e60 100644 --- a/tests/std/temp/out/unsafe/temp.type.rs +++ b/tests/std/temp/out/unsafe/temp.type.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p2_6_pointer_to_member_argument_HasTwoInts { pub first: i32, pub second: i32, @@ -32,7 +34,9 @@ pub static mut count_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 }); @@ -46,7 +50,9 @@ pub static mut count_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 }); @@ -60,7 +66,9 @@ pub static mut count_2: std::cell::LazyCell = std::cell::LazyCell::new(|| u TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 010980f4d9..a5ab8c271b 100644 --- a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs @@ -6,21 +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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, LvalueRef>)] #[byte_size(4)] pub struct p2_reference_does_not_instantiate_Member { #[offset(0)] pub value: i32, } impl p2_reference_does_not_instantiate_Member { - pub fn construct_1(this: Ptr, _a0: Ptr) { - field!(this, value).write(2); - } -} -impl DefaultConstructible for p2_reference_does_not_instantiate_Member { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, value).write(1); } + pub fn constructor_2( + this: Ptr, + _a0: LvalueRef>, + ) { + let _a0 = _a0.as_pointer(); + field!(this, value).write(2); + } } impl Default for p2_reference_does_not_instantiate_Member { fn default() -> Self { @@ -29,19 +44,25 @@ impl Default for p2_reference_does_not_instantiate_Member { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Default)] #[memberwise(move_constructor)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[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 DefaultConstructible for p2_reference_does_not_instantiate_Holder { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, member)); +impl p2_reference_does_not_instantiate_Holder { + pub fn constructor_1(this: Ptr) { + p2_reference_does_not_instantiate_Member::constructor_1(field_ptr!(this, member)); } } pub fn test_0() { - object!(holder, p2_reference_does_not_instantiate_Holder); + object!( + holder, + p2_reference_does_not_instantiate_Holder::constructor_1() + ); assert!(({ (*holder.borrow()).member.value } == 1)); (*holder.borrow_mut()).member.value = 3; assert!(({ (*holder.borrow()).member.value } == 3)); @@ -54,7 +75,9 @@ fn main_0() -> i32 { ({ test_0() }); return 0; } -#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] +#[derive( + Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg, ZeroInitialization, Destructible, Conversions, +)] #[byte_size(1)] pub struct p2_reference_does_not_instantiate_Wrapper_int_; pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs index f438666927..2c251655b9 100644 --- a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs @@ -7,23 +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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, LvalueRefUnsafe>)] pub struct p2_reference_does_not_instantiate_Member { pub value: i32, } impl p2_reference_does_not_instantiate_Member { - pub unsafe fn construct_1( + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).value).write(1); + } + pub unsafe fn constructor_2( this: *mut Self, - _a0: *const p2_reference_does_not_instantiate_Wrapper_int_, + _a0: LvalueRefUnsafe>, ) { + let _a0 = (_a0.as_ptr() as *const p2_reference_does_not_instantiate_Wrapper_int_); (&raw mut (*this).value).write(2); } } -impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Member { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).value).write(1); - } -} impl Default for p2_reference_does_not_instantiate_Member { fn default() -> Self { unsafe { p2_reference_does_not_instantiate_Member { value: 1 } } @@ -32,16 +42,22 @@ impl Default for p2_reference_does_not_instantiate_Member { #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, Default)] #[memberwise(move_constructor)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } -impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Holder { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).member); +impl p2_reference_does_not_instantiate_Holder { + pub unsafe fn constructor_1(this: *mut Self) { + p2_reference_does_not_instantiate_Member::constructor_1(&raw mut (*this).member); } } pub unsafe fn test_0() { - object_unsafe!(holder, p2_reference_does_not_instantiate_Holder); + object_unsafe!( + holder, + p2_reference_does_not_instantiate_Holder::constructor_1() + ); assert!(((holder.member.value) == (1))); holder.member.value = 3; assert!(((holder.member.value) == (3))); @@ -56,6 +72,15 @@ unsafe fn main_0() -> i32 { (unsafe { test_0() }); return 0; } -#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] +#[derive( + Clone, + Copy, + Default, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + ConversionsUnsafe, +)] pub struct p2_reference_does_not_instantiate_Wrapper_int_; pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs index ccbbd21b47..35d80cdd12 100644 --- a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs @@ -84,12 +84,24 @@ pub fn test_2() { Rc::new(RefCell::new(Ptr::alloc(81).to_owned_opt())), ))); let mut original: Ptr = ({ (*(*source.borrow()).1.borrow()).as_pointer() }); - let converted: Value<(Value, Value>>)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new( - (((*source.borrow()).0.as_pointer().read()) as i64), - )), - Rc::new(RefCell::new(cpp_move!((*source.borrow()).1.as_pointer()))), - ))); + let converted: Value<(Value, Value>>)> = Rc::new(RefCell::new({ + object!(__first, i64, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind((*source.borrow()).0.as_pointer()),) + )); + object!(__second, Option>, |__this| { + ConstructibleFrom::construct( + __this, + (RvalueRef::>>::bind( + (*source.borrow()).1.as_pointer(), + ),), + ) + }); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + })); assert!(({ ((*(*converted.borrow()).0.borrow()) == 0_i64) })); assert!(({ ({ (*(*converted.borrow()).1.borrow()).as_pointer() }) } == { (original).clone() })); assert!(((({ (*(*converted.borrow()).1.borrow()).as_pointer() }).read()) == 81)); @@ -106,10 +118,24 @@ pub fn test_3() { Rc::new(RefCell::new(None)), ))); { - let __first = (((*source.borrow()).0.as_pointer().read()) as i64); - let __second = cpp_move!((*source.borrow()).1.as_pointer()); - *(*target.borrow()).0.borrow_mut() = __first; - *(*target.borrow()).1.borrow_mut() = __second; + object!(__first, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*source.borrow()).0.as_pointer()), + __this + )); + object!(__second, Option>, |__this| { + ConvertibleTo::convert( + RvalueRef::>>::bind((*source.borrow()).1.as_pointer()), + __this, + ) + }); + MoveAssignable::move_assign( + (*target.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*target.borrow()).1.as_pointer(), + RvalueRef::>>::bind(__second.as_pointer()), + ); }; assert!(({ ((*(*target.borrow()).0.borrow()) == 4_i64) })); assert!(({ ({ (*(*target.borrow()).1.borrow()).as_pointer() }) } == { (original).clone() })); diff --git a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs index 05d651e5b5..ca2b64b432 100644 --- a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs @@ -77,8 +77,22 @@ pub unsafe fn test_2() { .1 .as_deref_mut() .map_or(::std::ptr::null_mut(), |v| v as *mut i32); - let mut converted: (i64, Option>) = - (((*&mut source.0) as i64), cpp_move_unsafe!(&mut source.1)); + let mut converted: (i64, Option>) = { + object_unsafe!(__first, i64, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut source.0),) + )); + object_unsafe!(__second, Option>, |__this| { + ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::>>::bind(&raw mut source.1),), + ) + }); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + }; assert!(((converted.0) == (0_i64))); assert!( ((converted @@ -111,7 +125,24 @@ pub unsafe fn test_3() { .map_or(::std::ptr::null_mut(), |v| v as *mut i32); let mut target: (i64, Option>) = (0_i64, None); { - target = (((*&mut source.0) as i64), cpp_move_unsafe!(&mut source.1)); + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut source.0), + __this + )); + object_unsafe!(__second, Option>, |__this| { + ConvertibleToUnsafe::convert( + RvalueRefUnsafe::>>::bind(&raw mut source.1), + __this, + ) + }); + MoveAssignableUnsafe::move_assign( + &raw mut target.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut target.1, + RvalueRefUnsafe::>>::bind(&raw mut __second), + ); }; assert!(((target.0) == (4_i64))); assert!( diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index ddf90123e1..956068cc7e 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -15,27 +15,26 @@ pub fn test_0() { assert!(({ ((*value.borrow()) == 2) })); } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct p6_forward_like_Movable { #[offset(0)] pub value: i32, } impl p6_forward_like_Movable { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl CopyConstructible for p6_forward_like_Movable { - fn copy_constructor(this: Ptr, other: LvalueRef>) { + pub fn constructor_2(this: Ptr, other: LvalueRef>) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); } -} -impl MoveConstructible for p6_forward_like_Movable { - fn move_constructor(this: Ptr, other: RvalueRef) { + pub fn constructor_3(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); @@ -43,15 +42,18 @@ impl MoveConstructible for p6_forward_like_Movable { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise)] #[memberwise(copy_constructor, move_constructor)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p6_forward_like_Holder { #[offset(0)] #[byte_size(4)] pub member: p6_forward_like_Movable, } -impl DefaultConstructible for p6_forward_like_Holder { - fn default_constructor(this: Ptr) { - p6_forward_like_Movable::construct(field_ptr!(this, member), 1); +impl p6_forward_like_Holder { + pub fn constructor_1(this: Ptr) { + p6_forward_like_Movable::constructor_1(field_ptr!(this, member), 1); } } impl Default for p6_forward_like_Holder { @@ -60,8 +62,8 @@ impl Default for p6_forward_like_Holder { p6_forward_like_Holder { member: { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - p6_forward_like_Movable::construct(__v.as_pointer(), 1); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p6_forward_like_Movable::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, } @@ -69,21 +71,21 @@ impl Default for p6_forward_like_Holder { } } pub fn take_1(__return: Ptr, self_: Ptr) { - CopyConstructible::copy_constructor( + p6_forward_like_Movable::constructor_2( __return.clone(), LvalueRef::bind(field_ptr!(self_, member)), ); return; } pub fn take_2(__return: Ptr, self_: Ptr) { - MoveConstructible::move_constructor( + p6_forward_like_Movable::constructor_3( __return.clone(), RvalueRef::bind(field_ptr!(self_, member)), ); return; } pub fn test_3() { - object!(holder, p6_forward_like_Holder); + object!(holder, p6_forward_like_Holder::constructor_1()); object!(copied, p6_forward_like_Movable, |copied| ({ take_1(Ptr::clone(&copied.clone()), holder.as_pointer()) })); @@ -94,21 +96,21 @@ pub fn test_3() { assert!(({ (*moved.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 0)); } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(4)] pub struct p9_move_Movable { #[offset(0)] pub value: i32, } impl p9_move_Movable { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl MoveConstructible for p9_move_Movable { - fn move_constructor(this: Ptr, other: RvalueRef) { + pub fn constructor_2(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); @@ -125,11 +127,10 @@ pub fn test_4() { ({ (moved_pointer).clone() } == { (target.as_pointer()) }) && ({ (pointer).clone() } == { (target.as_pointer()) }) ); - object!(source, p9_move_Movable(3)); + object!(source, p9_move_Movable::constructor_1(3)); object!( destination, - p9_move_Movable, - RvalueRef::bind(source.as_pointer()) + p9_move_Movable::constructor_2(RvalueRef::bind(source.as_pointer())) ); assert!(({ (*destination.borrow()).value } == 3) && ({ (*source.borrow()).value } == 0)); let strings: Value>> = Rc::new(RefCell::new(Vec::new())); @@ -151,8 +152,11 @@ pub fn test_4() { }) ); } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable)] -#[cpp_from(i32, construct, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct p10_forward_in_template_A { #[offset(0)] @@ -163,22 +167,18 @@ pub struct p10_forward_in_template_A { pub moves: i32, } impl p10_forward_in_template_A { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for p10_forward_in_template_A { - fn copy_constructor(this: Ptr, other: LvalueRef>) { + pub fn constructor_2(this: Ptr, other: LvalueRef>) { let other = other.as_pointer(); 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: RvalueRef) { + pub fn constructor_3(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(this, copies).write(0); @@ -192,15 +192,15 @@ impl Default for p10_forward_in_template_A { } } pub fn make_5(__return: Ptr, source: Ptr) { - CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind((source).clone())); + p10_forward_in_template_A::constructor_2(__return.clone(), LvalueRef::bind((source).clone())); return; } pub fn make_6(__return: Ptr, source: Ptr) { - MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((source).clone())); + p10_forward_in_template_A::constructor_3(__return.clone(), RvalueRef::bind((source).clone())); return; } pub fn test_7() { - object!(a, p10_forward_in_template_A(1)); + object!(a, p10_forward_in_template_A::constructor_1(1)); object!(copied, p10_forward_in_template_A, |copied| ({ make_5(Ptr::clone(&copied.clone()), a.as_pointer()) })); @@ -219,78 +219,80 @@ pub fn test_7() { assert!(({ (*a.borrow()).value } == 0)); } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct p11_move_if_noexcept_NoexceptMove { #[offset(0)] pub value: i32, } impl p11_move_if_noexcept_NoexceptMove { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl CopyConstructible for p11_move_if_noexcept_NoexceptMove { - fn copy_constructor( + pub fn constructor_2( this: Ptr, other: LvalueRef>, ) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); } -} -impl MoveConstructible for p11_move_if_noexcept_NoexceptMove { - fn move_constructor(this: Ptr, other: RvalueRef) { + pub fn constructor_3(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct p11_move_if_noexcept_ThrowingMove { #[offset(0)] pub value: i32, } impl p11_move_if_noexcept_ThrowingMove { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl CopyConstructible for p11_move_if_noexcept_ThrowingMove { - fn copy_constructor( + pub fn constructor_2( this: Ptr, other: LvalueRef>, ) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); } -} -impl MoveConstructible for p11_move_if_noexcept_ThrowingMove { - fn move_constructor(this: Ptr, other: RvalueRef) { + pub fn constructor_3(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } pub fn test_8() { - object!(moved_from, p11_move_if_noexcept_NoexceptMove(1)); + object!( + moved_from, + p11_move_if_noexcept_NoexceptMove::constructor_1(1) + ); object!( moved, - p11_move_if_noexcept_NoexceptMove, - RvalueRef::bind(moved_from.as_pointer()) + p11_move_if_noexcept_NoexceptMove::constructor_3(RvalueRef::bind(moved_from.as_pointer())) ); assert!(({ (*moved.borrow()).value } == 1) && ({ (*moved_from.borrow()).value } == 0)); - object!(copied_from, p11_move_if_noexcept_ThrowingMove(2)); + object!( + copied_from, + p11_move_if_noexcept_ThrowingMove::constructor_1(2) + ); object!( copied, - p11_move_if_noexcept_ThrowingMove, - LvalueRef::bind(copied_from.as_pointer()) + p11_move_if_noexcept_ThrowingMove::constructor_2(LvalueRef::bind(copied_from.as_pointer())) ); assert!(({ (*copied.borrow()).value } == 2) && ({ (*copied_from.borrow()).value } == 2)); } diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index 60ce4b7846..b72d0f16fb 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -23,7 +23,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p9_move_trivially_copyable_Point { #[offset(0)] @@ -58,37 +60,36 @@ pub fn test_1() { assert!(({ (*element.borrow()).x } == 5) && ({ (*element.borrow()).y } == 6)); } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(4)] pub struct p10_move_constructor_A { #[offset(0)] pub value: i32, } impl p10_move_constructor_A { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl MoveConstructible for p10_move_constructor_A { - fn move_constructor(this: Ptr, other: RvalueRef) { + pub fn constructor_2(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } pub fn test_2() { - object!(source, p10_move_constructor_A(1)); + object!(source, p10_move_constructor_A::constructor_1(1)); object!( target, - p10_move_constructor_A, - RvalueRef::bind(source.as_pointer()) + p10_move_constructor_A::constructor_2(RvalueRef::bind(source.as_pointer())) ); assert!(({ (*target.borrow()).value } == 1)); assert!(({ (*source.borrow()).value } == 0)); let values: Value> = Rc::new(RefCell::new(Vec::new())); - object!(element, p10_move_constructor_A(2)); + object!(element, p10_move_constructor_A::constructor_1(2)); MoveConstructible::push_moved(&values.as_pointer(), element.as_pointer()); assert!(({ (*values.borrow())[0_usize].value } == 2)); assert!(({ (*element.borrow()).value } == 0)); 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 d2081106fc..8a788a26cf 100644 --- a/tests/std/utilities/utility/out/refcount/utility.as.const.rs +++ b/tests/std/utilities/utility/out/refcount/utility.as.const.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 8b4e364fcf..2a8a93039b 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -16,28 +16,27 @@ pub unsafe fn test_0() { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct p6_forward_like_Movable { pub value: i32, } impl p6_forward_like_Movable { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl CopyConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn copy_constructor( + pub unsafe fn constructor_2( this: *mut Self, other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p6_forward_like_Movable); (&raw mut (*this).value).write((*other).value); } -} -impl MoveConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p6_forward_like_Movable); (&raw mut (*this).value).write((*other).value); (*other).value = 0; @@ -46,12 +45,15 @@ impl MoveConstructibleUnsafe for p6_forward_like_Movable { #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe)] #[memberwise(copy_constructor, move_constructor)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } -impl DefaultConstructibleUnsafe for p6_forward_like_Holder { - unsafe fn default_constructor(this: *mut Self) { - p6_forward_like_Movable::construct(&raw mut (*this).member, 1); +impl p6_forward_like_Holder { + pub unsafe fn constructor_1(this: *mut Self) { + p6_forward_like_Movable::constructor_1(&raw mut (*this).member, 1); } } impl Default for p6_forward_like_Holder { @@ -59,8 +61,8 @@ impl Default for p6_forward_like_Holder { unsafe { p6_forward_like_Holder { member: { - let mut __v: p6_forward_like_Movable = ::zero_init(); - p6_forward_like_Movable::construct(&raw mut __v, 1); + let mut __v: p6_forward_like_Movable = ZeroInitializationUnsafe::zero_init(); + p6_forward_like_Movable::constructor_1(&raw mut __v, 1); __v }, } @@ -68,18 +70,15 @@ impl Default for p6_forward_like_Holder { } } pub unsafe fn take_1(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(&(*self_).member)); + p6_forward_like_Movable::constructor_2(__return, LvalueRefUnsafe::bind(&(*self_).member)); return; } pub unsafe fn take_2(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - MoveConstructibleUnsafe::move_constructor( - __return, - RvalueRefUnsafe::bind(&mut (*self_).member), - ); + p6_forward_like_Movable::constructor_3(__return, RvalueRefUnsafe::bind(&mut (*self_).member)); return; } pub unsafe fn test_3() { - object_unsafe!(holder, p6_forward_like_Holder); + object_unsafe!(holder, p6_forward_like_Holder::constructor_1()); object_unsafe!(copied, p6_forward_like_Movable, |copied| (unsafe { take_1(copied, &mut holder) })); @@ -91,19 +90,19 @@ pub unsafe fn test_3() { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct p9_move_Movable { pub value: i32, } impl p9_move_Movable { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl MoveConstructibleUnsafe for p9_move_Movable { - unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + pub unsafe fn constructor_2(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p9_move_Movable); (&raw mut (*this).value).write((*other).value); (*other).value = 0; @@ -119,11 +118,10 @@ pub unsafe fn test_4() { assert!( ((moved_pointer) == (&mut target as *mut i32)) && ((pointer) == (&mut target as *mut i32)) ); - object_unsafe!(source, p9_move_Movable(3)); + object_unsafe!(source, p9_move_Movable::constructor_1(3)); object_unsafe!( destination, - p9_move_Movable, - RvalueRefUnsafe::bind(&mut source) + p9_move_Movable::constructor_2(RvalueRefUnsafe::bind(&mut source)) ); assert!(((destination.value) == (3)) && ((source.value) == (0))); let mut strings: Vec> = Vec::new(); @@ -144,22 +142,23 @@ pub unsafe fn test_4() { ); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe)] -#[cpp_from(i32, construct, value)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct p10_forward_in_template_A { pub value: i32, pub copies: i32, pub moves: i32, } impl p10_forward_in_template_A { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn copy_constructor( + pub unsafe fn constructor_2( this: *mut Self, other: LvalueRefUnsafe>, ) { @@ -168,9 +167,10 @@ impl CopyConstructibleUnsafe for p10_forward_in_template_A { (&raw mut (*this).copies).write((((*other).copies) + (1))); (&raw mut (*this).moves).write(0); } -} -impl MoveConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + pub unsafe fn constructor_3( + this: *mut Self, + other: RvalueRefUnsafe, + ) { let other = (other.as_ptr() as *mut p10_forward_in_template_A); (&raw mut (*this).value).write((*other).value); (&raw mut (*this).copies).write(0); @@ -187,18 +187,18 @@ pub unsafe fn make_5( __return: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A, ) { - CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(source)); + p10_forward_in_template_A::constructor_2(__return, LvalueRefUnsafe::bind(source)); return; } pub unsafe fn make_6( __return: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A, ) { - MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(source)); + p10_forward_in_template_A::constructor_3(__return, RvalueRefUnsafe::bind(source)); return; } pub unsafe fn test_7() { - object_unsafe!(a, p10_forward_in_template_A(1)); + object_unsafe!(a, p10_forward_in_template_A::constructor_1(1)); object_unsafe!(copied, p10_forward_in_template_A, |copied| (unsafe { make_5(copied, &mut a) })); @@ -212,28 +212,27 @@ pub unsafe fn test_7() { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct p11_move_if_noexcept_NoexceptMove { pub value: i32, } impl p11_move_if_noexcept_NoexceptMove { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl CopyConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { - unsafe fn copy_constructor( + pub unsafe fn constructor_2( this: *mut Self, other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p11_move_if_noexcept_NoexceptMove); (&raw mut (*this).value).write((*other).value); } -} -impl MoveConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { - unsafe fn move_constructor( + pub unsafe fn constructor_3( this: *mut Self, other: RvalueRefUnsafe, ) { @@ -244,28 +243,27 @@ impl MoveConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct p11_move_if_noexcept_ThrowingMove { pub value: i32, } impl p11_move_if_noexcept_ThrowingMove { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl CopyConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { - unsafe fn copy_constructor( + pub unsafe fn constructor_2( this: *mut Self, other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p11_move_if_noexcept_ThrowingMove); (&raw mut (*this).value).write((*other).value); } -} -impl MoveConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { - unsafe fn move_constructor( + pub unsafe fn constructor_3( this: *mut Self, other: RvalueRefUnsafe, ) { @@ -275,18 +273,22 @@ impl MoveConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { } } pub unsafe fn test_8() { - object_unsafe!(moved_from, p11_move_if_noexcept_NoexceptMove(1)); + object_unsafe!( + moved_from, + p11_move_if_noexcept_NoexceptMove::constructor_1(1) + ); object_unsafe!( moved, - p11_move_if_noexcept_NoexceptMove, - RvalueRefUnsafe::bind(&mut moved_from) + p11_move_if_noexcept_NoexceptMove::constructor_3(RvalueRefUnsafe::bind(&mut moved_from)) ); assert!(((moved.value) == (1)) && ((moved_from.value) == (0))); - object_unsafe!(copied_from, p11_move_if_noexcept_ThrowingMove(2)); + object_unsafe!( + copied_from, + p11_move_if_noexcept_ThrowingMove::constructor_1(2) + ); object_unsafe!( copied, - p11_move_if_noexcept_ThrowingMove, - LvalueRefUnsafe::bind(&copied_from) + p11_move_if_noexcept_ThrowingMove::constructor_2(LvalueRefUnsafe::bind(&copied_from)) ); 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 41b6475507..caa94a1e5e 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -22,7 +22,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p9_move_trivially_copyable_Point { pub x: i32, pub y: i32, @@ -49,35 +51,34 @@ pub unsafe fn test_1() { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct p10_move_constructor_A { pub value: i32, } impl p10_move_constructor_A { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl MoveConstructibleUnsafe for p10_move_constructor_A { - unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + pub unsafe fn constructor_2(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p10_move_constructor_A); (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } pub unsafe fn test_2() { - object_unsafe!(source, p10_move_constructor_A(1)); + object_unsafe!(source, p10_move_constructor_A::constructor_1(1)); object_unsafe!( target, - p10_move_constructor_A, - RvalueRefUnsafe::bind(&mut source) + p10_move_constructor_A::constructor_2(RvalueRefUnsafe::bind(&mut source)) ); assert!(((target.value) == (1))); assert!(((source.value) == (0))); let mut values: Vec = Vec::new(); - object_unsafe!(element, p10_move_constructor_A(2)); + object_unsafe!(element, p10_move_constructor_A::constructor_1(2)); values.push_moved(&mut element); assert!(((values[(0_usize)].value) == (2))); assert!(((element.value) == (0))); 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 3968b3170c..d70473ad09 100644 --- a/tests/std/utilities/utility/out/unsafe/utility.as.const.rs +++ b/tests/std/utilities/utility/out/unsafe/utility.as.const.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 bdf13b0f8f..576aa62fed 100644 --- a/tests/ub/out/refcount/ctor_ref_member.rs +++ b/tests/ub/out/refcount/ctor_ref_member.rs @@ -13,12 +13,13 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct, ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1, LvalueRef>)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -26,7 +27,8 @@ pub struct S { pub r: Ptr, } impl S { - pub fn construct(this: Ptr, x: Ptr) { + pub fn constructor_1(this: Ptr, x: LvalueRef>) { + let x = x.as_pointer(); field!(this, r).write((x).clone()); } } @@ -37,7 +39,7 @@ pub fn main() { fn main_0() -> i32 { object!(s, S, |s| { let __tmp_0: Value = Rc::new(RefCell::new(5)); - S::construct(s.clone(), __tmp_0.as_pointer()) + S::constructor_1(s.clone(), LvalueRef::bind(__tmp_0.as_pointer())) }); assert!((({ (*s.borrow()).r.clone() }.read()) == 5)); return 0; diff --git a/tests/ub/out/refcount/self_referencing_initializer.rs b/tests/ub/out/refcount/self_referencing_initializer.rs index 0628392e3f..c41ddd2eae 100644 --- a/tests/ub/out/refcount/self_referencing_initializer.rs +++ b/tests/ub/out/refcount/self_referencing_initializer.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 a6252b9b78..502c6d37e5 100644 --- a/tests/ub/out/refcount/ub6.rs +++ b/tests/ub/out/refcount/ub6.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 df6ec800d2..f63545f21a 100644 --- a/tests/ub/out/unsafe/ctor_ref_member.rs +++ b/tests/ub/out/unsafe/ctor_ref_member.rs @@ -13,17 +13,19 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1, LvalueRefUnsafe>)] pub struct S { pub r: *const i32, } impl S { - pub unsafe fn construct(this: *mut Self, x: *const i32) { + pub unsafe fn constructor_1(this: *mut Self, x: LvalueRefUnsafe>) { + let x = (x.as_ptr() as *const i32); (&raw mut (*this).r).write(x); } } @@ -36,7 +38,7 @@ pub fn main() { unsafe fn main_0() -> i32 { object_unsafe!(s, S, |s| { let mut __tmp_0: i32 = 5; - S::construct(s, &mut __tmp_0) + S::constructor_1(s, LvalueRefUnsafe::bind(&mut __tmp_0)) }); assert!(((*s.r) == (5))); return 0; diff --git a/tests/ub/out/unsafe/self_referencing_initializer.rs b/tests/ub/out/unsafe/self_referencing_initializer.rs index cfa5cbcf96..54d99126f4 100644 --- a/tests/ub/out/unsafe/self_referencing_initializer.rs +++ b/tests/ub/out/unsafe/self_referencing_initializer.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 d1522f289f..8578975d3d 100644 --- a/tests/ub/out/unsafe/ub6.rs +++ b/tests/ub/out/unsafe/ub6.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 9f515fbe1b..9719605c62 100644 --- a/tests/unit/out/refcount/05_new.rs +++ b/tests/unit/out/refcount/05_new.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct A {} #[derive( @@ -31,7 +33,9 @@ pub struct A {} TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct D {} impl D { diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index 4970fbf2f9..2aab41cbe5 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct GraphNode { #[offset(0)] @@ -35,7 +37,9 @@ pub struct GraphNode { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Graph { #[offset(0)] @@ -56,7 +60,12 @@ impl Graph { })); } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, Pointer)] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -64,14 +73,13 @@ pub struct Partial { pub p: Ptr, } impl Partial { - pub fn construct_1(this: Ptr, mut q: Ptr) { - field!(this, p).write((q).clone()); - } -} -impl DefaultConstructible for Partial { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, p).write(Ptr::::null()); } + pub fn constructor_2(this: Ptr, q: Pointer) { + let mut q = q.as_pointer(); + field!(this, p).write((q).clone()); + } } impl Default for Partial { fn default() -> Self { @@ -93,7 +101,9 @@ impl Default for Partial { DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Declared {} impl Declared {} @@ -107,7 +117,9 @@ impl Declared {} TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct S { #[offset(0)] @@ -126,11 +138,11 @@ fn main_0() -> i32 { adj: Ptr::>::null(), }; let arr: Value> = Rc::new(RefCell::new(Box::new([3, 1, 4]))); - object!(it, Partial::construct_1(arr.decay())); + object!(it, Partial::constructor_2(Pointer::bind(arr.decay()))); if ({ { (*it.borrow()).p.clone() } } != { arr.decay() }) { return 1; } - object!(def, Partial); + object!(def, Partial::constructor_1()); if !(({ (*def.borrow()).p.clone() }).is_null()) { return 1; } diff --git a/tests/unit/out/refcount/addr_of_global.rs b/tests/unit/out/refcount/addr_of_global.rs index 43a63d57af..7c3f0b1230 100644 --- a/tests/unit/out/refcount/addr_of_global.rs +++ b/tests/unit/out/refcount/addr_of_global.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Inner { #[offset(0)] @@ -33,7 +35,9 @@ pub struct Inner { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 deaf67bd22..e3de675ff5 100644 --- a/tests/unit/out/refcount/anonymous-struct.rs +++ b/tests/unit/out/refcount/anonymous-struct.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Outer_Named { #[offset(0)] @@ -36,7 +38,9 @@ pub struct Outer_Named { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -55,7 +59,9 @@ pub struct anon_0 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct anon_1 { #[offset(0)] @@ -74,7 +80,9 @@ pub struct anon_1 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct anon_2 { #[offset(0)] @@ -93,7 +101,9 @@ pub struct anon_2 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct anon_4 { #[offset(0)] @@ -110,7 +120,9 @@ pub struct anon_4 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct anon_5 { #[offset(0)] @@ -127,7 +139,9 @@ pub struct anon_5 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(12)] pub struct anon_3 { #[offset(0)] @@ -150,7 +164,9 @@ pub struct anon_3 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(44)] pub struct Outer { #[offset(0)] @@ -225,7 +241,9 @@ fn main_0() -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 7df4173370..722900ac17 100644 --- a/tests/unit/out/refcount/anonymous_enum.rs +++ b/tests/unit/out/refcount/anonymous_enum.rs @@ -23,7 +23,9 @@ pub const anon_1_SECOND_B: anon_1 = 1; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -46,7 +48,9 @@ pub const anon_2_FIELD_B: anon_2 = 1; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 a7d9a13ee8..84ba9fcf17 100644 --- a/tests/unit/out/refcount/any.rs +++ b/tests/unit/out/refcount/any.rs @@ -17,7 +17,10 @@ use std::rc::{Rc, Weak}; DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] +#[constructor(constructor_1, i32, i32)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -26,7 +29,7 @@ pub struct Point { pub y: i32, } impl Point { - pub fn construct(this: Ptr, mut x: i32, mut y: i32) { + pub fn constructor_1(this: Ptr, mut x: i32, mut y: i32) { field!(this, x).write(x); field!(this, y).write(y); } @@ -38,8 +41,8 @@ pub fn main() { fn main_0() -> i32 { let a: Value>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Point::construct(__v.as_pointer(), 3, 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_1(__v.as_pointer(), 3, 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); assert!(({ (*a.borrow()).is_some() })); @@ -78,8 +81,8 @@ fn main_0() -> i32 { let q: Ptr = { let mut __tmp_2 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Point::construct(__v.as_pointer(), 5, 6); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_1(__v.as_pointer(), 5, 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index a55ac2883a..4eae87808a 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -19,6 +19,9 @@ use std::rc::{Rc, Weak}; Swappable, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct NonCopy { #[offset(0)] @@ -27,8 +30,8 @@ pub struct NonCopy { #[offset(24)] pub tag: i32, } -impl DefaultConstructible for NonCopy { - fn default_constructor(this: Ptr) { +impl NonCopy { + pub fn constructor_1(this: Ptr) { field!(this, data).write(Vec::new()); field!(this, tag).write(0); } @@ -50,8 +53,8 @@ pub fn main() { fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 3, _>(|_| { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NonCopy::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); diff --git a/tests/unit/out/refcount/array_reference.rs b/tests/unit/out/refcount/array_reference.rs index 5ff4b1c8bf..cf494f4667 100644 --- a/tests/unit/out/refcount/array_reference.rs +++ b/tests/unit/out/refcount/array_reference.rs @@ -70,7 +70,9 @@ pub fn pick_10(s: Ptr) -> Ptr { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 d5a2db82e3..d777f68105 100644 --- a/tests/unit/out/refcount/as_const.rs +++ b/tests/unit/out/refcount/as_const.rs @@ -20,7 +20,9 @@ pub const Overload_kConstOverload: Overload = 2; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 4f27f30445..f96301dad8 100644 --- a/tests/unit/out/refcount/assign_rhs_first.rs +++ b/tests/unit/out/refcount/assign_rhs_first.rs @@ -25,7 +25,9 @@ pub fn advance_1() -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 b70578b8ec..bbd2ca8fbe 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -820,7 +820,9 @@ pub fn test_reference_members_9() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Slot_6 { #[offset(0)] @@ -837,7 +839,9 @@ pub struct Slot_6 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Slot_8 { #[offset(0)] @@ -854,7 +858,9 @@ pub struct Slot_8 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Slot_10 { #[offset(0)] @@ -929,7 +935,9 @@ pub fn test_pointer_elements_11() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Holder_12 { #[offset(0)] @@ -973,7 +981,9 @@ pub fn test_reference_pointer_13() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Node_14 { #[offset(0)] @@ -1081,7 +1091,9 @@ pub fn test_reference_subfields_18() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Index_16 { #[offset(0)] @@ -1097,7 +1109,9 @@ pub struct Index_16 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Slot_17 { #[offset(0)] @@ -1115,7 +1129,9 @@ pub struct Slot_17 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(2)] pub struct Index_19 { #[offset(0)] @@ -1131,7 +1147,9 @@ pub struct Index_19 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Slot_20 { #[offset(0)] @@ -1184,7 +1202,9 @@ pub fn observe_24(mut assigned: i32, mut stored: Ptr) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct GlobalRecord_Inner { #[offset(0)] @@ -1201,7 +1221,9 @@ pub struct GlobalRecord_Inner { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct GlobalRecord { #[offset(0)] @@ -1457,7 +1479,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Record_32 { #[offset(0)] @@ -1473,7 +1497,9 @@ pub struct Record_32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Link_33 { #[offset(0)] @@ -1495,7 +1521,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct IndexedBinding {} impl IndexedBinding { @@ -1751,7 +1779,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(12)] pub struct IndexedMember { #[offset(0)] @@ -2122,7 +2152,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct PointerSelector { #[offset(0)] @@ -2365,14 +2397,17 @@ pub fn test_stable_containers_58() { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Counts_59 { #[offset(0)] #[byte_size(24)] pub counts: Vec, } -impl DefaultConstructible for Counts_59 { - fn default_constructor(this: Ptr) { +impl Counts_59 { + pub fn constructor_1(this: Ptr) { field!(this, counts).write(Vec::new()); } } @@ -2387,7 +2422,9 @@ impl DefaultConstructible for Counts_59 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Pair_60 { #[offset(0)] @@ -2709,7 +2746,9 @@ fn main_0() -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Index_62 { #[offset(0)] @@ -2724,7 +2763,9 @@ pub struct Index_62 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(12)] pub struct Owner_63 { #[offset(0)] diff --git a/tests/unit/out/refcount/bounded_struct_ptr.rs b/tests/unit/out/refcount/bounded_struct_ptr.rs index 54fc36fef8..5ddee4f361 100644 --- a/tests/unit/out/refcount/bounded_struct_ptr.rs +++ b/tests/unit/out/refcount/bounded_struct_ptr.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 5cbf153e90..318586c3f3 100644 --- a/tests/unit/out/refcount/bst.rs +++ b/tests/unit/out/refcount/bst.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(24)] pub struct node_t { #[offset(0)] diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index 8749aed227..831c3621ea 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -21,7 +21,9 @@ pub const E_C: E = 2; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -40,7 +42,9 @@ pub struct Pair { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(64)] #[byte_align(64)] pub struct Wide { @@ -56,7 +60,9 @@ pub struct Wide { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(40)] pub struct Grid { #[offset(0)] @@ -97,6 +103,9 @@ impl Default for Grid { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct Bag { #[offset(0)] @@ -105,8 +114,8 @@ pub struct Bag { #[byte_size(24)] pub items: Vec, } -impl DefaultConstructible for Bag { - fn default_constructor(this: Ptr) { +impl Bag { + pub fn constructor_1(this: Ptr) { field!(this, n).write(0_i32); field!(this, items).write(Vec::new()); } @@ -380,7 +389,7 @@ pub fn nested_5() { assert!(({ ((*m.borrow())[(1) as usize][(1) as usize] == 42) })); assert!(({ (pm).clone() } == { (m.decay().offset(1).decay().offset(1)) })); assert!(({ (pm).clone() } < { (m.decay().offset(2).decay().offset(0)) })); - object!(b, Bag); + object!(b, Bag::constructor_1()); if 4_usize > (*b.borrow()).items.capacity() as usize { let len_0 = (*b.borrow()).items.len(); (*b.borrow_mut()) diff --git a/tests/unit/out/refcount/cast_array_to_pointer_decay.rs b/tests/unit/out/refcount/cast_array_to_pointer_decay.rs index 33ddcd4565..2be7893600 100644 --- a/tests/unit/out/refcount/cast_array_to_pointer_decay.rs +++ b/tests/unit/out/refcount/cast_array_to_pointer_decay.rs @@ -25,7 +25,9 @@ pub fn strlen_1(mut s: Ptr) -> i32 { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[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 d99c5277d1..01d48a3621 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -59,7 +61,9 @@ impl Pair { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Route { #[offset(0)] @@ -86,7 +90,9 @@ impl Route { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Counter { #[offset(0)] @@ -113,7 +119,9 @@ impl Counter { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 ebd24b3d08..541685d7cb 100644 --- a/tests/unit/out/refcount/class_template_lazy_member.rs +++ b/tests/unit/out/refcount/class_template_lazy_member.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Point { #[offset(0)] @@ -34,7 +36,9 @@ pub struct Point { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Box_int_ { #[offset(0)] @@ -56,7 +60,9 @@ impl Box_int_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Box_Point_ { #[offset(0)] @@ -79,7 +85,9 @@ impl Box_Point_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Deduced_int_ { #[offset(0)] @@ -101,7 +109,9 @@ impl Deduced_int_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 8eee2dcecd..69d4095d39 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -20,6 +20,9 @@ use std::rc::{Rc, Weak}; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct MyContainer_int_ { #[offset(0)] @@ -46,9 +49,7 @@ impl MyContainer_int_ { pub fn push_back(this: Ptr, item: Ptr) { CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); } -} -impl DefaultConstructible for MyContainer_int_ { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, vec_).write(Vec::new()); } } @@ -66,6 +67,9 @@ impl DefaultConstructible for MyContainer_int_ { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct MyContainer_char_ { #[offset(0)] @@ -92,9 +96,7 @@ impl MyContainer_char_ { pub fn push_back(this: Ptr, item: Ptr) { CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); } -} -impl DefaultConstructible for MyContainer_char_ { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, vec_).write(Vec::new()); } } @@ -112,6 +114,9 @@ impl DefaultConstructible for MyContainer_char_ { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct MyContainer_float_ { #[offset(0)] @@ -138,9 +143,7 @@ impl MyContainer_float_ { pub fn push_back(this: Ptr, item: Ptr) { CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); } -} -impl DefaultConstructible for MyContainer_float_ { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, vec_).write(Vec::new()); } } @@ -155,7 +158,9 @@ impl DefaultConstructible for MyContainer_float_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(2)] pub struct Boxed_short_ { #[offset(0)] @@ -180,7 +185,9 @@ impl Boxed_short_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Boxed_int_ { #[offset(0)] @@ -205,7 +212,9 @@ impl Boxed_int_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Boxed_long_ { #[offset(0)] @@ -230,7 +239,9 @@ impl Boxed_long_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Outer_int__Inner_int_ { #[offset(0)] @@ -254,7 +265,9 @@ impl Outer_int__Inner_int_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Outer_int_ { #[offset(0)] @@ -279,7 +292,9 @@ impl Outer_int_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Outer_long__Inner_int_ { #[offset(0)] @@ -303,7 +318,9 @@ impl Outer_long__Inner_int_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Outer_long__Inner_char_ { #[offset(0)] @@ -327,7 +344,9 @@ impl Outer_long__Inner_char_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Outer_long_ { #[offset(0)] @@ -352,7 +371,9 @@ impl Outer_long_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Elem { #[offset(0)] @@ -397,7 +418,7 @@ fn main_0() -> i32 { assert!((({ Boxed_long_::twice(10_i64,) }) == 20_i64)); let bl: Value = Rc::new(RefCell::new(Boxed_long_ { value: 7_i64 })); assert!((({ Boxed_long_::plus(bl.as_pointer(), 1_i64,) }) == 8_i64)); - object!(imc, MyContainer_int_); + object!(imc, MyContainer_int_::constructor_1()); assert!(({ MyContainer_int_::empty(imc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(1)); @@ -409,7 +430,7 @@ fn main_0() -> i32 { ); ({ MyContainer_int_::pop_back(imc.as_pointer()) }); assert!(({ MyContainer_int_::empty(imc.as_pointer(),) })); - object!(cmc, MyContainer_char_); + object!(cmc, MyContainer_char_::constructor_1()); assert!(({ MyContainer_char_::empty(cmc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(('a' as i8))); @@ -422,7 +443,7 @@ fn main_0() -> i32 { ); ({ MyContainer_char_::pop_back(cmc.as_pointer()) }); assert!(({ MyContainer_char_::empty(cmc.as_pointer(),) })); - object!(fmc, MyContainer_float_); + object!(fmc, MyContainer_float_::constructor_1()); assert!(({ MyContainer_float_::empty(fmc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new((1_f64 as f32))); diff --git a/tests/unit/out/refcount/clone_vs_move.rs b/tests/unit/out/refcount/clone_vs_move.rs index a574e73e31..01f08719fe 100644 --- a/tests/unit/out/refcount/clone_vs_move.rs +++ b/tests/unit/out/refcount/clone_vs_move.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Bar { #[offset(0)] @@ -32,7 +34,9 @@ pub struct Bar { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(40)] pub struct Foo { #[offset(0)] @@ -74,7 +78,9 @@ impl Default for Foo { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 fef3a5cb80..c4bf0369ef 100644 --- a/tests/unit/out/refcount/comma_operator.rs +++ b/tests/unit/out/refcount/comma_operator.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 0ffe5dbb4a..cdaf1ef018 100644 --- a/tests/unit/out/refcount/complex_function.rs +++ b/tests/unit/out/refcount/complex_function.rs @@ -26,7 +26,9 @@ pub fn bar_2(x: Ptr) -> Ptr { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct X1 { #[offset(0)] @@ -42,7 +44,9 @@ pub struct X1 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct X2 { #[offset(0)] @@ -64,7 +68,9 @@ impl X2 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct X3 { #[offset(0)] @@ -86,7 +92,9 @@ impl X3 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 700b3a4f88..bcb31b9e27 100644 --- a/tests/unit/out/refcount/compound_assign_paren.rs +++ b/tests/unit/out/refcount/compound_assign_paren.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 97e6a487cc..4d2bb260fd 100644 --- a/tests/unit/out/refcount/concepts.rs +++ b/tests/unit/out/refcount/concepts.rs @@ -22,7 +22,9 @@ const _: () = assert!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Sized {} impl Sized { diff --git a/tests/unit/out/refcount/constexpr_function.rs b/tests/unit/out/refcount/constexpr_function.rs index b93cdd6ebe..3f53ea24b1 100644 --- a/tests/unit/out/refcount/constexpr_function.rs +++ b/tests/unit/out/refcount/constexpr_function.rs @@ -32,7 +32,10 @@ pub fn half_3(mut x: f64) -> f64 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct Flag { #[offset(0)] @@ -71,7 +74,9 @@ pub fn imm_7(mut b: bool) -> bool { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 6307c112b3..7fbe88c197 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -16,14 +16,15 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, Memberwise, CopyConstructible, Movable, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -38,7 +39,7 @@ impl S { field!(this, v).with_mut(|__v| *__v = *__v + 1) }; } - pub fn construct(this: Ptr, mut init: i32) { + pub fn constructor_1(this: Ptr, mut init: i32) { field!(this, v).write(init); ({ S::mut_method(this.clone()) }); let __rhs = ({ S::const_method(this.clone()) }); @@ -53,9 +54,20 @@ impl Destructible for S { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, TriviallyCopyable, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, )] -#[cpp_from(i32, construct_1, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -64,20 +76,18 @@ pub struct Point { pub y: i32, } impl Point { - pub fn construct_2(this: Ptr, mut x: i32, mut y: i32) { + pub fn constructor_1(this: Ptr, mut x: i32, mut y: i32) { field!(this, x).write(x); field!(this, y).write(y); } - pub fn construct_1(this: Ptr, mut v: i32) { - Point::construct_2(this.clone(), v, (v + 1)); + pub fn constructor_2(this: Ptr, mut v: i32) { + Point::constructor_1(this.clone(), v, (v + 1)); { field!(this, y).with_mut(|__v| *__v = *__v * 10) }; } -} -impl DefaultConstructible for Point { - fn default_constructor(this: Ptr) { - Point::construct_1(this.clone(), 4); + pub fn constructor_3(this: Ptr) { + Point::constructor_2(this.clone(), 4); { field!(this, x).with_mut(|__v| *__v = *__v + 100) }; @@ -87,8 +97,8 @@ impl Default for Point { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_3(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -100,15 +110,15 @@ pub fn main() { } fn main_0() -> i32 { { - object!(s, S(3)); + object!(s, S::constructor_1(3)); assert!(({ (*s.borrow()).v } == 4)); assert!((total_0.with(|rc| *rc.borrow()) == 8)); } assert!((total_0.with(|rc| *rc.borrow()) == 18)); - object!(p, Point); + object!(p, Point::constructor_3()); assert!(({ (*p.borrow()).x } == 104)); assert!(({ (*p.borrow()).y } == 50)); - object!(q, Point::construct_1(7)); + object!(q, Point::constructor_2(7)); assert!(({ (*q.borrow()).x } == 7)); assert!(({ (*q.borrow()).y } == 80)); return 0; diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index 0f5a446b89..c4bb6c21e0 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -22,6 +22,8 @@ use std::rc::{Rc, Weak}; Default, )] #[memberwise(move_constructor)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(32)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/container_field_addr.rs b/tests/unit/out/refcount/container_field_addr.rs index 7ebb9e6509..c4cac46cc0 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -20,6 +20,9 @@ use std::rc::{Rc, Weak}; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct S { #[offset(0)] @@ -28,8 +31,8 @@ pub struct S { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for S { - fn default_constructor(this: Ptr) { +impl S { + pub fn constructor_1(this: Ptr) { field!(this, tag).write(0_i32); field!(this, v).write(Vec::new()); } @@ -58,12 +61,12 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(local, S); + object!(local, S::constructor_1()); (*local.borrow_mut()).tag = 7; ({ run_1((local.as_pointer())) }); let mut heap: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(__p.clone()); + S::constructor_1(__p.clone()); __p }; field!(heap, tag).write(7); diff --git a/tests/unit/out/refcount/conversion_operator_same_translation.rs b/tests/unit/out/refcount/conversion_operator_same_translation.rs index c6f562fa0d..95557778f6 100644 --- a/tests/unit/out/refcount/conversion_operator_same_translation.rs +++ b/tests/unit/out/refcount/conversion_operator_same_translation.rs @@ -14,13 +14,14 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, - CppFrom, TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_into(i8, to_i8)] -#[cpp_into(u8, to_u8)] +#[conversions(copy, move)] +#[conversion_function(to_i8, LvalueRef>, i8 )] +#[conversion_function(to_u8, LvalueRef>, u8 )] #[byte_size(4)] pub struct S { #[offset(0)] @@ -42,12 +43,14 @@ impl S { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_into(i64, to_i64_1)] +#[conversions(copy, move)] +#[conversion_function(to_i64_1, LvalueRef>, i64 )] +#[conversion_function(to_i64_2, LvalueRef>, i64 )] #[byte_size(4)] pub struct T { #[offset(0)] diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index dfbec42db3..4f00ada430 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -19,7 +19,11 @@ thread_local!( MoveAssignable, Swappable, Default, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -28,13 +32,11 @@ pub struct Partial { pub keep: i32, } impl Partial { - pub fn construct(this: Ptr, mut v: i32, mut keep: i32) { + pub fn constructor_1(this: Ptr, mut v: i32, mut keep: i32) { field!(this, v).write(v); field!(this, keep).write(keep); } -} -impl CopyConstructible for Partial { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, keep).write(o.with(|__s| __s.keep)); @@ -52,14 +54,28 @@ impl CopyAssignable for Partial { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct NonConstAssign { #[offset(0)] pub mark: i32, } impl NonConstAssign { + pub fn constructor_1(this: Ptr) { + field!(this, mark).write(0); + } pub fn operator_assign_2(this: Ptr, o: Ptr) -> Ptr { field!(this, mark).write((o.with(|__s| __s.mark) + 1)); return (this).clone(); @@ -69,18 +85,13 @@ impl NonConstAssign { return (this).clone(); } } -impl DefaultConstructible for NonConstAssign { - fn default_constructor(this: Ptr) { - field!(this, mark).write(0); - } -} impl Default for NonConstAssign { fn default() -> Self { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NonConstAssign::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -97,14 +108,17 @@ impl Default for NonConstAssign { Destructible, CopyConstructible, Movable, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct RefQualified { #[offset(0)] pub mark: i32, } -impl DefaultConstructible for RefQualified { - fn default_constructor(this: Ptr) { +impl RefQualified { + pub fn constructor_1(this: Ptr) { field!(this, mark).write(0); } } @@ -119,8 +133,9 @@ impl Default for RefQualified { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefQualified::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -130,6 +145,8 @@ impl Default for RefQualified { Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(24)] pub struct Holder { #[offset(0)] @@ -140,6 +157,7 @@ pub struct Holder { #[array_len(2)] pub arr: Box<[Partial]>, } +impl Holder {} impl Default for Holder { fn default() -> Self { { @@ -160,7 +178,6 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -169,19 +186,20 @@ thread_local!( Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct CopyCounted { #[offset(0)] pub v: i32, } impl CopyCounted { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for CopyCounted { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); @@ -191,6 +209,8 @@ impl CopyConstructible for CopyCounted { Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(12)] pub struct HasCopyCounted { #[offset(0)] @@ -201,6 +221,7 @@ pub struct HasCopyCounted { #[array_len(2)] pub arr: Box<[CopyCounted]>, } +impl HasCopyCounted {} impl Default for HasCopyCounted { fn default() -> Self { { @@ -224,13 +245,21 @@ impl Default for HasCopyCounted { CopyConstructible, Movable, Default, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct ExplicitOperatorCall { #[offset(0)] #[byte_size(24)] pub w: Vec, } +impl ExplicitOperatorCall { + pub fn constructor_1(this: Ptr) { + field!(this, w).write(Vec::new()); + } +} impl CopyAssignable for ExplicitOperatorCall { fn copy_assign( this: Ptr, @@ -245,11 +274,6 @@ impl CopyAssignable for ExplicitOperatorCall { return (this).clone(); } } -impl DefaultConstructible for ExplicitOperatorCall { - fn default_constructor(this: Ptr) { - field!(this, w).write(Vec::new()); - } -} thread_local!( pub static swap_copies_2: Value = Rc::new(RefCell::new(0)); ); @@ -258,47 +282,54 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, MoveConstructible, Swappable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Swapped { #[offset(0)] pub v: i32, } impl Swapped { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } - pub fn copy_assign(this: Ptr, o: Ptr) -> Ptr { - let mut t: i32 = this.with(|__s| __s.v); + pub fn constructor_2(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); - field!(o, v).write(t); - return (this).clone(); + (*swap_copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for Swapped { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn copy_assign(this: Ptr, o: ParameterObject) -> Ptr { let o = o.as_pointer(); + let mut t: i32 = this.with(|__s| __s.v); field!(this, v).write(o.with(|__s| __s.v)); - (*swap_copies_2.with(Value::clone).borrow_mut()).prefix_inc(); + field!(o, v).write(t); + return (this).clone(); } } impl CopyAssignable for Swapped { fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { object!(__o, Swapped, LvalueRef::bind(src.as_pointer())); - Swapped::copy_assign(this.clone(), Ptr::clone(&__o.as_pointer())); + Swapped::copy_assign( + this.clone(), + ParameterObject::bind(Ptr::clone(&__o.as_pointer())), + ); Ptr::clone(&this.clone()) } } impl MoveAssignable for Swapped { fn move_assign(this: Ptr, src: RvalueRef) -> Ptr { object!(__o, Swapped, RvalueRef::bind(src.as_pointer())); - Swapped::copy_assign(this.clone(), Ptr::clone(&__o.as_pointer())); + Swapped::copy_assign( + this.clone(), + ParameterObject::bind(Ptr::clone(&__o.as_pointer())), + ); Ptr::clone(&this.clone()) } } @@ -313,12 +344,15 @@ impl MoveAssignable for Swapped { Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct HoldsSwapped { #[offset(0)] #[byte_size(4)] pub s: Swapped, } +impl HoldsSwapped {} #[derive( Copy, Clone, @@ -331,22 +365,23 @@ pub struct HoldsSwapped { CopyConstructible, MoveConstructible, Swappable, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct VoidAssign { #[offset(0)] pub x: i32, } impl VoidAssign { + pub fn constructor_1(this: Ptr) { + field!(this, x).write(0); + } pub fn copy_assign(this: Ptr, o: Ptr) { field!(this, x).write((o.with(|__s| __s.x) + 5)); } } -impl DefaultConstructible for VoidAssign { - fn default_constructor(this: Ptr) { - field!(this, x).write(0); - } -} impl CopyAssignable for VoidAssign { fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { VoidAssign::copy_assign(this.clone(), src.as_pointer()); @@ -363,8 +398,8 @@ impl Default for VoidAssign { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + VoidAssign::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -385,15 +420,18 @@ impl Default for VoidAssign { Default, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct HoldsVoidAssign { #[offset(0)] #[byte_size(4)] pub v: VoidAssign, } -impl DefaultConstructible for HoldsVoidAssign { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, v)); +impl HoldsVoidAssign { + pub fn constructor_1(this: Ptr) { + VoidAssign::constructor_1(field_ptr!(this, v)); } } pub fn main() { @@ -401,9 +439,9 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Partial(1, 100)); - object!(b, Partial(2, 200)); - object!(c, Partial(3, 300)); + object!(a, Partial::constructor_1(1, 100)); + object!(b, Partial::constructor_1(2, 200)); + object!(c, Partial::constructor_1(3, 300)); assign!(a = b); assert!(({ (*a.borrow()).v } == 2) && ({ (*a.borrow()).keep } == 100)); assert!((assigns_0.with(|rc| *rc.borrow()) == 1)); @@ -413,8 +451,8 @@ fn main_0() -> i32 { assign!(a = a); assert!((assigns_0.with(|rc| *rc.borrow()) == 3)); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(_o.as_pointer(), 9, 900); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(_o.as_pointer(), 9, 900); assign!(a = _o) }); assert!(({ (*a.borrow()).v } == 9) && ({ (*a.borrow()).keep } == 100)); @@ -428,19 +466,19 @@ fn main_0() -> i32 { assert!((assigns_0.with(|rc| *rc.borrow()) == 6)); let h: Value = Rc::new(RefCell::new(Holder { p: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 4, 40); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 4, 40); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 5, 50); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 5, 50); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 6, 60); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 6, 60); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -453,33 +491,33 @@ fn main_0() -> i32 { && (array_elem!(h.as_pointer(), arr, 1).with(|__s| __s.keep) == 60) ); assert!((assigns_0.with(|rc| *rc.borrow()) == 8)); - object!(n, NonConstAssign); - object!(n1, NonConstAssign); - object!(n2, NonConstAssign); - object!(cn, NonConstAssign); + object!(n, NonConstAssign::constructor_1()); + object!(n1, NonConstAssign::constructor_1()); + object!(n2, NonConstAssign::constructor_1()); + object!(cn, NonConstAssign::constructor_1()); NonConstAssign::operator_assign_2(n1.as_pointer(), n.as_pointer()); NonConstAssign::operator_assign_3(n2.as_pointer(), cn.as_pointer()); assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); - object!(r, RefQualified); - object!(r1, RefQualified); + object!(r, RefQualified::constructor_1()); + object!(r1, RefQualified::constructor_1()); assign!(r1 = r); assert!(({ (*r1.borrow()).mark } == 1)); let h2: Value = Rc::new(RefCell::new(Holder { p: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 7, 70); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 7, 70); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 8, 80); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 8, 80); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 9, 90); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 9, 90); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -491,44 +529,48 @@ fn main_0() -> i32 { && (array_elem!(h2.as_pointer(), arr, 1).with(|__s| __s.keep) == 90) ); assert!((assigns_0.with(|rc| *rc.borrow()) == 11)); - object!(cc1, CopyCounted(1)); - object!(cc2, CopyCounted(2)); + object!(cc1, CopyCounted::constructor_1(1)); + object!(cc2, CopyCounted::constructor_1(2)); assign!(cc1 = cc2); assert!(({ (*cc1.borrow()).v } == 2)); let hc1: Value = Rc::new(RefCell::new(HasCopyCounted { c: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 2); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 3); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), })); let hc2: Value = Rc::new(RefCell::new(HasCopyCounted { c: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 5); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 6); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -540,8 +582,8 @@ fn main_0() -> i32 { && (array_elem!(hc1.as_pointer(), arr, 1).with(|__s| __s.v) == 6) ); assert!((copies_1.with(|rc| *rc.borrow()) == 0)); - object!(e1, ExplicitOperatorCall); - object!(e2, ExplicitOperatorCall); + object!(e1, ExplicitOperatorCall::constructor_1()); + object!(e2, ExplicitOperatorCall::constructor_1()); ({ let __tmp_1: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( @@ -557,32 +599,32 @@ fn main_0() -> i32 { && ((*e1.borrow()).w.len() == 1_usize) }) ); - object!(sw1, Swapped(1)); - object!(sw2, Swapped(2)); + object!(sw1, Swapped::constructor_1(1)); + object!(sw2, Swapped::constructor_1(2)); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(_o.as_pointer(), LvalueRef::bind(sw2.as_pointer())); - Swapped::copy_assign(sw1.as_pointer(), _o.as_pointer()) + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Swapped::constructor_2(_o.as_pointer(), LvalueRef::bind(sw2.as_pointer())); + Swapped::copy_assign(sw1.as_pointer(), ParameterObject::bind(_o.as_pointer())) }); assert!(({ (*sw1.borrow()).v } == 2) && (swap_copies_2.with(|rc| *rc.borrow()) == 1)); let hs1: Value = Rc::new(RefCell::new(HoldsSwapped { s: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Swapped::construct(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Swapped::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); let hs2: Value = Rc::new(RefCell::new(HoldsSwapped { s: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Swapped::construct(__v.as_pointer(), 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Swapped::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); assign!(hs1 = hs2); assert!(({ (*hs1.borrow()).s.v } == 4) && (swap_copies_2.with(|rc| *rc.borrow()) == 2)); - object!(hv1, HoldsVoidAssign); - object!(hv2, HoldsVoidAssign); + object!(hv1, HoldsVoidAssign::constructor_1()); + object!(hv2, HoldsVoidAssign::constructor_1()); assign!(hv1 = hv2); assert!(({ (*hv1.borrow()).v.x } == 5)); return 0; diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index f1c9d161c8..36d2db9828 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -14,7 +14,6 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -23,52 +22,66 @@ thread_local!( Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Counted { #[offset(0)] pub v: i32, } impl Counted { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, MoveAssignable, + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + Destructible, + Memberwise, + MoveConstructible, + MoveAssignable, + Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef)] +#[constructor(constructor_3, LvalueRef>)] #[byte_size(4)] pub struct NonConst { #[offset(0)] pub mark: i32, } impl NonConst { - pub fn construct_1(this: Ptr, o: Ptr) { + pub fn constructor_1(this: Ptr) { + field!(this, mark).write(0); + } + pub fn constructor_2(this: Ptr, o: LvalueRef) { + let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 1)); } - pub fn construct_2(this: Ptr, o: Ptr) { + pub fn constructor_3(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 10)); } } -impl DefaultConstructible for NonConst { - fn default_constructor(this: Ptr) { - field!(this, mark).write(0); - } -} impl Default for NonConst { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NonConst::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -79,7 +92,6 @@ impl Default for NonConst { ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -88,19 +100,20 @@ impl Default for NonConst { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Ignored { #[offset(0)] pub v: i32, } impl Ignored { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for Ignored { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, v).write(-1_i32); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); @@ -110,6 +123,8 @@ impl CopyConstructible for Ignored { Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(12)] pub struct Holder { #[offset(0)] @@ -120,6 +135,7 @@ pub struct Holder { #[array_len(2)] pub arr: Box<[Counted]>, } +impl Holder {} impl Default for Holder { fn default() -> Self { { @@ -133,29 +149,23 @@ impl Default for Holder { } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Box_int_ { #[offset(0)] pub val: i32, } impl Box_int_ { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, val).write(v); } -} -impl CopyConstructible for Box_int_ { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, val).write(o.with(|__s| __s.val)); } @@ -164,18 +174,20 @@ impl CopyConstructible for Box_int_ { Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct Owner { #[offset(0)] #[byte_size(4)] pub box_: Box_int_, } +impl Owner {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -184,24 +196,26 @@ pub struct Owner { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct OutOfLine { #[offset(0)] pub v: i32, } impl OutOfLine { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for OutOfLine { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl OutOfLine {} #[derive( Record, ByteRepr, @@ -211,19 +225,21 @@ impl CopyConstructible for OutOfLine { MoveConstructible, MoveAssignable, Swappable, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Tracked { #[offset(0)] pub copied_from: i32, } -impl DefaultConstructible for Tracked { - fn default_constructor(this: Ptr) { +impl Tracked { + pub fn constructor_1(this: Ptr) { field!(this, copied_from).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, copied_from).write(0); field!(o, copied_from).with_mut(|__v| { @@ -250,34 +266,35 @@ pub fn touch_1(mut t: Ptr) { __v.prefix_inc(); }); } -pub fn by_value_2(c: Ptr) -> i32 { +pub fn by_value_2(c: ParameterObject) -> i32 { + let c = c.as_pointer(); return c.with(|__s| __s.v); } pub fn make_3(__return: Ptr, mut v: i32) { - object!(c, Counted(v)); - CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind(c.as_pointer())); + object!(c, Counted::constructor_1(v)); + Counted::constructor_2(__return.clone(), LvalueRef::bind(c.as_pointer())); return; } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(8)] pub struct SelfPtr { #[offset(0)] #[byte_size(8)] pub self_: Ptr, } -impl DefaultConstructible for SelfPtr { - fn default_constructor(this: Ptr) { +impl SelfPtr { + pub fn constructor_1(this: Ptr) { field!(this, self_).write((this).clone()); } -} -impl CopyConstructible for SelfPtr { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); } -} -impl MoveConstructible for SelfPtr { - fn move_constructor(this: Ptr, _a0: RvalueRef) { + pub fn constructor_3(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); } @@ -286,8 +303,8 @@ impl Default for SelfPtr { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + SelfPtr::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -304,28 +321,33 @@ impl Default for SelfPtr { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct EmptyBase {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Derived { #[offset(0)] #[byte_size(4)] pub c: Counted, } -impl DefaultConstructible for Derived { - fn default_constructor(this: Ptr) { - Counted::construct(field_ptr!(this, c), 20); +impl Derived { + pub fn constructor_1(this: Ptr) { + Counted::constructor_1(field_ptr!(this, c), 20); } } impl Default for Derived { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Derived::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -336,52 +358,57 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Counted(1)); - object!(b, Counted, LvalueRef::bind(a.as_pointer())); - object!(c, Counted, LvalueRef::bind(a.as_pointer())); - object!(d, Counted, LvalueRef::bind(a.as_pointer())); + object!(a, Counted::constructor_1(1)); + object!(b, Counted::constructor_2(LvalueRef::bind(a.as_pointer()))); + object!(c, Counted::constructor_2(LvalueRef::bind(a.as_pointer()))); + object!(d, Counted::constructor_2(LvalueRef::bind(a.as_pointer()))); assert!((copies_0.with(|rc| *rc.borrow()) == 3)); assert!( (({ (*b.borrow()).v } == 1) && ({ (*c.borrow()).v } == 1)) && ({ (*d.borrow()).v } == 1) ); assert!( (({ - let _c: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(_c.as_pointer(), LvalueRef::bind(a.as_pointer())); - by_value_2(_c.as_pointer()) + let _c: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2(_c.as_pointer(), LvalueRef::bind(a.as_pointer())); + by_value_2(ParameterObject::bind(_c.as_pointer())) }) == 1) ); assert!((copies_0.with(|rc| *rc.borrow()) == 4)); object!(e, Counted, |e| ({ make_3(Ptr::clone(&e.clone()), 5,) })); assert!(({ (*e.borrow()).v } == 5)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); - object!(f, Counted(6)); + object!(f, Counted::constructor_1(6)); assert!(({ (*f.borrow()).v } == 6)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); - object!(g, Counted(7)); - object!(h, Counted, LvalueRef::bind(g.as_pointer())); + object!(g, Counted::constructor_1(7)); + object!(h, Counted::constructor_2(LvalueRef::bind(g.as_pointer()))); assert!(({ (*h.borrow()).v } == 7)); assert!((copies_0.with(|rc| *rc.borrow()) == 6)); let hold: Value = Rc::new(RefCell::new(Holder { c: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Counted::construct(__v.as_pointer(), 8); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer(), 8); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Counted::construct(__v.as_pointer(), 9); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Counted::construct(__v.as_pointer(), 10); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), })); - object!(hold2, Holder, LvalueRef::bind(hold.as_pointer())); + object!(hold2, Holder, |hold2| { + ::copy_constructor( + hold2.clone(), + LvalueRef::bind(hold.as_pointer()), + ) + }); assert!( (({ (*hold2.borrow()).c.v } == 8) && (array_elem!(hold2.as_pointer(), arr, 0).with(|__s| __s.v) == 9)) @@ -392,54 +419,72 @@ fn main_0() -> i32 { CopyConstructible::push_copied(&vec_.as_pointer(), a.as_pointer()); assert!(({ (*vec_.borrow())[0_usize].v } == 1)); assert!((copies_0.with(|rc| *rc.borrow()) == 10)); - object!(i1, Ignored(1)); - object!(i2, Ignored, LvalueRef::bind(i1.as_pointer())); + object!(i1, Ignored::constructor_1(1)); + object!(i2, Ignored::constructor_2(LvalueRef::bind(i1.as_pointer()))); assert!(({ (*i1.borrow()).v } == 1) && ({ (*i2.borrow()).v } == -1_i32)); assert!((copies_0.with(|rc| *rc.borrow()) == 11)); let o: Value = Rc::new(RefCell::new(Owner { box_: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Box_int_::construct(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Box_int_::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); - object!(o2, Owner, RvalueRef::bind(o.as_pointer())); + object!(o2, Owner, |o2| { + ::move_constructor(o2.clone(), RvalueRef::bind(o.as_pointer())) + }); assert!(({ (*o2.borrow()).box_.val } == 3)); - object!(ol1, OutOfLine(5)); - object!(ol2, OutOfLine, LvalueRef::bind(ol1.as_pointer())); + object!(ol1, OutOfLine::constructor_1(5)); + object!( + ol2, + OutOfLine::constructor_2(LvalueRef::bind(ol1.as_pointer())) + ); assert!(({ (*ol2.borrow()).v } == 105)); assert!((copies_0.with(|rc| *rc.borrow()) == 12)); - object!(n, NonConst); - object!(n1, NonConst::construct_1(n.as_pointer())); - object!(cn, NonConst); - object!(n2, NonConst::construct_2(cn.as_pointer())); + object!(n, NonConst::constructor_1()); + object!(n1, NonConst::constructor_2(LvalueRef::bind(n.as_pointer()))); + object!(cn, NonConst::constructor_1()); + object!( + n2, + NonConst::constructor_3(LvalueRef::bind(cn.as_pointer())) + ); assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); - object!(t1, Tracked); - object!(t2, Tracked, LvalueRef::bind(t1.as_pointer())); + object!(t1, Tracked::constructor_1()); + object!(t2, Tracked::constructor_2(LvalueRef::bind(t1.as_pointer()))); assign!(t2 = t1); assert!(({ (*t1.borrow()).copied_from } == 2)); - object!(ct, Tracked); - object!(t3, Tracked, LvalueRef::bind(ct.as_pointer())); + object!(ct, Tracked::constructor_1()); + object!(t3, Tracked::constructor_2(LvalueRef::bind(ct.as_pointer()))); ({ touch_1((ct.as_pointer())) }); assert!(({ (*ct.borrow()).copied_from } == 2)); let mut before: i32 = copies_0.with(|rc| *rc.borrow()); - object!(der, Derived); - object!(der2, Derived, LvalueRef::bind(der.as_pointer())); + object!(der, Derived::constructor_1()); + object!(der2, Derived, |der2| { + ::copy_constructor( + der2.clone(), + LvalueRef::bind(der.as_pointer()), + ) + }); assert!(({ (*der2.borrow()).c.v } == 20) && (copies_0.with(|rc| *rc.borrow()) == (before + 1))); let mut range: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(vec_.decay().begin())); let __last: Value> = Rc::new(RefCell::new(vec_.decay().end())); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push(>::cpp_from( - __it.borrow().iter_deref(), - )); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind( + __it.borrow().iter_deref(), + ),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((range[0_usize].v == 1) && (copies_0.with(|rc| *rc.borrow()) == (before + 2))); let selfs: Value> = Rc::new(RefCell::new(Vec::new())); @@ -450,16 +495,16 @@ fn main_0() -> i32 { } }); { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - DefaultConstructible::default_constructor(__tmp_1.as_pointer()); + SelfPtr::constructor_1(__tmp_1.as_pointer()); __tmp_1.as_pointer() },) { (__tmp_0,) => MoveConstructible::push_moved(&selfs.as_pointer(), (__tmp_0).clone()), } }; - object!(self_src, SelfPtr); + object!(self_src, SelfPtr::constructor_1()); CopyConstructible::push_copied(&selfs.as_pointer(), self_src.as_pointer()); assert!( ({ { (*selfs.borrow())[0_usize].self_.clone() } } == { (selfs.decay().offset(0_usize)) }) @@ -475,9 +520,9 @@ fn main_0() -> i32 { } }); { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - Counted::construct(__tmp_3.as_pointer(), 30); + Counted::constructor_1(__tmp_3.as_pointer(), 30); __tmp_3.as_pointer() },) { diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index 5c66db8525..99e7082ee2 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Inner { #[offset(0)] @@ -30,7 +32,6 @@ pub struct Inner { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, Memberwise, CopyConstructible, @@ -38,7 +39,9 @@ pub struct Inner { Swappable, )] #[memberwise(copy_assign, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(16)] pub struct Explicit { #[offset(0)] @@ -52,7 +55,7 @@ pub struct Explicit { pub arr: Box<[i32]>, } impl Explicit { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, inner).write(Inner { x: (v * 10) }); field!(this, arr).write(Box::new([v, (v + 1)])); @@ -70,7 +73,9 @@ impl Destructible for Explicit { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Implicit { #[offset(0)] @@ -102,7 +107,6 @@ impl Default for Implicit { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, CopyConstructible, @@ -110,19 +114,20 @@ impl Default for Implicit { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct DefaultCopyUserMove { #[offset(0)] pub v: i32, } impl DefaultCopyUserMove { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl MoveConstructible for DefaultCopyUserMove { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); @@ -141,26 +146,26 @@ impl MoveAssignable for DefaultCopyUserMove { ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct UserCopyDefaultMove { #[offset(0)] pub v: i32, } impl UserCopyDefaultMove { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for UserCopyDefaultMove { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); } @@ -176,17 +181,12 @@ impl CopyAssignable for UserCopyDefaultMove { } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Swappable, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] #[byte_size(64)] pub struct Buffer { #[offset(0)] @@ -203,7 +203,7 @@ pub struct Buffer { pub arr: Box<[i32]>, } impl Buffer { - pub fn construct(this: Ptr, n: i32) { + pub fn constructor_1(this: Ptr, n: i32) { let n: Value = Rc::new(RefCell::new(n)); field!(this, data).write( (0..({ ((*n.borrow()) as usize) })) @@ -226,6 +226,9 @@ impl Default for Buffer { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct Owner { #[offset(0)] @@ -241,8 +244,8 @@ pub struct Owner { #[byte_size(8)] pub p: Option>, } -impl DefaultConstructible for Owner { - fn default_constructor(this: Ptr) { +impl Owner { + pub fn constructor_1(this: Ptr) { field!(this, data).write(Vec::new()); field!(this, n).write(0_i32); field!(this, arr).write((0..2).map(|_| 0_i32).collect::>()); @@ -275,29 +278,27 @@ impl Default for Owner { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Copyable { #[offset(0)] #[byte_size(24)] pub data: Vec, } -impl DefaultConstructible for Copyable { - fn default_constructor(this: Ptr) { +impl Copyable { + pub fn constructor_1(this: Ptr) { field!(this, data).write(Vec::new()); } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Swappable, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] #[byte_size(32)] pub struct Holder { #[offset(0)] @@ -312,9 +313,9 @@ pub struct Holder { pub p: Option>, } impl Holder { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, inner).write(Inner { x: v }); - Explicit::construct(field_ptr!(this, e), v); + Explicit::constructor_1(field_ptr!(this, e), v); field!(this, p).write(None); } } @@ -324,13 +325,19 @@ pub fn same_0(a: Ptr, b: Ptr) -> bool { && ({ (array_elem!(a, arr, 0).read()) } == { (array_elem!(b, arr, 0).read()) })) && ({ (array_elem!(a, arr, 1).read()) } == { (array_elem!(b, arr, 1).read()) }); } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct SeesThis { #[offset(0)] #[byte_size(8)] pub self_: Ptr, } +impl SeesThis { + pub fn constructor_1(this: Ptr) { + field!(this, self_).write(Ptr::::null()); + } +} impl CopyAssignable for SeesThis { fn copy_assign(this: Ptr, _a0: LvalueRef>) -> Ptr { let _a0 = _a0.as_pointer(); @@ -345,11 +352,6 @@ impl MoveAssignable for SeesThis { return (this).clone(); } } -impl DefaultConstructible for SeesThis { - fn default_constructor(this: Ptr) { - field!(this, self_).write(Ptr::::null()); - } -} impl Default for SeesThis { fn default() -> Self { { @@ -361,6 +363,8 @@ impl Default for SeesThis { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Default)] #[memberwise(copy_assign, move_assign)] +#[derive(Conversions)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct HasSeesThis { #[offset(0)] @@ -370,13 +374,16 @@ pub struct HasSeesThis { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for HasSeesThis { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, s)); +impl HasSeesThis { + pub fn constructor_1(this: Ptr) { + SeesThis::constructor_1(field_ptr!(this, s)); field!(this, v).write(Vec::new()); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(8)] pub struct Counted_int_ { #[offset(0)] @@ -384,14 +391,12 @@ pub struct Counted_int_ { #[offset(4)] pub moves: i32, } -impl DefaultConstructible for Counted_int_ { - fn default_constructor(this: Ptr) { +impl Counted_int_ { + pub fn constructor_1(this: Ptr) { field!(this, v).write(0_i32); field!(this, moves).write(0); } -} -impl MoveConstructible for Counted_int_ { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_2(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -414,6 +419,9 @@ impl Default for Counted_int_ { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct HasCounted { #[offset(0)] @@ -423,14 +431,18 @@ pub struct HasCounted { #[byte_size(24)] pub w: Vec, } -impl DefaultConstructible for HasCounted { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, c)); +impl HasCounted { + pub fn constructor_1(this: Ptr) { + Counted_int_::constructor_1(field_ptr!(this, c)); field!(this, w).write(Vec::new()); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable)] -#[cpp_from(i32, construct_1, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRef>)] +#[constructor(constructor_4, RvalueRef)] #[byte_size(16)] pub struct CtorSeesThis { #[offset(0)] @@ -440,26 +452,20 @@ pub struct CtorSeesThis { pub id: i32, } impl CtorSeesThis { - pub fn construct_1(this: Ptr, mut id: i32) { - DefaultConstructible::default_constructor(this.clone()); - field!(this, id).write(id); - } -} -impl DefaultConstructible for CtorSeesThis { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, self_).write((this).clone()); field!(this, id).write(0); } -} -impl CopyConstructible for CtorSeesThis { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, mut id: i32) { + CtorSeesThis::constructor_1(this.clone()); + field!(this, id).write(id); + } + pub fn constructor_3(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); field!(this, id).write(0); } -} -impl MoveConstructible for CtorSeesThis { - fn move_constructor(this: Ptr, _a0: RvalueRef) { + pub fn constructor_4(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); field!(this, id).write(0); @@ -481,8 +487,9 @@ impl Default for CtorSeesThis { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CtorSeesThis::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -492,6 +499,9 @@ impl Default for CtorSeesThis { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(40)] pub struct HasCtorSeesThis { #[offset(0)] @@ -501,14 +511,17 @@ pub struct HasCtorSeesThis { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for HasCtorSeesThis { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, x)); +impl HasCtorSeesThis { + pub fn constructor_1(this: Ptr) { + CtorSeesThis::constructor_1(field_ptr!(this, x)); field!(this, v).write(Vec::new()); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct InitsCtorSeesThis { #[offset(0)] @@ -518,10 +531,10 @@ pub struct InitsCtorSeesThis { #[byte_size(16)] pub y: CtorSeesThis, } -impl DefaultConstructible for InitsCtorSeesThis { - fn default_constructor(this: Ptr) { - CtorSeesThis::construct_1(field_ptr!(this, x), 1); - CtorSeesThis::construct_1(field_ptr!(this, y), 2); +impl InitsCtorSeesThis { + pub fn constructor_1(this: Ptr) { + CtorSeesThis::constructor_2(field_ptr!(this, x), 1); + CtorSeesThis::constructor_2(field_ptr!(this, y), 2); } } impl Default for InitsCtorSeesThis { @@ -529,8 +542,8 @@ impl Default for InitsCtorSeesThis { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + InitsCtorSeesThis::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -548,6 +561,9 @@ impl Default for InitsCtorSeesThis { Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(24)] pub struct OutOfLineDefaulted { #[offset(0)] @@ -558,22 +574,17 @@ pub struct OutOfLineDefaulted { } impl OutOfLineDefaulted { pub fn construct(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, x)); + CtorSeesThis::constructor_1(field_ptr!(this, x)); field!(this, v).write(1); } -} -impl CopyConstructible for OutOfLineDefaulted { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - CopyConstructible::copy_constructor( - field_ptr!(this, x), - LvalueRef::bind(field_ptr!(_a0, x)), - ); + CtorSeesThis::constructor_3(field_ptr!(this, x), LvalueRef::bind(field_ptr!(_a0, x))); field!(this, v).write(_a0.with(|__s| __s.v)); } } -impl DefaultConstructible for OutOfLineDefaulted { - fn default_constructor(this: Ptr) { +impl Constructor<()> for OutOfLineDefaulted { + fn constructor(this: Ptr, _: ()) { { OutOfLineDefaulted::construct(this.clone()); } @@ -584,7 +595,7 @@ impl Default for OutOfLineDefaulted { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); OutOfLineDefaulted::construct(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -592,7 +603,9 @@ impl Default for OutOfLineDefaulted { } } impl OutOfLineDefaulted {} -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +impl OutOfLineDefaulted {} +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[constructor(constructor_1)] #[byte_size(40)] pub struct OutOfLineAssign { #[offset(0)] @@ -604,9 +617,9 @@ pub struct OutOfLineAssign { #[byte_size(24)] pub w: Vec, } -impl DefaultConstructible for OutOfLineAssign { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, s)); +impl OutOfLineAssign { + pub fn constructor_1(this: Ptr) { + SeesThis::constructor_1(field_ptr!(this, s)); field!(this, v).write(1); field!(this, w).write(Vec::new()); } @@ -654,7 +667,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Explicit(1)); + object!(a, Explicit::constructor_1(1)); let b: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_b = std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); @@ -669,15 +682,15 @@ fn main_0() -> i32 { && ({ same_0(c.as_pointer(), a.as_pointer(),) })) && ({ same_0(d.as_pointer(), a.as_pointer(),) }) ); - object!(e, Explicit(2)); - object!(f, Explicit(3)); + object!(e, Explicit::constructor_1(2)); + object!(f, Explicit::constructor_1(3)); assign!(e = b); assign!(f = RvalueRef(c)); assert!( ({ same_0(e.as_pointer(), b.as_pointer(),) }) && ({ same_0(f.as_pointer(), c.as_pointer(),) }) ); - object!(g, Explicit(4)); + object!(g, Explicit::constructor_1(4)); assign!(g = *assign!(e = f)); assert!( ({ same_0(g.as_pointer(), f.as_pointer(),) }) @@ -702,8 +715,8 @@ fn main_0() -> i32 { let vec_: Value> = Rc::new(RefCell::new(Vec::new())); CopyConstructible::push_copied(&vec_.as_pointer(), b.as_pointer()); match (Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Explicit::construct(__v.as_pointer(), 9); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Explicit::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() })) .as_pointer(),) @@ -711,33 +724,46 @@ fn main_0() -> i32 { (__tmp_1,) => MoveConstructible::push_moved(&vec_.as_pointer(), (__tmp_1).clone()), }; assert!(({ (*vec_.borrow())[0_usize].v } == 1) && ({ (*vec_.borrow())[1_usize].v } == 9)); - object!(m, DefaultCopyUserMove(7)); + object!(m, DefaultCopyUserMove::constructor_1(7)); let m1: Value = Rc::new(RefCell::new((*m.borrow()))); - object!(m2, DefaultCopyUserMove, RvalueRef::bind(m.as_pointer())); + object!( + m2, + DefaultCopyUserMove::constructor_3(RvalueRef::bind(m.as_pointer())) + ); assert!( (({ (*m1.borrow()).v } == 7) && ({ (*m2.borrow()).v } == 7)) && ({ (*m.borrow()).v } == 0) ); - object!(m3, DefaultCopyUserMove(1)); - object!(m4, DefaultCopyUserMove(1)); + object!(m3, DefaultCopyUserMove::constructor_1(1)); + object!(m4, DefaultCopyUserMove::constructor_1(1)); assign!(m3 = m1); assign!(m4 = RvalueRef(m1)); assert!( (({ (*m3.borrow()).v } == 7) && ({ (*m4.borrow()).v } == 7)) && ({ (*m1.borrow()).v } == 0) ); - object!(u, UserCopyDefaultMove(8)); - object!(u1, UserCopyDefaultMove, LvalueRef::bind(u.as_pointer())); - object!(u2, UserCopyDefaultMove, RvalueRef::bind(u.as_pointer())); + object!(u, UserCopyDefaultMove::constructor_1(8)); + object!( + u1, + UserCopyDefaultMove::constructor_2(LvalueRef::bind(u.as_pointer())) + ); + object!(u2, UserCopyDefaultMove, |u2| { + ::move_constructor( + u2.clone(), + RvalueRef::bind(u.as_pointer()), + ) + }); assert!( (({ (*u1.borrow()).v } == 108) && ({ (*u2.borrow()).v } == 8)) && ({ (*u.borrow()).v } == 8) ); - object!(u3, UserCopyDefaultMove(1)); - object!(u4, UserCopyDefaultMove(1)); + object!(u3, UserCopyDefaultMove::constructor_1(1)); + object!(u4, UserCopyDefaultMove::constructor_1(1)); assign!(u3 = u2); assign!(u4 = RvalueRef(u2)); assert!(({ (*u3.borrow()).v } == 108) && ({ (*u4.borrow()).v } == 8)); - object!(p, Buffer(3)); - object!(q, Buffer, RvalueRef::bind(p.as_pointer())); + object!(p, Buffer::constructor_1(3)); + object!(q, Buffer, |q| { + ::move_constructor(q.clone(), RvalueRef::bind(p.as_pointer())) + }); assert!( ({ ((({ (*q.borrow()).n } == 3) && ((*q.borrow()).data.len() == 3_usize)) @@ -745,7 +771,7 @@ fn main_0() -> i32 { && ((*p.borrow()).data.is_empty()) }) ); - object!(r, Buffer(1)); + object!(r, Buffer::constructor_1(1)); assign!(r = RvalueRef(q)); assert!( ({ @@ -772,8 +798,8 @@ fn main_0() -> i32 { { let mut __tmp_2 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ::move_constructor( __v.as_pointer(), RvalueRef::bind(bufs.decay().offset(0_usize)), ); @@ -789,7 +815,7 @@ fn main_0() -> i32 { && ((*bufs.borrow())[0_usize].data.is_empty()) }) ); - object!(o1, Owner); + object!(o1, Owner::constructor_1()); ({ let __tmp_3: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( @@ -801,7 +827,9 @@ fn main_0() -> i32 { array_elem!(o1.as_pointer(), arr, 0).write(5); array_elem!(o1.as_pointer(), arr, 1).write(6); field_ptr!(o1.as_pointer(), p).write(Ptr::alloc(7).to_owned_opt()); - object!(o2, Owner, RvalueRef::bind(o1.as_pointer())); + object!(o2, Owner, |o2| { + ::move_constructor(o2.clone(), RvalueRef::bind(o1.as_pointer())) + }); assert!( ({ ((({ (*o2.borrow()).n } == 5) && ((*o2.borrow()).data.len() == 1_usize)) @@ -815,7 +843,7 @@ fn main_0() -> i32 { && (({ (*o1.borrow()).p.clone() }.as_pointer()).is_null()) }) ); - object!(o3, Owner); + object!(o3, Owner::constructor_1()); assign!(o3 = RvalueRef(o2)); assert!( ((({ (*o3.borrow()).n } == 5) @@ -833,10 +861,15 @@ fn main_0() -> i32 { data: Vec::from([1, 2]), })); let mut c2: Copyable = (*c1.borrow()).clone(); - object!(c3, Copyable, RvalueRef::bind(c1.as_pointer())); + object!(c3, Copyable, |c3| { + ::move_constructor( + c3.clone(), + RvalueRef::bind(c1.as_pointer()), + ) + }); assert!(({ (c2.data.len() == 2_usize) && ((*c3.borrow()).data.len() == 2_usize) })); assert!(({ (*c1.borrow()).data.is_empty() })); - object!(c4, Copyable); + object!(c4, Copyable::constructor_1()); assign!(c4 = RvalueRef(c3)); assert!( ({ @@ -844,15 +877,20 @@ fn main_0() -> i32 { && ((*c3.borrow()).data.is_empty()) }) ); - object!(h1, Holder(4)); + object!(h1, Holder::constructor_1(4)); field_ptr!(h1.as_pointer(), p).write(Ptr::alloc(9).to_owned_opt()); - object!(h2, Holder, RvalueRef::bind(h1.as_pointer())); + object!(h2, Holder, |h2| { + ::move_constructor( + h2.clone(), + RvalueRef::bind(h1.as_pointer()), + ) + }); assert!( ((({ (*h2.borrow()).inner.x } == 4) && ({ (*h2.borrow()).e.v } == 4)) && (({ (*h2.borrow()).p.clone() }.as_pointer().read()) == 9)) && (({ (*h1.borrow()).p.clone() }.as_pointer()).is_null()) ); - object!(h3, Holder(1)); + object!(h3, Holder::constructor_1(1)); assign!(h3 = RvalueRef(h2)); assert!( ((({ (*h3.borrow()).inner.x } == 4) @@ -860,40 +898,58 @@ fn main_0() -> i32 { && (({ (*h3.borrow()).p.clone() }.as_pointer().read()) == 9)) && (({ (*h2.borrow()).p.clone() }.as_pointer()).is_null()) ); - object!(t1, HasSeesThis); - object!(t2, HasSeesThis); - object!(t3, HasSeesThis); + object!(t1, HasSeesThis::constructor_1()); + object!(t2, HasSeesThis::constructor_1()); + object!(t3, HasSeesThis::constructor_1()); assign!(t2 = RvalueRef(t1)); assert!(({ { (*t2.borrow()).s.self_.clone() } } == { (field_ptr!(t2.as_pointer(), s)) })); assign!(t3 = t2); assert!(({ { (*t3.borrow()).s.self_.clone() } } == { (field_ptr!(t3.as_pointer(), s)) })); - object!(k1, HasCounted); - object!(k2, HasCounted, RvalueRef::bind(k1.as_pointer())); + object!(k1, HasCounted::constructor_1()); + object!(k2, HasCounted, |k2| { + ::move_constructor( + k2.clone(), + RvalueRef::bind(k1.as_pointer()), + ) + }); assert!(({ (*k2.borrow()).c.moves } == 1)); - object!(k3, HasCounted); + object!(k3, HasCounted::constructor_1()); assign!(k3 = RvalueRef(k2)); assert!(({ (*k3.borrow()).c.moves } == 2)); { - object!(d, CtorSeesThis); + object!(d, CtorSeesThis::constructor_1()); assert!(({ { (*d.borrow()).self_.clone() } } == { (d.as_pointer()) })); - object!(e, CtorSeesThis, LvalueRef::bind(d.as_pointer())); + object!( + e, + CtorSeesThis::constructor_3(LvalueRef::bind(d.as_pointer())) + ); assert!(({ { (*e.borrow()).self_.clone() } } == { (e.as_pointer()) })); - object!(f, CtorSeesThis::construct_1(3)); + object!(f, CtorSeesThis::constructor_2(3)); assert!( ({ { (*f.borrow()).self_.clone() } } == { (f.as_pointer()) }) && ({ (*f.borrow()).id } == 3) ); - object!(h1, HasCtorSeesThis); + object!(h1, HasCtorSeesThis::constructor_1()); assert!(({ { (*h1.borrow()).x.self_.clone() } } == { (field_ptr!(h1.as_pointer(), x)) })); - object!(h2, HasCtorSeesThis, LvalueRef::bind(h1.as_pointer())); + object!(h2, HasCtorSeesThis, |h2| { + ::copy_constructor( + h2.clone(), + LvalueRef::bind(h1.as_pointer()), + ) + }); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); - object!(h3, HasCtorSeesThis, RvalueRef::bind(h1.as_pointer())); + object!(h3, HasCtorSeesThis, |h3| { + ::move_constructor( + h3.clone(), + RvalueRef::bind(h1.as_pointer()), + ) + }); assert!(({ { (*h3.borrow()).x.self_.clone() } } == { (field_ptr!(h3.as_pointer(), x)) })); assign!(h2 = RvalueRef(h3)); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); assign!(h2 = h1); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); - object!(i, InitsCtorSeesThis); + object!(i, InitsCtorSeesThis::constructor_1()); assert!( ({ { (*i.borrow()).x.self_.clone() } } == { (field_ptr!(i.as_pointer(), x)) }) && ({ (*i.borrow()).x.id } == 1) @@ -904,7 +960,7 @@ fn main_0() -> i32 { ); let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - CtorSeesThis::construct_1(__p.clone(), 4); + CtorSeesThis::constructor_2(__p.clone(), 4); __p }; assert!( @@ -917,14 +973,17 @@ fn main_0() -> i32 { && ({ { (*o1.borrow()).x.self_.clone() } } == { (field_ptr!(o1.as_pointer(), x)) }) ); (*o1.borrow_mut()).v = 2; - object!(o2, OutOfLineDefaulted, LvalueRef::bind(o1.as_pointer())); + object!( + o2, + OutOfLineDefaulted::constructor_2(LvalueRef::bind(o1.as_pointer())) + ); assert!( ({ (*o2.borrow()).v } == 2) && ({ { (*o2.borrow()).x.self_.clone() } } == { (field_ptr!(o2.as_pointer(), x)) }) ); - object!(a1, OutOfLineAssign); - object!(a2, OutOfLineAssign); - object!(a3, OutOfLineAssign); + object!(a1, OutOfLineAssign::constructor_1()); + object!(a2, OutOfLineAssign::constructor_1()); + object!(a3, OutOfLineAssign::constructor_1()); (*a1.borrow_mut()).v = 3; ({ let __tmp_4: Value = Rc::new(RefCell::new(4)); diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index 81abcb51e9..3779e7dc33 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -11,24 +11,24 @@ use std::rc::{Rc, Weak}; ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Swappable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct NoCopy { #[offset(0)] pub v: i32, } impl NoCopy { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl MoveConstructible for NoCopy { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); @@ -42,19 +42,20 @@ impl MoveAssignable for NoCopy { return (this).clone(); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_2)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct PrivateCopy { #[offset(0)] pub v: i32, } -impl DefaultConstructible for PrivateCopy { - fn default_constructor(this: Ptr) { +impl PrivateCopy { + pub fn constructor_2(this: Ptr) { field!(this, v).write(0); } -} -impl MoveConstructible for PrivateCopy { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); @@ -72,21 +73,23 @@ impl Default for PrivateCopy { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + PrivateCopy::constructor_2(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Immovable { #[offset(0)] pub v: i32, } -impl DefaultConstructible for Immovable { - fn default_constructor(this: Ptr) { +impl Immovable { + pub fn constructor_1(this: Ptr) { field!(this, v).write(0); } } @@ -94,8 +97,8 @@ impl Default for Immovable { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Immovable::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -112,6 +115,8 @@ impl Default for Immovable { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] #[byte_size(8)] pub struct Container { #[offset(0)] @@ -120,18 +125,22 @@ pub struct Container { #[offset(4)] pub tag: i32, } +impl Container {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct VecHolder { #[offset(0)] #[byte_size(24)] pub items: Vec, } -impl DefaultConstructible for VecHolder { - fn default_constructor(this: Ptr) { +impl VecHolder { + pub fn constructor_1(this: Ptr) { field!(this, items).write(Vec::new()); } } @@ -146,39 +155,52 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, NoCopy(1)); - object!(b, NoCopy, RvalueRef::bind(a.as_pointer())); + object!(a, NoCopy::constructor_1(1)); + object!(b, NoCopy::constructor_3(RvalueRef::bind(a.as_pointer()))); assert!(({ (*b.borrow()).v } == 1) && ({ (*a.borrow()).v } == 0)); assign!(a = RvalueRef(b)); assert!(({ (*a.borrow()).v } == 1) && ({ (*b.borrow()).v } == 0)); ({ bump_0((a.as_pointer())) }); assert!(({ (*a.borrow()).v } == 2)); - object!(p, PrivateCopy); + object!(p, PrivateCopy::constructor_2()); (*p.borrow_mut()).v = 3; - object!(q, PrivateCopy, RvalueRef::bind(p.as_pointer())); + object!( + q, + PrivateCopy::constructor_3(RvalueRef::bind(p.as_pointer())) + ); assert!(({ (*q.borrow()).v } == 3) && ({ (*p.borrow()).v } == 0)); assign!(p = RvalueRef(q)); assert!(({ (*p.borrow()).v } == 3) && ({ (*q.borrow()).v } == 0)); - object!(im, Immovable); + object!(im, Immovable::constructor_1()); (*im.borrow_mut()).v = 4; ({ bump_ref_1(im.as_pointer()) }); let mut pim: Ptr = (im.as_pointer()); assert!((pim.with(|__s| __s.v) == 5)); let c: Value = Rc::new(RefCell::new(Container { inner: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoCopy::construct(__v.as_pointer(), 6); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NoCopy::constructor_1(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, tag: 7, })); - object!(d, Container, RvalueRef::bind(c.as_pointer())); + object!(d, Container, |d| { + ::move_constructor( + d.clone(), + RvalueRef::bind(c.as_pointer()), + ) + }); assert!( (({ (*d.borrow()).inner.v } == 6) && ({ (*d.borrow()).tag } == 7)) && ({ (*c.borrow()).inner.v } == 0) ); - object!(h, VecHolder); - object!(h2, VecHolder, RvalueRef::bind(h.as_pointer())); + object!(h, VecHolder::constructor_1()); + object!(h2, VecHolder, |h2| { + ::move_constructor( + h2.clone(), + RvalueRef::bind(h.as_pointer()), + ) + }); assert!(({ ((*h2.borrow()).items.len() == 0_usize) })); return 0; } @@ -187,8 +209,8 @@ impl CopyAssignable for PrivateCopy { unreachable!("PrivateCopy::copy_assign is never defined") } } -impl CopyConstructible for PrivateCopy { - fn copy_constructor(this: Ptr, _: LvalueRef>) { +impl Constructor<(LvalueRef>,)> for PrivateCopy { + fn constructor(this: Ptr, _: (LvalueRef>,)) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/refcount/default.rs b/tests/unit/out/refcount/default.rs index f11e1d2ebc..6f657c55a8 100644 --- a/tests/unit/out/refcount/default.rs +++ b/tests/unit/out/refcount/default.rs @@ -15,7 +15,9 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(144)] pub struct Pointers { #[offset(0)] @@ -61,7 +63,9 @@ impl Default for Pointers { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(440)] pub struct SmallArrays { #[offset(0)] @@ -105,7 +109,9 @@ impl Default for SmallArrays { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[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 4ea07b2fa9..ed9a024b22 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -13,23 +13,32 @@ pub fn baz_1(mut a: Ptr, mut b: Ptr) -> bool { return ({ a } == { b }); } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, TriviallyCopyable, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Bar { #[offset(0)] pub v: i32, } impl Bar { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } } -impl DefaultConstructible for Bar { - fn default_constructor(this: Ptr) { +impl Constructor<()> for Bar { + fn constructor(this: Ptr, _: ()) { { - Bar::construct(this.clone(), 1); + Bar::constructor_1(this.clone(), 1); } } } @@ -37,8 +46,8 @@ impl Default for Bar { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Bar::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -58,8 +67,8 @@ pub fn by_ref_5(b: Ptr) -> i32 { } thread_local!( pub static global_bar_6: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Bar::construct(__v.as_pointer(), 9); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -83,14 +92,17 @@ pub fn first_9(r: Ptr) -> i32 { DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, i32)] #[byte_size(4)] pub struct Holder_int_ { #[offset(0)] pub v: i32, } impl Holder_int_ { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } } @@ -104,13 +116,13 @@ fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(0)); assert!(((({ baz_1((a.as_pointer()), Ptr::::null(),) }) as i32) == (false as i32))); assert!(((({ baz_1((a.as_pointer()), (a.as_pointer()),) }) as i32) == (true as i32))); - object!(b, Bar(1)); + object!(b, Bar::constructor_1(1)); assert!(({ (*b.borrow()).v } == 1)); { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); assert!( ({ - Bar::construct(__tmp_0.as_pointer(), 2); + Bar::constructor_1(__tmp_0.as_pointer(), 2); __tmp_0.as_pointer() } .with(|__s| __s.v) @@ -119,18 +131,18 @@ fn main_0() -> i32 { }; let mut arr: [Bar; 3] = [ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Bar::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Bar::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Bar::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]; @@ -142,27 +154,27 @@ fn main_0() -> i32 { assert!((counter_2.with(|rc| *rc.borrow()) == 1)); assert!( (({ - let _b: Value = Rc::new(RefCell::new(::zero_init())); - Bar::construct(_b.as_pointer(), 7); + let _b: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(_b.as_pointer(), 7); by_ref_5(_b.as_pointer()) }) == 7) ); assert!( (({ - let _b: Value = Rc::new(RefCell::new(::zero_init())); - Bar::construct(_b.as_pointer(), 3); + let _b: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(_b.as_pointer(), 3); by_ref_5(_b.as_pointer()) }) == 3) ); assert!((({ by_global_ref_7(global_bar_6.with(|v| v.as_pointer()),) }) == 9)); assert!( (({ - let _b: Value = Rc::new(RefCell::new(::zero_init())); - Bar::construct(_b.as_pointer(), 4); + let _b: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(_b.as_pointer(), 4); by_global_ref_7(_b.as_pointer()) }) == 4) ); - object!(h, Holder_int_(4)); + object!(h, Holder_int_::constructor_1(4)); assert!(({ (*h.borrow()).v } == 4)); assert!((({ shifted_8(3, -1_i32,) }) == 2)); assert!((({ shifted_8(3, 4,) }) == 7)); diff --git a/tests/unit/out/refcount/default_in_statics.rs b/tests/unit/out/refcount/default_in_statics.rs index b97707734c..53c1045bd0 100644 --- a/tests/unit/out/refcount/default_in_statics.rs +++ b/tests/unit/out/refcount/default_in_statics.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Inner { #[offset(0)] @@ -34,7 +36,9 @@ pub struct Inner { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(88)] pub struct Outer { #[offset(0)] @@ -90,7 +94,9 @@ impl Default for Outer { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 423d58b630..38119de0d4 100644 --- a/tests/unit/out/refcount/delete_array_order.rs +++ b/tests/unit/out/refcount/delete_array_order.rs @@ -19,6 +19,8 @@ use std::rc::{Rc, Weak}; Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[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 76fed90ce0..bc17b6fa88 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -22,6 +22,8 @@ thread_local!( Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(1)] pub struct S {} impl Destructible for S { @@ -43,6 +45,8 @@ impl Destructible for S { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(1)] pub struct Defaulted { #[offset(0)] @@ -65,6 +69,8 @@ pub struct Defaulted { Swappable, )] #[memberwise(move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(1)] pub struct Middle { #[offset(0)] @@ -87,6 +93,8 @@ pub struct Middle { Swappable, )] #[memberwise(copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(1)] pub struct Outer { #[offset(0)] @@ -109,6 +117,8 @@ pub struct Outer { Swappable, )] #[memberwise(move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(3)] pub struct ArrayMember { #[offset(0)] @@ -130,6 +140,8 @@ pub struct ArrayMember { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(1)] pub struct EmptyBody { #[offset(0)] @@ -154,6 +166,8 @@ impl Destructible for EmptyBody { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(1)] pub struct Templated_char_ { #[offset(0)] @@ -182,6 +196,8 @@ impl Destructible for Templated_char_ { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct Templated_int_ { #[offset(0)] @@ -210,6 +226,8 @@ impl Destructible for Templated_int_ { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct Copied { #[offset(0)] @@ -240,6 +258,8 @@ thread_local!( Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct Tagged { #[offset(0)] @@ -267,6 +287,8 @@ impl Destructible for Tagged { Swappable, )] #[memberwise(move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[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 519779ad0d..b791c8fdae 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -25,6 +25,8 @@ thread_local!( Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -36,11 +38,13 @@ impl Destructible for S { last_1.with(|rc| *rc.borrow_mut() = this.with(|__s| __s.v)); } } -pub fn by_value_2(s: Ptr) -> i32 { +pub fn by_value_2(s: ParameterObject) -> i32 { + let s = s.as_pointer(); assert!((destroyed_0.with(|rc| *rc.borrow()) == 0)); return s.with(|__s| __s.v); } -pub fn with_default_3(s: Ptr) -> i32 { +pub fn with_default_3(s: ParameterObject) -> i32 { + let s = s.as_pointer(); return s.with(|__s| __s.v); } #[derive( @@ -54,17 +58,22 @@ pub fn with_default_3(s: Ptr) -> i32 { DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, ParameterObject)] #[byte_size(4)] pub struct Holder { #[offset(0)] pub v: i32, } impl Holder { - pub fn construct(this: Ptr, s: Ptr) { + pub fn constructor_1(this: Ptr, s: ParameterObject) { + let s = s.as_pointer(); field!(this, v).write(s.with(|__s| __s.v)); } - pub fn add(this: Ptr, s: Ptr) -> i32 { + pub fn add(this: Ptr, s: ParameterObject) -> i32 { + let s = s.as_pointer(); return (this.with(|__s| __s.v) + s.with(|__s| __s.v)); } } @@ -81,7 +90,7 @@ fn main_0() -> i32 { ({ (({ let _s: Value = Rc::new(RefCell::new((*s.borrow()).clone())); - by_value_2(_s.as_pointer()) + by_value_2(ParameterObject::bind(_s.as_pointer())) }) == 1) }) ); @@ -94,7 +103,7 @@ fn main_0() -> i32 { assert!( (({ let _s: Value = Rc::new(RefCell::new(S { v: 2 })); - by_value_2(_s.as_pointer()) + by_value_2(ParameterObject::bind(_s.as_pointer())) }) == 2) ); assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 2)); @@ -102,7 +111,7 @@ fn main_0() -> i32 { assert!( (({ let _s: Value = Rc::new(RefCell::new(S { v: 5 })); - with_default_3(_s.as_pointer()) + with_default_3(ParameterObject::bind(_s.as_pointer())) }) == 5) ); assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 5)); @@ -110,7 +119,7 @@ fn main_0() -> i32 { { object!(h, Holder, |h| { let __tmp_0: Value = Rc::new(RefCell::new(S { v: 3 })); - Holder::construct(h.clone(), __tmp_0.as_pointer()) + Holder::constructor_1(h.clone(), ParameterObject::bind(__tmp_0.as_pointer())) }); assert!( (destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 3) @@ -118,7 +127,7 @@ fn main_0() -> i32 { assert!( (({ let _s: Value = Rc::new(RefCell::new(S { v: 4 })); - Holder::add(h.as_pointer(), _s.as_pointer()) + Holder::add(h.as_pointer(), ParameterObject::bind(_s.as_pointer())) }) == 7) ); assert!( diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index 2c30e3fc3c..191cf428b5 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -25,6 +25,8 @@ thread_local!( Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -56,6 +58,8 @@ impl Destructible for S { Swappable, )] #[memberwise(move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct Outer { #[offset(0)] @@ -89,19 +93,19 @@ pub fn main() { } fn main_0() -> i32 { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&__v.as_pointer()), 1) }); }; assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 1)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); &({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&__v.as_pointer()), 2) }); }); assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 2)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); let mut x: i32 = { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); { ({ make_2(Ptr::clone(&__tmp_0.as_pointer()), 3) }); __tmp_0.as_pointer() @@ -114,7 +118,7 @@ fn main_0() -> i32 { ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); x = ({ S::get({ ({ make_2(Ptr::clone(&__tmp_1.as_pointer()), 4) }); @@ -128,7 +132,7 @@ fn main_0() -> i32 { ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); { - let __tmp_2: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_2: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); x = { ({ make_outer_3(Ptr::clone(&__tmp_2.as_pointer())) }); __tmp_2.as_pointer() @@ -144,7 +148,7 @@ fn main_0() -> i32 { assert!((x == 5) && (destroyed_0.with(|rc| *rc.borrow()) == 1)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); x = ({ - let _s: Value = Rc::new(RefCell::new(::zero_init())); + let _s: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&_s.as_pointer()), 6) }); use_4(_s.as_pointer()) }); @@ -165,7 +169,7 @@ fn main_0() -> i32 { x = { (if (x == 3) { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&__v.as_pointer()), 9) }); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -180,7 +184,7 @@ fn main_0() -> i32 { ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&__tmp_3.as_pointer()), 11) }); let r: Ptr = __tmp_3.as_pointer(); assert!((destroyed_0.with(|rc| *rc.borrow()) == 0) && (r.with(|__s| __s.v) == 11)); @@ -192,7 +196,7 @@ fn main_0() -> i32 { let _dtor_s = std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); ({ - let _arg0: Value = Rc::new(RefCell::new(::zero_init())); + let _arg0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&_arg0.as_pointer()), 13) }); assign!(s = _arg0) }); diff --git a/tests/unit/out/refcount/doubly_linked_list.rs b/tests/unit/out/refcount/doubly_linked_list.rs index b11c88a210..e9a847d3d9 100644 --- a/tests/unit/out/refcount/doubly_linked_list.rs +++ b/tests/unit/out/refcount/doubly_linked_list.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(24)] pub struct Node { #[offset(0)] diff --git a/tests/unit/out/refcount/emplace_receiver_alias.rs b/tests/unit/out/refcount/emplace_receiver_alias.rs index 8562a87dd6..7fc1217ace 100644 --- a/tests/unit/out/refcount/emplace_receiver_alias.rs +++ b/tests/unit/out/refcount/emplace_receiver_alias.rs @@ -30,17 +30,22 @@ fn main_0() -> i32 { let mut __tmp_0 = { ({ select_rows_0((alias).clone(), (calls.as_pointer())) }) }; let mut __tmp_1 = { { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new((alias).decay().offset(0_usize).decay())); let __last: Value> = Rc::new(RefCell::new( (alias).decay().offset(0_usize).decay().offset((3) as isize), )); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push((__it.borrow().iter_deref().read())); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; __tmp_0.with_mut(|__v: &mut Vec>| __v.push(__tmp_1)) diff --git a/tests/unit/out/refcount/emplace_receiver_order.rs b/tests/unit/out/refcount/emplace_receiver_order.rs index 78a71cd0ac..cb369b1ee9 100644 --- a/tests/unit/out/refcount/emplace_receiver_order.rs +++ b/tests/unit/out/refcount/emplace_receiver_order.rs @@ -37,7 +37,7 @@ fn main_0() -> i32 { { let mut __tmp_0 = { { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(rows.decay().offset(0_usize).decay())); let __last: Value> = Rc::new(RefCell::new( @@ -45,10 +45,15 @@ fn main_0() -> i32 { )); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push((__it.borrow().iter_deref().read())); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; receiver.with_mut(|__v: &mut Vec>| __v.push(__tmp_0)) @@ -59,7 +64,7 @@ fn main_0() -> i32 { { ({ select_rows_0((rows.as_pointer()), (calls.as_pointer())) }) }; let mut __tmp_2 = { { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(rows.decay().offset(0_usize).decay())); let __last: Value> = Rc::new(RefCell::new( @@ -67,10 +72,15 @@ fn main_0() -> i32 { )); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push((__it.borrow().iter_deref().read())); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; __tmp_1.with_mut(|__v: &mut Vec>| __v.push(__tmp_2)) diff --git a/tests/unit/out/refcount/enum_int_interop.rs b/tests/unit/out/refcount/enum_int_interop.rs index 50af878240..3c053eb092 100644 --- a/tests/unit/out/refcount/enum_int_interop.rs +++ b/tests/unit/out/refcount/enum_int_interop.rs @@ -29,7 +29,9 @@ pub const Tag_TAG_TWO: Tag = 2; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 fa3c78775e..2db50121d3 100644 --- a/tests/unit/out/refcount/enum_underlying_type.rs +++ b/tests/unit/out/refcount/enum_underlying_type.rs @@ -25,14 +25,26 @@ 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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(1)] pub struct HoldsEmpty { #[offset(0)] pub e: Empty, } -impl DefaultConstructible for HoldsEmpty { - fn default_constructor(this: Ptr) { +impl HoldsEmpty { + pub fn constructor_1(this: Ptr) { field!(this, e).write(::default()); } } @@ -76,7 +88,7 @@ fn main_0() -> i32 { let mut sc: Scoped = Scoped_NEG; assert!(((sc as i32) == -2_i32)); assert!((((Scoped_POS as i8) as i32) == 2)); - object!(he, HoldsEmpty); + object!(he, HoldsEmpty::constructor_1()); assert!(!({ (*he.borrow()).e })); let mut ev: Empty = ::default(); assert!(((ev as i32) == ({ (*he.borrow()).e } as i32))); diff --git a/tests/unit/out/refcount/exprs.rs b/tests/unit/out/refcount/exprs.rs index 7d400a4dd7..bfc3ccee0f 100644 --- a/tests/unit/out/refcount/exprs.rs +++ b/tests/unit/out/refcount/exprs.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct X { #[offset(0)] @@ -33,7 +35,9 @@ pub struct X { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 55acde50d1..e83258f355 100644 --- a/tests/unit/out/refcount/fft.rs +++ b/tests/unit/out/refcount/fft.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Complex { #[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 810952eb44..586d4d520c 100644 --- a/tests/unit/out/refcount/field_array_elem_ptr.rs +++ b/tests/unit/out/refcount/field_array_elem_ptr.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -34,7 +36,9 @@ pub struct Point { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[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 b2b7935a1e..b2f2329ea7 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Counter { #[offset(0)] @@ -56,6 +58,9 @@ impl Counter { Swappable, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(40)] pub struct S { #[offset(0)] @@ -75,9 +80,7 @@ impl S { pub fn bump(this: Ptr) { ({ Counter::add(field_ptr!(this, c), this.with(|__s| __s.tag)) }); } -} -impl DefaultConstructible for S { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, tag).write(0_i32); field!(this, c).write(::default()); field!(this, arr).write( diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index 3ec270e01d..b4007c4652 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -15,7 +15,9 @@ use std::rc::{Rc, Weak}; FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(12)] pub struct Inner { #[offset(0)] @@ -46,7 +48,9 @@ impl Default for Inner { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Header { #[offset(0)] @@ -67,6 +71,9 @@ pub struct Header { Swappable, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(104)] pub struct Outer { #[offset(0)] @@ -102,9 +109,7 @@ impl Outer { MoveConstructible::push_moved(&field_ref!(this, v).as_pointer(), __tmp_0.as_pointer()) }); } -} -impl DefaultConstructible for Outer { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, x).write(0_i32); field!(this, inner).write(::default()); field!(this, items).write((0..3).map(|_| ::default()).collect::>()); diff --git a/tests/unit/out/refcount/field_pointers_malloced_struct.rs b/tests/unit/out/refcount/field_pointers_malloced_struct.rs index 351fee566e..6fd9214c78 100644 --- a/tests/unit/out/refcount/field_pointers_malloced_struct.rs +++ b/tests/unit/out/refcount/field_pointers_malloced_struct.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(12)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index e0982d9a88..f665062c8d 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct P { #[offset(0)] diff --git a/tests/unit/out/refcount/fn_ptr.rs b/tests/unit/out/refcount/fn_ptr.rs index a9a103042f..de9aea0872 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -35,12 +35,12 @@ pub fn identity_hash_6(mut v: bool) -> usize { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(FnPtr u64 > , construct, ptr)] +#[conversions(copy, move)] #[byte_size(8)] pub struct HashHolder_unsigned_long__ptr__bool__ { #[offset(0)] @@ -48,7 +48,8 @@ pub struct HashHolder_unsigned_long__ptr__bool__ { pub h: FnPtr u64>, } impl HashHolder_unsigned_long__ptr__bool__ { - pub fn construct(this: Ptr, h: Ptr u64>>) { + pub fn constructor_1(this: Ptr, h: LvalueRef u64>>>) { + let h = h.as_pointer(); field!(this, h).write((h.read())); } } @@ -100,7 +101,10 @@ fn main_0() -> i32 { let __tmp_0: Value u64>> = Rc::new(RefCell::new( (FnPtr:: usize>::new(identity_hash_6)).cast:: u64>(), )); - HashHolder_unsigned_long__ptr__bool__::construct(hh.clone(), __tmp_0.as_pointer()) + HashHolder_unsigned_long__ptr__bool__::constructor_1( + hh.clone(), + LvalueRef::bind(__tmp_0.as_pointer()), + ) }); assert!((({ { (*hh.borrow()).h.clone() }.call(true,) }) == 1_u64)); let mut handler: FnPtr = FnPtr::::new(add_to_total_8); diff --git a/tests/unit/out/refcount/fn_ptr_cast.rs b/tests/unit/out/refcount/fn_ptr_cast.rs index 5a0f58991f..6c7a6e4834 100644 --- a/tests/unit/out/refcount/fn_ptr_cast.rs +++ b/tests/unit/out/refcount/fn_ptr_cast.rs @@ -34,7 +34,9 @@ pub fn test_double_cast_2() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 cd140b5183..7e8ac3b925 100644 --- a/tests/unit/out/refcount/fn_ptr_stable_sort.rs +++ b/tests/unit/out/refcount/fn_ptr_stable_sort.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 6c6ee7cbbc..22c991bf97 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Handler { #[offset(0)] @@ -42,7 +44,9 @@ pub fn negate_1(mut x: i32) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct S {} impl S { @@ -57,35 +61,36 @@ impl S { } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub data_: i32, } impl MoveOnly { - pub fn construct(this: Ptr, mut data: i32) { + pub fn constructor_1(this: Ptr, mut data: i32) { field!(this, data_).write(data); } - pub fn get(this: Ptr) -> i32 { - return this.with(|__s| __s.data_); - } -} -impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, x: RvalueRef) { + pub fn constructor_2(this: Ptr, x: RvalueRef) { let x = x.as_pointer(); field!(this, data_).write(x.with(|__s| __s.data_)); field!(x, data_).write(0); } + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.data_); + } } pub fn make_move_only_2(__return: Ptr) { - MoveOnly::construct(__return.clone(), 4); + MoveOnly::constructor_1(__return.clone(), 4); return; } -pub fn scale_move_only_3(__return: Ptr, x: Ptr) { - MoveOnly::construct(__return.clone(), (({ MoveOnly::get((x).clone()) }) * 10)); +pub fn scale_move_only_3(__return: Ptr, x: ParameterObject) { + let x = x.as_pointer(); + MoveOnly::constructor_1(__return.clone(), (({ MoveOnly::get((x).clone()) }) * 10)); return; } pub fn main() { @@ -120,12 +125,15 @@ fn main_0() -> i32 { let mut mk: FnPtr)> = FnPtr::)>::new(make_move_only_2); object!(m, MoveOnly, |m| ({ mk.call(Ptr::clone(&m.clone()),) })); assert!((({ MoveOnly::get(m.as_pointer(),) }) == 4)); - let mut sc: FnPtr, Ptr)> = - FnPtr::, Ptr)>::new(scale_move_only_3); + let mut sc: FnPtr, ParameterObject)> = + FnPtr::, ParameterObject)>::new(scale_move_only_3); object!(n, MoveOnly, |n| ({ - let _arg0: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(_arg0.as_pointer(), RvalueRef::bind(m.as_pointer())); - sc.call(Ptr::clone(&n.clone()), _arg0.as_pointer()) + let _arg0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_2(_arg0.as_pointer(), RvalueRef::bind(m.as_pointer())); + sc.call( + Ptr::clone(&n.clone()), + ParameterObject::bind(_arg0.as_pointer()), + ) })); assert!((({ MoveOnly::get(n.as_pointer(),) }) == 40)); assert!((({ MoveOnly::get(m.as_pointer(),) }) == 0)); diff --git a/tests/unit/out/refcount/fn_ptr_vtable.rs b/tests/unit/out/refcount/fn_ptr_vtable.rs index d7b6cf703b..3c29459b04 100644 --- a/tests/unit/out/refcount/fn_ptr_vtable.rs +++ b/tests/unit/out/refcount/fn_ptr_vtable.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 5abd8b284b..d73522be9b 100644 --- a/tests/unit/out/refcount/fn_ref.rs +++ b/tests/unit/out/refcount/fn_ref.rs @@ -31,7 +31,9 @@ pub fn call_forwarded_4(f: FnPtr i32>, mut x: i32) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 10ab5ac542..a975aa7a93 100644 --- a/tests/unit/out/refcount/for_body_destructor.rs +++ b/tests/unit/out/refcount/for_body_destructor.rs @@ -19,6 +19,9 @@ use std::rc::{Rc, Weak}; Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[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 e955dbad8d..ab3ac134d4 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -20,6 +20,9 @@ use std::rc::{Rc, Weak}; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct S { #[offset(0)] @@ -28,8 +31,8 @@ pub struct S { #[offset(24)] pub a: i32, } -impl DefaultConstructible for S { - fn default_constructor(this: Ptr) { +impl S { + pub fn constructor_1(this: Ptr) { field!(this, v).write(Vec::new()); field!(this, a).write(0_i32); } @@ -39,7 +42,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S); + object!(s, S::constructor_1()); ({ let __tmp_0: Value = Rc::new(RefCell::new(1)); MoveConstructible::push_moved( diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index c12b3aa9e3..9102d7ef1b 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -10,9 +10,12 @@ pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -23,22 +26,18 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); 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: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); @@ -53,34 +52,32 @@ pub fn chosen_overload_1(_a0: Ptr) -> Overload { return Overload_kRvalueOverload; } impl Holder { - pub fn construct_1(this: Ptr, x: Ptr) { - CopyConstructible::copy_constructor(field_ptr!(this, t), LvalueRef::bind((x).clone())); + pub fn constructor_1_1(this: Ptr, x: LvalueRef) { + let x = x.as_pointer(); + Tracked::constructor_2(field_ptr!(this, t), LvalueRef::bind((x).clone())); } } impl Holder { - pub fn construct_2(this: Ptr, x: Ptr) { - MoveConstructible::move_constructor(field_ptr!(this, t), RvalueRef::bind((x).clone())); + pub fn constructor_1_2(this: Ptr, x: RvalueRef) { + let x = x.as_pointer(); + Tracked::constructor_3(field_ptr!(this, t), RvalueRef::bind((x).clone())); } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(copy_constructor, move_constructor)] -#[cpp_from(Tracked, construct_1, mut_ptr)] -#[cpp_from_move(Tracked, construct_2, ptr)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1_1, LvalueRef)] +#[constructor(constructor_1_2, RvalueRef)] #[byte_size(12)] pub struct Holder { #[offset(0)] #[byte_size(12)] pub t: Tracked, } +impl Holder {} pub fn forward_once_2(x: Ptr) -> Overload { return ({ chosen_overload_0((x).clone()) }); } @@ -94,11 +91,11 @@ pub fn forward_twice_5(x: Ptr) -> Overload { return ({ forward_once_3((x).clone()) }); } pub fn forward_into_ctor_6(__return: Ptr, x: Ptr) { - Holder::construct_1(__return.clone(), (x).clone()); + Holder::constructor_1_1(__return.clone(), LvalueRef::bind((x).clone())); return; } pub fn forward_into_ctor_7(__return: Ptr, x: Ptr) { - Holder::construct_2(__return.clone(), (x).clone()); + Holder::constructor_1_2(__return.clone(), RvalueRef::bind((x).clone())); return; } pub fn main() { @@ -106,20 +103,20 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(lvalue, Tracked(7)); + object!(lvalue, Tracked::constructor_1(7)); assert!( ((({ forward_once_2(lvalue.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(({ (*lvalue.borrow()).v } == 7)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_x.as_pointer(), 8); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 8); forward_once_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(relayed, Tracked(9)); + object!(relayed, Tracked::constructor_1(9)); assert!( ((({ forward_twice_4(relayed.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -127,13 +124,13 @@ fn main_0() -> i32 { assert!(({ (*relayed.borrow()).v } == 9)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_x.as_pointer(), 10); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 10); forward_twice_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(kept, Tracked(11)); + object!(kept, Tracked::constructor_1(11)); object!(from_lvalue, Holder, |from_lvalue| ({ forward_into_ctor_6(Ptr::clone(&from_lvalue.clone()), kept.as_pointer()) })); @@ -142,8 +139,8 @@ fn main_0() -> i32 { assert!(({ (*from_lvalue.borrow()).t.moves } == 0)); assert!(({ (*kept.borrow()).v } == 11)); object!(from_rvalue, Holder, |from_rvalue| ({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_x.as_pointer(), 12); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 12); forward_into_ctor_7(Ptr::clone(&from_rvalue.clone()), _x.as_pointer()) })); assert!(({ (*from_rvalue.borrow()).t.v } == 12)); diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index 152965ba21..75903e0673 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -10,9 +10,12 @@ pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -23,22 +26,18 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); 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: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); @@ -74,7 +73,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Tracked(3)); + object!(a, Tracked::constructor_1(3)); assert!( ((({ forward_by_decltype_2(a.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -82,13 +81,13 @@ fn main_0() -> i32 { assert!(({ (*a.borrow()).v } == 3)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_x.as_pointer(), 4); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 4); forward_by_decltype_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(b, Tracked(5)); + object!(b, Tracked::constructor_1(5)); assert!( ((({ forward_abbreviated_4(b.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -96,17 +95,17 @@ fn main_0() -> i32 { assert!(({ (*b.borrow()).v } == 5)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_x.as_pointer(), 6); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 6); forward_abbreviated_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(c, Tracked(7)); + object!(c, Tracked::constructor_1(7)); assert!( (({ - let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_args_1.as_pointer(), 8); + let _args_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args_1.as_pointer(), 8); forward_abbreviated_pack_6(c.as_pointer(), _args_1.as_pointer()) }) == ((Overload_kLvalueOverload as i32) + (Overload_kRvalueOverload as i32))) ); diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index d448573954..3d55c011d1 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -12,9 +12,12 @@ pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -25,22 +28,18 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); 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: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); @@ -60,8 +59,9 @@ pub fn chosen_overload_2(_a0: Ptr) -> Overload { pub fn chosen_overload_3(_a0: Ptr) -> Overload { return Overload_kIntRvalueOverload; } -pub fn copy_or_move_into_param_4(__return: Ptr, t: Ptr) { - MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((t).clone())); +pub fn copy_or_move_into_param_4(__return: Ptr, t: ParameterObject) { + let t = t.as_pointer(); + Tracked::constructor_3(__return.clone(), RvalueRef::bind((t).clone())); return; } pub fn main() { @@ -69,7 +69,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Tracked(5)); + object!(a, Tracked::constructor_1(5)); assert!( ((({ chosen_overload_0(a.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) ); @@ -78,21 +78,27 @@ fn main_0() -> i32 { ((({ chosen_overload_1(a.as_pointer(),) }) as i32) == (Overload_kRvalueOverload as i32)) ); assert!(({ (*a.borrow()).v } == 5)); - object!(b, Tracked(6)); + object!(b, Tracked::constructor_1(6)); object!(moved, Tracked, |moved| ({ - let _t: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(_t.as_pointer(), RvalueRef::bind(b.as_pointer())); - copy_or_move_into_param_4(Ptr::clone(&moved.clone()), _t.as_pointer()) + let _t: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_3(_t.as_pointer(), RvalueRef::bind(b.as_pointer())); + copy_or_move_into_param_4( + Ptr::clone(&moved.clone()), + ParameterObject::bind(_t.as_pointer()), + ) })); assert!(({ (*moved.borrow()).v } == 6)); assert!(({ (*moved.borrow()).copies } == 0)); assert!(({ (*moved.borrow()).moves } == 2)); assert!(({ (*b.borrow()).v } == 0)); - object!(c, Tracked(7)); + object!(c, Tracked::constructor_1(7)); object!(copied, Tracked, |copied| ({ - let _t: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(_t.as_pointer(), LvalueRef::bind(c.as_pointer())); - copy_or_move_into_param_4(Ptr::clone(&copied.clone()), _t.as_pointer()) + let _t: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(_t.as_pointer(), LvalueRef::bind(c.as_pointer())); + copy_or_move_into_param_4( + Ptr::clone(&copied.clone()), + ParameterObject::bind(_t.as_pointer()), + ) })); assert!(({ (*copied.borrow()).v } == 7)); assert!(({ (*copied.borrow()).copies } == 1)); diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index 1322d87ae1..83247cb240 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -12,9 +12,12 @@ pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -25,22 +28,18 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); 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: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); @@ -97,15 +96,20 @@ pub fn forward_pack_7( return digits; } impl Pair { - pub fn construct(this: Ptr, x: Ptr, y: Ptr) { - CopyConstructible::copy_constructor(field_ptr!(this, a), LvalueRef::bind((x).clone())); - MoveConstructible::move_constructor(field_ptr!(this, b), RvalueRef::bind((y).clone())); + pub fn constructor_1_1(this: Ptr, x: LvalueRef, y: RvalueRef) { + let x = x.as_pointer(); + let y = y.as_pointer(); + Tracked::constructor_2(field_ptr!(this, a), LvalueRef::bind((x).clone())); + Tracked::constructor_3(field_ptr!(this, b), RvalueRef::bind((y).clone())); } } #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1_1, LvalueRef, RvalueRef)] #[byte_size(24)] pub struct Pair { #[offset(0)] @@ -115,8 +119,13 @@ pub struct Pair { #[byte_size(12)] pub b: Tracked, } +impl Pair {} pub fn forward_pack_into_ctor_8(__return: Ptr, args_0: Ptr, args_1: Ptr) { - Pair::construct(__return.clone(), (args_0).clone(), (args_1).clone()); + Pair::constructor_1_1( + __return.clone(), + LvalueRef::bind((args_0).clone()), + RvalueRef::bind((args_1).clone()), + ); return; } pub fn main() { @@ -125,21 +134,21 @@ pub fn main() { } fn main_0() -> i32 { assert!((({ forward_pack_4() }) == 0)); - object!(a, Tracked(1)); + object!(a, Tracked::constructor_1(1)); assert!((({ forward_pack_5(a.as_pointer(),) }) == (Overload_kLvalueOverload as i32))); assert!(({ (*a.borrow()).v } == 1)); assert!( (({ - let _args: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_args.as_pointer(), 2); + let _args: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args.as_pointer(), 2); forward_pack_6(_args.as_pointer()) }) == (Overload_kRvalueOverload as i32)) ); let i: Value = Rc::new(RefCell::new(3)); assert!( (({ - let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_args_1.as_pointer(), 4); + let _args_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args_1.as_pointer(), 4); let _args_3: Value = Rc::new(RefCell::new(5)); forward_pack_7( a.as_pointer(), @@ -151,10 +160,10 @@ fn main_0() -> i32 { ); assert!(({ (*a.borrow()).v } == 1)); assert!(({ ((*i.borrow()) == 3) })); - object!(lhs, Tracked(6)); + object!(lhs, Tracked::constructor_1(6)); object!(p, Pair, |p| ({ - let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_args_1.as_pointer(), 7); + let _args_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args_1.as_pointer(), 7); forward_pack_into_ctor_8( Ptr::clone(&p.clone()), lhs.as_pointer(), diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index d4b2be0dee..b2098a0d9d 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -26,7 +26,9 @@ pub fn scaled_2(v: Ptr, mut k: f64) -> f64 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct V { #[offset(0)] @@ -46,7 +48,9 @@ pub fn get_3(w: Ptr) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct W_int_ { #[offset(0)] @@ -66,7 +70,9 @@ pub fn get_4(w: Ptr) -> i64 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct W_long_ { #[offset(0)] @@ -83,7 +89,9 @@ pub struct W_long_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 34902af520..60a3a5951d 100644 --- a/tests/unit/out/refcount/function_overloading.rs +++ b/tests/unit/out/refcount/function_overloading.rs @@ -32,7 +32,9 @@ pub fn bar_4(x: Ptr) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Foo {} impl Foo { diff --git a/tests/unit/out/refcount/global_call_temporaries.rs b/tests/unit/out/refcount/global_call_temporaries.rs index 34692c03ce..91d788b618 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -114,7 +114,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 45fe592233..f1f34df9ee 100644 --- a/tests/unit/out/refcount/global_init_side_effect.rs +++ b/tests/unit/out/refcount/global_init_side_effect.rs @@ -17,30 +17,31 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(1)] pub struct S {} impl S { - pub fn construct(this: Ptr, mut x: i32) { + pub fn constructor_1(this: Ptr, mut x: i32) { total_0.with(|rc| *rc.borrow_mut() += x); } } thread_local!( pub static a_1: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - S::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); thread_local!( pub static b_2: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - S::construct(__v.as_pointer(), 10); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::constructor_1(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index 46ffacf574..3e989d0e15 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -32,28 +32,39 @@ 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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, i32)] #[byte_size(4)] pub struct Ctor { #[offset(0)] pub v: i32, } impl Ctor { - pub fn construct_1(this: Ptr, mut x: i32) { - field!(this, v).write(x); - } -} -impl DefaultConstructible for Ctor { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, v).write(({ next_0() })); } + pub fn constructor_2(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } } impl Default for Ctor { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Ctor::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -61,15 +72,15 @@ impl Default for Ctor { } thread_local!( pub static default_ctor_7: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Ctor::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); thread_local!( pub static arg_ctor_8: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Ctor::construct_1(__v.as_pointer(), 7); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Ctor::constructor_2(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -82,8 +93,8 @@ thread_local!( ); thread_local!( pub static inline_member_11: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Ctor::construct_1(__v.as_pointer(), 5); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Ctor::constructor_2(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -98,7 +109,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Holder {} thread_local!( @@ -112,33 +125,43 @@ thread_local!( ); thread_local!( static local_ctor_14: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Ctor::construct_1(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Ctor::constructor_2(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Singleton { #[offset(0)] pub hits: i32, } impl Singleton { + pub fn constructor_1(this: Ptr) { + field!(this, hits).write(0); + } pub fn instance() -> Ptr { return s_15.with(|v| v.as_pointer()); } } -impl DefaultConstructible for Singleton { - fn default_constructor(this: Ptr) { - field!(this, hits).write(0); - } -} impl Default for Singleton { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Singleton::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -146,8 +169,8 @@ impl Default for Singleton { } thread_local!( static s_15: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Singleton::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); diff --git a/tests/unit/out/refcount/global_pointers.rs b/tests/unit/out/refcount/global_pointers.rs index 6d36fe5e09..72794e1869 100644 --- a/tests/unit/out/refcount/global_pointers.rs +++ b/tests/unit/out/refcount/global_pointers.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 021b71d9a2..5368ea07f3 100644 --- a/tests/unit/out/refcount/global_without_initializer.rs +++ b/tests/unit/out/refcount/global_without_initializer.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index 197ee125ce..22b3208ef7 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(24)] pub struct MinHeapNode { #[offset(0)] @@ -60,6 +62,9 @@ pub fn Swap_0(a: Ptr, b: Ptr) { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct MinHeap { #[offset(0)] @@ -234,9 +239,7 @@ impl MinHeap { } } } -} -impl DefaultConstructible for MinHeap { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, size).write(0_i32); field!(this, capacity).write(0_i32); field!(this, arr).write(None); 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 973cb5d533..b5e695214e 100644 --- a/tests/unit/out/refcount/immutable-deref-on-func-call.rs +++ b/tests/unit/out/refcount/immutable-deref-on-func-call.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 20f3787eb8..f30d5b13c8 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -20,14 +20,17 @@ use std::rc::{Rc, Weak}; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Holder { #[offset(0)] #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for Holder { - fn default_constructor(this: Ptr) { +impl Holder { + pub fn constructor_1(this: Ptr) { field!(this, v).write(Vec::new()); } } @@ -51,7 +54,7 @@ fn main_0() -> i32 { let mut p: Ptr> = (v.as_pointer()); let mut a: i32 = (index!(p, 0_usize).read()); index!(p, 1_usize).write(30); - object!(h, Holder); + object!(h, Holder::constructor_1()); ({ let __tmp_2: Value = Rc::new(RefCell::new(40)); MoveConstructible::push_moved( diff --git a/tests/unit/out/refcount/in_class_field_initializer.rs b/tests/unit/out/refcount/in_class_field_initializer.rs index e4c30a6732..a4404eedc0 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.rs @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -14,8 +26,8 @@ pub struct Inner { #[offset(4)] pub y: i32, } -impl DefaultConstructible for Inner { - fn default_constructor(this: Ptr) { +impl Inner { + pub fn constructor_1(this: Ptr) { field!(this, x).write(3); field!(this, y).write(4); } @@ -25,7 +37,19 @@ impl Default for Inner { { Inner { x: 3, y: 4 } } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct S { #[offset(0)] @@ -39,12 +63,12 @@ pub struct S { #[byte_size(8)] pub d: Inner, } -impl DefaultConstructible for S { - fn default_constructor(this: Ptr) { +impl S { + pub fn constructor_1(this: Ptr) { field!(this, a).write(1); field!(this, b).write(2_i8); field!(this, c).write(::default()); - DefaultConstructible::default_constructor(field_ptr!(this, d)); + Inner::constructor_1(field_ptr!(this, d)); } } impl Default for S { @@ -69,7 +93,10 @@ impl Default for S { FnPtrArg, DefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] +#[constructor(constructor_1, i32, i32)] #[byte_size(8)] pub struct Boxed_int_ { #[offset(0)] @@ -78,7 +105,7 @@ pub struct Boxed_int_ { pub tag: i32, } impl Boxed_int_ { - pub fn construct(this: Ptr, mut x: i32, mut t: i32) { + pub fn constructor_1(this: Ptr, mut x: i32, mut t: i32) { field!(this, v).write(x); field!(this, tag).write(t); } @@ -93,14 +120,14 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S); + object!(s, S::constructor_1()); assert!(({ (*s.borrow()).a } == 1)); assert!((({ (*s.borrow()).b } as i32) == 2)); assert!(({ (*s.borrow()).c.x } == 3)); assert!(({ (*s.borrow()).c.y } == 4)); assert!(({ (*s.borrow()).d.x } == 3)); assert!(({ (*s.borrow()).d.y } == 4)); - object!(boxed, Boxed_int_(5, 9)); + object!(boxed, Boxed_int_::constructor_1(5, 9)); assert!(({ (*boxed.borrow()).v } == 5)); assert!(({ (*boxed.borrow()).tag } == 9)); return 0; diff --git a/tests/unit/out/refcount/inet_pton_ntop.rs b/tests/unit/out/refcount/inet_pton_ntop.rs index b855b288c8..ed93375fa8 100644 --- a/tests/unit/out/refcount/inet_pton_ntop.rs +++ b/tests/unit/out/refcount/inet_pton_ntop.rs @@ -63,7 +63,6 @@ fn main_0() -> i32 { ({ let mut __tmp_2 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { - // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"1.2.3.4").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { @@ -105,7 +104,6 @@ fn main_0() -> i32 { ({ let mut __tmp_3 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { - // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"999.1.1.1").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { @@ -139,7 +137,6 @@ fn main_0() -> i32 { ({ let mut __tmp_4 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { - // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"not an ip").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { @@ -173,7 +170,6 @@ fn main_0() -> i32 { ({ let mut __tmp_5 = { (buf.decay()).to_any() }; if libc::AF_INET6 == libc::AF_INET { - // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"::1").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { @@ -213,7 +209,6 @@ fn main_0() -> i32 { ({ let mut __tmp_6 = { (buf.decay()).to_any() }; if libc::AF_INET6 == libc::AF_INET { - // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"2001:db8::5").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { diff --git a/tests/unit/out/refcount/init.rs b/tests/unit/out/refcount/init.rs index af6248358f..89b82c13f4 100644 --- a/tests/unit/out/refcount/init.rs +++ b/tests/unit/out/refcount/init.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 a1bf443709..0e4e1e348d 100644 --- a/tests/unit/out/refcount/init_list.rs +++ b/tests/unit/out/refcount/init_list.rs @@ -20,7 +20,9 @@ pub fn f_0(list: Vec) { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -28,7 +30,19 @@ pub struct Pair { #[offset(4)] pub b: i32, } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Holder { #[offset(0)] @@ -40,9 +54,7 @@ impl Holder { field!(this, p).write({ (*o.upgrade().deref()) }); return (this).clone(); } -} -impl DefaultConstructible for Holder { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, p).write(Pair { a: 0, b: 0 }); } } @@ -58,14 +70,26 @@ 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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Seven { #[offset(0)] pub v: i32, } -impl DefaultConstructible for Seven { - fn default_constructor(this: Ptr) { +impl Seven { + pub fn constructor_1(this: Ptr) { field!(this, v).write(7); } } @@ -87,7 +111,7 @@ fn main_0() -> i32 { let mut vec_: Vec = Vec::from([1, 2, 3]); ({ f_0(Vec::from([1, 2, 3, 4])) }); let p: Value = Rc::new(RefCell::new(Pair { a: 1, b: 2 })); - object!(h, Holder); + object!(h, Holder::constructor_1()); Holder::operator_assign_1(h.as_pointer(), p.as_pointer()); assert!(({ (*h.borrow()).p.a } == 1) && ({ (*h.borrow()).p.b } == 2)); assert!((({ sum_1(p.as_pointer(),) }) == 3)); diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 65956063ca..2fe567d0e7 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -19,6 +19,9 @@ use std::rc::{Rc, Weak}; Swappable, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct Elem { #[offset(0)] @@ -31,8 +34,8 @@ pub struct Elem { #[byte_size(24)] pub coeffs: Vec, } -impl DefaultConstructible for Elem { - fn default_constructor(this: Ptr) { +impl Elem { + pub fn constructor_1(this: Ptr) { field!(this, id).write(0_i32); field!(this, hist).write((0..4).map(|_| 0_i32).collect::>()); field!(this, coeffs).write(Vec::new()); @@ -62,6 +65,9 @@ impl Default for Elem { Swappable, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(88)] pub struct State { #[offset(0)] @@ -81,8 +87,8 @@ pub struct State { #[byte_size(24)] pub rows: Vec>, } -impl DefaultConstructible for State { - fn default_constructor(this: Ptr) { +impl State { + pub fn constructor_1(this: Ptr) { field!(this, count).write(0_i32); field!(this, grid).write( (0..2) @@ -182,26 +188,26 @@ thread_local!( thread_local!( pub static move_assigns_5: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct Counted { #[offset(0)] pub v: i32, } -impl DefaultConstructible for Counted { - fn default_constructor(this: Ptr) { +impl Counted { + pub fn constructor_1(this: Ptr) { field!(this, v).write(0); } -} -impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); 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: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); @@ -348,7 +354,12 @@ fn main_0() -> i32 { ((array_elem!(elems.decay().offset(1_usize), hist, 2).read()) == 5) && ((array_elem!(first, hist, 2).read()) == 0) ); - object!(moved, State, RvalueRef::bind(t.as_pointer())); + object!(moved, State, |moved| { + ::move_constructor( + moved.clone(), + RvalueRef::bind(t.as_pointer()), + ) + }); assert!( ({ ((*moved.borrow()).grid[(0) as usize][(0) as usize] == 100) @@ -399,13 +410,13 @@ fn main_0() -> i32 { (*ca.borrow_mut())[1_usize].v = 5; let cb: Value> = Rc::new(RefCell::new({ let __v: Value> = Rc::new(RefCell::new( - (0..3).map(|_| ::zero_init()).collect(), + (0..3).map(|_| ZeroInitialization::zero_init()).collect(), )); let __p: Ptr = __v.decay(); for __i in 0..3 { - MoveConstructible::move_constructor( + Constructor::constructor( __p.offset(__i), - RvalueRef::bind(ca.decay().offset(__i)), + (RvalueRef::::bind(ca.decay().offset(__i)),), ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -460,13 +471,13 @@ fn main_0() -> i32 { }); let vb: Value]>> = Rc::new(RefCell::new({ let __v: Value]>> = Rc::new(RefCell::new( - (0..2).map(|_| >::zero_init()).collect(), + (0..2).map(|_| ZeroInitialization::zero_init()).collect(), )); let __p: Ptr> = __v.decay(); for __i in 0..2 { - MoveConstructible::move_constructor( + Constructor::constructor( __p.offset(__i), - RvalueRef::bind(va.decay().offset(__i)), + (RvalueRef::>::bind(va.decay().offset(__i)),), ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index fb0bb5334d..0c2b885a5c 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Edge { #[offset(0)] @@ -114,6 +116,9 @@ pub fn quicksort_1(arr: Ptr>>>, mut start: i32, mut end Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct DisjointSet { #[offset(0)] @@ -227,9 +232,7 @@ impl DisjointSet { ); } } -} -impl DefaultConstructible for DisjointSet { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, rank).write(None); field!(this, parent).write(None); field!(this, n).write(0_i32); @@ -239,6 +242,9 @@ impl DefaultConstructible for DisjointSet { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(16)] pub struct Graph { #[offset(0)] @@ -249,8 +255,8 @@ pub struct Graph { #[offset(12)] pub E: i32, } -impl DefaultConstructible for Graph { - fn default_constructor(this: Ptr) { +impl Graph { + pub fn constructor_1(this: Ptr) { field!(this, edges).write(None); field!(this, V).write(0_i32); field!(this, E).write(0_i32); diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index f4c2bb7b5c..55c942e682 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -19,6 +19,8 @@ use std::rc::{Rc, Weak}; Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(1)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { #[offset(0)] @@ -31,8 +33,17 @@ impl Destructible for Guard__lambda_at_lambda_as_field_cpp_34_13__ { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, DefaultConstructible, Copyable, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + Copyable, + Conversions, )] +#[conversions(copy)] #[byte_size(8)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { #[offset(0)] @@ -53,7 +64,9 @@ impl Destructible for Guard__lambda_at_lambda_as_field_cpp_45_13__ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { #[offset(0)] @@ -92,7 +105,9 @@ impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { #[offset(0)] @@ -107,8 +122,9 @@ impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { return ({ (*this.upgrade().deref()).f.call(x) }); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable)] -#[cpp_from(FnPtr i32 > , construct, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] +#[conversions(move)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(8)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { #[offset(0)] @@ -118,14 +134,12 @@ pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { pub moves: i32, } impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { - pub fn construct(this: Ptr, f: FnPtr i32>) { + pub fn constructor_1(this: Ptr, f: FnPtr i32>) { let f: Value i32>> = Rc::new(RefCell::new(f)); field!(this, f).write((*f.borrow()).copy_from()); field!(this, moves).write(0); } -} -impl MoveConstructible for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn move_constructor( + pub fn constructor_2( this: Ptr, o: RvalueRef, ) { @@ -252,7 +266,7 @@ fn main_0() -> i32 { assert!(({ (({ (*ww.borrow()).call(2,) }) == 202) })); object!( m, - Moving__lambda_at_lambda_as_field_cpp_64_12__(FnPtr:: i32>::new( + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_1(FnPtr:: i32>::new( |mut x: i32| -> i32 { { return (x * 2); @@ -262,8 +276,9 @@ fn main_0() -> i32 { ); object!( m2, - Moving__lambda_at_lambda_as_field_cpp_64_12__, - RvalueRef::bind(m.as_pointer()) + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_2(RvalueRef::bind( + m.as_pointer() + )) ); assert!(({ (({ (*m2.borrow()).f.call(3,) }) == 6) })); assert!(({ (*m2.borrow()).moves } == 1)); diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 9afa88dffb..8fc8d569db 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -6,7 +6,11 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(8)] pub struct Counted { #[offset(0)] @@ -14,21 +18,17 @@ pub struct Counted { #[offset(4)] pub moves: i32, } -impl DefaultConstructible for Counted { - fn default_constructor(this: Ptr) { +impl Counted { + pub fn constructor_1(this: Ptr) { field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); 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: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, copies).write(o.with(|__s| __s.copies)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -38,8 +38,8 @@ impl Default for Counted { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -48,19 +48,19 @@ impl Default for Counted { thread_local!( pub static drops_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(1)] pub struct Dropped {} -impl DefaultConstructible for Dropped { - fn default_constructor(this: Ptr) {} -} -impl CopyConstructible for Dropped { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { +impl Dropped { + pub fn constructor_1(this: Ptr) {} + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); } -} -impl MoveConstructible for Dropped { - fn move_constructor(this: Ptr, _a0: RvalueRef) { + pub fn constructor_3(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); } } @@ -74,15 +74,12 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(c, Counted); + object!(c, Counted::constructor_1()); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let c: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( - __v.as_pointer(), - LvalueRef::bind(c.as_pointer()), - ); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2(__v.as_pointer(), LvalueRef::bind(c.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -97,14 +94,15 @@ fn main_0() -> i32 { let h: Value i32>> = Rc::new(RefCell::new((*f.borrow()).move_from())); assert!(({ (({ (*h.borrow()).call() }) == 11) })); let mut returned: i32 = { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); { ({ lambda!( { let c: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2( __v.as_pointer(), LvalueRef::bind(c.as_pointer()), ); @@ -112,10 +110,7 @@ fn main_0() -> i32 { })); }, |__return: Ptr| { - CopyConstructible::copy_constructor( - __return.clone(), - LvalueRef::bind(c.as_pointer()), - ); + Counted::constructor_2(__return.clone(), LvalueRef::bind(c.as_pointer())); return; } ) @@ -128,8 +123,8 @@ fn main_0() -> i32 { assert!((returned == 2)); let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 2, _>(|_| { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); @@ -137,8 +132,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())); - CopyConstructible::copy_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2( __v.as_pointer(), LvalueRef::bind(arr.decay().offset(__i)), ); @@ -161,8 +157,9 @@ fn main_0() -> i32 { let m: Value> = Rc::new(RefCell::new(lambda!( { let d: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Dropped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -179,8 +176,9 @@ fn main_0() -> i32 { let k: Value> = Rc::new(RefCell::new(lambda!( { let d: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Dropped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -197,8 +195,9 @@ fn main_0() -> i32 { let inner: Value> = Rc::new(RefCell::new(lambda!( { let d: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Dropped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, diff --git a/tests/unit/out/refcount/lambda_capture_ref.rs b/tests/unit/out/refcount/lambda_capture_ref.rs index 6eb83999c3..6a13250210 100644 --- a/tests/unit/out/refcount/lambda_capture_ref.rs +++ b/tests/unit/out/refcount/lambda_capture_ref.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 638e8b333f..5f0cc56787 100644 --- a/tests/unit/out/refcount/lambda_capture_star_this.rs +++ b/tests/unit/out/refcount/lambda_capture_star_this.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 cb10482d9f..44e5c89ccd 100644 --- a/tests/unit/out/refcount/lambda_capture_this.rs +++ b/tests/unit/out/refcount/lambda_capture_this.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 dc0d6519a4..b0a6c97a82 100644 --- a/tests/unit/out/refcount/lambda_capture_value.rs +++ b/tests/unit/out/refcount/lambda_capture_value.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 9a02d69619..8ff9412094 100644 --- a/tests/unit/out/refcount/lambda_decltype_type.rs +++ b/tests/unit/out/refcount/lambda_decltype_type.rs @@ -6,7 +6,11 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[offset(0)] @@ -35,9 +39,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { array_elem!(this, items, i).write(v); field!(this, size).with_mut(|__v| __v.postfix_inc()); } -} -impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, items).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(0); field!(this, cmp).write(FnPtr:: bool>::new( @@ -64,7 +66,11 @@ impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { #[offset(0)] @@ -93,9 +99,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { array_elem!(this, items, i).write(v); field!(this, size).with_mut(|__v| __v.postfix_inc()); } -} -impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, items).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(0); field!(this, cmp).write(FnPtr:: bool>::new( @@ -135,14 +139,20 @@ fn main_0() -> i32 { } }, ))); - object!(desc, Sorted__lambda_at_lambda_decltype_type_cpp_22_18__); + object!( + desc, + Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::constructor_1() + ); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 2) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 7) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 4) }); assert!(((array_elem!(desc.as_pointer(), items, 0).read()) == 7)); assert!(((array_elem!(desc.as_pointer(), items, 1).read()) == 4)); assert!(((array_elem!(desc.as_pointer(), items, 2).read()) == 2)); - object!(asc, Sorted__lambda_at_lambda_decltype_type_cpp_19_23__); + object!( + asc, + Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::constructor_1() + ); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 2) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 7) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 4) }); diff --git a/tests/unit/out/refcount/lambda_generic_explicit_args.rs b/tests/unit/out/refcount/lambda_generic_explicit_args.rs index 4eb1a8cd82..5d81e380fc 100644 --- a/tests/unit/out/refcount/lambda_generic_explicit_args.rs +++ b/tests/unit/out/refcount/lambda_generic_explicit_args.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 2ced1e422c..45d71a6fd0 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -9,7 +9,19 @@ use std::rc::{Rc, Weak}; pub fn pick_0(mut x: i32) -> i32 { return x; } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -17,8 +29,8 @@ pub struct S { #[offset(4)] pub k: i32, } -impl DefaultConstructible for S { - fn default_constructor(this: Ptr) { +impl S { + pub fn constructor_1(this: Ptr) { field!(this, j).write(10); field!(this, k).write( (({ @@ -91,7 +103,7 @@ fn main_0() -> i32 { }) == 237) ); assert!((({ pick_0(1,) }) == 1)); - object!(s, S); + object!(s, S::constructor_1()); assert!(({ (*s.borrow()).k } == 4)); assert!((g_1.with(|rc| *rc.borrow()) == 10)); let a: Value = Rc::new(RefCell::new(2)); diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index 1585f4b343..20b2fb98e5 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -6,8 +6,10 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultConstructible)] -#[cpp_from(i32, construct, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultConstructible, Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(8)] pub struct Owner { #[offset(0)] @@ -15,18 +17,20 @@ pub struct Owner { pub p: Ptr, } impl Owner { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, p).write(Ptr::alloc(v)); } + pub fn constructor_3(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); + field!(this, p).write(o.with(|__s| __s.p.clone())); + field!(o, p).write(Ptr::::null()); + } pub fn take(this: Ptr) -> FnPtr i32> { return lambda!( { let self_: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( - __v.as_pointer(), - RvalueRef::bind((this).clone()), - ); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Owner::constructor_3(__v.as_pointer(), RvalueRef::bind((this).clone())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -36,13 +40,6 @@ impl Owner { ); } } -impl MoveConstructible for Owner { - fn move_constructor(this: Ptr, o: RvalueRef) { - let o = o.as_pointer(); - field!(this, p).write(o.with(|__s| __s.p.clone())); - field!(o, p).write(Ptr::::null()); - } -} impl Destructible for Owner { fn destroy(this: Ptr) { this.with(|__s| __s.p.clone()).delete(); @@ -53,15 +50,12 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(o, Owner(5)); + object!(o, Owner::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let h: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( - __v.as_pointer(), - RvalueRef::bind(o.as_pointer()), - ); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Owner::constructor_3(__v.as_pointer(), RvalueRef::bind(o.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -81,8 +75,8 @@ fn main_0() -> i32 { let consume: Value> = Rc::new(RefCell::new(lambda!( { let h: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Owner::construct(__v.as_pointer(), 7); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Owner::constructor_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let total: Ptr = total.as_pointer(); @@ -101,7 +95,7 @@ fn main_0() -> i32 { ({ (*consume.borrow()).call() }); ({ (*consume.borrow()).call() }); assert!(({ ((*total.borrow()) == 7) })); - object!(o2, Owner(9)); + object!(o2, Owner::constructor_1(9)); let t: Value i32>> = Rc::new(RefCell::new(({ Owner::take(o2.as_pointer()) }))); let _dtor_t = std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(__p.as_pointer())); diff --git a/tests/unit/out/refcount/lambda_nested.rs b/tests/unit/out/refcount/lambda_nested.rs index 2a9fadde0a..c10784772e 100644 --- a/tests/unit/out/refcount/lambda_nested.rs +++ b/tests/unit/out/refcount/lambda_nested.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 cc2b905054..32edd6b930 100644 --- a/tests/unit/out/refcount/lambda_static_local.rs +++ b/tests/unit/out/refcount/lambda_static_local.rs @@ -89,7 +89,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 ef88225324..cbe1a2dcb5 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -19,6 +19,9 @@ use std::rc::{Rc, Weak}; Swappable, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct UserDefined { #[offset(0)] @@ -29,8 +32,8 @@ pub struct UserDefined { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for UserDefined { - fn default_constructor(this: Ptr) { +impl UserDefined { + pub fn constructor_1(this: Ptr) { field!(this, a).write(Box::<[i32]>::from(std::array::from_fn::<_, 1, _>(|_| { 0_i32 }))); @@ -56,7 +59,9 @@ impl Default for UserDefined { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct FieldIsLibcType { #[offset(0)] @@ -97,7 +102,7 @@ fn main_0() -> i32 { let st: Value = Rc::new(RefCell::new(Default::default())); (*st.borrow_mut()).st_size = (1024 as ::libc::off_t); assert!(({ (*st.borrow()).st_size } == (1024 as ::libc::off_t))); - object!(ud, UserDefined); + object!(ud, UserDefined::constructor_1()); elem!(field_ref!(ud.as_pointer(), a).decay(), 0_usize).write(3); assert!(((elem!(field_ref!(ud.as_pointer(), a).decay(), 0_usize).read()) == 3)); assert!(({ ((*ud.borrow()).v.len() == 0_usize) })); diff --git a/tests/unit/out/refcount/linked_list.rs b/tests/unit/out/refcount/linked_list.rs index dc1e47b3a3..14eb33d736 100644 --- a/tests/unit/out/refcount/linked_list.rs +++ b/tests/unit/out/refcount/linked_list.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Node { #[offset(0)] diff --git a/tests/unit/out/refcount/local_record_template.rs b/tests/unit/out/refcount/local_record_template.rs index 417268e98e..2b72bcbf2f 100644 --- a/tests/unit/out/refcount/local_record_template.rs +++ b/tests/unit/out/refcount/local_record_template.rs @@ -40,7 +40,9 @@ pub fn wrap_10(mut v: i64) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Local_5 { #[offset(0)] @@ -57,7 +59,9 @@ pub struct Local_5 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Local_7 { #[offset(0)] @@ -78,7 +82,9 @@ pub fn other_11() -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Local_1 { #[offset(0)] @@ -110,7 +116,9 @@ fn main_0() -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 38a0839aa7..d4c16f8bde 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -15,7 +15,20 @@ pub fn bar_1(x: Ptr) { pub fn inc_2(x: Ptr) { x.with_mut(|__v| __v.postfix_inc()); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32, i32)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -24,23 +37,21 @@ pub struct Point { pub y: i32, } impl Point { - pub fn construct_1(this: Ptr, mut x: i32, mut y: i32) { - field!(this, x).write(x); - field!(this, y).write(y); - } -} -impl DefaultConstructible for Point { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, x).write(0); field!(this, y).write(0); } + pub fn constructor_2(this: Ptr, mut x: i32, mut y: i32) { + field!(this, x).write(x); + field!(this, y).write(y); + } } impl Default for Point { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -689,14 +700,24 @@ fn main_0() -> i32 { ))) .as_pointer(),) { - (__tmp_58,) => ( - Rc::new(RefCell::new( - ((*__tmp_58.upgrade().deref()).0.as_pointer().read()), - )), - Rc::new(RefCell::new( - ((*__tmp_58.upgrade().deref()).1.as_pointer().read()), - )), - ), + (__tmp_58,) => { + object!(__first, i32, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_58.upgrade().deref()).0.as_pointer() + ),) + )); + object!(__second, i32, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_58.upgrade().deref()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + } } }; let (__it, __inserted) = @@ -807,8 +828,8 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key1.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Point::construct_1(__v.as_pointer(), 3, 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_2(__v.as_pointer(), 3, 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -854,8 +875,8 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(({ (*key8.borrow()) }))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Point::construct_1(__v.as_pointer(), 5, 6); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_2(__v.as_pointer(), 5, 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index b181f563ef..c8c3306cea 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -16,28 +16,27 @@ thread_local!( pub static made_2: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct Key { #[offset(0)] pub k: i32, } impl Key { - pub fn construct(this: Ptr, mut k: i32) { + pub fn constructor_1(this: Ptr, mut k: i32) { field!(this, k).write(k); } -} -impl CopyConstructible for Key { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); 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: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, k).write(o.with(|__s| __s.k)); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); @@ -50,7 +49,7 @@ impl LessThanComparable for Key { } pub fn make_key_3(__return: Ptr, mut k: i32) { (*made_2.with(Value::clone).borrow_mut()).prefix_inc(); - Key::construct(__return.clone(), k); + Key::constructor_1(__return.clone(), k); return; } pub fn main() { @@ -60,9 +59,9 @@ pub fn main() { fn main_0() -> i32 { let mut ok: bool = true; let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - object!(a, Key(1)); - object!(b, Key(2)); - object!(c, Key(3)); + object!(a, Key::constructor_1(1)); + object!(b, Key::constructor_1(2)); + object!(c, Key::constructor_1(3)); match (a.as_pointer(),) { (__tmp_0,) => ({ (*m.borrow_mut()).subscript(__tmp_0, || 0_i32) }), } @@ -107,7 +106,7 @@ fn main_0() -> i32 { }; ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; { - let __tmp_4: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_4: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ ({ make_key_3(Ptr::clone(&__tmp_4.as_pointer()), 4) }); __tmp_4.as_pointer() @@ -126,7 +125,7 @@ fn main_0() -> i32 { .write(40) }; { - let __tmp_6: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_6: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ ({ make_key_3(Ptr::clone(&__tmp_6.as_pointer()), 4) }); __tmp_6.as_pointer() @@ -202,9 +201,9 @@ fn main_0() -> i32 { .0 .as_pointer()); { - let __tmp_12: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_12: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - Key::construct(__tmp_12.as_pointer(), 0); + Key::constructor_1(__tmp_12.as_pointer(), 0); __tmp_12.as_pointer() },) { diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index cee6bfa7de..9140286dc0 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -20,7 +20,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Key { #[offset(0)] @@ -33,14 +35,26 @@ impl LessThanComparable for Key { return ({ a.with(|__s| __s.order) } < { b.with(|__s| __s.order) }); } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Mapped { #[offset(0)] pub value: i32, } -impl DefaultConstructible for Mapped { - fn default_constructor(this: Ptr) { +impl Mapped { + pub fn constructor_1(this: Ptr) { field!(this, value).write(0); (*default_constructions_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -49,8 +63,8 @@ impl Default for Mapped { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Mapped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 1ee6e1bce2..9d4c95638a 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -18,33 +18,31 @@ thread_local!( thread_local!( pub static moves_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible)] -#[cpp_from(i32, construct_1, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRef>)] +#[constructor(constructor_4, RvalueRef)] #[byte_size(4)] pub struct Item { #[offset(0)] pub value: i32, } impl Item { - pub fn construct_1(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr) { + field!(this, value).write(0); + } + pub fn constructor_2(this: Ptr, mut value: i32) { field!(this, value).write(value); (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl DefaultConstructible for Item { - fn default_constructor(this: Ptr) { - field!(this, value).write(0); - } -} -impl CopyConstructible for Item { - fn copy_constructor(this: Ptr, other: LvalueRef>) { + pub fn constructor_3(this: Ptr, other: LvalueRef>) { let other = other.as_pointer(); 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: RvalueRef) { + pub fn constructor_4(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); @@ -55,8 +53,8 @@ impl Default for Item { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,14 +64,31 @@ 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, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef, i32 )] #[byte_size(4)] pub struct RefItem { #[offset(0)] pub value: i32, } impl RefItem { - pub fn construct_1(this: Ptr, counter: Ptr, mut amount: i32) { + pub fn constructor_1(this: Ptr) { + field!(this, value).write(0); + } + pub fn constructor_2(this: Ptr, counter: LvalueRef, mut amount: i32) { + let counter = counter.as_pointer(); field!(this, value).write({ { counter.with_mut(|__v| *__v = *__v + amount) @@ -83,17 +98,12 @@ impl RefItem { (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); } } -impl DefaultConstructible for RefItem { - fn default_constructor(this: Ptr) { - field!(this, value).write(0); - } -} impl Default for RefItem { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -241,7 +251,7 @@ fn main_0() -> i32 { m.as_pointer(), &key.as_pointer(), || { - (Rc::new(RefCell::new(copy_constructed(key .as_pointer() .clone()))), Rc::new(RefCell::new((__tmp_2.read()) ))) + ( Rc::new(RefCell::new(copy_constructed(key .as_pointer() .clone()))), Rc::new(RefCell::new((__tmp_2.read()) )), ) }, ); ( @@ -267,7 +277,7 @@ fn main_0() -> i32 { m.as_pointer(), &key.as_pointer(), || { - (Rc::new(RefCell::new(copy_constructed(key .as_pointer() .clone()))), Rc::new(RefCell::new((__tmp_4.read()) ))) + ( Rc::new(RefCell::new(copy_constructed(key .as_pointer() .clone()))), Rc::new(RefCell::new((__tmp_4.read()) )), ) }, ); ( @@ -364,8 +374,8 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), 10); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -375,7 +385,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(__inserted)), ) }; - object!(source, Item::construct_1(20)); + object!(source, Item::constructor_2(20)); made_1.with(|rc| { *rc.borrow_mut() = { copies_2.with(|rc| { @@ -398,8 +408,9 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_3( __v.as_pointer(), LvalueRef::bind((__tmp_7).clone()), ); @@ -440,8 +451,9 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), RvalueRef::bind((__tmp_8).clone()), ); @@ -481,8 +493,9 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_3( __v.as_pointer(), LvalueRef::bind((__tmp_9).clone()), ); @@ -524,8 +537,9 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), RvalueRef::bind((__tmp_10).clone()), ); @@ -564,8 +578,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItem::construct_1(__v.as_pointer(), counter.as_pointer(), 5); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_2( + __v.as_pointer(), + LvalueRef::bind(counter.as_pointer()), + 5, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -586,8 +605,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItem::construct_1(__v.as_pointer(), (__tmp_11).clone(), 2); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_11).clone()), + 2, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -617,8 +641,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItem::construct_1(__v.as_pointer(), (__tmp_12).clone(), 2); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_12).clone()), + 2, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -663,9 +692,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_14: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_14: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - Item::construct_1(__tmp_14.as_pointer(), 30); + Item::constructor_2(__tmp_14.as_pointer(), 30); __tmp_14.as_pointer() },) { @@ -675,8 +704,9 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), RvalueRef::bind((__tmp_13).clone()), ); @@ -706,9 +736,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_16: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_16: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - Item::construct_1(__tmp_16.as_pointer(), 40); + Item::constructor_2(__tmp_16.as_pointer(), 40); __tmp_16.as_pointer() },) { @@ -718,8 +748,9 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), RvalueRef::bind((__tmp_15).clone()), ); diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index 0b80f5ae8b..9ee23c4dd4 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -12,14 +12,31 @@ thread_local!( thread_local!( pub static visits_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef, i32 )] #[byte_size(4)] pub struct Item { #[offset(0)] pub value: i32, } impl Item { - pub fn construct_1(this: Ptr, counter: Ptr, mut amount: i32) { + pub fn constructor_1(this: Ptr) { + field!(this, value).write(0); + } + pub fn constructor_2(this: Ptr, counter: LvalueRef, mut amount: i32) { + let counter = counter.as_pointer(); field!(this, value).write({ { counter.with_mut(|__v| *__v = *__v + amount) @@ -29,17 +46,12 @@ impl Item { (*made_0.with(Value::clone).borrow_mut()).prefix_inc(); } } -impl DefaultConstructible for Item { - fn default_constructor(this: Ptr) { - field!(this, value).write(0); - } -} impl Default for Item { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -58,7 +70,11 @@ 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, TriviallyCopyable)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(12)] pub struct Temporary { #[offset(0)] @@ -68,8 +84,8 @@ pub struct Temporary { #[array_len(2)] pub data: Box<[i32]>, } -impl DefaultConstructible for Temporary { - fn default_constructor(this: Ptr) { +impl Temporary { + pub fn constructor_1(this: Ptr) { field!(this, n).write(5); field!(this, data).write(Box::new([6, 7])); (*temporary_calls_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -79,43 +95,56 @@ impl Default for Temporary { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Default, + Conversions, )] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(12)] pub struct Nested { #[offset(0)] #[byte_size(12)] pub inner: Temporary, } -impl DefaultConstructible for Nested { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, inner)); +impl Nested { + pub fn constructor_1(this: Ptr) { + Temporary::constructor_1(field_ptr!(this, inner)); } } pub fn make_temporary_5() -> Temporary { return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn make_nested_6() -> Nested { return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Nested::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Owner { #[offset(0)] @@ -123,38 +152,37 @@ pub struct Owner { pub ptr: Option>, } impl Owner { - pub fn value(this: Ptr) -> Ptr { - return field_ptr!(this.with(|__s| __s.ptr.clone()).as_pointer(), n); - } -} -impl DefaultConstructible for Owner { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, ptr).write(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })))); } + pub fn value(this: Ptr) -> Ptr { + return field_ptr!(this.with(|__s| __s.ptr.clone()).as_pointer(), n); + } } impl Default for Owner { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Owner::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Noncopy { #[offset(0)] pub n: i32, } -impl DefaultConstructible for Noncopy { - fn default_constructor(this: Ptr) { +impl Noncopy { + pub fn constructor_1(this: Ptr) { field!(this, n).write(5); } } @@ -164,9 +192,11 @@ impl Default for Noncopy { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, TriviallyCopyable, + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[cpp_from(i32, construct_1, ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(8)] pub struct Held { #[offset(0)] @@ -174,24 +204,23 @@ pub struct Held { pub ptr: Ptr, } impl Held { - pub fn construct_1(this: Ptr, n: Ptr) { - field!(this, ptr).write((n).clone()); + pub fn constructor_1(this: Ptr) { + field!(this, ptr).write(Ptr::::null()); } - pub fn construct_2(this: Ptr, n: Ptr, mut _a1: i32) { + pub fn constructor_2(this: Ptr, n: LvalueRef>) { + let n = n.as_pointer(); field!(this, ptr).write((n).clone()); } -} -impl DefaultConstructible for Held { - fn default_constructor(this: Ptr) { - field!(this, ptr).write(Ptr::::null()); + pub fn constructor_3(this: Ptr, n: Ptr, mut _a1: i32) { + field!(this, ptr).write((n).clone()); } } impl Default for Held { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Held::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -306,8 +335,9 @@ thread_local!( match (field_ptr!( (*{ __tmp_7 = Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_7 @@ -401,8 +431,8 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), counter.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2(__v.as_pointer(), LvalueRef::bind(counter.as_pointer()), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -429,8 +459,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), (__tmp_9).clone(), 2); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_9).clone()), + 2, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -467,8 +502,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), (__tmp_11).clone(), 2); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_11).clone()), + 2, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -502,8 +542,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), (__tmp_13).clone(), 2); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_13).clone()), + 2, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -538,8 +583,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), (__tmp_16).clone(), 2); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_16).clone()), + 2, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -583,8 +633,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), (__tmp_19).clone(), 3); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_19).clone()), + 3, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -614,8 +669,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), (__tmp_21).clone(), 3); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_21).clone()), + 3, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -645,8 +705,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), (__tmp_24).clone(), 3); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_24).clone()), + 3, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -684,8 +749,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), (__tmp_27).clone(), 3); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_27).clone()), + 3, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -725,8 +795,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), (__tmp_30).clone(), 3); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_30).clone()), + 3, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -752,8 +827,13 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Item::construct_1(__v.as_pointer(), (__tmp_33).clone(), 3); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_33).clone()), + 3, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -1267,12 +1347,13 @@ fn main_0() -> i32 { keys.decay().offset(0).clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - Item::construct_1( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Item::constructor_2( __v.as_pointer(), - (__tmp_61).clone(), + LvalueRef::bind((__tmp_61).clone()), 2, ); Rc::try_unwrap(__v) @@ -1320,12 +1401,13 @@ fn main_0() -> i32 { keys.decay().offset(1).clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - Item::construct_1( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Item::constructor_2( __v.as_pointer(), - (__tmp_64).clone(), + LvalueRef::bind((__tmp_64).clone()), 2, ); Rc::try_unwrap(__v) @@ -1373,12 +1455,13 @@ fn main_0() -> i32 { keys.decay().offset(2).clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - Item::construct_1( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Item::constructor_2( __v.as_pointer(), - (__tmp_69).clone(), + LvalueRef::bind((__tmp_69).clone()), 2, ); Rc::try_unwrap(__v) @@ -1638,11 +1721,12 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - Held::construct_1( + let __v: Value = Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_2( __v.as_pointer(), - ordinary.as_pointer(), + LvalueRef::bind(ordinary.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -1690,12 +1774,13 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - Held::construct_1( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_2( __v.as_pointer(), - (__tmp_83).clone(), + LvalueRef::bind((__tmp_83).clone()), ); Rc::try_unwrap(__v) .ok() @@ -1746,9 +1831,10 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - Held::construct_2( + let __v: Value = Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_3( __v.as_pointer(), ordinary_array.decay(), 0, @@ -1798,10 +1884,11 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - Held::construct_2( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_3( __v.as_pointer(), (__tmp_88).clone(), 0, @@ -1869,8 +1956,8 @@ fn main_0() -> i32 { (*{ __tmp_94 = Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_94 @@ -1906,8 +1993,8 @@ fn main_0() -> i32 { (*{ __tmp_96 = Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Nested::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_96 @@ -1944,8 +2031,8 @@ fn main_0() -> i32 { (*{ __tmp_98 = Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_98 @@ -1981,8 +2068,8 @@ fn main_0() -> i32 { (*{ __tmp_100 = Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_100 @@ -2017,8 +2104,8 @@ fn main_0() -> i32 { ((*{ __tmp_102 = Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_102 @@ -2053,8 +2140,8 @@ fn main_0() -> i32 { ((*(*{ __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })))))); &mut __tmp_104 @@ -2128,11 +2215,12 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - Held::construct_1( + let __v: Value = Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_2( __v.as_pointer(), - ordinary.as_pointer(), + LvalueRef::bind(ordinary.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -2156,12 +2244,11 @@ fn main_0() -> i32 { field_ptr!( (*{ __tmp_106 = Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - DefaultConstructible::default_constructor( - __v.as_pointer(), - ); + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_106 @@ -2173,12 +2260,11 @@ fn main_0() -> i32 { array_field_ptr!( (*{ __tmp_107 = Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - DefaultConstructible::default_constructor( - __v.as_pointer(), - ); + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_107 @@ -2199,12 +2285,15 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - Held::construct_1( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_2( __v.as_pointer(), - (__tmp_105).clone(), + LvalueRef::bind( + (__tmp_105).clone(), + ), ); Rc::try_unwrap(__v) .ok() @@ -2244,13 +2333,11 @@ fn main_0() -> i32 { Rc::new(RefCell::new(Map::new())); { let __tmp_109: Value = - Rc::new(RefCell::new(::zero_init())); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); { match (({ Owner::value({ - DefaultConstructible::default_constructor( - __tmp_109.as_pointer(), - ); + Owner::constructor_1(__tmp_109.as_pointer()); __tmp_109.as_pointer() }) }),) @@ -2265,12 +2352,15 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - Held::construct_1( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_2( __v.as_pointer(), - (__tmp_108).clone(), + LvalueRef::bind( + (__tmp_108).clone(), + ), ); Rc::try_unwrap(__v) .ok() @@ -2324,8 +2414,8 @@ fn main_0() -> i32 { let __tmp_111: Value>>; match ({ __tmp_111 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Noncopy::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); __tmp_111.as_pointer() @@ -2364,8 +2454,8 @@ fn main_0() -> i32 { let __tmp_113: Value>>; match ({ __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Noncopy::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); __tmp_113.as_pointer() diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index 8ddeaa17c7..754e499b86 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -25,7 +25,6 @@ pub fn pick_3(mut i: i32) -> Ptr { ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -34,19 +33,20 @@ pub fn pick_3(mut i: i32) -> Ptr { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Bag { #[offset(0)] pub n: i32, } impl Bag { - pub fn construct(this: Ptr, mut n: i32) { + pub fn constructor_1(this: Ptr, mut n: i32) { field!(this, n).write(n); } -} -impl CopyConstructible for Bag { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, n).write(o.with(|__s| __s.n)); (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); @@ -58,7 +58,7 @@ impl LessThanComparable for Bag { } } pub fn make_4(__return: Ptr, mut n: i32) { - Bag::construct(__return.clone(), n); + Bag::constructor_1(__return.clone(), n); return; } pub fn main() { @@ -159,8 +159,8 @@ fn main_0() -> i32 { calls_0.with(|rc| *rc.borrow_mut() = 0); assert!( ({ - let __tmp_7: Value = Rc::new(RefCell::new(::zero_init())); - let __tmp_9: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_7: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + let __tmp_9: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match ( { ({ make_4(Ptr::clone(&__tmp_7.as_pointer()), 1) }); @@ -185,8 +185,8 @@ fn main_0() -> i32 { .with(|__s| __s.n) == 2) }) && ({ - let __tmp_11: Value = Rc::new(RefCell::new(::zero_init())); - let __tmp_13: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_11: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + let __tmp_13: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match ( { ({ make_4(Ptr::clone(&__tmp_11.as_pointer()), 1) }); diff --git a/tests/unit/out/refcount/memcpy_struct_struct.rs b/tests/unit/out/refcount/memcpy_struct_struct.rs index 8a4c3563f7..9481df496d 100644 --- a/tests/unit/out/refcount/memcpy_struct_struct.rs +++ b/tests/unit/out/refcount/memcpy_struct_struct.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Entry { #[offset(0)] diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 56a09bd1b9..b091e740be 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -11,24 +11,24 @@ use std::rc::{Rc, Weak}; ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Swappable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub v: i32, } impl MoveOnly { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); @@ -45,13 +45,17 @@ impl MoveAssignable for MoveOnly { return (this).clone(); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct ConstMoveAssign { #[offset(0)] pub mark: i32, } impl ConstMoveAssign { + pub fn constructor_1(this: Ptr) { + field!(this, mark).write(0); + } pub fn operator_assign_2(this: Ptr, o: Ptr) -> Ptr { field!(this, mark).write((o.with(|__s| __s.mark) + 1)); return (this).clone(); @@ -61,26 +65,21 @@ impl ConstMoveAssign { return (this).clone(); } } -impl DefaultConstructible for ConstMoveAssign { - fn default_constructor(this: Ptr) { - field!(this, mark).write(0); - } -} impl Default for ConstMoveAssign { fn default() -> Self { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ConstMoveAssign::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } pub fn make_0(__return: Ptr, mut v: i32) { - object!(m, MoveOnly(v)); - MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind(m.as_pointer())); + object!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return.clone(), RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -88,15 +87,15 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, MoveOnly(1)); - object!(b, MoveOnly(2)); - object!(c, MoveOnly(3)); + object!(a, MoveOnly::constructor_1(1)); + object!(b, MoveOnly::constructor_1(2)); + object!(c, MoveOnly::constructor_1(3)); assign!(a = RvalueRef(b)); assert!(({ (*a.borrow()).v } == 2)); assert!(({ (*b.borrow()).v } == 0)); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnly::construct(_o.as_pointer(), 3); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(_o.as_pointer(), 3); assign!(b = RvalueRef(_o)) }); assign!(c = RvalueRef(*assign!(a = RvalueRef(b)))); @@ -104,13 +103,13 @@ fn main_0() -> i32 { (({ (*b.borrow()).v } == 0) && ({ (*a.borrow()).v } == 0)) && ({ (*c.borrow()).v } == 3) ); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnly::construct(_o.as_pointer(), 5); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(_o.as_pointer(), 5); assign!(a = RvalueRef(_o)) }); assert!(({ (*a.borrow()).v } == 5)); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_0(Ptr::clone(&_o.as_pointer()), 6) }); assign!(a = RvalueRef(_o)) }); @@ -119,23 +118,23 @@ fn main_0() -> i32 { assert!(({ (*a.borrow()).v } == 6)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - MoveOnly::construct(__tmp_1.as_pointer(), 7); + MoveOnly::constructor_1(__tmp_1.as_pointer(), 7); __tmp_1.as_pointer() },) { (__tmp_0,) => MoveConstructible::push_moved(&vec_.as_pointer(), (__tmp_0).clone()), } }; - object!(d, MoveOnly(8)); + object!(d, MoveOnly::constructor_1(8)); assign!(*vec_.decay().offset(0_usize) = RvalueRef(d)); assert!(({ (*vec_.borrow())[0_usize].v } == 8)); assert!(({ (*d.borrow()).v } == 0)); - object!(m, ConstMoveAssign); - object!(m1, ConstMoveAssign); - object!(m2, ConstMoveAssign); - object!(cm, ConstMoveAssign); + object!(m, ConstMoveAssign::constructor_1()); + object!(m1, ConstMoveAssign::constructor_1()); + object!(m2, ConstMoveAssign::constructor_1()); + object!(cm, ConstMoveAssign::constructor_1()); ConstMoveAssign::operator_assign_2(m1.as_pointer(), m.as_pointer()); ConstMoveAssign::operator_assign_3(m2.as_pointer(), cm.as_pointer()); assert!(({ (*m1.borrow()).mark } == 1)); diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index f87768df30..d1b1faf1c4 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -7,60 +7,67 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub v: i32, } impl MoveOnly { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, RvalueRef)] +#[constructor(constructor_3, RvalueRef>)] #[byte_size(4)] pub struct ConstMove { #[offset(0)] pub mark: i32, } impl ConstMove { - pub fn construct_1(this: Ptr, o: Ptr) { + pub fn constructor_1(this: Ptr) { + field!(this, mark).write(0); + } + pub fn constructor_2(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 1)); } - pub fn construct_2(this: Ptr, o: Ptr) { + pub fn constructor_3(this: Ptr, o: RvalueRef>) { + let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 10)); } } -impl DefaultConstructible for ConstMove { - fn default_constructor(this: Ptr) { - field!(this, mark).write(0); - } -} impl Default for ConstMove { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ConstMove::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct ThrowingMove { #[offset(0)] @@ -71,22 +78,18 @@ pub struct ThrowingMove { pub moves: i32, } impl ThrowingMove { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for ThrowingMove { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); 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: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); @@ -95,9 +98,12 @@ impl MoveConstructible for ThrowingMove { } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct NoexceptMove { #[offset(0)] @@ -108,22 +114,18 @@ pub struct NoexceptMove { pub moves: i32, } impl NoexceptMove { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for NoexceptMove { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); 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: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); @@ -131,12 +133,13 @@ impl MoveConstructible for NoexceptMove { field!(o, v).write(0); } } -pub fn by_value_0(m: Ptr) -> i32 { +pub fn by_value_0(m: ParameterObject) -> i32 { + let m = m.as_pointer(); return m.with(|__s| __s.v); } pub fn make_1(__return: Ptr, mut v: i32) { - object!(m, MoveOnly(v)); - MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind(m.as_pointer())); + object!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return.clone(), RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -144,75 +147,87 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, MoveOnly(1)); - object!(b, MoveOnly, RvalueRef::bind(a.as_pointer())); + object!(a, MoveOnly::constructor_1(1)); + object!(b, MoveOnly::constructor_3(RvalueRef::bind(a.as_pointer()))); assert!(({ (*b.borrow()).v } == 1)); assert!(({ (*a.borrow()).v } == 0)); - object!(c, MoveOnly, RvalueRef::bind(b.as_pointer())); + object!(c, MoveOnly::constructor_3(RvalueRef::bind(b.as_pointer()))); assert!(({ (*c.borrow()).v } == 1)); assert!(({ (*b.borrow()).v } == 0)); - object!(d, MoveOnly, RvalueRef::bind(c.as_pointer())); + object!(d, MoveOnly::constructor_3(RvalueRef::bind(c.as_pointer()))); assert!(({ (*d.borrow()).v } == 1)); assert!(({ (*c.borrow()).v } == 0)); object!(e, MoveOnly, |e| ({ make_1(Ptr::clone(&e.clone()), 5,) })); assert!(({ (*e.borrow()).v } == 5)); assert!( (({ - let _m: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnly::construct(_m.as_pointer(), 6); - by_value_0(_m.as_pointer()) + let _m: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(_m.as_pointer(), 6); + by_value_0(ParameterObject::bind(_m.as_pointer())) }) == 6) ); assert!( (({ - let _m: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(_m.as_pointer(), RvalueRef::bind(e.as_pointer())); - by_value_0(_m.as_pointer()) + let _m: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_3(_m.as_pointer(), RvalueRef::bind(e.as_pointer())); + by_value_0(ParameterObject::bind(_m.as_pointer())) }) == 5) ); assert!(({ (*e.borrow()).v } == 0)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - MoveOnly::construct(__tmp_1.as_pointer(), 7); + MoveOnly::constructor_1(__tmp_1.as_pointer(), 7); __tmp_1.as_pointer() },) { (__tmp_0,) => MoveConstructible::push_moved(&vec_.as_pointer(), (__tmp_0).clone()), } }; - object!(f, MoveOnly(8)); + object!(f, MoveOnly::constructor_1(8)); MoveConstructible::push_moved(&vec_.as_pointer(), f.as_pointer()); assert!(({ (*vec_.borrow())[0_usize].v } == 7) && ({ (*vec_.borrow())[1_usize].v } == 8)); assert!(({ (*f.borrow()).v } == 0)); - object!(m, ConstMove); - object!(m1, ConstMove::construct_1(m.as_pointer())); - object!(cm, ConstMove); - object!(m2, ConstMove::construct_2(cm.as_pointer())); + object!(m, ConstMove::constructor_1()); + object!( + m1, + ConstMove::constructor_2(RvalueRef::bind(m.as_pointer())) + ); + object!(cm, ConstMove::constructor_1()); + object!( + m2, + ConstMove::constructor_3(RvalueRef::bind(cm.as_pointer())) + ); assert!(({ (*m1.borrow()).mark } == 1)); assert!(({ (*m2.borrow()).mark } == 10)); - object!(t, ThrowingMove(1)); - object!(t1, ThrowingMove, LvalueRef::bind(t.as_pointer())); + object!(t, ThrowingMove::constructor_1(1)); + object!( + t1, + ThrowingMove::constructor_2(LvalueRef::bind(t.as_pointer())) + ); assert!(({ (*t1.borrow()).v } == 1)); assert!(({ (*t1.borrow()).copies } == 1)); assert!(({ (*t1.borrow()).moves } == 0)); assert!(({ (*t.borrow()).v } == 1)); - object!(n, NoexceptMove(2)); - object!(n1, NoexceptMove, RvalueRef::bind(n.as_pointer())); + object!(n, NoexceptMove::constructor_1(2)); + object!( + n1, + NoexceptMove::constructor_3(RvalueRef::bind(n.as_pointer())) + ); assert!(({ (*n1.borrow()).v } == 2)); assert!(({ (*n1.borrow()).copies } == 0)); assert!(({ (*n1.borrow()).moves } == 1)); assert!(({ (*n.borrow()).v } == 0)); - object!(g, MoveOnly(3)); - object!(g1, MoveOnly, RvalueRef::bind(g.as_pointer())); + object!(g, MoveOnly::constructor_1(3)); + object!(g1, MoveOnly::constructor_3(RvalueRef::bind(g.as_pointer()))); assert!(({ (*g1.borrow()).v } == 3)); assert!(({ (*g.borrow()).v } == 0)); let nv: Value> = Rc::new(RefCell::new(Vec::new())); { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - NoexceptMove::construct(__tmp_3.as_pointer(), 4); + NoexceptMove::constructor_1(__tmp_3.as_pointer(), 4); __tmp_3.as_pointer() },) { diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index 8af642151c..a3f1965027 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -7,18 +7,30 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct Chain { #[offset(0)] pub v: i32, } impl Chain { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } + pub fn constructor_2(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); + field!(this, v).write((o.with(|__s| __s.v) + 100)); + } + pub fn constructor_3(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); + field!(this, v).write((o.with(|__s| __s.v) + 1)); + field!(o, v).write(0); + } pub fn add_4(this: Ptr, mut n: i32) -> Ptr { { field!(this, v).with_mut(|__v| *__v = *__v + n) @@ -32,31 +44,19 @@ impl Chain { return (this).clone(); } pub fn take(this: Ptr, __return: Ptr) { - MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((this).clone())); + Chain::constructor_3(__return.clone(), RvalueRef::bind((this).clone())); return; } pub fn copy(this: Ptr, __return: Ptr) { - CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind((this).clone())); + Chain::constructor_2(__return.clone(), LvalueRef::bind((this).clone())); return; } pub fn self_(this: Ptr) -> Ptr { return (this).clone(); } } -impl CopyConstructible for Chain { - fn copy_constructor(this: Ptr, o: LvalueRef>) { - let o = o.as_pointer(); - field!(this, v).write((o.with(|__s| __s.v) + 100)); - } -} -impl MoveConstructible for Chain { - fn move_constructor(this: Ptr, o: RvalueRef) { - let o = o.as_pointer(); - field!(this, v).write((o.with(|__s| __s.v) + 1)); - field!(o, v).write(0); - } -} -pub fn consume_0(c: Ptr) -> i32 { +pub fn consume_0(c: ParameterObject) -> i32 { + let c = c.as_pointer(); return c.with(|__s| __s.v); } pub fn main() { @@ -64,22 +64,23 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Chain(1)); + object!(a, Chain::constructor_1(1)); ({ Chain::add_4(({ Chain::add_4(a.as_pointer(), 1) }), 1) }); assert!(({ (*a.borrow()).v } == 3)); - object!(b0, Chain(5)); + object!(b0, Chain::constructor_1(5)); object!( b, - Chain, - RvalueRef::bind(({ Chain::add_5(({ Chain::add_5(b0.as_pointer(), 1,) }), 1,) })) + Chain::constructor_3(RvalueRef::bind( + ({ Chain::add_5(({ Chain::add_5(b0.as_pointer(), 1,) }), 1,) }) + )) ); assert!(({ (*b.borrow()).v } == 8) && ({ (*b0.borrow()).v } == 0)); object!(c, Chain, |c| { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ Chain::take( { - Chain::construct(__tmp_0.as_pointer(), 10); + Chain::constructor_1(__tmp_0.as_pointer(), 10); __tmp_0.as_pointer() }, Ptr::clone(&c.clone()), @@ -91,18 +92,18 @@ fn main_0() -> i32 { Chain::copy(c.as_pointer(), Ptr::clone(&d.clone())) })); assert!(({ (*d.borrow()).v } == 111) && ({ (*c.borrow()).v } == 11)); - object!(g, Chain(20)); + object!(g, Chain::constructor_1(20)); assert!( (({ - let _c: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + let _c: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Chain::constructor_3( _c.as_pointer(), RvalueRef::bind(({ Chain::self_(g.as_pointer()) })), ); - consume_0(_c.as_pointer()) + consume_0(ParameterObject::bind(_c.as_pointer())) }) == 21) ); - object!(e, Chain(30)); + object!(e, Chain::constructor_1(30)); object!(f, Chain, |f| ({ Chain::take(e.as_pointer(), Ptr::clone(&f.clone())) })); diff --git a/tests/unit/out/refcount/nested_structs.rs b/tests/unit/out/refcount/nested_structs.rs index e88997c5c7..ba856f8057 100644 --- a/tests/unit/out/refcount/nested_structs.rs +++ b/tests/unit/out/refcount/nested_structs.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Level0_Level1_1_Level2_1_Level3_1 { #[offset(0)] @@ -34,7 +36,9 @@ pub struct Level0_Level1_1_Level2_1_Level3_1 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Level0_Level1_1_Level2_1_Level3_2 { #[offset(0)] @@ -53,7 +57,9 @@ pub struct Level0_Level1_1_Level2_1_Level3_2 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Level0_Level1_1_Level2_1 { #[offset(0)] @@ -70,7 +76,9 @@ pub struct Level0_Level1_1_Level2_1 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Level0_Level1_1 { #[offset(0)] @@ -87,7 +95,9 @@ pub struct Level0_Level1_1 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Level0_Level1_2 { #[offset(0)] @@ -106,7 +116,9 @@ pub struct Level0_Level1_2 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Level0 {} pub fn main() { diff --git a/tests/unit/out/refcount/netdb.rs b/tests/unit/out/refcount/netdb.rs index c425dd26cf..0012c957b8 100644 --- a/tests/unit/out/refcount/netdb.rs +++ b/tests/unit/out/refcount/netdb.rs @@ -52,8 +52,6 @@ pub fn test_ipv4_literal_0() { __addrs.push(::std::net::IpAddr::V4(::std::net::Ipv4Addr::UNSPECIFIED)); } } else { - // A host name that is not UTF-8 is not found, as the resolver takes a - // str. match Ptr::::from_string_literal(b"127.0.0.1") .with_c_bytes(|__s| str::from_utf8(__s).map(str::to_owned)) { @@ -199,8 +197,6 @@ pub fn test_ipv6_literal_1() { __addrs.push(::std::net::IpAddr::V4(::std::net::Ipv4Addr::UNSPECIFIED)); } } else { - // A host name that is not UTF-8 is not found, as the resolver takes a - // str. match Ptr::::from_string_literal(b"::1") .with_c_bytes(|__s| str::from_utf8(__s).map(str::to_owned)) { @@ -338,8 +334,6 @@ pub fn test_null_hints_2() { __addrs.push(::std::net::IpAddr::V4(::std::net::Ipv4Addr::UNSPECIFIED)); } } else { - // A host name that is not UTF-8 is not found, as the resolver takes a - // str. match Ptr::::from_string_literal(b"127.0.0.1") .with_c_bytes(|__s| str::from_utf8(__s).map(str::to_owned)) { diff --git a/tests/unit/out/refcount/new.rs b/tests/unit/out/refcount/new.rs index 8b075a627b..70b58d0ede 100644 --- a/tests/unit/out/refcount/new.rs +++ b/tests/unit/out/refcount/new.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 84d527d72b..912c97f12f 100644 --- a/tests/unit/out/refcount/new_bst.rs +++ b/tests/unit/out/refcount/new_bst.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 f7d7b59779..500d0aa66f 100644 --- a/tests/unit/out/refcount/new_struct.rs +++ b/tests/unit/out/refcount/new_struct.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -36,7 +38,9 @@ pub struct Pair { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 048c716494..0aff173c99 100644 --- a/tests/unit/out/refcount/nttp_distinct_specializations.rs +++ b/tests/unit/out/refcount/nttp_distinct_specializations.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct S_2_ { #[offset(0)] @@ -41,7 +43,9 @@ impl S_2_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct S_1_ { #[offset(0)] @@ -63,7 +67,9 @@ impl S_1_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 5e769a9cf3..a3be2b5e09 100644 --- a/tests/unit/out/refcount/offsetof.rs +++ b/tests/unit/out/refcount/offsetof.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(12)] pub struct Layout { #[offset(0)] @@ -36,7 +38,9 @@ pub struct Layout { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[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 57e54cc913..c253a00c35 100644 --- a/tests/unit/out/refcount/opaque_forward_decl.rs +++ b/tests/unit/out/refcount/opaque_forward_decl.rs @@ -36,7 +36,9 @@ fn main_0() -> i32 { }; return (c.x - 42); } -#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] +#[derive( + Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg, ZeroInitialization, Destructible, Conversions, +)] #[byte_size(1)] pub struct opaque; pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/opaque_record_copy.rs b/tests/unit/out/refcount/opaque_record_copy.rs index 05c563cafd..dd60c43296 100644 --- a/tests/unit/out/refcount/opaque_record_copy.rs +++ b/tests/unit/out/refcount/opaque_record_copy.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Probe {} #[derive( @@ -31,7 +33,9 @@ pub struct Probe {} TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Wrapper_Probe_ { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_arithmetic_free.rs b/tests/unit/out/refcount/operator_arithmetic_free.rs index 6aa2ec1264..fbfe6b0329 100644 --- a/tests/unit/out/refcount/operator_arithmetic_free.rs +++ b/tests/unit/out/refcount/operator_arithmetic_free.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 37a0b9d95d..8b8915f4cb 100644 --- a/tests/unit/out/refcount/operator_arithmetic_member.rs +++ b/tests/unit/out/refcount/operator_arithmetic_member.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 ba2321d034..27a0128cfa 100644 --- a/tests/unit/out/refcount/operator_bitwise_free.rs +++ b/tests/unit/out/refcount/operator_bitwise_free.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 0599c2fb9c..b2177ac0fb 100644 --- a/tests/unit/out/refcount/operator_bitwise_member.rs +++ b/tests/unit/out/refcount/operator_bitwise_member.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 a511b9ee95..5a2c77a088 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Eq { #[offset(0)] @@ -39,6 +41,8 @@ pub struct Eq { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct Cmp { #[offset(0)] @@ -89,6 +93,8 @@ impl LessThanComparable for Cmp { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct Both { #[offset(0)] @@ -128,6 +134,8 @@ impl LessThanComparable for Both { PartiallyOrderedWith, )] #[three_way(OrdOnly::operator_cmp)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct OrdOnly { #[offset(0)] @@ -166,6 +174,8 @@ impl LessThanComparable for OrdOnly { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct Inner { #[offset(0)] @@ -205,6 +215,8 @@ impl LessThanComparable for Inner { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct Outer { #[offset(0)] @@ -252,7 +264,9 @@ impl LessThanComparable for Outer { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Secondary { #[offset(0)] @@ -291,6 +305,8 @@ impl LessThanComparable for Secondary { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[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 00fa12bc4e..8601f21645 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -45,7 +47,9 @@ pub fn operator_lt_1(mut a: i32, b: Ptr) -> bool { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 95230986c7..acadd8cc62 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 999d5b316a..76333aa36a 100644 --- a/tests/unit/out/refcount/operator_comparison_mixed.rs +++ b/tests/unit/out/refcount/operator_comparison_mixed.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 8c03fcda7f..fe5d82ba36 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct X { #[offset(0)] @@ -57,7 +59,9 @@ pub fn operator_ge_3(mut a: X, mut b: X) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Result { #[offset(0)] @@ -74,7 +78,9 @@ pub struct Result { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Custom { #[offset(0)] @@ -98,7 +104,9 @@ impl Custom { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Mixed { #[offset(0)] @@ -138,19 +146,21 @@ impl LessThanComparable for Mixed { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_into(bool, to_bool)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, bool)] +#[conversion_function(to_bool, LvalueRef>, bool )] #[byte_size(1)] pub struct MyBool { #[offset(0)] pub value: bool, } impl MyBool { - pub fn construct(this: Ptr, mut v: bool) { + pub fn constructor_1(this: Ptr, mut v: bool) { field!(this, value).write(v); } pub fn to_bool(this: Ptr) -> bool { @@ -168,7 +178,9 @@ impl MyBool { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Boolish { #[offset(0)] @@ -184,15 +196,15 @@ impl LessThanComparable for Boolish { } pub fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MyBool::construct(__v.as_pointer(), (a.v == b.v)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MyBool::constructor_1(__v.as_pointer(), (a.v == b.v)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MyBool::construct(__v.as_pointer(), (a.v < b.v)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MyBool::constructor_1(__v.as_pointer(), (a.v < b.v)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -201,21 +213,22 @@ pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveAssignable, Default, )] #[memberwise(copy_assign)] -#[cpp_into(bool, to_bool)] +#[derive(Conversions)] +#[constructor(constructor_1, explicit, bool)] +#[conversion_function(to_bool, LvalueRef>, bool )] #[byte_size(1)] pub struct RefBool { #[offset(0)] pub value: bool, } impl RefBool { - pub fn construct(this: Ptr, mut v: bool) { + pub fn constructor_1(this: Ptr, mut v: bool) { field!(this, value).write(v); } pub fn to_bool(this: Ptr) -> bool { @@ -224,8 +237,8 @@ impl RefBool { } thread_local!( pub static ref_true_8: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefBool::construct(__v.as_pointer(), true); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefBool::constructor_1(__v.as_pointer(), true); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -240,7 +253,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 5428aa4572..100f191845 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -12,24 +12,19 @@ impl LessThanComparable for S { } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct S { #[offset(0)] data_: i32, } impl S { - pub fn construct(this: Ptr, mut data: i32) { + pub fn constructor_1(this: Ptr, mut data: i32) { field!(this, data_).write(data); } } @@ -38,9 +33,9 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, S(1)); - object!(b, S(2)); - object!(c, S(1)); + object!(a, S::constructor_1(1)); + object!(b, S::constructor_1(2)); + object!(c, S::constructor_1(1)); assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); assert!(({ LessThanComparable::less(a.as_pointer(), b.as_pointer(),) })); assert!(!({ LessThanComparable::less(b.as_pointer(), a.as_pointer(),) })); diff --git a/tests/unit/out/refcount/operator_compound_assignment_free.rs b/tests/unit/out/refcount/operator_compound_assignment_free.rs index ccde867cc8..a41d9466f0 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_free.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_free.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 74ff0168e0..752e0a4e1f 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_member.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_member.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 e22d7ed68c..73a37d4914 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Defaulted { #[offset(0)] @@ -54,6 +56,8 @@ impl ThreeWayComparable for DefaultedOrd { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct DefaultedOrd { #[offset(0)] @@ -85,7 +89,9 @@ pub fn operator_add_0(x: Ptr, y: Ptr) -> Inline { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Inline { #[offset(0)] @@ -102,7 +108,9 @@ pub struct Inline { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct OutOfLine { #[offset(0)] @@ -124,7 +132,9 @@ impl LessThanComparable for Tmpl_int_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Tmpl_int_ { #[offset(0)] @@ -141,7 +151,9 @@ pub struct Tmpl_int_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Tmpl_long_ { #[offset(0)] @@ -158,7 +170,9 @@ pub struct Tmpl_long_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 b62e640d02..92681a1bd6 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 00c15017c1..aadf9531f8 100644 --- a/tests/unit/out/refcount/operator_logical_free.rs +++ b/tests/unit/out/refcount/operator_logical_free.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 f00dcd2c1a..cbb4b85656 100644 --- a/tests/unit/out/refcount/operator_logical_member.rs +++ b/tests/unit/out/refcount/operator_logical_member.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 dc1f21b0e5..ddd80ba8d8 100644 --- a/tests/unit/out/refcount/operator_member_pointer_free.rs +++ b/tests/unit/out/refcount/operator_member_pointer_free.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Inner { #[offset(0)] @@ -32,7 +34,9 @@ pub struct Inner { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[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 47534cf43d..abb506ed45 100644 --- a/tests/unit/out/refcount/operator_member_pointer_member.rs +++ b/tests/unit/out/refcount/operator_member_pointer_member.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Inner { #[offset(0)] @@ -34,7 +36,9 @@ pub struct Inner { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Table {} impl Table { @@ -54,7 +58,9 @@ thread_local!( FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[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 b374fe8e7c..1dc7af38ef 100644 --- a/tests/unit/out/refcount/operator_other_free.rs +++ b/tests/unit/out/refcount/operator_other_free.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 462a8f50d7..e933c0b1ef 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_member.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Static {} impl Static { @@ -33,12 +35,14 @@ impl Static { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_into(i32, to_i32)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRef>, i32 )] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_overloads.rs b/tests/unit/out/refcount/operator_overloads.rs index 9c04822e52..b74cfdd244 100644 --- a/tests/unit/out/refcount/operator_overloads.rs +++ b/tests/unit/out/refcount/operator_overloads.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 40680854c3..93b109eb64 100644 --- a/tests/unit/out/refcount/operator_qualifiers.rs +++ b/tests/unit/out/refcount/operator_qualifiers.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 96e874ef02..3174e5eb07 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -20,6 +20,8 @@ use std::rc::{Rc, Weak}; PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[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 3327a1528d..1d662beb1d 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Lt { #[offset(0)] @@ -39,7 +41,9 @@ impl LessThanComparable for Lt { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Eq { #[offset(0)] @@ -59,6 +63,8 @@ pub struct Eq { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct Cmp { #[offset(0)] @@ -89,7 +95,9 @@ impl LessThanComparable for Cmp { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Free { #[offset(0)] @@ -111,7 +119,9 @@ impl LessThanComparable for Free { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 7de23c49e2..cba600c702 100644 --- a/tests/unit/out/refcount/overload_mangling.rs +++ b/tests/unit/out/refcount/overload_mangling.rs @@ -30,7 +30,9 @@ pub fn twice_2(mut n: i32) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Access_S_ {} impl Access_S_ { @@ -58,7 +60,9 @@ impl Access_S_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -152,7 +156,9 @@ impl S { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Box_ { #[offset(0)] diff --git a/tests/unit/out/refcount/pair.rs b/tests/unit/out/refcount/pair.rs index ae6933b441..5140efef8b 100644 --- a/tests/unit/out/refcount/pair.rs +++ b/tests/unit/out/refcount/pair.rs @@ -30,14 +30,24 @@ fn main_0() -> i32 { ))) .as_pointer(),) { - (__tmp_0,) => ( - Rc::new(RefCell::new( - (((*__tmp_0.upgrade().deref()).0.as_pointer().read()) as f64), - )), - Rc::new(RefCell::new( - ((*__tmp_0.upgrade().deref()).1.as_pointer().read()), - )), - ), + (__tmp_0,) => { + object!(__first, f64, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_0.upgrade().deref()).0.as_pointer() + ),) + )); + object!(__second, i32, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_0.upgrade().deref()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + } }, )); assert!(({ ((*(*p3.borrow()).0.borrow()) == 5_f64) })); @@ -60,10 +70,22 @@ fn main_0() -> i32 { .as_pointer(), ) { (__tmp_1, __tmp_2) => { - let __first = cpp_move!((*__tmp_2.upgrade().deref()).0.as_pointer()); - let __second = (((*__tmp_2.upgrade().deref()).1.as_pointer().read()) as u64); - *(*__tmp_1.upgrade().deref()).0.borrow_mut() = __first; - *(*__tmp_1.upgrade().deref()).1.borrow_mut() = __second; + object!(__first, Ptr, |__this| ConvertibleTo::convert( + RvalueRef::>::bind((*__tmp_2.upgrade().deref()).0.as_pointer()), + __this + )); + object!(__second, u64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*__tmp_2.upgrade().deref()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*__tmp_1.upgrade().deref()).0.as_pointer(), + RvalueRef::>::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*__tmp_1.upgrade().deref()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); } }; assert!( @@ -132,10 +154,22 @@ fn main_0() -> i32 { ))); let mut pw: Ptr = ((*w.borrow()).0.as_pointer()); { - let __first = (((*narrow.borrow()).0.as_pointer().read()) as i64); - let __second = (((*narrow.borrow()).1.as_pointer().read()) as i64); - *(*w.borrow()).0.borrow_mut() = __first; - *(*w.borrow()).1.borrow_mut() = __second; + object!(__first, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).0.as_pointer()), + __this + )); + object!(__second, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*w.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*w.borrow()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); }; assert!(((pw.read()) == 3_i64)); let m: Value<(Value, Value)> = Rc::new(RefCell::new(( @@ -143,10 +177,22 @@ fn main_0() -> i32 { Rc::new(RefCell::new(6)), ))); { - let __first = (((*m.borrow()).0.as_pointer().read()) as i64); - let __second = (((*m.borrow()).1.as_pointer().read()) as i64); - *(*w.borrow()).0.borrow_mut() = __first; - *(*w.borrow()).1.borrow_mut() = __second; + object!(__first, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*m.borrow()).0.as_pointer()), + __this + )); + object!(__second, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*m.borrow()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*w.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*w.borrow()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); }; assert!(((pw.read()) == 5_i64)); (*(*{ @@ -170,10 +216,22 @@ fn main_0() -> i32 { .borrow_mut()) = 8; assert!(({ ((*(*d.borrow()).0.borrow()) == 8) && ((*(*d.borrow()).1.borrow()) == 4) })); (*(*{ - let __first = (((*narrow.borrow()).0.as_pointer().read()) as i64); - let __second = (((*narrow.borrow()).1.as_pointer().read()) as i64); - *(*w.borrow()).0.borrow_mut() = __first; - *(*w.borrow()).1.borrow_mut() = __second; + object!(__first, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).0.as_pointer()), + __this + )); + object!(__second, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*w.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*w.borrow()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); w.as_pointer() } .upgrade() @@ -182,10 +240,22 @@ fn main_0() -> i32 { .borrow_mut()) = 9_i64; assert!(({ ((*(*w.borrow()).0.borrow()) == 3_i64) && ((*(*w.borrow()).1.borrow()) == 9_i64) })); (*(*{ - let __first = (((*narrow.borrow()).0.as_pointer().read()) as i64); - let __second = (((*narrow.borrow()).1.as_pointer().read()) as i64); - *(*w.borrow()).0.borrow_mut() = __first; - *(*w.borrow()).1.borrow_mut() = __second; + object!(__first, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*narrow.borrow()).0.as_pointer()), + __this + )); + object!(__second, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*narrow.borrow()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*w.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*w.borrow()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); w.as_pointer() } .upgrade() diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index 437a960d52..bf4a93e669 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -14,19 +14,20 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Celsius { #[offset(0)] pub degrees: i32, } impl Celsius { - pub fn construct(this: Ptr, mut d: i32) { + pub fn constructor_1(this: Ptr, mut d: i32) { field!(this, degrees).write(d); } } @@ -38,12 +39,13 @@ impl Celsius { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_into(i32, to_i32)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRef>, i32 )] #[byte_size(4)] pub struct Meters { #[offset(0)] @@ -62,19 +64,21 @@ impl Meters { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(Celsius, construct, ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1, LvalueRef>)] #[byte_size(4)] pub struct Label { #[offset(0)] pub id: i32, } impl Label { - pub fn construct(this: Ptr, c: Ptr) { + pub fn constructor_1(this: Ptr, c: LvalueRef>) { + let c = c.as_pointer(); field!(this, id).write(c.with(|__s| __s.degrees)); } } @@ -86,13 +90,14 @@ impl Label { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(Celsius, construct_1, ptr)] -#[cpp_from_move(Celsius, construct_2, ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1, LvalueRef>)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(8)] pub struct Owner { #[offset(0)] @@ -101,11 +106,13 @@ pub struct Owner { pub copied: i32, } impl Owner { - pub fn construct_1(this: Ptr, c: Ptr) { + pub fn constructor_1(this: Ptr, c: LvalueRef>) { + let c = c.as_pointer(); field!(this, taken).write(0); field!(this, copied).write(c.with(|__s| __s.degrees)); } - pub fn construct_2(this: Ptr, c: Ptr) { + pub fn constructor_2(this: Ptr, c: RvalueRef) { + let c = c.as_pointer(); field!(this, taken).write(c.with(|__s| __s.degrees)); field!(this, copied).write(0); } @@ -118,40 +125,50 @@ impl Owner { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(Celsius, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, Celsius)] #[byte_size(4)] pub struct Holder { #[offset(0)] pub value: i32, } impl Holder { - pub fn construct(this: Ptr, mut c: Celsius) { + pub fn constructor_1(this: Ptr, mut c: Celsius) { field!(this, value).write(c.degrees); } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, TriviallyCopyable, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Fallback { #[offset(0)] pub value: i32, } impl Fallback { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, value).write(v); } } -impl DefaultConstructible for Fallback { - fn default_constructor(this: Ptr) { +impl Constructor<()> for Fallback { + fn constructor(this: Ptr, _: ()) { { - Fallback::construct(this.clone(), -1_i32); + Fallback::constructor_1(this.clone(), -1_i32); } } } @@ -159,8 +176,8 @@ impl Default for Fallback { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Fallback::construct(__v.as_pointer(), -1_i32); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Fallback::constructor_1(__v.as_pointer(), -1_i32); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -177,7 +194,9 @@ impl Default for Fallback { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Counter { #[offset(0)] @@ -191,25 +210,28 @@ pub struct Counter { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(Counter, construct, mut_ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1, LvalueRef)] #[byte_size(4)] pub struct Observer { #[offset(0)] pub seen: i32, } impl Observer { - pub fn construct(this: Ptr, c: Ptr) { + pub fn constructor_1(this: Ptr, c: LvalueRef) { + let c = c.as_pointer(); field!(this, seen).write(c.with(|__s| __s.hits)); field!(c, hits).with_mut(|__v| __v.postfix_inc()); } } impl Tag { - pub fn construct(this: Ptr, u: Ptr) { + pub fn constructor_1_1(this: Ptr, u: LvalueRef>) { + let u = u.as_pointer(); field!(this, code).write((u.with(|__s| __s.degrees) + 100)); } } @@ -221,12 +243,13 @@ impl Tag { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(Celsius, construct, ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1_1, LvalueRef>)] #[byte_size(4)] pub struct Tag { #[offset(0)] @@ -240,19 +263,21 @@ pub struct Tag { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(Ptr< i8 > , construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, Pointer>)] #[byte_size(4)] pub struct Name { #[offset(0)] pub len: i32, } impl Name { - pub fn construct(this: Ptr, mut s: Ptr) { + pub fn constructor_1(this: Ptr, s: Pointer>) { + let mut s = s.as_pointer(); field!(this, len).write(0); 'loop_: while ((elem!(s, this.with(|__s| __s.len)).read()) != 0) { field!(this, len).with_mut(|__v| { @@ -274,13 +299,13 @@ fn main_0() -> i32 { assert!(({ ((*(*widened.borrow()).1.borrow()) == 2_u32) })); let from_ints: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Celsius::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Celsius::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Celsius::construct(__v.as_pointer(), 2); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Celsius::constructor_1(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ))); @@ -300,14 +325,24 @@ fn main_0() -> i32 { ))) .as_pointer(),) { - (__tmp_0,) => ( - Rc::new(RefCell::new( - (((*__tmp_0.upgrade().deref()).0.as_pointer().read()) as i64), - )), - Rc::new(RefCell::new( - (((*__tmp_0.upgrade().deref()).1.as_pointer().read()) as f64), - )), - ), + (__tmp_0,) => { + object!(__first, i64, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_0.upgrade().deref()).0.as_pointer() + ),) + )); + object!(__second, f64, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_0.upgrade().deref()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + } }, )); assert!(({ ((*(*from_moved_pair.borrow()).0.borrow()) == 3_i64) })); @@ -316,162 +351,245 @@ fn main_0() -> i32 { Rc::new(RefCell::new(5)), Rc::new(RefCell::new(6)), ))); - let from_copied_pair: Value<(Value, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new(>::cpp_from( - (*ints.borrow()).0.as_pointer(), - ))), - Rc::new(RefCell::new( - (((*ints.borrow()).1.as_pointer().read()) as i64), - )), - ))); + let from_copied_pair: Value<(Value, Value)> = Rc::new(RefCell::new({ + object!(__first, Celsius, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind( + (*ints.borrow()).0.as_pointer() + ),) + )); + object!(__second, i64, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind( + (*ints.borrow()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + })); assert!(({ (*(*from_copied_pair.borrow()).0.borrow()).degrees } == 5)); assert!(({ ((*(*from_copied_pair.borrow()).1.borrow()) == 6_i64) })); let meters: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new((Meters { value: 8 }))), Rc::new(RefCell::new((Meters { value: 9 }))), ))); - let from_operator_pair: Value<(Value, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new(>::cpp_from( - (*meters.borrow()).0.as_pointer(), - ))), - Rc::new(RefCell::new(>::cpp_from( - (*meters.borrow()).1.as_pointer(), - ))), - ))); + let from_operator_pair: Value<(Value, Value)> = Rc::new(RefCell::new({ + object!(__first, i32, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind( + (*meters.borrow()).0.as_pointer() + ),) + )); + object!(__second, i32, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind( + (*meters.borrow()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + })); assert!(({ ((*(*from_operator_pair.borrow()).0.borrow()) == 8) })); assert!(({ ((*(*from_operator_pair.borrow()).1.borrow()) == 9) })); let celsius: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Celsius::construct(__v.as_pointer(), 10); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Celsius::constructor_1(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Celsius::construct(__v.as_pointer(), 11); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Celsius::constructor_1(__v.as_pointer(), 11); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ))); - let from_record_pair: Value<(Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + A::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct B { #[offset(0)] pub v: i32, } -impl DefaultConstructible for B { - fn default_constructor(this: Ptr) { +impl B { + pub fn constructor_1(this: Ptr) { field!(this, v).write(2); } } @@ -51,8 +71,8 @@ impl Default for B { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + B::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,19 +86,20 @@ impl Default for B { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct NoDefault { #[offset(0)] pub v: i32, } impl NoDefault { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } } @@ -102,19 +123,20 @@ pub fn always_given_3(mut x: NoDefault) -> i32 { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct S_NoDefault_ { #[offset(0)] pub v: i32, } impl S_NoDefault_ { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } pub fn get(this: Ptr, mut t: NoDefault) -> i32 { @@ -129,8 +151,8 @@ fn main_0() -> i32 { assert!( (({ used_0({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + A::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 1) @@ -138,8 +160,8 @@ fn main_0() -> i32 { assert!( (({ used_0({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - A::construct_1(__v.as_pointer(), 5); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + A::constructor_2(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 5) @@ -147,8 +169,8 @@ fn main_0() -> i32 { assert!( (({ used_1({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + B::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 2) @@ -157,8 +179,8 @@ fn main_0() -> i32 { (({ scaled_2( { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - A::construct_1(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + A::constructor_2(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, (4usize as i32), @@ -169,8 +191,8 @@ fn main_0() -> i32 { (({ scaled_2( { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - A::construct_1(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + A::constructor_2(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, 2, @@ -180,18 +202,18 @@ fn main_0() -> i32 { assert!( (({ always_given_3({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoDefault::construct(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NoDefault::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 3) ); - object!(s, S_NoDefault_(1)); + object!(s, S_NoDefault_::constructor_1(1)); assert!( (({ S_NoDefault_::get(s.as_pointer(), { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoDefault::construct(__v.as_pointer(), 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NoDefault::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 5) diff --git a/tests/unit/out/refcount/template_static_member.rs b/tests/unit/out/refcount/template_static_member.rs index 8f0105ef25..4a3e57b40f 100644 --- a/tests/unit/out/refcount/template_static_member.rs +++ b/tests/unit/out/refcount/template_static_member.rs @@ -20,7 +20,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Static_int_ {} thread_local!( @@ -37,7 +39,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Static_char_ {} thread_local!( @@ -54,7 +58,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Static_long_ {} thread_local!( @@ -74,7 +80,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct Range_int_ {} thread_local!( @@ -94,7 +102,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 fff18c3bc5..ab371a0ab0 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -20,14 +20,17 @@ use std::rc::{Rc, Weak}; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Inner { #[offset(0)] #[byte_size(24)] pub values: Vec, } -impl DefaultConstructible for Inner { - fn default_constructor(this: Ptr) { +impl Inner { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); } } @@ -44,6 +47,9 @@ impl DefaultConstructible for Inner { Swappable, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(56)] pub struct Outer { #[offset(0)] @@ -57,10 +63,10 @@ pub struct Outer { #[array_len(8)] pub name: Box<[i8]>, } -impl DefaultConstructible for Outer { - fn default_constructor(this: Ptr) { +impl Outer { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); - DefaultConstructible::default_constructor(field_ptr!(this, inner)); + Inner::constructor_1(field_ptr!(this, inner)); field!(this, name).write((0..8).map(|_| 0_i8).collect::>()); } } @@ -103,7 +109,7 @@ pub fn main() { fn main_0() -> i32 { let calls: Value = Rc::new(RefCell::new(0)); let mut member: i32 = { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ sum_1( (match { @@ -116,7 +122,7 @@ fn main_0() -> i32 { }) }; let mut nested: i32 = { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ sum_1( (match { @@ -129,7 +135,7 @@ fn main_0() -> i32 { }) }; let mut element: i32 = { - let __tmp_6: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_6: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match ( (match { ({ make_0(Ptr::clone(&__tmp_6.as_pointer()), calls.as_pointer()) }); @@ -149,7 +155,7 @@ fn main_0() -> i32 { .read()) }; let mut length: usize = { - let __tmp_9: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_9: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match { ({ make_0(Ptr::clone(&__tmp_9.as_pointer()), calls.as_pointer()) }); __tmp_9.as_pointer() diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index 13657670a7..b908d68d41 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -20,14 +20,17 @@ use std::rc::{Rc, Weak}; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Outer { #[offset(0)] #[byte_size(24)] pub values: Vec, } -impl DefaultConstructible for Outer { - fn default_constructor(this: Ptr) { +impl Outer { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); } } @@ -45,19 +48,20 @@ pub fn make_0(__return: Ptr) { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(Vec , construct, ptr)] +#[conversions(copy, move)] #[byte_size(4)] pub struct H { #[offset(0)] pub last: i32, } impl H { - pub fn construct(this: Ptr, values: Ptr>) { + pub fn constructor_1(this: Ptr, values: LvalueRef>>) { + let values = values.as_pointer(); field!(this, last).write((index!(values, 3_usize).read())); } } @@ -67,15 +71,17 @@ pub fn main() { } fn main_0() -> i32 { object!(h, H, |h| { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); - H::construct( + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + H::constructor_1( h.clone(), - (match { - ({ make_0(Ptr::clone(&__tmp_1.as_pointer())) }); - __tmp_1.as_pointer() - } { - __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), - }), + LvalueRef::bind( + (match { + ({ make_0(Ptr::clone(&__tmp_1.as_pointer())) }); + __tmp_1.as_pointer() + } { + __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), + }), + ), ) }); printf!(b"%d\n", { (*h.borrow()).last }); diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index 5dfcce5ada..d528835867 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -20,14 +20,17 @@ use std::rc::{Rc, Weak}; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Inner { #[offset(0)] #[byte_size(24)] pub values: Vec, } -impl DefaultConstructible for Inner { - fn default_constructor(this: Ptr) { +impl Inner { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); } } @@ -45,6 +48,9 @@ impl DefaultConstructible for Inner { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct Outer { #[offset(0)] @@ -54,10 +60,10 @@ pub struct Outer { #[byte_size(24)] pub inner: Inner, } -impl DefaultConstructible for Outer { - fn default_constructor(this: Ptr) { +impl Outer { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); - DefaultConstructible::default_constructor(field_ptr!(this, inner)); + Inner::constructor_1(field_ptr!(this, inner)); } } pub fn make_0(__return: Ptr) { @@ -78,8 +84,8 @@ pub fn main() { } fn main_0() -> i32 { { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); printf!( b"%d\n", ({ diff --git a/tests/unit/out/refcount/this.rs b/tests/unit/out/refcount/this.rs index 6967f7c14c..cf648bb3b7 100644 --- a/tests/unit/out/refcount/this.rs +++ b/tests/unit/out/refcount/this.rs @@ -13,12 +13,15 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct_1, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, i32 , Pointer)] +#[constructor(constructor_3, i32 , Pointer>)] #[byte_size(16)] pub struct S { #[offset(0)] @@ -28,11 +31,12 @@ pub struct S { pub self__: Ptr, } impl S { - pub fn construct_1(this: Ptr, mut a: i32) { + pub fn constructor_1(this: Ptr, mut a: i32) { field!(this, a_).write(a); field!(this, self__).write(Ptr::::null()); } - pub fn construct_2(this: Ptr, mut a: i32, mut other: Ptr) { + pub fn constructor_2(this: Ptr, mut a: i32, other: Pointer) { + let mut other = other.as_pointer(); field!(this, a_).write(a); field!(this, self__).write(Ptr::::null()); if (this == other) { @@ -41,7 +45,8 @@ impl S { field!(this, self__).write((other).clone()); } } - pub fn construct_3(this: Ptr, mut a: i32, mut other: Ptr) { + pub fn constructor_3(this: Ptr, mut a: i32, other: Pointer>) { + let mut other = other.as_pointer(); field!(this, a_).write(a); field!(this, self__).write(Ptr::::null()); if (this == other) { @@ -84,8 +89,8 @@ impl S { } pub fn reset(this: Ptr) { let __rhs = { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - S::construct_1(__v.as_pointer(), 0); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::constructor_1(__v.as_pointer(), 0); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; this.write(__rhs); @@ -118,19 +123,20 @@ pub fn bump_0(mut p: Ptr) { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct D { #[offset(0)] pub a_: i32, } impl D { - pub fn construct(this: Ptr, mut a: i32) { + pub fn constructor_1(this: Ptr, mut a: i32) { field!(this, a_).write(a); { field!(this, a_).with_mut(|__v| *__v = *__v * 2) @@ -142,7 +148,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S::construct_1(1)); + object!(s, S::constructor_1(1)); let ref_: Ptr = ({ S::returns_this_reference(s.as_pointer()) }); field!(ref_, a_).with_mut(|__v| __v.postfix_inc()); assert!(({ (*s.borrow()).a_ } == 2)); @@ -160,16 +166,16 @@ fn main_0() -> i32 { assert!(({ (*s.borrow()).a_ } == 8)); ({ S::bump_me(s.as_pointer()) }); assert!(({ (*s.borrow()).a_ } == 9)); - object!(d, D(3)); + object!(d, D::constructor_1(3)); assert!(({ (*d.borrow()).a_ } == 6)); let cr: Ptr = ({ S::cref(s.as_pointer()) }); assert!((cr.with(|__s| __s.a_) == 9)); - object!(t, S::construct_1(0)); + object!(t, S::constructor_1(0)); assert!(({ S::is(s.as_pointer(), (s.as_pointer()),) })); assert!(!({ S::is(s.as_pointer(), (t.as_pointer()),) })); let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - S::construct_1(__p.clone(), 1); + S::constructor_1(__p.clone(), 1); __p }; let mut q: Ptr = ({ S::returns_this_pointer((p).clone()) }); @@ -178,7 +184,7 @@ fn main_0() -> i32 { p.delete(); let mut h: Ptr = { let __p = Ptr::alloc(::zero_init()); - S::construct_1(__p.clone(), 5); + S::constructor_1(__p.clone(), 5); __p }; ({ S::destroy((h).clone()) }); @@ -192,21 +198,24 @@ fn main_0() -> i32 { ((({ S::copy_if_different_const(s.as_pointer(), (s.as_pointer()),) }) as i32) == (false as i32)) ); - object!(other, S::construct_1(22)); + object!(other, S::constructor_1(22)); assert!( ((({ S::copy_if_different(s.as_pointer(), (other.as_pointer()),) }) as i32) == (true as i32)) ); assert!(({ (*s.borrow()).a_ } == { (*other.borrow()).a_ })); assert!(({ { (*s.borrow()).self__.clone() } } == { { (*other.borrow()).self__.clone() } })); - object!(u, S::construct_2(1, (s.as_pointer()))); + object!(u, S::constructor_2(1, Pointer::bind((s.as_pointer())))); assert!(({ { (*u.borrow()).self__.clone() } } == { (s.as_pointer()) })); let s_const: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - S::construct_1(__v.as_pointer(), 100); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::constructor_1(__v.as_pointer(), 100); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - object!(u1, S::construct_3(1, (s_const.as_pointer()))); + object!( + u1, + S::constructor_3(1, Pointer::bind((s_const.as_pointer()))) + ); assert!(({ (*u1.borrow()).self__.clone() }).is_null()); return 0; } diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index a4735ddfbe..c9e1dd91e9 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Outer_RunInfo { #[offset(0)] @@ -39,14 +41,17 @@ pub struct Outer_RunInfo { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Outer { #[offset(0)] #[byte_size(24)] pub runs: Vec, } -impl DefaultConstructible for Outer { - fn default_constructor(this: Ptr) { +impl Outer { + pub fn constructor_1(this: Ptr) { field!(this, runs).write(Vec::new()); } } @@ -55,7 +60,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(o, Outer); + object!(o, Outer::constructor_1()); let info: Value = Rc::new(RefCell::new(::default())); (*info.borrow_mut()).block_idx = 1; (*info.borrow_mut()).num_extra_zero_runs = 2; diff --git a/tests/unit/out/refcount/unary_expr_or_type_trait.rs b/tests/unit/out/refcount/unary_expr_or_type_trait.rs index 5016cccfce..113098923a 100644 --- a/tests/unit/out/refcount/unary_expr_or_type_trait.rs +++ b/tests/unit/out/refcount/unary_expr_or_type_trait.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 3793ad37fe..2430ac05fb 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -25,7 +25,9 @@ pub fn inc_1(r: Ptr) { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -75,7 +77,9 @@ pub trait Shape { FnPtrArg, DefaultInitializable, Copyable, + Conversions, )] +#[conversions(copy, move)] #[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 aed059e058..9bc761e053 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -34,7 +36,9 @@ pub struct Inner { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(48)] pub struct Cookie { #[offset(0)] @@ -66,7 +70,19 @@ impl Default for Cookie { } } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Counter { #[offset(0)] @@ -78,9 +94,7 @@ impl Counter { __v.prefix_inc(); }); } -} -impl DefaultConstructible for Counter { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, n).write(0); } } @@ -148,7 +162,7 @@ fn main_0() -> i32 { let field_addr: Value = Rc::new(RefCell::new(Inner { a: 0, b: 0 })); ({ set_0((field_ptr!(field_addr.as_pointer(), b)), 7) }); assert!(({ (*field_addr.borrow()).b } == 7)); - object!(counter, Counter); + object!(counter, Counter::constructor_1()); ({ Counter::inc(counter.as_pointer()) }); assert!(({ (*counter.borrow()).n } == 1)); return 0; diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index 81a2e7b04a..b8555ff7db 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -10,6 +10,9 @@ use std::rc::{Rc, Weak}; Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct SafePointer { #[offset(0)] @@ -24,9 +27,7 @@ impl SafePointer { __v.prefix_inc(); }); } -} -impl DefaultConstructible for SafePointer { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, ptr).write(None); } } @@ -41,7 +42,9 @@ impl DefaultConstructible for SafePointer { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/unique_ptr_const_deref.rs b/tests/unit/out/refcount/unique_ptr_const_deref.rs index 5bdcba70e9..af51ec923f 100644 --- a/tests/unit/out/refcount/unique_ptr_const_deref.rs +++ b/tests/unit/out/refcount/unique_ptr_const_deref.rs @@ -10,14 +10,17 @@ use std::rc::{Rc, Weak}; Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Holder { #[offset(0)] #[byte_size(8)] pub val: Option>, } -impl DefaultConstructible for Holder { - fn default_constructor(this: Ptr) { +impl Holder { + pub fn constructor_1(this: Ptr) { field!(this, val).write(None); } } @@ -32,7 +35,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(h, Holder); + object!(h, Holder::constructor_1()); { (*h.borrow_mut()).val = Some(Rc::new(RefCell::new(10))).take(); }; diff --git a/tests/unit/out/refcount/unique_ptr_field_reset.rs b/tests/unit/out/refcount/unique_ptr_field_reset.rs index 7c2722665e..6a752b9461 100644 --- a/tests/unit/out/refcount/unique_ptr_field_reset.rs +++ b/tests/unit/out/refcount/unique_ptr_field_reset.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Data { #[offset(0)] @@ -27,6 +29,9 @@ pub struct Data { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(16)] pub struct Holder { #[offset(0)] @@ -39,9 +44,7 @@ impl Holder { pub fn set(this: Ptr, mut p: Ptr) { field_ptr!(this, data).write(p.to_owned_opt()); } -} -impl DefaultConstructible for Holder { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, data).write(None); field!(this, n).write(0_i32); } @@ -62,7 +65,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(h, Holder); + object!(h, Holder::constructor_1()); (*h.borrow_mut()).n = 1; let mut hp: Ptr = (h.as_pointer()); field_ptr!(hp, data).write(Ptr::alloc(Data { v: 3 }).to_owned_opt()); diff --git a/tests/unit/out/refcount/unique_ptr_nested.rs b/tests/unit/out/refcount/unique_ptr_nested.rs index 4bd124f7ec..1935680037 100644 --- a/tests/unit/out/refcount/unique_ptr_nested.rs +++ b/tests/unit/out/refcount/unique_ptr_nested.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -29,14 +31,17 @@ pub struct Inner { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Outer { #[offset(0)] #[byte_size(8)] pub inner: Option>, } -impl DefaultConstructible for Outer { - fn default_constructor(this: Ptr) { +impl Outer { + pub fn constructor_1(this: Ptr) { field!(this, inner).write(None); } } diff --git a/tests/unit/out/refcount/unique_ptr_struct.rs b/tests/unit/out/refcount/unique_ptr_struct.rs index c265f0cfa5..25ab325abf 100644 --- a/tests/unit/out/refcount/unique_ptr_struct.rs +++ b/tests/unit/out/refcount/unique_ptr_struct.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index b1d257ca32..fc4a2b93e2 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -11,7 +11,7 @@ pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { let n: Value = Rc::new(RefCell::new(n)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); (*ap.borrow_mut()) = __args.decay(); - object!(guard, Guard_1(ap.as_pointer())); + object!(guard, Guard_1::constructor_1(ap.as_pointer())); let mut total: i32 = 0; { let mut i: i32 = 0; @@ -31,11 +31,11 @@ pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, Copyable, + Conversions, )] -#[cpp_from(Ptr , construct, mut_ptr)] +#[conversions(copy)] #[byte_size(16)] pub struct Guard_1 { #[offset(0)] @@ -45,7 +45,7 @@ pub struct Guard_1 { pub active: bool, } impl Guard_1 { - pub fn construct(this: Ptr, val: Ptr>) { + pub fn constructor_1(this: Ptr, val: Ptr>) { field!(this, ap).write((val).clone()); field!(this, active).write(true); } @@ -85,7 +85,9 @@ pub fn sum_ptr_2(n: i32, __args: Box<[VaArg]>) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[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 37f11f02c4..7d9809b4eb 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -38,6 +40,9 @@ pub fn copy_0(mut copy_vector: Vec) {} Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct Foo { #[offset(0)] @@ -47,8 +52,8 @@ pub struct Foo { #[byte_size(24)] pub b: Vec, } -impl DefaultConstructible for Foo { - fn default_constructor(this: Ptr) { +impl Foo { + pub fn constructor_1(this: Ptr) { field!(this, a).write(Vec::new()); field!(this, b).write(Vec::new()); } @@ -61,19 +66,20 @@ impl DefaultConstructible for Foo { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Wrapped { #[offset(0)] pub v: i32, } impl Wrapped { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } } @@ -183,15 +189,23 @@ fn main_0() -> i32 { { let mut __tmp_10 = { >::from(v2.decay().begin()) }; let start_idx = __tmp_10.index(); - let mut temp_vec: Vec = Vec::new(); + let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(src.decay().begin())); let __last: Value> = Rc::new(RefCell::new(src.decay().end())); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - temp_vec.push((__it.borrow().iter_deref().read())); + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } v2.as_pointer().with_mut(|v: &mut Vec| { - v.splice(start_idx..start_idx, temp_vec); + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); }); (__tmp_10).clone() }; @@ -544,7 +558,7 @@ fn main_0() -> i32 { && ({ (*v11.borrow())[2_usize] } == 3) }) ); - object!(foo, Foo); + object!(foo, Foo::constructor_1()); ({ let __tmp_22: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( @@ -689,15 +703,23 @@ fn main_0() -> i32 { let mut __tmp_27 = { >::from(longs.decay().begin().iter_add(1_isize)) }; let start_idx = __tmp_27.index(); - let mut temp_vec: Vec = Vec::new(); + let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(ints.decay())); let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - temp_vec.push(((__it.borrow().iter_deref().read()) as i64)); + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } longs.as_pointer().with_mut(|v: &mut Vec| { - v.splice(start_idx..start_idx, temp_vec); + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); }); (__tmp_27).clone() })); @@ -713,17 +735,25 @@ fn main_0() -> i32 { { let mut __tmp_28 = { >::from(longs.decay().end()) }; let start_idx = __tmp_28.index(); - let mut temp_vec: Vec = Vec::new(); + let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(more.decay().begin())); let __last: Value> = Rc::new(RefCell::new(more.decay().end())); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - temp_vec.push(((__it.borrow().iter_deref().read()) as i64)); + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } longs.as_pointer().with_mut(|v: &mut Vec| { - v.splice(start_idx..start_idx, temp_vec); + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); }); (__tmp_28).clone() }; @@ -734,15 +764,23 @@ fn main_0() -> i32 { { let mut __tmp_29 = { >::from(doubles.decay().begin()) }; let start_idx = __tmp_29.index(); - let mut temp_vec: Vec = Vec::new(); + let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(ints.decay())); let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((2) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - temp_vec.push(((__it.borrow().iter_deref().read()) as f64)); + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } doubles.as_pointer().with_mut(|v: &mut Vec| { - v.splice(start_idx..start_idx, temp_vec); + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); }); (__tmp_29).clone() }; @@ -756,17 +794,23 @@ fn main_0() -> i32 { { let mut __tmp_30 = { >::from(wrapped.decay().begin()) }; let start_idx = __tmp_30.index(); - let mut temp_vec: Vec = Vec::new(); + let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(ints.decay())); let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - temp_vec.push(>::cpp_from( - __it.borrow().iter_deref(), - )); + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } wrapped.as_pointer().with_mut(|v: &mut Vec| { - v.splice(start_idx..start_idx, temp_vec); + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); }); (__tmp_30).clone() }; @@ -780,17 +824,25 @@ fn main_0() -> i32 { { let mut __tmp_31 = { >::from(same.decay().begin()) }; let start_idx = __tmp_31.index(); - let mut temp_vec: Vec = Vec::new(); + let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(more.decay().begin())); let __last: Value> = Rc::new(RefCell::new(more.decay().end())); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - temp_vec.push((__it.borrow().iter_deref().read())); + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } same.as_pointer().with_mut(|v: &mut Vec| { - v.splice(start_idx..start_idx, temp_vec); + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); }); (__tmp_31).clone() }; diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index 939b203404..258b666ca4 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -14,19 +14,20 @@ use std::rc::{Rc, Weak}; ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Degrees { #[offset(0)] pub value: i32, } impl Degrees { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, value).write(v); } } @@ -38,12 +39,13 @@ impl Degrees { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_into(i64, to_i64)] +#[conversions(copy, move)] +#[conversion_function(to_i64, LvalueRef>, i64 )] #[byte_size(4)] pub struct Reading { #[offset(0)] @@ -61,51 +63,71 @@ pub fn main() { fn main_0() -> i32 { let src: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v1: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(src.decay())); let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push((__it.borrow().iter_deref().read())); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v1.len() == 3_usize)); assert!(((v1[0_usize] == 1_u32) && (v1[1_usize] == 2_u32)) && (v1[2_usize] == 3_u32)); let mut v2: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(src.decay())); let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push(((__it.borrow().iter_deref().read()) as u64)); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v2.len() == 3_usize)); assert!(((v2[0_usize] == 1_u64) && (v2[1_usize] == 2_u64)) && (v2[2_usize] == 3_u64)); let mut v3: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(src.decay())); let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push(((__it.borrow().iter_deref().read()) as i32)); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v3.len() == 3_usize)); assert!(((v3[0_usize] == 1) && (v3[1_usize] == 2)) && (v3[2_usize] == 3)); let src1: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v4: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(src1.decay())); let __last: Value> = Rc::new(RefCell::new(src1.decay().to_end())); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push((__it.borrow().iter_deref().read())); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v4.len() == 3_usize)); assert!(((v4[0_usize] == 1_u32) && (v4[1_usize] == 2_u32)) && (v4[2_usize] == 3_u32)); @@ -117,14 +139,19 @@ fn main_0() -> i32 { let mut start: Ptr = buf.decay(); let mut len: usize = 5_usize; let mut v5: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new((start).clone())); let __last: Value> = Rc::new(RefCell::new(start.offset((len) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push((__it.borrow().iter_deref().read())); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v5.len() == 5_usize)); assert!(((v5[0_usize] as i32) == 10) && ((v5[4_usize] as i32) == 50)); @@ -148,7 +175,7 @@ fn main_0() -> i32 { } .write(30); let v6: Value, Value)>> = Rc::new(RefCell::new({ - let mut __v = Vec::new(); + let __v: Value, Value)>> = Rc::new(RefCell::new(Vec::new())); let __it: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() .with(|__m: &Map, Value)>| __m.begin()), @@ -161,13 +188,17 @@ fn main_0() -> i32 { __it.as_pointer(), __last.as_pointer(), ) { - __v.push(<(Value, Value) as CppFrom<( - Value, - Value, - )>>::cpp_from(__it.borrow().iter_deref())); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::, Value)>>::bind( + __it.borrow().iter_deref(), + ),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!(({ ((*v6.borrow()).len() == 3_usize) })); assert!( @@ -189,7 +220,7 @@ fn main_0() -> i32 { ) }; let start_idx = __tmp_3.index(); - let mut temp_vec: Vec<(Value, Value)> = Vec::new(); + let temp_vec: Value, Value)>> = Rc::new(RefCell::new(Vec::new())); let __it: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() .with(|__m: &Map, Value)>| __m.begin()), @@ -202,15 +233,22 @@ fn main_0() -> i32 { __it.as_pointer(), __last.as_pointer(), ) { - temp_vec.push(<(Value, Value) as CppFrom<( - Value, - Value, - )>>::cpp_from(__it.borrow().iter_deref())); + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::, Value)>>::bind( + __it.borrow().iter_deref(), + ),), + ); __it.borrow_mut().iter_inc(); } v6.as_pointer() .with_mut(|v: &mut Vec<(Value, Value)>| { - v.splice(start_idx..start_idx, temp_vec); + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); }); (__tmp_3).clone() }; @@ -224,16 +262,19 @@ fn main_0() -> i32 { ); let ints: Value> = Rc::new(RefCell::new(Box::new([4, 5, 6]))); let mut v7: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(ints.decay())); let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push(>::cpp_from( - __it.borrow().iter_deref(), - )); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v7[1_usize].value == 5)); let readings: Value> = Rc::new(RefCell::new(Box::new([ @@ -241,17 +282,22 @@ fn main_0() -> i32 { Reading { raw_: 5 }, ]))); let mut v8: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(readings.decay())); let __last: Value> = Rc::new(RefCell::new(readings.decay().offset((2) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push(>::cpp_from( - __it.borrow().iter_deref(), - )); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind( + __it.borrow().iter_deref(), + ),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v8[0_usize] == 40_i64) && (v8[1_usize] == 50_i64)); return 0; diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index 7eca784f53..1b9a9a024e 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -44,6 +46,9 @@ impl Point { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct Holder { #[offset(0)] @@ -53,8 +58,8 @@ pub struct Holder { #[byte_size(24)] pub points: Vec, } -impl DefaultConstructible for Holder { - fn default_constructor(this: Ptr) { +impl Holder { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); field!(this, points).write(Vec::new()); } @@ -115,7 +120,7 @@ fn main_0() -> i32 { p.write(9); assert!(({ (*v.borrow())[2_usize] } == 9)); assert!((({ sum_ref_1(v.as_pointer(),) }) == ((((3 + 0) + 9) + 42) + 5))); - object!(h, Holder); + object!(h, Holder::constructor_1()); (*h.borrow_mut()).values.resize_with(2_usize, || 0_i32); vec_elem!(h.as_pointer(), values, 1_usize).write(6); ({ diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index 6020baa986..a3c027a626 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct TestAllocator_int_ {} impl TestAllocator_int_ { @@ -39,7 +41,9 @@ impl TestAllocator_int_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct TestAllocator_double_ {} impl TestAllocator_double_ { @@ -398,51 +402,71 @@ fn main_0() -> i32 { ({ fn_1(v7.as_pointer(), copy_constructed(v8.as_pointer())) }); let src: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v9: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(src.decay())); let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push((__it.borrow().iter_deref().read())); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v9.len() == 3_usize)); assert!(((v9[0_usize] == 1_u32) && (v9[1_usize] == 2_u32)) && (v9[2_usize] == 3_u32)); let mut v10: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(src.decay())); let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push(((__it.borrow().iter_deref().read()) as u64)); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v10.len() == 3_usize)); assert!(((v10[0_usize] == 1_u64) && (v10[1_usize] == 2_u64)) && (v10[2_usize] == 3_u64)); let mut v11: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(src.decay())); let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push(((__it.borrow().iter_deref().read()) as i32)); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v11.len() == 3_usize)); assert!(((v11[0_usize] == 1) && (v11[1_usize] == 2)) && (v11[2_usize] == 3)); let src1: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v12: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(src1.decay())); let __last: Value> = Rc::new(RefCell::new(src1.decay().to_end())); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push((__it.borrow().iter_deref().read())); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v12.len() == 3_usize)); assert!(((v12[0_usize] == 1_u32) && (v12[1_usize] == 2_u32)) && (v12[2_usize] == 3_u32)); @@ -451,14 +475,19 @@ fn main_0() -> i32 { let mut start: Ptr = buf.decay(); let mut len: usize = 5_usize; let mut v13: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new((start).clone())); let __last: Value> = Rc::new(RefCell::new(start.offset((len) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push((__it.borrow().iter_deref().read())); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((v13.len() == 5_usize)); assert!(((v13[0_usize] as i32) == 10) && ((v13[4_usize] as i32) == 50)); diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 7af3f1a185..65c08c7ed9 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -21,14 +21,17 @@ pub fn unused_param_0(mut x: i32) {} Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct NonTrivial { #[offset(0)] #[byte_size(24)] pub data: Vec, } -impl DefaultConstructible for NonTrivial { - fn default_constructor(this: Ptr) { +impl NonTrivial { + pub fn constructor_1(this: Ptr) { field!(this, data).write(Vec::new()); } } @@ -52,7 +55,9 @@ pub fn bump_and_return_4() -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Holder { #[offset(0)] @@ -62,14 +67,17 @@ pub struct Holder { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct NonCopyable { #[offset(0)] #[byte_size(8)] pub value: Option>, } -impl DefaultConstructible for NonCopyable { - fn default_constructor(this: Ptr) { +impl NonCopyable { + pub fn constructor_1(this: Ptr) { field!(this, value).write(None); } } @@ -121,7 +129,7 @@ fn main_0() -> i32 { let mut arr: [i32; 3] = [1, 2, 3]; let h: Value = Rc::new(RefCell::new(Holder { field: 17 })); let mut hp: Ptr = (h.as_pointer()); - object!(nt, NonTrivial); + object!(nt, NonTrivial::constructor_1()); ({ unused_ref_param_1(nt.as_pointer()) }); ({ unused_ptr_param_2((nt.as_pointer())) }); let g: Value = Rc::new(RefCell::new(NonCopyable { diff --git a/tests/unit/out/unsafe/05_new.rs b/tests/unit/out/unsafe/05_new.rs index a1efffa008..15c795f57f 100644 --- a/tests/unit/out/unsafe/05_new.rs +++ b/tests/unit/out/unsafe/05_new.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct A {} #[repr(C)] #[derive( @@ -28,7 +30,9 @@ pub struct A {} TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct D {} impl D { pub unsafe fn operator_call(this: *const Self, mut ptr: *const A) { diff --git a/tests/unit/out/unsafe/10_struct.rs b/tests/unit/out/unsafe/10_struct.rs index 62398003c9..3a1746e7b8 100644 --- a/tests/unit/out/unsafe/10_struct.rs +++ b/tests/unit/out/unsafe/10_struct.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct GraphNode { pub dst: u32, pub next: *mut GraphNode, @@ -31,7 +33,9 @@ pub struct GraphNode { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Graph { pub V: u32, pub adj: *mut *mut GraphNode, @@ -49,19 +53,29 @@ impl Graph { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, PointerUnsafe)] pub struct Partial { pub p: *mut i32, } impl Partial { - pub unsafe fn construct_1(this: *mut Self, mut q: *mut i32) { - (&raw mut (*this).p).write(q); - } -} -impl DefaultConstructibleUnsafe for Partial { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).p).write(std::ptr::null_mut()); } + pub unsafe fn constructor_2(this: *mut Self, q: PointerUnsafe) { + let mut q = (q.as_ptr() as *mut i32); + (&raw mut (*this).p).write(q); + } } impl Default for Partial { fn default() -> Self { @@ -82,7 +96,9 @@ impl Default for Partial { DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Declared {} impl Declared {} #[repr(C)] @@ -95,7 +111,9 @@ impl Declared {} TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S { pub i: i32, pub d: *mut Declared, @@ -112,11 +130,14 @@ unsafe fn main_0() -> i32 { adj: std::ptr::null_mut(), }; let mut arr: [i32; 3] = [3, 1, 4]; - object_unsafe!(it, Partial::construct_1(arr.as_mut_ptr())); + object_unsafe!( + it, + Partial::constructor_2(PointerUnsafe::bind(arr.as_mut_ptr())) + ); if ((it.p) != (arr.as_mut_ptr())) { return 1; } - object_unsafe!(def, Partial); + object_unsafe!(def, Partial::constructor_1()); if !((def.p).is_null()) { return 1; } diff --git a/tests/unit/out/unsafe/addr_of_global.rs b/tests/unit/out/unsafe/addr_of_global.rs index f341572944..7a6ba57664 100644 --- a/tests/unit/out/unsafe/addr_of_global.rs +++ b/tests/unit/out/unsafe/addr_of_global.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Inner { pub value: i32, } @@ -30,7 +32,9 @@ pub struct Inner { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 41649bba63..d5e0bb02e4 100644 --- a/tests/unit/out/unsafe/anonymous-struct.rs +++ b/tests/unit/out/unsafe/anonymous-struct.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Outer_Named { pub a: i32, pub b: i32, @@ -31,7 +33,9 @@ pub struct Outer_Named { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct anon_0 { pub c: i32, pub d: i32, @@ -46,7 +50,9 @@ pub struct anon_0 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct anon_1 { pub g: i32, pub h: i32, @@ -61,7 +67,9 @@ pub struct anon_1 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct anon_2 { pub e: i32, pub f: i32, @@ -76,7 +84,9 @@ pub struct anon_2 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct anon_4 { pub j: i32, } @@ -90,7 +100,9 @@ pub struct anon_4 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct anon_5 { pub k: i32, } @@ -104,7 +116,9 @@ pub struct anon_5 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct anon_3 { pub i: i32, pub inner_named: anon_4, @@ -120,7 +134,9 @@ pub struct anon_3 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Outer { pub named: Outer_Named, pub anonymous_named_0: anon_0, @@ -185,7 +201,9 @@ unsafe fn main_0() -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 0914fe7a73..8f10b7516a 100644 --- a/tests/unit/out/unsafe/anonymous_enum.rs +++ b/tests/unit/out/unsafe/anonymous_enum.rs @@ -22,7 +22,9 @@ pub const anon_1_SECOND_B: anon_1 = 1; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S { pub a: i32, } @@ -42,7 +44,9 @@ pub const anon_2_FIELD_B: anon_2 = 1; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 676e6ad93b..6aa4d696a0 100644 --- a/tests/unit/out/unsafe/any.rs +++ b/tests/unit/out/unsafe/any.rs @@ -16,13 +16,16 @@ use std::rc::Rc; DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] +#[constructor(constructor_1, i32, i32)] pub struct Point { pub x: i32, pub y: i32, } impl Point { - pub unsafe fn construct(this: *mut Self, mut x: i32, mut y: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32, mut y: i32) { (&raw mut (*this).x).write(x); (&raw mut (*this).y).write(y); } @@ -35,8 +38,8 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut a: Option> = Some(Box::new({ - let mut __v: Point = ::zero_init(); - Point::construct(&raw mut __v, 3, 4); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_1(&raw mut __v, 3, 4); __v })); assert!(a.is_some()); @@ -64,8 +67,8 @@ unsafe fn main_0() -> i32 { ); let q: *mut Point = { a = Some(Box::new({ - let mut __v: Point = ::zero_init(); - Point::construct(&raw mut __v, 5, 6); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_1(&raw mut __v, 5, 6); __v })); a.as_mut().unwrap().downcast_mut::().unwrap() diff --git a/tests/unit/out/unsafe/array_of_noncopy_struct.rs b/tests/unit/out/unsafe/array_of_noncopy_struct.rs index 26b8dd2b99..2525d2f09d 100644 --- a/tests/unit/out/unsafe/array_of_noncopy_struct.rs +++ b/tests/unit/out/unsafe/array_of_noncopy_struct.rs @@ -18,12 +18,15 @@ use std::rc::Rc; SwappableUnsafe, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct NonCopy { pub data: Vec, pub tag: i32, } -impl DefaultConstructibleUnsafe for NonCopy { - unsafe fn default_constructor(this: *mut Self) { +impl NonCopy { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(Vec::new()); (&raw mut (*this).tag).write(0); } @@ -46,8 +49,8 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut arr: [NonCopy; 3] = std::array::from_fn::<_, 3, _>(|_| { - let mut __v: NonCopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: NonCopy = ZeroInitializationUnsafe::zero_init(); + NonCopy::constructor_1(&raw mut __v); __v }); arr[(0) as usize].tag = 7; diff --git a/tests/unit/out/unsafe/array_reference.rs b/tests/unit/out/unsafe/array_reference.rs index 5f8e415d87..c68b203715 100644 --- a/tests/unit/out/unsafe/array_reference.rs +++ b/tests/unit/out/unsafe/array_reference.rs @@ -66,7 +66,9 @@ pub unsafe fn pick_10(s: *const [libc::c_char; 5]) -> *const [libc::c_char; 5] { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 90835907eb..4e5e74334d 100644 --- a/tests/unit/out/unsafe/as_const.rs +++ b/tests/unit/out/unsafe/as_const.rs @@ -19,7 +19,9 @@ pub const Overload_kConstOverload: Overload = 2; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 19cbba57bc..d0f7762a62 100644 --- a/tests/unit/out/unsafe/assign_rhs_first.rs +++ b/tests/unit/out/unsafe/assign_rhs_first.rs @@ -22,7 +22,9 @@ pub unsafe fn advance_1() -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 a6d55f72e3..ebf3f25628 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -845,7 +845,9 @@ pub unsafe fn test_reference_members_9() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Slot_6 { pub value: *mut u32, } @@ -859,7 +861,9 @@ pub struct Slot_6 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Slot_8 { pub value: *mut i16, } @@ -873,7 +877,9 @@ pub struct Slot_8 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Slot_10 { pub value: *mut i32, } @@ -931,7 +937,9 @@ pub unsafe fn test_pointer_elements_11() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Holder_12 { pub p: *mut i32, } @@ -966,7 +974,9 @@ pub unsafe fn test_reference_pointer_13() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Node_14 { pub link: *mut *mut Node_14, } @@ -1048,7 +1058,9 @@ pub unsafe fn test_reference_subfields_18() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Index_16 { pub value: u32, } @@ -1062,7 +1074,9 @@ pub struct Index_16 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Slot_17 { pub ref_: *mut Index_16, } @@ -1076,7 +1090,9 @@ pub struct Slot_17 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Index_19 { pub value: i16, } @@ -1090,7 +1106,9 @@ pub struct Index_19 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Slot_20 { pub ref_: *mut Index_19, } @@ -1139,7 +1157,9 @@ pub unsafe fn observe_24(mut assigned: i32, mut stored: *const i32) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct GlobalRecord_Inner { pub value: i32, } @@ -1153,7 +1173,9 @@ pub struct GlobalRecord_Inner { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct GlobalRecord { pub inner: GlobalRecord_Inner, } @@ -1428,7 +1450,9 @@ static mut flag_31: std::cell::LazyCell = std::cell::LazyCell::new(|| unsa TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Record_32 { pub value: i32, } @@ -1442,7 +1466,9 @@ pub struct Record_32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Link_33 { pub next: *mut Link_33, } @@ -1458,7 +1484,9 @@ pub static mut selected_values_34: std::cell::LazyCell<[u32; 3]> = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct IndexedBinding {} impl IndexedBinding { pub unsafe fn get_1_0(this: *mut Self) -> *mut u32 { @@ -1686,7 +1714,9 @@ pub static mut global_rows_46: std::cell::LazyCell<[[u32; 2]; 2]> = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct IndexedMember { pub key: i32, pub value: u32, @@ -1954,7 +1984,9 @@ pub static mut scoped_pointers_53: std::cell::LazyCell<[*mut u32; 1]> = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct PointerSelector { pub ptr: *mut u32, } @@ -2130,11 +2162,14 @@ pub unsafe fn test_stable_containers_58() { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Counts_59 { pub counts: Vec, } -impl DefaultConstructibleUnsafe for Counts_59 { - unsafe fn default_constructor(this: *mut Self) { +impl Counts_59 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).counts).write(Vec::new()); } } @@ -2148,7 +2183,9 @@ impl DefaultConstructibleUnsafe for Counts_59 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pair_60 { pub u: u32, pub f: i32, @@ -2459,7 +2496,9 @@ unsafe fn main_0() -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Index_62 { pub value: i32, } @@ -2473,7 +2512,9 @@ pub struct Index_62 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 408ea795bd..55e6c1e43b 100644 --- a/tests/unit/out/unsafe/bounded_struct_ptr.rs +++ b/tests/unit/out/unsafe/bounded_struct_ptr.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 d66b21ad01..37605e38a8 100644 --- a/tests/unit/out/unsafe/bst.rs +++ b/tests/unit/out/unsafe/bst.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct node_t { pub left: *mut node_t, pub right: *mut node_t, diff --git a/tests/unit/out/unsafe/cast.rs b/tests/unit/out/unsafe/cast.rs index 0ebeef59cb..49f7e8d1f1 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -20,7 +20,9 @@ pub const E_C: E = 2; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pair { pub x: i32, pub y: i32, @@ -35,7 +37,9 @@ pub struct Pair { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Wide { pub c: libc::c_char, } @@ -49,7 +53,9 @@ pub struct Wide { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Grid { pub h: i32, pub row: [i32; 3], @@ -68,12 +74,15 @@ pub struct Grid { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Bag { pub n: i32, pub items: Vec, } -impl DefaultConstructibleUnsafe for Bag { - unsafe fn default_constructor(this: *mut Self) { +impl Bag { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).n).write(0_i32); (&raw mut (*this).items).write(Vec::new()); } @@ -320,7 +329,7 @@ pub unsafe fn nested_5() { assert!(((m[(1) as usize][(1) as usize]) == (42))); assert!(((pm) == (&mut m[(1) as usize][(1) as usize] as *mut i32))); assert!(((pm) < (&mut m[(2) as usize][(0) as usize] as *mut i32))); - object_unsafe!(b, Bag); + object_unsafe!(b, Bag::constructor_1()); if 4_usize > b.items.capacity() as usize { let len_0 = b.items.len(); b.items.reserve_exact(4_usize - len_0 as usize); diff --git a/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs b/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs index 6cc29e2494..8af40a1171 100644 --- a/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs +++ b/tests/unit/out/unsafe/cast_array_to_pointer_decay.rs @@ -26,7 +26,9 @@ pub unsafe fn strlen_1(mut s: *mut libc::c_char) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Row { pub a: [i32; 3], } diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index a1be7efaff..fd2a3eea1b 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pair { pub first: i32, pub second: i32, @@ -60,7 +62,9 @@ impl Pair { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Route { pub path: Pair, pub cost: f64, @@ -82,7 +86,9 @@ impl Route { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Counter { pub v: i32, pub calls: i32, @@ -103,7 +109,9 @@ impl Counter { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 dbb14b2a0e..489f9a4684 100644 --- a/tests/unit/out/unsafe/class_template_lazy_member.rs +++ b/tests/unit/out/unsafe/class_template_lazy_member.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Point { pub x: i32, } @@ -30,7 +32,9 @@ pub struct Point { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Box_int_ { pub val: i32, } @@ -49,7 +53,9 @@ impl Box_int_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Box_Point_ { pub val: Point, } @@ -68,7 +74,9 @@ impl Box_Point_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Deduced_int_ { pub val: i32, } @@ -87,7 +95,9 @@ impl Deduced_int_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 91c1cf5f86..f8e23d09af 100644 --- a/tests/unit/out/unsafe/class_templates.rs +++ b/tests/unit/out/unsafe/class_templates.rs @@ -19,6 +19,9 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct MyContainer_int_ { vec_: Vec, } @@ -42,9 +45,7 @@ impl MyContainer_int_ { pub unsafe fn push_back(this: *mut Self, item: *const i32) { (*this).vec_.push_copied(item); } -} -impl DefaultConstructibleUnsafe for MyContainer_int_ { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).vec_).write(Vec::new()); } } @@ -61,6 +62,9 @@ impl DefaultConstructibleUnsafe for MyContainer_int_ { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct MyContainer_char_ { vec_: Vec, } @@ -84,9 +88,7 @@ impl MyContainer_char_ { pub unsafe fn push_back(this: *mut Self, item: *const libc::c_char) { (*this).vec_.push_copied(item); } -} -impl DefaultConstructibleUnsafe for MyContainer_char_ { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).vec_).write(Vec::new()); } } @@ -103,6 +105,9 @@ impl DefaultConstructibleUnsafe for MyContainer_char_ { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct MyContainer_float_ { vec_: Vec, } @@ -126,9 +131,7 @@ impl MyContainer_float_ { pub unsafe fn push_back(this: *mut Self, item: *const f32) { (*this).vec_.push_copied(item); } -} -impl DefaultConstructibleUnsafe for MyContainer_float_ { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).vec_).write(Vec::new()); } } @@ -142,7 +145,9 @@ impl DefaultConstructibleUnsafe for MyContainer_float_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Boxed_short_ { pub value: i16, } @@ -164,7 +169,9 @@ impl Boxed_short_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Boxed_int_ { pub value: i32, } @@ -186,7 +193,9 @@ impl Boxed_int_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Boxed_long_ { pub value: i64, } @@ -208,7 +217,9 @@ impl Boxed_long_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Outer_int__Inner_int_ { pub t: i32, pub u: i32, @@ -228,7 +239,9 @@ impl Outer_int__Inner_int_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Outer_int_ { pub v: i32, } @@ -247,7 +260,9 @@ impl Outer_int_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Outer_long__Inner_int_ { pub t: i64, pub u: i32, @@ -267,7 +282,9 @@ impl Outer_long__Inner_int_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Outer_long__Inner_char_ { pub t: i64, pub u: libc::c_char, @@ -287,7 +304,9 @@ impl Outer_long__Inner_char_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Outer_long_ { pub v: i64, } @@ -306,7 +325,9 @@ impl Outer_long_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Elem { pub i: i32, } @@ -350,7 +371,7 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { Boxed_long_::twice(10_i64,) }) == (20_i64))); let mut bl: Boxed_long_ = Boxed_long_ { value: 7_i64 }; assert!(((unsafe { Boxed_long_::plus(&raw const bl, 1_i64,) }) == (8_i64))); - object_unsafe!(imc, MyContainer_int_); + object_unsafe!(imc, MyContainer_int_::constructor_1()); assert!((unsafe { MyContainer_int_::empty(&raw const imc,) })); (unsafe { let mut _item: i32 = 1; @@ -362,7 +383,7 @@ unsafe fn main_0() -> i32 { ); (unsafe { MyContainer_int_::pop_back(&raw mut imc) }); assert!((unsafe { MyContainer_int_::empty(&raw const imc,) })); - object_unsafe!(cmc, MyContainer_char_); + object_unsafe!(cmc, MyContainer_char_::constructor_1()); assert!((unsafe { MyContainer_char_::empty(&raw const cmc,) })); (unsafe { let mut _item: libc::c_char = ('a' as libc::c_char); @@ -375,7 +396,7 @@ unsafe fn main_0() -> i32 { ); (unsafe { MyContainer_char_::pop_back(&raw mut cmc) }); assert!((unsafe { MyContainer_char_::empty(&raw const cmc,) })); - object_unsafe!(fmc, MyContainer_float_); + object_unsafe!(fmc, MyContainer_float_::constructor_1()); assert!((unsafe { MyContainer_float_::empty(&raw const fmc,) })); (unsafe { let mut _item: f32 = (1_f64 as f32); diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index 919d9683c7..5f4a43f0d3 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Bar { pub w: i32, } @@ -30,7 +32,9 @@ pub struct Bar { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Foo { pub x: i32, pub y: *mut i32, @@ -48,7 +52,9 @@ pub struct Foo { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 f7a3f19530..e45b678f5b 100644 --- a/tests/unit/out/unsafe/comma_operator.rs +++ b/tests/unit/out/unsafe/comma_operator.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 99d90add18..e7fd5acef1 100644 --- a/tests/unit/out/unsafe/complex_function.rs +++ b/tests/unit/out/unsafe/complex_function.rs @@ -25,7 +25,9 @@ pub unsafe fn bar_2(x: *mut i32) -> *mut i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct X1 { pub v: i32, } @@ -39,7 +41,9 @@ pub struct X1 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct X2 { pub v: *mut X1, } @@ -58,7 +62,9 @@ impl X2 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct X3 { pub v: *mut X2, } @@ -77,7 +83,9 @@ impl X3 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 076ee701db..f7fb2d99ac 100644 --- a/tests/unit/out/unsafe/compound_assign_paren.rs +++ b/tests/unit/out/unsafe/compound_assign_paren.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Item { pub flags: u8, } diff --git a/tests/unit/out/unsafe/concepts.rs b/tests/unit/out/unsafe/concepts.rs index 2423f931ca..1a49420df5 100644 --- a/tests/unit/out/unsafe/concepts.rs +++ b/tests/unit/out/unsafe/concepts.rs @@ -21,7 +21,9 @@ const _: () = assert!( TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Sized {} impl Sized { pub unsafe fn size(this: *mut Self) -> i32 { diff --git a/tests/unit/out/unsafe/constexpr_function.rs b/tests/unit/out/unsafe/constexpr_function.rs index 3e63c0340c..e3ad223505 100644 --- a/tests/unit/out/unsafe/constexpr_function.rs +++ b/tests/unit/out/unsafe/constexpr_function.rs @@ -31,7 +31,10 @@ pub unsafe fn half_3(mut x: f64) -> f64 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] pub struct Flag { pub v: i32, } @@ -66,7 +69,9 @@ pub unsafe fn imm_7(mut b: bool) -> bool { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct P { pub v: i32, } diff --git a/tests/unit/out/unsafe/constructor.rs b/tests/unit/out/unsafe/constructor.rs index c90dd9a043..9e158e1fb5 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -13,14 +13,15 @@ pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] pub struct S { pub v: i32, } @@ -31,7 +32,7 @@ impl S { pub unsafe fn mut_method(this: *mut Self) { (*this).v += 1; } - pub unsafe fn construct(this: *mut Self, mut init: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut init: i32) { (&raw mut (*this).v).write(init); (unsafe { S::mut_method(this) }); (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += @@ -47,26 +48,33 @@ impl DestructibleUnsafe for S { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, TriviallyCopyableUnsafe, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, )] -#[cpp_from(i32, construct_1, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3)] pub struct Point { pub x: i32, pub y: i32, } impl Point { - pub unsafe fn construct_2(this: *mut Self, mut x: i32, mut y: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32, mut y: i32) { (&raw mut (*this).x).write(x); (&raw mut (*this).y).write(y); } - pub unsafe fn construct_1(this: *mut Self, mut v: i32) { - Point::construct_2(this, v, ((v) + (1))); + pub unsafe fn constructor_2(this: *mut Self, mut v: i32) { + Point::constructor_1(this, v, ((v) + (1))); (*this).y *= 10; } -} -impl DefaultConstructibleUnsafe for Point { - unsafe fn default_constructor(this: *mut Self) { - Point::construct_1(this, 4); + pub unsafe fn constructor_3(this: *mut Self) { + Point::constructor_2(this, 4); (*this).x += 100; } } @@ -74,8 +82,8 @@ impl Default for Point { fn default() -> Self { unsafe { { - let mut __v: Point = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_3(&raw mut __v); __v } } @@ -89,15 +97,15 @@ pub fn main() { } unsafe fn main_0() -> i32 { { - object_unsafe!(s, S(3)); + object_unsafe!(s, S::constructor_1(3)); assert!(((s.v) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (8))); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (18))); - object_unsafe!(p, Point); + object_unsafe!(p, Point::constructor_3()); assert!(((p.x) == (104))); assert!(((p.y) == (50))); - object_unsafe!(q, Point::construct_1(7)); + object_unsafe!(q, Point::constructor_2(7)); assert!(((q.x) == (7))); assert!(((q.y) == (80))); return 0; diff --git a/tests/unit/out/unsafe/container_element_receiver.rs b/tests/unit/out/unsafe/container_element_receiver.rs index 313f7890e5..c7b686a2e7 100644 --- a/tests/unit/out/unsafe/container_element_receiver.rs +++ b/tests/unit/out/unsafe/container_element_receiver.rs @@ -21,6 +21,8 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Holder { pub ref_: *mut Vec, pub vec_: Vec, diff --git a/tests/unit/out/unsafe/container_field_addr.rs b/tests/unit/out/unsafe/container_field_addr.rs index 261c0dc092..8d7181e194 100644 --- a/tests/unit/out/unsafe/container_field_addr.rs +++ b/tests/unit/out/unsafe/container_field_addr.rs @@ -19,12 +19,15 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S { pub tag: i32, pub v: Vec, } -impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(this: *mut Self) { +impl S { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).tag).write(0_i32); (&raw mut (*this).v).write(Vec::new()); } @@ -55,12 +58,12 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(local, S); + object_unsafe!(local, S::constructor_1()); local.tag = 7; (unsafe { run_1((&mut local as *mut S)) }); let mut heap: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - DefaultConstructibleUnsafe::default_constructor(__p); + S::constructor_1(__p); __p }; (*heap).tag = 7; diff --git a/tests/unit/out/unsafe/conversion_operator_same_translation.rs b/tests/unit/out/unsafe/conversion_operator_same_translation.rs index f6ff700658..4c1a73b75e 100644 --- a/tests/unit/out/unsafe/conversion_operator_same_translation.rs +++ b/tests/unit/out/unsafe/conversion_operator_same_translation.rs @@ -13,13 +13,14 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_into(libc::c_char, to_libcc_char)] -#[cpp_into(u8, to_u8)] +#[conversions(copy, move)] +#[conversion_function(to_libcc_char, LvalueRefUnsafe>, libc::c_char )] +#[conversion_function(to_u8, LvalueRefUnsafe>, u8 )] pub struct S { pub v: i32, } @@ -38,12 +39,14 @@ impl S { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_into(i64, to_i64_1)] +#[conversions(copy, move)] +#[conversion_function(to_i64_1, LvalueRefUnsafe>, i64 )] +#[conversion_function(to_i64_2, LvalueRefUnsafe>, i64 )] 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 9864b73db1..405d122f4c 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -16,19 +16,21 @@ pub static mut assigns_0: std::cell::LazyCell = std::cell::LazyCell::new(|| MoveAssignableUnsafe, SwappableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Partial { pub v: i32, pub keep: i32, } impl Partial { - pub unsafe fn construct(this: *mut Self, mut v: i32, mut keep: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32, mut keep: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).keep).write(keep); } -} -impl CopyConstructibleUnsafe for Partial { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Partial); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).keep).write((*o).keep); @@ -47,12 +49,24 @@ impl CopyAssignableUnsafe for Partial { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct NonConstAssign { pub mark: i32, } impl NonConstAssign { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).mark).write(0); + } pub unsafe fn operator_assign_2( this: *mut Self, o: *mut NonConstAssign, @@ -68,17 +82,12 @@ impl NonConstAssign { return &mut (*this); } } -impl DefaultConstructibleUnsafe for NonConstAssign { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).mark).write(0); - } -} impl Default for NonConstAssign { fn default() -> Self { unsafe { { - let mut __v: NonConstAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: NonConstAssign = ZeroInitializationUnsafe::zero_init(); + NonConstAssign::constructor_1(&raw mut __v); __v } } @@ -94,12 +103,15 @@ impl Default for NonConstAssign { DestructibleUnsafe, CopyConstructibleUnsafe, MovableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct RefQualified { pub mark: i32, } -impl DefaultConstructibleUnsafe for RefQualified { - unsafe fn default_constructor(this: *mut Self) { +impl RefQualified { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).mark).write(0); } } @@ -117,8 +129,8 @@ impl Default for RefQualified { fn default() -> Self { unsafe { { - let mut __v: RefQualified = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: RefQualified = ZeroInitializationUnsafe::zero_init(); + RefQualified::constructor_1(&raw mut __v); __v } } @@ -134,16 +146,18 @@ impl Default for RefQualified { Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Holder { pub p: Partial, pub arr: [Partial; 2], } +impl Holder {} pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -152,17 +166,18 @@ pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct CopyCounted { pub v: i32, } impl CopyCounted { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for CopyCounted { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const CopyCounted); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); @@ -178,10 +193,13 @@ impl CopyConstructibleUnsafe for CopyCounted { Default, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct HasCopyCounted { pub c: CopyCounted, pub arr: [CopyCounted; 2], } +impl HasCopyCounted {} #[repr(C)] #[derive( Clone, @@ -192,10 +210,18 @@ pub struct HasCopyCounted { CopyConstructibleUnsafe, MovableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct ExplicitOperatorCall { pub w: Vec, } +impl ExplicitOperatorCall { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).w).write(Vec::new()); + } +} impl CopyAssignableUnsafe for ExplicitOperatorCall { unsafe fn copy_assign( this: *mut Self, @@ -208,44 +234,40 @@ impl CopyAssignableUnsafe for ExplicitOperatorCall { return &mut (*this); } } -impl DefaultConstructibleUnsafe for ExplicitOperatorCall { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).w).write(Vec::new()); - } -} pub static mut swap_copies_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MoveConstructibleUnsafe, SwappableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Swapped { pub v: i32, } impl Swapped { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } - pub unsafe fn copy_assign(this: *mut Self, o: *mut Swapped) -> *mut Swapped { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Swapped); + (&raw mut (*this).v).write((*o).v); + (*std::cell::LazyCell::force_mut(&mut *&raw mut swap_copies_2)).prefix_inc(); + } + pub unsafe fn copy_assign(this: *mut Self, o: ParameterObjectUnsafe) -> *mut Swapped { + let o = (o.as_ptr() as *mut Swapped); let mut t: i32 = (*this).v; (*this).v = (*o).v; (*o).v = t; return &mut (*this); } } -impl CopyConstructibleUnsafe for Swapped { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { - let o = (o.as_ptr() as *const Swapped); - (&raw mut (*this).v).write((*o).v); - (*std::cell::LazyCell::force_mut(&mut *&raw mut swap_copies_2)).prefix_inc(); - } -} impl CopyAssignableUnsafe for Swapped { unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { object_unsafe!( @@ -253,7 +275,7 @@ impl CopyAssignableUnsafe for Swapped { Swapped, LvalueRefUnsafe::bind((src.as_ptr() as *const Swapped)) ); - Swapped::copy_assign(this, &raw mut __o); + Swapped::copy_assign(this, ParameterObjectUnsafe::bind(&raw mut __o)); this } } @@ -264,7 +286,7 @@ impl MoveAssignableUnsafe for Swapped { Swapped, RvalueRefUnsafe::bind((src.as_ptr() as *mut Swapped)) ); - Swapped::copy_assign(this, &raw mut __o); + Swapped::copy_assign(this, ParameterObjectUnsafe::bind(&raw mut __o)); this } } @@ -278,9 +300,12 @@ impl MoveAssignableUnsafe for Swapped { Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct HoldsSwapped { pub s: Swapped, } +impl HoldsSwapped {} #[repr(C)] #[derive( Copy, @@ -292,20 +317,21 @@ pub struct HoldsSwapped { CopyConstructibleUnsafe, MoveConstructibleUnsafe, SwappableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct VoidAssign { pub x: i32, } impl VoidAssign { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).x).write(0); + } pub unsafe fn copy_assign(this: *mut Self, o: *const VoidAssign) { (*this).x = (((*o).x) + (5)); } } -impl DefaultConstructibleUnsafe for VoidAssign { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).x).write(0); - } -} impl CopyAssignableUnsafe for VoidAssign { unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { VoidAssign::copy_assign(this, (src.as_ptr() as *const VoidAssign)); @@ -322,8 +348,8 @@ impl Default for VoidAssign { fn default() -> Self { unsafe { { - let mut __v: VoidAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: VoidAssign = ZeroInitializationUnsafe::zero_init(); + VoidAssign::constructor_1(&raw mut __v); __v } } @@ -343,12 +369,15 @@ impl Default for VoidAssign { Default, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct HoldsVoidAssign { pub v: VoidAssign, } -impl DefaultConstructibleUnsafe for HoldsVoidAssign { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).v); +impl HoldsVoidAssign { + pub unsafe fn constructor_1(this: *mut Self) { + VoidAssign::constructor_1(&raw mut (*this).v); } } pub fn main() { @@ -358,9 +387,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Partial(1, 100)); - object_unsafe!(b, Partial(2, 200)); - object_unsafe!(c, Partial(3, 300)); + object_unsafe!(a, Partial::constructor_1(1, 100)); + object_unsafe!(b, Partial::constructor_1(2, 200)); + object_unsafe!(c, Partial::constructor_1(3, 300)); assign_unsafe!(a = b); assert!(((a.v) == (2)) && ((a.keep) == (100))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (1))); @@ -373,8 +402,8 @@ unsafe fn main_0() -> i32 { }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3))); (unsafe { - let mut _o: Partial = ::zero_init(); - Partial::construct(&raw mut _o, 9, 900); + let mut _o: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut _o, 9, 900); assign_unsafe!(a = _o) }); assert!(((a.v) == (9)) && ((a.keep) == (100))); @@ -388,19 +417,19 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (6))); let mut h: Holder = Holder { p: { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 4, 40); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 4, 40); __v }, arr: [ { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 5, 50); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 5, 50); __v }, { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 6, 60); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 6, 60); __v }, ], @@ -410,33 +439,33 @@ unsafe fn main_0() -> i32 { assert!(((h.p.v) == (2)) && ((h.p.keep) == (40))); assert!(((h.arr[(1) as usize].v) == (2)) && ((h.arr[(1) as usize].keep) == (60))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (8))); - object_unsafe!(n, NonConstAssign); - object_unsafe!(n1, NonConstAssign); - object_unsafe!(n2, NonConstAssign); - object_unsafe!(cn, NonConstAssign); + object_unsafe!(n, NonConstAssign::constructor_1()); + object_unsafe!(n1, NonConstAssign::constructor_1()); + object_unsafe!(n2, NonConstAssign::constructor_1()); + object_unsafe!(cn, NonConstAssign::constructor_1()); (unsafe { NonConstAssign::operator_assign_2(&raw mut n1, &mut n) }); (unsafe { NonConstAssign::operator_assign_3(&raw mut n2, &cn) }); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); - object_unsafe!(r, RefQualified); - object_unsafe!(r1, RefQualified); + object_unsafe!(r, RefQualified::constructor_1()); + object_unsafe!(r1, RefQualified::constructor_1()); assign_unsafe!(r1 = r); assert!(((r1.mark) == (1))); let mut h2: Holder = Holder { p: { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 7, 70); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 7, 70); __v }, arr: [ { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 8, 80); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 8, 80); __v }, { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 9, 90); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 9, 90); __v }, ], @@ -445,44 +474,44 @@ unsafe fn main_0() -> i32 { 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))); - object_unsafe!(cc1, CopyCounted(1)); - object_unsafe!(cc2, CopyCounted(2)); + object_unsafe!(cc1, CopyCounted::constructor_1(1)); + object_unsafe!(cc2, CopyCounted::constructor_1(2)); assign_unsafe!(cc1 = cc2); assert!(((cc1.v) == (2))); let mut hc1: HasCopyCounted = HasCopyCounted { c: { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 1); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 1); __v }, arr: [ { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 2); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 2); __v }, { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 3); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 3); __v }, ], }; let mut hc2: HasCopyCounted = HasCopyCounted { c: { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 4); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 4); __v }, arr: [ { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 5); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 5); __v }, { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 6); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 6); __v }, ], @@ -493,8 +522,8 @@ unsafe fn main_0() -> i32 { && ((hc1.arr[(1) as usize].v) == (6)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (0))); - object_unsafe!(e1, ExplicitOperatorCall); - object_unsafe!(e2, ExplicitOperatorCall); + object_unsafe!(e1, ExplicitOperatorCall::constructor_1()); + object_unsafe!(e2, ExplicitOperatorCall::constructor_1()); { let mut __tmp_0: i32 = 5; e1.w.push_moved(&mut __tmp_0) @@ -503,12 +532,12 @@ unsafe fn main_0() -> i32 { assert!( (((e2.w.len()) == (1_usize)) && ((e2.w[(0_usize)]) == (5))) && ((e1.w.len()) == (1_usize)) ); - object_unsafe!(sw1, Swapped(1)); - object_unsafe!(sw2, Swapped(2)); + object_unsafe!(sw1, Swapped::constructor_1(1)); + object_unsafe!(sw2, Swapped::constructor_1(2)); (unsafe { - let mut _o: Swapped = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut _o, LvalueRefUnsafe::bind(&sw2)); - Swapped::copy_assign(&raw mut sw1, &mut _o) + let mut _o: Swapped = ZeroInitializationUnsafe::zero_init(); + Swapped::constructor_2(&raw mut _o, LvalueRefUnsafe::bind(&sw2)); + Swapped::copy_assign(&raw mut sw1, ParameterObjectUnsafe::bind(&mut _o)) }); assert!( ((sw1.v) == (2)) @@ -516,15 +545,15 @@ unsafe fn main_0() -> i32 { ); let mut hs1: HoldsSwapped = HoldsSwapped { s: { - let mut __v: Swapped = ::zero_init(); - Swapped::construct(&raw mut __v, 3); + let mut __v: Swapped = ZeroInitializationUnsafe::zero_init(); + Swapped::constructor_1(&raw mut __v, 3); __v }, }; let mut hs2: HoldsSwapped = HoldsSwapped { s: { - let mut __v: Swapped = ::zero_init(); - Swapped::construct(&raw mut __v, 4); + let mut __v: Swapped = ZeroInitializationUnsafe::zero_init(); + Swapped::constructor_1(&raw mut __v, 4); __v }, }; @@ -533,8 +562,8 @@ unsafe fn main_0() -> i32 { ((hs1.s.v) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut swap_copies_2)) == (2)) ); - object_unsafe!(hv1, HoldsVoidAssign); - object_unsafe!(hv2, HoldsVoidAssign); + object_unsafe!(hv1, HoldsVoidAssign::constructor_1()); + object_unsafe!(hv2, HoldsVoidAssign::constructor_1()); assign_unsafe!(hv1 = hv2); assert!(((hv1.v.x) == (5))); return 0; diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index eb11c9e37a..e3052cb205 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -11,7 +11,6 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -20,17 +19,18 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Counted { pub v: i32, } impl Counted { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Counted); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); @@ -38,31 +38,42 @@ impl CopyConstructibleUnsafe for Counted { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, MoveAssignableUnsafe, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + MemberwiseUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe)] +#[constructor(constructor_3, LvalueRefUnsafe>)] pub struct NonConst { pub mark: i32, } impl NonConst { - pub unsafe fn construct_1(this: *mut Self, o: *mut NonConst) { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).mark).write(0); + } + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe) { + let o = (o.as_ptr() as *mut NonConst); (&raw mut (*this).mark).write((((*o).mark) + (1))); } - pub unsafe fn construct_2(this: *mut Self, o: *const NonConst) { + pub unsafe fn constructor_3(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const NonConst); (&raw mut (*this).mark).write((((*o).mark) + (10))); } } -impl DefaultConstructibleUnsafe for NonConst { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).mark).write(0); - } -} impl Default for NonConst { fn default() -> Self { unsafe { { - let mut __v: NonConst = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: NonConst = ZeroInitializationUnsafe::zero_init(); + NonConst::constructor_1(&raw mut __v); __v } } @@ -72,7 +83,6 @@ impl Default for NonConst { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -81,17 +91,18 @@ impl Default for NonConst { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Ignored { pub v: i32, } impl Ignored { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for Ignored { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const Ignored); (&raw mut (*this).v).write(-1_i32); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); @@ -107,31 +118,30 @@ impl CopyConstructibleUnsafe for Ignored { Default, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Holder { pub c: Counted, pub arr: [Counted; 2], } +impl Holder {} #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - CppFromUnsafe, - DefaultInitializableUnsafe, - MemberwiseUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Box_int_ { pub val: i32, } impl Box_int_ { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).val).write(v); } -} -impl CopyConstructibleUnsafe for Box_int_ { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Box_int_); (&raw mut (*this).val).write((*o).val); } @@ -141,14 +151,16 @@ impl CopyConstructibleUnsafe for Box_int_ { FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Owner { pub box_: Box_int_, } +impl Owner {} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -157,22 +169,24 @@ pub struct Owner { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct OutOfLine { pub v: i32, } impl OutOfLine { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for OutOfLine { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const OutOfLine); (&raw mut (*this).v).write((((*o).v) + (100))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } +impl OutOfLine {} #[repr(C)] #[derive( FnPtrArg, @@ -181,17 +195,19 @@ impl CopyConstructibleUnsafe for OutOfLine { MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Tracked { pub copied_from: i32, } -impl DefaultConstructibleUnsafe for Tracked { - unsafe fn default_constructor(this: *mut Self) { +impl Tracked { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).copied_from).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).copied_from).write(0); (*(&raw const (*o).copied_from).cast_mut()).prefix_inc(); @@ -212,32 +228,33 @@ impl Default for Tracked { pub unsafe fn touch_1(mut t: *const Tracked) { (*(&raw const (*t).copied_from).cast_mut()).prefix_inc(); } -pub unsafe fn by_value_2(c: *mut Counted) -> i32 { +pub unsafe fn by_value_2(c: ParameterObjectUnsafe) -> i32 { + let c = (c.as_ptr() as *mut Counted); return (*c).v; } pub unsafe fn make_3(__return: *mut Counted, mut v: i32) { - object_unsafe!(c, Counted(v)); - CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(&c)); + object_unsafe!(c, Counted::constructor_1(v)); + Counted::constructor_2(__return, LvalueRefUnsafe::bind(&c)); return; } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct SelfPtr { pub self_: *mut SelfPtr, } -impl DefaultConstructibleUnsafe for SelfPtr { - unsafe fn default_constructor(this: *mut Self) { +impl SelfPtr { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).self_).write(this); } -} -impl CopyConstructibleUnsafe for SelfPtr { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const SelfPtr); (&raw mut (*this).self_).write(this); } -} -impl MoveConstructibleUnsafe for SelfPtr { - unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, _a0: RvalueRefUnsafe) { let _a0 = (_a0.as_ptr() as *mut SelfPtr); (&raw mut (*this).self_).write(this); } @@ -246,8 +263,8 @@ impl Default for SelfPtr { fn default() -> Self { unsafe { { - let mut __v: SelfPtr = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: SelfPtr = ZeroInitializationUnsafe::zero_init(); + SelfPtr::constructor_1(&raw mut __v); __v } } @@ -263,27 +280,32 @@ impl Default for SelfPtr { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct EmptyBase {} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Derived { pub c: Counted, } -impl DefaultConstructibleUnsafe for Derived { - unsafe fn default_constructor(this: *mut Self) { - Counted::construct(&raw mut (*this).c, 20); +impl Derived { + pub unsafe fn constructor_1(this: *mut Self) { + Counted::constructor_1(&raw mut (*this).c, 20); } } impl Default for Derived { fn default() -> Self { unsafe { { - let mut __v: Derived = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Derived = ZeroInitializationUnsafe::zero_init(); + Derived::constructor_1(&raw mut __v); __v } } @@ -296,50 +318,52 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Counted(1)); - object_unsafe!(b, Counted, LvalueRefUnsafe::bind(&a)); - object_unsafe!(c, Counted, LvalueRefUnsafe::bind(&a)); - object_unsafe!(d, Counted, LvalueRefUnsafe::bind(&a)); + object_unsafe!(a, Counted::constructor_1(1)); + object_unsafe!(b, Counted::constructor_2(LvalueRefUnsafe::bind(&a))); + object_unsafe!(c, Counted::constructor_2(LvalueRefUnsafe::bind(&a))); + object_unsafe!(d, Counted::constructor_2(LvalueRefUnsafe::bind(&a))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (3))); assert!((((b.v) == (1)) && ((c.v) == (1))) && ((d.v) == (1))); assert!( ((unsafe { - let mut _c: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut _c, LvalueRefUnsafe::bind(&a)); - by_value_2(&mut _c) + let mut _c: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut _c, LvalueRefUnsafe::bind(&a)); + by_value_2(ParameterObjectUnsafe::bind(&mut _c)) }) == (1)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (4))); object_unsafe!(e, Counted, |e| (unsafe { make_3(e, 5,) })); assert!(((e.v) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5))); - object_unsafe!(f, Counted(6)); + object_unsafe!(f, Counted::constructor_1(6)); assert!(((f.v) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5))); - object_unsafe!(g, Counted(7)); - object_unsafe!(h, Counted, LvalueRefUnsafe::bind(&g)); + object_unsafe!(g, Counted::constructor_1(7)); + object_unsafe!(h, Counted::constructor_2(LvalueRefUnsafe::bind(&g))); assert!(((h.v) == (7))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (6))); let mut hold: Holder = Holder { c: { - let mut __v: Counted = ::zero_init(); - Counted::construct(&raw mut __v, 8); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v, 8); __v }, arr: [ { - let mut __v: Counted = ::zero_init(); - Counted::construct(&raw mut __v, 9); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v, 9); __v }, { - let mut __v: Counted = ::zero_init(); - Counted::construct(&raw mut __v, 10); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v, 10); __v }, ], }; - object_unsafe!(hold2, Holder, LvalueRefUnsafe::bind(&hold)); + object_unsafe!(hold2, Holder, |hold2| { + ::copy_constructor(hold2, LvalueRefUnsafe::bind(&hold)) + }); assert!( (((hold2.c.v) == (8)) && ((hold2.arr[(0) as usize].v) == (9))) && ((hold2.arr[(1) as usize].v) == (10)) @@ -349,40 +373,44 @@ unsafe fn main_0() -> i32 { vec_.push_copied(&mut a); assert!(((vec_[(0_usize)].v) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (10))); - object_unsafe!(i1, Ignored(1)); - object_unsafe!(i2, Ignored, LvalueRefUnsafe::bind(&i1)); + object_unsafe!(i1, Ignored::constructor_1(1)); + object_unsafe!(i2, Ignored::constructor_2(LvalueRefUnsafe::bind(&i1))); assert!(((i1.v) == (1)) && ((i2.v) == (-1_i32))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (11))); let mut o: Owner = Owner { box_: { - let mut __v: Box_int_ = ::zero_init(); - Box_int_::construct(&raw mut __v, 3); + let mut __v: Box_int_ = ZeroInitializationUnsafe::zero_init(); + Box_int_::constructor_1(&raw mut __v, 3); __v }, }; - object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o)); + object_unsafe!(o2, Owner, |o2| { + ::move_constructor(o2, RvalueRefUnsafe::bind(&mut o)) + }); assert!(((o2.box_.val) == (3))); - object_unsafe!(ol1, OutOfLine(5)); - object_unsafe!(ol2, OutOfLine, LvalueRefUnsafe::bind(&ol1)); + object_unsafe!(ol1, OutOfLine::constructor_1(5)); + object_unsafe!(ol2, OutOfLine::constructor_2(LvalueRefUnsafe::bind(&ol1))); assert!(((ol2.v) == (105))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (12))); - object_unsafe!(n, NonConst); - object_unsafe!(n1, NonConst::construct_1(&mut n)); - object_unsafe!(cn, NonConst); - object_unsafe!(n2, NonConst::construct_2(&cn)); + object_unsafe!(n, NonConst::constructor_1()); + object_unsafe!(n1, NonConst::constructor_2(LvalueRefUnsafe::bind(&mut n))); + object_unsafe!(cn, NonConst::constructor_1()); + object_unsafe!(n2, NonConst::constructor_3(LvalueRefUnsafe::bind(&cn))); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); - object_unsafe!(t1, Tracked); - object_unsafe!(t2, Tracked, LvalueRefUnsafe::bind(&t1)); + object_unsafe!(t1, Tracked::constructor_1()); + object_unsafe!(t2, Tracked::constructor_2(LvalueRefUnsafe::bind(&t1))); assign_unsafe!(t2 = t1); assert!(((t1.copied_from) == (2))); - object_unsafe!(ct, Tracked); - object_unsafe!(t3, Tracked, LvalueRefUnsafe::bind(&ct)); + object_unsafe!(ct, Tracked::constructor_1()); + object_unsafe!(t3, Tracked::constructor_2(LvalueRefUnsafe::bind(&ct))); (unsafe { touch_1((&ct as *const Tracked)) }); assert!(((ct.copied_from) == (2))); let mut before: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)); - object_unsafe!(der, Derived); - object_unsafe!(der2, Derived, LvalueRefUnsafe::bind(&der)); + object_unsafe!(der, Derived::constructor_1()); + object_unsafe!(der2, Derived, |der2| { + ::copy_constructor(der2, LvalueRefUnsafe::bind(&der)) + }); assert!( ((der2.c.v) == (20)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((before) + (1))) @@ -390,12 +418,14 @@ unsafe fn main_0() -> i32 { let mut range: Vec = { let mut __tmp_0 = { vec_.begin() }; let mut __tmp_1 = { vec_.end() }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = (__tmp_0).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { - __v.push(>::cpp_from( - __it.iter_deref(), - )); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -410,16 +440,16 @@ unsafe fn main_0() -> i32 { selfs.reserve_exact(2_usize - len_0 as usize); }; { - let mut __tmp_3: SelfPtr = ::zero_init(); + let mut __tmp_3: SelfPtr = ZeroInitializationUnsafe::zero_init(); match (({ - DefaultConstructibleUnsafe::default_constructor(&raw mut __tmp_3); + SelfPtr::constructor_1(&raw mut __tmp_3); &mut __tmp_3 } as *mut SelfPtr),) { (__tmp_2,) => selfs.push_moved(__tmp_2), } }; - object_unsafe!(self_src, SelfPtr); + object_unsafe!(self_src, SelfPtr::constructor_1()); selfs.push_copied(&mut self_src); assert!( ((selfs[(0_usize)].self_) == (&mut selfs[(0_usize)] as *mut SelfPtr)) @@ -431,9 +461,9 @@ unsafe fn main_0() -> i32 { temps.reserve_exact(1_usize - len_0 as usize); }; { - let mut __tmp_5: Counted = ::zero_init(); + let mut __tmp_5: Counted = ZeroInitializationUnsafe::zero_init(); match (({ - Counted::construct(&raw mut __tmp_5, 30); + Counted::constructor_1(&raw mut __tmp_5, 30); &mut __tmp_5 } as *mut Counted),) { diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 7dabf54a1b..c7a1b84532 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Inner { pub x: i32, } @@ -26,7 +28,6 @@ pub struct Inner { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, @@ -34,14 +35,16 @@ pub struct Inner { SwappableUnsafe, )] #[memberwise(copy_assign, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct Explicit { pub v: i32, pub inner: Inner, pub arr: [i32; 2], } impl Explicit { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).inner).write(Inner { x: ((v) * (10)) }); (&raw mut (*this).arr).write([v, ((v) + (1))]); @@ -60,7 +63,9 @@ impl DestructibleUnsafe for Explicit { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Implicit { pub v: i32, pub inner: Inner, @@ -73,7 +78,6 @@ pub struct Implicit { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, @@ -81,17 +85,18 @@ pub struct Implicit { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct DefaultCopyUserMove { pub v: i32, } impl DefaultCopyUserMove { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl MoveConstructibleUnsafe for DefaultCopyUserMove { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut DefaultCopyUserMove); (&raw mut (*this).v).write((*o).v); (*o).v = 0; @@ -112,24 +117,24 @@ impl MoveAssignableUnsafe for DefaultCopyUserMove { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct UserCopyDefaultMove { pub v: i32, } impl UserCopyDefaultMove { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for UserCopyDefaultMove { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const UserCopyDefaultMove); (&raw mut (*this).v).write((((*o).v) + (100))); } @@ -148,14 +153,15 @@ impl CopyAssignableUnsafe for UserCopyDefaultMove { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] pub struct Buffer { pub data: Vec, pub rows: Vec>, @@ -163,7 +169,7 @@ pub struct Buffer { pub arr: [i32; 2], } impl Buffer { - pub unsafe fn construct(this: *mut Self, mut n: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut n: i32) { (&raw mut (*this).data).write(Vec::from_fn((n as usize), |_| { copy_constructed_unsafe(&mut n) })); @@ -183,14 +189,17 @@ impl Buffer { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Owner { pub data: Vec, pub n: i32, pub arr: [i32; 2], pub p: Option>, } -impl DefaultConstructibleUnsafe for Owner { - unsafe fn default_constructor(this: *mut Self) { +impl Owner { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(Vec::new()); (&raw mut (*this).n).write(0_i32); (&raw mut (*this).arr).write([0_i32; 2]); @@ -210,11 +219,14 @@ impl DefaultConstructibleUnsafe for Owner { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Copyable { pub data: Vec, } -impl DefaultConstructibleUnsafe for Copyable { - unsafe fn default_constructor(this: *mut Self) { +impl Copyable { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(Vec::new()); } } @@ -222,13 +234,14 @@ impl DefaultConstructibleUnsafe for Copyable { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] pub struct Holder { pub inner: Inner, #[destroy] @@ -236,9 +249,9 @@ pub struct Holder { pub p: Option>, } impl Holder { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).inner).write(Inner { x: v }); - Explicit::construct(&raw mut (*this).e, v); + Explicit::constructor_1(&raw mut (*this).e, v); (&raw mut (*this).p).write(None); } } @@ -248,10 +261,16 @@ pub unsafe fn same_0(a: *const Explicit, b: *const Explicit) -> bool { && (((*a).arr[(1) as usize]) == ((*b).arr[(1) as usize])); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[constructor(constructor_1)] pub struct SeesThis { pub self_: *mut SeesThis, } +impl SeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).self_).write(std::ptr::null_mut()); + } +} impl CopyAssignableUnsafe for SeesThis { unsafe fn copy_assign(this: *mut Self, _a0: LvalueRefUnsafe>) -> *mut SeesThis { let _a0 = (_a0.as_ptr() as *const SeesThis); @@ -266,11 +285,6 @@ impl MoveAssignableUnsafe for SeesThis { return &mut (*this); } } -impl DefaultConstructibleUnsafe for SeesThis { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).self_).write(std::ptr::null_mut()); - } -} impl Default for SeesThis { fn default() -> Self { unsafe { @@ -283,30 +297,35 @@ impl Default for SeesThis { #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, Default)] #[memberwise(copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[constructor(constructor_1)] pub struct HasSeesThis { pub s: SeesThis, pub v: Vec, } -impl DefaultConstructibleUnsafe for HasSeesThis { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).s); +impl HasSeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + SeesThis::constructor_1(&raw mut (*this).s); (&raw mut (*this).v).write(Vec::new()); } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, +)] +#[conversions(move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct Counted_int_ { pub v: i32, pub moves: i32, } -impl DefaultConstructibleUnsafe for Counted_int_ { - unsafe fn default_constructor(this: *mut Self) { +impl Counted_int_ { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(0_i32); (&raw mut (*this).moves).write(0); } -} -impl MoveConstructibleUnsafe for Counted_int_ { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_2(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Counted_int_); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -335,46 +354,47 @@ impl Default for Counted_int_ { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct HasCounted { pub c: Counted_int_, pub w: Vec, } -impl DefaultConstructibleUnsafe for HasCounted { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).c); +impl HasCounted { + pub unsafe fn constructor_1(this: *mut Self) { + Counted_int_::constructor_1(&raw mut (*this).c); (&raw mut (*this).w).write(Vec::new()); } } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, )] -#[cpp_from(i32, construct_1, value)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRefUnsafe>)] +#[constructor(constructor_4, RvalueRefUnsafe)] pub struct CtorSeesThis { pub self_: *mut CtorSeesThis, pub id: i32, } impl CtorSeesThis { - pub unsafe fn construct_1(this: *mut Self, mut id: i32) { - DefaultConstructibleUnsafe::default_constructor(this); - (*this).id = id; - } -} -impl DefaultConstructibleUnsafe for CtorSeesThis { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).self_).write(this); (&raw mut (*this).id).write(0); } -} -impl CopyConstructibleUnsafe for CtorSeesThis { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, mut id: i32) { + CtorSeesThis::constructor_1(this); + (*this).id = id; + } + pub unsafe fn constructor_3(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const CtorSeesThis); (&raw mut (*this).self_).write(this); (&raw mut (*this).id).write(0); } -} -impl MoveConstructibleUnsafe for CtorSeesThis { - unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { + pub unsafe fn constructor_4(this: *mut Self, _a0: RvalueRefUnsafe) { let _a0 = (_a0.as_ptr() as *mut CtorSeesThis); (&raw mut (*this).self_).write(this); (&raw mut (*this).id).write(0); @@ -402,8 +422,8 @@ impl Default for CtorSeesThis { fn default() -> Self { unsafe { { - let mut __v: CtorSeesThis = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: CtorSeesThis = ZeroInitializationUnsafe::zero_init(); + CtorSeesThis::constructor_1(&raw mut __v); __v } } @@ -419,13 +439,16 @@ impl Default for CtorSeesThis { Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct HasCtorSeesThis { pub x: CtorSeesThis, pub v: Vec, } -impl DefaultConstructibleUnsafe for HasCtorSeesThis { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); +impl HasCtorSeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + CtorSeesThis::constructor_1(&raw mut (*this).x); (&raw mut (*this).v).write(Vec::new()); } } @@ -434,22 +457,25 @@ impl DefaultConstructibleUnsafe for HasCtorSeesThis { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct InitsCtorSeesThis { pub x: CtorSeesThis, pub y: CtorSeesThis, } -impl DefaultConstructibleUnsafe for InitsCtorSeesThis { - unsafe fn default_constructor(this: *mut Self) { - CtorSeesThis::construct_1(&raw mut (*this).x, 1); - CtorSeesThis::construct_1(&raw mut (*this).y, 2); +impl InitsCtorSeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + CtorSeesThis::constructor_2(&raw mut (*this).x, 1); + CtorSeesThis::constructor_2(&raw mut (*this).y, 2); } } impl Default for InitsCtorSeesThis { fn default() -> Self { unsafe { { - let mut __v: InitsCtorSeesThis = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: InitsCtorSeesThis = ZeroInitializationUnsafe::zero_init(); + InitsCtorSeesThis::constructor_1(&raw mut __v); __v } } @@ -466,28 +492,26 @@ impl Default for InitsCtorSeesThis { SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct OutOfLineDefaulted { pub x: CtorSeesThis, pub v: i32, } impl OutOfLineDefaulted { pub unsafe fn construct(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + CtorSeesThis::constructor_1(&raw mut (*this).x); (&raw mut (*this).v).write(1); } -} -impl CopyConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const OutOfLineDefaulted); - CopyConstructibleUnsafe::copy_constructor( - &raw mut (*this).x, - LvalueRefUnsafe::bind(&(*_a0).x), - ); + CtorSeesThis::constructor_3(&raw mut (*this).x, LvalueRefUnsafe::bind(&(*_a0).x)); (&raw mut (*this).v).write((*_a0).v); } } -impl DefaultConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn default_constructor(this: *mut Self) { +impl ConstructorUnsafe<()> for OutOfLineDefaulted { + unsafe fn constructor(this: *mut Self, _: ()) { unsafe { OutOfLineDefaulted::construct(this); } @@ -497,7 +521,7 @@ impl Default for OutOfLineDefaulted { fn default() -> Self { unsafe { { - let mut __v: OutOfLineDefaulted = ::zero_init(); + let mut __v: OutOfLineDefaulted = ZeroInitializationUnsafe::zero_init(); OutOfLineDefaulted::construct(&raw mut __v); __v } @@ -505,16 +529,18 @@ impl Default for OutOfLineDefaulted { } } impl OutOfLineDefaulted {} +impl OutOfLineDefaulted {} #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[constructor(constructor_1)] pub struct OutOfLineAssign { pub s: SeesThis, pub v: i32, pub w: Vec, } -impl DefaultConstructibleUnsafe for OutOfLineAssign { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).s); +impl OutOfLineAssign { + pub unsafe fn constructor_1(this: *mut Self) { + SeesThis::constructor_1(&raw mut (*this).s); (&raw mut (*this).v).write(1); (&raw mut (*this).w).write(Vec::new()); } @@ -571,7 +597,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Explicit(1)); + object_unsafe!(a, Explicit::constructor_1(1)); let mut b: Explicit = a.clone(); let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { DestructibleUnsafe::destroy(__p) @@ -588,12 +614,12 @@ unsafe fn main_0() -> i32 { ((unsafe { same_0(&b, &a,) }) && (unsafe { same_0(&c, &a,) })) && (unsafe { same_0(&d, &a,) }) ); - object_unsafe!(e, Explicit(2)); - object_unsafe!(f, Explicit(3)); + object_unsafe!(e, Explicit::constructor_1(2)); + object_unsafe!(f, Explicit::constructor_1(3)); assign_unsafe!(e = b); assign_unsafe!(f = RvalueRefUnsafe(c)); assert!((unsafe { same_0(&e, &b,) }) && (unsafe { same_0(&f, &c,) })); - object_unsafe!(g, Explicit(4)); + object_unsafe!(g, Explicit::constructor_1(4)); assign_unsafe!(g = (*assign_unsafe!(e = f))); assert!((unsafe { same_0(&g, &f,) }) && (unsafe { same_0(&e, &f,) })); let mut i: Implicit = Implicit { @@ -615,39 +641,52 @@ unsafe fn main_0() -> i32 { let mut vec_: Vec = Vec::new(); vec_.push_copied(&mut b); match ((&mut { - let mut __v: Explicit = ::zero_init(); - Explicit::construct(&raw mut __v, 9); + let mut __v: Explicit = ZeroInitializationUnsafe::zero_init(); + Explicit::constructor_1(&raw mut __v, 9); __v } as *mut Explicit),) { (__tmp_0,) => vec_.push_moved(__tmp_0), }; assert!(((vec_[(0_usize)].v) == (1)) && ((vec_[(1_usize)].v) == (9))); - object_unsafe!(m, DefaultCopyUserMove(7)); + object_unsafe!(m, DefaultCopyUserMove::constructor_1(7)); let mut m1: DefaultCopyUserMove = m; - object_unsafe!(m2, DefaultCopyUserMove, RvalueRefUnsafe::bind(&mut m)); + object_unsafe!( + m2, + DefaultCopyUserMove::constructor_3(RvalueRefUnsafe::bind(&mut m)) + ); assert!((((m1.v) == (7)) && ((m2.v) == (7))) && ((m.v) == (0))); - object_unsafe!(m3, DefaultCopyUserMove(1)); - object_unsafe!(m4, DefaultCopyUserMove(1)); + object_unsafe!(m3, DefaultCopyUserMove::constructor_1(1)); + object_unsafe!(m4, DefaultCopyUserMove::constructor_1(1)); assign_unsafe!(m3 = m1); assign_unsafe!(m4 = RvalueRefUnsafe(m1)); assert!((((m3.v) == (7)) && ((m4.v) == (7))) && ((m1.v) == (0))); - object_unsafe!(u, UserCopyDefaultMove(8)); - object_unsafe!(u1, UserCopyDefaultMove, LvalueRefUnsafe::bind(&u)); - object_unsafe!(u2, UserCopyDefaultMove, RvalueRefUnsafe::bind(&mut u)); + object_unsafe!(u, UserCopyDefaultMove::constructor_1(8)); + object_unsafe!( + u1, + UserCopyDefaultMove::constructor_2(LvalueRefUnsafe::bind(&u)) + ); + object_unsafe!(u2, UserCopyDefaultMove, |u2| { + ::move_constructor( + u2, + RvalueRefUnsafe::bind(&mut u), + ) + }); assert!((((u1.v) == (108)) && ((u2.v) == (8))) && ((u.v) == (8))); - object_unsafe!(u3, UserCopyDefaultMove(1)); - object_unsafe!(u4, UserCopyDefaultMove(1)); + object_unsafe!(u3, UserCopyDefaultMove::constructor_1(1)); + object_unsafe!(u4, UserCopyDefaultMove::constructor_1(1)); assign_unsafe!(u3 = u2); assign_unsafe!(u4 = RvalueRefUnsafe(u2)); assert!(((u3.v) == (108)) && ((u4.v) == (8))); - object_unsafe!(p, Buffer(3)); - object_unsafe!(q, Buffer, RvalueRefUnsafe::bind(&mut p)); + object_unsafe!(p, Buffer::constructor_1(3)); + object_unsafe!(q, Buffer, |q| { + ::move_constructor(q, RvalueRefUnsafe::bind(&mut p)) + }); assert!( ((((q.n) == (3)) && ((q.data.len()) == (3_usize))) && ((q.data[(2_usize)]) == (3))) && (p.data.is_empty()) ); - object_unsafe!(r, Buffer(1)); + object_unsafe!(r, Buffer::constructor_1(1)); assign_unsafe!(r = RvalueRefUnsafe(q)); assert!( ((((r.n) == (3)) && ((r.data.len()) == (3_usize))) && ((r.arr[(1) as usize]) == (4))) @@ -662,8 +701,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_1 = { { - let mut __v: Buffer = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( + let mut __v: Buffer = ZeroInitializationUnsafe::zero_init(); + ::move_constructor( &raw mut __v, RvalueRefUnsafe::bind(&mut bufs[(0_usize)]), ); @@ -676,7 +715,7 @@ unsafe fn main_0() -> i32 { (((bufs[(1_usize)].n) == (3)) && ((bufs[(1_usize)].data.len()) == (3_usize))) && (bufs[(0_usize)].data.is_empty()) ); - object_unsafe!(o1, Owner); + object_unsafe!(o1, Owner::constructor_1()); { let mut __tmp_2: i32 = 5; o1.data.push_moved(&mut __tmp_2) @@ -692,7 +731,9 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(__tmp_3)) } }; - object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o1)); + object_unsafe!(o2, Owner, |o2| { + ::move_constructor(o2, RvalueRefUnsafe::bind(&mut o1)) + }); assert!( ((((o2.n) == (5)) && ((o2.data.len()) == (1_usize))) && ((o2.arr[(1) as usize]) == (6))) && ((*o2 @@ -709,7 +750,7 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - object_unsafe!(o3, Owner); + object_unsafe!(o3, Owner::constructor_1()); assign_unsafe!(o3 = RvalueRefUnsafe(o2)); assert!( ((((o3.n) == (5)) && ((o3.data[(0_usize)]) == (5))) && ((o3.arr[(0) as usize]) == (5))) @@ -731,13 +772,15 @@ unsafe fn main_0() -> i32 { data: Vec::from([1, 2]), }; let mut c2: Copyable = c1.clone(); - object_unsafe!(c3, Copyable, RvalueRefUnsafe::bind(&mut c1)); + object_unsafe!(c3, Copyable, |c3| { + ::move_constructor(c3, RvalueRefUnsafe::bind(&mut c1)) + }); assert!(((c2.data.len()) == (2_usize)) && ((c3.data.len()) == (2_usize))); assert!(c1.data.is_empty()); - object_unsafe!(c4, Copyable); + object_unsafe!(c4, Copyable::constructor_1()); assign_unsafe!(c4 = RvalueRefUnsafe(c3)); assert!(((c4.data[(1_usize)]) == (2)) && (c3.data.is_empty())); - object_unsafe!(h1, Holder(4)); + object_unsafe!(h1, Holder::constructor_1(4)); { let mut __tmp_4 = { (Box::leak(Box::new(9)) as *mut i32) }; h1.p = if __tmp_4.is_null() { @@ -746,7 +789,9 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(__tmp_4)) } }; - object_unsafe!(h2, Holder, RvalueRefUnsafe::bind(&mut h1)); + object_unsafe!(h2, Holder, |h2| { + ::move_constructor(h2, RvalueRefUnsafe::bind(&mut h1)) + }); assert!( ((((h2.inner.x) == (4)) && ((h2.e.v) == (4))) && ((*h2 @@ -760,7 +805,7 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - object_unsafe!(h3, Holder(1)); + object_unsafe!(h3, Holder::constructor_1(1)); assign_unsafe!(h3 = RvalueRefUnsafe(h2)); assert!( ((((h3.inner.x) == (4)) && ((h3.e.arr[(1) as usize]) == (5))) @@ -775,42 +820,57 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - object_unsafe!(t1, HasSeesThis); - object_unsafe!(t2, HasSeesThis); - object_unsafe!(t3, HasSeesThis); + object_unsafe!(t1, HasSeesThis::constructor_1()); + object_unsafe!(t2, HasSeesThis::constructor_1()); + object_unsafe!(t3, HasSeesThis::constructor_1()); assign_unsafe!(t2 = RvalueRefUnsafe(t1)); assert!(((t2.s.self_) == (&mut t2.s as *mut SeesThis))); assign_unsafe!(t3 = t2); assert!(((t3.s.self_) == (&mut t3.s as *mut SeesThis))); - object_unsafe!(k1, HasCounted); - object_unsafe!(k2, HasCounted, RvalueRefUnsafe::bind(&mut k1)); + object_unsafe!(k1, HasCounted::constructor_1()); + object_unsafe!(k2, HasCounted, |k2| { + ::move_constructor( + k2, + RvalueRefUnsafe::bind(&mut k1), + ) + }); assert!(((k2.c.moves) == (1))); - object_unsafe!(k3, HasCounted); + object_unsafe!(k3, HasCounted::constructor_1()); assign_unsafe!(k3 = RvalueRefUnsafe(k2)); assert!(((k3.c.moves) == (2))); { - object_unsafe!(d, CtorSeesThis); + object_unsafe!(d, CtorSeesThis::constructor_1()); assert!(((d.self_) == (&mut d as *mut CtorSeesThis))); - object_unsafe!(e, CtorSeesThis, LvalueRefUnsafe::bind(&d)); + object_unsafe!(e, CtorSeesThis::constructor_3(LvalueRefUnsafe::bind(&d))); assert!(((e.self_) == (&mut e as *mut CtorSeesThis))); - object_unsafe!(f, CtorSeesThis::construct_1(3)); + object_unsafe!(f, CtorSeesThis::constructor_2(3)); assert!(((f.self_) == (&mut f as *mut CtorSeesThis)) && ((f.id) == (3))); - object_unsafe!(h1, HasCtorSeesThis); + object_unsafe!(h1, HasCtorSeesThis::constructor_1()); assert!(((h1.x.self_) == (&mut h1.x as *mut CtorSeesThis))); - object_unsafe!(h2, HasCtorSeesThis, LvalueRefUnsafe::bind(&h1)); + object_unsafe!(h2, HasCtorSeesThis, |h2| { + ::copy_constructor( + h2, + LvalueRefUnsafe::bind(&h1), + ) + }); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); - object_unsafe!(h3, HasCtorSeesThis, RvalueRefUnsafe::bind(&mut h1)); + object_unsafe!(h3, HasCtorSeesThis, |h3| { + ::move_constructor( + h3, + RvalueRefUnsafe::bind(&mut h1), + ) + }); assert!(((h3.x.self_) == (&mut h3.x as *mut CtorSeesThis))); assign_unsafe!(h2 = RvalueRefUnsafe(h3)); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); assign_unsafe!(h2 = h1); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); - object_unsafe!(i, InitsCtorSeesThis); + object_unsafe!(i, InitsCtorSeesThis::constructor_1()); assert!(((i.x.self_) == (&mut i.x as *mut CtorSeesThis)) && ((i.x.id) == (1))); assert!(((i.y.self_) == (&mut i.y as *mut CtorSeesThis)) && ((i.y.id) == (2))); let mut p: *mut CtorSeesThis = { let __p: *mut CtorSeesThis = Box::leak(Box::new(::zero_init())); - CtorSeesThis::construct_1(__p, 4); + CtorSeesThis::constructor_2(__p, 4); __p }; assert!((((*p).self_) == (p)) && (((*p).id) == (4))); @@ -823,11 +883,14 @@ unsafe fn main_0() -> i32 { object_unsafe!(o1, OutOfLineDefaulted()); assert!(((o1.v) == (1)) && ((o1.x.self_) == (&mut o1.x as *mut CtorSeesThis))); o1.v = 2; - object_unsafe!(o2, OutOfLineDefaulted, LvalueRefUnsafe::bind(&o1)); + object_unsafe!( + o2, + OutOfLineDefaulted::constructor_2(LvalueRefUnsafe::bind(&o1)) + ); assert!(((o2.v) == (2)) && ((o2.x.self_) == (&mut o2.x as *mut CtorSeesThis))); - object_unsafe!(a1, OutOfLineAssign); - object_unsafe!(a2, OutOfLineAssign); - object_unsafe!(a3, OutOfLineAssign); + object_unsafe!(a1, OutOfLineAssign::constructor_1()); + object_unsafe!(a2, OutOfLineAssign::constructor_1()); + object_unsafe!(a3, OutOfLineAssign::constructor_1()); a1.v = 3; { let mut __tmp_5: i32 = 4; diff --git a/tests/unit/out/unsafe/copy_move_deleted.rs b/tests/unit/out/unsafe/copy_move_deleted.rs index be888a3cd0..3824cb5879 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.rs @@ -10,22 +10,22 @@ use std::rc::Rc; #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, SwappableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct NoCopy { pub v: i32, } impl NoCopy { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl MoveConstructibleUnsafe for NoCopy { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut NoCopy); (&raw mut (*this).v).write((*o).v); (*o).v = 0; @@ -40,17 +40,20 @@ impl MoveAssignableUnsafe for NoCopy { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_2)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct PrivateCopy { pub v: i32, } -impl DefaultConstructibleUnsafe for PrivateCopy { - unsafe fn default_constructor(this: *mut Self) { +impl PrivateCopy { + pub unsafe fn constructor_2(this: *mut Self) { (&raw mut (*this).v).write(0); } -} -impl MoveConstructibleUnsafe for PrivateCopy { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut PrivateCopy); (&raw mut (*this).v).write((*o).v); (*o).v = 0; @@ -68,20 +71,21 @@ impl Default for PrivateCopy { fn default() -> Self { unsafe { { - let mut __v: PrivateCopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: PrivateCopy = ZeroInitializationUnsafe::zero_init(); + PrivateCopy::constructor_2(&raw mut __v); __v } } } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[constructor(constructor_1)] pub struct Immovable { pub v: i32, } -impl DefaultConstructibleUnsafe for Immovable { - unsafe fn default_constructor(this: *mut Self) { +impl Immovable { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(0); } } @@ -89,8 +93,8 @@ impl Default for Immovable { fn default() -> Self { unsafe { { - let mut __v: Immovable = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Immovable = ZeroInitializationUnsafe::zero_init(); + Immovable::constructor_1(&raw mut __v); __v } } @@ -106,10 +110,13 @@ impl Default for Immovable { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] pub struct Container { pub inner: NoCopy, pub tag: i32, } +impl Container {} #[repr(C)] #[derive( FnPtrArg, @@ -120,11 +127,14 @@ pub struct Container { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct VecHolder { pub items: Vec, } -impl DefaultConstructibleUnsafe for VecHolder { - unsafe fn default_constructor(this: *mut Self) { +impl VecHolder { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).items).write(Vec::new()); } } @@ -141,36 +151,40 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, NoCopy(1)); - object_unsafe!(b, NoCopy, RvalueRefUnsafe::bind(&mut a)); + object_unsafe!(a, NoCopy::constructor_1(1)); + object_unsafe!(b, NoCopy::constructor_3(RvalueRefUnsafe::bind(&mut a))); assert!(((b.v) == (1)) && ((a.v) == (0))); assign_unsafe!(a = RvalueRefUnsafe(b)); assert!(((a.v) == (1)) && ((b.v) == (0))); (unsafe { bump_0((&mut a as *mut NoCopy)) }); assert!(((a.v) == (2))); - object_unsafe!(p, PrivateCopy); + object_unsafe!(p, PrivateCopy::constructor_2()); p.v = 3; - object_unsafe!(q, PrivateCopy, RvalueRefUnsafe::bind(&mut p)); + object_unsafe!(q, PrivateCopy::constructor_3(RvalueRefUnsafe::bind(&mut p))); assert!(((q.v) == (3)) && ((p.v) == (0))); assign_unsafe!(p = RvalueRefUnsafe(q)); assert!(((p.v) == (3)) && ((q.v) == (0))); - object_unsafe!(im, Immovable); + object_unsafe!(im, Immovable::constructor_1()); im.v = 4; (unsafe { bump_ref_1(&mut im) }); let mut pim: *mut Immovable = (&mut im as *mut Immovable); assert!((((*pim).v) == (5))); let mut c: Container = Container { inner: { - let mut __v: NoCopy = ::zero_init(); - NoCopy::construct(&raw mut __v, 6); + let mut __v: NoCopy = ZeroInitializationUnsafe::zero_init(); + NoCopy::constructor_1(&raw mut __v, 6); __v }, tag: 7, }; - object_unsafe!(d, Container, RvalueRefUnsafe::bind(&mut c)); + object_unsafe!(d, Container, |d| { + ::move_constructor(d, RvalueRefUnsafe::bind(&mut c)) + }); assert!((((d.inner.v) == (6)) && ((d.tag) == (7))) && ((c.inner.v) == (0))); - object_unsafe!(h, VecHolder); - object_unsafe!(h2, VecHolder, RvalueRefUnsafe::bind(&mut h)); + object_unsafe!(h, VecHolder::constructor_1()); + object_unsafe!(h2, VecHolder, |h2| { + ::move_constructor(h2, RvalueRefUnsafe::bind(&mut h)) + }); assert!(((h2.items.len()) == (0_usize))); return 0; } @@ -179,8 +193,8 @@ impl CopyAssignableUnsafe for PrivateCopy { unreachable!("PrivateCopy::copy_assign is never defined") } } -impl CopyConstructibleUnsafe for PrivateCopy { - unsafe fn copy_constructor(this: *mut Self, _: LvalueRefUnsafe>) { +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for PrivateCopy { + unsafe fn constructor(this: *mut Self, _: (LvalueRefUnsafe>,)) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/unsafe/default.rs b/tests/unit/out/unsafe/default.rs index a192846a4e..961b1b4023 100644 --- a/tests/unit/out/unsafe/default.rs +++ b/tests/unit/out/unsafe/default.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pointers { pub x1: *mut i32, pub x2: *const i32, @@ -34,7 +36,9 @@ pub struct Pointers { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct SmallArrays { pub a: [i32; 32], pub f: Option i32>, @@ -50,7 +54,9 @@ pub struct SmallArrays { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 90b63a8497..23bb7e5c10 100644 --- a/tests/unit/out/unsafe/default_function_arguments.rs +++ b/tests/unit/out/unsafe/default_function_arguments.rs @@ -14,21 +14,28 @@ pub unsafe fn baz_1(mut a: *mut i32, mut b: *mut i32) -> bool { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, TriviallyCopyableUnsafe, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct Bar { pub v: i32, } impl Bar { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } } -impl DefaultConstructibleUnsafe for Bar { - unsafe fn default_constructor(this: *mut Self) { +impl ConstructorUnsafe<()> for Bar { + unsafe fn constructor(this: *mut Self, _: ()) { unsafe { - Bar::construct(this, 1); + Bar::constructor_1(this, 1); } } } @@ -36,8 +43,8 @@ impl Default for Bar { fn default() -> Self { unsafe { { - let mut __v: Bar = ::zero_init(); - Bar::construct(&raw mut __v, 1); + let mut __v: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut __v, 1); __v } } @@ -55,8 +62,8 @@ pub unsafe fn by_ref_5(b: *const Bar) -> i32 { } pub static mut global_bar_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Bar = ::zero_init(); - Bar::construct(&raw mut __v, 9); + let mut __v: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut __v, 9); __v } }); @@ -79,12 +86,15 @@ pub unsafe fn first_9(r: *mut [i32; 3]) -> i32 { DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, i32)] pub struct Holder_int_ { pub v: i32, } impl Holder_int_ { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } } @@ -110,13 +120,13 @@ unsafe fn main_0() -> i32 { }) as i32) == (true as i32)) ); - object_unsafe!(b, Bar(1)); + object_unsafe!(b, Bar::constructor_1(1)); assert!(((b.v) == (1))); { - let mut __tmp_0: Bar = ::zero_init(); + let mut __tmp_0: Bar = ZeroInitializationUnsafe::zero_init(); assert!( (((*{ - Bar::construct(&raw mut __tmp_0, 2); + Bar::constructor_1(&raw mut __tmp_0, 2); &mut __tmp_0 }) .v) == (2)) @@ -124,18 +134,18 @@ unsafe fn main_0() -> i32 { }; let mut arr: [Bar; 3] = [ { - let mut __v: Bar = ::zero_init(); - Bar::construct(&raw mut __v, 1); + let mut __v: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut __v, 1); __v }, { - let mut __v: Bar = ::zero_init(); - Bar::construct(&raw mut __v, 1); + let mut __v: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut __v, 1); __v }, { - let mut __v: Bar = ::zero_init(); - Bar::construct(&raw mut __v, 1); + let mut __v: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut __v, 1); __v }, ]; @@ -147,15 +157,15 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut counter_2)) == (1))); assert!( ((unsafe { - let mut _b: Bar = ::zero_init(); - Bar::construct(&raw mut _b, 7); + let mut _b: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut _b, 7); by_ref_5(&mut _b) }) == (7)) ); assert!( ((unsafe { - let mut _b: Bar = ::zero_init(); - Bar::construct(&raw mut _b, 3); + let mut _b: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut _b, 3); by_ref_5(&mut _b) }) == (3)) ); @@ -166,12 +176,12 @@ unsafe fn main_0() -> i32 { ); assert!( ((unsafe { - let mut _b: Bar = ::zero_init(); - Bar::construct(&raw mut _b, 4); + let mut _b: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut _b, 4); by_global_ref_7(&mut _b) }) == (4)) ); - object_unsafe!(h, Holder_int_(4)); + object_unsafe!(h, Holder_int_::constructor_1(4)); assert!(((h.v) == (4))); assert!(((unsafe { shifted_8(3, -1_i32,) }) == (2))); assert!(((unsafe { shifted_8(3, 4,) }) == (7))); diff --git a/tests/unit/out/unsafe/default_in_statics.rs b/tests/unit/out/unsafe/default_in_statics.rs index b6fea9700d..0f0c778393 100644 --- a/tests/unit/out/unsafe/default_in_statics.rs +++ b/tests/unit/out/unsafe/default_in_statics.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Inner { pub v: i32, pub name: *const libc::c_char, @@ -31,7 +33,9 @@ pub struct Inner { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Outer { pub p1: *mut i32, pub p2: *const i32, @@ -52,7 +56,9 @@ pub struct Outer { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 37887d77ab..49713f23e3 100644 --- a/tests/unit/out/unsafe/delete_array_order.rs +++ b/tests/unit/out/unsafe/delete_array_order.rs @@ -18,6 +18,8 @@ use std::rc::Rc; MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] 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 3addd21275..c4907e839b 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -19,6 +19,8 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct S {} impl DestructibleUnsafe for S { unsafe fn destroy(this: *mut Self) { @@ -38,6 +40,8 @@ impl DestructibleUnsafe for S { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct Defaulted { #[destroy] pub s: S, @@ -56,6 +60,8 @@ pub struct Defaulted { SwappableUnsafe, )] #[memberwise(move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Middle { #[destroy] pub s: S, @@ -74,6 +80,8 @@ pub struct Middle { SwappableUnsafe, )] #[memberwise(copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Outer { #[destroy] pub m: Middle, @@ -92,6 +100,8 @@ pub struct Outer { SwappableUnsafe, )] #[memberwise(move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct ArrayMember { #[destroy] pub items: [S; 3], @@ -108,6 +118,8 @@ pub struct ArrayMember { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct EmptyBody { pub s: S, } @@ -128,6 +140,8 @@ impl DestructibleUnsafe for EmptyBody { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct Templated_char_ { pub v: libc::c_char, } @@ -150,6 +164,8 @@ impl DestructibleUnsafe for Templated_char_ { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct Templated_int_ { pub v: i32, } @@ -172,6 +188,8 @@ impl DestructibleUnsafe for Templated_int_ { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct Copied { pub v: i32, } @@ -195,6 +213,8 @@ pub static mut order_count_2: std::cell::LazyCell = std::cell::LazyCell::ne MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct Tagged { pub tag: i32, } @@ -219,6 +239,8 @@ impl DestructibleUnsafe for Tagged { SwappableUnsafe, )] #[memberwise(move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Ordered { #[destroy] pub first: Tagged, diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index 985751c001..b0e4935fc0 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -20,6 +20,8 @@ pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| un MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct S { pub v: i32, } @@ -29,11 +31,13 @@ impl DestructibleUnsafe for S { (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = (*this).v; } } -pub unsafe fn by_value_2(s: *mut S) -> i32 { +pub unsafe fn by_value_2(s: ParameterObjectUnsafe) -> i32 { + let s = (s.as_ptr() as *mut S); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (0))); return (*s).v; } -pub unsafe fn with_default_3(s: *mut S) -> i32 { +pub unsafe fn with_default_3(s: ParameterObjectUnsafe) -> i32 { + let s = (s.as_ptr() as *mut S); return (*s).v; } #[repr(C)] @@ -46,15 +50,20 @@ pub unsafe fn with_default_3(s: *mut S) -> i32 { DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, ParameterObjectUnsafe)] pub struct Holder { pub v: i32, } impl Holder { - pub unsafe fn construct(this: *mut Self, s: *mut S) { + pub unsafe fn constructor_1(this: *mut Self, s: ParameterObjectUnsafe) { + let s = (s.as_ptr() as *mut S); (&raw mut (*this).v).write((*s).v); } - pub unsafe fn add(this: *const Self, s: *mut S) -> i32 { + pub unsafe fn add(this: *const Self, s: ParameterObjectUnsafe) -> i32 { + let s = (s.as_ptr() as *mut S); return (((*this).v) + ((*s).v)); } } @@ -73,7 +82,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _s: S = s.clone(); - by_value_2(&mut _s) + by_value_2(ParameterObjectUnsafe::bind(&mut _s)) }) == (1)) ); assert!( @@ -86,7 +95,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _s: S = S { v: 2 }; - by_value_2(&mut _s) + by_value_2(ParameterObjectUnsafe::bind(&mut _s)) }) == (2)) ); assert!( @@ -97,7 +106,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _s: S = S { v: 5 }; - with_default_3(&mut _s) + with_default_3(ParameterObjectUnsafe::bind(&mut _s)) }) == (5)) ); assert!( @@ -108,7 +117,7 @@ unsafe fn main_0() -> i32 { { object_unsafe!(h, Holder, |h| { let mut __tmp_0: S = S { v: 3 }; - Holder::construct(h, &mut __tmp_0) + Holder::constructor_1(h, ParameterObjectUnsafe::bind(&mut __tmp_0)) }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) @@ -117,7 +126,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _s: S = S { v: 4 }; - Holder::add(&raw const h, &mut _s) + Holder::add(&raw const h, ParameterObjectUnsafe::bind(&mut _s)) }) == (7)) ); assert!( diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index b1f69ed8dc..c49a623c5c 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -20,6 +20,8 @@ pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| un MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct S { pub v: i32, } @@ -48,6 +50,8 @@ impl DestructibleUnsafe for S { SwappableUnsafe, )] #[memberwise(move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Outer { #[destroy] pub inner: S, @@ -79,7 +83,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { { - let mut __v: S = ::zero_init(); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut __v, 1) }); }; assert!( @@ -88,7 +92,7 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; &({ - let mut __v: S = ::zero_init(); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut __v, 2) }); }); assert!( @@ -97,7 +101,7 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; let mut x: i32 = { - let mut __tmp_0: S = ::zero_init(); + let mut __tmp_0: S = ZeroInitializationUnsafe::zero_init(); (*{ (unsafe { make_2(&raw mut __tmp_0, 3) }); &mut __tmp_0 @@ -110,7 +114,7 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { - let mut __tmp_1: S = ::zero_init(); + let mut __tmp_1: S = ZeroInitializationUnsafe::zero_init(); x = (unsafe { S::get( &(*{ @@ -126,7 +130,7 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { - let mut __tmp_2: Outer = ::zero_init(); + let mut __tmp_2: Outer = ZeroInitializationUnsafe::zero_init(); x = (*{ (unsafe { make_outer_3(&raw mut __tmp_2) }); &mut __tmp_2 @@ -143,7 +147,7 @@ unsafe fn main_0() -> i32 { assert!(((x) == (5)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1))); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; x = (unsafe { - let mut _s: S = ::zero_init(); + let mut _s: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut _s, 6) }); use_4(&mut _s) }); @@ -163,7 +167,7 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; x = (if ((x) == (3)) { { - let mut __v: S = ::zero_init(); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut __v, 9) }); __v } @@ -177,7 +181,7 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { - let mut __tmp_3: S = ::zero_init(); + let mut __tmp_3: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut __tmp_3, 11) }); let r: *const S = &mut __tmp_3; assert!( @@ -196,7 +200,7 @@ unsafe fn main_0() -> i32 { DestructibleUnsafe::destroy(__p) }); (unsafe { - let mut _arg0: S = ::zero_init(); + let mut _arg0: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut _arg0, 13) }); assign_unsafe!(s = _arg0) }); diff --git a/tests/unit/out/unsafe/doubly_linked_list.rs b/tests/unit/out/unsafe/doubly_linked_list.rs index 3a382f5f2d..fca0f3445f 100644 --- a/tests/unit/out/unsafe/doubly_linked_list.rs +++ b/tests/unit/out/unsafe/doubly_linked_list.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Node { pub val: i32, pub next: *mut Node, diff --git a/tests/unit/out/unsafe/emplace_receiver_alias.rs b/tests/unit/out/unsafe/emplace_receiver_alias.rs index 6547e096ea..56d855dadc 100644 --- a/tests/unit/out/unsafe/emplace_receiver_alias.rs +++ b/tests/unit/out/unsafe/emplace_receiver_alias.rs @@ -30,10 +30,14 @@ unsafe fn main_0() -> i32 { (*(unsafe { select_rows_0(alias, (&mut calls as *mut i32)) })).push({ let mut __tmp_0 = { (&mut (*alias))[(0_usize)].as_mut_ptr() }; let mut __tmp_1 = { (&mut (*alias))[(0_usize)].as_mut_ptr().offset((3) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = __tmp_0; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { - __v.push((*__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v diff --git a/tests/unit/out/unsafe/emplace_receiver_order.rs b/tests/unit/out/unsafe/emplace_receiver_order.rs index d10debc89e..5f7496e063 100644 --- a/tests/unit/out/unsafe/emplace_receiver_order.rs +++ b/tests/unit/out/unsafe/emplace_receiver_order.rs @@ -38,10 +38,14 @@ unsafe fn main_0() -> i32 { (*receiver).push({ let mut __tmp_0 = { rows[(0_usize)].as_mut_ptr() }; let mut __tmp_1 = { rows[(0_usize)].as_mut_ptr().offset((3) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = __tmp_0; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { - __v.push((*__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -61,11 +65,15 @@ unsafe fn main_0() -> i32 { let mut __tmp_3 = { rows[(0_usize)].as_mut_ptr() }; let mut __tmp_4 = { rows[(0_usize)].as_mut_ptr().offset((3) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = __tmp_3; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) { - __v.push((*__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v diff --git a/tests/unit/out/unsafe/enum_int_interop.rs b/tests/unit/out/unsafe/enum_int_interop.rs index 8a143f7963..c94e18bbda 100644 --- a/tests/unit/out/unsafe/enum_int_interop.rs +++ b/tests/unit/out/unsafe/enum_int_interop.rs @@ -29,7 +29,9 @@ pub const Tag_TAG_TWO: Tag = 2; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 1b958a6d17..2cb2f2a65f 100644 --- a/tests/unit/out/unsafe/enum_underlying_type.rs +++ b/tests/unit/out/unsafe/enum_underlying_type.rs @@ -26,12 +26,22 @@ pub const Scoped_NEG: Scoped = -2; pub const Scoped_POS: Scoped = 2; pub type Empty = bool; #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct HoldsEmpty { pub e: Empty, } -impl DefaultConstructibleUnsafe for HoldsEmpty { - unsafe fn default_constructor(this: *mut Self) { +impl HoldsEmpty { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).e).write(false); } } @@ -73,7 +83,7 @@ unsafe fn main_0() -> i32 { let mut sc: Scoped = Scoped_NEG; assert!(((sc as i32) == (-2_i32))); assert!((((Scoped_POS as i8) as i32) == (2))); - object_unsafe!(he, HoldsEmpty); + object_unsafe!(he, HoldsEmpty::constructor_1()); assert!(!(he.e)); let mut ev: Empty = false; assert!(((ev as i32) == (he.e as i32))); diff --git a/tests/unit/out/unsafe/exprs.rs b/tests/unit/out/unsafe/exprs.rs index 4608f32b8e..c2a6006a8d 100644 --- a/tests/unit/out/unsafe/exprs.rs +++ b/tests/unit/out/unsafe/exprs.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct X { pub x: i32, } @@ -30,7 +32,9 @@ pub struct X { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 77b617c94d..c472658993 100644 --- a/tests/unit/out/unsafe/fft.rs +++ b/tests/unit/out/unsafe/fft.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Complex { pub re: f64, pub img: f64, diff --git a/tests/unit/out/unsafe/field_array_elem_ptr.rs b/tests/unit/out/unsafe/field_array_elem_ptr.rs index 5550ca4167..2a770876c4 100644 --- a/tests/unit/out/unsafe/field_array_elem_ptr.rs +++ b/tests/unit/out/unsafe/field_array_elem_ptr.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Point { pub x: i32, pub y: i32, @@ -31,7 +33,9 @@ pub struct Point { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 d5c643bb92..c3d8cccdc3 100644 --- a/tests/unit/out/unsafe/field_method_receiver.rs +++ b/tests/unit/out/unsafe/field_method_receiver.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Counter { pub n: i32, } @@ -48,6 +50,9 @@ impl Counter { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S { pub tag: i32, pub c: Counter, @@ -61,9 +66,7 @@ impl S { Counter::add(&raw mut (*this).c, _k) }); } -} -impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).tag).write(0_i32); (&raw mut (*this).c).write(::default()); (&raw mut (*this).arr).write([::default(); 2]); diff --git a/tests/unit/out/unsafe/field_pointers.rs b/tests/unit/out/unsafe/field_pointers.rs index c913579ed6..f501b40dac 100644 --- a/tests/unit/out/unsafe/field_pointers.rs +++ b/tests/unit/out/unsafe/field_pointers.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Inner { pub a: i32, pub name: [libc::c_char; 8], @@ -31,7 +33,9 @@ pub struct Inner { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Header { pub tag: i32, pub size: i16, @@ -49,6 +53,9 @@ pub struct Header { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Outer { pub x: i32, pub inner: Inner, @@ -70,9 +77,7 @@ impl Outer { (*this).v.push_moved(&mut __tmp_0) }; } -} -impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).x).write(0_i32); (&raw mut (*this).inner).write(::default()); (&raw mut (*this).items).write([::default(); 3]); diff --git a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs index a7ac86a38a..691ef1594b 100644 --- a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs +++ b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S { pub a: i32, pub b: i32, diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index 3861d5282c..c673c84678 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct P { pub x: i32, } diff --git a/tests/unit/out/unsafe/fn_ptr.rs b/tests/unit/out/unsafe/fn_ptr.rs index 870d01053d..5e494ad054 100644 --- a/tests/unit/out/unsafe/fn_ptr.rs +++ b/tests/unit/out/unsafe/fn_ptr.rs @@ -38,17 +38,21 @@ pub unsafe fn identity_hash_6(mut v: bool) -> usize { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(Option u64 > , construct, ptr)] +#[conversions(copy, move)] pub struct HashHolder_unsigned_long__ptr__bool__ { pub h: Option u64>, } impl HashHolder_unsigned_long__ptr__bool__ { - pub unsafe fn construct(this: *mut Self, h: *const Option u64>) { + pub unsafe fn constructor_1( + this: *mut Self, + h: LvalueRefUnsafe u64>>>, + ) { + let h = (h.as_ptr() as *const Option u64>); (&raw mut (*this).h).write((*h)); } } @@ -99,7 +103,10 @@ unsafe fn main_0() -> i32 { Option usize>, Option u64>, >(Some(identity_hash_6)); - HashHolder_unsigned_long__ptr__bool__::construct(hh, &mut __tmp_0) + HashHolder_unsigned_long__ptr__bool__::constructor_1( + hh, + LvalueRefUnsafe::bind(&mut __tmp_0), + ) }); assert!(((unsafe { (hh.h).unwrap()(true,) }) == (1_u64))); let mut handler: Option = Some(add_to_total_8); diff --git a/tests/unit/out/unsafe/fn_ptr_cast.rs b/tests/unit/out/unsafe/fn_ptr_cast.rs index d7985a0583..b223df991e 100644 --- a/tests/unit/out/unsafe/fn_ptr_cast.rs +++ b/tests/unit/out/unsafe/fn_ptr_cast.rs @@ -39,7 +39,9 @@ pub unsafe fn test_double_cast_2() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 a92cbc2ae9..e2bac77010 100644 --- a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs +++ b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 dfedc383e9..8ebe5a40f9 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Handler { pub tag: i32, pub cb: Option i32>, @@ -37,7 +39,9 @@ pub unsafe fn negate_1(mut x: i32) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S {} impl S { pub unsafe fn pick_1(mut x: i32) -> i32 { @@ -52,33 +56,34 @@ impl S { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct MoveOnly { pub data_: i32, } impl MoveOnly { - pub unsafe fn construct(this: *mut Self, mut data: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut data: i32) { (&raw mut (*this).data_).write(data); } - pub unsafe fn get(this: *const Self) -> i32 { - return (*this).data_; - } -} -impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, x: RvalueRefUnsafe) { + pub unsafe fn constructor_2(this: *mut Self, x: RvalueRefUnsafe) { let x = (x.as_ptr() as *mut MoveOnly); (&raw mut (*this).data_).write((*x).data_); (*x).data_ = 0; } + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).data_; + } } pub unsafe fn make_move_only_2(__return: *mut MoveOnly) { - MoveOnly::construct(__return, 4); + MoveOnly::constructor_1(__return, 4); return; } -pub unsafe fn scale_move_only_3(__return: *mut MoveOnly, x: *mut MoveOnly) { - MoveOnly::construct( +pub unsafe fn scale_move_only_3(__return: *mut MoveOnly, x: ParameterObjectUnsafe) { + let x = (x.as_ptr() as *mut MoveOnly); + MoveOnly::constructor_1( __return, ((unsafe { MoveOnly::get(&raw const (*x)) }) * (10)), ); @@ -118,11 +123,12 @@ unsafe fn main_0() -> i32 { let mut mk: Option = Some(make_move_only_2); object_unsafe!(m, MoveOnly, |m| (unsafe { (mk).unwrap()(m,) })); assert!(((unsafe { MoveOnly::get(&raw const m,) }) == (4))); - let mut sc: Option = Some(scale_move_only_3); + let mut sc: Option)> = + Some(scale_move_only_3); object_unsafe!(n, MoveOnly, |n| (unsafe { - let mut _arg0: MoveOnly = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut _arg0, RvalueRefUnsafe::bind(&mut m)); - (sc).unwrap()(n, &mut _arg0) + let mut _arg0: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_2(&raw mut _arg0, RvalueRefUnsafe::bind(&mut m)); + (sc).unwrap()(n, ParameterObjectUnsafe::bind(&mut _arg0)) })); assert!(((unsafe { MoveOnly::get(&raw const n,) }) == (40))); assert!(((unsafe { MoveOnly::get(&raw const m,) }) == (0))); diff --git a/tests/unit/out/unsafe/fn_ptr_vtable.rs b/tests/unit/out/unsafe/fn_ptr_vtable.rs index 26dce17a82..28abdff5b6 100644 --- a/tests/unit/out/unsafe/fn_ptr_vtable.rs +++ b/tests/unit/out/unsafe/fn_ptr_vtable.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 0ecb990a2e..272e78474b 100644 --- a/tests/unit/out/unsafe/fn_ref.rs +++ b/tests/unit/out/unsafe/fn_ref.rs @@ -31,7 +31,9 @@ pub unsafe fn call_forwarded_4(f: Option i32>, mut x: i32) -> TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 f1fb22888d..64d9652476 100644 --- a/tests/unit/out/unsafe/for_body_destructor.rs +++ b/tests/unit/out/unsafe/for_body_destructor.rs @@ -18,6 +18,9 @@ use std::rc::Rc; MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] 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 4cee7d467c..4a89daab57 100644 --- a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs @@ -19,12 +19,15 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S { pub v: Vec, pub a: i32, } -impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(this: *mut Self) { +impl S { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(Vec::new()); (&raw mut (*this).a).write(0_i32); } @@ -36,7 +39,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S); + object_unsafe!(s, S::constructor_1()); { let mut __tmp_0: i32 = 1; s.v.push_moved(&mut __tmp_0) diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index a6c2edcaf1..a43ba113a2 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -11,31 +11,30 @@ pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } impl Tracked { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } -} -impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); @@ -50,30 +49,30 @@ pub unsafe fn chosen_overload_1(_a0: *mut Tracked) -> Overload { return Overload_kRvalueOverload; } impl Holder { - pub unsafe fn construct_1(this: *mut Self, x: *mut Tracked) { - CopyConstructibleUnsafe::copy_constructor(&raw mut (*this).t, LvalueRefUnsafe::bind(x)); + pub unsafe fn constructor_1_1(this: *mut Self, x: LvalueRefUnsafe) { + let x = (x.as_ptr() as *mut Tracked); + Tracked::constructor_2(&raw mut (*this).t, LvalueRefUnsafe::bind(x)); } } impl Holder { - pub unsafe fn construct_2(this: *mut Self, x: *mut Tracked) { - MoveConstructibleUnsafe::move_constructor(&raw mut (*this).t, RvalueRefUnsafe::bind(x)); + pub unsafe fn constructor_1_2(this: *mut Self, x: RvalueRefUnsafe) { + let x = (x.as_ptr() as *mut Tracked); + Tracked::constructor_3(&raw mut (*this).t, RvalueRefUnsafe::bind(x)); } } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - CppFromUnsafe, - DefaultInitializableUnsafe, - MemberwiseUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(copy_constructor, move_constructor)] -#[cpp_from(Tracked, construct_1, mut_ptr)] -#[cpp_from_move(Tracked, construct_2, ptr)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1_1, LvalueRefUnsafe)] +#[constructor(constructor_1_2, RvalueRefUnsafe)] pub struct Holder { pub t: Tracked, } +impl Holder {} pub unsafe fn forward_once_2(x: *mut Tracked) -> Overload { return (unsafe { chosen_overload_0(x) }); } @@ -87,11 +86,11 @@ pub unsafe fn forward_twice_5(x: *mut Tracked) -> Overload { return (unsafe { forward_once_3(x) }); } pub unsafe fn forward_into_ctor_6(__return: *mut Holder, x: *mut Tracked) { - Holder::construct_1(__return, x); + Holder::constructor_1_1(__return, LvalueRefUnsafe::bind(x)); return; } pub unsafe fn forward_into_ctor_7(__return: *mut Holder, x: *mut Tracked) { - Holder::construct_2(__return, x); + Holder::constructor_1_2(__return, RvalueRefUnsafe::bind(x)); return; } pub fn main() { @@ -101,33 +100,33 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(lvalue, Tracked(7)); + object_unsafe!(lvalue, Tracked::constructor_1(7)); assert!( (((unsafe { forward_once_2(&mut lvalue,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((lvalue.v) == (7))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - Tracked::construct(&raw mut _x, 8); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 8); forward_once_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(relayed, Tracked(9)); + object_unsafe!(relayed, Tracked::constructor_1(9)); assert!( (((unsafe { forward_twice_4(&mut relayed,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((relayed.v) == (9))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - Tracked::construct(&raw mut _x, 10); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 10); forward_twice_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(kept, Tracked(11)); + object_unsafe!(kept, Tracked::constructor_1(11)); object_unsafe!(from_lvalue, Holder, |from_lvalue| (unsafe { forward_into_ctor_6(from_lvalue, &mut kept) })); @@ -136,8 +135,8 @@ unsafe fn main_0() -> i32 { assert!(((from_lvalue.t.moves) == (0))); assert!(((kept.v) == (11))); object_unsafe!(from_rvalue, Holder, |from_rvalue| (unsafe { - let mut _x: Tracked = ::zero_init(); - Tracked::construct(&raw mut _x, 12); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 12); forward_into_ctor_7(from_rvalue, &mut _x) })); assert!(((from_rvalue.t.v) == (12))); diff --git a/tests/unit/out/unsafe/forward_decltype.rs b/tests/unit/out/unsafe/forward_decltype.rs index 6c78d55ef1..7111d34853 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -11,31 +11,30 @@ pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } impl Tracked { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } -} -impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); @@ -72,37 +71,37 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Tracked(3)); + object_unsafe!(a, Tracked::constructor_1(3)); assert!( (((unsafe { forward_by_decltype_2(&mut a,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((a.v) == (3))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - Tracked::construct(&raw mut _x, 4); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 4); forward_by_decltype_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(b, Tracked(5)); + object_unsafe!(b, Tracked::constructor_1(5)); assert!( (((unsafe { forward_abbreviated_4(&mut b,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((b.v) == (5))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - Tracked::construct(&raw mut _x, 6); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 6); forward_abbreviated_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(c, Tracked(7)); + object_unsafe!(c, Tracked::constructor_1(7)); assert!( ((unsafe { - let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&raw mut _args_1, 8); + let mut _args_1: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args_1, 8); forward_abbreviated_pack_6(&mut c, &mut _args_1) }) == ((Overload_kLvalueOverload as i32) + (Overload_kRvalueOverload as i32))) ); diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index e5f675c7ce..a49ede2127 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -13,31 +13,30 @@ pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } impl Tracked { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } -} -impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); @@ -57,8 +56,9 @@ pub unsafe fn chosen_overload_2(_a0: *const i32) -> Overload { pub unsafe fn chosen_overload_3(_a0: *mut i32) -> Overload { return Overload_kIntRvalueOverload; } -pub unsafe fn copy_or_move_into_param_4(__return: *mut Tracked, t: *mut Tracked) { - MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(t)); +pub unsafe fn copy_or_move_into_param_4(__return: *mut Tracked, t: ParameterObjectUnsafe) { + let t = (t.as_ptr() as *mut Tracked); + Tracked::constructor_3(__return, RvalueRefUnsafe::bind(t)); return; } pub fn main() { @@ -68,28 +68,28 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Tracked(5)); + object_unsafe!(a, Tracked::constructor_1(5)); assert!((((unsafe { chosen_overload_0(&a,) }) as i32) == (Overload_kLvalueOverload as i32))); assert!(((a.v) == (5))); assert!( (((unsafe { chosen_overload_1(&mut a,) }) as i32) == (Overload_kRvalueOverload as i32)) ); assert!(((a.v) == (5))); - object_unsafe!(b, Tracked(6)); + object_unsafe!(b, Tracked::constructor_1(6)); object_unsafe!(moved, Tracked, |moved| (unsafe { - let mut _t: Tracked = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut _t, RvalueRefUnsafe::bind(&mut b)); - copy_or_move_into_param_4(moved, &mut _t) + let mut _t: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_3(&raw mut _t, RvalueRefUnsafe::bind(&mut b)); + copy_or_move_into_param_4(moved, ParameterObjectUnsafe::bind(&mut _t)) })); assert!(((moved.v) == (6))); assert!(((moved.copies) == (0))); assert!(((moved.moves) == (2))); assert!(((b.v) == (0))); - object_unsafe!(c, Tracked(7)); + object_unsafe!(c, Tracked::constructor_1(7)); object_unsafe!(copied, Tracked, |copied| (unsafe { - let mut _t: Tracked = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut _t, LvalueRefUnsafe::bind(&c)); - copy_or_move_into_param_4(copied, &mut _t) + let mut _t: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut _t, LvalueRefUnsafe::bind(&c)); + copy_or_move_into_param_4(copied, ParameterObjectUnsafe::bind(&mut _t)) })); assert!(((copied.v) == (7))); assert!(((copied.copies) == (1))); diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index 5b7c949f79..21a28f6080 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -13,31 +13,30 @@ pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } impl Tracked { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } -} -impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); @@ -92,9 +91,15 @@ pub unsafe fn forward_pack_7( return digits; } impl Pair { - pub unsafe fn construct(this: *mut Self, x: *mut Tracked, y: *mut Tracked) { - CopyConstructibleUnsafe::copy_constructor(&raw mut (*this).a, LvalueRefUnsafe::bind(x)); - MoveConstructibleUnsafe::move_constructor(&raw mut (*this).b, RvalueRefUnsafe::bind(y)); + pub unsafe fn constructor_1_1( + this: *mut Self, + x: LvalueRefUnsafe, + y: RvalueRefUnsafe, + ) { + let x = (x.as_ptr() as *mut Tracked); + let y = (y.as_ptr() as *mut Tracked); + Tracked::constructor_2(&raw mut (*this).a, LvalueRefUnsafe::bind(x)); + Tracked::constructor_3(&raw mut (*this).b, RvalueRefUnsafe::bind(y)); } } #[repr(C)] @@ -102,16 +107,24 @@ impl Pair { FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1_1, LvalueRefUnsafe, RvalueRefUnsafe)] pub struct Pair { pub a: Tracked, pub b: Tracked, } +impl Pair {} pub unsafe fn forward_pack_into_ctor_8( __return: *mut Pair, args_0: *mut Tracked, args_1: *mut Tracked, ) { - Pair::construct(__return, args_0, args_1); + Pair::constructor_1_1( + __return, + LvalueRefUnsafe::bind(args_0), + RvalueRefUnsafe::bind(args_1), + ); return; } pub fn main() { @@ -122,31 +135,31 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!(((unsafe { forward_pack_4() }) == (0))); - object_unsafe!(a, Tracked(1)); + object_unsafe!(a, Tracked::constructor_1(1)); assert!(((unsafe { forward_pack_5(&mut a,) }) == (Overload_kLvalueOverload as i32))); assert!(((a.v) == (1))); assert!( ((unsafe { - let mut _args: Tracked = ::zero_init(); - Tracked::construct(&raw mut _args, 2); + let mut _args: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args, 2); forward_pack_6(&mut _args) }) == (Overload_kRvalueOverload as i32)) ); let mut i: i32 = 3; assert!( ((unsafe { - let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&raw mut _args_1, 4); + let mut _args_1: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args_1, 4); let mut _args_3: i32 = 5; forward_pack_7(&mut a, &mut _args_1, &mut i, &mut _args_3) }) == (1234)) ); assert!(((a.v) == (1))); assert!(((i) == (3))); - object_unsafe!(lhs, Tracked(6)); + object_unsafe!(lhs, Tracked::constructor_1(6)); object_unsafe!(p, Pair, |p| (unsafe { - let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&raw mut _args_1, 7); + let mut _args_1: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args_1, 7); forward_pack_into_ctor_8(p, &mut lhs, &mut _args_1) })); assert!(((p.a.v) == (6))); diff --git a/tests/unit/out/unsafe/friend.rs b/tests/unit/out/unsafe/friend.rs index 54853b5c19..1572274b47 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -25,7 +25,9 @@ pub unsafe fn scaled_2(v: *const V, mut k: f64) -> f64 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct V { pub x: i32, } @@ -42,7 +44,9 @@ pub unsafe fn get_3(w: *const W_int_) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct W_int_ { pub x: i32, } @@ -59,7 +63,9 @@ pub unsafe fn get_4(w: *const W_long_) -> i64 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct W_long_ { pub x: i64, } @@ -73,7 +79,9 @@ pub struct W_long_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 907ea78ec0..b1a5f87c1f 100644 --- a/tests/unit/out/unsafe/function_overloading.rs +++ b/tests/unit/out/unsafe/function_overloading.rs @@ -31,7 +31,9 @@ pub unsafe fn bar_4(x: *mut i32) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Foo {} impl Foo { pub unsafe fn foo_1(this: *const Self) {} diff --git a/tests/unit/out/unsafe/global_call_temporaries.rs b/tests/unit/out/unsafe/global_call_temporaries.rs index 718dcbe31b..901f1d1e13 100644 --- a/tests/unit/out/unsafe/global_call_temporaries.rs +++ b/tests/unit/out/unsafe/global_call_temporaries.rs @@ -98,7 +98,9 @@ pub static mut call_assigned_6: std::cell::LazyCell = std::cell::LazyCell:: TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 53c5e4a197..037d1c716c 100644 --- a/tests/unit/out/unsafe/global_init_side_effect.rs +++ b/tests/unit/out/unsafe/global_init_side_effect.rs @@ -14,29 +14,30 @@ pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct S {} impl S { - pub unsafe fn construct(this: *mut Self, mut x: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += x; } } pub static mut a_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: S = ::zero_init(); - S::construct(&raw mut __v, 1); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); + S::constructor_1(&raw mut __v, 1); __v } }); pub static mut b_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: S = ::zero_init(); - S::construct(&raw mut __v, 10); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); + S::constructor_1(&raw mut __v, 10); __v } }); diff --git a/tests/unit/out/unsafe/global_non_const_init.rs b/tests/unit/out/unsafe/global_non_const_init.rs index 667aebda32..610423735b 100644 --- a/tests/unit/out/unsafe/global_non_const_init.rs +++ b/tests/unit/out/unsafe/global_non_const_init.rs @@ -28,26 +28,35 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, i32)] pub struct Ctor { pub v: i32, } impl Ctor { - pub unsafe fn construct_1(this: *mut Self, mut x: i32) { - (&raw mut (*this).v).write(x); - } -} -impl DefaultConstructibleUnsafe for Ctor { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write((unsafe { next_0() })); } + pub unsafe fn constructor_2(this: *mut Self, mut x: i32) { + (&raw mut (*this).v).write(x); + } } impl Default for Ctor { fn default() -> Self { unsafe { { - let mut __v: Ctor = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); + Ctor::constructor_1(&raw mut __v); __v } } @@ -55,15 +64,15 @@ impl Default for Ctor { } pub static mut default_ctor_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Ctor = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); + Ctor::constructor_1(&raw mut __v); __v } }); pub static mut arg_ctor_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Ctor = ::zero_init(); - Ctor::construct_1(&raw mut __v, 7); + let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); + Ctor::constructor_2(&raw mut __v, 7); __v } }); @@ -77,8 +86,8 @@ pub static mut str_9: std::cell::LazyCell> = }); pub static mut inline_member_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Ctor = ::zero_init(); - Ctor::construct_1(&raw mut __v, 5); + let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); + Ctor::constructor_2(&raw mut __v, 5); __v } }); @@ -92,7 +101,9 @@ pub static mut inline_member_11: std::cell::LazyCell = std::cell::LazyCell TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Holder {} pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { (unsafe { next_0() }) }); @@ -104,32 +115,40 @@ static mut once_13: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { (unsafe { next_0() }) }); static mut local_ctor_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Ctor = ::zero_init(); - Ctor::construct_1(&raw mut __v, 3); + let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); + Ctor::constructor_2(&raw mut __v, 3); __v } }); #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Singleton { pub hits: i32, } impl Singleton { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).hits).write(0); + } pub unsafe fn instance() -> *mut Singleton { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut s_15)); } } -impl DefaultConstructibleUnsafe for Singleton { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).hits).write(0); - } -} impl Default for Singleton { fn default() -> Self { unsafe { { - let mut __v: Singleton = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Singleton = ZeroInitializationUnsafe::zero_init(); + Singleton::constructor_1(&raw mut __v); __v } } @@ -137,8 +156,8 @@ impl Default for Singleton { } static mut s_15: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Singleton = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Singleton = ZeroInitializationUnsafe::zero_init(); + Singleton::constructor_1(&raw mut __v); __v } }); diff --git a/tests/unit/out/unsafe/global_pointers.rs b/tests/unit/out/unsafe/global_pointers.rs index a9c88f06ad..a6ab209fd5 100644 --- a/tests/unit/out/unsafe/global_pointers.rs +++ b/tests/unit/out/unsafe/global_pointers.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 7b58d8de0b..bea625254b 100644 --- a/tests/unit/out/unsafe/global_without_initializer.rs +++ b/tests/unit/out/unsafe/global_without_initializer.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S { pub a: i32, } diff --git a/tests/unit/out/unsafe/huffman.rs b/tests/unit/out/unsafe/huffman.rs index b08a31aac0..cb7efdb49b 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct MinHeapNode { pub data: libc::c_char, pub freq: i32, @@ -58,6 +60,9 @@ pub unsafe fn Swap_0(a: *mut MinHeapNode, b: *mut MinHeapNode) { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct MinHeap { pub size: i32, pub capacity: i32, @@ -255,9 +260,7 @@ impl MinHeap { } } } -} -impl DefaultConstructibleUnsafe for MinHeap { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).size).write(0_i32); (&raw mut (*this).capacity).write(0_i32); (&raw mut (*this).arr).write(None); 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 f3768f61ff..8ab42f850f 100644 --- a/tests/unit/out/unsafe/immutable-deref-on-func-call.rs +++ b/tests/unit/out/unsafe/immutable-deref-on-func-call.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 8528b4c6d6..f064c49e32 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -19,11 +19,14 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Holder { pub v: Vec, } -impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(this: *mut Self) { +impl Holder { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(Vec::new()); } } @@ -49,7 +52,7 @@ unsafe fn main_0() -> i32 { let mut p: *mut Vec = (&mut v as *mut Vec); let mut a: i32 = (&mut (*p))[(0_usize)]; (&mut (*p))[(1_usize)] = 30; - object_unsafe!(h, Holder); + object_unsafe!(h, Holder::constructor_1()); { let mut __tmp_2: i32 = 40; h.v.push_moved(&mut __tmp_2) diff --git a/tests/unit/out/unsafe/in_class_field_initializer.rs b/tests/unit/out/unsafe/in_class_field_initializer.rs index 8dbb959f6a..2f0295ed62 100644 --- a/tests/unit/out/unsafe/in_class_field_initializer.rs +++ b/tests/unit/out/unsafe/in_class_field_initializer.rs @@ -7,13 +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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Inner { pub x: i32, pub y: i32, } -impl DefaultConstructibleUnsafe for Inner { - unsafe fn default_constructor(this: *mut Self) { +impl Inner { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).x).write(3); (&raw mut (*this).y).write(4); } @@ -24,19 +34,29 @@ impl Default for Inner { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S { pub a: i32, pub b: libc::c_char, pub c: Inner, pub d: Inner, } -impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(this: *mut Self) { +impl S { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).a).write(1); (&raw mut (*this).b).write((2 as libc::c_char)); (&raw mut (*this).c).write(::default()); - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).d); + Inner::constructor_1(&raw mut (*this).d); } } impl Default for S { @@ -60,13 +80,16 @@ impl Default for S { ZeroInitializationUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy, move)] +#[constructor(constructor_1, i32, i32)] pub struct Boxed_int_ { pub v: i32, pub tag: i32, } impl Boxed_int_ { - pub unsafe fn construct(this: *mut Self, mut x: i32, mut t: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32, mut t: i32) { (&raw mut (*this).v).write(x); (&raw mut (*this).tag).write(t); } @@ -83,14 +106,14 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S); + object_unsafe!(s, S::constructor_1()); assert!(((s.a) == (1))); assert!(((s.b as i32) == (2))); assert!(((s.c.x) == (3))); assert!(((s.c.y) == (4))); assert!(((s.d.x) == (3))); assert!(((s.d.y) == (4))); - object_unsafe!(boxed, Boxed_int_(5, 9)); + object_unsafe!(boxed, Boxed_int_::constructor_1(5, 9)); assert!(((boxed.v) == (5))); assert!(((boxed.tag) == (9))); return 0; diff --git a/tests/unit/out/unsafe/init.rs b/tests/unit/out/unsafe/init.rs index 3d59a03d41..0f36941bdf 100644 --- a/tests/unit/out/unsafe/init.rs +++ b/tests/unit/out/unsafe/init.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 ac9d1c1658..1d8f5874e8 100644 --- a/tests/unit/out/unsafe/init_list.rs +++ b/tests/unit/out/unsafe/init_list.rs @@ -17,13 +17,25 @@ pub unsafe fn f_0(mut list: Vec) {} TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pair { pub a: i32, pub b: i32, } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Holder { pub p: Pair, } @@ -32,9 +44,7 @@ impl Holder { (*this).p = (*o); return &mut (*this); } -} -impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).p).write(Pair { a: 0, b: 0 }); } } @@ -51,12 +61,22 @@ pub unsafe fn sum_1(p: *const Pair) -> i32 { return (((*p).a) + ((*p).b)); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Seven { pub v: i32, } -impl DefaultConstructibleUnsafe for Seven { - unsafe fn default_constructor(this: *mut Self) { +impl Seven { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(7); } } @@ -80,7 +100,7 @@ unsafe fn main_0() -> i32 { let mut vec_: Vec = Vec::from([1, 2, 3]); (unsafe { f_0(Vec::from([1, 2, 3, 4])) }); let mut p: Pair = Pair { a: 1, b: 2 }; - object_unsafe!(h, Holder); + object_unsafe!(h, Holder::constructor_1()); (unsafe { Holder::operator_assign_1(&raw mut h, &mut p) }); assert!(((h.p.a) == (1)) && ((h.p.b) == (2))); assert!(((unsafe { sum_1(&p,) }) == (3))); diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index ff19c40209..19128f8439 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -19,13 +19,16 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Elem { pub id: i32, pub hist: [i32; 4], pub coeffs: Vec, } -impl DefaultConstructibleUnsafe for Elem { - unsafe fn default_constructor(this: *mut Self) { +impl Elem { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).id).write(0_i32); (&raw mut (*this).hist).write([0_i32; 4]); (&raw mut (*this).coeffs).write(Vec::new()); @@ -43,6 +46,9 @@ impl DefaultConstructibleUnsafe for Elem { SwappableUnsafe, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct State { pub count: i32, pub grid: [[i32; 3]; 2], @@ -50,8 +56,8 @@ pub struct State { pub elems: Vec, pub rows: Vec>, } -impl DefaultConstructibleUnsafe for State { - unsafe fn default_constructor(this: *mut Self) { +impl State { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).count).write(0_i32); (&raw mut (*this).grid).write([[0_i32; 3]; 2]); (&raw mut (*this).arr).write(std::array::from_fn::<_, 3, _>(|_| 0_i32)); @@ -138,24 +144,26 @@ 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(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Counted { pub v: i32, } -impl DefaultConstructibleUnsafe for Counted { - unsafe fn default_constructor(this: *mut Self) { +impl Counted { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(0); } -} -impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Counted); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)).prefix_inc(); } -} -impl MoveConstructibleUnsafe for Counted { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Counted); (&raw mut (*this).v).write((*o).v); (*o).v = -1_i32; @@ -253,7 +261,9 @@ unsafe fn main_0() -> i32 { assert!( ((elems[(1_usize)].hist[(2) as usize]) == (5)) && (((*first).hist[(2) as usize]) == (0)) ); - object_unsafe!(moved, State, RvalueRefUnsafe::bind(&mut t)); + object_unsafe!(moved, State, |moved| { + ::move_constructor(moved, RvalueRefUnsafe::bind(&mut t)) + }); assert!( ((moved.grid[(0) as usize][(0) as usize]) == (100)) && ((moved.grid[(1) as usize][(2) as usize]) == (5)) diff --git a/tests/unit/out/unsafe/kruskal.rs b/tests/unit/out/unsafe/kruskal.rs index 2f887245a5..7028ca1939 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Edge { pub u: i32, pub v: i32, @@ -182,6 +184,9 @@ pub unsafe fn quicksort_1(arr: *mut Option>, mut start: i32, mut end Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct DisjointSet { pub rank: Option>, pub parent: Option>, @@ -291,9 +296,7 @@ impl DisjointSet { + (1)); } } -} -impl DefaultConstructibleUnsafe for DisjointSet { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).rank).write(None); (&raw mut (*this).parent).write(None); (&raw mut (*this).n).write(0_i32); @@ -309,13 +312,16 @@ impl DefaultConstructibleUnsafe for DisjointSet { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Graph { pub edges: Option>, pub V: i32, pub E: i32, } -impl DefaultConstructibleUnsafe for Graph { - unsafe fn default_constructor(this: *mut Self) { +impl Graph { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).edges).write(None); (&raw mut (*this).V).write(0_i32); (&raw mut (*this).E).write(0_i32); diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index 509d44bfd8..cd0356b6f9 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -18,6 +18,8 @@ use std::rc::Rc; MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { pub f: FnPtr, } @@ -28,8 +30,15 @@ impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_34_13__ { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DefaultConstructibleUnsafe, CopyableUnsafe, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + CopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { pub f: FnPtr, } @@ -46,7 +55,9 @@ impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_45_13__ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { pub f: FnPtr i32>, pub calls: i32, @@ -80,7 +91,9 @@ impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { pub f: FnPtr i32>, pub calls: i32, @@ -92,20 +105,19 @@ impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe)] -#[cpp_from(FnPtr i32 > , construct, value)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { pub f: FnPtr i32>, pub moves: i32, } impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { - pub unsafe fn construct(this: *mut Self, mut f: FnPtr i32>) { + pub unsafe fn constructor_1(this: *mut Self, mut f: FnPtr i32>) { (&raw mut (*this).f).write(f.copy_from()); (&raw mut (*this).moves).write(0); } -} -impl MoveConstructibleUnsafe for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - unsafe fn move_constructor( + pub unsafe fn constructor_2( this: *mut Self, o: RvalueRefUnsafe, ) { @@ -229,7 +241,7 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { ww.call(2,) }) == (202))); object_unsafe!( m, - Moving__lambda_at_lambda_as_field_cpp_64_12__(FnPtr:: i32>::new( + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_1(FnPtr:: i32>::new( |mut x: i32| -> i32 { unsafe { return ((x) * (2)); @@ -239,8 +251,7 @@ unsafe fn main_0() -> i32 { ); object_unsafe!( m2, - Moving__lambda_at_lambda_as_field_cpp_64_12__, - RvalueRefUnsafe::bind(&mut m) + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_2(RvalueRefUnsafe::bind(&mut m)) ); assert!(((unsafe { m2.f.call(3,) }) == (6))); assert!(((m2.moves) == (1))); diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index 122501d962..a3d0d20e44 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -7,26 +7,26 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Counted { pub copies: i32, pub moves: i32, } -impl DefaultConstructibleUnsafe for Counted { - unsafe fn default_constructor(this: *mut Self) { +impl Counted { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Counted); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } -} -impl MoveConstructibleUnsafe for Counted { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Counted); (&raw mut (*this).copies).write((*o).copies); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -36,8 +36,8 @@ impl Default for Counted { fn default() -> Self { unsafe { { - let mut __v: Counted = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v); __v } } @@ -45,18 +45,18 @@ impl Default for Counted { } pub static mut drops_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Dropped {} -impl DefaultConstructibleUnsafe for Dropped { - unsafe fn default_constructor(this: *mut Self) {} -} -impl CopyConstructibleUnsafe for Dropped { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { +impl Dropped { + pub unsafe fn constructor_1(this: *mut Self) {} + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const Dropped); } -} -impl MoveConstructibleUnsafe for Dropped { - unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, _a0: RvalueRefUnsafe) { let _a0 = (_a0.as_ptr() as *mut Dropped); } } @@ -72,12 +72,12 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(c, Counted); + object_unsafe!(c, Counted::constructor_1()); let mut f: FnPtr i32> = lambda_unsafe!( { let c: Counted = { - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&c)); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&c)); __v }; }, @@ -92,25 +92,19 @@ unsafe fn main_0() -> i32 { let mut h: FnPtr i32> = f.move_from(); assert!(((unsafe { h.call() }) == (11))); let mut returned: i32 = { - let mut __tmp_0: Counted = ::zero_init(); + let mut __tmp_0: Counted = ZeroInitializationUnsafe::zero_init(); (*{ (unsafe { lambda_unsafe!( { let c: Counted = { - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor( - &raw mut __v, - LvalueRefUnsafe::bind(&c), - ); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&c)); __v }; }, |__return: *mut Counted| { - CopyConstructibleUnsafe::copy_constructor( - __return, - LvalueRefUnsafe::bind(&c), - ); + Counted::constructor_2(__return, LvalueRefUnsafe::bind(&c)); return; } ) @@ -122,18 +116,15 @@ unsafe fn main_0() -> i32 { }; assert!(((returned) == (2))); let mut arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|_| { - let mut __v: Counted = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v); __v }); let mut a: FnPtr i32> = lambda_unsafe!( { let arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|__i: usize| { - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor( - &raw mut __v, - LvalueRefUnsafe::bind(&arr[(__i)]), - ); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&arr[(__i)])); __v }); }, @@ -150,8 +141,8 @@ unsafe fn main_0() -> i32 { let mut m: FnPtr = lambda_unsafe!( { let d: Dropped = { - let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); + Dropped::constructor_1(&raw mut __v); __v }; }, @@ -170,8 +161,8 @@ unsafe fn main_0() -> i32 { let mut k: FnPtr = lambda_unsafe!( { let d: Dropped = { - let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); + Dropped::constructor_1(&raw mut __v); __v }; }, @@ -190,8 +181,8 @@ unsafe fn main_0() -> i32 { let mut inner: FnPtr = lambda_unsafe!( { let d: Dropped = { - let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); + Dropped::constructor_1(&raw mut __v); __v }; }, diff --git a/tests/unit/out/unsafe/lambda_capture_ref.rs b/tests/unit/out/unsafe/lambda_capture_ref.rs index 6590dbd343..70a8492246 100644 --- a/tests/unit/out/unsafe/lambda_capture_ref.rs +++ b/tests/unit/out/unsafe/lambda_capture_ref.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 90c2955b37..d2de505594 100644 --- a/tests/unit/out/unsafe/lambda_capture_star_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_star_this.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 f055abe092..25e3fc0593 100644 --- a/tests/unit/out/unsafe/lambda_capture_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_this.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 fc656980c3..3f53a18ed6 100644 --- a/tests/unit/out/unsafe/lambda_capture_value.rs +++ b/tests/unit/out/unsafe/lambda_capture_value.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 08727a0734..359658656c 100644 --- a/tests/unit/out/unsafe/lambda_decltype_type.rs +++ b/tests/unit/out/unsafe/lambda_decltype_type.rs @@ -7,7 +7,11 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { pub items: [i32; 4], pub size: i32, @@ -28,9 +32,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { (*this).items[(i) as usize] = v; (*this).size.postfix_inc(); } -} -impl DefaultConstructibleUnsafe for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).items).write([0_i32; 4]); (&raw mut (*this).size).write(0); (&raw mut (*this).cmp).write(FnPtr:: bool>::new( @@ -58,7 +60,11 @@ impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { pub items: [i32; 4], pub size: i32, @@ -79,9 +85,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { (*this).items[(i) as usize] = v; (*this).size.postfix_inc(); } -} -impl DefaultConstructibleUnsafe for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).items).write([0_i32; 4]); (&raw mut (*this).size).write(0); (&raw mut (*this).cmp).write(FnPtr:: bool>::new( @@ -121,14 +125,20 @@ unsafe fn main_0() -> i32 { return ((a) > (b)); } }); - object_unsafe!(desc, Sorted__lambda_at_lambda_decltype_type_cpp_22_18__); + object_unsafe!( + desc, + Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::constructor_1() + ); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 2) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 7) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 4) }); assert!(((desc.items[(0) as usize]) == (7))); assert!(((desc.items[(1) as usize]) == (4))); assert!(((desc.items[(2) as usize]) == (2))); - object_unsafe!(asc, Sorted__lambda_at_lambda_decltype_type_cpp_19_23__); + object_unsafe!( + asc, + Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::constructor_1() + ); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 2) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 7) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 4) }); diff --git a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs b/tests/unit/out/unsafe/lambda_generic_explicit_args.rs index 5de0535d40..d7dd2a6d11 100644 --- a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs +++ b/tests/unit/out/unsafe/lambda_generic_explicit_args.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 cd9d7a8e24..b938db43ce 100644 --- a/tests/unit/out/unsafe/lambda_immediate_init.rs +++ b/tests/unit/out/unsafe/lambda_immediate_init.rs @@ -10,13 +10,23 @@ pub unsafe fn pick_0(mut x: i32) -> i32 { return x; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S { pub j: i32, pub k: i32, } -impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(this: *mut Self) { +impl S { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).j).write(10); (&raw mut (*this).k).write( ((unsafe { @@ -89,7 +99,7 @@ unsafe fn main_0() -> i32 { }) == (237)) ); assert!(((unsafe { pick_0(1,) }) == (1))); - object_unsafe!(s, S); + object_unsafe!(s, S::constructor_1()); assert!(((s.k) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut g_1)) == (10))); let mut a: i32 = 2; diff --git a/tests/unit/out/unsafe/lambda_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index 465e9ffbb8..864bf6bade 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -7,24 +7,28 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultConstructibleUnsafe)] -#[cpp_from(i32, construct, value)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultConstructibleUnsafe, ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Owner { pub p: *mut i32, } impl Owner { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).p).write((Box::leak(Box::new(v)) as *mut i32)); } + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Owner); + (&raw mut (*this).p).write((*o).p); + (*o).p = std::ptr::null_mut(); + } pub unsafe fn take(this: *mut Self) -> FnPtr i32> { return lambda_unsafe!( { let self_: Owner = { - let mut __v: Owner = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( - &raw mut __v, - RvalueRefUnsafe::bind(&mut (*this)), - ); + let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); + Owner::constructor_3(&raw mut __v, RvalueRefUnsafe::bind(&mut (*this))); __v }; }, @@ -34,13 +38,6 @@ impl Owner { ); } } -impl MoveConstructibleUnsafe for Owner { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { - let o = (o.as_ptr() as *mut Owner); - (&raw mut (*this).p).write((*o).p); - (*o).p = std::ptr::null_mut(); - } -} impl DestructibleUnsafe for Owner { unsafe fn destroy(this: *mut Self) { { @@ -58,15 +55,12 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(o, Owner(5)); + object_unsafe!(o, Owner::constructor_1(5)); let mut f: FnPtr i32> = lambda_unsafe!( { let h: Owner = { - let mut __v: Owner = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( - &raw mut __v, - RvalueRefUnsafe::bind(&mut o), - ); + let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); + Owner::constructor_3(&raw mut __v, RvalueRefUnsafe::bind(&mut o)); __v }; }, @@ -88,8 +82,8 @@ unsafe fn main_0() -> i32 { let mut consume: FnPtr = lambda_unsafe!( { let h: Owner = { - let mut __v: Owner = ::zero_init(); - Owner::construct(&raw mut __v, 7); + let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); + Owner::constructor_1(&raw mut __v, 7); __v }; let total: *mut i32 = &mut total; @@ -105,7 +99,7 @@ unsafe fn main_0() -> i32 { (unsafe { consume.call() }); (unsafe { consume.call() }); assert!(((total) == (7))); - object_unsafe!(o2, Owner(9)); + object_unsafe!(o2, Owner::constructor_1(9)); let mut t: FnPtr i32> = (unsafe { Owner::take(&raw mut o2) }); let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { DestructibleUnsafe::destroy(__p) diff --git a/tests/unit/out/unsafe/lambda_nested.rs b/tests/unit/out/unsafe/lambda_nested.rs index 57e99f3436..9a276cf17e 100644 --- a/tests/unit/out/unsafe/lambda_nested.rs +++ b/tests/unit/out/unsafe/lambda_nested.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 5e0406de52..08d48ccff2 100644 --- a/tests/unit/out/unsafe/lambda_static_local.rs +++ b/tests/unit/out/unsafe/lambda_static_local.rs @@ -77,7 +77,9 @@ static mut calls_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsaf TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 b5d7cfed8e..eee5baa317 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -18,12 +18,15 @@ use std::rc::Rc; SwappableUnsafe, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct UserDefined { pub a: [i32; 1], pub v: Vec, } -impl DefaultConstructibleUnsafe for UserDefined { - unsafe fn default_constructor(this: *mut Self) { +impl UserDefined { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).a).write(std::array::from_fn::<_, 1, _>(|_| 0_i32)); (&raw mut (*this).v).write(Vec::new()); } @@ -47,7 +50,9 @@ impl Default for UserDefined { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct FieldIsLibcType { pub addr: libc::sockaddr, } @@ -87,7 +92,7 @@ unsafe fn main_0() -> i32 { let mut st: ::libc::stat = std::mem::zeroed(); st.st_size = (1024 as ::libc::off_t); assert!(((st.st_size) == (1024 as ::libc::off_t))); - object_unsafe!(ud, UserDefined); + object_unsafe!(ud, UserDefined::constructor_1()); ud.a[(0_usize)] = 3; assert!(((ud.a[(0_usize)]) == (3))); assert!(((ud.v.len()) == (0_usize))); diff --git a/tests/unit/out/unsafe/linked_list.rs b/tests/unit/out/unsafe/linked_list.rs index 3101cc9ed8..b5e917018d 100644 --- a/tests/unit/out/unsafe/linked_list.rs +++ b/tests/unit/out/unsafe/linked_list.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Node { pub val: i32, pub next: *mut Node, diff --git a/tests/unit/out/unsafe/local_record_template.rs b/tests/unit/out/unsafe/local_record_template.rs index 86593fe51e..3c54b068d8 100644 --- a/tests/unit/out/unsafe/local_record_template.rs +++ b/tests/unit/out/unsafe/local_record_template.rs @@ -39,7 +39,9 @@ pub unsafe fn wrap_10(mut v: i64) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Local_5 { pub x: i32, } @@ -53,7 +55,9 @@ pub struct Local_5 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Local_7 { pub x: i64, } @@ -71,7 +75,9 @@ pub unsafe fn other_11() -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Local_1 { pub x: i64, pub y: i64, @@ -101,7 +107,9 @@ unsafe fn main_0() -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Local_3 { pub x: i32, } diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index bafffe08be..e7a22f483a 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -16,29 +16,38 @@ pub unsafe fn inc_2(x: *mut i32) { (*x).postfix_inc(); } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32, i32)] pub struct Point { pub x: i32, pub y: i32, } impl Point { - pub unsafe fn construct_1(this: *mut Self, mut x: i32, mut y: i32) { - (&raw mut (*this).x).write(x); - (&raw mut (*this).y).write(y); - } -} -impl DefaultConstructibleUnsafe for Point { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).x).write(0); (&raw mut (*this).y).write(0); } + pub unsafe fn constructor_2(this: *mut Self, mut x: i32, mut y: i32) { + (&raw mut (*this).x).write(x); + (&raw mut (*this).y).write(y); + } } impl Default for Point { fn default() -> Self { unsafe { { - let mut __v: Point = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_1(&raw mut __v); __v } } @@ -417,7 +426,20 @@ unsafe fn main_0() -> i32 { assert!(!(not_inserted.1)); assert!((((*not_inserted.0.iter_deref()).1) == (2))); m3.emplace(match ((&mut (4, 5) as *mut (i32, i32)),) { - (__tmp_27,) => ((*&mut (*__tmp_27).0), (*&mut (*__tmp_27).1)), + (__tmp_27,) => { + object_unsafe!(__first, i32, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_27).0),) + )); + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_27).1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + } }); assert!(((m3.len()) == (2_usize))); { @@ -463,8 +485,8 @@ unsafe fn main_0() -> i32 { let mut points: UnsafeMap = UnsafeMap::new(); let mut point_new: (UnsafeBidirectionalIterator<(i32, Point)>, bool) = points.try_emplace(key1, || { - let mut __v: Point = ::zero_init(); - Point::construct_1(&raw mut __v, 3, 4); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_2(&raw mut __v, 3, 4); __v }); assert!(((point_new.1) as bool)); @@ -497,8 +519,8 @@ unsafe fn main_0() -> i32 { ) }; points.emplace((key8, { - let mut __v: Point = ::zero_init(); - Point::construct_1(&raw mut __v, 5, 6); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_2(&raw mut __v, 5, 6); __v })); { diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 6079a7fda5..716f383024 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -11,26 +11,25 @@ pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u pub static mut made_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Key { pub k: i32, } impl Key { - pub unsafe fn construct(this: *mut Self, mut k: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut k: i32) { (&raw mut (*this).k).write(k); } -} -impl CopyConstructibleUnsafe for Key { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Key); (&raw mut (*this).k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } -} -impl MoveConstructibleUnsafe for Key { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Key); (&raw mut (*this).k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); @@ -43,7 +42,7 @@ impl LessThanComparableUnsafe for Key { } pub unsafe fn make_key_3(__return: *mut Key, mut k: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)).prefix_inc(); - Key::construct(__return, k); + Key::constructor_1(__return, k); return; } pub fn main() { @@ -55,9 +54,9 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut ok: bool = true; let mut m: UnsafeMap = UnsafeMap::new(); - object_unsafe!(a, Key(1)); - object_unsafe!(b, Key(2)); - object_unsafe!(c, Key(3)); + object_unsafe!(a, Key::constructor_1(1)); + object_unsafe!(b, Key::constructor_1(2)); + object_unsafe!(c, Key::constructor_1(3)); (*m.subscript(&a, || 0_i32)) = 10; ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1)) as i32)) @@ -76,7 +75,7 @@ unsafe fn main_0() -> i32 { & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) != 0; { - let mut __tmp_1: Key = ::zero_init(); + let mut __tmp_1: Key = ZeroInitializationUnsafe::zero_init(); (*match (({ (unsafe { make_key_3(&raw mut __tmp_1, 4) }); &mut __tmp_1 @@ -86,7 +85,7 @@ unsafe fn main_0() -> i32 { }) = 40 }; { - let mut __tmp_3: Key = ::zero_init(); + let mut __tmp_3: Key = ZeroInitializationUnsafe::zero_init(); (*match (({ (unsafe { make_key_3(&raw mut __tmp_3, 4) }); &mut __tmp_3 @@ -116,9 +115,9 @@ unsafe fn main_0() -> i32 { != 0; let mut first: *const Key = (&(*m.begin().iter_deref()).0 as *const Key); { - let mut __tmp_5: Key = ::zero_init(); + let mut __tmp_5: Key = ZeroInitializationUnsafe::zero_init(); (*match (({ - Key::construct(&raw mut __tmp_5, 0); + Key::constructor_1(&raw mut __tmp_5, 0); &mut __tmp_5 } as *mut Key),) { diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index b311990fe3..fe4f9c4623 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -18,7 +18,9 @@ pub static mut default_constructions_0: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Key { pub order: i32, pub identity: i32, @@ -29,12 +31,22 @@ impl LessThanComparableUnsafe for Key { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Mapped { pub value: i32, } -impl DefaultConstructibleUnsafe for Mapped { - unsafe fn default_constructor(this: *mut Self) { +impl Mapped { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)).prefix_inc(); } @@ -43,8 +55,8 @@ impl Default for Mapped { fn default() -> Self { unsafe { { - let mut __v: Mapped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Mapped = ZeroInitializationUnsafe::zero_init(); + Mapped::constructor_1(&raw mut __v); __v } } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 9e806e81cf..8e174ec643 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -11,31 +11,29 @@ 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(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe)] -#[cpp_from(i32, construct_1, value)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRefUnsafe>)] +#[constructor(constructor_4, RvalueRefUnsafe)] pub struct Item { pub value: i32, } impl Item { - pub unsafe fn construct_1(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).value).write(0); + } + pub unsafe fn constructor_2(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); } -} -impl DefaultConstructibleUnsafe for Item { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).value).write(0); - } -} -impl CopyConstructibleUnsafe for Item { - unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + pub unsafe fn constructor_3(this: *mut Self, other: LvalueRefUnsafe>) { let other = (other.as_ptr() as *const Item); (&raw mut (*this).value).write((*other).value); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)).prefix_inc(); } -} -impl MoveConstructibleUnsafe for Item { - unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + pub unsafe fn constructor_4(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut Item); (&raw mut (*this).value).write((*other).value); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); @@ -46,8 +44,8 @@ impl Default for Item { fn default() -> Self { unsafe { { - let mut __v: Item = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_1(&raw mut __v); __v } } @@ -58,12 +56,27 @@ pub unsafe fn argument_4(item: *mut Item) -> *mut Item { return item; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe, i32 )] pub struct RefItem { pub value: i32, } impl RefItem { - pub unsafe fn construct_1(this: *mut Self, counter: *mut i32, mut amount: i32) { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).value).write(0); + } + pub unsafe fn constructor_2(this: *mut Self, counter: LvalueRefUnsafe, mut amount: i32) { + let counter = (counter.as_ptr() as *mut i32); (&raw mut (*this).value).write({ (*counter) += amount; (*counter) @@ -71,17 +84,12 @@ impl RefItem { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for RefItem { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).value).write(0); - } -} impl Default for RefItem { fn default() -> Self { unsafe { { - let mut __v: RefItem = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_1(&raw mut __v); __v } } @@ -256,11 +264,11 @@ unsafe fn main_0() -> i32 { let mut items: UnsafeMap = UnsafeMap::new(); let mut key: i32 = 0; items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, 10); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, 10); __v }); - object_unsafe!(source, Item::construct_1(20)); + object_unsafe!(source, Item::constructor_2(20)); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = { (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) = { (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = 0; @@ -268,16 +276,14 @@ unsafe fn main_0() -> i32 { }; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) }; - let mut hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { - argument_4(&mut source) - }) as *mut Item),) - { - (__tmp_6,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(__tmp_6)); - __v - }), - }; + let mut hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = + match (((unsafe { argument_4(&mut source) }) as *mut Item),) { + (__tmp_6,) => items.try_emplace(key, || { + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_3(&raw mut __v, LvalueRefUnsafe::bind(__tmp_6)); + __v + }), + }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) @@ -286,17 +292,14 @@ unsafe fn main_0() -> i32 { as i32)) != 0; ok = ((ok as i32) & (((!(hit.1)) && (((*hit.0.iter_deref()).1.value) == (10))) as i32)) != 0; - let mut move_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { - argument_4(&mut source) - }) - as *mut Item),) - { - (__tmp_7,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(__tmp_7)); - __v - }), - }; + let mut move_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = + match (((unsafe { argument_4(&mut source) }) as *mut Item),) { + (__tmp_7,) => items.try_emplace(key, || { + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&raw mut __v, RvalueRefUnsafe::bind(__tmp_7)); + __v + }), + }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) @@ -306,16 +309,14 @@ unsafe fn main_0() -> i32 { != 0; ok = ((ok as i32) & (((!(move_hit.1)) && ((source.value) == (20))) as i32)) != 0; key.prefix_inc(); - let mut copied: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { - argument_4(&mut source) - }) as *mut Item),) - { - (__tmp_8,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(__tmp_8)); - __v - }), - }; + let mut copied: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = + match (((unsafe { argument_4(&mut source) }) as *mut Item),) { + (__tmp_8,) => items.try_emplace(key, || { + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_3(&raw mut __v, LvalueRefUnsafe::bind(__tmp_8)); + __v + }), + }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (3)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) @@ -325,16 +326,14 @@ unsafe fn main_0() -> i32 { != 0; ok = ((ok as i32) & (((copied.1) && (((*copied.0.iter_deref()).1.value) == (20))) as i32)) != 0; key.prefix_inc(); - let mut moved: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { - argument_4(&mut source) - }) as *mut Item),) - { - (__tmp_9,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(__tmp_9)); - __v - }), - }; + let mut moved: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = + match (((unsafe { argument_4(&mut source) }) as *mut Item),) { + (__tmp_9,) => items.try_emplace(key, || { + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&raw mut __v, RvalueRefUnsafe::bind(__tmp_9)); + __v + }), + }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) @@ -350,16 +349,16 @@ unsafe fn main_0() -> i32 { key = 0; let mut counter: i32 = 0; refs.try_emplace(key, || { - let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&raw mut __v, &mut counter, 5); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&mut counter), 5); __v }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = 0; let mut ref_hit: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_10,) => refs.try_emplace(key, || { - let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&raw mut __v, __tmp_10, 2); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_10), 2); __v }), }; @@ -373,8 +372,8 @@ unsafe fn main_0() -> i32 { let mut ref_new: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_11,) => refs.try_emplace(key, || { - let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&raw mut __v, __tmp_11, 2); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_11), 2); __v }), }; @@ -397,18 +396,15 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) }; let mut temporary_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_13: Item = ::zero_init(); + let mut __tmp_13: Item = ZeroInitializationUnsafe::zero_init(); match (({ - Item::construct_1(&raw mut __tmp_13, 30); + Item::constructor_2(&raw mut __tmp_13, 30); &mut __tmp_13 } as *mut Item),) { (__tmp_12,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( - &raw mut __v, - RvalueRefUnsafe::bind(__tmp_12), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&raw mut __v, RvalueRefUnsafe::bind(__tmp_12)); __v }), } @@ -423,18 +419,15 @@ unsafe fn main_0() -> i32 { key.prefix_inc(); key.prefix_inc(); let mut temporary_new: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_15: Item = ::zero_init(); + let mut __tmp_15: Item = ZeroInitializationUnsafe::zero_init(); match (({ - Item::construct_1(&raw mut __tmp_15, 40); + Item::constructor_2(&raw mut __tmp_15, 40); &mut __tmp_15 } as *mut Item),) { (__tmp_14,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( - &raw mut __v, - RvalueRefUnsafe::bind(__tmp_14), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&raw mut __v, RvalueRefUnsafe::bind(__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 4fb0165186..96e0eacc66 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -9,12 +9,27 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe, i32 )] pub struct Item { pub value: i32, } impl Item { - pub unsafe fn construct_1(this: *mut Self, counter: *mut i32, mut amount: i32) { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).value).write(0); + } + pub unsafe fn constructor_2(this: *mut Self, counter: LvalueRefUnsafe, mut amount: i32) { + let counter = (counter.as_ptr() as *mut i32); (&raw mut (*this).value).write({ (*counter) += amount; (*counter) @@ -22,17 +37,12 @@ impl Item { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for Item { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).value).write(0); - } -} impl Default for Item { fn default() -> Self { unsafe { { - let mut __v: Item = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_1(&raw mut __v); __v } } @@ -49,13 +59,23 @@ 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, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Temporary { pub n: i32, pub data: [i32; 2], } -impl DefaultConstructibleUnsafe for Temporary { - unsafe fn default_constructor(this: *mut Self) { +impl Temporary { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).n).write(5); (&raw mut (*this).data).write([6, 7]); (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)).prefix_inc(); @@ -65,8 +85,8 @@ impl Default for Temporary { fn default() -> Self { unsafe { { - let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v } } @@ -74,27 +94,36 @@ impl Default for Temporary { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, Default, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Nested { pub inner: Temporary, } -impl DefaultConstructibleUnsafe for Nested { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).inner); +impl Nested { + pub unsafe fn constructor_1(this: *mut Self) { + Temporary::constructor_1(&raw mut (*this).inner); } } pub unsafe fn make_temporary_5() -> Temporary { return { - let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v }; } pub unsafe fn make_nested_6() -> Nested { return { - let mut __v: Nested = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Nested = ZeroInitializationUnsafe::zero_init(); + Nested::constructor_1(&raw mut __v); __v }; } @@ -103,10 +132,20 @@ pub unsafe fn make_nested_6() -> Nested { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Owner { pub ptr: Option>, } impl Owner { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).ptr).write(Some(Box::new({ + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); + __v + }))); + } pub unsafe fn value(this: *mut Self) -> *const i32 { return &(*(*this).ptr.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const Temporary as *mut Temporary @@ -114,33 +153,25 @@ impl Owner { .n; } } -impl DefaultConstructibleUnsafe for Owner { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).ptr).write(Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); - __v - }))); - } -} impl Default for Owner { fn default() -> Self { unsafe { { - let mut __v: Owner = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); + Owner::constructor_1(&raw mut __v); __v } } } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[constructor(constructor_1)] pub struct Noncopy { pub n: i32, } -impl DefaultConstructibleUnsafe for Noncopy { - unsafe fn default_constructor(this: *mut Self) { +impl Noncopy { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).n).write(5); } } @@ -151,31 +182,38 @@ impl Default for Noncopy { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, TriviallyCopyableUnsafe, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, )] -#[cpp_from(i32, construct_1, ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Held { pub ptr: *const i32, } impl Held { - pub unsafe fn construct_1(this: *mut Self, n: *const i32) { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).ptr).write(std::ptr::null()); + } + pub unsafe fn constructor_2(this: *mut Self, n: LvalueRefUnsafe>) { + let n = (n.as_ptr() as *const i32); (&raw mut (*this).ptr).write((n)); } - pub unsafe fn construct_2(this: *mut Self, n: *const [i32; 2], mut _a1: i32) { + pub unsafe fn constructor_3(this: *mut Self, n: *const [i32; 2], mut _a1: i32) { (&raw mut (*this).ptr).write((*n).as_ptr()); } } -impl DefaultConstructibleUnsafe for Held { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).ptr).write(std::ptr::null()); - } -} impl Default for Held { fn default() -> Self { unsafe { { - let mut __v: Held = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Held = ZeroInitializationUnsafe::zero_init(); + Held::constructor_1(&raw mut __v); __v } } @@ -245,8 +283,8 @@ pub static mut global_owned_16: std::cell::LazyCell<( let mut __tmp_6: Option>; match ((&mut (*(*{ __tmp_6 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_6 @@ -299,8 +337,8 @@ unsafe fn main_0() -> i32 { let mut key: i32 = 0; let mut counter: i32 = 0; m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, &mut counter, 3); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&mut counter), 3); __v }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) = 0; @@ -313,8 +351,8 @@ unsafe fn main_0() -> i32 { } as *mut i32), ) { (__tmp_7, __tmp_8) => (*__tmp_7).try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_8, 2); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_8), 2); __v }), }; @@ -331,8 +369,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_10,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_10, 2); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_10), 2); __v }), }; @@ -349,8 +387,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_12,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_12, 2); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_12), 2); __v }), }; @@ -368,8 +406,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_15,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_15, 2); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_15), 2); __v }), }; @@ -391,8 +429,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_18,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_18, 3); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_18), 3); __v }), }; @@ -412,8 +450,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_20,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_20, 3); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_20), 3); __v }), }; @@ -429,8 +467,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_23,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_23, 3); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_23), 3); __v }), }; @@ -455,8 +493,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_26,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_26, 3); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_26), 3); __v }), }; @@ -480,8 +518,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_29,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_29, 3); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_29), 3); __v }), }; @@ -495,8 +533,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_32,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_32, 3); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_32), 3); __v }), }; @@ -726,8 +764,12 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_60,) => selected.try_emplace(keys[(0) as usize], || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_60, 2); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2( + &raw mut __v, + LvalueRefUnsafe::bind(__tmp_60), + 2, + ); __v }), }; @@ -749,8 +791,12 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_63,) => selected.try_emplace(keys[(1) as usize], || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_63, 2); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2( + &raw mut __v, + LvalueRefUnsafe::bind(__tmp_63), + 2, + ); __v }), }; @@ -772,8 +818,12 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_68,) => selected.try_emplace(keys[(2) as usize], || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, __tmp_68, 2); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2( + &raw mut __v, + LvalueRefUnsafe::bind(__tmp_68), + 2, + ); __v }), }; @@ -912,8 +962,11 @@ unsafe fn main_0() -> i32 { let mut ordinary: i32 = 9; if (hit != 0) { references.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - Held::construct_1(&raw mut __v, &ordinary); + let mut __v: Held = ZeroInitializationUnsafe::zero_init(); + Held::constructor_2( + &raw mut __v, + LvalueRefUnsafe::bind(&ordinary), + ); __v }); } @@ -943,8 +996,12 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_79,) => references.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - Held::construct_1(&raw mut __v, __tmp_79); + let mut __v: Held = + ZeroInitializationUnsafe::zero_init(); + Held::constructor_2( + &raw mut __v, + LvalueRefUnsafe::bind(__tmp_79), + ); __v }), }; @@ -970,8 +1027,8 @@ unsafe fn main_0() -> i32 { let ordinary_array: [i32; 2] = [9, 10]; if (hit != 0) { arrays.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - Held::construct_2(&raw mut __v, &ordinary_array, 0); + let mut __v: Held = ZeroInitializationUnsafe::zero_init(); + Held::constructor_3(&raw mut __v, &ordinary_array, 0); __v }); } @@ -999,8 +1056,9 @@ unsafe fn main_0() -> i32 { } as *mut [i32; 2]),) { (__tmp_82,) => arrays.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - Held::construct_2(&raw mut __v, __tmp_82, 0); + let mut __v: Held = + ZeroInitializationUnsafe::zero_init(); + Held::constructor_3(&raw mut __v, __tmp_82, 0); __v }), }; @@ -1044,8 +1102,8 @@ unsafe fn main_0() -> i32 { let mut __tmp_86: Option>; match ((&mut (*(*{ __tmp_86 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_86 @@ -1063,8 +1121,8 @@ unsafe fn main_0() -> i32 { let mut __tmp_88: Option>; match ((&mut (*&mut (*(*{ __tmp_88 = Some(Box::new({ - let mut __v: Nested = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Nested = ZeroInitializationUnsafe::zero_init(); + Nested::constructor_1(&raw mut __v); __v })); &mut __tmp_88 @@ -1083,8 +1141,8 @@ unsafe fn main_0() -> i32 { let mut __tmp_90: Option>; match ((&mut (*(*{ __tmp_90 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_90 @@ -1102,8 +1160,8 @@ unsafe fn main_0() -> i32 { let mut __tmp_92: Option>; match ((&mut (*(*{ __tmp_92 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_92 @@ -1119,8 +1177,8 @@ unsafe fn main_0() -> i32 { let mut __tmp_94: Option>; match ((&mut (*((*{ __tmp_94 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_94 @@ -1138,8 +1196,8 @@ unsafe fn main_0() -> i32 { let mut __tmp_96: Option>>>; match ((&mut (*((*(*{ __tmp_96 = Some(Box::new(Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })))); &mut __tmp_96 @@ -1191,8 +1249,11 @@ unsafe fn main_0() -> i32 { let mut ordinary: i32 = 9; if (hit != 0) { references.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - Held::construct_1(&raw mut __v, &ordinary); + let mut __v: Held = ZeroInitializationUnsafe::zero_init(); + Held::constructor_2( + &raw mut __v, + LvalueRefUnsafe::bind(&ordinary), + ); __v }); } @@ -1207,10 +1268,9 @@ unsafe fn main_0() -> i32 { match ((if (choose != 0) { (&mut (*(*{ __tmp_98 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor( - &raw mut __v, - ); + let mut __v: Temporary = + ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_98 @@ -1223,10 +1283,9 @@ unsafe fn main_0() -> i32 { } else { (&mut (*(*{ __tmp_99 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor( - &raw mut __v, - ); + let mut __v: Temporary = + ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_99 @@ -1241,8 +1300,12 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_97,) => references.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - Held::construct_1(&raw mut __v, __tmp_97); + let mut __v: Held = + ZeroInitializationUnsafe::zero_init(); + Held::constructor_2( + &raw mut __v, + LvalueRefUnsafe::bind(__tmp_97), + ); __v }), }; @@ -1266,22 +1329,24 @@ unsafe fn main_0() -> i32 { ); let mut owners: UnsafeMap = UnsafeMap::new(); { - let mut __tmp_101: Owner = ::zero_init(); + let mut __tmp_101: Owner = ZeroInitializationUnsafe::zero_init(); { match (((unsafe { Owner::value( &mut (*{ - DefaultConstructibleUnsafe::default_constructor( - &raw mut __tmp_101, - ); + Owner::constructor_1(&raw mut __tmp_101); &mut __tmp_101 }), ) }) as *const i32),) { (__tmp_100,) => owners.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - Held::construct_1(&raw mut __v, __tmp_100); + let mut __v: Held = + ZeroInitializationUnsafe::zero_init(); + Held::constructor_2( + &raw mut __v, + LvalueRefUnsafe::bind(__tmp_100), + ); __v }), }; @@ -1305,8 +1370,8 @@ unsafe fn main_0() -> i32 { let mut __tmp_103: Option>; match (({ __tmp_103 = Some(Box::new({ - let mut __v: Noncopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Noncopy = ZeroInitializationUnsafe::zero_init(); + Noncopy::constructor_1(&raw mut __v); __v })); &mut __tmp_103 @@ -1322,8 +1387,8 @@ unsafe fn main_0() -> i32 { let mut __tmp_105: Option>; match (({ __tmp_105 = Some(Box::new({ - let mut __v: Noncopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Noncopy = ZeroInitializationUnsafe::zero_init(); + Noncopy::constructor_1(&raw mut __v); __v })); &mut __tmp_105 diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 927725fa71..52daa3f512 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -20,7 +20,6 @@ pub unsafe fn pick_3(mut i: i32) -> *mut i32 { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -29,17 +28,18 @@ pub unsafe fn pick_3(mut i: i32) -> *mut i32 { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Bag { pub n: i32, } impl Bag { - pub unsafe fn construct(this: *mut Self, mut n: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut n: i32) { (&raw mut (*this).n).write(n); } -} -impl CopyConstructibleUnsafe for Bag { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Bag); (&raw mut (*this).n).write((*o).n); (*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)).prefix_inc(); @@ -51,7 +51,7 @@ impl LessThanComparableUnsafe for Bag { } } pub unsafe fn make_4(__return: *mut Bag, mut n: i32) { - Bag::construct(__return, n); + Bag::constructor_1(__return, n); return; } pub fn main() { @@ -165,8 +165,8 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) = 0; assert!( ({ - let mut __tmp_5: Bag = ::zero_init(); - let mut __tmp_7: Bag = ::zero_init(); + let mut __tmp_5: Bag = ZeroInitializationUnsafe::zero_init(); + let mut __tmp_7: Bag = ZeroInitializationUnsafe::zero_init(); (((*match ( ({ (unsafe { make_4(&raw mut __tmp_5, 1) }); @@ -189,8 +189,8 @@ unsafe fn main_0() -> i32 { }) .n) == (2)) }) && ({ - let mut __tmp_9: Bag = ::zero_init(); - let mut __tmp_11: Bag = ::zero_init(); + let mut __tmp_9: Bag = ZeroInitializationUnsafe::zero_init(); + let mut __tmp_11: Bag = ZeroInitializationUnsafe::zero_init(); (((*match ( ({ (unsafe { make_4(&raw mut __tmp_9, 1) }); diff --git a/tests/unit/out/unsafe/memcpy_struct_struct.rs b/tests/unit/out/unsafe/memcpy_struct_struct.rs index 0ea1856566..e2a8ed6756 100644 --- a/tests/unit/out/unsafe/memcpy_struct_struct.rs +++ b/tests/unit/out/unsafe/memcpy_struct_struct.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Entry { pub bits: u8, pub value: u16, diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index dd069c5785..215170a416 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -10,22 +10,22 @@ use std::rc::Rc; #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, SwappableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct MoveOnly { pub v: i32, } impl MoveOnly { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut MoveOnly); (&raw mut (*this).v).write((*o).v); (*o).v = 0; @@ -43,11 +43,15 @@ impl MoveAssignableUnsafe for MoveOnly { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[constructor(constructor_1)] pub struct ConstMoveAssign { pub mark: i32, } impl ConstMoveAssign { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).mark).write(0); + } pub unsafe fn operator_assign_2( this: *mut Self, o: *mut ConstMoveAssign, @@ -63,25 +67,20 @@ impl ConstMoveAssign { return &mut (*this); } } -impl DefaultConstructibleUnsafe for ConstMoveAssign { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).mark).write(0); - } -} impl Default for ConstMoveAssign { fn default() -> Self { unsafe { { - let mut __v: ConstMoveAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: ConstMoveAssign = ZeroInitializationUnsafe::zero_init(); + ConstMoveAssign::constructor_1(&raw mut __v); __v } } } } pub unsafe fn make_0(__return: *mut MoveOnly, mut v: i32) { - object_unsafe!(m, MoveOnly(v)); - MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut m)); + object_unsafe!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -91,27 +90,27 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, MoveOnly(1)); - object_unsafe!(b, MoveOnly(2)); - object_unsafe!(c, MoveOnly(3)); + object_unsafe!(a, MoveOnly::constructor_1(1)); + object_unsafe!(b, MoveOnly::constructor_1(2)); + object_unsafe!(c, MoveOnly::constructor_1(3)); assign_unsafe!(a = RvalueRefUnsafe(b)); assert!(((a.v) == (2))); assert!(((b.v) == (0))); (unsafe { - let mut _o: MoveOnly = ::zero_init(); - MoveOnly::construct(&raw mut _o, 3); + let mut _o: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut _o, 3); assign_unsafe!(b = RvalueRefUnsafe(_o)) }); assign_unsafe!(c = RvalueRefUnsafe((*assign_unsafe!(a = RvalueRefUnsafe(b))))); assert!((((b.v) == (0)) && ((a.v) == (0))) && ((c.v) == (3))); (unsafe { - let mut _o: MoveOnly = ::zero_init(); - MoveOnly::construct(&raw mut _o, 5); + let mut _o: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut _o, 5); assign_unsafe!(a = RvalueRefUnsafe(_o)) }); assert!(((a.v) == (5))); (unsafe { - let mut _o: MoveOnly = ::zero_init(); + let mut _o: MoveOnly = ZeroInitializationUnsafe::zero_init(); (unsafe { make_0(&raw mut _o, 6) }); assign_unsafe!(a = RvalueRefUnsafe(_o)) }); @@ -123,23 +122,23 @@ unsafe fn main_0() -> i32 { assert!(((a.v) == (6))); let mut vec_: Vec = Vec::new(); { - let mut __tmp_1: MoveOnly = ::zero_init(); + let mut __tmp_1: MoveOnly = ZeroInitializationUnsafe::zero_init(); match (({ - MoveOnly::construct(&raw mut __tmp_1, 7); + MoveOnly::constructor_1(&raw mut __tmp_1, 7); &mut __tmp_1 } as *mut MoveOnly),) { (__tmp_0,) => vec_.push_moved(__tmp_0), } }; - object_unsafe!(d, MoveOnly(8)); + object_unsafe!(d, MoveOnly::constructor_1(8)); assign_unsafe!(vec_[(0_usize)] = RvalueRefUnsafe(d)); assert!(((vec_[(0_usize)].v) == (8))); assert!(((d.v) == (0))); - object_unsafe!(m, ConstMoveAssign); - object_unsafe!(m1, ConstMoveAssign); - object_unsafe!(m2, ConstMoveAssign); - object_unsafe!(cm, ConstMoveAssign); + object_unsafe!(m, ConstMoveAssign::constructor_1()); + object_unsafe!(m1, ConstMoveAssign::constructor_1()); + object_unsafe!(m2, ConstMoveAssign::constructor_1()); + object_unsafe!(cm, ConstMoveAssign::constructor_1()); (unsafe { ConstMoveAssign::operator_assign_2(&raw mut m1, &mut m) }); (unsafe { ConstMoveAssign::operator_assign_3(&raw mut m2, &cm) }); assert!(((m1.mark) == (1))); diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index 19b86d5dfd..560f78c913 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -8,48 +8,52 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct MoveOnly { pub v: i32, } impl MoveOnly { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut MoveOnly); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, RvalueRefUnsafe)] +#[constructor(constructor_3, RvalueRefUnsafe>)] pub struct ConstMove { pub mark: i32, } impl ConstMove { - pub unsafe fn construct_1(this: *mut Self, o: *mut ConstMove) { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).mark).write(0); + } + pub unsafe fn constructor_2(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut ConstMove); (&raw mut (*this).mark).write((((*o).mark) + (1))); } - pub unsafe fn construct_2(this: *mut Self, o: *const ConstMove) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe>) { + let o = (o.as_ptr() as *const ConstMove); (&raw mut (*this).mark).write((((*o).mark) + (10))); } } -impl DefaultConstructibleUnsafe for ConstMove { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).mark).write(0); - } -} impl Default for ConstMove { fn default() -> Self { unsafe { { - let mut __v: ConstMove = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: ConstMove = ZeroInitializationUnsafe::zero_init(); + ConstMove::constructor_1(&raw mut __v); __v } } @@ -57,31 +61,30 @@ impl Default for ConstMove { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct ThrowingMove { pub v: i32, pub copies: i32, pub moves: i32, } impl ThrowingMove { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for ThrowingMove { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const ThrowingMove); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } -} -impl MoveConstructibleUnsafe for ThrowingMove { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut ThrowingMove); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); @@ -91,31 +94,30 @@ impl MoveConstructibleUnsafe for ThrowingMove { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct NoexceptMove { pub v: i32, pub copies: i32, pub moves: i32, } impl NoexceptMove { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for NoexceptMove { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const NoexceptMove); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } -} -impl MoveConstructibleUnsafe for NoexceptMove { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut NoexceptMove); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); @@ -123,12 +125,13 @@ impl MoveConstructibleUnsafe for NoexceptMove { (*o).v = 0; } } -pub unsafe fn by_value_0(m: *mut MoveOnly) -> i32 { +pub unsafe fn by_value_0(m: ParameterObjectUnsafe) -> i32 { + let m = (m.as_ptr() as *mut MoveOnly); return (*m).v; } pub unsafe fn make_1(__return: *mut MoveOnly, mut v: i32) { - object_unsafe!(m, MoveOnly(v)); - MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut m)); + object_unsafe!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -138,75 +141,78 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, MoveOnly(1)); - object_unsafe!(b, MoveOnly, RvalueRefUnsafe::bind(&mut a)); + object_unsafe!(a, MoveOnly::constructor_1(1)); + object_unsafe!(b, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut a))); assert!(((b.v) == (1))); assert!(((a.v) == (0))); - object_unsafe!(c, MoveOnly, RvalueRefUnsafe::bind(&mut b)); + object_unsafe!(c, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut b))); assert!(((c.v) == (1))); assert!(((b.v) == (0))); - object_unsafe!(d, MoveOnly, RvalueRefUnsafe::bind(&mut c)); + object_unsafe!(d, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut c))); assert!(((d.v) == (1))); assert!(((c.v) == (0))); object_unsafe!(e, MoveOnly, |e| (unsafe { make_1(e, 5,) })); assert!(((e.v) == (5))); assert!( ((unsafe { - let mut _m: MoveOnly = ::zero_init(); - MoveOnly::construct(&raw mut _m, 6); - by_value_0(&mut _m) + let mut _m: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut _m, 6); + by_value_0(ParameterObjectUnsafe::bind(&mut _m)) }) == (6)) ); assert!( ((unsafe { - let mut _m: MoveOnly = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut _m, RvalueRefUnsafe::bind(&mut e)); - by_value_0(&mut _m) + let mut _m: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_3(&raw mut _m, RvalueRefUnsafe::bind(&mut e)); + by_value_0(ParameterObjectUnsafe::bind(&mut _m)) }) == (5)) ); assert!(((e.v) == (0))); let mut vec_: Vec = Vec::new(); { - let mut __tmp_1: MoveOnly = ::zero_init(); + let mut __tmp_1: MoveOnly = ZeroInitializationUnsafe::zero_init(); match (({ - MoveOnly::construct(&raw mut __tmp_1, 7); + MoveOnly::constructor_1(&raw mut __tmp_1, 7); &mut __tmp_1 } as *mut MoveOnly),) { (__tmp_0,) => vec_.push_moved(__tmp_0), } }; - object_unsafe!(f, MoveOnly(8)); + object_unsafe!(f, MoveOnly::constructor_1(8)); vec_.push_moved(&mut f); assert!(((vec_[(0_usize)].v) == (7)) && ((vec_[(1_usize)].v) == (8))); assert!(((f.v) == (0))); - object_unsafe!(m, ConstMove); - object_unsafe!(m1, ConstMove::construct_1(&mut m)); - object_unsafe!(cm, ConstMove); - object_unsafe!(m2, ConstMove::construct_2(&cm)); + object_unsafe!(m, ConstMove::constructor_1()); + object_unsafe!(m1, ConstMove::constructor_2(RvalueRefUnsafe::bind(&mut m))); + object_unsafe!(cm, ConstMove::constructor_1()); + object_unsafe!(m2, ConstMove::constructor_3(RvalueRefUnsafe::bind(&cm))); assert!(((m1.mark) == (1))); assert!(((m2.mark) == (10))); - object_unsafe!(t, ThrowingMove(1)); - object_unsafe!(t1, ThrowingMove, LvalueRefUnsafe::bind(&t)); + object_unsafe!(t, ThrowingMove::constructor_1(1)); + object_unsafe!(t1, ThrowingMove::constructor_2(LvalueRefUnsafe::bind(&t))); assert!(((t1.v) == (1))); assert!(((t1.copies) == (1))); assert!(((t1.moves) == (0))); assert!(((t.v) == (1))); - object_unsafe!(n, NoexceptMove(2)); - object_unsafe!(n1, NoexceptMove, RvalueRefUnsafe::bind(&mut n)); + object_unsafe!(n, NoexceptMove::constructor_1(2)); + object_unsafe!( + n1, + NoexceptMove::constructor_3(RvalueRefUnsafe::bind(&mut n)) + ); assert!(((n1.v) == (2))); assert!(((n1.copies) == (0))); assert!(((n1.moves) == (1))); assert!(((n.v) == (0))); - object_unsafe!(g, MoveOnly(3)); - object_unsafe!(g1, MoveOnly, RvalueRefUnsafe::bind(&mut g)); + object_unsafe!(g, MoveOnly::constructor_1(3)); + object_unsafe!(g1, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut g))); assert!(((g1.v) == (3))); assert!(((g.v) == (0))); let mut nv: Vec = Vec::new(); { - let mut __tmp_3: NoexceptMove = ::zero_init(); + let mut __tmp_3: NoexceptMove = ZeroInitializationUnsafe::zero_init(); match (({ - NoexceptMove::construct(&raw mut __tmp_3, 4); + NoexceptMove::constructor_1(&raw mut __tmp_3, 4); &mut __tmp_3 } as *mut NoexceptMove),) { diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index ef8486e171..bf79529233 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -8,16 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Chain { pub v: i32, } impl Chain { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Chain); + (&raw mut (*this).v).write((((*o).v) + (100))); + } + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Chain); + (&raw mut (*this).v).write((((*o).v) + (1))); + (*o).v = 0; + } pub unsafe fn add_4(this: *mut Self, mut n: i32) -> *mut Chain { (*this).v += n; return &mut (*this); @@ -27,31 +39,19 @@ impl Chain { return &mut (*this); } pub unsafe fn take(this: *mut Self, __return: *mut Chain) { - MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut (*this))); + Chain::constructor_3(__return, RvalueRefUnsafe::bind(&mut (*this))); return; } pub unsafe fn copy(this: *const Self, __return: *mut Chain) { - CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(&(*this))); + Chain::constructor_2(__return, LvalueRefUnsafe::bind(&(*this))); return; } pub unsafe fn self_(this: *mut Self) -> *mut Chain { return &mut (*this); } } -impl CopyConstructibleUnsafe for Chain { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { - let o = (o.as_ptr() as *const Chain); - (&raw mut (*this).v).write((((*o).v) + (100))); - } -} -impl MoveConstructibleUnsafe for Chain { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { - let o = (o.as_ptr() as *mut Chain); - (&raw mut (*this).v).write((((*o).v) + (1))); - (*o).v = 0; - } -} -pub unsafe fn consume_0(c: *mut Chain) -> i32 { +pub unsafe fn consume_0(c: ParameterObjectUnsafe) -> i32 { + let c = (c.as_ptr() as *mut Chain); return (*c).v; } pub fn main() { @@ -61,24 +61,23 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Chain(1)); + object_unsafe!(a, Chain::constructor_1(1)); (unsafe { Chain::add_4(&raw mut (*(unsafe { Chain::add_4(&raw mut a, 1) })), 1) }); assert!(((a.v) == (3))); - object_unsafe!(b0, Chain(5)); + object_unsafe!(b0, Chain::constructor_1(5)); object_unsafe!( b, - Chain, - RvalueRefUnsafe::bind( + Chain::constructor_3(RvalueRefUnsafe::bind( (unsafe { Chain::add_5(&mut (*(unsafe { Chain::add_5(&raw mut b0, 1,) })), 1,) }) - ) + )) ); assert!(((b.v) == (8)) && ((b0.v) == (0))); object_unsafe!(c, Chain, |c| { - let mut __tmp_0: Chain = ::zero_init(); + let mut __tmp_0: Chain = ZeroInitializationUnsafe::zero_init(); (unsafe { Chain::take( &mut (*{ - Chain::construct(&raw mut __tmp_0, 10); + Chain::constructor_1(&raw mut __tmp_0, 10); &mut __tmp_0 }), c, @@ -88,18 +87,18 @@ unsafe fn main_0() -> i32 { assert!(((c.v) == (11))); object_unsafe!(d, Chain, |d| (unsafe { Chain::copy(&raw const c, d,) })); assert!(((d.v) == (111)) && ((c.v) == (11))); - object_unsafe!(g, Chain(20)); + object_unsafe!(g, Chain::constructor_1(20)); assert!( ((unsafe { - let mut _c: Chain = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( + let mut _c: Chain = ZeroInitializationUnsafe::zero_init(); + Chain::constructor_3( &raw mut _c, RvalueRefUnsafe::bind((unsafe { Chain::self_(&raw mut g) })), ); - consume_0(&mut _c) + consume_0(ParameterObjectUnsafe::bind(&mut _c)) }) == (21)) ); - object_unsafe!(e, Chain(30)); + object_unsafe!(e, Chain::constructor_1(30)); object_unsafe!(f, Chain, |f| (unsafe { Chain::take(&raw mut e, f,) })); assert!(((f.v) == (31)) && ((e.v) == (0))); return 0; diff --git a/tests/unit/out/unsafe/nested_structs.rs b/tests/unit/out/unsafe/nested_structs.rs index a32dba8a86..bfb1764e3f 100644 --- a/tests/unit/out/unsafe/nested_structs.rs +++ b/tests/unit/out/unsafe/nested_structs.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Level0_Level1_1_Level2_1_Level3_1 { pub x1: i32, } @@ -30,7 +32,9 @@ pub struct Level0_Level1_1_Level2_1_Level3_1 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Level0_Level1_1_Level2_1_Level3_2 { pub x1: i32, pub x2: i32, @@ -45,7 +49,9 @@ pub struct Level0_Level1_1_Level2_1_Level3_2 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Level0_Level1_1_Level2_1 { pub x1: i32, } @@ -59,7 +65,9 @@ pub struct Level0_Level1_1_Level2_1 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Level0_Level1_1 { pub x1: i32, } @@ -73,7 +81,9 @@ pub struct Level0_Level1_1 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Level0_Level1_2 { pub x1: i32, pub x2: i32, @@ -88,7 +98,9 @@ pub struct Level0_Level1_2 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Level0 {} pub fn main() { unsafe { diff --git a/tests/unit/out/unsafe/new.rs b/tests/unit/out/unsafe/new.rs index 122825c5c6..374d0c37ce 100644 --- a/tests/unit/out/unsafe/new.rs +++ b/tests/unit/out/unsafe/new.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 dac1d68074..7837ddd131 100644 --- a/tests/unit/out/unsafe/new_bst.rs +++ b/tests/unit/out/unsafe/new_bst.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 fe46b51827..0ffe4e02f1 100644 --- a/tests/unit/out/unsafe/new_struct.rs +++ b/tests/unit/out/unsafe/new_struct.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pair { pub x: i32, pub y: i32, @@ -31,7 +33,9 @@ pub struct Pair { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 72c4559f6c..2e455c7a70 100644 --- a/tests/unit/out/unsafe/nttp_distinct_specializations.rs +++ b/tests/unit/out/unsafe/nttp_distinct_specializations.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S_2_ { pub v: i32, pub w: i32, @@ -36,7 +38,9 @@ impl S_2_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S_1_ { pub v: i32, } @@ -55,7 +59,9 @@ impl S_1_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S_3_ { pub v: i32, } diff --git a/tests/unit/out/unsafe/offsetof.rs b/tests/unit/out/unsafe/offsetof.rs index fde3ab7987..034870dd88 100644 --- a/tests/unit/out/unsafe/offsetof.rs +++ b/tests/unit/out/unsafe/offsetof.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Layout { pub a: u8, pub b: u32, @@ -31,7 +33,9 @@ pub struct Layout { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 b3b437641c..54d591d405 100644 --- a/tests/unit/out/unsafe/opaque_forward_decl.rs +++ b/tests/unit/out/unsafe/opaque_forward_decl.rs @@ -34,6 +34,15 @@ unsafe fn main_0() -> i32 { }; return ((c.x) - (42)); } -#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] +#[derive( + Clone, + Copy, + Default, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + ConversionsUnsafe, +)] pub struct opaque; pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/opaque_record_copy.rs b/tests/unit/out/unsafe/opaque_record_copy.rs index 1ec8a560a5..6c3042bf02 100644 --- a/tests/unit/out/unsafe/opaque_record_copy.rs +++ b/tests/unit/out/unsafe/opaque_record_copy.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Probe {} #[repr(C)] #[derive( @@ -28,7 +30,9 @@ pub struct Probe {} TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Wrapper_Probe_ { pub base_: Probe, pub tag: i32, diff --git a/tests/unit/out/unsafe/operator_arithmetic_free.rs b/tests/unit/out/unsafe/operator_arithmetic_free.rs index eb22d6f97f..7a9dccd758 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_free.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_free.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 2c3c8bda4b..681ebd8169 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_member.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_member.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 f60a99aedd..57a7d648ba 100644 --- a/tests/unit/out/unsafe/operator_bitwise_free.rs +++ b/tests/unit/out/unsafe/operator_bitwise_free.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 e3907641d2..351eaa5d27 100644 --- a/tests/unit/out/unsafe/operator_bitwise_member.rs +++ b/tests/unit/out/unsafe/operator_bitwise_member.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 d8bd31e8ea..94ba85e9ea 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Eq { pub a: i32, pub b: i32, @@ -34,6 +36,8 @@ pub struct Eq { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Cmp { pub a: i32, pub b: i32, @@ -76,6 +80,8 @@ impl LessThanComparableUnsafe for Cmp { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Both { pub a: i32, } @@ -110,6 +116,8 @@ impl LessThanComparableUnsafe for Both { PartiallyOrderedWithUnsafe, )] #[three_way(OrdOnly::operator_cmp)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct OrdOnly { pub a: i32, } @@ -143,6 +151,8 @@ impl LessThanComparableUnsafe for OrdOnly { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Inner { pub x: i32, } @@ -177,6 +187,8 @@ impl LessThanComparableUnsafe for Inner { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Outer { pub i: Inner, pub y: i32, @@ -218,7 +230,9 @@ impl LessThanComparableUnsafe for Outer { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Secondary { pub a: i32, } @@ -255,6 +269,8 @@ impl LessThanComparableUnsafe for Secondary { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] 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 1d3c92e5d4..3f29909619 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S { pub v: i32, } @@ -41,7 +43,9 @@ pub unsafe fn operator_lt_1(mut a: i32, b: *const S) -> bool { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 0f0c0299c7..4e3b54c8b4 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 d70ad8a71d..a19dca88fe 100644 --- a/tests/unit/out/unsafe/operator_comparison_mixed.rs +++ b/tests/unit/out/unsafe/operator_comparison_mixed.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 197e3a3414..d267606bf5 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct X { pub v: i32, } @@ -53,7 +55,9 @@ pub unsafe fn operator_ge_3(mut a: X, mut b: X) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Result { pub r: i32, } @@ -67,7 +71,9 @@ pub struct Result { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Custom { pub v: i32, } @@ -88,7 +94,9 @@ impl Custom { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Mixed { pub v: i32, } @@ -117,17 +125,19 @@ impl LessThanComparableUnsafe for Mixed { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_into(bool, to_bool)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, bool)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool )] pub struct MyBool { pub value: bool, } impl MyBool { - pub unsafe fn construct(this: *mut Self, mut v: bool) { + pub unsafe fn constructor_1(this: *mut Self, mut v: bool) { (&raw mut (*this).value).write(v); } pub unsafe fn to_bool(this: *const Self) -> bool { @@ -144,7 +154,9 @@ impl MyBool { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Boolish { pub v: i32, } @@ -158,15 +170,15 @@ impl LessThanComparableUnsafe for Boolish { } pub unsafe fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let mut __v: MyBool = ::zero_init(); - MyBool::construct(&raw mut __v, ((a.v) == (b.v))); + let mut __v: MyBool = ZeroInitializationUnsafe::zero_init(); + MyBool::constructor_1(&raw mut __v, ((a.v) == (b.v))); __v }; } pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let mut __v: MyBool = ::zero_init(); - MyBool::construct(&raw mut __v, ((a.v) < (b.v))); + let mut __v: MyBool = ZeroInitializationUnsafe::zero_init(); + MyBool::constructor_1(&raw mut __v, ((a.v) < (b.v))); __v }; } @@ -174,19 +186,20 @@ pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveAssignableUnsafe, Default, )] #[memberwise(copy_assign)] -#[cpp_into(bool, to_bool)] +#[derive(ConversionsUnsafe)] +#[constructor(constructor_1, explicit, bool)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool )] pub struct RefBool { pub value: bool, } impl RefBool { - pub unsafe fn construct(this: *mut Self, mut v: bool) { + pub unsafe fn constructor_1(this: *mut Self, mut v: bool) { (&raw mut (*this).value).write(v); } pub unsafe fn to_bool(this: *const Self) -> bool { @@ -195,8 +208,8 @@ impl RefBool { } pub static mut ref_true_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: RefBool = ::zero_init(); - RefBool::construct(&raw mut __v, true); + let mut __v: RefBool = ZeroInitializationUnsafe::zero_init(); + RefBool::constructor_1(&raw mut __v, true); __v } }); @@ -210,7 +223,9 @@ pub static mut ref_true_8: std::cell::LazyCell = std::cell::LazyCell::n TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 a8079f7e48..d2172b3b03 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -13,20 +13,17 @@ impl LessThanComparableUnsafe for S { } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - CppFromUnsafe, - DefaultInitializableUnsafe, - MemberwiseUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] pub struct S { data_: i32, } impl S { - pub unsafe fn construct(this: *mut Self, mut data: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut data: i32) { (&raw mut (*this).data_).write(data); } } @@ -37,9 +34,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, S(1)); - object_unsafe!(b, S(2)); - object_unsafe!(c, S(1)); + object_unsafe!(a, S::constructor_1(1)); + object_unsafe!(b, S::constructor_1(2)); + object_unsafe!(c, S::constructor_1(1)); assert!( (unsafe { let _x: *const S = &a; diff --git a/tests/unit/out/unsafe/operator_compound_assignment_free.rs b/tests/unit/out/unsafe/operator_compound_assignment_free.rs index 8f4b0ef00a..d07f94df86 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_free.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_free.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 6cc08edab3..bd8b89492b 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_member.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_member.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 ca483959cb..1d43aabf16 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Defaulted { pub a: i32, pub b: i32, @@ -50,6 +52,8 @@ impl ThreeWayComparableUnsafe for DefaultedOrd { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct DefaultedOrd { pub a: i32, } @@ -78,7 +82,9 @@ pub unsafe fn operator_add_0(x: *const Inline, y: *const Inline) -> Inline { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Inline { pub a: i32, } @@ -92,7 +98,9 @@ pub struct Inline { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct OutOfLine { pub a: i32, } @@ -111,7 +119,9 @@ impl LessThanComparableUnsafe for Tmpl_int_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Tmpl_int_ { pub v: i32, } @@ -125,7 +135,9 @@ pub struct Tmpl_int_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Tmpl_long_ { pub v: i64, } @@ -139,7 +151,9 @@ pub struct Tmpl_long_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 557eb3f9aa..a80f6bd106 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 4e7bbefdc5..440d7d9a09 100644 --- a/tests/unit/out/unsafe/operator_logical_free.rs +++ b/tests/unit/out/unsafe/operator_logical_free.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 839cbe90ce..5de075709d 100644 --- a/tests/unit/out/unsafe/operator_logical_member.rs +++ b/tests/unit/out/unsafe/operator_logical_member.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 32ef575f1e..9daac8ade1 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_free.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_free.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Inner { pub x: i32, } @@ -30,7 +32,9 @@ pub struct Inner { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 acd45f374d..c44182e765 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_member.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_member.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Inner { pub x: i32, } @@ -30,7 +32,9 @@ pub struct Inner { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Table {} impl Table { pub unsafe fn operator_index(mut i: i32) -> *mut i32 { @@ -49,7 +53,9 @@ pub static mut table_0: std::cell::LazyCell<[i32; 3]> = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 47881cca64..05b8c9c5da 100644 --- a/tests/unit/out/unsafe/operator_other_free.rs +++ b/tests/unit/out/unsafe/operator_other_free.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 06b1da4f26..d14ee5c86c 100644 --- a/tests/unit/out/unsafe/operator_other_member.rs +++ b/tests/unit/out/unsafe/operator_other_member.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Static {} impl Static { pub unsafe fn operator_call(mut a: i32, mut b: i32) -> i32 { @@ -30,12 +32,14 @@ impl Static { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_into(i32, to_i32)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] 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 297a4a697c..1f690397e0 100644 --- a/tests/unit/out/unsafe/operator_overloads.rs +++ b/tests/unit/out/unsafe/operator_overloads.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 41a39f0738..a177054c4d 100644 --- a/tests/unit/out/unsafe/operator_qualifiers.rs +++ b/tests/unit/out/unsafe/operator_qualifiers.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 b66591f0ff..adab99e390 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -19,6 +19,8 @@ use std::rc::Rc; PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] 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 87f7a79611..befbfad472 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Lt { pub v: i32, } @@ -35,7 +37,9 @@ impl LessThanComparableUnsafe for Lt { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Eq { pub v: i32, } @@ -52,6 +56,8 @@ pub struct Eq { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Cmp { pub v: i32, } @@ -76,7 +82,9 @@ impl LessThanComparableUnsafe for Cmp { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Free { pub v: i32, } @@ -95,7 +103,9 @@ impl LessThanComparableUnsafe for Free { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 14ba1ffaaf..005bf039cc 100644 --- a/tests/unit/out/unsafe/overload_mangling.rs +++ b/tests/unit/out/unsafe/overload_mangling.rs @@ -25,7 +25,9 @@ pub unsafe fn twice_2(mut n: i32) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Access_S_ {} impl Access_S_ { pub unsafe fn get_1(this: *mut Self, mut p: *mut S) -> i32 { @@ -51,7 +53,9 @@ impl Access_S_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S { pub base: i32, } @@ -146,7 +150,9 @@ impl S { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Box_ { pub v: i32, } diff --git a/tests/unit/out/unsafe/pair.rs b/tests/unit/out/unsafe/pair.rs index ea56436da7..bae0c585f0 100644 --- a/tests/unit/out/unsafe/pair.rs +++ b/tests/unit/out/unsafe/pair.rs @@ -20,7 +20,20 @@ unsafe fn main_0() -> i32 { assert!(((p2.0) == (3_f64))); assert!(((p2.1) == (4))); let mut p3: (f64, i32) = match ((&mut (5, 6) as *mut (i32, i32)),) { - (__tmp_0,) => (((*&mut (*__tmp_0).0) as f64), (*&mut (*__tmp_0).1)), + (__tmp_0,) => { + object_unsafe!(__first, f64, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).0),) + )); + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + } }; assert!(((p3.0) == (5_f64))); assert!(((p3.1) == (6))); @@ -33,9 +46,21 @@ unsafe fn main_0() -> i32 { (&mut (arr.as_ptr().offset((1) as isize), n) as *mut (*const i32, u32)), ) { (__tmp_1, __tmp_2) => { - (*__tmp_1) = ( - cpp_move_unsafe!(&mut (*__tmp_2).0), - ((*&mut (*__tmp_2).1) as u64), + object_unsafe!(__first, *const i32, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::<*const i32>::bind(&raw mut (*__tmp_2).0), + __this + )); + object_unsafe!(__second, u64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut (*__tmp_2).1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut (*__tmp_1).0, + RvalueRefUnsafe::<*const i32>::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut (*__tmp_1).1, + RvalueRefUnsafe::::bind(&raw mut __second), ); } }; @@ -78,12 +103,42 @@ unsafe fn main_0() -> i32 { let mut narrow: (i32, i32) = (3, 4); let mut pw: *mut i64 = (&mut w.0 as *mut i64); { - w = (((*&narrow.0) as i64), ((*&narrow.1) as i64)); + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.0), + __this + )); + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut w.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut w.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); }; assert!(((*pw) == (3_i64))); let mut m: (i32, i32) = (5, 6); { - w = (((*&mut m.0) as i64), ((*&mut m.1) as i64)); + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut m.0), + __this + )); + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut m.1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut w.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut w.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); }; assert!(((*pw) == (5_i64))); (*{ @@ -101,13 +156,43 @@ unsafe fn main_0() -> i32 { .0 = 8; assert!(((d.0) == (8)) && ((d.1) == (4))); (*{ - w = (((*&narrow.0) as i64), ((*&narrow.1) as i64)); + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.0), + __this + )); + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut w.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut w.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); &mut w }) .1 = 9_i64; assert!(((w.0) == (3_i64)) && ((w.1) == (9_i64))); (*{ - w = (((*&mut narrow.0) as i64), ((*&mut narrow.1) as i64)); + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut narrow.0), + __this + )); + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut narrow.1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut w.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut w.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); &mut w }) .0 = 10_i64; diff --git a/tests/unit/out/unsafe/pair_converting_construction.rs b/tests/unit/out/unsafe/pair_converting_construction.rs index 9228e4c5cc..2674a4d16b 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.rs @@ -13,17 +13,18 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct Celsius { pub degrees: i32, } impl Celsius { - pub unsafe fn construct(this: *mut Self, mut d: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut d: i32) { (&raw mut (*this).degrees).write(d); } } @@ -34,12 +35,13 @@ impl Celsius { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_into(i32, to_i32)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] pub struct Meters { pub value: i32, } @@ -55,17 +57,19 @@ impl Meters { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(Celsius, construct, ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1, LvalueRefUnsafe>)] pub struct Label { pub id: i32, } impl Label { - pub unsafe fn construct(this: *mut Self, c: *const Celsius) { + pub unsafe fn constructor_1(this: *mut Self, c: LvalueRefUnsafe>) { + let c = (c.as_ptr() as *const Celsius); (&raw mut (*this).id).write((*c).degrees); } } @@ -76,23 +80,26 @@ impl Label { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(Celsius, construct_1, ptr)] -#[cpp_from_move(Celsius, construct_2, ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1, LvalueRefUnsafe>)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct Owner { pub taken: i32, pub copied: i32, } impl Owner { - pub unsafe fn construct_1(this: *mut Self, c: *const Celsius) { + pub unsafe fn constructor_1(this: *mut Self, c: LvalueRefUnsafe>) { + let c = (c.as_ptr() as *const Celsius); (&raw mut (*this).taken).write(0); (&raw mut (*this).copied).write((*c).degrees); } - pub unsafe fn construct_2(this: *mut Self, c: *mut Celsius) { + pub unsafe fn constructor_2(this: *mut Self, c: RvalueRefUnsafe) { + let c = (c.as_ptr() as *mut Celsius); (&raw mut (*this).taken).write((*c).degrees); (&raw mut (*this).copied).write(0); } @@ -104,37 +111,45 @@ impl Owner { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(Celsius, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, Celsius)] pub struct Holder { pub value: i32, } impl Holder { - pub unsafe fn construct(this: *mut Self, mut c: Celsius) { + pub unsafe fn constructor_1(this: *mut Self, mut c: Celsius) { (&raw mut (*this).value).write(c.degrees); } } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, TriviallyCopyableUnsafe, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct Fallback { pub value: i32, } impl Fallback { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).value).write(v); } } -impl DefaultConstructibleUnsafe for Fallback { - unsafe fn default_constructor(this: *mut Self) { +impl ConstructorUnsafe<()> for Fallback { + unsafe fn constructor(this: *mut Self, _: ()) { unsafe { - Fallback::construct(this, -1_i32); + Fallback::constructor_1(this, -1_i32); } } } @@ -142,8 +157,8 @@ impl Default for Fallback { fn default() -> Self { unsafe { { - let mut __v: Fallback = ::zero_init(); - Fallback::construct(&raw mut __v, -1_i32); + let mut __v: Fallback = ZeroInitializationUnsafe::zero_init(); + Fallback::constructor_1(&raw mut __v, -1_i32); __v } } @@ -159,7 +174,9 @@ impl Default for Fallback { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Counter { pub hits: i32, } @@ -170,23 +187,26 @@ pub struct Counter { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(Counter, construct, mut_ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1, LvalueRefUnsafe)] pub struct Observer { pub seen: i32, } impl Observer { - pub unsafe fn construct(this: *mut Self, c: *mut Counter) { + pub unsafe fn constructor_1(this: *mut Self, c: LvalueRefUnsafe) { + let c = (c.as_ptr() as *mut Counter); (&raw mut (*this).seen).write((*c).hits); (*c).hits.postfix_inc(); } } impl Tag { - pub unsafe fn construct(this: *mut Self, u: *const Celsius) { + pub unsafe fn constructor_1_1(this: *mut Self, u: LvalueRefUnsafe>) { + let u = (u.as_ptr() as *const Celsius); (&raw mut (*this).code).write((((*u).degrees) + (100))); } } @@ -197,12 +217,13 @@ impl Tag { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(Celsius, construct, ptr)] +#[conversions(copy, move)] +#[constructor(constructor_1_1, LvalueRefUnsafe>)] pub struct Tag { pub code: i32, } @@ -213,17 +234,19 @@ pub struct Tag { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(*const libc::c_char , construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, PointerUnsafe>)] pub struct Name { pub len: i32, } impl Name { - pub unsafe fn construct(this: *mut Self, mut s: *const libc::c_char) { + pub unsafe fn constructor_1(this: *mut Self, s: PointerUnsafe>) { + let mut s = (s.as_ptr() as *const libc::c_char); (&raw mut (*this).len).write(0); 'loop_: while ((*s.offset(((*this).len) as isize)) != 0) { (*this).len.prefix_inc(); @@ -242,13 +265,13 @@ unsafe fn main_0() -> i32 { assert!(((widened.1) == (2_u32))); let mut from_ints: (Celsius, Celsius) = ( { - let mut __v: Celsius = ::zero_init(); - Celsius::construct(&raw mut __v, 1); + let mut __v: Celsius = ZeroInitializationUnsafe::zero_init(); + Celsius::constructor_1(&raw mut __v, 1); __v }, { - let mut __v: Celsius = ::zero_init(); - Celsius::construct(&raw mut __v, 2); + let mut __v: Celsius = ZeroInitializationUnsafe::zero_init(); + Celsius::constructor_1(&raw mut __v, 2); __v }, ); @@ -262,126 +285,255 @@ unsafe fn main_0() -> i32 { assert!(((from_operators.0) == (7))); assert!(((from_operators.1) == (7_i64))); let mut from_moved_pair: (i64, f64) = match ((&mut (3, 4) as *mut (i32, i32)),) { - (__tmp_0,) => (((*&mut (*__tmp_0).0) as i64), ((*&mut (*__tmp_0).1) as f64)), + (__tmp_0,) => { + object_unsafe!(__first, i64, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).0),) + )); + object_unsafe!(__second, f64, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + } }; assert!(((from_moved_pair.0) == (3_i64))); assert!(((from_moved_pair.1) == (4_f64))); let mut ints: (i32, i32) = (5, 6); - let mut from_copied_pair: (Celsius, i64) = ( - >::cpp_from(&ints.0), - ((*&ints.1) as i64), - ); + let mut from_copied_pair: (Celsius, i64) = { + object_unsafe!(__first, Celsius, |__this| { + ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const ints.0),), + ) + }); + object_unsafe!(__second, i64, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const ints.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + }; assert!(((from_copied_pair.0.degrees) == (5))); assert!(((from_copied_pair.1) == (6_i64))); let mut meters: (Meters, Meters) = ((Meters { value: 8 }), (Meters { value: 9 })); - let mut from_operator_pair: (i32, i32) = ( - >::cpp_from(&meters.0), - >::cpp_from(&meters.1), - ); + let mut from_operator_pair: (i32, i32) = { + object_unsafe!(__first, i32, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const meters.0),) + )); + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const meters.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + }; assert!(((from_operator_pair.0) == (8))); assert!(((from_operator_pair.1) == (9))); let mut celsius: (Celsius, Celsius) = ( { - let mut __v: Celsius = ::zero_init(); - Celsius::construct(&raw mut __v, 10); + let mut __v: Celsius = ZeroInitializationUnsafe::zero_init(); + Celsius::constructor_1(&raw mut __v, 10); __v }, { - let mut __v: Celsius = ::zero_init(); - Celsius::construct(&raw mut __v, 11); + let mut __v: Celsius = ZeroInitializationUnsafe::zero_init(); + Celsius::constructor_1(&raw mut __v, 11); __v }, ); - let mut from_record_pair: (Label, Owner) = ( - ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: A = ZeroInitializationUnsafe::zero_init(); + A::constructor_1(&raw mut __v); __v } } } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct B { pub v: i32, } -impl DefaultConstructibleUnsafe for B { - unsafe fn default_constructor(this: *mut Self) { +impl B { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(2); } } @@ -49,8 +65,8 @@ impl Default for B { fn default() -> Self { unsafe { { - let mut __v: B = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: B = ZeroInitializationUnsafe::zero_init(); + B::constructor_1(&raw mut __v); __v } } @@ -63,17 +79,18 @@ impl Default for B { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct NoDefault { pub v: i32, } impl NoDefault { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } } @@ -96,17 +113,18 @@ pub unsafe fn always_given_3(mut x: NoDefault) -> i32 { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct S_NoDefault_ { pub v: i32, } impl S_NoDefault_ { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } pub unsafe fn get(this: *const Self, mut t: NoDefault) -> i32 { @@ -123,8 +141,8 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { used_0({ - let mut __v: A = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: A = ZeroInitializationUnsafe::zero_init(); + A::constructor_1(&raw mut __v); __v }) }) == (1)) @@ -132,8 +150,8 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { used_0({ - let mut __v: A = ::zero_init(); - A::construct_1(&raw mut __v, 5); + let mut __v: A = ZeroInitializationUnsafe::zero_init(); + A::constructor_2(&raw mut __v, 5); __v }) }) == (5)) @@ -141,8 +159,8 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { used_1({ - let mut __v: B = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: B = ZeroInitializationUnsafe::zero_init(); + B::constructor_1(&raw mut __v); __v }) }) == (2)) @@ -151,8 +169,8 @@ unsafe fn main_0() -> i32 { ((unsafe { scaled_2( { - let mut __v: A = ::zero_init(); - A::construct_1(&raw mut __v, 3); + let mut __v: A = ZeroInitializationUnsafe::zero_init(); + A::constructor_2(&raw mut __v, 3); __v }, (::std::mem::size_of::() as i32), @@ -163,8 +181,8 @@ unsafe fn main_0() -> i32 { ((unsafe { scaled_2( { - let mut __v: A = ::zero_init(); - A::construct_1(&raw mut __v, 3); + let mut __v: A = ZeroInitializationUnsafe::zero_init(); + A::constructor_2(&raw mut __v, 3); __v }, 2, @@ -174,18 +192,18 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { always_given_3({ - let mut __v: NoDefault = ::zero_init(); - NoDefault::construct(&raw mut __v, 3); + let mut __v: NoDefault = ZeroInitializationUnsafe::zero_init(); + NoDefault::constructor_1(&raw mut __v, 3); __v }) }) == (3)) ); - object_unsafe!(s, S_NoDefault_(1)); + object_unsafe!(s, S_NoDefault_::constructor_1(1)); assert!( ((unsafe { S_NoDefault_::get(&raw const s, { - let mut __v: NoDefault = ::zero_init(); - NoDefault::construct(&raw mut __v, 4); + let mut __v: NoDefault = ZeroInitializationUnsafe::zero_init(); + NoDefault::constructor_1(&raw mut __v, 4); __v }) }) == (5)) diff --git a/tests/unit/out/unsafe/template_static_member.rs b/tests/unit/out/unsafe/template_static_member.rs index 0036ac4a57..c873d53a4f 100644 --- a/tests/unit/out/unsafe/template_static_member.rs +++ b/tests/unit/out/unsafe/template_static_member.rs @@ -17,7 +17,9 @@ pub static mut s_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsaf TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Static_int_ {} pub static mut s_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { (55 as libc::c_char) }); @@ -31,7 +33,9 @@ pub static mut s_1: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Static_char_ {} pub static mut s_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 55_i64 }); #[repr(C)] @@ -44,7 +48,9 @@ pub static mut s_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsaf TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 }); @@ -58,7 +64,9 @@ pub static mut hi_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsa TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Range_int_ {} pub static mut lo_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { (-2_i32 as i64) }); @@ -73,7 +81,9 @@ pub static mut hi_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsa TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 6213be8029..b8206f7d9c 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -19,11 +19,14 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Inner { pub values: Vec, } -impl DefaultConstructibleUnsafe for Inner { - unsafe fn default_constructor(this: *mut Self) { +impl Inner { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); } } @@ -40,15 +43,18 @@ impl DefaultConstructibleUnsafe for Inner { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Outer { pub values: Vec, pub inner: Inner, pub name: [libc::c_char; 8], } -impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(this: *mut Self) { +impl Outer { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).inner); + Inner::constructor_1(&raw mut (*this).inner); (&raw mut (*this).name).write([(0 as libc::c_char); 8]); } } @@ -80,7 +86,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut calls: i32 = 0; let mut member: i32 = { - let mut __tmp_0: Outer = ::zero_init(); + let mut __tmp_0: Outer = ZeroInitializationUnsafe::zero_init(); (unsafe { sum_1( &(*{ @@ -92,7 +98,7 @@ unsafe fn main_0() -> i32 { }) }; let mut nested: i32 = { - let mut __tmp_1: Outer = ::zero_init(); + let mut __tmp_1: Outer = ZeroInitializationUnsafe::zero_init(); (unsafe { sum_1( &(*{ @@ -105,7 +111,7 @@ unsafe fn main_0() -> i32 { }) }; let mut element: i32 = { - let mut __tmp_2: Outer = ::zero_init(); + let mut __tmp_2: Outer = ZeroInitializationUnsafe::zero_init(); (*{ (unsafe { make_0(&raw mut __tmp_2, &mut calls) }); &mut __tmp_2 @@ -113,7 +119,7 @@ unsafe fn main_0() -> i32 { .values[(((calls) - (2)) as usize)] }; let mut length: usize = { - let mut __tmp_3: Outer = ::zero_init(); + let mut __tmp_3: Outer = ZeroInitializationUnsafe::zero_init(); libc::strlen( ((*{ (unsafe { make_0(&raw mut __tmp_3, &mut calls) }); diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index 7ccbb9e43c..ca5082b431 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -19,11 +19,14 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Outer { pub values: Vec, } -impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(this: *mut Self) { +impl Outer { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); } } @@ -40,17 +43,18 @@ pub unsafe fn make_0(__return: *mut Outer) { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(Vec , construct, ptr)] +#[conversions(copy, move)] pub struct H { pub last: i32, } impl H { - pub unsafe fn construct(this: *mut Self, values: *const Vec) { + pub unsafe fn constructor_1(this: *mut Self, values: LvalueRefUnsafe>>) { + let values = (values.as_ptr() as *const Vec); (&raw mut (*this).last).write((&(*values))[(3_usize)]); } } @@ -62,14 +66,16 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(h, H, |h| { - let mut __tmp_0: Outer = ::zero_init(); - H::construct( + let mut __tmp_0: Outer = ZeroInitializationUnsafe::zero_init(); + H::constructor_1( h, - &(*{ - (unsafe { make_0(&raw mut __tmp_0) }); - &mut __tmp_0 - }) - .values, + LvalueRefUnsafe::bind( + &(*{ + (unsafe { make_0(&raw mut __tmp_0) }); + &mut __tmp_0 + }) + .values, + ), ) }); (unsafe { libc::printf(c"%d\n".as_ptr() as *const libc::c_char, (h.last)) }); diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index 7a3f5dc295..f23edc40f5 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -19,11 +19,14 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Inner { pub values: Vec, } -impl DefaultConstructibleUnsafe for Inner { - unsafe fn default_constructor(this: *mut Self) { +impl Inner { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); } } @@ -40,14 +43,17 @@ impl DefaultConstructibleUnsafe for Inner { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Outer { pub values: Vec, pub inner: Inner, } -impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(this: *mut Self) { +impl Outer { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).inner); + Inner::constructor_1(&raw mut (*this).inner); } } pub unsafe fn make_0(__return: *mut Outer) { @@ -70,8 +76,8 @@ pub fn main() { } unsafe fn main_0() -> i32 { { - let mut __tmp_0: Outer = ::zero_init(); - let mut __tmp_1: Outer = ::zero_init(); + let mut __tmp_0: Outer = ZeroInitializationUnsafe::zero_init(); + let mut __tmp_1: Outer = ZeroInitializationUnsafe::zero_init(); (unsafe { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, diff --git a/tests/unit/out/unsafe/this.rs b/tests/unit/out/unsafe/this.rs index 754894f450..471e7670b3 100644 --- a/tests/unit/out/unsafe/this.rs +++ b/tests/unit/out/unsafe/this.rs @@ -13,22 +13,26 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct_1, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, i32 , PointerUnsafe)] +#[constructor(constructor_3, i32 , PointerUnsafe>)] pub struct S { pub a_: i32, pub self__: *mut S, } impl S { - pub unsafe fn construct_1(this: *mut Self, mut a: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut a: i32) { (&raw mut (*this).a_).write(a); (&raw mut (*this).self__).write(std::ptr::null_mut()); } - pub unsafe fn construct_2(this: *mut Self, mut a: i32, mut other: *mut S) { + pub unsafe fn constructor_2(this: *mut Self, mut a: i32, other: PointerUnsafe) { + let mut other = (other.as_ptr() as *mut S); (&raw mut (*this).a_).write(a); (&raw mut (*this).self__).write(std::ptr::null_mut()); if ((this) == (other)) { @@ -37,7 +41,8 @@ impl S { (*this).self__ = other; } } - pub unsafe fn construct_3(this: *mut Self, mut a: i32, mut other: *const S) { + pub unsafe fn constructor_3(this: *mut Self, mut a: i32, other: PointerUnsafe>) { + let mut other = (other.as_ptr() as *const S); (&raw mut (*this).a_).write(a); (&raw mut (*this).self__).write(std::ptr::null_mut()); if (((this).cast_const()) == (other)) { @@ -85,8 +90,8 @@ impl S { } pub unsafe fn reset(this: *mut Self) { (*this) = { - let mut __v: S = ::zero_init(); - S::construct_1(&raw mut __v, 0); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); + S::constructor_1(&raw mut __v, 0); __v }; } @@ -117,17 +122,18 @@ pub unsafe fn bump_0(mut p: *mut S) { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct D { pub a_: i32, } impl D { - pub unsafe fn construct(this: *mut Self, mut a: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut a: i32) { (&raw mut (*this).a_).write(a); (*this).a_ *= 2; } @@ -139,7 +145,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S::construct_1(1)); + object_unsafe!(s, S::constructor_1(1)); let ref_: *mut S = (unsafe { S::returns_this_reference(&raw mut s) }); (*ref_).a_.postfix_inc(); assert!(((s.a_) == (2))); @@ -159,11 +165,11 @@ unsafe fn main_0() -> i32 { assert!(((s.a_) == (8))); (unsafe { S::bump_me(&raw mut s) }); assert!(((s.a_) == (9))); - object_unsafe!(d, D(3)); + object_unsafe!(d, D::constructor_1(3)); assert!(((d.a_) == (6))); let cr: *const S = (unsafe { S::cref(&raw const s) }); assert!((((*cr).a_) == (9))); - object_unsafe!(t, S::construct_1(0)); + object_unsafe!(t, S::constructor_1(0)); assert!( (unsafe { let _o: *const S = (&mut s as *mut S).cast_const(); @@ -173,7 +179,7 @@ unsafe fn main_0() -> i32 { assert!(!(unsafe { S::is(&raw const s, (&mut t as *mut S).cast_const(),) })); let mut p: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - S::construct_1(__p, 1); + S::constructor_1(__p, 1); __p }; let mut q: *mut S = (unsafe { S::returns_this_pointer(&raw mut (*p)) }); @@ -187,7 +193,7 @@ unsafe fn main_0() -> i32 { }; let mut h: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - S::construct_1(__p, 5); + S::constructor_1(__p, 5); __p }; (unsafe { S::destroy(&raw mut (*h)) }); @@ -208,21 +214,27 @@ unsafe fn main_0() -> i32 { }) as i32) == (false as i32)) ); - object_unsafe!(other, S::construct_1(22)); + object_unsafe!(other, S::constructor_1(22)); assert!( (((unsafe { S::copy_if_different(&raw mut s, (&mut other as *mut S),) }) as i32) == (true as i32)) ); assert!(((s.a_) == (other.a_))); assert!(((s.self__) == (other.self__))); - object_unsafe!(u, S::construct_2(1, (&mut s as *mut S))); + object_unsafe!( + u, + S::constructor_2(1, PointerUnsafe::bind((&mut s as *mut S))) + ); assert!(((u.self__) == (&mut s as *mut S))); let s_const: S = { - let mut __v: S = ::zero_init(); - S::construct_1(&raw mut __v, 100); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); + S::constructor_1(&raw mut __v, 100); __v }; - object_unsafe!(u1, S::construct_3(1, (&s_const as *const S))); + object_unsafe!( + u1, + S::constructor_3(1, PointerUnsafe::bind((&s_const as *const S))) + ); assert!((u1.self__).is_null()); return 0; } diff --git a/tests/unit/out/unsafe/typedef-anon-struct.rs b/tests/unit/out/unsafe/typedef-anon-struct.rs index 025c03922c..111a77f22b 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Outer_RunInfo { pub block_idx: i32, pub num_extra_zero_runs: i32, @@ -34,11 +36,14 @@ pub struct Outer_RunInfo { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Outer { pub runs: Vec, } -impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(this: *mut Self) { +impl Outer { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).runs).write(Vec::new()); } } @@ -49,7 +54,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(o, Outer); + object_unsafe!(o, Outer::constructor_1()); let mut info: Outer_RunInfo = ::default(); info.block_idx = 1; info.num_extra_zero_runs = 2; diff --git a/tests/unit/out/unsafe/unary_expr_or_type_trait.rs b/tests/unit/out/unsafe/unary_expr_or_type_trait.rs index 15e272bafb..be0622e922 100644 --- a/tests/unit/out/unsafe/unary_expr_or_type_trait.rs +++ b/tests/unit/out/unsafe/unary_expr_or_type_trait.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 ec913013c6..748a99e85b 100644 --- a/tests/unit/out/unsafe/unboxed_locals.rs +++ b/tests/unit/out/unsafe/unboxed_locals.rs @@ -22,7 +22,9 @@ pub unsafe fn inc_1(r: *mut i32) { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pair { pub first: i32, pub second: i32, @@ -68,7 +70,9 @@ pub unsafe trait Shape { ZeroInitializationUnsafe, DefaultInitializableUnsafe, CopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 4bd99e639c..ad4045ab72 100644 --- a/tests/unit/out/unsafe/unboxed_records.rs +++ b/tests/unit/out/unsafe/unboxed_records.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Inner { pub a: i32, pub b: i32, @@ -31,7 +33,9 @@ pub struct Inner { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Cookie { pub x: i32, pub data: *mut i32, @@ -40,7 +44,17 @@ pub struct Cookie { pub arr: [i32; 4], } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Counter { pub n: i32, } @@ -48,9 +62,7 @@ impl Counter { pub unsafe fn inc(this: *mut Self) { (*this).n.prefix_inc(); } -} -impl DefaultConstructibleUnsafe for Counter { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).n).write(0); } } @@ -121,7 +133,7 @@ unsafe fn main_0() -> i32 { let mut field_addr: Inner = Inner { a: 0, b: 0 }; (unsafe { set_0((&mut field_addr.b as *mut i32), 7) }); assert!(((field_addr.b) == (7))); - object_unsafe!(counter, Counter); + object_unsafe!(counter, Counter::constructor_1()); (unsafe { Counter::inc(&raw mut counter) }); assert!(((counter.n) == (1))); return 0; diff --git a/tests/unit/out/unsafe/unique_ptr.rs b/tests/unit/out/unsafe/unique_ptr.rs index 958c921601..45b54ebaa8 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -16,6 +16,9 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct SafePointer { pub ptr: Option>, } @@ -27,9 +30,7 @@ impl SafePointer { .map_or(::std::ptr::null_mut(), |v| v as *const i32 as *mut i32)) .prefix_inc(); } -} -impl DefaultConstructibleUnsafe for SafePointer { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).ptr).write(None); } } @@ -43,7 +44,9 @@ impl DefaultConstructibleUnsafe for SafePointer { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 6ee90dac3a..f8dd9749e8 100644 --- a/tests/unit/out/unsafe/unique_ptr_const_deref.rs +++ b/tests/unit/out/unsafe/unique_ptr_const_deref.rs @@ -16,11 +16,14 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Holder { pub val: Option>, } -impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(this: *mut Self) { +impl Holder { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).val).write(None); } } @@ -43,7 +46,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(h, Holder); + object_unsafe!(h, Holder::constructor_1()); { h.val = Some(Box::new(10)).take(); }; diff --git a/tests/unit/out/unsafe/unique_ptr_field_reset.rs b/tests/unit/out/unsafe/unique_ptr_field_reset.rs index 2c898407c7..794691a49b 100644 --- a/tests/unit/out/unsafe/unique_ptr_field_reset.rs +++ b/tests/unit/out/unsafe/unique_ptr_field_reset.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Data { pub v: i32, } @@ -30,6 +32,9 @@ pub struct Data { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Holder { pub data: Option>, pub n: i32, @@ -42,9 +47,7 @@ impl Holder { Some(Box::from_raw(p)) }; } -} -impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(None); (&raw mut (*this).n).write(0_i32); } @@ -67,7 +70,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(h, Holder); + object_unsafe!(h, Holder::constructor_1()); h.n = 1; let mut hp: *mut Holder = (&mut h as *mut Holder); { diff --git a/tests/unit/out/unsafe/unique_ptr_nested.rs b/tests/unit/out/unsafe/unique_ptr_nested.rs index 1d6e66ec66..a0dddc0a8d 100644 --- a/tests/unit/out/unsafe/unique_ptr_nested.rs +++ b/tests/unit/out/unsafe/unique_ptr_nested.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Inner { pub x: i32, pub y: i32, @@ -31,11 +33,14 @@ pub struct Inner { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Outer { pub inner: Option>, } -impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(this: *mut Self) { +impl Outer { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).inner).write(None); } } diff --git a/tests/unit/out/unsafe/unique_ptr_struct.rs b/tests/unit/out/unsafe/unique_ptr_struct.rs index 6fbf268dcf..78047726f7 100644 --- a/tests/unit/out/unsafe/unique_ptr_struct.rs +++ b/tests/unit/out/unsafe/unique_ptr_struct.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Point { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs index 3c13297f45..7011b782b9 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -9,7 +9,7 @@ use std::rc::Rc; pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); - object_unsafe!(guard, Guard_1(&mut ap)); + object_unsafe!(guard, Guard_1::constructor_1(&mut ap)); let mut total: i32 = 0; { let mut i: i32 = 0; @@ -28,17 +28,17 @@ pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, CopyableUnsafe, + ConversionsUnsafe, )] -#[cpp_from(*const VaArg , construct, mut_ptr)] +#[conversions(copy)] pub struct Guard_1 { pub ap: *mut *const VaArg, pub active: bool, } impl Guard_1 { - pub unsafe fn construct(this: *mut Self, val: *mut *const VaArg) { + pub unsafe fn constructor_1(this: *mut Self, val: *mut *const VaArg) { (&raw mut (*this).ap).write(val); (&raw mut (*this).active).write(true); } @@ -76,7 +76,9 @@ pub unsafe fn sum_ptr_2(mut n: i32, __args: Box<[VaArg]>) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] 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 9a5c15a49f..44560dac26 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S { pub x: i32, } @@ -34,12 +36,15 @@ pub unsafe fn copy_0(mut copy_vector: Vec) {} Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Foo { pub a: Vec, pub b: Vec, } -impl DefaultConstructibleUnsafe for Foo { - unsafe fn default_constructor(this: *mut Self) { +impl Foo { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).a).write(Vec::new()); (&raw mut (*this).b).write(Vec::new()); } @@ -51,17 +56,18 @@ impl DefaultConstructibleUnsafe for Foo { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct Wrapped { pub v: i32, } impl Wrapped { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } } @@ -183,10 +189,14 @@ unsafe fn main_0() -> i32 { let mut __tmp_9 = { src.end() }; let __off = __tmp_7.iter_distance(&UnsafeRandomAccessIterator::Vec(v2.as_mut_ptr())) as usize; - let mut __tmp = Vec::new(); + let mut __tmp: Vec = Vec::new(); let mut __it = (__tmp_8).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_9) { - __tmp.push((*__it.iter_deref())); + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } v2.splice(__off..__off, __tmp); @@ -418,7 +428,7 @@ unsafe fn main_0() -> i32 { ((((v10.len()) == (1_usize)) && ((v10[(0_usize)]) == (4))) && ((v11.len()) == (3_usize))) && ((v11[(2_usize)]) == (3)) ); - object_unsafe!(foo, Foo); + object_unsafe!(foo, Foo::constructor_1()); { let mut __tmp_15: i32 = 5; foo.a.push_moved(&mut __tmp_15) @@ -507,10 +517,14 @@ unsafe fn main_0() -> i32 { let mut __tmp_20 = { ints.as_mut_ptr().offset((3) as isize) }; let __off = __tmp_19.iter_distance(&UnsafeRandomAccessIterator::Vec(longs.as_mut_ptr())) as usize; - let mut __tmp = Vec::new(); + let mut __tmp: Vec = Vec::new(); let mut __it = ints.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { - __tmp.push(((*__it.iter_deref()) as i64)); + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } longs.splice(__off..__off, __tmp); @@ -528,10 +542,14 @@ unsafe fn main_0() -> i32 { let mut __tmp_23 = { more.end() }; let __off = __tmp_21.iter_distance(&UnsafeRandomAccessIterator::Vec(longs.as_mut_ptr())) as usize; - let mut __tmp = Vec::new(); + let mut __tmp: Vec = Vec::new(); let mut __it = (__tmp_22).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_23) { - __tmp.push(((*__it.iter_deref()) as i64)); + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } longs.splice(__off..__off, __tmp); @@ -545,10 +563,14 @@ unsafe fn main_0() -> i32 { let __off = __tmp_24 .iter_distance(&UnsafeRandomAccessIterator::Vec(doubles.as_mut_ptr())) as usize; - let mut __tmp = Vec::new(); + let mut __tmp: Vec = Vec::new(); let mut __it = ints.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_25) { - __tmp.push(((*__it.iter_deref()) as f64)); + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } doubles.splice(__off..__off, __tmp); @@ -562,10 +584,14 @@ unsafe fn main_0() -> i32 { let __off = __tmp_26 .iter_distance(&UnsafeRandomAccessIterator::Vec(wrapped.as_mut_ptr())) as usize; - let mut __tmp = Vec::new(); + let mut __tmp: Vec = Vec::new(); let mut __it = ints.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_27) { - __tmp.push(>::cpp_from(__it.iter_deref())); + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } wrapped.splice(__off..__off, __tmp); @@ -579,10 +605,14 @@ unsafe fn main_0() -> i32 { let mut __tmp_30 = { more.end() }; let __off = __tmp_28.iter_distance(&UnsafeRandomAccessIterator::Vec(same.as_mut_ptr())) as usize; - let mut __tmp = Vec::new(); + let mut __tmp: Vec = Vec::new(); let mut __it = (__tmp_29).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_30) { - __tmp.push((*__it.iter_deref())); + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } same.splice(__off..__off, __tmp); diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index 70957875b5..202b307dc7 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -13,17 +13,18 @@ use std::rc::Rc; VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct Degrees { pub value: i32, } impl Degrees { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).value).write(v); } } @@ -34,12 +35,13 @@ impl Degrees { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_into(i64, to_i64)] +#[conversions(copy, move)] +#[conversion_function(to_i64, LvalueRefUnsafe>, i64 )] pub struct Reading { pub raw_: i32, } @@ -58,10 +60,14 @@ unsafe fn main_0() -> i32 { let mut src: [u32; 3] = [1_u32, 2_u32, 3_u32]; let mut v1: Vec = { let mut __tmp_0 = { src.as_mut_ptr().offset((3) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_0) { - __v.push((*__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -73,10 +79,14 @@ unsafe fn main_0() -> i32 { ); let mut v2: Vec = { let mut __tmp_1 = { src.as_mut_ptr().offset((3) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { - __v.push(((*__it.iter_deref()) as u64)); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -88,10 +98,14 @@ unsafe fn main_0() -> i32 { ); let mut v3: Vec = { let mut __tmp_2 = { src.as_mut_ptr().offset((3) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) { - __v.push(((*__it.iter_deref()) as i32)); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -101,10 +115,14 @@ unsafe fn main_0() -> i32 { let src1: [u32; 3] = [1_u32, 2_u32, 3_u32]; let mut v4: Vec = { let mut __tmp_3 = { src1.as_ptr().add(src1.len()) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = src1.as_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { - __v.push((*__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -125,10 +143,14 @@ unsafe fn main_0() -> i32 { let mut len: usize = 5_usize; let mut v5: Vec = { let mut __tmp_5 = { start.offset((len) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = start; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { - __v.push((*__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -160,12 +182,16 @@ unsafe fn main_0() -> i32 { let mut v6: Vec<(i32, i32)> = { let mut __tmp_9 = { m.begin() }; let mut __tmp_10 = { m.end() }; - let mut __v = Vec::new(); + let mut __v: Vec<(i32, i32)> = Vec::new(); let mut __it = (__tmp_9).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) { - __v.push(<(i32, i32) as CppFromUnsafe<(i32, i32)>>::cpp_from( - __it.iter_deref(), - )); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind( + __it.iter_deref(), + ),), + ); __it.iter_inc(); } __v @@ -180,12 +206,16 @@ unsafe fn main_0() -> i32 { let mut __tmp_13 = { m.end() }; let __off = __tmp_11.iter_distance(&UnsafeRandomAccessIterator::Vec(v6.as_mut_ptr())) as usize; - let mut __tmp = Vec::new(); + let mut __tmp: Vec<(i32, i32)> = Vec::new(); let mut __it = (__tmp_12).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_13) { - __tmp.push(<(i32, i32) as CppFromUnsafe<(i32, i32)>>::cpp_from( - __it.iter_deref(), - )); + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::>::bind( + __it.iter_deref(), + ),), + ); __it.iter_inc(); } v6.splice(__off..__off, __tmp); @@ -198,10 +228,14 @@ unsafe fn main_0() -> i32 { let mut ints: [i32; 3] = [4, 5, 6]; let mut v7: Vec = { let mut __tmp_14 = { ints.as_mut_ptr().offset((3) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = ints.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_14) { - __v.push(>::cpp_from(__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -210,10 +244,14 @@ unsafe fn main_0() -> i32 { let mut readings: [Reading; 2] = [Reading { raw_: 4 }, Reading { raw_: 5 }]; let mut v8: Vec = { let mut __tmp_15 = { readings.as_mut_ptr().offset((2) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = readings.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_15) { - __v.push(>::cpp_from(__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v diff --git a/tests/unit/out/unsafe/vector_subscript_direct.rs b/tests/unit/out/unsafe/vector_subscript_direct.rs index 3811ac10a2..05d58cc823 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Point { pub x: i32, pub y: i32, @@ -39,12 +41,15 @@ impl Point { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Holder { pub values: Vec, pub points: Vec, } -impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(this: *mut Self) { +impl Holder { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); (&raw mut (*this).points).write(Vec::new()); } @@ -109,7 +114,7 @@ unsafe fn main_0() -> i32 { (*p) = 9; assert!(((v[(2_usize)]) == (9))); assert!(((unsafe { sum_ref_1(&v,) }) == (((((3) + (0)) + (9)) + (42)) + (5)))); - object_unsafe!(h, Holder); + object_unsafe!(h, Holder::constructor_1()); h.values.resize_with(2_usize, || 0_i32); h.values[(1_usize)] = 6; { diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index fce95b321f..1ba3b4e042 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct TestAllocator_int_ {} impl TestAllocator_int_ { pub unsafe fn allocate(this: *mut Self, mut n: usize) -> *mut i32 { @@ -45,7 +47,9 @@ impl TestAllocator_int_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct TestAllocator_double_ {} impl TestAllocator_double_ { pub unsafe fn allocate(this: *mut Self, mut n: usize) -> *mut f64 { @@ -315,10 +319,14 @@ unsafe fn main_0() -> i32 { let mut src: [u32; 3] = [1_u32, 2_u32, 3_u32]; let mut v9: Vec = { let mut __tmp_16 = { src.as_mut_ptr().offset((3) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_16) { - __v.push((*__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -330,10 +338,14 @@ unsafe fn main_0() -> i32 { ); let mut v10: Vec = { let mut __tmp_17 = { src.as_mut_ptr().offset((3) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_17) { - __v.push(((*__it.iter_deref()) as u64)); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -345,10 +357,14 @@ unsafe fn main_0() -> i32 { ); let mut v11: Vec = { let mut __tmp_18 = { src.as_mut_ptr().offset((3) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_18) { - __v.push(((*__it.iter_deref()) as i32)); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -358,10 +374,14 @@ unsafe fn main_0() -> i32 { let src1: [u32; 3] = [1_u32, 2_u32, 3_u32]; let mut v12: Vec = { let mut __tmp_19 = { src1.as_ptr().add(src1.len()) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = src1.as_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_19) { - __v.push((*__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -376,10 +396,14 @@ unsafe fn main_0() -> i32 { let mut len: usize = 5_usize; let mut v13: Vec = { let mut __tmp_20 = { start.offset((len) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = start; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { - __v.push((*__it.iter_deref())); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v diff --git a/tests/unit/out/unsafe/void_cast.rs b/tests/unit/out/unsafe/void_cast.rs index a118dad1d3..73b2c93ee8 100644 --- a/tests/unit/out/unsafe/void_cast.rs +++ b/tests/unit/out/unsafe/void_cast.rs @@ -20,11 +20,14 @@ pub unsafe fn unused_param_0(mut x: i32) {} Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct NonTrivial { pub data: Vec, } -impl DefaultConstructibleUnsafe for NonTrivial { - unsafe fn default_constructor(this: *mut Self) { +impl NonTrivial { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(Vec::new()); } } @@ -46,7 +49,9 @@ pub unsafe fn bump_and_return_4() -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Holder { pub field: i32, } @@ -60,11 +65,14 @@ pub struct Holder { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct NonCopyable { pub value: Option>, } -impl DefaultConstructibleUnsafe for NonCopyable { - unsafe fn default_constructor(this: *mut Self) { +impl NonCopyable { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(None); } } @@ -118,7 +126,7 @@ unsafe fn main_0() -> i32 { let mut arr: [i32; 3] = [1, 2, 3]; let mut h: Holder = Holder { field: 17 }; let mut hp: *mut Holder = (&mut h as *mut Holder); - object_unsafe!(nt, NonTrivial); + object_unsafe!(nt, NonTrivial::constructor_1()); (unsafe { unused_ref_param_1(&nt) }); (unsafe { unused_ptr_param_2((&mut nt as *mut NonTrivial).cast_const()) }); let mut g: NonCopyable = NonCopyable {