diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 16b7aebe2e..eae697d31c 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -229,6 +229,9 @@ std::string Converter::GetTemplateArgumentAsString(const clang::TemplateArgument &arg) { switch (arg.getKind()) { case clang::TemplateArgument::Type: + if (IsReferenceToObject(arg.getAsType())) { + return GetReferenceMarkerAsString(arg.getAsType()); + } return GetUnboxedTypeAsString(arg.getAsType()); case clang::TemplateArgument::Integral: if (!arg.getIntegralType()->isBooleanType()) { @@ -1173,10 +1176,16 @@ void Converter::AddAssignmentTraits(const clang::CXXRecordDecl *decl) { StrCat(GetAssignmentTraitSignature(*trait)); PushBrace fn_brace(*this); // An argument by value is constructed from the source. - std::string arg = "src"; + clang::QualType source_type = ctx_.getCanonicalTagType(decl); + if (trait == &kCopyAssignable) { + source_type.addConst(); + } + auto arg = GetReferredObjectPointer( + "src", ctx_.getLValueReferenceType(source_type)); if (!param_type->isReferenceType()) { - StrCat(std::format("{}(__o, {}, {});", GetObjectMacro(), record_name, - trait == &kMoveAssignable ? "Moved(src)" : "src")); + StrCat(std::format("{}(__o, {}, {}::bind({}));", GetObjectMacro(), + record_name, + GetReferenceMarker(trait == &kMoveAssignable), arg)); arg = GetReturnSlotArg(GetPlacementReceiver("__o")); } StrCat(std::format("{}::{}({}, {});", GetUFCSName(method), @@ -1187,9 +1196,15 @@ void Converter::AddAssignmentTraits(const clang::CXXRecordDecl *decl) { std::string Converter::GetAssignmentTraitSignature(const RecordTrait &trait) const { - return std::format("unsafe fn {}(this: *mut Self, src: {} Self) -> *mut Self", - trait.method, - &trait == &kMoveAssignable ? "*mut" : "*const"); + return std::format("unsafe fn {}(this: *mut Self, src: {}) -> *mut Self", + trait.method, GetCopyOrMoveSourceType(trait)); +} + +std::string Converter::GetCopyOrMoveSourceType(const RecordTrait &trait) const { + if (&trait == &kMoveConstructible || &trait == &kMoveAssignable) { + return std::format("{}", GetReferenceMarker(true)); + } + return std::format("{}>", GetReferenceMarker(false)); } void Converter::ConvertTemplateInstantiatedCtors(clang::CXXRecordDecl *decl) { @@ -2744,14 +2759,14 @@ void Converter::EmitArgList(const CallInfo &info) { StrCat(GetReturnSlotArg(in_place_.receiver), token::kComma); } - // The move operator= is picked by a Moved source. + // The move operator= is picked by an rvalue reference source. auto *method = clang::dyn_cast_or_null( info.expr->getDirectCallee()); bool moved = method && GetRecordTrait(method) == &kMoveAssignable; for (unsigned i = 0; i < info.args.size(); i++) { const auto &ca = info.args[i]; if (moved) { - StrCat("Moved"); + StrCat(GetReferenceMarker(true), "::bind"); } PushParen moved_paren(*this, moved); switch (ca.kind) { @@ -2913,7 +2928,7 @@ void Converter::ConvertAssignCall(clang::CallExpr *expr, })); } if (GetRecordTrait(method) == &kMoveAssignable) { - src = std::format("Moved({})", src); + src = std::format("{}({})", GetReferenceMarker(true), src); } std::string dst; if (auto *member = clang::dyn_cast(expr)) { @@ -4458,6 +4473,12 @@ void Converter::SetUFCSReceiver(clang::Expr *base, bool is_arrow, void Converter::ConvertMemberExpr(clang::MemberExpr *expr) { if (auto mapped = GetMappedAsString(expr); !mapped.empty()) { + if (auto type = expr->getMemberDecl()->getType(); + IsReferenceToObject(type)) { + mapped = + std::format("({}.as_ptr() as {})", mapped, + ToString(ctx_.getPointerType(type->getPointeeType()))); + } if (RuleRegistry::ReturnsPointer(ctx_, expr) && !isAddrOf() && !Mapper::IsRefExpr(ctx_, expr)) { PushParen paren(*this); @@ -4934,8 +4955,9 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) { auto *trait = GetRecordTrait(ctor); bool from_source = trait == &kCopyConstructible || trait == &kMoveConstructible; - if (trait == &kMoveConstructible) { - args = std::format("Moved({})", args); + 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()) { @@ -4953,10 +4975,7 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) { return; } auto path = - from_source - ? std::format("{}::{}", GetCopyOrMoveTraitName(kConstructFrom), - kConstructFrom.method) - : std::format("{}::{}", GetConstructorPath(ctor), GetCtorName(ctor)); + std::format("{}::{}", GetConstructorPath(ctor), GetCtorName(ctor)); StrCat(std::format("{}({}{}{})", path, in_place ? in_place_.receiver : GetPlacementReceiver(), args.empty() ? "" : ", ", args)); @@ -5834,9 +5853,28 @@ void Converter::ConvertFunctionParameters(clang::FunctionDecl *decl) { if (UsesReturnSlot(decl->getReturnType())) { StrCat(GetReturnSlotParam(decl->getReturnType())); } + if (auto *source = GetCopyOrMoveSource(decl)) { + StrCat(GetNamedDeclAsString(source), token::kColon, + GetReferenceMarkerAsString(source->getType()), token::kComma); + return; + } ConvertParamList(DefinitionParameters(decl), decl->isVariadic()); } +void Converter::EmitFunctionPreamble(clang::FunctionDecl *decl) { + if (auto *source = GetCopyOrMoveSource(decl)) { + auto name = GetNamedDeclAsString(source); + StrCat(std::format("let {} = {};", name, + GetReferredObjectPointer(name, source->getType()))); + } +} + +std::string Converter::GetReferredObjectPointer(std::string_view reference, + clang::QualType type) { + return std::format("({}.as_ptr() as {})", reference, + ToString(ctx_.getPointerType(type->getPointeeType()))); +} + void Converter::ConvertParamList(llvm::ArrayRef params, bool is_variadic) { ScopedValue in_formals(in_function_formals_, true); @@ -7150,9 +7188,24 @@ std::string Converter::GetMappedAsString(clang::Expr *expr, clang::Expr **args, if (!effects.empty()) { result = std::format("{{ {} {} }}", effects, result); } + if (auto referred = RuleRegistry::GetReferenceReturnedByReference(expr); + !referred.isNull() && IsReferenceToObject(referred) && + tgt_ir->return_type.is_pointer()) { + result = CollapseReference(result, referred, place); + } return result; } +std::string Converter::CollapseReference(std::string_view result, + clang::QualType referred, + bool is_place) { + auto type = ToString(ctx_.getPointerType(referred->getPointeeType())); + if (is_place) { + return std::format("(*(({}).as_ptr() as {}))", result, type); + } + return std::format("((*({})).as_ptr() as {})", result, type); +} + bool Converter::UsedOnce(const TranslationRule::ExprRule &rule, unsigned n) { unsigned uses = 0; TranslationRule::AnyFragment(rule.body, [&](const auto &frag) { @@ -7215,6 +7268,33 @@ std::vector Converter::ArgsToEvaluateFirst( return first; } +bool Converter::IsReferenceToObject(clang::QualType type) const { + if (!type->isReferenceType()) { + return false; + } + auto pointee = type->getPointeeType(); + auto *record = pointee->getAsCXXRecordDecl(); + return !pointee->isFunctionType() && !pointee->isArrayType() && + !(record && IsAbstractUserClass(record)); +} + +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); +} + +const char *Converter::GetReferenceMarker(bool is_rvalue) const { + return is_rvalue ? "RvalueRefUnsafe" : "LvalueRefUnsafe"; +} + bool Converter::ReturnsPointerToArg(clang::Expr *) { return false; } std::string Converter::ConvertPointerToArg(clang::Expr *, std::string_view) { @@ -7278,6 +7358,13 @@ std::string Converter::ConvertIRFragment( value = std::format("({})", value); } borrows_ |= outer_borrows; + if (auto bound = + RuleRegistry::GetReferenceBoundToParam(ctx_, expr, arg_idx); + !bound.isNull() && IsReferenceToObject(bound)) { + value = std::format("{}::bind({})", + GetReferenceMarker(bound->isRValueReferenceType()), + value); + } result += value; } else if (std::get_if(&frag)) { assert(expr && "variadic arguments outside an expression rule"); diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index c180fceaf0..0f54173255 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -101,6 +101,16 @@ 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 std::string CollapseReference(std::string_view result, + clang::QualType referred, + bool is_place); + bool VisitRecoveryExpr(clang::RecoveryExpr *expr); bool VisitExprWithCleanups(clang::ExprWithCleanups *expr); bool VisitMaterializeTemporaryExpr(clang::MaterializeTemporaryExpr *expr); @@ -142,7 +152,10 @@ class Converter : public clang::RecursiveASTVisitor { virtual bool VisitFunctionDecl(clang::FunctionDecl *decl); - virtual void EmitFunctionPreamble(clang::FunctionDecl *) {} + virtual void EmitFunctionPreamble(clang::FunctionDecl *decl); + + virtual std::string GetReferredObjectPointer(std::string_view reference, + clang::QualType type); virtual void ConvertFunctionBody(clang::FunctionDecl *decl); @@ -1011,6 +1024,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual std::string GetAssignmentTraitSignature(const RecordTrait &trait) const; + std::string GetCopyOrMoveSourceType(const RecordTrait &trait) const; + virtual void AddDefaultTraitForUnion(const clang::RecordDecl *decl); clang::CXXConstructExpr * diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 1e1686901a..444884f2d5 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -896,6 +896,16 @@ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { return is_copy ? &kCopyAssignable : &kMoveAssignable; } +const clang::ParmVarDecl *GetCopyOrMoveSource(const clang::FunctionDecl *decl) { + auto *method = clang::dyn_cast(decl); + auto *trait = method ? GetRecordTrait(method) : nullptr; + if (trait != &kCopyConstructible && trait != &kMoveConstructible && + trait != &kCopyAssignable && trait != &kMoveAssignable) { + return nullptr; + } + return DefinitionParameters(decl)[0]; +} + bool IsDerivedCopyOrMove(const clang::CXXMethodDecl *method) { if (auto *ctor = clang::dyn_cast(method); ctor && ctor->isDefaultConstructor()) { diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 4a1feb55d1..f1e1851fbb 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -125,36 +125,39 @@ inline constexpr RecordTrait kDefaultConstructible{ "unsafe fn default_constructor(this: *mut Self)", "this"}}; inline constexpr RecordTrait kCopyConstructible{ "copy_constructor", - {"CopyConstructible", "fn copy_constructor(this: Ptr, _: Ptr)", + {"CopyConstructible", + "fn copy_constructor(this: Ptr, _: LvalueRef>)", "this.clone()"}, {"CopyConstructibleUnsafe", - "unsafe fn copy_constructor(this: *mut Self, _: *const Self)", "this"}}; + "unsafe fn copy_constructor(this: *mut Self, _: " + "LvalueRefUnsafe>)", + "this"}}; inline constexpr RecordTrait kMoveConstructible{ "move_constructor", - {"MoveConstructible", "fn move_constructor(this: Ptr, _: Ptr)", + {"MoveConstructible", + "fn move_constructor(this: Ptr, _: RvalueRef)", "this.clone()"}, {"MoveConstructibleUnsafe", - "unsafe fn move_constructor(this: *mut Self, _: *mut Self)", "this"}}; + "unsafe fn move_constructor(this: *mut Self, _: RvalueRefUnsafe)", + "this"}}; inline constexpr RecordTrait kCopyAssignable{ "copy_assign", {"CopyAssignable", - "fn copy_assign(this: Ptr, _: Ptr) -> Ptr", + "fn copy_assign(this: Ptr, _: LvalueRef>) -> Ptr", "this.clone()"}, {"CopyAssignableUnsafe", - "unsafe fn copy_assign(this: *mut Self, _: *const Self) -> *mut Self", + "unsafe fn copy_assign(this: *mut Self, _: LvalueRefUnsafe>) " + "-> *mut Self", "this"}}; inline constexpr RecordTrait kMoveAssignable{ "move_assign", {"MoveAssignable", - "fn move_assign(this: Ptr, _: Ptr) -> Ptr", + "fn move_assign(this: Ptr, _: RvalueRef) -> Ptr", "this.clone()"}, {"MoveAssignableUnsafe", - "unsafe fn move_assign(this: *mut Self, _: *mut Self) -> *mut Self", + "unsafe fn move_assign(this: *mut Self, _: RvalueRefUnsafe) -> " + "*mut Self", "this"}}; -// The construction from a source, which picks the copy or the move -// constructor from the type of the source. -inline constexpr RecordTrait kConstructFrom{ - "construct_from", {"ConstructFrom"}, {"ConstructFromUnsafe"}}; inline constexpr RecordTrait kSwappable{ "swap", {"Swappable", "fn swap(this: Ptr, _: Ptr)", "this.clone()"}, @@ -233,6 +236,8 @@ inline constexpr RecordTrait kMemberwise{ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method); +const clang::ParmVarDecl *GetCopyOrMoveSource(const clang::FunctionDecl *decl); + const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn); bool IsEqualityComparableTrait(const RecordTrait &trait); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index a00932712d..d11751a3e4 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -314,6 +314,15 @@ bool ConverterRefCount::VisitReferenceType(clang::ReferenceType *type) { return false; } +const char *ConverterRefCount::GetReferenceMarker(bool is_rvalue) const { + return is_rvalue ? "RvalueRef" : "LvalueRef"; +} + +std::string ConverterRefCount::CollapseReference(std::string_view result, + clang::QualType, bool) { + return std::format("{}.with(|__r| __r.as_pointer())", result); +} + std::string ConverterRefCount::ConvertFunctionPointerType( const clang::FunctionProtoType *proto) { PushConversionKind push(*this, ConversionKind::Unboxed); @@ -642,7 +651,7 @@ ConverterRefCount::GetComparisonArg(const clang::ParmVarDecl *param, if (IsTriviallyCopyable(decl)) { return std::format("{}.read()", value); } - return std::format("{{ {} {}::{}({}, {}.clone()); {} }}", + return std::format("{{ {} {}::{}({}, LvalueRef::bind({}.clone())); {} }}", CreatePlacementStorage(GetRecordName(decl)), GetCopyOrMoveTraitName(kCopyConstructible), kCopyConstructible.method, GetPlacementReceiver(), value, @@ -848,7 +857,14 @@ bool ConverterRefCount::VisitFieldDecl(clang::FieldDecl *decl) { return Converter::VisitFieldDecl(decl); } +std::string +ConverterRefCount::GetReferredObjectPointer(std::string_view reference, + clang::QualType) { + return std::format("{}.as_pointer()", reference); +} + void ConverterRefCount::EmitFunctionPreamble(clang::FunctionDecl *decl) { + Converter::EmitFunctionPreamble(decl); PushConversionKind push(*this, ConversionKind::FullRefCount); if (decl->isVariadic()) { StrCat("let __args: Value> = " @@ -1792,7 +1808,9 @@ bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) { if (known) { str = GetMappedAsString(expr); if (member->getType()->isReferenceType()) { - str = std::format("{}.borrow().clone()", str); + str = std::format("{}.borrow().{}()", str, + IsReferenceToObject(member->getType()) ? "as_pointer" + : "clone"); borrows_ = true; } } else if (clang::isa(member)) { @@ -3623,8 +3641,8 @@ std::string ConverterRefCount::ConvertObjectOperand(clang::Expr *expr, std::string ConverterRefCount::GetAssignmentTraitSignature(const RecordTrait &trait) const { - return std::format("fn {}(this: Ptr, src: Ptr) -> Ptr", - trait.method); + return std::format("fn {}(this: Ptr, src: {}) -> Ptr", + trait.method, GetCopyOrMoveSourceType(trait)); } const char *ConverterRefCount::GetConstructorSelf() const { diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 0b791f3fe4..2777cf53b2 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -29,6 +29,12 @@ class ConverterRefCount final : public Converter { bool VisitReferenceType(clang::ReferenceType *type) override; + const char *GetReferenceMarker(bool is_rvalue) const override; + + std::string CollapseReference(std::string_view result, + clang::QualType referred, + bool is_place) override; + bool VisitPointerType(clang::PointerType *type) override; std::string @@ -124,6 +130,9 @@ class ConverterRefCount final : public Converter { void EmitFunctionPreamble(clang::FunctionDecl *decl) override; + std::string GetReferredObjectPointer(std::string_view reference, + clang::QualType type) override; + bool VisitVarDecl(clang::VarDecl *decl) override; bool LazyStaticInit() const override { return false; } std::string ForceGlobalInit(const clang::VarDecl *decl) override; diff --git a/cpp2rust/converter/rules/registry.cpp b/cpp2rust/converter/rules/registry.cpp index 82dc77c55f..583961c19c 100644 --- a/cpp2rust/converter/rules/registry.cpp +++ b/cpp2rust/converter/rules/registry.cpp @@ -620,6 +620,31 @@ bool ReturnsReference(const clang::Expr *expr) { ->isReferenceType(); } +clang::QualType GetReferenceReturnedByReference(const clang::Expr *expr) { + if (ExprHasUserDefinedDecl(expr)) { + return {}; + } + auto match = findExpr(expr); + if (!match.rule_decl) { + return {}; + } + auto *function = match.rule_decl->decl->getAsFunction(); + if (!function || !function->getReturnType()->isReferenceType()) { + return {}; + } + auto pointee = function->getReturnType()->getPointeeType(); + auto *tmpl = function->getDescribedFunctionTemplate(); + if (!tmpl || !pointee->isDependentType()) { + return {}; + } + clang::MultiLevelTemplateArgumentList args(tmpl, match.args, /*Final=*/false); + clang::Sema::InstantiatingTemplate inst( + *sema_, expr->getBeginLoc(), const_cast(function)); + auto type = sema_->SubstType(pointee, args, expr->getBeginLoc(), + clang::DeclarationName()); + return !type.isNull() && type->isReferenceType() ? type : clang::QualType(); +} + static bool BindsGenericToReference(const TranslationRule::TypeInfo ¶m, const Matcher::Bindings &bindings) { auto n = param.generic; @@ -628,6 +653,20 @@ static bool BindsGenericToReference(const TranslationRule::TypeInfo ¶m, bindings[n - 1].getAsType()->isReferenceType(); } +clang::QualType GetReferenceBoundToParam(clang::ASTContext &ctx, + const clang::Expr *expr, + unsigned index) { + auto [rule, bindings] = Search(ctx, expr); + assert(rule && "expression must have a translation rule"); + if (index >= rule->params.size()) { + return {}; + } + auto ¶m = rule->params[index]; + return BindsGenericToReference(param, bindings) + ? bindings[param.generic - 1].getAsType() + : clang::QualType(); +} + bool ParamIsPointer(clang::ASTContext &ctx, const clang::Expr *expr, unsigned index) { auto [rule, bindings] = Search(ctx, expr); diff --git a/cpp2rust/converter/rules/registry.h b/cpp2rust/converter/rules/registry.h index adf78602c7..c035aa8da7 100644 --- a/cpp2rust/converter/rules/registry.h +++ b/cpp2rust/converter/rules/registry.h @@ -54,6 +54,8 @@ bool HasExprRule(const clang::FunctionDecl *decl); bool IsLibcPassthrough(clang::ASTContext &ctx, const clang::Expr *expr); bool ReturnsPointer(clang::ASTContext &ctx, const clang::Expr *expr); bool ReturnsReference(const clang::Expr *expr); + +clang::QualType GetReferenceReturnedByReference(const clang::Expr *expr); // The argument of expr, a call, that its rule returns a reference to, or to an // element of, which element is then set to. clang::Expr *GetReferencedArg(clang::ASTContext &ctx, const clang::Expr *expr, @@ -61,6 +63,10 @@ clang::Expr *GetReferencedArg(clang::ASTContext &ctx, const clang::Expr *expr, // The argument of expr, a call, that its rule returns a reference to, after // computing something else, e.g., the receiver of std::string::append. clang::Expr *GetReturnedArg(clang::ASTContext &ctx, const clang::Expr *expr); +clang::QualType GetReferenceBoundToParam(clang::ASTContext &ctx, + const clang::Expr *expr, + unsigned index); + bool ParamIsPointer(clang::ASTContext &ctx, const clang::Expr *expr, unsigned index); diff --git a/cpp2rust/converter/translation_rule.cpp b/cpp2rust/converter/translation_rule.cpp index 7ba5431a2a..5235253ff9 100644 --- a/cpp2rust/converter/translation_rule.cpp +++ b/cpp2rust/converter/translation_rule.cpp @@ -433,7 +433,7 @@ bool ExprRule::takesAddress(clang::ASTContext &ctx, const clang::Expr *expr, if (i >= params.size()) { return usesInit(); } - if (!params[i].is_pointer()) { + if (!RuleRegistry::ParamIsPointer(ctx, expr, i)) { return false; } if (arg->getType()->isPointerType()) { diff --git a/libcc2rs-macros/Cargo.toml b/libcc2rs-macros/Cargo.toml index 25ed02f400..dc55c02ecf 100644 --- a/libcc2rs-macros/Cargo.toml +++ b/libcc2rs-macros/Cargo.toml @@ -12,6 +12,7 @@ quote = "1" syn = { version = "2", features = ["full", "visit-mut", "extra-traits"] } [dev-dependencies] +libcc2rs = { path = "../libcc2rs" } # trybuild 1.0.123 passes --diagnostic-width to rustc, which cargo also passes # when it knows the width of the terminal, and rustc rejects it twice. trybuild = ">=1, <1.0.123" diff --git a/libcc2rs-macros/src/assign.rs b/libcc2rs-macros/src/assign.rs index a374c0b6f1..9c34278bf2 100644 --- a/libcc2rs-macros/src/assign.rs +++ b/libcc2rs-macros/src/assign.rs @@ -6,11 +6,16 @@ use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::{quote, quote_spanned}; use syn::{Expr, ExprAssign, UnOp, parse_macro_input}; -// The argument of Moved(x), the C++ std::move(x). +// The argument of RvalueRef(x), or of RvalueRefUnsafe(x) in the unsafe model, +// the C++ std::move(x). fn moved(expr: &Expr) -> Option<&Expr> { match expr { Expr::Call(call) if call.args.len() == 1 => match &*call.func { - Expr::Path(path) if path.path.is_ident("Moved") => call.args.first(), + Expr::Path(path) + if path.path.is_ident("RvalueRef") || path.path.is_ident("RvalueRefUnsafe") => + { + call.args.first() + } _ => None, }, _ => None, @@ -34,29 +39,37 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let src_name = quote_spanned!(Span::mixed_site() => __src); // The source is evaluated first, as the right operand of a C++ =. let expanded = if is_unsafe { - let src = match moved(&right) { - Some(object) => quote!(::libcc2rs::Moved(&raw mut #object)), - None => quote!(&raw const #right), + let assign = match moved(&right) { + Some(object) => quote! { + let #src_name = ::libcc2rs::RvalueRefUnsafe::bind(&raw mut #object); + ::libcc2rs::MoveAssignableUnsafe::move_assign(&raw mut #left, #src_name) + }, + None => quote! { + let #src_name = ::libcc2rs::LvalueRefUnsafe::bind(&raw const #right); + ::libcc2rs::CopyAssignableUnsafe::copy_assign(&raw mut #left, #src_name) + }, }; - quote! { - unsafe { - let #src_name = #src; - ::libcc2rs::AssignFromUnsafe::assign_from(&raw mut #left, #src_name) - } - } + quote!(unsafe { #assign }) } else { - let src = match moved(&right) { + let dst = object_ptr(&left); + match moved(&right) { Some(object) => { let ptr = object_ptr(object); - quote!(::libcc2rs::Moved(#ptr)) + quote! { + { + let #src_name = ::libcc2rs::RvalueRef::bind(#ptr); + ::libcc2rs::MoveAssignable::move_assign(#dst, #src_name) + } + } } - None => object_ptr(&right), - }; - let dst = object_ptr(&left); - quote! { - { - let #src_name = #src; - ::libcc2rs::AssignFrom::assign_from(#dst, #src_name) + None => { + let ptr = object_ptr(&right); + quote! { + { + let #src_name = ::libcc2rs::LvalueRef::bind(#ptr); + ::libcc2rs::CopyAssignable::copy_assign(#dst, #src_name) + } + } } } }; diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index 33d68ff76a..0b66dc0cd7 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -139,19 +139,24 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - }; if is_unsafe { let src_ty = if is_move { - quote!(*mut Self) + quote!(::libcc2rs::RvalueRefUnsafe) } else { - quote!(*const Self) + quote!(::libcc2rs::LvalueRefUnsafe<::libcc2rs::Const>) }; let body = if is_move { - quote!(unsafe { ::libcc2rs::#copy_trait::#copy_method(this, src) }) + quote!(unsafe { + ::libcc2rs::#copy_trait::#copy_method( + this, + ::libcc2rs::LvalueRefUnsafe::bind(src.as_ptr()), + ) + }) } else if is_assign { quote! { - unsafe { *this = (*src).clone() }; + unsafe { *this = (*src.as_const_ptr()).clone() }; this } } else { - quote!(unsafe { ::std::ptr::write(this, (*src).clone()) }) + quote!(unsafe { ::std::ptr::write(this, (*src.as_const_ptr()).clone()) }) }; let ret = if is_assign { quote!(-> *mut Self) @@ -171,15 +176,23 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - } else { quote!() }; + let src_ty = if is_move { + quote!(::libcc2rs::RvalueRef) + } else { + quote!(::libcc2rs::LvalueRef<::libcc2rs::Const>) + }; let body = if is_move { - quote!(::libcc2rs::#copy_trait::#copy_method(this, src)) + quote!(::libcc2rs::#copy_trait::#copy_method( + this, + ::libcc2rs::LvalueRef::bind(src.as_pointer()), + )) } else if is_assign { quote! { - this.write(src.with(::clone)); + this.write(src.as_pointer().with(::clone)); this.clone() } } else { - quote!(this.write(src.with(::clone));) + 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) { @@ -209,7 +222,7 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - }; quote! { impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause { - fn #method(this: ::libcc2rs::Ptr, src: ::libcc2rs::Ptr) #ret { + fn #method(this: ::libcc2rs::Ptr, src: #src_ty) #ret { #body } #copied @@ -356,10 +369,20 @@ fn impl_memberwise( }; let tr = quote!(::libcc2rs::#trait_name); if is_unsafe { - let (src_ty, src_field) = if is_move { - (quote!(*mut Self), quote!(&raw mut)) + let (src_ty, marker, object, src_field) = if is_move { + ( + quote!(::libcc2rs::RvalueRefUnsafe), + quote!(::libcc2rs::RvalueRefUnsafe), + quote!(as_ptr), + quote!(&raw mut), + ) } else { - (quote!(*const Self), quote!(&raw const)) + ( + quote!(::libcc2rs::LvalueRefUnsafe<::libcc2rs::Const>), + quote!(::libcc2rs::LvalueRefUnsafe), + quote!(as_const_ptr), + quote!(&raw const), + ) }; let (ret, tail) = if is_assign { (quote!(-> *mut Self), quote!(this)) @@ -369,12 +392,26 @@ fn impl_memberwise( return quote! { impl #impl_generics #tr for #name #ty_generics #where_clause { unsafe fn #method(this: *mut Self, src: #src_ty) #ret { - #(unsafe { #tr::#method(&raw mut (*this).#members, #src_field (*src).#members) };)* + let src = src.#object(); + #(unsafe { + #tr::#method(&raw mut (*this).#members, #marker::bind(#src_field (*src).#members)) + };)* #tail } } }; } + let (src_ty, marker) = if is_move { + ( + quote!(::libcc2rs::RvalueRef), + quote!(::libcc2rs::RvalueRef), + ) + } else { + ( + quote!(::libcc2rs::LvalueRef<::libcc2rs::Const>), + quote!(::libcc2rs::LvalueRef), + ) + }; let (ret, tail) = if is_assign { (quote!(-> ::libcc2rs::Ptr), quote!(this.clone())) } else { @@ -382,10 +419,11 @@ fn impl_memberwise( }; quote! { impl #impl_generics #tr for #name #ty_generics #where_clause { - fn #method(this: ::libcc2rs::Ptr, src: ::libcc2rs::Ptr) #ret { + fn #method(this: ::libcc2rs::Ptr, src: #src_ty) #ret { + let src = src.as_pointer(); #(#tr::#method( ::libcc2rs::field_ptr!(this, #members), - ::libcc2rs::field_ptr!(src, #members), + #marker::bind(::libcc2rs::field_ptr!(src, #members)), );)* #tail } diff --git a/libcc2rs-macros/src/lib.rs b/libcc2rs-macros/src/lib.rs index 6242e09e3c..1c2779d9a9 100644 --- a/libcc2rs-macros/src/lib.rs +++ b/libcc2rs-macros/src/lib.rs @@ -94,9 +94,9 @@ pub fn lambda_unsafe(input: TokenStream) -> TokenStream { } // assign!(a = b); // a = b; -// assign!(*p = Moved(b)); // *p = std::move(b); +// assign!(*p = RvalueRef(b)); // *p = std::move(b); // -// The C++ operator= of a class, picked by its source as AssignFrom does. Both +// The C++ operator= of a class, picked by its source. Both // operands are objects, written as in C++: a variable, or *p for the object // that the pointer p points to (in the unsafe model, any place). The source is // evaluated first. The result is the pointer that operator= returns. diff --git a/libcc2rs-macros/tests/ui/reference_binding.rs b/libcc2rs-macros/tests/ui/reference_binding.rs new file mode 100644 index 0000000000..2e7ca362f7 --- /dev/null +++ b/libcc2rs-macros/tests/ui/reference_binding.rs @@ -0,0 +1,48 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +use libcc2rs::{Const, LvalueRef, LvalueRefUnsafe, RvalueRef, RvalueRefUnsafe, Volatile}; + +fn lvalue_reference_drops_const(r: LvalueRef>) -> LvalueRef { + r.into() +} + +fn lvalue_reference_drops_volatile(r: LvalueRef>) -> LvalueRef { + r.into() +} + +fn lvalue_reference_drops_one_of_two(r: LvalueRef>>) -> LvalueRef> { + r.into() +} + +fn rvalue_reference_drops_const(r: RvalueRef>) -> RvalueRef { + r.into() +} + +fn rvalue_reference_binds_to_lvalue(r: LvalueRef) -> RvalueRef { + r.into() +} + +fn lvalue_reference_binds_to_rvalue(r: RvalueRef) -> LvalueRef { + r.into() +} + +fn volatile_lvalue_reference_binds_to_rvalue( + r: RvalueRef, +) -> LvalueRef>> { + r.into() +} + +fn unsafe_lvalue_reference_drops_const(r: LvalueRefUnsafe>) -> LvalueRefUnsafe { + r.into() +} + +fn unsafe_rvalue_reference_binds_to_lvalue(r: LvalueRefUnsafe) -> RvalueRefUnsafe { + r.into() +} + +fn unsafe_lvalue_reference_binds_to_rvalue(r: RvalueRefUnsafe) -> LvalueRefUnsafe { + r.into() +} + +fn main() {} diff --git a/libcc2rs-macros/tests/ui/reference_binding.stderr b/libcc2rs-macros/tests/ui/reference_binding.stderr new file mode 100644 index 0000000000..2199d97ce9 --- /dev/null +++ b/libcc2rs-macros/tests/ui/reference_binding.stderr @@ -0,0 +1,165 @@ +error[E0277]: the trait bound `LvalueRef: From>>` is not satisfied + --> tests/ui/reference_binding.rs:7:7 + | +7 | r.into() + | ^^^^ the trait `From>>` is not implemented for `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>` + +error[E0277]: the trait bound `LvalueRef: From>>` is not satisfied + --> tests/ui/reference_binding.rs:11:7 + | +11 | r.into() + | ^^^^ the trait `From>>` is not implemented for `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>` + +error[E0277]: the trait bound `LvalueRef>: From>>>` is not satisfied + --> tests/ui/reference_binding.rs:15:7 + | +15 | r.into() + | ^^^^ the trait `From>>>` is not implemented for `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>>` + +error[E0277]: the trait bound `RvalueRef: From>>` is not satisfied + --> tests/ui/reference_binding.rs:19:7 + | +19 | r.into() + | ^^^^ the trait `From>>` is not implemented for `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>` + +error[E0277]: the trait bound `RvalueRef: From>` is not satisfied + --> tests/ui/reference_binding.rs:23:7 + | +23 | r.into() + | ^^^^ the trait `From>` is not implemented for `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>` + +error[E0277]: the trait bound `LvalueRef: From>` is not satisfied + --> tests/ui/reference_binding.rs:27:7 + | +27 | r.into() + | ^^^^ the trait `From>` is not implemented for `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>` + +error[E0277]: the trait bound `LvalueRef>>: From>` is not satisfied + --> tests/ui/reference_binding.rs:33:7 + | +33 | r.into() + | ^^^^ the trait `From>` is not implemented for `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>>>` + +error[E0277]: the trait bound `LvalueRefUnsafe: From>>` is not satisfied + --> tests/ui/reference_binding.rs:37:7 + | +37 | r.into() + | ^^^^ the trait `From>>` is not implemented for `LvalueRefUnsafe` + | + = help: the following other types implement trait `From`: + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>>` + `LvalueRefUnsafe>>` implements `From>` + `LvalueRefUnsafe>>` implements `From>>` + = note: required for `LvalueRefUnsafe>` to implement `Into>` + +error[E0277]: the trait bound `RvalueRefUnsafe: From>` is not satisfied + --> tests/ui/reference_binding.rs:41:7 + | +41 | r.into() + | ^^^^ the trait `From>` is not implemented for `RvalueRefUnsafe` + | +help: the following other types implement trait `From` + --> $LIBCC2RS/src/reference.rs + | + | impl<$param> From<$from> for $to { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `RvalueRefUnsafe>` implements `From>` + | `RvalueRefUnsafe>` implements `From>` + | `RvalueRefUnsafe>>` implements `From>` + | `RvalueRefUnsafe>>` implements `From>>` +... + | / binds_unsafe!( + | | LvalueRefUnsafe => LvalueRefUnsafe>, + | | LvalueRefUnsafe => LvalueRefUnsafe>, + | | LvalueRefUnsafe => LvalueRefUnsafe>>, +... | + | | RvalueRefUnsafe> => RvalueRefUnsafe>>, + | | ); + | |_- in this macro invocation + = note: required for `LvalueRefUnsafe` to implement `Into>` + = note: this error originates in the macro `binds_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `LvalueRefUnsafe: From>` is not satisfied + --> tests/ui/reference_binding.rs:45:7 + | +45 | r.into() + | ^^^^ the trait `From>` is not implemented for `LvalueRefUnsafe` + | + = help: the following other types implement trait `From`: + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>>` + `LvalueRefUnsafe>>` implements `From>` + `LvalueRefUnsafe>>` implements `From>>` + = note: required for `RvalueRefUnsafe` to implement `Into>` diff --git a/libcc2rs/src/capture.rs b/libcc2rs/src/capture.rs index b1fcc4473d..205736033d 100644 --- a/libcc2rs/src/capture.rs +++ b/libcc2rs/src/capture.rs @@ -96,7 +96,7 @@ impl CopyLambda>> for &&&Capture<'_, Value>> { let dst: Value> = Rc::new(RefCell::new(FnPtr::zero_init())); CopyConstructible::copy_constructor( AsPointer::>::as_pointer(&dst), - AsPointer::>::as_pointer(self.0), + crate::LvalueRef::bind(AsPointer::>::as_pointer(self.0)), ); dst } @@ -128,7 +128,7 @@ impl CopyCtor> for &Capture< let dst: Value = Rc::new(RefCell::new(T::zero_init())); T::copy_constructor( AsPointer::::as_pointer(&dst), - AsPointer::::as_pointer(self.0), + crate::LvalueRef::bind(AsPointer::::as_pointer(self.0)), ); dst } @@ -153,7 +153,7 @@ impl MoveWithCtor> for &&Cap let dst: Value = Rc::new(RefCell::new(T::zero_init())); T::move_constructor( AsPointer::::as_pointer(&dst), - AsPointer::::as_pointer(self.0), + crate::RvalueRef::bind(AsPointer::::as_pointer(self.0)), ); dst } @@ -228,7 +228,10 @@ 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(), self.0); + CopyConstructibleUnsafe::copy_constructor( + dst.as_mut_ptr(), + crate::LvalueRefUnsafe::bind(self.0), + ); dst.assume_init() } } @@ -252,7 +255,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(), self.0); + T::copy_constructor(dst.as_mut_ptr(), crate::LvalueRefUnsafe::bind(self.0)); dst.assume_init() } } @@ -276,7 +279,7 @@ 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(), self.0); + T::move_constructor(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 308212102e..231b9f4bef 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -7,6 +7,7 @@ use crate::capture::{ use crate::fn_ptr::{FnPtr, FnSig}; use crate::initialization::ZeroInitialization; use crate::rc::{AsPointer, Ptr, Value}; +use crate::reference::{Const, LvalueRef, RvalueRef}; use crate::reinterpret::ByteRepr; use crate::void::AnyPtr; @@ -24,8 +25,8 @@ pub trait DefaultConstructible: Sized { } } -pub trait MoveConstructible: Sized { - fn move_constructor(this: Ptr, src: Ptr); +pub trait MoveConstructible: ByteRepr + Sized { + fn move_constructor(this: Ptr, src: RvalueRef); // 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 @@ -38,7 +39,7 @@ pub trait MoveConstructible: Sized { elems.push(Self::zero_init()); elems.len() - 1 }); - Self::move_constructor(v.decay().offset(i), src); + Self::move_constructor(v.decay().offset(i), RvalueRef::bind(src)); } } @@ -47,7 +48,7 @@ pub trait TriviallyMoveConstructible: MoveConstructible { } pub trait CopyConstructible: MoveConstructible { - fn copy_constructor(this: Ptr, src: Ptr); + fn copy_constructor(this: Ptr, src: LvalueRef>); // A copy of the value that src points to, made by the copy constructor, // which a type with Clone clones. @@ -69,7 +70,7 @@ pub trait CopyConstructible: MoveConstructible { elems.push(Self::zero_init()); elems.len() - 1 }); - Self::copy_constructor(v.decay().offset(i), src); + Self::copy_constructor(v.decay().offset(i), LvalueRef::bind(src)); } // A copy of the elements of the vector that src points to, made by the @@ -89,13 +90,13 @@ pub trait TriviallyCopyConstructible: CopyConstructible { } pub trait CopyAssignable: MoveAssignable { - fn copy_assign(this: Ptr, src: Ptr) -> Ptr; + fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr; } pub trait TriviallyCopyAssignable: CopyAssignable {} -pub trait MoveAssignable: Sized { - fn move_assign(this: Ptr, src: Ptr) -> Ptr; +pub trait MoveAssignable: ByteRepr + Sized { + fn move_assign(this: Ptr, src: RvalueRef) -> Ptr; } pub trait TriviallyMoveAssignable: MoveAssignable {} @@ -155,16 +156,16 @@ pub trait DefaultConstructibleUnsafe { } } -pub trait MoveConstructibleUnsafe { +pub trait MoveConstructibleUnsafe: Sized { /// # Safety /// `src` must point to a live value. - unsafe fn move_constructor(this: *mut Self, src: *mut Self); + unsafe fn move_constructor(this: *mut Self, src: crate::RvalueRefUnsafe); } pub trait CopyConstructibleUnsafe: MoveConstructibleUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn copy_constructor(this: *mut Self, src: *const Self); + unsafe fn copy_constructor(this: *mut Self, src: crate::LvalueRefUnsafe>); } pub trait TriviallyMoveConstructibleUnsafe: MoveConstructibleUnsafe { @@ -182,15 +183,18 @@ pub trait TriviallyCopyConstructibleUnsafe: CopyConstructibleUnsafe { pub trait CopyAssignableUnsafe: MoveAssignableUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self; + unsafe fn copy_assign( + this: *mut Self, + src: crate::LvalueRefUnsafe>, + ) -> *mut Self; } pub trait TriviallyCopyAssignableUnsafe: CopyAssignableUnsafe {} -pub trait MoveAssignableUnsafe { +pub trait MoveAssignableUnsafe: Sized { /// # Safety /// `src` must point to a live value. - unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self; + unsafe fn move_assign(this: *mut Self, src: crate::RvalueRefUnsafe) -> *mut Self; } pub trait TriviallyMoveAssignableUnsafe: MoveAssignableUnsafe {} @@ -246,8 +250,8 @@ macro_rules! impl_copy_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn copy_constructor(this: $crate::Ptr, src: $crate::Ptr) { - this.write(src.with(Self::clone)); + fn copy_constructor(this: $crate::Ptr, src: $crate::LvalueRef<$crate::Const>) { + this.write(src.as_pointer().with(Self::clone)); } fn copied(src: $crate::Ptr) -> Self { @@ -268,8 +272,8 @@ macro_rules! impl_copy_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn copy_assign(this: $crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { - this.write(src.with(Self::clone)); + fn copy_assign(this: $crate::Ptr, src: $crate::LvalueRef<$crate::Const>) -> $crate::Ptr { + this.write(src.as_pointer().with(Self::clone)); this.clone() } } @@ -278,7 +282,8 @@ macro_rules! impl_copy_by_clone { where $ty: Clone, { - unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + 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()) } } } @@ -287,7 +292,8 @@ macro_rules! impl_copy_by_clone { where $ty: Clone, { - unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, src: $crate::LvalueRefUnsafe<$crate::Const>) -> *mut Self { + let src = src.as_const_ptr(); unsafe { *this = (*src).clone() }; this } @@ -302,8 +308,8 @@ macro_rules! impl_move_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn move_constructor(this: $crate::Ptr, src: $crate::Ptr) { - this.write(src.with(Self::clone)); + 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) { @@ -316,8 +322,8 @@ macro_rules! impl_move_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn move_assign(this: $crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { - this.write(src.with(Self::clone)); + fn move_assign(this: $crate::Ptr, src: $crate::RvalueRef) -> $crate::Ptr { + this.write(src.as_pointer().with(Self::clone)); this.clone() } } @@ -326,7 +332,8 @@ macro_rules! impl_move_by_clone { where $ty: Clone, { - unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe fn move_constructor(this: *mut Self, src: $crate::RvalueRefUnsafe) { + let src = src.as_ptr(); unsafe { std::ptr::write(this, (*src).clone()) } } } @@ -335,7 +342,8 @@ macro_rules! impl_move_by_clone { where $ty: Clone, { - unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(this: *mut Self, src: $crate::RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); unsafe { *this = (*src).clone() }; this } @@ -455,8 +463,8 @@ macro_rules! impl_move_by_take { where $ty: Default + $crate::ByteRepr, { - fn move_constructor(this: $crate::Ptr, src: $crate::Ptr) { - let value = src.with_mut(std::mem::take); + fn move_constructor(this: $crate::Ptr, src: $crate::RvalueRef) { + let value = src.as_pointer().with_mut(std::mem::take); this.with_mut(|dst| *dst = value); } @@ -470,8 +478,8 @@ macro_rules! impl_move_by_take { where $ty: Default + $crate::ByteRepr, { - fn move_assign(this: $crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { - let value = src.with_mut(std::mem::take); + fn move_assign(this: $crate::Ptr, src: $crate::RvalueRef) -> $crate::Ptr { + let value = src.as_pointer().with_mut(std::mem::take); this.with_mut(|dst| *dst = value); this.clone() } @@ -481,7 +489,8 @@ macro_rules! impl_move_by_take { where $ty: Default, { - unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe fn move_constructor(this: *mut Self, src: $crate::RvalueRefUnsafe) { + let src = src.as_ptr(); unsafe { std::ptr::write(this, std::mem::take(&mut *src)) } } } @@ -490,7 +499,8 @@ macro_rules! impl_move_by_take { where $ty: Default, { - unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(this: *mut Self, src: $crate::RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); unsafe { *this = std::mem::take(&mut *src) }; this } @@ -656,6 +666,8 @@ impl_trivial_copy_move!( 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_by_clone!( (A, B)); impl_move_by_clone!( (A, B)); @@ -749,8 +761,8 @@ impl TriviallyDe } impl MoveConstructible for FnPtr { - fn move_constructor(this: Ptr, src: Ptr) { - let value = src.with(FnPtr::move_from); + fn move_constructor(this: Ptr, src: RvalueRef) { + let value = src.as_pointer().with(FnPtr::move_from); this.with_mut(|dst| *dst = value); } } @@ -762,8 +774,8 @@ impl TriviallyMoveConstructible for FnPtr { } impl CopyConstructible for FnPtr { - fn copy_constructor(this: Ptr, src: Ptr) { - let value = src.with(FnPtr::copy_from); + fn copy_constructor(this: Ptr, src: LvalueRef>) { + let value = src.as_pointer().with(FnPtr::copy_from); this.with_mut(|dst| *dst = value); } } @@ -775,7 +787,7 @@ impl TriviallyCopyConstructible for FnPtr { } impl MoveAssignable for FnPtr { - fn move_assign(this: Ptr, src: Ptr) -> Ptr { + fn move_assign(this: Ptr, src: RvalueRef) -> Ptr { ::move_constructor(this.clone(), src); this } @@ -784,7 +796,7 @@ impl MoveAssignable for FnPtr { impl TriviallyMoveAssignable for FnPtr {} impl CopyAssignable for FnPtr { - fn copy_assign(this: Ptr, src: Ptr) -> Ptr { + fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { ::copy_constructor(this.clone(), src); this } @@ -805,13 +817,15 @@ impl SwappableUnsafe for FnPtr { } impl MoveConstructibleUnsafe for FnPtr { - unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe fn move_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: *const Self) { + unsafe fn copy_constructor(this: *mut Self, src: crate::LvalueRefUnsafe>) { + let src = src.as_const_ptr(); unsafe { std::ptr::write(this, (*src).copy_from()) } } } @@ -829,14 +843,19 @@ impl TriviallyCopyConstructibleUnsafe for FnPtr { } impl MoveAssignableUnsafe for FnPtr { - unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(this: *mut Self, src: crate::RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); unsafe { *this = (*src).move_from() }; this } } impl CopyAssignableUnsafe for FnPtr { - unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe fn copy_assign( + this: *mut Self, + src: crate::LvalueRefUnsafe>, + ) -> *mut Self { + let src = src.as_const_ptr(); unsafe { *this = (*src).copy_from() }; this } @@ -873,8 +892,10 @@ fn assign_elems( } impl MoveConstructible for Box<[T]> { - fn move_constructor(this: Ptr, src: Ptr) { - construct_elems(&this, &src, T::move_constructor); + fn move_constructor(this: Ptr, src: RvalueRef) { + construct_elems(&this, &src.as_pointer(), |dst, src| { + T::move_constructor(dst, RvalueRef::bind(src)) + }); } } @@ -887,8 +908,10 @@ impl TriviallyMov } impl CopyConstructible for Box<[T]> { - fn copy_constructor(this: Ptr, src: Ptr) { - construct_elems(&this, &src, T::copy_constructor); + fn copy_constructor(this: Ptr, src: LvalueRef>) { + construct_elems(&this, &src.as_pointer(), |dst, src| { + T::copy_constructor(dst, LvalueRef::bind(src)) + }); } } @@ -901,16 +924,20 @@ impl TriviallyCop } impl MoveAssignable for Box<[T]> { - fn move_assign(this: Ptr, src: Ptr) -> Ptr { - assign_elems(&this, &src, T::move_assign) + fn move_assign(this: Ptr, src: RvalueRef) -> Ptr { + assign_elems(&this, &src.as_pointer(), |dst, src| { + T::move_assign(dst, RvalueRef::bind(src)) + }) } } impl TriviallyMoveAssignable for Box<[T]> {} impl CopyAssignable for Box<[T]> { - fn copy_assign(this: Ptr, src: Ptr) -> Ptr { - assign_elems(&this, &src, T::copy_assign) + fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { + assign_elems(&this, &src.as_pointer(), |dst, src| { + T::copy_assign(dst, LvalueRef::bind(src)) + }) } } @@ -937,21 +964,23 @@ impl SwappableUnsafe for [T; N] { } impl MoveConstructibleUnsafe for [T; N] { - unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe fn move_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), src.add(i)) } + unsafe { T::move_constructor(this.add(i), crate::RvalueRefUnsafe::bind(src.add(i))) } } } } impl CopyConstructibleUnsafe for [T; N] { - unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + unsafe fn copy_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), src.add(i)) } + unsafe { T::copy_constructor(this.add(i), crate::LvalueRefUnsafe::bind(src.add(i))) } } } } @@ -975,22 +1004,27 @@ impl TriviallyCopyConstruct } impl MoveAssignableUnsafe for [T; N] { - unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + 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), src.add(i)) }; + unsafe { T::move_assign(dst.add(i), crate::RvalueRefUnsafe::bind(src.add(i))) }; } this } } impl CopyAssignableUnsafe for [T; N] { - unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe fn copy_assign( + this: *mut Self, + src: crate::LvalueRefUnsafe>, + ) -> *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), src.add(i)) }; + unsafe { T::copy_assign(dst.add(i), crate::LvalueRefUnsafe::bind(src.add(i))) }; } this } diff --git a/libcc2rs/src/lib.rs b/libcc2rs/src/lib.rs index f6555fb360..db2b0cbc10 100644 --- a/libcc2rs/src/lib.rs +++ b/libcc2rs/src/lib.rs @@ -61,6 +61,9 @@ pub use constructor::{ mod cmp; pub use cmp::*; +mod reference; +pub use reference::*; + mod conversion; pub use conversion::{CppFrom, CppFromUnsafe}; @@ -89,7 +92,6 @@ pub mod __capture { } mod object; -pub use object::{AssignFrom, AssignFromUnsafe, ConstructFrom, ConstructFromUnsafe, Moved}; // Used by object! and object_unsafe!. #[doc(hidden)] pub mod __object { diff --git a/libcc2rs/src/object.rs b/libcc2rs/src/object.rs index fc0575a955..f5fc220642 100644 --- a/libcc2rs/src/object.rs +++ b/libcc2rs/src/object.rs @@ -7,8 +7,8 @@ // // object!(a, Buffer(4)); // Buffer a(4); // object!(a, Buffer::construct_2(4, 5)); // an overload of many -// object!(b, Buffer, a.as_pointer()); // Buffer b = a; -// object!(c, Buffer, Moved(b.as_pointer())); // Buffer c = std::move(b); +// object!(b, Buffer, LvalueRef::bind(a.as_pointer())); // Buffer b = a; +// object!(c, Buffer, RvalueRef::bind(b.as_pointer())); // Buffer c = std::move(b); // object!(d, Buffer); // Buffer d; // object!(e, Buffer, |e| make(Ptr::clone(e))); // Buffer e = make(); // @@ -16,12 +16,12 @@ // its storage (&Ptr). Assignment (libcc2rs-macros): // // assign!(d = a); // d = a; -// assign!(d = Moved(a)); // d = std::move(a); +// assign!(d = RvalueRef(a)); // d = std::move(a); // assign!(*p = a); // *p = a; // // object_unsafe! and assign_unsafe! are the same in the unsafe model, whose -// object sources are references or raw pointers (`&a`, `Moved(&mut a)`), and -// whose storage is &mut T. +// object sources are LvalueRefUnsafe::bind(&a) and RvalueRefUnsafe::bind(&mut a), +// and whose storage is &mut T. #![allow(private_bounds, clippy::missing_safety_doc)] @@ -31,113 +31,9 @@ use std::rc::Rc; use crate::capture::{ Destructible, DestructibleUnsafe, TriviallyDestructible, TriviallyDestructibleUnsafe, }; -use crate::constructor::{ - CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, - MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, -}; use crate::initialization::ZeroInitialization; use crate::rc::{AsPointer, Ptr, Value}; -// The C++ std::move of a source: construction and assignment from it use the -// move constructor and the move operator=. -pub struct Moved

(pub P); - -// Construction of *self from src, in the refcount model: copy from a Ptr, -// move from a Moved>. -pub trait ConstructFrom { - fn construct_from(self, src: S); -} - -impl ConstructFrom> for Ptr { - #[inline(always)] - fn construct_from(self, src: Ptr) { - T::copy_constructor(self, src) - } -} - -impl ConstructFrom>> for Ptr { - #[inline(always)] - fn construct_from(self, src: Moved>) { - T::move_constructor(self, src.0) - } -} - -// The C++ operator= of *self from src, in the refcount model. -pub trait AssignFrom: Sized { - fn assign_from(self, src: S) -> Self; -} - -impl AssignFrom> for Ptr { - #[inline(always)] - fn assign_from(self, src: Ptr) -> Ptr { - T::copy_assign(self, src) - } -} - -impl AssignFrom>> for Ptr { - #[inline(always)] - fn assign_from(self, src: Moved>) -> Ptr { - T::move_assign(self, src.0) - } -} - -// Construction of self from src, in the unsafe model: copy from a reference or -// a raw pointer, move from a Moved one. -pub trait ConstructFromUnsafe { - /// # Safety - /// `src` must point to a live value. - unsafe fn construct_from(this: *mut Self, src: S); -} - -// The C++ operator= of self from src, in the unsafe model. -pub trait AssignFromUnsafe { - /// # Safety - /// `src` must point to a live value. - unsafe fn assign_from(this: *mut Self, src: S) -> *mut Self; -} - -// The sources of the unsafe model: a reference or a raw pointer copies, and a -// Moved one moves. -macro_rules! unsafe_sources { - ($($src:ty),*) => {$( - impl<'a, T: CopyConstructibleUnsafe> ConstructFromUnsafe<$src> for T { - #[inline(always)] - unsafe fn construct_from(this: *mut Self, src: $src) { - unsafe { T::copy_constructor(this, src) } - } - } - - impl<'a, T: CopyAssignableUnsafe> AssignFromUnsafe<$src> for T { - #[inline(always)] - unsafe fn assign_from(this: *mut Self, src: $src) -> *mut T { - unsafe { T::copy_assign(this, src) } - } - } - )*}; -} - -unsafe_sources!(&'a T, &'a mut T, *const T, *mut T); - -macro_rules! unsafe_moved_sources { - ($($src:ty),*) => {$( - impl<'a, T: MoveConstructibleUnsafe> ConstructFromUnsafe> for T { - #[inline(always)] - unsafe fn construct_from(this: *mut Self, src: Moved<$src>) { - unsafe { T::move_constructor(this, src.0) } - } - } - - impl<'a, T: MoveAssignableUnsafe> AssignFromUnsafe> for T { - #[inline(always)] - unsafe fn assign_from(this: *mut Self, src: Moved<$src>) -> *mut T { - unsafe { T::move_assign(this, src.0) } - } - } - )*}; -} - -unsafe_moved_sources!(&'a mut T, *mut T); - // The pointer to an object of the assign! macro: a variable (Value) or a // reference (Ptr) to it. pub trait ObjectPtr { @@ -255,11 +151,19 @@ macro_rules! object { } $crate::object!(@guard $name); }; - ($name:ident, $ty:ty, $src:expr) => { + ($name:ident, $ty:ty, LvalueRef::bind($src:expr)) => { + let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); + $crate::CopyConstructible::copy_constructor( + $crate::AsPointer::<$ty>::as_pointer(&$name), + $crate::LvalueRef::bind($src), + ); + $crate::object!(@guard $name); + }; + ($name:ident, $ty:ty, RvalueRef::bind($src:expr)) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); - $crate::ConstructFrom::construct_from( + $crate::MoveConstructible::move_constructor( $crate::AsPointer::<$ty>::as_pointer(&$name), - $src, + $crate::RvalueRef::bind($src), ); $crate::object!(@guard $name); }; @@ -298,11 +202,25 @@ macro_rules! object_unsafe { } $crate::object_unsafe!(@guard $name); }; - ($name:ident, $ty:ty, $src:expr) => { + ($name:ident, $ty:ty, LvalueRefUnsafe::bind($src:expr)) => { + let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); + #[allow(unused_unsafe)] + unsafe { + $crate::CopyConstructibleUnsafe::copy_constructor( + &raw mut $name, + $crate::LvalueRefUnsafe::bind::<$ty>($src), + ) + }; + $crate::object_unsafe!(@guard $name); + }; + ($name:ident, $ty:ty, RvalueRefUnsafe::bind($src:expr)) => { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - $crate::ConstructFromUnsafe::construct_from(&raw mut $name, $src) + $crate::MoveConstructibleUnsafe::move_constructor( + &raw mut $name, + $crate::RvalueRefUnsafe::bind::<$ty>($src), + ) }; $crate::object_unsafe!(@guard $name); }; diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs new file mode 100644 index 0000000000..91cd69c53f --- /dev/null +++ b/libcc2rs/src/reference.rs @@ -0,0 +1,548 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +use std::fmt; +use std::marker::PhantomData; + +use crate::capture::{ + Destructible, DestructibleUnsafe, TriviallyDestructible, TriviallyDestructibleUnsafe, +}; +use crate::constructor::{ + CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, + MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, Swappable, + SwappableUnsafe, +}; +use crate::rc::Ptr; +use crate::reinterpret::ByteRepr; + +pub struct Const(PhantomData); + +pub struct Volatile(PhantomData); + +pub trait Cv { + type Object; +} + +impl Cv for T { + type Object = T; +} + +impl Cv for Const { + type Object = T::Object; +} + +impl Cv for Volatile { + type Object = T::Object; +} + +macro_rules! reference { + ($name:ident) => { + pub struct $name(Ptr); + + impl $name { + #[inline] + pub fn bind(ptr: Ptr) -> Self { + Self(ptr) + } + + #[inline] + pub fn as_pointer(&self) -> Ptr { + self.0.clone() + } + } + + // TODO: remove, with the copy of a pair by Clone (constructor.rs). + impl Clone for $name { + #[inline] + fn clone(&self) -> Self { + Self(self.0.clone()) + } + } + + impl fmt::Debug for $name { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } + } + + impl crate::ZeroInitialization for $name { + #[inline] + fn zero_init() -> Self { + Self(Ptr::null()) + } + } + + impl ByteRepr for $name + where + T::Object: ByteRepr, + { + #[inline] + fn byte_size() -> usize { + std::mem::size_of::() + } + fn to_bytes(&self, buf: &mut [u8]) { + self.0.to_bytes(buf) + } + fn from_bytes(buf: &[u8]) -> Self { + Self(Ptr::from_bytes(buf)) + } + } + + impl MoveConstructible for $name + where + T::Object: ByteRepr, + { + fn move_constructor(this: Ptr, src: RvalueRef) { + this.write(src.as_pointer().with(Self::clone)); + } + } + + impl CopyConstructible for $name + where + T::Object: ByteRepr, + { + fn copy_constructor(this: Ptr, src: LvalueRef>) { + this.write(src.as_pointer().with(Self::clone)); + } + } + + impl Destructible for $name + where + T::Object: ByteRepr, + { + fn destroy(_this: Ptr) {} + } + + impl TriviallyDestructible for $name where T::Object: ByteRepr {} + + impl Swappable for $name { + fn swap(this: Ptr, other: Ptr) { + T::swap(this.with(|r| r.0.clone()), other.with(|r| r.0.clone())); + } + } + + impl crate::WeaklyEqualityComparableWith for $name + where + T::Object: crate::WeaklyEqualityComparableWith + ByteRepr, + { + fn equal(this: Ptr, rhs: Ptr) -> bool { + ::equal( + this.with(|r| r.0.clone()), + rhs.with(|r| r.0.clone()), + ) + } + } + + impl crate::LessThanComparable for $name + where + T::Object: crate::LessThanComparable + ByteRepr, + { + fn less(this: Ptr, rhs: Ptr) -> bool { + ::less( + this.with(|r| r.0.clone()), + rhs.with(|r| r.0.clone()), + ) + } + } + }; +} + +reference!(LvalueRef); +reference!(RvalueRef); + +impl CopyAssignable for LvalueRef { + fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { + T::copy_assign( + this.with(|r| r.0.clone()), + LvalueRef::bind(src.as_pointer().with(|r| r.0.clone())), + ); + this.clone() + } +} + +impl MoveAssignable for LvalueRef { + fn move_assign(this: Ptr, src: RvalueRef) -> Ptr { + T::copy_assign( + this.with(|r| r.0.clone()), + LvalueRef::bind(src.as_pointer().with(|r| r.0.clone())), + ); + this.clone() + } +} + +impl CopyAssignable for RvalueRef { + fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { + T::copy_assign( + this.with(|r| r.0.clone()), + LvalueRef::bind(src.as_pointer().with(|r| r.0.clone())), + ); + this.clone() + } +} + +impl MoveAssignable for RvalueRef { + fn move_assign(this: Ptr, src: RvalueRef) -> Ptr { + T::move_assign( + this.with(|r| r.0.clone()), + RvalueRef::bind(src.as_pointer().with(|r| r.0.clone())), + ); + this.clone() + } +} + +macro_rules! reference_unsafe { + ($name:ident) => { + pub struct $name(*mut std::ffi::c_void, PhantomData); + + impl $name { + #[inline] + pub fn bind(ptr: *const U) -> Self { + Self(ptr.cast_mut().cast(), PhantomData) + } + + #[inline] + pub fn as_ptr(&self) -> *mut T { + self.0.cast() + } + } + + impl $name> { + #[inline] + pub fn as_const_ptr(&self) -> *const T { + self.0.cast() + } + } + + impl Clone for $name { + #[inline] + fn clone(&self) -> Self { + *self + } + } + + impl Copy for $name {} + + impl Default for $name { + #[inline] + fn default() -> 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) { + let src = src.as_ptr(); + unsafe { std::ptr::write(this, *src) } + } + } + + impl CopyConstructibleUnsafe for $name { + unsafe fn copy_constructor(this: *mut Self, src: LvalueRefUnsafe>) { + let src = src.as_const_ptr(); + unsafe { std::ptr::write(this, *src) } + } + } + + impl DestructibleUnsafe for $name { + unsafe fn destroy(_this: *mut Self) {} + } + + impl TriviallyDestructibleUnsafe for $name {} + + impl SwappableUnsafe for $name { + unsafe fn swap(this: *mut Self, other: *mut Self) { + unsafe { T::swap((*this).as_ptr().cast::(), (*other).as_ptr().cast::()) } + } + } + + impl crate::WeaklyEqualityComparableWithUnsafe + for $name + { + unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { + unsafe { T::equal((*this).as_ptr().cast::(), (*rhs).as_ptr().cast::()) } + } + } + + impl crate::WeaklyEqualityComparableWithUnsafe + for $name> + { + unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { + unsafe { T::equal((*this).as_ptr().cast::(), (*rhs).as_ptr().cast::()) } + } + } + + impl crate::LessThanComparableUnsafe for $name { + unsafe fn less(this: *const Self, rhs: *const Self) -> bool { + unsafe { T::less((*this).as_ptr().cast::(), (*rhs).as_ptr().cast::()) } + } + } + + impl crate::LessThanComparableUnsafe + for $name> + { + unsafe fn less(this: *const Self, rhs: *const Self) -> bool { + unsafe { T::less((*this).as_ptr().cast::(), (*rhs).as_ptr().cast::()) } + } + } + }; +} + +reference_unsafe!(LvalueRefUnsafe); +reference_unsafe!(RvalueRefUnsafe); + +impl CopyAssignableUnsafe for LvalueRefUnsafe { + unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { + let src = src.as_const_ptr(); + unsafe { + T::copy_assign( + (*this).as_ptr().cast::(), + LvalueRefUnsafe::bind((*src).as_ptr().cast::()), + ) + }; + this + } +} + +impl MoveAssignableUnsafe for LvalueRefUnsafe { + unsafe fn move_assign(this: *mut Self, src: RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); + unsafe { + T::copy_assign( + (*this).as_ptr().cast::(), + LvalueRefUnsafe::bind((*src).as_ptr().cast::()), + ) + }; + this + } +} + +impl CopyAssignableUnsafe for RvalueRefUnsafe { + unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { + let src = src.as_const_ptr(); + unsafe { + T::copy_assign( + (*this).as_ptr().cast::(), + LvalueRefUnsafe::bind((*src).as_ptr().cast::()), + ) + }; + this + } +} + +impl MoveAssignableUnsafe for RvalueRefUnsafe { + unsafe fn move_assign(this: *mut Self, src: RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); + unsafe { + T::move_assign( + (*this).as_ptr().cast::(), + RvalueRefUnsafe::bind((*src).as_ptr().cast::()), + ) + }; + this + } +} + +macro_rules! binds { + ($(<$param:ident $(: $bound:path)?> $from:ty => $to:ty),* $(,)?) => {$( + impl<$param $(: $bound)?> From<$from> for $to { + #[inline] + fn from(r: $from) -> Self { + Self(r.0) + } + } + )*}; +} + +macro_rules! binds_unsafe { + ($(<$param:ident> $from:ty => $to:ty),* $(,)?) => {$( + impl<$param> From<$from> for $to { + #[inline] + fn from(r: $from) -> Self { + Self(r.0, PhantomData) + } + } + )*}; +} + +binds!( + LvalueRef => LvalueRef>, + LvalueRef => LvalueRef>, + LvalueRef => LvalueRef>>, + LvalueRef> => LvalueRef>>, + LvalueRef> => LvalueRef>>, + RvalueRef => LvalueRef>, + RvalueRef> => LvalueRef>, + RvalueRef => RvalueRef>, + RvalueRef => RvalueRef>, + RvalueRef => RvalueRef>>, + RvalueRef> => RvalueRef>>, + RvalueRef> => RvalueRef>>, +); + +binds_unsafe!( + LvalueRefUnsafe => LvalueRefUnsafe>, + LvalueRefUnsafe => LvalueRefUnsafe>, + LvalueRefUnsafe => LvalueRefUnsafe>>, + LvalueRefUnsafe> => LvalueRefUnsafe>>, + RvalueRefUnsafe => LvalueRefUnsafe>, + RvalueRefUnsafe> => LvalueRefUnsafe>, + RvalueRefUnsafe => RvalueRefUnsafe>, + RvalueRefUnsafe => RvalueRefUnsafe>, + RvalueRefUnsafe => RvalueRefUnsafe>>, + RvalueRefUnsafe> => RvalueRefUnsafe>>, +); + +pub trait AddLvalueReference { + type Type; +} + +pub trait AddRvalueReference { + type Type; +} + +impl AddLvalueReference for LvalueRef { + type Type = LvalueRef; +} + +impl AddLvalueReference for RvalueRef { + type Type = LvalueRef; +} + +impl AddRvalueReference for LvalueRef { + type Type = LvalueRef; +} + +impl AddRvalueReference for RvalueRef { + type Type = RvalueRef; +} + +impl AddLvalueReference for LvalueRefUnsafe { + type Type = LvalueRefUnsafe; +} + +impl AddLvalueReference for RvalueRefUnsafe { + type Type = LvalueRefUnsafe; +} + +impl AddRvalueReference for LvalueRefUnsafe { + type Type = LvalueRefUnsafe; +} + +impl AddRvalueReference for RvalueRefUnsafe { + type Type = RvalueRefUnsafe; +} + +#[cfg(test)] +mod tests { + use std::cell::RefCell; + use std::rc::Rc; + + use super::*; + use crate::rc::{AsPointer, Value}; + + fn object(value: i32) -> Value { + Rc::new(RefCell::new(value)) + } + + #[test] + fn lvalue_reference_binds_as_more_cv_qualified() { + let x = object(1); + let r = LvalueRef::::bind(x.as_pointer()); + let to_const: LvalueRef> = r.clone().into(); + let to_volatile: LvalueRef> = r.clone().into(); + let to_const_volatile: LvalueRef>> = r.clone().into(); + let from_const: LvalueRef>> = to_const.clone().into(); + let from_volatile: LvalueRef>> = to_volatile.clone().into(); + r.as_pointer().write(5); + for bound in [ + to_const.as_pointer(), + to_volatile.as_pointer(), + to_const_volatile.as_pointer(), + from_const.as_pointer(), + from_volatile.as_pointer(), + ] { + assert!(bound == x.as_pointer()); + assert_eq!(bound.with(|v| *v), 5); + } + } + + #[test] + fn rvalue_binds_to_const_lvalue_reference() { + let x = object(1); + let r = RvalueRef::::bind(x.as_pointer()); + let to_const: LvalueRef> = r.clone().into(); + let from_const: LvalueRef> = RvalueRef::>::from(r.clone()).into(); + assert!(to_const.as_pointer() == x.as_pointer()); + assert!(from_const.as_pointer() == x.as_pointer()); + } + + #[test] + fn rvalue_reference_binds_as_more_cv_qualified() { + let x = object(1); + let r = RvalueRef::::bind(x.as_pointer()); + let to_const: RvalueRef> = r.clone().into(); + let to_volatile: RvalueRef> = r.clone().into(); + let to_const_volatile: RvalueRef>> = r.clone().into(); + let from_const: RvalueRef>> = to_const.clone().into(); + let from_volatile: RvalueRef>> = to_volatile.clone().into(); + for bound in [ + to_const.as_pointer(), + to_volatile.as_pointer(), + to_const_volatile.as_pointer(), + from_const.as_pointer(), + from_volatile.as_pointer(), + ] { + assert!(bound == x.as_pointer()); + } + } + + #[test] + fn unsafe_references_bind_as_more_cv_qualified() { + let mut x = 1; + let address = &raw mut x; + let r = LvalueRefUnsafe::::bind(address.cast_const()); + let to_const: LvalueRefUnsafe> = r.into(); + let to_const_volatile: LvalueRefUnsafe>> = to_const.into(); + let moved = RvalueRefUnsafe::::bind(address.cast_const()); + let rvalue_to_const: LvalueRefUnsafe> = moved.into(); + unsafe { *r.as_ptr() = 5 }; + assert_eq!(to_const.as_const_ptr(), address.cast_const()); + assert_eq!(to_const_volatile.as_ptr().cast::(), address); + assert_eq!(rvalue_to_const.as_const_ptr(), address.cast_const()); + assert_eq!(unsafe { *to_const.as_const_ptr() }, 5); + } + + #[test] + fn reference_collapsing() { + let x = object(1); + let _: as AddLvalueReference>::Type = + LvalueRef::::bind(x.as_pointer()); + let _: as AddLvalueReference>::Type = + LvalueRef::::bind(x.as_pointer()); + let _: as AddRvalueReference>::Type = + LvalueRef::::bind(x.as_pointer()); + let _: as AddRvalueReference>::Type = + RvalueRef::::bind(x.as_pointer()); + let _: > as AddRvalueReference>::Type = + LvalueRef::>::bind(x.as_pointer()); + } + + #[test] + fn unsafe_reference_collapsing() { + let x = 1; + let _: as AddLvalueReference>::Type = + LvalueRefUnsafe::::bind(&raw const x); + let _: as AddLvalueReference>::Type = + LvalueRefUnsafe::::bind(&raw const x); + let _: as AddRvalueReference>::Type = + LvalueRefUnsafe::::bind(&raw const x); + let _: as AddRvalueReference>::Type = + RvalueRefUnsafe::::bind(&raw const x); + } +} diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index 3928183a5a..2d5d2559a3 100644 --- a/libcc2rs/src/swap.rs +++ b/libcc2rs/src/swap.rs @@ -50,7 +50,7 @@ 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), src.clone()); + T::move_constructor(pointer(&dst), crate::RvalueRef::bind(src.clone())); Rc::try_unwrap(dst).ok().unwrap().into_inner() } @@ -64,7 +64,7 @@ pub(crate) fn copy_constructed_in_storage, ) -> T { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - T::copy_constructor(pointer(&dst), src); + T::copy_constructor(pointer(&dst), crate::LvalueRef::bind(src)); Rc::try_unwrap(dst).ok().unwrap().into_inner() } @@ -73,7 +73,7 @@ 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(), src); + T::copy_constructor(dst.as_mut_ptr(), crate::LvalueRefUnsafe::bind(src)); dst.assume_init() } } @@ -81,7 +81,7 @@ 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(), src); + T::move_constructor(dst.as_mut_ptr(), crate::RvalueRefUnsafe::bind(src)); dst.assume_init() } } @@ -156,9 +156,9 @@ where { let storage: Value = Rc::new(RefCell::new(T::zero_init())); let tmp = AsPointer::::as_pointer(&storage); - T::move_constructor(tmp.clone(), this.clone()); - T::move_assign(this, other.clone()); - T::move_assign(other.clone(), tmp.clone()); + T::move_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 +170,12 @@ where { let mut tmp = MaybeUninit::::uninit(); unsafe { - MoveConstructibleUnsafe::move_constructor(tmp.as_mut_ptr(), this); - MoveAssignableUnsafe::move_assign(this, other); - MoveAssignableUnsafe::move_assign(other, tmp.as_mut_ptr()); + MoveConstructibleUnsafe::move_constructor( + tmp.as_mut_ptr(), + crate::RvalueRefUnsafe::bind(this), + ); + MoveAssignableUnsafe::move_assign(this, crate::RvalueRefUnsafe::bind(other)); + MoveAssignableUnsafe::move_assign(other, crate::RvalueRefUnsafe::bind(tmp.as_mut_ptr())); DestructibleUnsafe::destroy(tmp.as_mut_ptr()); } } diff --git a/rules/array/tgt_refcount.rs b/rules/array/tgt_refcount.rs index c1e3e02b7c..e2fe6e3b2c 100644 --- a/rules/array/tgt_refcount.rs +++ b/rules/array/tgt_refcount.rs @@ -36,7 +36,7 @@ fn f4( Rc::new(RefCell::new((0..T2).map(|_| T1::zero_init()).collect())); let __p: Ptr = __v.decay(); for __i in 0..T2 { - __p.offset(__i).construct_from(Moved(a0.offset(__i))); + MoveConstructible::move_constructor(__p.offset(__i), RvalueRef::bind(a0.offset(__i))); } Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -46,7 +46,7 @@ fn f5( a1: Ptr, ) -> Ptr> { for __i in 0..T2 { - assign!(*a0.decay().offset(__i) = Moved(*a1.offset(__i))); + assign!(*a0.decay().offset(__i) = RvalueRef(*a1.offset(__i))); } a0 } diff --git a/rules/array/tgt_unsafe.rs b/rules/array/tgt_unsafe.rs index 0c26310026..75deb1b919 100644 --- a/rules/array/tgt_unsafe.rs +++ b/rules/array/tgt_unsafe.rs @@ -48,7 +48,7 @@ unsafe fn f5<'a, T1: MoveAssignableUnsafe, const T2: usize>( a1: &mut [T1; T2], ) -> &'a mut [T1; T2] { for __i in 0..T2 { - assign_unsafe!(a0[__i] = Moved(a1[__i])); + assign_unsafe!(a0[__i] = RvalueRefUnsafe(a1[__i])); } a0 } diff --git a/rules/deque/tgt_unsafe.rs b/rules/deque/tgt_unsafe.rs index 7ef71bfc24..6cbe7d4254 100644 --- a/rules/deque/tgt_unsafe.rs +++ b/rules/deque/tgt_unsafe.rs @@ -59,7 +59,7 @@ unsafe fn f9(a0: &mut Vec) -> Vec { } unsafe fn f10<'a, T1: CopyConstructibleUnsafe>(a0: &'a mut Vec, a1: *const Vec) -> &'a mut Vec { - AssignFromUnsafe::assign_from(&raw mut *a0, a1); + 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 0d3a440f37..55a4ffcaed 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -186,26 +186,26 @@ macro_rules! uninhabited_iterator { } impl crate::MoveConstructible for $name { - fn move_constructor(_: Ptr, src: Ptr) { - src.with(|it| it.never()) + fn move_constructor(_: Ptr, src: crate::RvalueRef) { + src.as_pointer().with(|it| it.never()) } } impl crate::CopyConstructible for $name { - fn copy_constructor(_: Ptr, src: Ptr) { - src.with(|it| it.never()) + fn copy_constructor(_: Ptr, src: crate::LvalueRef>) { + src.as_pointer().with(|it| it.never()) } } impl crate::MoveConstructibleUnsafe for $name { - unsafe fn move_constructor(_: *mut Self, src: *mut Self) { - unsafe { (*src).never() } + unsafe fn move_constructor(_: *mut Self, src: crate::RvalueRefUnsafe) { + unsafe { (*src.as_ptr()).never() } } } impl crate::CopyConstructibleUnsafe for $name { - unsafe fn copy_constructor(_: *mut Self, src: *const Self) { - unsafe { (*src).never() } + unsafe fn copy_constructor(_: *mut Self, src: crate::LvalueRefUnsafe>) { + unsafe { (*src.as_const_ptr()).never() } } } }; diff --git a/rules/map/shim.rs b/rules/map/shim.rs index e3a1b1156e..9529c345e0 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -8,10 +8,10 @@ use std::ops::Bound; use std::rc::{Rc, Weak}; use crate::{ - AsPointer, BidirectionalIterator, ByteRepr, CopyAssignable, CopyAssignableUnsafe, - CopyConstructible, CopyConstructibleUnsafe, LessThanComparable, LessThanComparableUnsafe, Ptr, - UnsafeBidirectionalIterator, Value, ZeroInitialization, copy_constructed, - copy_constructed_unsafe, cpp_cmp, + AsPointer, BidirectionalIterator, ByteRepr, Const, CopyAssignable, CopyAssignableUnsafe, + CopyConstructible, CopyConstructibleUnsafe, LessThanComparable, LessThanComparableUnsafe, + LvalueRef, LvalueRefUnsafe, Ptr, UnsafeBidirectionalIterator, Value, ZeroInitialization, + copy_constructed, copy_constructed_unsafe, cpp_cmp, }; impl ByteRepr for BTreeMap {} @@ -115,8 +115,8 @@ where K: LessThanComparable + CopyConstructible + ZeroInitialization + 'static, V: CopyConstructible + ZeroInitialization + 'static, { - fn copy_constructor(this: Ptr, src: Ptr) { - this.write(Self::copied(src)); + fn copy_constructor(this: Ptr, src: LvalueRef>) { + this.write(Self::copied(src.as_pointer())); } fn copied(src: Ptr) -> Self { @@ -147,8 +147,8 @@ where K: LessThanComparable + CopyConstructible + ZeroInitialization + 'static, V: CopyConstructible + ZeroInitialization + 'static, { - fn copy_assign(this: Ptr, src: Ptr) -> Ptr { - let map = Self::copied(src); + fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { + let map = Self::copied(src.as_pointer()); this.write(map); this.clone() } @@ -459,7 +459,8 @@ impl CopyConstructibleUnsafe for UnsafeMap { - unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + unsafe fn copy_constructor(this: *mut Self, src: LvalueRefUnsafe>) { + let src = src.as_const_ptr(); unsafe { std::ptr::write(this, (*src).copied()) } } } @@ -467,7 +468,8 @@ impl CopyAssignableUnsafe for UnsafeMap { - unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { + let src = src.as_const_ptr(); unsafe { *this = (*src).copied() }; this } diff --git a/rules/map/tgt_unsafe.rs b/rules/map/tgt_unsafe.rs index f179b9c1ba..e3194d1e71 100644 --- a/rules/map/tgt_unsafe.rs +++ b/rules/map/tgt_unsafe.rs @@ -81,7 +81,7 @@ unsafe fn f25<'a, T1, T2>(a0: &'a mut UnsafeMap, a1: &mut UnsafeMa } unsafe fn f26<'a, T1: LessThanComparableUnsafe + CopyConstructibleUnsafe, T2: CopyConstructibleUnsafe>(a0: &'a mut UnsafeMap, a1: *const UnsafeMap) -> &'a mut UnsafeMap { - AssignFromUnsafe::assign_from(&raw mut *a0, a1); + CopyAssignableUnsafe::copy_assign(&raw mut *a0, LvalueRefUnsafe::bind(a1)); a0 } diff --git a/rules/pair/src_cxx20.cpp b/rules/pair/src_cxx20.cpp index ddd18d87ae..dafe7b0291 100644 --- a/rules/pair/src_cxx20.cpp +++ b/rules/pair/src_cxx20.cpp @@ -27,3 +27,8 @@ template bool f32(const std::pair &a0, const std::pair &a1) { return a0 >= a1; } + +template +bool f33(const std::pair &a0, const std::pair &a1) { + return a0 == a1; +} diff --git a/rules/pair/tgt_refcount.rs b/rules/pair/tgt_refcount.rs index c580b20db3..91712d0c89 100644 --- a/rules/pair/tgt_refcount.rs +++ b/rules/pair/tgt_refcount.rs @@ -49,12 +49,12 @@ fn f13( a0 } -fn f14<'a, T1: MoveAssignable, T2: MoveAssignable>( +fn f14<'a, T1: MoveAssignable + ByteRepr, T2: MoveAssignable + ByteRepr>( a0: &'a mut (Value, Value), a1: &mut (Value, Value), ) -> &'a mut (Value, Value) { - assign!(a0.0 = Moved(a1.0)); - assign!(a0.1 = Moved(a1.1)); + assign!(a0.0 = RvalueRef(a1.0)); + assign!(a0.1 = RvalueRef(a1.1)); a0 } @@ -153,3 +153,7 @@ fn f31(a0: 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()) +} diff --git a/rules/pair/tgt_unsafe.rs b/rules/pair/tgt_unsafe.rs index 919a8baa94..cac4001e53 100644 --- a/rules/pair/tgt_unsafe.rs +++ b/rules/pair/tgt_unsafe.rs @@ -39,8 +39,8 @@ unsafe fn f13<'a, T1: CopyAssignableUnsafe, T2: CopyAssignableUnsafe>(a0: &'a mu } 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 = Moved(a1.0)); - assign_unsafe!(a0.1 = Moved(a1.1)); + assign_unsafe!(a0.0 = RvalueRefUnsafe(a1.0)); + assign_unsafe!(a0.1 = RvalueRefUnsafe(a1.1)); a0 } @@ -117,3 +117,7 @@ unsafe fn f31(a0: (T 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) +} diff --git a/rules/unique_ptr/shim.rs b/rules/unique_ptr/shim.rs index bba738f7c5..52653abb93 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -3,7 +3,7 @@ use crate::{ ByteRepr, MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, - Ptr, Swappable, SwappableUnsafe, Value, + Ptr, RvalueRef, RvalueRefUnsafe, Swappable, SwappableUnsafe, Value, }; pub trait CppArray {} @@ -12,8 +12,8 @@ impl MoveConstructible for Option> where Self: ByteRepr, { - fn move_constructor(this: Ptr, src: Ptr) { - let value = src.with_mut(Option::take); + fn move_constructor(this: Ptr, src: RvalueRef) { + let value = src.as_pointer().with_mut(Option::take); this.with_mut(|dst| *dst = value); } } @@ -22,21 +22,23 @@ impl MoveAssignable for Option> where Self: ByteRepr, { - fn move_assign(this: Ptr, src: Ptr) -> Ptr { - let value = src.with_mut(Option::take); + fn move_assign(this: Ptr, src: RvalueRef) -> Ptr { + let value = src.as_pointer().with_mut(Option::take); this.with_mut(|dst| *dst = value); this.clone() } } impl MoveConstructibleUnsafe for Option> { - unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe fn move_constructor(this: *mut Self, src: RvalueRefUnsafe) { + let src = src.as_ptr(); unsafe { std::ptr::write(this, (*src).take()) } } } impl MoveAssignableUnsafe for Option> { - unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(this: *mut Self, src: RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); unsafe { *this = (*src).take() }; this } diff --git a/rules/vector/shim.rs b/rules/vector/shim.rs index f3047eaaf3..d37069e48b 100644 --- a/rules/vector/shim.rs +++ b/rules/vector/shim.rs @@ -2,9 +2,9 @@ // Distributed under the MIT license that can be found in the LICENSE file. use crate::{ - ArgRepr, ByteRepr, ConstructFromUnsafe, CopyAssignable, CopyAssignableUnsafe, - CopyConstructible, CopyConstructibleUnsafe, FnPtrArg, MoveConstructibleUnsafe, Moved, Ptr, - ZeroInitialization, copy_constructed_unsafe, record_from_repr, + ArgRepr, ByteRepr, Const, CopyAssignable, CopyAssignableUnsafe, CopyConstructible, + CopyConstructibleUnsafe, FnPtrArg, LvalueRef, LvalueRefUnsafe, MoveConstructibleUnsafe, Ptr, + RvalueRefUnsafe, ZeroInitialization, copy_constructed_unsafe, record_from_repr, }; impl ByteRepr for Vec {} @@ -23,8 +23,8 @@ crate::constructor::impl_move_by_take!( Vec); // A vector is copied by copying its elements, each with its copy constructor. impl CopyConstructible for Vec { - fn copy_constructor(this: Ptr, src: Ptr) { - this.write(T::copied_elems(&src)); + fn copy_constructor(this: Ptr, src: LvalueRef>) { + this.write(T::copied_elems(&src.as_pointer())); } fn copied(src: Ptr) -> Self { @@ -33,8 +33,8 @@ impl CopyConstructible for } impl CopyAssignable for Vec { - fn copy_assign(this: Ptr, src: Ptr) -> Ptr { - this.write(T::copied_elems(&src)); + fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { + this.write(T::copied_elems(&src.as_pointer())); this.clone() } } @@ -84,7 +84,7 @@ impl PushConstructedUnsafe for Vec { { unsafe { push_constructed(self, src.cast_mut(), |dst, src| { - ConstructFromUnsafe::construct_from(dst, src.cast_const()) + T::copy_constructor(dst, LvalueRefUnsafe::bind(src)) }) } } @@ -95,7 +95,7 @@ impl PushConstructedUnsafe for Vec { { unsafe { push_constructed(self, src, |dst, src| { - ConstructFromUnsafe::construct_from(dst, Moved(src)) + T::move_constructor(dst, RvalueRefUnsafe::bind(src)) }) } } @@ -111,13 +111,15 @@ unsafe fn copied_elems_unsafe(src: *const Vec) -> } impl CopyConstructibleUnsafe for Vec { - unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + unsafe fn copy_constructor(this: *mut Self, src: LvalueRefUnsafe>) { + let src = src.as_const_ptr(); unsafe { std::ptr::write(this, copied_elems_unsafe(src)) } } } impl CopyAssignableUnsafe for Vec { - unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { + let src = src.as_const_ptr(); unsafe { *this = copied_elems_unsafe(src) }; this } diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index 5fc277be99..b223a45645 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -222,7 +222,7 @@ fn f104(a0: Vec) -> UnsafeRandomAccessIterator { } unsafe fn f105<'a, T1: CopyConstructibleUnsafe>(a0: &'a mut Vec, a1: *const Vec) -> &'a mut Vec { - AssignFromUnsafe::assign_from(&raw mut *a0, a1); + CopyAssignableUnsafe::copy_assign(&raw mut *a0, LvalueRefUnsafe::bind(a1)); a0 } 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 f9bffd1c6b..5211876784 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 @@ -95,15 +95,15 @@ fn main_0() -> i32 { } pub fn shuffle_1(mut x: i32) -> i32 { object!(a, S(x)); - object!(b, S, Moved(a.as_pointer())); + object!(b, S, RvalueRef::bind(a.as_pointer())); assert!(({ (*a.borrow()).v.is_empty() })); object!(c, S(1)); - assign!(c = Moved(b)); + 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, Moved(t.as_pointer())); + object!(u, T, RvalueRef::bind(t.as_pointer())); object!(w, T); - assign!(w = Moved(u)); + assign!(w = RvalueRef(u)); assert!( ((({ T::size(t.as_pointer(),) }) == 0) && (({ T::size(u.as_pointer(),) }) == 0)) && (({ T::size(w.as_pointer(),) }) == 1) 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 e9e6c05d71..6c424bfeca 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 @@ -77,15 +77,15 @@ unsafe fn main_0() -> i32 { } pub unsafe fn shuffle_1(mut x: i32) -> i32 { object_unsafe!(a, S(x)); - object_unsafe!(b, S, Moved(&mut a)); + object_unsafe!(b, S, RvalueRefUnsafe::bind(&mut a)); assert!(a.v.is_empty()); object_unsafe!(c, S(1)); - assign_unsafe!(c = Moved(b)); + assign_unsafe!(c = RvalueRefUnsafe(b)); assert!(b.v.is_empty()); let mut t: T = T { v: Vec::from([1]) }; - object_unsafe!(u, T, Moved(&mut t)); + object_unsafe!(u, T, RvalueRefUnsafe::bind(&mut t)); object_unsafe!(w, T); - assign_unsafe!(w = Moved(u)); + assign_unsafe!(w = RvalueRefUnsafe(u)); assert!( (((unsafe { T::size(&raw const t,) }) == (0)) && ((unsafe { T::size(&raw const u,) }) == (0))) 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 ce8d8c60c4..00e752b7cf 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 @@ -90,9 +90,9 @@ fn main_0() -> i32 { assert!((({ S::get(s.as_pointer(),) }) == 4)); assert!((({ S::add(s.as_pointer(), 2,) }) == 6)); object!(m, M(2)); - object!(n, M, Moved(m.as_pointer())); + object!(n, M, RvalueRef::bind(m.as_pointer())); assert!(({ (*n.borrow()).v } == 2)); - object!(c, M, n.as_pointer()); + object!(c, M, LvalueRef::bind(n.as_pointer())); assert!(({ (*c.borrow()).v } == 3)); assert!((({ move_m_1(5,) }) == 5)); object!(derived, Derived(3)); @@ -117,12 +117,14 @@ impl M { } } impl MoveConstructible for M { - fn move_constructor(this: Ptr, _a0: Ptr) { + fn move_constructor(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: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 1)); } } @@ -151,7 +153,7 @@ impl S { impl M {} pub fn move_m_1(mut x: i32) -> i32 { object!(m, M(x)); - object!(n, M, Moved(m.as_pointer())); + object!(n, M, RvalueRef::bind(m.as_pointer())); return { (*n.borrow()).v }; } impl Derived {} 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 b8cec259eb..059056900a 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 @@ -81,9 +81,9 @@ unsafe fn main_0() -> i32 { 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, Moved(&mut m)); + object_unsafe!(n, M, RvalueRefUnsafe::bind(&mut m)); assert!(((n.v) == (2))); - object_unsafe!(c, M, &n); + object_unsafe!(c, M, LvalueRefUnsafe::bind(&n)); assert!(((c.v) == (3))); assert!(((unsafe { move_m_1(5,) }) == (5))); object_unsafe!(derived, Derived(3)); @@ -108,12 +108,14 @@ impl M { } } impl MoveConstructibleUnsafe for M { - unsafe fn move_constructor(this: *mut Self, _a0: *mut M) { + unsafe fn move_constructor(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: *const M) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const M); (&raw mut (*this).v).write((((*o).v) + (1))); } } @@ -140,7 +142,7 @@ impl S { impl M {} pub unsafe fn move_m_1(mut x: i32) -> i32 { object_unsafe!(m, M(x)); - object_unsafe!(n, M, Moved(&mut m)); + object_unsafe!(n, M, RvalueRefUnsafe::bind(&mut m)); return n.v; } impl Derived {} 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 79458eb9a7..efa08bb605 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 @@ -67,7 +67,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index eac9cfd4f8..9d5edbf4fc 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 @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(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(); } 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 4c20fca662..f5e3f4f2bc 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 @@ -67,7 +67,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index f7bd50ec67..71eb9129c1 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 @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(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(); } 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 ff95817e92..42f9c61e41 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 @@ -67,7 +67,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index 27a7a19458..e40f13ae30 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 @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(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(); } 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 5cfa74c365..318037e78f 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 @@ -67,7 +67,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs index 5b95a4faa2..afc2b03b66 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 @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(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(); } 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 cc25f1572b..cfbfc17551 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 @@ -67,7 +67,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index 947b8ea2a9..890dc010a4 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 @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(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(); } 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 0e2f2cdacd..0b2af40577 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 @@ -67,7 +67,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs index e64c52a6e7..f0ccef5c69 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 @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(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(); } 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 38f3a11bae..1881620397 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 @@ -67,7 +67,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index 8d40bf22f8..93cd43ae0b 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 @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(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(); } 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 1099fd29ae..302b248269 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 @@ -67,7 +67,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } 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 4b2bbc17d3..5d170897e2 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 @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(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(); } diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index f98c669f4f..2b4fecaf95 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -38,7 +38,8 @@ impl HasConstexprCtor { } } impl CopyConstructible for HasConstexprCtor { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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(); } @@ -104,7 +105,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -300,7 +302,7 @@ pub fn test_14() { let r: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), (r).clone()); + CopyConstructible::copy_constructor(__v.as_pointer(), LvalueRef::bind((r).clone())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -337,12 +339,15 @@ pub fn test_16() { let k: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), k.as_pointer()); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind(k.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || -> i32 { - object!(c, HasConstexprCtor, k.as_pointer()); + object!(c, HasConstexprCtor, LvalueRef::bind(k.as_pointer())); return { (*c.borrow()).m }; } ))); @@ -394,8 +399,9 @@ impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember { fn copy_constructor( this: Ptr, - o: Ptr, + o: LvalueRef>, ) { + let o = o.as_pointer(); field!(this, value).write(o.with(|__s| __s.value)); field!(this, scratch).write(o.with(|__s| __s.scratch)); (*copies_18.with(Value::clone).borrow_mut()).prefix_inc(); @@ -411,7 +417,10 @@ pub fn test_19() { Rc::new(RefCell::new( ::zero_init(), )); - ConstructFrom::construct_from(__v.as_pointer(), k.as_pointer()); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind(k.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -856,14 +865,14 @@ impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestruct } } impl CopyConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn copy_constructor(this: Ptr, _: Ptr) { + fn copy_constructor(this: Ptr, _: LvalueRef>) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } impl CopyAssignable for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn copy_assign(this: Ptr, _: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _: LvalueRef>) -> Ptr { unreachable!( "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign 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 f1bd018218..a923657ccf 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -33,7 +33,8 @@ impl HasConstexprCtor { } } impl CopyConstructibleUnsafe for HasConstexprCtor { - unsafe fn copy_constructor(this: *mut Self, o: *const HasConstexprCtor) { + unsafe fn copy_constructor(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(); } @@ -80,7 +81,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(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(); } @@ -257,7 +259,7 @@ pub unsafe fn test_14() { { let r: LifetimeTracked = { let mut __v: LifetimeTracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, r); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(r)); __v }; }, @@ -294,12 +296,12 @@ pub unsafe fn test_16() { { let k: HasConstexprCtor = { let mut __v: HasConstexprCtor = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &k); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&k)); __v }; }, || -> i32 { - object_unsafe!(c, HasConstexprCtor, &k); + object_unsafe!(c, HasConstexprCtor, LvalueRefUnsafe::bind(&k)); return c.m; } ); @@ -344,8 +346,9 @@ impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMember { unsafe fn copy_constructor( this: *mut Self, - o: *const p5_2_mutable_subobject_is_odr_used_HasMutableMember, + o: LvalueRefUnsafe>, ) { + let o = (o.as_ptr() as *const p5_2_mutable_subobject_is_odr_used_HasMutableMember); (&raw mut (*this).value).write((*o).value); (&raw mut (*this).scratch).write((*o).scratch); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)).prefix_inc(); @@ -358,7 +361,7 @@ pub unsafe fn test_19() { let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = { let mut __v: p5_2_mutable_subobject_is_odr_used_HasMutableMember = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &k); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&k)); __v }; }, @@ -766,14 +769,14 @@ impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDe } } impl CopyConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn copy_constructor(this: *mut Self, _: *const Self) { + unsafe fn copy_constructor(this: *mut Self, _: LvalueRefUnsafe>) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } impl CopyAssignableUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn copy_assign(this: *mut Self, _: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, _: LvalueRefUnsafe>) -> *mut Self { unreachable!( "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" ) 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 0b4938b1d8..206493ac95 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 @@ -37,7 +37,7 @@ pub fn pass_0( let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - ConstructFrom::construct_from(__v.as_pointer(), Moved(object.as_pointer())); + MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(object.as_pointer())); 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 6bdefc877d..5a52ddae70 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 @@ -31,7 +31,7 @@ pub unsafe fn pass_0( return { let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut object)); + MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(&mut object)); __v }; } diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref-p5-cv-qualification.cpp b/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref-p5-cv-qualification.cpp new file mode 100644 index 0000000000..845a473c26 --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref-p5-cv-qualification.cpp @@ -0,0 +1,45 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [dcl.init.ref]/5.1: a reference binds to an object that is less +// cv-qualified than the type it refers to, for const, volatile and both. +namespace p5_1_more_cv_qualified_reference { +void test() { + int x = 1; + const int &read_only = x; + volatile int &unstable = x; + const volatile int &read_only_unstable = x; + unstable = 2; + assert(read_only == 2); + assert(read_only_unstable == 2); + assert(&read_only == &x); + assert(&unstable == &x); + assert(&read_only_unstable == &x); +} +} // namespace p5_1_more_cv_qualified_reference + +// N4950 [dcl.init.ref]/5.1, [over.ics.rank]/3.2.6: of two references that +// bind, the one to the less cv-qualified type is chosen. +namespace p5_1_overloads_by_cv_qualification { +int which(int &) { return 1; } +int which(const int &) { return 2; } +int which(volatile int &) { return 3; } +int which(const volatile int &) { return 4; } + +void test() { + int plain = 0; + const int read_only = 0; + volatile int unstable = 0; + const volatile int read_only_unstable = 0; + assert(which(plain) == 1); + assert(which(read_only) == 2); + assert(which(unstable) == 3); + assert(which(read_only_unstable) == 4); +} +} // namespace p5_1_overloads_by_cv_qualification + +int main() { + p5_1_more_cv_qualified_reference::test(); + p5_1_overloads_by_cv_qualification::test(); + return 0; +} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref.cpp b/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref.cpp new file mode 100644 index 0000000000..f13961359d --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref.cpp @@ -0,0 +1,92 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include +#include + +// N4950 [dcl.init.ref]/5.1: an lvalue reference binds directly to an lvalue +// of a reference-compatible type, including one that is less cv-qualified. +namespace p5_1_lvalue_reference_to_lvalue { +void test() { + int x = 1; + int &plain = x; + const int &read_only = x; + plain = 2; + assert(read_only == 2); + assert(&read_only == &x); +} +} // namespace p5_1_lvalue_reference_to_lvalue + +// N4950 [dcl.init.ref]/5.3: a const lvalue reference and an rvalue reference +// bind to an rvalue, whose temporary lives as long as the reference. +namespace p5_3_reference_to_rvalue { +struct Counter { + int count; +}; + +Counter make(int count) { return Counter{count}; } + +void test() { + const Counter &kept = make(3); + Counter &&owned = make(4); + owned.count += 1; + assert(kept.count == 3); + assert(owned.count == 5); + + const int &number = 7; + int &&temporary = 8; + temporary += 1; + assert(number == 7); + assert(temporary == 9); +} +} // namespace p5_3_reference_to_rvalue + +// N4950 [dcl.init.ref]/5, [over.ics.rank]/3.2.3: an lvalue binds to T& rather +// than to const T&, and an rvalue to T&& rather than to const T&. +namespace p5_overloads_by_value_category { +int which(int &) { return 1; } +int which(const int &) { return 2; } +int which(int &&) { return 3; } + +void test() { + int x = 0; + const int y = 0; + assert(which(x) == 1); + assert(which(y) == 2); + assert(which(5) == 3); + assert(which(std::move(x)) == 3); +} +} // namespace p5_overloads_by_value_category + +// N4950 [dcl.init.ref]/5.4.4: an rvalue reference does not bind to an lvalue, +// so only the const lvalue reference overload takes one. +namespace p5_4_4_rvalue_reference_rejects_lvalue { +int which(const int &) { return 1; } +int which(int &&) { return 2; } + +void test() { + int x = 0; + assert(which(x) == 1); + assert(which(std::move(x)) == 2); + assert(which(3) == 2); +} +} // namespace p5_4_4_rvalue_reference_rejects_lvalue + +// N4950 [dcl.init.ref]/5.3: an xvalue binds to an rvalue reference without a +// copy, so the reference refers to the original object. +namespace p5_3_xvalue_binds_directly { +void test() { + int x = 1; + int &&moved = std::move(x); + moved = 6; + assert(x == 6); + assert(&moved == &x); +} +} // namespace p5_3_xvalue_binds_directly + +int main() { + p5_1_lvalue_reference_to_lvalue::test(); + p5_3_reference_to_rvalue::test(); + p5_overloads_by_value_category::test(); + p5_4_4_rvalue_reference_rejects_lvalue::test(); + p5_3_xvalue_binds_directly::test(); + return 0; +} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref-p5-cv-qualification.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref-p5-cv-qualification.rs new file mode 100644 index 0000000000..26d3030208 --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref-p5-cv-qualification.rs @@ -0,0 +1,52 @@ +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}; +pub fn test_0() { + let x: Value = Rc::new(RefCell::new(1)); + let read_only: Ptr = x.as_pointer(); + let unstable: Ptr = x.as_pointer(); + let read_only_unstable: Ptr = x.as_pointer(); + unstable.write(2); + assert!(((read_only.read()) == 2)); + assert!(((read_only_unstable.read()) == 2)); + assert!(({ (read_only).clone() } == { (x.as_pointer()) })); + assert!(({ (unstable).clone() } == { (x.as_pointer()) })); + assert!(({ (read_only_unstable).clone() } == { (x.as_pointer()) })); +} +pub fn which_1(_a0: Ptr) -> i32 { + return 1; +} +pub fn which_2(_a0: Ptr) -> i32 { + return 2; +} +pub fn which_3(_a0: Ptr) -> i32 { + return 3; +} +pub fn which_4(_a0: Ptr) -> i32 { + return 4; +} +pub fn test_5() { + let plain: Value = Rc::new(RefCell::new(0)); + let read_only: Value = Rc::new(RefCell::new(0)); + let unstable: Value = Rc::new(RefCell::new(0)); + let read_only_unstable: Value = Rc::new(RefCell::new(0)); + assert!((({ which_1(plain.as_pointer(),) }) == 1)); + assert!((({ which_2(read_only.as_pointer(),) }) == 2)); + assert!((({ which_3(unstable.as_pointer(),) }) == 3)); + assert!((({ which_4(read_only_unstable.as_pointer(),) }) == 4)); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_5() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} 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 new file mode 100644 index 0000000000..a1876bad6b --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs @@ -0,0 +1,115 @@ +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}; +pub fn test_0() { + let x: Value = Rc::new(RefCell::new(1)); + let plain: Ptr = x.as_pointer(); + let read_only: Ptr = x.as_pointer(); + plain.write(2); + assert!(((read_only.read()) == 2)); + assert!(({ (read_only).clone() } == { (x.as_pointer()) })); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, +)] +#[byte_size(4)] +pub struct p5_3_reference_to_rvalue_Counter { + #[offset(0)] + pub count: i32, +} +pub fn make_1(mut count: i32) -> p5_3_reference_to_rvalue_Counter { + return p5_3_reference_to_rvalue_Counter { count: count }; +} +pub fn test_2() { + let __tmp_0: Value = Rc::new(RefCell::new(({ make_1(3) }))); + let kept: Ptr = __tmp_0.as_pointer(); + let __tmp_1: Value = Rc::new(RefCell::new(({ make_1(4) }))); + let owned: Ptr = __tmp_1.as_pointer(); + { + field!(owned, count).with_mut(|__v| *__v = *__v + 1) + }; + assert!((kept.with(|__s| __s.count) == 3)); + assert!((owned.with(|__s| __s.count) == 5)); + let __tmp_2: Value = Rc::new(RefCell::new(7)); + let number: Ptr = __tmp_2.as_pointer(); + let __tmp_3: Value = Rc::new(RefCell::new(8)); + let temporary: Ptr = __tmp_3.as_pointer(); + { + temporary.with_mut(|__v| *__v = *__v + 1) + }; + assert!(((number.read()) == 7)); + assert!(((temporary.read()) == 9)); +} +pub fn which_3(_a0: Ptr) -> i32 { + return 1; +} +pub fn which_4(_a0: Ptr) -> i32 { + return 2; +} +pub fn which_5(_a0: Ptr) -> i32 { + return 3; +} +pub fn test_6() { + let x: Value = Rc::new(RefCell::new(0)); + let y: Value = Rc::new(RefCell::new(0)); + assert!((({ which_3(x.as_pointer(),) }) == 1)); + assert!((({ which_4(y.as_pointer(),) }) == 2)); + assert!( + (({ + let _arg0: Value = Rc::new(RefCell::new(5)); + which_5(_arg0.as_pointer()) + }) == 3) + ); + assert!((({ which_5(x.as_pointer(),) }) == 3)); +} +pub fn which_7(_a0: Ptr) -> i32 { + return 1; +} +pub fn which_8(_a0: Ptr) -> i32 { + return 2; +} +pub fn test_9() { + let x: Value = Rc::new(RefCell::new(0)); + assert!((({ which_7(x.as_pointer(),) }) == 1)); + assert!((({ which_8(x.as_pointer(),) }) == 2)); + assert!( + (({ + let _arg0: Value = Rc::new(RefCell::new(3)); + which_8(_arg0.as_pointer()) + }) == 2) + ); +} +pub fn test_10() { + let x: Value = Rc::new(RefCell::new(1)); + let moved: Ptr = x.as_pointer(); + moved.write(6); + assert!(({ ((*x.borrow()) == 6) })); + assert!(({ (moved).clone() } == { (x.as_pointer()) })); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_2() }); + ({ test_6() }); + ({ test_9() }); + ({ test_10() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref-p5-cv-qualification.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref-p5-cv-qualification.rs new file mode 100644 index 0000000000..bad1c17dfb --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref-p5-cv-qualification.rs @@ -0,0 +1,54 @@ +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; +pub unsafe fn test_0() { + let mut x: i32 = 1; + let read_only: *const i32 = &x; + let unstable: *mut i32 = &mut x; + let read_only_unstable: *const i32 = &x; + (*unstable) = 2; + assert!(((*read_only) == (2))); + assert!(((*read_only_unstable) == (2))); + assert!(((read_only) == ((&mut x as *mut i32).cast_const()))); + assert!(((unstable) == (&mut x as *mut i32))); + assert!(((read_only_unstable) == ((&mut x as *mut i32).cast_const()))); +} +pub unsafe fn which_1(_a0: *mut i32) -> i32 { + return 1; +} +pub unsafe fn which_2(_a0: *const i32) -> i32 { + return 2; +} +pub unsafe fn which_3(_a0: *mut i32) -> i32 { + return 3; +} +pub unsafe fn which_4(_a0: *const i32) -> i32 { + return 4; +} +pub unsafe fn test_5() { + let mut plain: i32 = 0; + let read_only: i32 = 0; + let mut unstable: i32 = 0; + let read_only_unstable: i32 = 0; + assert!(((unsafe { which_1(&mut plain,) }) == (1))); + assert!(((unsafe { which_2(&read_only,) }) == (2))); + assert!(((unsafe { which_3(&mut unstable,) }) == (3))); + assert!(((unsafe { which_4(&read_only_unstable,) }) == (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_5() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} 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 new file mode 100644 index 0000000000..6ebabc94ac --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs @@ -0,0 +1,110 @@ +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; +pub unsafe fn test_0() { + let mut x: i32 = 1; + let plain: *mut i32 = &mut x; + let read_only: *const i32 = &x; + (*plain) = 2; + assert!(((*read_only) == (2))); + assert!(((read_only) == ((&mut x as *mut i32).cast_const()))); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, +)] +pub struct p5_3_reference_to_rvalue_Counter { + pub count: i32, +} +pub unsafe fn make_1(mut count: i32) -> p5_3_reference_to_rvalue_Counter { + return p5_3_reference_to_rvalue_Counter { count: count }; +} +pub unsafe fn test_2() { + let mut __tmp_0: p5_3_reference_to_rvalue_Counter = (unsafe { make_1(3) }); + let kept: *const p5_3_reference_to_rvalue_Counter = &mut __tmp_0; + let mut __tmp_1: p5_3_reference_to_rvalue_Counter = (unsafe { make_1(4) }); + let owned: *mut p5_3_reference_to_rvalue_Counter = &mut __tmp_1; + (*owned).count += 1; + assert!((((*kept).count) == (3))); + assert!((((*owned).count) == (5))); + let mut __tmp_2: i32 = 7; + let number: *const i32 = &mut __tmp_2; + let mut __tmp_3: i32 = 8; + let temporary: *mut i32 = &mut __tmp_3; + (*temporary) += 1; + assert!(((*number) == (7))); + assert!(((*temporary) == (9))); +} +pub unsafe fn which_3(_a0: *mut i32) -> i32 { + return 1; +} +pub unsafe fn which_4(_a0: *const i32) -> i32 { + return 2; +} +pub unsafe fn which_5(_a0: *mut i32) -> i32 { + return 3; +} +pub unsafe fn test_6() { + let mut x: i32 = 0; + let y: i32 = 0; + assert!(((unsafe { which_3(&mut x,) }) == (1))); + assert!(((unsafe { which_4(&y,) }) == (2))); + assert!( + ((unsafe { + let mut _arg0: i32 = 5; + which_5(&mut _arg0) + }) == (3)) + ); + assert!(((unsafe { which_5(&mut x,) }) == (3))); +} +pub unsafe fn which_7(_a0: *const i32) -> i32 { + return 1; +} +pub unsafe fn which_8(_a0: *mut i32) -> i32 { + return 2; +} +pub unsafe fn test_9() { + let mut x: i32 = 0; + assert!(((unsafe { which_7(&x,) }) == (1))); + assert!(((unsafe { which_8(&mut x,) }) == (2))); + assert!( + ((unsafe { + let mut _arg0: i32 = 3; + which_8(&mut _arg0) + }) == (2)) + ); +} +pub unsafe fn test_10() { + let mut x: i32 = 1; + let moved: *mut i32 = &mut x; + (*moved) = 6; + assert!(((x) == (6))); + assert!(((moved) == (&mut x as *mut i32))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_0() }); + (unsafe { test_2() }); + (unsafe { test_6() }); + (unsafe { test_9() }); + (unsafe { test_10() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/dcl.ref.cpp b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/dcl.ref.cpp new file mode 100644 index 0000000000..ae1ecbb6d9 --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/dcl.ref.cpp @@ -0,0 +1,92 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include +#include + +// N4950 [dcl.ref]/1: a reference is an alias of the object it is bound to: +// an assignment to it assigns to that object, and its address is the address +// of that object. +namespace p1_reference_is_an_alias { +void test() { + int x = 1; + int y = 2; + int &alias = x; + alias = y; + assert(x == 2); + assert(&alias == &x); + y = 9; + assert(alias == 2); +} +} // namespace p1_reference_is_an_alias + +// N4950 [dcl.ref]/1: a reference to a pointer is an alias of the pointer +// object, not of what it points to. +namespace p1_reference_to_pointer { +void test() { + int x = 1; + int y = 2; + int *pointer = &x; + int *&alias = pointer; + alias = &y; + assert(pointer == &y); + *alias = 7; + assert(y == 7); + assert(x == 1); +} +} // namespace p1_reference_to_pointer + +// N4950 [dcl.ref]/6: an lvalue reference to any reference type, and an rvalue +// reference to an lvalue reference type, is an lvalue reference. +namespace p6_reference_collapsing { +template void assign_through(T &&target, int value) { + target = value; +} + +template int &as_lvalue_reference(T &target) { return target; } + +using IntRef = int &; +using IntRvalueRef = int &&; + +void test() { + int x = 1; + assign_through(x, 5); + assert(x == 5); + + IntRef &lvalue_of_lvalue = x; + IntRef &&rvalue_of_lvalue = x; + IntRvalueRef &lvalue_of_rvalue = x; + lvalue_of_lvalue = 6; + assert(x == 6); + rvalue_of_lvalue = 7; + assert(x == 7); + lvalue_of_rvalue = 8; + assert(x == 8); + assert(&lvalue_of_lvalue == &x); + assert(&rvalue_of_lvalue == &x); + assert(&lvalue_of_rvalue == &x); + + as_lvalue_reference(x) = 9; + assert(x == 9); +} +} // namespace p6_reference_collapsing + +// N4950 [dcl.ref]/6: an rvalue reference to an rvalue reference type is an +// rvalue reference, and binds to an rvalue. +namespace p6_rvalue_of_rvalue_reference { +using IntRvalueRef = int &&; + +int take(IntRvalueRef &&value) { return value; } + +void test() { + int x = 4; + assert(take(std::move(x)) == 4); + assert(take(11) == 11); +} +} // namespace p6_rvalue_of_rvalue_reference + +int main() { + p1_reference_is_an_alias::test(); + p1_reference_to_pointer::test(); + p6_reference_collapsing::test(); + p6_rvalue_of_rvalue_reference::test(); + return 0; +} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.ref.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.ref.rs new file mode 100644 index 0000000000..3cb7dd77ef --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.ref.rs @@ -0,0 +1,79 @@ +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}; +pub fn test_0() { + let x: Value = Rc::new(RefCell::new(1)); + let mut y: i32 = 2; + let alias: Ptr = x.as_pointer(); + alias.write(y); + assert!(({ ((*x.borrow()) == 2) })); + assert!(({ (alias).clone() } == { (x.as_pointer()) })); + y = 9; + assert!(((alias.read()) == 2)); +} +pub fn test_1() { + let x: Value = Rc::new(RefCell::new(1)); + let y: Value = Rc::new(RefCell::new(2)); + let pointer: Value> = Rc::new(RefCell::new((x.as_pointer()))); + let alias: Ptr> = pointer.as_pointer(); + alias.write((y.as_pointer())); + assert!(({ ({ (*pointer.borrow()).clone() } == { (y.as_pointer()) }) })); + (alias.read()).write(7); + assert!(({ ((*y.borrow()) == 7) })); + assert!(({ ((*x.borrow()) == 1) })); +} +pub fn assign_through_2(target: Ptr, mut value: i32) { + target.write(value); +} +pub fn as_lvalue_reference_3(target: Ptr) -> Ptr { + return (target).clone(); +} +pub fn test_4() { + let x: Value = Rc::new(RefCell::new(1)); + ({ assign_through_2(x.as_pointer(), 5) }); + assert!(({ ((*x.borrow()) == 5) })); + let lvalue_of_lvalue: Ptr = x.as_pointer(); + let rvalue_of_lvalue: Ptr = x.as_pointer(); + let lvalue_of_rvalue: Ptr = x.as_pointer(); + lvalue_of_lvalue.write(6); + assert!(({ ((*x.borrow()) == 6) })); + rvalue_of_lvalue.write(7); + assert!(({ ((*x.borrow()) == 7) })); + lvalue_of_rvalue.write(8); + assert!(({ ((*x.borrow()) == 8) })); + assert!(({ (lvalue_of_lvalue).clone() } == { (x.as_pointer()) })); + assert!(({ (rvalue_of_lvalue).clone() } == { (x.as_pointer()) })); + assert!(({ (lvalue_of_rvalue).clone() } == { (x.as_pointer()) })); + ({ as_lvalue_reference_3(x.as_pointer()) }).write(9); + assert!(({ ((*x.borrow()) == 9) })); +} +pub fn take_5(value: Ptr) -> i32 { + return (value.read()); +} +pub fn test_6() { + let x: Value = Rc::new(RefCell::new(4)); + assert!((({ take_5(x.as_pointer(),) }) == 4)); + assert!( + (({ + let _value: Value = Rc::new(RefCell::new(11)); + take_5(_value.as_pointer()) + }) == 11) + ); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_1() }); + ({ test_4() }); + ({ test_6() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.ref.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.ref.rs new file mode 100644 index 0000000000..c3ea0d8acb --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.ref.rs @@ -0,0 +1,81 @@ +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; +pub unsafe fn test_0() { + let mut x: i32 = 1; + let mut y: i32 = 2; + let alias: *mut i32 = &mut x; + (*alias) = y; + assert!(((x) == (2))); + assert!(((alias) == (&mut x as *mut i32))); + y = 9; + assert!(((*alias) == (2))); +} +pub unsafe fn test_1() { + let mut x: i32 = 1; + let mut y: i32 = 2; + let mut pointer: *mut i32 = (&mut x as *mut i32); + let alias: *mut *mut i32 = &mut pointer; + (*alias) = (&mut y as *mut i32); + assert!(((pointer) == (&mut y as *mut i32))); + (*(*alias)) = 7; + assert!(((y) == (7))); + assert!(((x) == (1))); +} +pub unsafe fn assign_through_2(target: *mut i32, mut value: i32) { + (*target) = value; +} +pub unsafe fn as_lvalue_reference_3(target: *mut i32) -> *mut i32 { + return target; +} +pub unsafe fn test_4() { + let mut x: i32 = 1; + (unsafe { assign_through_2(&mut x, 5) }); + assert!(((x) == (5))); + let lvalue_of_lvalue: *mut i32 = &mut x; + let rvalue_of_lvalue: *mut i32 = &mut x; + let lvalue_of_rvalue: *mut i32 = &mut x; + (*lvalue_of_lvalue) = 6; + assert!(((x) == (6))); + (*rvalue_of_lvalue) = 7; + assert!(((x) == (7))); + (*lvalue_of_rvalue) = 8; + assert!(((x) == (8))); + assert!(((lvalue_of_lvalue) == (&mut x as *mut i32))); + assert!(((rvalue_of_lvalue) == (&mut x as *mut i32))); + assert!(((lvalue_of_rvalue) == (&mut x as *mut i32))); + (*(unsafe { as_lvalue_reference_3(&mut x) })) = 9; + assert!(((x) == (9))); +} +pub unsafe fn take_5(value: *mut i32) -> i32 { + return (*value); +} +pub unsafe fn test_6() { + let mut x: i32 = 4; + assert!(((unsafe { take_5(&mut x,) }) == (4))); + assert!( + ((unsafe { + let mut _value: i32 = 11; + take_5(&mut _value) + }) == (11)) + ); +} +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() }); + (unsafe { test_4() }); + (unsafe { test_6() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} 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 623ff80f49..a1888f1daf 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 @@ -145,16 +145,18 @@ pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { fn copy_constructor( this: Ptr, - _a0: Ptr, + _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( this: Ptr, - _a0: Ptr, + _a0: RvalueRef, ) { + let _a0 = _a0.as_pointer(); (*moveCount_10.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -184,14 +186,17 @@ pub fn test_11() { object!( from_lvalue, p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - (holder.as_pointer()).member::(pm) + 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, - Moved( + RvalueRef::bind( (holder.as_pointer()) .member::(pm) ) 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 94eb7fbc68..1811b24dc4 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 @@ -132,16 +132,18 @@ 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( this: *mut Self, - _a0: *const p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, + _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( this: *mut Self, - _a0: *mut p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, + _a0: RvalueRefUnsafe, ) { + let _a0 = (_a0.as_ptr() as *mut p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves); (*std::cell::LazyCell::force_mut(&mut *&raw mut moveCount_10)).prefix_inc(); } } @@ -166,16 +168,18 @@ pub unsafe fn test_11() { object_unsafe!( from_lvalue, p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) - .wrapping_byte_offset(pm) - .cast::()) + 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, - Moved( + RvalueRefUnsafe::bind( &mut (*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) .wrapping_byte_offset(pm) .cast::()) 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 c9707c9790..f25fdafd12 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 @@ -67,7 +67,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.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 87f2db939c..44809583da 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 @@ -67,7 +67,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs index 1d35d3d76e..d01b906459 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 @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(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(); } 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 e8d742890a..c1521c990e 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 @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(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(); } diff --git a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs index c2345ac1f5..ccbbd21b47 100644 --- a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs @@ -65,14 +65,16 @@ pub fn test_1() { }) ); let referent: Value = Rc::new(RefCell::new(5)); - let bound: Value<(Value>, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new(referent.as_pointer())), + let bound: Value<(Value>>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(referent.as_pointer()))), Rc::new(RefCell::new(('c' as i8))), ))); (*referent.borrow_mut()) = 6; - assert!(({ (((*bound.borrow()).0.borrow().clone().read()) == 6) })); + assert!(({ (((*bound.borrow()).0.borrow().as_pointer().read()) == 6) })); assert!( - ({ ({ ((*bound.borrow()).0.borrow().clone()).clone() } == { (referent.as_pointer()) }) }) + ({ + ({ ((*bound.borrow()).0.borrow().as_pointer()).clone() } == { (referent.as_pointer()) }) + }) ); assert!(({ (((*(*bound.borrow()).1.borrow()) as i32) == (('c' as i8) as i32)) })); } @@ -160,6 +162,148 @@ pub fn test_4() { && (LessThanComparable::less(b.as_pointer(), c.as_pointer())); assert!(ordered); } +pub fn test_5() { + let x: Value = Rc::new(RefCell::new(1)); + let y: Value = Rc::new(RefCell::new(2)); + let to_x: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + let to_y: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(y.as_pointer()))), + Rc::new(RefCell::new(5)), + ))); + { + assign!((*to_x.borrow()).0 = (*to_y.borrow()).0); + assign!((*to_x.borrow()).1 = (*to_y.borrow()).1); + }; + assert!(({ ((*x.borrow()) == 2) })); + assert!(({ ({ ((*to_x.borrow()).0.borrow().as_pointer()).clone() } == { (x.as_pointer()) }) })); + assert!(({ ((*(*to_x.borrow()).1.borrow()) == 5) })); + (*y.borrow_mut()) = 9; + assert!(({ (((*to_x.borrow()).0.borrow().as_pointer().read()) == 2) })); + let u: Value = Rc::new(RefCell::new(1)); + let v: Value = Rc::new(RefCell::new(2)); + let at_u: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new((u.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + let at_v: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new((v.as_pointer()))), + Rc::new(RefCell::new(5)), + ))); + { + assign!((*at_u.borrow()).0 = (*at_v.borrow()).0); + assign!((*at_u.borrow()).1 = (*at_v.borrow()).1); + }; + assert!(({ ((*u.borrow()) == 1) })); + assert!(({ ({ (*(*at_u.borrow()).0.borrow()).clone() } == { (v.as_pointer()) }) })); +} +pub fn test_6() { + let x: Value = Rc::new(RefCell::new(1)); + let y: Value = Rc::new(RefCell::new(2)); + let to_x: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + let to_y: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(y.as_pointer()))), + Rc::new(RefCell::new(5)), + ))); + { + assign!((*to_x.borrow()).0 = RvalueRef((*to_y.borrow()).0)); + assign!((*to_x.borrow()).1 = RvalueRef((*to_y.borrow()).1)); + }; + assert!(({ ((*x.borrow()) == 2) })); + assert!(({ ((*y.borrow()) == 2) })); + assert!(({ ({ ((*to_x.borrow()).0.borrow().as_pointer()).clone() } == { (x.as_pointer()) }) })); +} +pub fn test_7() { + let x: Value = Rc::new(RefCell::new(4)); + let y: Value = Rc::new(RefCell::new(4)); + let to_x: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + let to_y: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(y.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + assert!( + ({ + WeaklyEqualityComparableWith::equal( + (*to_x.borrow()).0.as_pointer(), + (*to_y.borrow()).0.as_pointer(), + ) && WeaklyEqualityComparableWith::equal( + (*to_x.borrow()).1.as_pointer(), + (*to_y.borrow()).1.as_pointer(), + ) + }) + ); + (*y.borrow_mut()) = 5; + assert!( + !(WeaklyEqualityComparableWith::equal( + (*to_x.borrow()).0.as_pointer(), + (*to_y.borrow()).0.as_pointer() + ) && WeaklyEqualityComparableWith::equal( + (*to_x.borrow()).1.as_pointer(), + (*to_y.borrow()).1.as_pointer() + )) + ); +} +pub fn test_8() { + let x: Value = Rc::new(RefCell::new(1)); + let to_x: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + ({ (*to_x.borrow()).get_value::<0>().as_pointer() }) + .with(|__r| __r.as_pointer()) + .write(7); + assert!(({ ((*x.borrow()) == 7) })); + ({ (*to_x.borrow()).get_value::<1>().as_pointer() }).write(3); + assert!(({ ((*(*to_x.borrow()).1.borrow()) == 3) })); +} +pub fn test_9() { + let x: Value = Rc::new(RefCell::new(1)); + let read_only: Value<(Value>>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + (*x.borrow_mut()) = 5; + assert!(({ (((*read_only.borrow()).0.borrow().as_pointer().read()) == 5) })); + assert!( + ({ ({ ((*read_only.borrow()).0.borrow().as_pointer()).clone() } == { (x.as_pointer()) }) }) + ); +} +pub fn test_10() { + let x: Value = Rc::new(RefCell::new(2)); + let owned: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(RvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + (*owned.borrow()).0.borrow().as_pointer().write(7); + assert!(({ ((*x.borrow()) == 7) })); + assert!( + ({ ({ ((*owned.borrow()).0.borrow().as_pointer()).clone() } == { (x.as_pointer()) }) }) + ); + let a: Value = Rc::new(RefCell::new(1)); + let b: Value = Rc::new(RefCell::new(2)); + let to_a: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(RvalueRef::bind(a.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + let to_b: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(RvalueRef::bind(b.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + { + assign!((*to_a.borrow()).0 = RvalueRef((*to_b.borrow()).0)); + assign!((*to_a.borrow()).1 = RvalueRef((*to_b.borrow()).1)); + }; + assert!(({ ((*a.borrow()) == 2) })); + assert!(({ ({ ((*to_a.borrow()).0.borrow().as_pointer()).clone() } == { (a.as_pointer()) }) })); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -170,6 +314,12 @@ fn main_0() -> i32 { ({ test_2() }); ({ test_3() }); ({ test_4() }); + ({ test_5() }); + ({ test_6() }); + ({ test_7() }); + ({ test_8() }); + ({ test_9() }); + ({ test_10() }); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs index 5a5eb41f5c..05d651e5b5 100644 --- a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs @@ -61,10 +61,11 @@ pub unsafe fn test_1() { assert!(((values.len()) == (2_usize))); assert!(((copied.0.len()) == (2_usize)) && ((copied.0[(1_usize)]) == (7))); let mut referent: i32 = 5; - let mut bound: (*const i32, libc::c_char) = (&mut referent, ('c' as libc::c_char)); + let mut bound: (LvalueRefUnsafe>, libc::c_char) = + (LvalueRefUnsafe::bind(&mut referent), ('c' as libc::c_char)); referent = 6; - assert!(((*bound.0) == (6))); - assert!(((bound.0) == ((&mut referent as *mut i32).cast_const()))); + assert!(((*(bound.0.as_ptr() as *const i32)) == (6))); + assert!(((bound.0.as_ptr() as *const i32) == ((&mut referent as *mut i32).cast_const()))); assert!((((bound.1) as i32) == (('c' as libc::c_char) as i32))); } pub unsafe fn test_2() { @@ -160,6 +161,91 @@ pub unsafe fn test_4() { (LessThanComparableUnsafe::less(&a, &b)) && (LessThanComparableUnsafe::less(&b, &c)); assert!(ordered); } +pub unsafe fn test_5() { + let mut x: i32 = 1; + let mut y: i32 = 2; + let mut to_x: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut x), 0); + let mut to_y: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut y), 5); + { + assign_unsafe!(to_x.0 = (*&mut to_y).0); + assign_unsafe!(to_x.1 = (*&mut to_y).1); + }; + assert!(((x) == (2))); + assert!(((to_x.0.as_ptr() as *mut i32) == (&mut x as *mut i32))); + assert!(((to_x.1) == (5))); + y = 9; + assert!(((*(to_x.0.as_ptr() as *mut i32)) == (2))); + let mut u: i32 = 1; + let mut v: i32 = 2; + let mut at_u: (*mut i32, i32) = ((&mut u as *mut i32), 0); + let mut at_v: (*mut i32, i32) = ((&mut v as *mut i32), 5); + { + assign_unsafe!(at_u.0 = (*&mut at_v).0); + assign_unsafe!(at_u.1 = (*&mut at_v).1); + }; + assert!(((u) == (1))); + assert!(((at_u.0) == (&mut v as *mut i32))); +} +pub unsafe fn test_6() { + let mut x: i32 = 1; + let mut y: i32 = 2; + let mut to_x: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut x), 0); + let mut to_y: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut y), 5); + { + assign_unsafe!(to_x.0 = RvalueRefUnsafe(to_y.0)); + assign_unsafe!(to_x.1 = RvalueRefUnsafe(to_y.1)); + }; + assert!(((x) == (2))); + assert!(((y) == (2))); + assert!(((to_x.0.as_ptr() as *mut i32) == (&mut x as *mut i32))); +} +pub unsafe fn test_7() { + let mut x: i32 = 4; + let mut y: i32 = 4; + let mut to_x: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut x), 0); + let mut to_y: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut y), 0); + assert!( + WeaklyEqualityComparableWithUnsafe::equal(&to_x.0, &to_y.0) + && WeaklyEqualityComparableWithUnsafe::equal(&to_x.1, &to_y.1) + ); + y = 5; + assert!( + !(WeaklyEqualityComparableWithUnsafe::equal(&to_x.0, &to_y.0) + && WeaklyEqualityComparableWithUnsafe::equal(&to_x.1, &to_y.1)) + ); +} +pub unsafe fn test_8() { + let mut x: i32 = 1; + let mut to_x: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut x), 0); + (*((*to_x.get_mut::<0>()).as_ptr() as *mut i32)) = 7; + assert!(((x) == (7))); + *to_x.get_mut::<1>() = 3; + assert!(((to_x.1) == (3))); +} +pub unsafe fn test_9() { + let mut x: i32 = 1; + let mut read_only: (LvalueRefUnsafe>, i32) = (LvalueRefUnsafe::bind(&mut x), 0); + x = 5; + assert!(((*(read_only.0.as_ptr() as *const i32)) == (5))); + assert!(((read_only.0.as_ptr() as *const i32) == ((&mut x as *mut i32).cast_const()))); +} +pub unsafe fn test_10() { + let mut x: i32 = 2; + let mut owned: (RvalueRefUnsafe, i32) = (RvalueRefUnsafe::bind(&mut x), 0); + (*(owned.0.as_ptr() as *mut i32)) = 7; + assert!(((x) == (7))); + assert!(((owned.0.as_ptr() as *mut i32) == (&mut x as *mut i32))); + let mut a: i32 = 1; + let mut b: i32 = 2; + let mut to_a: (RvalueRefUnsafe, i32) = (RvalueRefUnsafe::bind(&mut a), 0); + let mut to_b: (RvalueRefUnsafe, i32) = (RvalueRefUnsafe::bind(&mut b), 0); + { + assign_unsafe!(to_a.0 = RvalueRefUnsafe(to_b.0)); + assign_unsafe!(to_a.1 = RvalueRefUnsafe(to_b.1)); + }; + assert!(((a) == (2))); + assert!(((to_a.0.as_ptr() as *mut i32) == (&mut a as *mut i32))); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -172,6 +258,12 @@ unsafe fn main_0() -> i32 { (unsafe { test_2() }); (unsafe { test_3() }); (unsafe { test_4() }); + (unsafe { test_5() }); + (unsafe { test_6() }); + (unsafe { test_7() }); + (unsafe { test_8() }); + (unsafe { test_9() }); + (unsafe { test_10() }); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/pairs/pairs.pair.cpp b/tests/std/utilities/pairs/pairs.pair.cpp index 199fc15e9c..145682c5fa 100644 --- a/tests/std/utilities/pairs/pairs.pair.cpp +++ b/tests/std/utilities/pairs/pairs.pair.cpp @@ -109,11 +109,118 @@ void test() { } } // namespace over_match_oper_p3_4_rewritten_candidates +// N4950 [pairs.pair]/22: operator= assigns p.first to first and p.second to +// second. A member of reference type is assigned through, and still refers to +// the same object, while a member of pointer type is given the other pointer. +namespace p22_copy_assignment_of_reference_member { +void test() { + int x = 1; + int y = 2; + std::pair to_x{x, 0}; + std::pair to_y{y, 5}; + to_x = to_y; + assert(x == 2); + assert(&to_x.first == &x); + assert(to_x.second == 5); + y = 9; + assert(to_x.first == 2); + + int u = 1; + int v = 2; + std::pair at_u{&u, 0}; + std::pair at_v{&v, 5}; + at_u = at_v; + assert(u == 1); + assert(at_u.first == &v); +} +} // namespace p22_copy_assignment_of_reference_member + +// N4950 [pairs.pair]/29: the move assignment forwards p.first, which for a +// member of lvalue reference type is an lvalue, so it is assigned through. +namespace p29_move_assignment_of_reference_member { +void test() { + int x = 1; + int y = 2; + std::pair to_x{x, 0}; + std::pair to_y{y, 5}; + to_x = std::move(to_y); + assert(x == 2); + assert(y == 2); + assert(&to_x.first == &x); +} +} // namespace p29_move_assignment_of_reference_member + +// N4950 [pairs.spec]/1: operator== compares the members, and a member of +// reference type is compared by the value of the object it refers to. +namespace spec_p1_equality_of_reference_member { +void test() { + int x = 4; + int y = 4; + std::pair to_x{x, 0}; + std::pair to_y{y, 0}; + assert(to_x == to_y); + y = 5; + assert(to_x != to_y); +} +} // namespace spec_p1_equality_of_reference_member + +// N4950 [pair.astuple]/4: get(p) returns a reference to the member, which +// for a member of reference type is a reference to the object it refers to. +namespace astuple_p4_get_of_reference_member { +void test() { + int x = 1; + std::pair to_x{x, 0}; + std::get<0>(to_x) = 7; + assert(x == 7); + std::get<1>(to_x) = 3; + assert(to_x.second == 3); +} +} // namespace astuple_p4_get_of_reference_member + +// N4950 [pairs.pair]/1, [dcl.ref]/1: a member of type reference to const +// refers to the object it was bound to and reads its current value. +namespace p1_reference_to_const_member { +void test() { + int x = 1; + std::pair read_only{x, 0}; + x = 5; + assert(read_only.first == 5); + assert(&read_only.first == &x); +} +} // namespace p1_reference_to_const_member + +// N4950 [pairs.pair]/29: the move assignment forwards p.first, which for a +// member of rvalue reference type is an rvalue, and assigns to the object the +// member refers to. +namespace p29_move_assignment_of_rvalue_reference_member { +void test() { + int x = 2; + std::pair owned{std::move(x), 0}; + owned.first = 7; + assert(x == 7); + assert(&owned.first == &x); + + int a = 1; + int b = 2; + std::pair to_a{std::move(a), 0}; + std::pair to_b{std::move(b), 0}; + to_a = std::move(to_b); + assert(a == 2); + assert(&to_a.first == &a); +} +} // namespace p29_move_assignment_of_rvalue_reference_member + int main() { p2_move_constructor::test(); p12_forwarding_constructor::test(); p16_converting_move_constructor::test(); p40_converting_move_assignment::test(); over_match_oper_p3_4_rewritten_candidates::test(); + p22_copy_assignment_of_reference_member::test(); + p29_move_assignment_of_reference_member::test(); + spec_p1_equality_of_reference_member::test(); + astuple_p4_get_of_reference_member::test(); + p1_reference_to_const_member::test(); + p29_move_assignment_of_rvalue_reference_member::test(); return 0; } diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 5d5204134d..ddf90123e1 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -29,12 +29,14 @@ impl p6_forward_like_Movable { } } impl CopyConstructible for p6_forward_like_Movable { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(this: Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } @@ -67,11 +69,17 @@ impl Default for p6_forward_like_Holder { } } pub fn take_1(__return: Ptr, self_: Ptr) { - ConstructFrom::construct_from(__return.clone(), field_ptr!(self_, member)); + CopyConstructible::copy_constructor( + __return.clone(), + LvalueRef::bind(field_ptr!(self_, member)), + ); return; } pub fn take_2(__return: Ptr, self_: Ptr) { - ConstructFrom::construct_from(__return.clone(), Moved(field_ptr!(self_, member))); + MoveConstructible::move_constructor( + __return.clone(), + RvalueRef::bind(field_ptr!(self_, member)), + ); return; } pub fn test_3() { @@ -100,7 +108,8 @@ impl p9_move_Movable { } } impl MoveConstructible for p9_move_Movable { - fn move_constructor(this: Ptr, other: Ptr) { + fn move_constructor(this: Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } @@ -117,7 +126,11 @@ pub fn test_4() { && ({ (pointer).clone() } == { (target.as_pointer()) }) ); object!(source, p9_move_Movable(3)); - object!(destination, p9_move_Movable, Moved(source.as_pointer())); + object!( + destination, + p9_move_Movable, + RvalueRef::bind(source.as_pointer()) + ); assert!(({ (*destination.borrow()).value } == 3) && ({ (*source.borrow()).value } == 0)); let strings: Value>> = Rc::new(RefCell::new(Vec::new())); let text: Value> = Rc::new(RefCell::new({ @@ -157,14 +170,16 @@ impl p10_forward_in_template_A { } } impl CopyConstructible for p10_forward_in_template_A { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(this: Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(this, copies).write(0); field!(this, moves).write((other.with(|__s| __s.moves) + 1)); @@ -177,11 +192,11 @@ impl Default for p10_forward_in_template_A { } } pub fn make_5(__return: Ptr, source: Ptr) { - ConstructFrom::construct_from(__return.clone(), (source).clone()); + CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind((source).clone())); return; } pub fn make_6(__return: Ptr, source: Ptr) { - ConstructFrom::construct_from(__return.clone(), Moved((source).clone())); + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((source).clone())); return; } pub fn test_7() { @@ -218,12 +233,17 @@ impl p11_move_if_noexcept_NoexceptMove { } } impl CopyConstructible for p11_move_if_noexcept_NoexceptMove { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor( + 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: Ptr) { + fn move_constructor(this: Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } @@ -243,12 +263,17 @@ impl p11_move_if_noexcept_ThrowingMove { } } impl CopyConstructible for p11_move_if_noexcept_ThrowingMove { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor( + 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: Ptr) { + fn move_constructor(this: Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } @@ -258,14 +283,14 @@ pub fn test_8() { object!( moved, p11_move_if_noexcept_NoexceptMove, - Moved(moved_from.as_pointer()) + 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, p11_move_if_noexcept_ThrowingMove, - copied_from.as_pointer() + 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 e38d344304..60ce4b7846 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -72,14 +72,19 @@ impl p10_move_constructor_A { } } impl MoveConstructible for p10_move_constructor_A { - fn move_constructor(this: Ptr, other: Ptr) { + fn move_constructor(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!(target, p10_move_constructor_A, Moved(source.as_pointer())); + object!( + target, + p10_move_constructor_A, + RvalueRef::bind(source.as_pointer()) + ); assert!(({ (*target.borrow()).value } == 1)); assert!(({ (*source.borrow()).value } == 0)); let values: Value> = Rc::new(RefCell::new(Vec::new())); diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index c670d40b34..8b4e364fcf 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -28,12 +28,17 @@ impl p6_forward_like_Movable { } } impl CopyConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn copy_constructor(this: *mut Self, other: *const p6_forward_like_Movable) { + unsafe fn copy_constructor( + 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: *mut p6_forward_like_Movable) { + unsafe fn move_constructor(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; } @@ -63,11 +68,14 @@ impl Default for p6_forward_like_Holder { } } pub unsafe fn take_1(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - ConstructFromUnsafe::construct_from(__return, &(*self_).member); + CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(&(*self_).member)); return; } pub unsafe fn take_2(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - ConstructFromUnsafe::construct_from(__return, Moved(&mut (*self_).member)); + MoveConstructibleUnsafe::move_constructor( + __return, + RvalueRefUnsafe::bind(&mut (*self_).member), + ); return; } pub unsafe fn test_3() { @@ -95,7 +103,8 @@ impl p9_move_Movable { } } impl MoveConstructibleUnsafe for p9_move_Movable { - unsafe fn move_constructor(this: *mut Self, other: *mut p9_move_Movable) { + unsafe fn move_constructor(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; } @@ -111,7 +120,11 @@ pub unsafe fn test_4() { ((moved_pointer) == (&mut target as *mut i32)) && ((pointer) == (&mut target as *mut i32)) ); object_unsafe!(source, p9_move_Movable(3)); - object_unsafe!(destination, p9_move_Movable, Moved(&mut source)); + object_unsafe!( + destination, + p9_move_Movable, + RvalueRefUnsafe::bind(&mut source) + ); assert!(((destination.value) == (3)) && ((source.value) == (0))); let mut strings: Vec> = Vec::new(); let mut text: Vec = std::slice::from_raw_parts( @@ -146,14 +159,19 @@ impl p10_forward_in_template_A { } } impl CopyConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn copy_constructor(this: *mut Self, other: *const p10_forward_in_template_A) { + unsafe fn copy_constructor( + this: *mut Self, + other: LvalueRefUnsafe>, + ) { + let other = (other.as_ptr() as *const p10_forward_in_template_A); (&raw mut (*this).value).write((*other).value); (&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: *mut p10_forward_in_template_A) { + unsafe fn move_constructor(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); (&raw mut (*this).moves).write((((*other).moves) + (1))); @@ -169,14 +187,14 @@ pub unsafe fn make_5( __return: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A, ) { - ConstructFromUnsafe::construct_from(__return, source); + CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(source)); return; } pub unsafe fn make_6( __return: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A, ) { - ConstructFromUnsafe::construct_from(__return, Moved(source)); + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(source)); return; } pub unsafe fn test_7() { @@ -206,12 +224,20 @@ impl p11_move_if_noexcept_NoexceptMove { } } impl CopyConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { - unsafe fn copy_constructor(this: *mut Self, other: *const p11_move_if_noexcept_NoexceptMove) { + unsafe fn copy_constructor( + 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(this: *mut Self, other: *mut p11_move_if_noexcept_NoexceptMove) { + unsafe fn move_constructor( + this: *mut Self, + other: RvalueRefUnsafe, + ) { + let other = (other.as_ptr() as *mut p11_move_if_noexcept_NoexceptMove); (&raw mut (*this).value).write((*other).value); (*other).value = 0; } @@ -230,12 +256,20 @@ impl p11_move_if_noexcept_ThrowingMove { } } impl CopyConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { - unsafe fn copy_constructor(this: *mut Self, other: *const p11_move_if_noexcept_ThrowingMove) { + unsafe fn copy_constructor( + 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(this: *mut Self, other: *mut p11_move_if_noexcept_ThrowingMove) { + unsafe fn move_constructor( + this: *mut Self, + other: RvalueRefUnsafe, + ) { + let other = (other.as_ptr() as *mut p11_move_if_noexcept_ThrowingMove); (&raw mut (*this).value).write((*other).value); (*other).value = 0; } @@ -245,11 +279,15 @@ pub unsafe fn test_8() { object_unsafe!( moved, p11_move_if_noexcept_NoexceptMove, - Moved(&mut moved_from) + 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, p11_move_if_noexcept_ThrowingMove, &copied_from); + object_unsafe!( + copied, + p11_move_if_noexcept_ThrowingMove, + LvalueRefUnsafe::bind(&copied_from) + ); assert!(((copied.value) == (2)) && ((copied_from.value) == (2))); } pub fn main() { diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index e9ed628da7..41b6475507 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -61,14 +61,19 @@ impl p10_move_constructor_A { } } impl MoveConstructibleUnsafe for p10_move_constructor_A { - unsafe fn move_constructor(this: *mut Self, other: *mut p10_move_constructor_A) { + unsafe fn move_constructor(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!(target, p10_move_constructor_A, Moved(&mut source)); + object_unsafe!( + target, + p10_move_constructor_A, + RvalueRefUnsafe::bind(&mut source) + ); assert!(((target.value) == (1))); assert!(((source.value) == (0))); let mut values: Vec = Vec::new(); diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index a117175a55..dfbec42db3 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -34,13 +34,15 @@ impl Partial { } } impl CopyConstructible for Partial { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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)); } } impl CopyAssignable for Partial { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); if (this == (o)) { return (this).clone(); } @@ -107,7 +109,8 @@ impl DefaultConstructible for RefQualified { } } impl CopyAssignable for RefQualified { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 1)); return (this).clone(); } @@ -178,7 +181,8 @@ impl CopyCounted { } } impl CopyConstructible for CopyCounted { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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(); } @@ -228,7 +232,11 @@ pub struct ExplicitOperatorCall { pub w: Vec, } impl CopyAssignable for ExplicitOperatorCall { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign( + this: Ptr, + o: LvalueRef>, + ) -> Ptr { + let o = o.as_pointer(); match (field_ref!(o, w).as_pointer(),) { (__tmp_0,) => field!(this, w).with_mut(|__b0| { (*__b0) = copy_constructed(__tmp_0); @@ -274,21 +282,22 @@ impl Swapped { } } impl CopyConstructible for Swapped { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*swap_copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyAssignable for Swapped { - fn copy_assign(this: Ptr, src: Ptr) -> Ptr { - object!(__o, Swapped, src); + 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())); Ptr::clone(&this.clone()) } } impl MoveAssignable for Swapped { - fn move_assign(this: Ptr, src: Ptr) -> Ptr { - object!(__o, Swapped, Moved(src)); + 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())); Ptr::clone(&this.clone()) } @@ -339,14 +348,14 @@ impl DefaultConstructible for VoidAssign { } } impl CopyAssignable for VoidAssign { - fn copy_assign(this: Ptr, src: Ptr) -> Ptr { - VoidAssign::copy_assign(this.clone(), src); + fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { + VoidAssign::copy_assign(this.clone(), src.as_pointer()); Ptr::clone(&this.clone()) } } impl MoveAssignable for VoidAssign { - fn move_assign(this: Ptr, src: Ptr) -> Ptr { - VoidAssign::copy_assign(this.clone(), src); + fn move_assign(this: Ptr, src: RvalueRef) -> Ptr { + VoidAssign::copy_assign(this.clone(), src.as_pointer()); Ptr::clone(&this.clone()) } } @@ -552,7 +561,7 @@ fn main_0() -> i32 { object!(sw2, Swapped(2)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_o.as_pointer(), sw2.as_pointer()); + CopyConstructible::copy_constructor(_o.as_pointer(), LvalueRef::bind(sw2.as_pointer())); Swapped::copy_assign(sw1.as_pointer(), _o.as_pointer()) }); assert!(({ (*sw1.borrow()).v } == 2) && (swap_copies_2.with(|rc| *rc.borrow()) == 1)); diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 1d75ac83e3..f1c9d161c8 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -35,7 +35,8 @@ impl Counted { } } impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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(); } @@ -99,7 +100,8 @@ impl Ignored { } } impl CopyConstructible for Ignored { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, v).write(-1_i32); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -153,7 +155,8 @@ impl Box_int_ { } } impl CopyConstructible for Box_int_ { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, val).write(o.with(|__s| __s.val)); } } @@ -193,7 +196,8 @@ impl OutOfLine { } } impl CopyConstructible for OutOfLine { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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(); } @@ -219,7 +223,8 @@ impl DefaultConstructible for Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, copied_from).write(0); field!(o, copied_from).with_mut(|__v| { __v.prefix_inc(); @@ -227,7 +232,8 @@ impl CopyConstructible for Tracked { } } impl CopyAssignable for Tracked { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(o, copied_from).with_mut(|__v| { __v.prefix_inc(); }); @@ -249,7 +255,7 @@ pub fn by_value_2(c: Ptr) -> i32 { } pub fn make_3(__return: Ptr, mut v: i32) { object!(c, Counted(v)); - ConstructFrom::construct_from(__return.clone(), c.as_pointer()); + CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind(c.as_pointer())); return; } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] @@ -265,12 +271,14 @@ impl DefaultConstructible for SelfPtr { } } impl CopyConstructible for SelfPtr { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(this: Ptr, _a0: RvalueRef) { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); } } @@ -329,9 +337,9 @@ pub fn main() { } fn main_0() -> i32 { object!(a, Counted(1)); - object!(b, Counted, a.as_pointer()); - object!(c, Counted, a.as_pointer()); - object!(d, Counted, a.as_pointer()); + object!(b, Counted, LvalueRef::bind(a.as_pointer())); + object!(c, Counted, LvalueRef::bind(a.as_pointer())); + object!(d, Counted, 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) @@ -339,7 +347,7 @@ fn main_0() -> i32 { assert!( (({ let _c: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_c.as_pointer(), a.as_pointer()); + CopyConstructible::copy_constructor(_c.as_pointer(), LvalueRef::bind(a.as_pointer())); by_value_2(_c.as_pointer()) }) == 1) ); @@ -351,7 +359,7 @@ fn main_0() -> i32 { assert!(({ (*f.borrow()).v } == 6)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); object!(g, Counted(7)); - object!(h, Counted, g.as_pointer()); + object!(h, Counted, 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 { @@ -373,7 +381,7 @@ fn main_0() -> i32 { }, ]), })); - object!(hold2, Holder, hold.as_pointer()); + object!(hold2, Holder, LvalueRef::bind(hold.as_pointer())); assert!( (({ (*hold2.borrow()).c.v } == 8) && (array_elem!(hold2.as_pointer(), arr, 0).with(|__s| __s.v) == 9)) @@ -385,7 +393,7 @@ fn main_0() -> i32 { assert!(({ (*vec_.borrow())[0_usize].v } == 1)); assert!((copies_0.with(|rc| *rc.borrow()) == 10)); object!(i1, Ignored(1)); - object!(i2, Ignored, i1.as_pointer()); + object!(i2, Ignored, 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 { @@ -395,10 +403,10 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); - object!(o2, Owner, Moved(o.as_pointer())); + object!(o2, Owner, RvalueRef::bind(o.as_pointer())); assert!(({ (*o2.borrow()).box_.val } == 3)); object!(ol1, OutOfLine(5)); - object!(ol2, OutOfLine, ol1.as_pointer()); + object!(ol2, OutOfLine, LvalueRef::bind(ol1.as_pointer())); assert!(({ (*ol2.borrow()).v } == 105)); assert!((copies_0.with(|rc| *rc.borrow()) == 12)); object!(n, NonConst); @@ -408,16 +416,16 @@ fn main_0() -> i32 { assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); object!(t1, Tracked); - object!(t2, Tracked, t1.as_pointer()); + object!(t2, Tracked, LvalueRef::bind(t1.as_pointer())); assign!(t2 = t1); assert!(({ (*t1.borrow()).copied_from } == 2)); object!(ct, Tracked); - object!(t3, Tracked, ct.as_pointer()); + object!(t3, Tracked, 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, der.as_pointer()); + object!(der2, Derived, 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(); diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index 8b1aef8ecd..5c66db8525 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -122,13 +122,15 @@ impl DefaultCopyUserMove { } } impl MoveConstructible for DefaultCopyUserMove { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for DefaultCopyUserMove { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); return (this).clone(); @@ -158,12 +160,17 @@ impl UserCopyDefaultMove { } } impl CopyConstructible for UserCopyDefaultMove { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); } } impl CopyAssignable for UserCopyDefaultMove { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign( + this: Ptr, + o: LvalueRef>, + ) -> Ptr { + let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); return (this).clone(); } @@ -325,13 +332,15 @@ pub struct SeesThis { pub self_: Ptr, } impl CopyAssignable for SeesThis { - fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _a0: LvalueRef>) -> Ptr { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); return (this).clone(); } } impl MoveAssignable for SeesThis { - fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn move_assign(this: Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); return (this).clone(); } @@ -382,13 +391,15 @@ impl DefaultConstructible for Counted_int_ { } } impl MoveConstructible for Counted_int_ { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(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)); } } impl MoveAssignable for Counted_int_ { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); return (this).clone(); @@ -441,24 +452,28 @@ impl DefaultConstructible for CtorSeesThis { } } impl CopyConstructible for CtorSeesThis { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(this: Ptr, _a0: RvalueRef) { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); field!(this, id).write(0); } } impl CopyAssignable for CtorSeesThis { - fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _a0: LvalueRef>) -> Ptr { + let _a0 = _a0.as_pointer(); return (this).clone(); } } impl MoveAssignable for CtorSeesThis { - fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn move_assign(this: Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); return (this).clone(); } } @@ -548,8 +563,12 @@ impl OutOfLineDefaulted { } } impl CopyConstructible for OutOfLineDefaulted { - fn copy_constructor(this: Ptr, _a0: Ptr) { - ConstructFrom::construct_from(field_ptr!(this, x), field_ptr!(_a0, x)); + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); + CopyConstructible::copy_constructor( + field_ptr!(this, x), + LvalueRef::bind(field_ptr!(_a0, x)), + ); field!(this, v).write(_a0.with(|__s| __s.v)); } } @@ -604,7 +623,11 @@ impl Default for OutOfLineAssign { } } impl CopyAssignable for OutOfLineAssign { - fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn copy_assign( + this: Ptr, + _a0: LvalueRef>, + ) -> Ptr { + let _a0 = _a0.as_pointer(); assign!(*field_ptr!(this, s) = *field_ptr!(_a0, s)); field!(this, v).write(_a0.with(|__s| __s.v)); match (field_ref!(_a0, w).as_pointer(),) { @@ -616,8 +639,9 @@ impl CopyAssignable for OutOfLineAssign { } } impl MoveAssignable for OutOfLineAssign { - fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { - assign!(*field_ptr!(this, s) = Moved(*field_ptr!(_a0, s))); + fn move_assign(this: Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); + assign!(*field_ptr!(this, s) = RvalueRef(*field_ptr!(_a0, s))); field!(this, v).write({ (*_a0.upgrade().deref()).v }); field!(this, w).with_mut(|__b0| { (*__b0) = field!(_a0, w).with_mut(std::mem::take); @@ -648,7 +672,7 @@ fn main_0() -> i32 { object!(e, Explicit(2)); object!(f, Explicit(3)); assign!(e = b); - assign!(f = Moved(c)); + assign!(f = RvalueRef(c)); assert!( ({ same_0(e.as_pointer(), b.as_pointer(),) }) && ({ same_0(f.as_pointer(), c.as_pointer(),) }) @@ -689,20 +713,20 @@ fn main_0() -> i32 { assert!(({ (*vec_.borrow())[0_usize].v } == 1) && ({ (*vec_.borrow())[1_usize].v } == 9)); object!(m, DefaultCopyUserMove(7)); let m1: Value = Rc::new(RefCell::new((*m.borrow()))); - object!(m2, DefaultCopyUserMove, Moved(m.as_pointer())); + object!(m2, DefaultCopyUserMove, 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)); assign!(m3 = m1); - assign!(m4 = Moved(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, u.as_pointer()); - object!(u2, UserCopyDefaultMove, Moved(u.as_pointer())); + object!(u1, UserCopyDefaultMove, LvalueRef::bind(u.as_pointer())); + object!(u2, UserCopyDefaultMove, RvalueRef::bind(u.as_pointer())); assert!( (({ (*u1.borrow()).v } == 108) && ({ (*u2.borrow()).v } == 8)) && ({ (*u.borrow()).v } == 8) @@ -710,10 +734,10 @@ fn main_0() -> i32 { object!(u3, UserCopyDefaultMove(1)); object!(u4, UserCopyDefaultMove(1)); assign!(u3 = u2); - assign!(u4 = Moved(u2)); + assign!(u4 = RvalueRef(u2)); assert!(({ (*u3.borrow()).v } == 108) && ({ (*u4.borrow()).v } == 8)); object!(p, Buffer(3)); - object!(q, Buffer, Moved(p.as_pointer())); + object!(q, Buffer, RvalueRef::bind(p.as_pointer())); assert!( ({ ((({ (*q.borrow()).n } == 3) && ((*q.borrow()).data.len() == 3_usize)) @@ -722,7 +746,7 @@ fn main_0() -> i32 { }) ); object!(r, Buffer(1)); - assign!(r = Moved(q)); + assign!(r = RvalueRef(q)); assert!( ({ ((({ (*r.borrow()).n } == 3) && ((*r.borrow()).data.len() == 3_usize)) @@ -749,9 +773,9 @@ fn main_0() -> i32 { let mut __tmp_2 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( __v.as_pointer(), - Moved(bufs.decay().offset(0_usize)), + RvalueRef::bind(bufs.decay().offset(0_usize)), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -777,7 +801,7 @@ 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, Moved(o1.as_pointer())); + object!(o2, Owner, RvalueRef::bind(o1.as_pointer())); assert!( ({ ((({ (*o2.borrow()).n } == 5) && ((*o2.borrow()).data.len() == 1_usize)) @@ -792,7 +816,7 @@ fn main_0() -> i32 { }) ); object!(o3, Owner); - assign!(o3 = Moved(o2)); + assign!(o3 = RvalueRef(o2)); assert!( ((({ (*o3.borrow()).n } == 5) && ((vec_elem!(o3.as_pointer(), data, 0_usize).read()) == 5)) @@ -809,11 +833,11 @@ fn main_0() -> i32 { data: Vec::from([1, 2]), })); let mut c2: Copyable = (*c1.borrow()).clone(); - object!(c3, Copyable, Moved(c1.as_pointer())); + object!(c3, Copyable, 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); - assign!(c4 = Moved(c3)); + assign!(c4 = RvalueRef(c3)); assert!( ({ ((vec_elem!(c4.as_pointer(), data, 1_usize).read()) == 2) @@ -822,14 +846,14 @@ fn main_0() -> i32 { ); object!(h1, Holder(4)); field_ptr!(h1.as_pointer(), p).write(Ptr::alloc(9).to_owned_opt()); - object!(h2, Holder, Moved(h1.as_pointer())); + object!(h2, Holder, 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)); - assign!(h3 = Moved(h2)); + assign!(h3 = RvalueRef(h2)); assert!( ((({ (*h3.borrow()).inner.x } == 4) && ((array_elem!(field_ptr!(h3.as_pointer(), e), arr, 1).read()) == 5)) @@ -839,20 +863,20 @@ fn main_0() -> i32 { object!(t1, HasSeesThis); object!(t2, HasSeesThis); object!(t3, HasSeesThis); - assign!(t2 = Moved(t1)); + 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, Moved(k1.as_pointer())); + object!(k2, HasCounted, RvalueRef::bind(k1.as_pointer())); assert!(({ (*k2.borrow()).c.moves } == 1)); object!(k3, HasCounted); - assign!(k3 = Moved(k2)); + assign!(k3 = RvalueRef(k2)); assert!(({ (*k3.borrow()).c.moves } == 2)); { object!(d, CtorSeesThis); assert!(({ { (*d.borrow()).self_.clone() } } == { (d.as_pointer()) })); - object!(e, CtorSeesThis, d.as_pointer()); + object!(e, CtorSeesThis, LvalueRef::bind(d.as_pointer())); assert!(({ { (*e.borrow()).self_.clone() } } == { (e.as_pointer()) })); object!(f, CtorSeesThis::construct_1(3)); assert!( @@ -861,11 +885,11 @@ fn main_0() -> i32 { ); object!(h1, HasCtorSeesThis); assert!(({ { (*h1.borrow()).x.self_.clone() } } == { (field_ptr!(h1.as_pointer(), x)) })); - object!(h2, HasCtorSeesThis, h1.as_pointer()); + object!(h2, HasCtorSeesThis, LvalueRef::bind(h1.as_pointer())); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); - object!(h3, HasCtorSeesThis, Moved(h1.as_pointer())); + object!(h3, HasCtorSeesThis, RvalueRef::bind(h1.as_pointer())); assert!(({ { (*h3.borrow()).x.self_.clone() } } == { (field_ptr!(h3.as_pointer(), x)) })); - assign!(h2 = Moved(h3)); + 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)) })); @@ -893,7 +917,7 @@ fn main_0() -> i32 { && ({ { (*o1.borrow()).x.self_.clone() } } == { (field_ptr!(o1.as_pointer(), x)) }) ); (*o1.borrow_mut()).v = 2; - object!(o2, OutOfLineDefaulted, o1.as_pointer()); + object!(o2, OutOfLineDefaulted, LvalueRef::bind(o1.as_pointer())); assert!( ({ (*o2.borrow()).v } == 2) && ({ { (*o2.borrow()).x.self_.clone() } } == { (field_ptr!(o2.as_pointer(), x)) }) @@ -917,7 +941,7 @@ fn main_0() -> i32 { }) ); assert!(({ { (*a2.borrow()).s.self_.clone() } } == { (field_ptr!(a2.as_pointer(), s)) })); - assign!(a3 = Moved(a2)); + assign!(a3 = RvalueRef(a2)); assert!( ({ (({ (*a3.borrow()).v } == 3) && ((*a3.borrow()).w.len() == 1_usize)) diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index 65c9b482e9..81abcb51e9 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -28,13 +28,15 @@ impl NoCopy { } } impl MoveConstructible for NoCopy { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for NoCopy { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); return (this).clone(); @@ -52,13 +54,15 @@ impl DefaultConstructible for PrivateCopy { } } impl MoveConstructible for PrivateCopy { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for PrivateCopy { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); return (this).clone(); @@ -143,17 +147,17 @@ pub fn main() { } fn main_0() -> i32 { object!(a, NoCopy(1)); - object!(b, NoCopy, Moved(a.as_pointer())); + object!(b, NoCopy, RvalueRef::bind(a.as_pointer())); assert!(({ (*b.borrow()).v } == 1) && ({ (*a.borrow()).v } == 0)); - assign!(a = Moved(b)); + 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); (*p.borrow_mut()).v = 3; - object!(q, PrivateCopy, Moved(p.as_pointer())); + object!(q, PrivateCopy, RvalueRef::bind(p.as_pointer())); assert!(({ (*q.borrow()).v } == 3) && ({ (*p.borrow()).v } == 0)); - assign!(p = Moved(q)); + assign!(p = RvalueRef(q)); assert!(({ (*p.borrow()).v } == 3) && ({ (*q.borrow()).v } == 0)); object!(im, Immovable); (*im.borrow_mut()).v = 4; @@ -168,23 +172,23 @@ fn main_0() -> i32 { }, tag: 7, })); - object!(d, Container, Moved(c.as_pointer())); + object!(d, Container, 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, Moved(h.as_pointer())); + object!(h2, VecHolder, RvalueRef::bind(h.as_pointer())); assert!(({ ((*h2.borrow()).items.len() == 0_usize) })); return 0; } impl CopyAssignable for PrivateCopy { - fn copy_assign(this: Ptr, _: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _: LvalueRef>) -> Ptr { unreachable!("PrivateCopy::copy_assign is never defined") } } impl CopyConstructible for PrivateCopy { - fn copy_constructor(this: Ptr, _: Ptr) { + fn copy_constructor(this: Ptr, _: LvalueRef>) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index 38d211ae47..6c6ee7cbbc 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -74,7 +74,8 @@ impl MoveOnly { } } impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, x: Ptr) { + fn move_constructor(this: Ptr, x: RvalueRef) { + let x = x.as_pointer(); field!(this, data_).write(x.with(|__s| __s.data_)); field!(x, data_).write(0); } @@ -123,7 +124,7 @@ fn main_0() -> i32 { FnPtr::, Ptr)>::new(scale_move_only_3); object!(n, MoveOnly, |n| ({ let _arg0: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_arg0.as_pointer(), Moved(m.as_pointer())); + MoveConstructible::move_constructor(_arg0.as_pointer(), RvalueRef::bind(m.as_pointer())); sc.call(Ptr::clone(&n.clone()), _arg0.as_pointer()) })); assert!((({ MoveOnly::get(n.as_pointer(),) }) == 40)); diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index 2830c24e3f..c12b3aa9e3 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -30,14 +30,16 @@ impl Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(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)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -52,12 +54,12 @@ pub fn chosen_overload_1(_a0: Ptr) -> Overload { } impl Holder { pub fn construct_1(this: Ptr, x: Ptr) { - ConstructFrom::construct_from(field_ptr!(this, t), (x).clone()); + CopyConstructible::copy_constructor(field_ptr!(this, t), LvalueRef::bind((x).clone())); } } impl Holder { pub fn construct_2(this: Ptr, x: Ptr) { - ConstructFrom::construct_from(field_ptr!(this, t), Moved((x).clone())); + MoveConstructible::move_constructor(field_ptr!(this, t), RvalueRef::bind((x).clone())); } } #[derive( diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index 9b665040ef..152965ba21 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -30,14 +30,16 @@ impl Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(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)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index 8c178d0bd4..d448573954 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -32,14 +32,16 @@ impl Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(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)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -59,7 +61,7 @@ pub fn chosen_overload_3(_a0: Ptr) -> Overload { return Overload_kIntRvalueOverload; } pub fn copy_or_move_into_param_4(__return: Ptr, t: Ptr) { - ConstructFrom::construct_from(__return.clone(), Moved((t).clone())); + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((t).clone())); return; } pub fn main() { @@ -79,7 +81,7 @@ fn main_0() -> i32 { object!(b, Tracked(6)); object!(moved, Tracked, |moved| ({ let _t: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_t.as_pointer(), Moved(b.as_pointer())); + MoveConstructible::move_constructor(_t.as_pointer(), RvalueRef::bind(b.as_pointer())); copy_or_move_into_param_4(Ptr::clone(&moved.clone()), _t.as_pointer()) })); assert!(({ (*moved.borrow()).v } == 6)); @@ -89,7 +91,7 @@ fn main_0() -> i32 { object!(c, Tracked(7)); object!(copied, Tracked, |copied| ({ let _t: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_t.as_pointer(), c.as_pointer()); + CopyConstructible::copy_constructor(_t.as_pointer(), LvalueRef::bind(c.as_pointer())); copy_or_move_into_param_4(Ptr::clone(&copied.clone()), _t.as_pointer()) })); assert!(({ (*copied.borrow()).v } == 7)); diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index 69e43be7ae..1322d87ae1 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -32,14 +32,16 @@ impl Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(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)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -96,8 +98,8 @@ pub fn forward_pack_7( } impl Pair { pub fn construct(this: Ptr, x: Ptr, y: Ptr) { - ConstructFrom::construct_from(field_ptr!(this, a), (x).clone()); - ConstructFrom::construct_from(field_ptr!(this, b), Moved((y).clone())); + CopyConstructible::copy_constructor(field_ptr!(this, a), LvalueRef::bind((x).clone())); + MoveConstructible::move_constructor(field_ptr!(this, b), RvalueRef::bind((y).clone())); } } #[derive( diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index dffd012142..65956063ca 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -194,27 +194,31 @@ impl DefaultConstructible for Counted { } } impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyAssignable for Counted { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copy_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); return (this).clone(); } } impl MoveAssignable for Counted { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*move_assigns_5.with(Value::clone).borrow_mut()).prefix_inc(); @@ -344,7 +348,7 @@ 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, Moved(t.as_pointer())); + object!(moved, State, RvalueRef::bind(t.as_pointer())); assert!( ({ ((*moved.borrow()).grid[(0) as usize][(0) as usize] == 100) @@ -362,7 +366,7 @@ fn main_0() -> i32 { && ((elem!(field_ref!(t.as_pointer(), arr).decay(), 1_usize).read()) == 7) ); let assigned: Value = Rc::new(RefCell::new(::default())); - assign!(assigned = Moved(moved)); + assign!(assigned = RvalueRef(moved)); assert!( ({ ((*assigned.borrow()).grid[(0) as usize][(0) as usize] == 100) @@ -399,8 +403,10 @@ fn main_0() -> i32 { )); let __p: Ptr = __v.decay(); for __i in 0..3 { - __p.offset(__i) - .construct_from(Moved(ca.decay().offset(__i))); + MoveConstructible::move_constructor( + __p.offset(__i), + RvalueRef::bind(ca.decay().offset(__i)), + ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -433,7 +439,7 @@ fn main_0() -> i32 { ); { for __i in 0..3 { - assign!(*ca.as_pointer().decay().offset(__i) = Moved(*cb.decay().offset(__i))); + assign!(*ca.as_pointer().decay().offset(__i) = RvalueRef(*cb.decay().offset(__i))); } ca.as_pointer() }; @@ -458,8 +464,10 @@ fn main_0() -> i32 { )); let __p: Ptr> = __v.decay(); for __i in 0..2 { - __p.offset(__i) - .construct_from(Moved(va.decay().offset(__i))); + MoveConstructible::move_constructor( + __p.offset(__i), + RvalueRef::bind(va.decay().offset(__i)), + ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -474,7 +482,7 @@ fn main_0() -> i32 { ))); { for __i in 0..2 { - assign!(*vc.as_pointer().decay().offset(__i) = Moved(*vb.decay().offset(__i))); + assign!(*vc.as_pointer().decay().offset(__i) = RvalueRef(*vb.decay().offset(__i))); } vc.as_pointer() }; diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index faf000ed8c..f4c2bb7b5c 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -125,7 +125,11 @@ impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { } } impl MoveConstructible for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor( + this: Ptr, + o: RvalueRef, + ) { + let o = o.as_pointer(); field!(this, f).write((*o.upgrade().deref()).f.move_from()); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); } @@ -259,7 +263,7 @@ fn main_0() -> i32 { object!( m2, Moving__lambda_at_lambda_as_field_cpp_64_12__, - Moved(m.as_pointer()) + 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 225a2866f9..9afa88dffb 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -21,13 +21,15 @@ impl DefaultConstructible for Counted { } } impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(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)); } @@ -53,10 +55,14 @@ impl DefaultConstructible for Dropped { fn default_constructor(this: Ptr) {} } impl CopyConstructible for Dropped { - fn copy_constructor(this: Ptr, _a0: Ptr) {} + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); + } } impl MoveConstructible for Dropped { - fn move_constructor(this: Ptr, _a0: Ptr) {} + fn move_constructor(this: Ptr, _a0: RvalueRef) { + let _a0 = _a0.as_pointer(); + } } impl Destructible for Dropped { fn destroy(this: Ptr) { @@ -73,7 +79,10 @@ fn main_0() -> i32 { { let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), c.as_pointer()); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind(c.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -95,12 +104,18 @@ fn main_0() -> i32 { { let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), c.as_pointer()); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind(c.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, |__return: Ptr| { - ConstructFrom::construct_from(__return.clone(), c.as_pointer()); + CopyConstructible::copy_constructor( + __return.clone(), + LvalueRef::bind(c.as_pointer()), + ); return; } ) @@ -123,7 +138,10 @@ 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())); - ConstructFrom::construct_from(__v.as_pointer(), arr.decay().offset(__i)); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind(arr.decay().offset(__i)), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index 12c53fdf5d..1585f4b343 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -23,7 +23,10 @@ impl Owner { { let self_: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved((this).clone())); + MoveConstructible::move_constructor( + __v.as_pointer(), + RvalueRef::bind((this).clone()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -34,7 +37,8 @@ impl Owner { } } impl MoveConstructible for Owner { - fn move_constructor(this: Ptr, o: Ptr) { + 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()); } @@ -54,7 +58,10 @@ fn main_0() -> i32 { { let h: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(o.as_pointer())); + MoveConstructible::move_constructor( + __v.as_pointer(), + RvalueRef::bind(o.as_pointer()), + ); 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 1086236bbc..b181f563ef 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -30,13 +30,15 @@ impl Key { } } impl CopyConstructible for Key { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(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(); } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 3e3dc3f6cd..1ee6e1bce2 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -37,13 +37,15 @@ impl DefaultConstructible for Item { } } impl CopyConstructible for Item { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(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(); field!(other, value).write(-1_i32); @@ -397,7 +399,10 @@ 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())); - ConstructFrom::construct_from(__v.as_pointer(), (__tmp_7).clone()); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind((__tmp_7).clone()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -436,9 +441,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())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( __v.as_pointer(), - Moved((__tmp_8).clone()), + RvalueRef::bind((__tmp_8).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -477,7 +482,10 @@ 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())); - ConstructFrom::construct_from(__v.as_pointer(), (__tmp_9).clone()); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind((__tmp_9).clone()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -517,9 +525,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())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( __v.as_pointer(), - Moved((__tmp_10).clone()), + RvalueRef::bind((__tmp_10).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -668,9 +676,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())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( __v.as_pointer(), - Moved((__tmp_13).clone()), + RvalueRef::bind((__tmp_13).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -711,9 +719,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())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( __v.as_pointer(), - Moved((__tmp_15).clone()), + RvalueRef::bind((__tmp_15).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index 301534b219..8ddeaa17c7 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -46,7 +46,8 @@ impl Bag { } } impl CopyConstructible for Bag { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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(); } diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 5664557646..56a09bd1b9 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -28,13 +28,15 @@ impl MoveOnly { } } impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for MoveOnly { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); if (this == (o)) { return (this).clone(); } @@ -78,7 +80,7 @@ impl Default for ConstMoveAssign { } pub fn make_0(__return: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(__return.clone(), Moved(m.as_pointer())); + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -89,31 +91,31 @@ fn main_0() -> i32 { object!(a, MoveOnly(1)); object!(b, MoveOnly(2)); object!(c, MoveOnly(3)); - assign!(a = Moved(b)); + 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); - assign!(b = Moved(_o)) + assign!(b = RvalueRef(_o)) }); - assign!(c = Moved(*assign!(a = Moved(b)))); + assign!(c = RvalueRef(*assign!(a = RvalueRef(b)))); assert!( (({ (*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); - assign!(a = Moved(_o)) + assign!(a = RvalueRef(_o)) }); assert!(({ (*a.borrow()).v } == 5)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); ({ make_0(Ptr::clone(&_o.as_pointer()), 6) }); - assign!(a = Moved(_o)) + assign!(a = RvalueRef(_o)) }); assert!(({ (*a.borrow()).v } == 6)); - assign!(a = Moved(a)); + assign!(a = RvalueRef(a)); assert!(({ (*a.borrow()).v } == 6)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { @@ -127,7 +129,7 @@ fn main_0() -> i32 { } }; object!(d, MoveOnly(8)); - assign!(*vec_.decay().offset(0_usize) = Moved(d)); + assign!(*vec_.decay().offset(0_usize) = RvalueRef(d)); assert!(({ (*vec_.borrow())[0_usize].v } == 8)); assert!(({ (*d.borrow()).v } == 0)); object!(m, ConstMoveAssign); diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index 97c764b6c1..f87768df30 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -21,7 +21,8 @@ impl MoveOnly { } } impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } @@ -77,14 +78,16 @@ impl ThrowingMove { } } impl CopyConstructible for ThrowingMove { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(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)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -112,14 +115,16 @@ impl NoexceptMove { } } impl CopyConstructible for NoexceptMove { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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: Ptr) { + fn move_constructor(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)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -131,7 +136,7 @@ pub fn by_value_0(m: Ptr) -> i32 { } pub fn make_1(__return: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(__return.clone(), Moved(m.as_pointer())); + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -140,13 +145,13 @@ pub fn main() { } fn main_0() -> i32 { object!(a, MoveOnly(1)); - object!(b, MoveOnly, Moved(a.as_pointer())); + object!(b, MoveOnly, RvalueRef::bind(a.as_pointer())); assert!(({ (*b.borrow()).v } == 1)); assert!(({ (*a.borrow()).v } == 0)); - object!(c, MoveOnly, Moved(b.as_pointer())); + object!(c, MoveOnly, RvalueRef::bind(b.as_pointer())); assert!(({ (*c.borrow()).v } == 1)); assert!(({ (*b.borrow()).v } == 0)); - object!(d, MoveOnly, Moved(c.as_pointer())); + object!(d, MoveOnly, 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,) })); @@ -161,7 +166,7 @@ fn main_0() -> i32 { assert!( (({ let _m: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_m.as_pointer(), Moved(e.as_pointer())); + MoveConstructible::move_constructor(_m.as_pointer(), RvalueRef::bind(e.as_pointer())); by_value_0(_m.as_pointer()) }) == 5) ); @@ -188,19 +193,19 @@ fn main_0() -> i32 { assert!(({ (*m1.borrow()).mark } == 1)); assert!(({ (*m2.borrow()).mark } == 10)); object!(t, ThrowingMove(1)); - object!(t1, ThrowingMove, t.as_pointer()); + object!(t1, ThrowingMove, 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, Moved(n.as_pointer())); + object!(n1, NoexceptMove, 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, Moved(g.as_pointer())); + object!(g1, MoveOnly, RvalueRef::bind(g.as_pointer())); assert!(({ (*g1.borrow()).v } == 3)); assert!(({ (*g.borrow()).v } == 0)); let nv: Value> = Rc::new(RefCell::new(Vec::new())); diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index de74dd8d5d..8af642151c 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -32,11 +32,11 @@ impl Chain { return (this).clone(); } pub fn take(this: Ptr, __return: Ptr) { - ConstructFrom::construct_from(__return.clone(), Moved((this).clone())); + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((this).clone())); return; } pub fn copy(this: Ptr, __return: Ptr) { - ConstructFrom::construct_from(__return.clone(), (this).clone()); + CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind((this).clone())); return; } pub fn self_(this: Ptr) -> Ptr { @@ -44,12 +44,14 @@ impl Chain { } } impl CopyConstructible for Chain { - fn copy_constructor(this: Ptr, o: Ptr) { + 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: Ptr) { + 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); } @@ -69,7 +71,7 @@ fn main_0() -> i32 { object!( b, Chain, - Moved(({ Chain::add_5(({ Chain::add_5(b0.as_pointer(), 1,) }), 1,) })) + 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| { @@ -93,9 +95,9 @@ fn main_0() -> i32 { assert!( (({ let _c: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( _c.as_pointer(), - Moved(({ Chain::self_(g.as_pointer()) })), + RvalueRef::bind(({ Chain::self_(g.as_pointer()) })), ); consume_0(_c.as_pointer()) }) == 21) diff --git a/tests/unit/out/refcount/pair.rs b/tests/unit/out/refcount/pair.rs index 1da712b674..ae6933b441 100644 --- a/tests/unit/out/refcount/pair.rs +++ b/tests/unit/out/refcount/pair.rs @@ -115,8 +115,8 @@ fn main_0() -> i32 { let mut pd: Ptr = ((*d.borrow()).0.as_pointer()); let mut ps: Ptr = ((*s.borrow()).0.as_pointer()); { - assign!((*d.borrow()).0 = Moved((*s.borrow()).0)); - assign!((*d.borrow()).1 = Moved((*s.borrow()).1)); + assign!((*d.borrow()).0 = RvalueRef((*s.borrow()).0)); + assign!((*d.borrow()).1 = RvalueRef((*s.borrow()).1)); }; assert!(((pd.read()) == 3)); ps.write(5); @@ -160,8 +160,8 @@ fn main_0() -> i32 { .borrow_mut()) = 7; assert!(({ ((*(*p.borrow()).1.borrow()) == 7) && ((*(*q.borrow()).1.borrow()) == 4) })); (*(*{ - assign!((*d.borrow()).0 = Moved((*q.borrow()).0)); - assign!((*d.borrow()).1 = Moved((*q.borrow()).1)); + assign!((*d.borrow()).0 = RvalueRef((*q.borrow()).0)); + assign!((*d.borrow()).1 = RvalueRef((*q.borrow()).1)); d.as_pointer() } .upgrade() diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index b497cf9c2c..06aa981bdb 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -50,7 +50,8 @@ impl Destructible for Buffer { } } impl CopyConstructible for Buffer { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, data).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(o.with(|__s| __s.size)); { @@ -67,7 +68,8 @@ impl CopyConstructible for Buffer { } } impl MoveConstructible for Buffer { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, data).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(o.with(|__s| __s.size)); { @@ -86,7 +88,8 @@ impl MoveConstructible for Buffer { } } impl CopyAssignable for Buffer { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); if (this == (o)) { return (this).clone(); } @@ -105,7 +108,8 @@ impl CopyAssignable for Buffer { } } impl MoveAssignable for Buffer { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); if (this == (o)) { return (this).clone(); } @@ -127,7 +131,7 @@ impl MoveAssignable for Buffer { } pub fn make_3(__return: Ptr, mut size: i32) { object!(b, Buffer(size)); - ConstructFrom::construct_from(__return.clone(), Moved(b.as_pointer())); + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind(b.as_pointer())); return; } pub fn main() { @@ -137,14 +141,14 @@ pub fn main() { fn main_0() -> i32 { { object!(a, Buffer(4)); - object!(b, Buffer, a.as_pointer()); + object!(b, Buffer, LvalueRef::bind(a.as_pointer())); assert!( ((alive_0.with(|rc| *rc.borrow()) == 2) && (copies_1.with(|rc| *rc.borrow()) == 1)) && (moves_2.with(|rc| *rc.borrow()) == 0) ); array_elem!(b.as_pointer(), data, 0).write(100); assert!(((array_elem!(a.as_pointer(), data, 0).read()) == 0)); - object!(c, Buffer, Moved(a.as_pointer())); + object!(c, Buffer, RvalueRef::bind(a.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 3) && (moves_2.with(|rc| *rc.borrow()) == 1)); assert!( ({ (*a.borrow()).size } == 0) @@ -161,12 +165,12 @@ fn main_0() -> i32 { && ((array_elem!(d.as_pointer(), data, 0).read()) == 100)) && (copies_1.with(|rc| *rc.borrow()) == 2) ); - assign!(d = Moved(c)); + assign!(d = RvalueRef(c)); assert!( (((array_elem!(d.as_pointer(), data, 0).read()) == 0) && ({ (*c.borrow()).size } == 0)) && (moves_2.with(|rc| *rc.borrow()) == 3) ); - assign!(d = Moved(d)); + assign!(d = RvalueRef(d)); assert!(({ (*d.borrow()).size } == 4) && (moves_2.with(|rc| *rc.borrow()) == 3)); } assert!((alive_0.with(|rc| *rc.borrow()) == 0)); diff --git a/tests/unit/out/refcount/rule_of_three.rs b/tests/unit/out/refcount/rule_of_three.rs index 7a72047e63..cefeb4ff1a 100644 --- a/tests/unit/out/refcount/rule_of_three.rs +++ b/tests/unit/out/refcount/rule_of_three.rs @@ -55,7 +55,8 @@ impl Destructible for Buffer { } } impl CopyConstructible for Buffer { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, data).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(o.with(|__s| __s.size)); { @@ -72,7 +73,8 @@ impl CopyConstructible for Buffer { } } impl CopyAssignable for Buffer { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); if (this == (o)) { return (this).clone(); } @@ -110,7 +112,7 @@ pub fn main() { fn main_0() -> i32 { { object!(a, Buffer(4)); - object!(b, Buffer, a.as_pointer()); + object!(b, Buffer, LvalueRef::bind(a.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 2) && (copies_1.with(|rc| *rc.borrow()) == 1)); array_elem!(b.as_pointer(), data, 0).write(100); assert!(((array_elem!(a.as_pointer(), data, 0).read()) == 0)); @@ -124,7 +126,7 @@ fn main_0() -> i32 { assert!((copies_1.with(|rc| *rc.borrow()) == 2)); assert!((({ sum_2(a.as_pointer(),) }) == 6)); assert!((({ sum_2(b.as_pointer(),) }) == 106)); - object!(d, Buffer, a.as_pointer()); + object!(d, Buffer, LvalueRef::bind(a.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 4) && (copies_1.with(|rc| *rc.borrow()) == 3)); assert!( ({ (*a.borrow()).size } == 4) && ((array_elem!(a.as_pointer(), data, 3).read()) == 3) diff --git a/tests/unit/out/refcount/rvalue_rule_arg_move.rs b/tests/unit/out/refcount/rvalue_rule_arg_move.rs index 1ee22ca2c7..d4933d171e 100644 --- a/tests/unit/out/refcount/rvalue_rule_arg_move.rs +++ b/tests/unit/out/refcount/rvalue_rule_arg_move.rs @@ -36,13 +36,15 @@ impl Elem { } } impl CopyConstructible for Elem { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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(); } } impl MoveConstructible for Elem { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -65,7 +67,7 @@ fn main_0() -> i32 { let mut __tmp_0 = { >::from(v.decay().end()) }; let __a2 = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(a.as_pointer())); + MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(a.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; (*v.borrow_mut()).insert(__tmp_0.index(), __a2); diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 895a9c7f1a..abe31408f9 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -63,14 +63,16 @@ pub fn size_t_in_rules_3() { Rc::new(RefCell::new((0..3).map(|_| ::zero_init()).collect())); let __p: Ptr = __v.decay(); for __i in 0..3 { - __p.offset(__i) - .construct_from(Moved(ar2.decay().offset(__i))); + MoveConstructible::move_constructor( + __p.offset(__i), + RvalueRef::bind(ar2.decay().offset(__i)), + ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); { for __i in 0..3 { - assign!(*ar3.as_pointer().decay().offset(__i) = Moved(*ar.decay().offset(__i))); + assign!(*ar3.as_pointer().decay().offset(__i) = RvalueRef(*ar.decay().offset(__i))); } ar3.as_pointer() }; diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index 6ff5de4e6d..38e95b18dc 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -27,25 +27,29 @@ impl DefaultConstructible for Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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(); } } impl MoveConstructible for Tracked { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); } } impl CopyAssignable for Tracked { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); return (this).clone(); } } impl MoveAssignable for Tracked { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); return (this).clone(); } diff --git a/tests/unit/out/refcount/structured_binding_copy_ctor.rs b/tests/unit/out/refcount/structured_binding_copy_ctor.rs index 3a0162e107..1e9c93ba33 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -36,7 +36,8 @@ impl Counted { } } impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor(this: Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!(this, x).write((other.with(|__s| __s.x) * 2)); field!(this, y).write((other.with(|__s| __s.y) * 2)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); @@ -54,7 +55,7 @@ fn main_0() -> i32 { object!(s, Counted(1, 2)); let __decomp_2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), s.as_pointer()); + CopyConstructible::copy_constructor(__v.as_pointer(), LvalueRef::bind(s.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((copies_0.with(|rc| *rc.borrow()) == 1)); diff --git a/tests/unit/out/refcount/structured_binding_element_ctor.rs b/tests/unit/out/refcount/structured_binding_element_ctor.rs index 405c4024d0..e73c88804f 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -27,13 +27,15 @@ impl Elem { } } impl CopyConstructible for Elem { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor(this: Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!(this, v).write((other.with(|__s| __s.v) + 100)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Elem { - fn move_constructor(this: Ptr, other: Ptr) { + fn move_constructor(this: Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!(this, v).write((other.with(|__s| __s.v) + 1000)); field!(other, v).write(-1_i32); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); @@ -88,7 +90,7 @@ fn main_0() -> i32 { let mut base_moves: i32 = moves_1.with(|rc| *rc.borrow()); let __decomp_3: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), t.as_pointer()); + CopyConstructible::copy_constructor(__v.as_pointer(), LvalueRef::bind(t.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((copies_0.with(|rc| *rc.borrow()) == (base_copies + 2))); @@ -102,7 +104,7 @@ fn main_0() -> i32 { assert!(({ (*t.borrow()).a.v } == 50)); let __decomp_5: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(t.as_pointer())); + MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(t.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((moves_1.with(|rc| *rc.borrow()) == (base_moves + 2))); @@ -125,7 +127,10 @@ fn main_0() -> i32 { Elem::construct(__tmp_0.as_pointer(), 7); { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(__tmp_0.as_pointer())); + MoveConstructible::move_constructor( + __v.as_pointer(), + RvalueRef::bind(__tmp_0.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } })), @@ -134,7 +139,10 @@ fn main_0() -> i32 { Elem::construct(__tmp_1.as_pointer(), 8); { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(__tmp_1.as_pointer())); + MoveConstructible::move_constructor( + __v.as_pointer(), + RvalueRef::bind(__tmp_1.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } })), diff --git a/tests/unit/out/refcount/structured_binding_move_ctor.rs b/tests/unit/out/refcount/structured_binding_move_ctor.rs index 58ccc2b8df..5fe6efe7c3 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -27,14 +27,16 @@ impl Movable { } } impl CopyConstructible for Movable { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor(this: Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!(this, x).write(other.with(|__s| __s.x)); field!(this, y).write(other.with(|__s| __s.y)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Movable { - fn move_constructor(this: Ptr, other: Ptr) { + fn move_constructor(this: Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!(this, x).write(other.with(|__s| __s.x)); field!(this, y).write(other.with(|__s| __s.y)); field!(other, x).write(0); @@ -88,7 +90,7 @@ fn main_0() -> i32 { object!(m, Movable(3, 4)); let __decomp_2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(m.as_pointer())); + MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(m.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((moves_1.with(|rc| *rc.borrow()) == 1)); diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 782246a0d9..e3c2df9ae8 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -27,25 +27,29 @@ impl DefaultConstructible for Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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(); } } impl MoveConstructible for Tracked { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); } } impl CopyAssignable for Tracked { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); return (this).clone(); } } impl MoveAssignable for Tracked { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); return (this).clone(); } @@ -150,7 +154,8 @@ impl CopyOnly { } } impl CopyConstructible for CopyOnly { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copy_only_copies_1.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -161,7 +166,8 @@ impl Destructible for CopyOnly { } } impl CopyAssignable for CopyOnly { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copy_only_copies_1.with(Value::clone).borrow_mut()).prefix_inc(); return (this).clone(); @@ -206,27 +212,31 @@ impl Moved { } } impl CopyConstructible for Moved { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(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(); } } impl MoveConstructible for Moved { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyAssignable for Moved { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); return (this).clone(); } } impl MoveAssignable for Moved { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*move_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -310,7 +320,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); ({ @@ -327,7 +337,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); let m2: Value, Value)>> = Rc::new(RefCell::new(Map::new())); @@ -345,7 +355,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); @@ -647,7 +657,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); ({ @@ -664,7 +674,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); Swappable::swap(maps.decay().offset(0), maps.decay().offset(1)); diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index 11379eabf7..919d9683c7 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -310,7 +310,7 @@ unsafe fn main_0() -> i32 { assert!(((b2.w) == (2))); let mut v4: Vec = Vec::new(); { - AssignFromUnsafe::assign_from(&raw mut v4, &mut v2); + CopyAssignableUnsafe::copy_assign(&raw mut v4, LvalueRefUnsafe::bind(&mut v2)); }; { let mut i: i32 = 0; diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index f4702998d3..9864b73db1 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -28,13 +28,15 @@ impl Partial { } } impl CopyConstructibleUnsafe for Partial { - unsafe fn copy_constructor(this: *mut Self, o: *const Partial) { + unsafe fn copy_constructor(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); } } impl CopyAssignableUnsafe for Partial { - unsafe fn copy_assign(this: *mut Self, o: *const Partial) -> *mut Partial { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Partial { + let o = (o.as_ptr() as *const Partial); if (((this).cast_const()) == (o)) { return &mut (*this); } @@ -102,7 +104,11 @@ impl DefaultConstructibleUnsafe for RefQualified { } } impl CopyAssignableUnsafe for RefQualified { - unsafe fn copy_assign(this: *mut Self, o: *const RefQualified) -> *mut RefQualified { + unsafe fn copy_assign( + this: *mut Self, + o: LvalueRefUnsafe>, + ) -> *mut RefQualified { + let o = (o.as_ptr() as *const RefQualified); (*this).mark = (((*o).mark) + (1)); return &mut (*this); } @@ -156,7 +162,8 @@ impl CopyCounted { } } impl CopyConstructibleUnsafe for CopyCounted { - unsafe fn copy_constructor(this: *mut Self, o: *const CopyCounted) { + unsafe fn copy_constructor(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(); } @@ -192,10 +199,11 @@ pub struct ExplicitOperatorCall { impl CopyAssignableUnsafe for ExplicitOperatorCall { unsafe fn copy_assign( this: *mut Self, - o: *const ExplicitOperatorCall, + o: LvalueRefUnsafe>, ) -> *mut ExplicitOperatorCall { + let o = (o.as_ptr() as *const ExplicitOperatorCall); { - AssignFromUnsafe::assign_from(&raw mut (*this).w, &(*o).w); + CopyAssignableUnsafe::copy_assign(&raw mut (*this).w, LvalueRefUnsafe::bind(&(*o).w)); }; return &mut (*this); } @@ -232,21 +240,30 @@ impl Swapped { } } impl CopyConstructibleUnsafe for Swapped { - unsafe fn copy_constructor(this: *mut Self, o: *const 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: *const Self) -> *mut Self { - object_unsafe!(__o, Swapped, src); + unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { + object_unsafe!( + __o, + Swapped, + LvalueRefUnsafe::bind((src.as_ptr() as *const Swapped)) + ); Swapped::copy_assign(this, &raw mut __o); this } } impl MoveAssignableUnsafe for Swapped { - unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { - object_unsafe!(__o, Swapped, Moved(src)); + unsafe fn move_assign(this: *mut Self, src: RvalueRefUnsafe) -> *mut Self { + object_unsafe!( + __o, + Swapped, + RvalueRefUnsafe::bind((src.as_ptr() as *mut Swapped)) + ); Swapped::copy_assign(this, &raw mut __o); this } @@ -290,14 +307,14 @@ impl DefaultConstructibleUnsafe for VoidAssign { } } impl CopyAssignableUnsafe for VoidAssign { - unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { - VoidAssign::copy_assign(this, src); + unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { + VoidAssign::copy_assign(this, (src.as_ptr() as *const VoidAssign)); this } } impl MoveAssignableUnsafe for VoidAssign { - unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { - VoidAssign::copy_assign(this, src); + unsafe fn move_assign(this: *mut Self, src: RvalueRefUnsafe) -> *mut Self { + VoidAssign::copy_assign(this, (src.as_ptr() as *mut VoidAssign)); this } } @@ -490,7 +507,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(sw2, Swapped(2)); (unsafe { let mut _o: Swapped = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut _o, &sw2); + CopyConstructibleUnsafe::copy_constructor(&raw mut _o, LvalueRefUnsafe::bind(&sw2)); Swapped::copy_assign(&raw mut sw1, &mut _o) }); assert!( diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 3f21fe6fe3..eb11c9e37a 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -30,7 +30,8 @@ impl Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: *const Counted) { + unsafe fn copy_constructor(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(); } @@ -90,7 +91,8 @@ impl Ignored { } } impl CopyConstructibleUnsafe for Ignored { - unsafe fn copy_constructor(this: *mut Self, _a0: *const Ignored) { + unsafe fn copy_constructor(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(); } @@ -129,7 +131,8 @@ impl Box_int_ { } } impl CopyConstructibleUnsafe for Box_int_ { - unsafe fn copy_constructor(this: *mut Self, o: *const Box_int_) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Box_int_); (&raw mut (*this).val).write((*o).val); } } @@ -164,7 +167,8 @@ impl OutOfLine { } } impl CopyConstructibleUnsafe for OutOfLine { - unsafe fn copy_constructor(this: *mut Self, o: *const OutOfLine) { + unsafe fn copy_constructor(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(); } @@ -187,13 +191,15 @@ impl DefaultConstructibleUnsafe for Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(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(); } } impl CopyAssignableUnsafe for Tracked { - unsafe fn copy_assign(this: *mut Self, o: *const Tracked) -> *mut Tracked { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Tracked { + let o = (o.as_ptr() as *const Tracked); (*(&raw const (*o).copied_from).cast_mut()).prefix_inc(); return &mut (*this); } @@ -211,7 +217,7 @@ pub unsafe fn by_value_2(c: *mut Counted) -> i32 { } pub unsafe fn make_3(__return: *mut Counted, mut v: i32) { object_unsafe!(c, Counted(v)); - ConstructFromUnsafe::construct_from(__return, &c); + CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(&c)); return; } #[repr(C)] @@ -225,12 +231,14 @@ impl DefaultConstructibleUnsafe for SelfPtr { } } impl CopyConstructibleUnsafe for SelfPtr { - unsafe fn copy_constructor(this: *mut Self, _a0: *const SelfPtr) { + unsafe fn copy_constructor(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: *mut SelfPtr) { + unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { + let _a0 = (_a0.as_ptr() as *mut SelfPtr); (&raw mut (*this).self_).write(this); } } @@ -289,15 +297,15 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(a, Counted(1)); - object_unsafe!(b, Counted, &a); - object_unsafe!(c, Counted, &a); - object_unsafe!(d, Counted, &a); + object_unsafe!(b, Counted, LvalueRefUnsafe::bind(&a)); + object_unsafe!(c, Counted, LvalueRefUnsafe::bind(&a)); + object_unsafe!(d, Counted, 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(); - ConstructFromUnsafe::construct_from(&raw mut _c, &a); + CopyConstructibleUnsafe::copy_constructor(&raw mut _c, LvalueRefUnsafe::bind(&a)); by_value_2(&mut _c) }) == (1)) ); @@ -309,7 +317,7 @@ unsafe fn main_0() -> i32 { 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, &g); + object_unsafe!(h, Counted, LvalueRefUnsafe::bind(&g)); assert!(((h.v) == (7))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (6))); let mut hold: Holder = Holder { @@ -331,7 +339,7 @@ unsafe fn main_0() -> i32 { }, ], }; - object_unsafe!(hold2, Holder, &hold); + object_unsafe!(hold2, Holder, LvalueRefUnsafe::bind(&hold)); assert!( (((hold2.c.v) == (8)) && ((hold2.arr[(0) as usize].v) == (9))) && ((hold2.arr[(1) as usize].v) == (10)) @@ -342,7 +350,7 @@ unsafe fn main_0() -> i32 { 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, &i1); + object_unsafe!(i2, Ignored, 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 { @@ -352,10 +360,10 @@ unsafe fn main_0() -> i32 { __v }, }; - object_unsafe!(o2, Owner, Moved(&mut o)); + object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o)); assert!(((o2.box_.val) == (3))); object_unsafe!(ol1, OutOfLine(5)); - object_unsafe!(ol2, OutOfLine, &ol1); + object_unsafe!(ol2, OutOfLine, LvalueRefUnsafe::bind(&ol1)); assert!(((ol2.v) == (105))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (12))); object_unsafe!(n, NonConst); @@ -365,16 +373,16 @@ unsafe fn main_0() -> i32 { assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); object_unsafe!(t1, Tracked); - object_unsafe!(t2, Tracked, &t1); + object_unsafe!(t2, Tracked, LvalueRefUnsafe::bind(&t1)); assign_unsafe!(t2 = t1); assert!(((t1.copied_from) == (2))); object_unsafe!(ct, Tracked); - object_unsafe!(t3, Tracked, &ct); + object_unsafe!(t3, Tracked, 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, &der); + object_unsafe!(der2, Derived, LvalueRefUnsafe::bind(&der)); assert!( ((der2.c.v) == (20)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((before) + (1))) diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index ece42c2a54..7dabf54a1b 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -91,7 +91,8 @@ impl DefaultCopyUserMove { } } impl MoveConstructibleUnsafe for DefaultCopyUserMove { - unsafe fn move_constructor(this: *mut Self, o: *mut DefaultCopyUserMove) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut DefaultCopyUserMove); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } @@ -99,8 +100,9 @@ impl MoveConstructibleUnsafe for DefaultCopyUserMove { impl MoveAssignableUnsafe for DefaultCopyUserMove { unsafe fn move_assign( this: *mut Self, - o: *mut DefaultCopyUserMove, + o: RvalueRefUnsafe, ) -> *mut DefaultCopyUserMove { + let o = (o.as_ptr() as *mut DefaultCopyUserMove); (*this).v = (*o).v; (*o).v = 0; return &mut (*this); @@ -127,15 +129,17 @@ impl UserCopyDefaultMove { } } impl CopyConstructibleUnsafe for UserCopyDefaultMove { - unsafe fn copy_constructor(this: *mut Self, o: *const UserCopyDefaultMove) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const UserCopyDefaultMove); (&raw mut (*this).v).write((((*o).v) + (100))); } } impl CopyAssignableUnsafe for UserCopyDefaultMove { unsafe fn copy_assign( this: *mut Self, - o: *const UserCopyDefaultMove, + o: LvalueRefUnsafe>, ) -> *mut UserCopyDefaultMove { + let o = (o.as_ptr() as *const UserCopyDefaultMove); (*this).v = (((*o).v) + (100)); return &mut (*this); } @@ -249,13 +253,15 @@ pub struct SeesThis { pub self_: *mut SeesThis, } impl CopyAssignableUnsafe for SeesThis { - unsafe fn copy_assign(this: *mut Self, _a0: *const SeesThis) -> *mut SeesThis { + unsafe fn copy_assign(this: *mut Self, _a0: LvalueRefUnsafe>) -> *mut SeesThis { + let _a0 = (_a0.as_ptr() as *const SeesThis); (*this).self_ = this; return &mut (*this); } } impl MoveAssignableUnsafe for SeesThis { - unsafe fn move_assign(this: *mut Self, _a0: *mut SeesThis) -> *mut SeesThis { + unsafe fn move_assign(this: *mut Self, _a0: RvalueRefUnsafe) -> *mut SeesThis { + let _a0 = (_a0.as_ptr() as *mut SeesThis); (*this).self_ = this; return &mut (*this); } @@ -300,13 +306,15 @@ impl DefaultConstructibleUnsafe for Counted_int_ { } } impl MoveConstructibleUnsafe for Counted_int_ { - unsafe fn move_constructor(this: *mut Self, o: *mut Counted_int_) { + unsafe fn move_constructor(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))); } } impl MoveAssignableUnsafe for Counted_int_ { - unsafe fn move_assign(this: *mut Self, o: *mut Counted_int_) -> *mut Counted_int_ { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Counted_int_ { + let o = (o.as_ptr() as *mut Counted_int_); (*this).v = (*o).v; (*this).moves = (((*o).moves) + (1)); return &mut (*this); @@ -359,24 +367,34 @@ impl DefaultConstructibleUnsafe for CtorSeesThis { } } impl CopyConstructibleUnsafe for CtorSeesThis { - unsafe fn copy_constructor(this: *mut Self, _a0: *const CtorSeesThis) { + unsafe fn copy_constructor(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: *mut CtorSeesThis) { + unsafe fn move_constructor(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); } } impl CopyAssignableUnsafe for CtorSeesThis { - unsafe fn copy_assign(this: *mut Self, _a0: *const CtorSeesThis) -> *mut CtorSeesThis { + unsafe fn copy_assign( + this: *mut Self, + _a0: LvalueRefUnsafe>, + ) -> *mut CtorSeesThis { + let _a0 = (_a0.as_ptr() as *const CtorSeesThis); return &mut (*this); } } impl MoveAssignableUnsafe for CtorSeesThis { - unsafe fn move_assign(this: *mut Self, _a0: *mut CtorSeesThis) -> *mut CtorSeesThis { + unsafe fn move_assign( + this: *mut Self, + _a0: RvalueRefUnsafe, + ) -> *mut CtorSeesThis { + let _a0 = (_a0.as_ptr() as *mut CtorSeesThis); return &mut (*this); } } @@ -459,8 +477,12 @@ impl OutOfLineDefaulted { } } impl CopyConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn copy_constructor(this: *mut Self, _a0: *const OutOfLineDefaulted) { - ConstructFromUnsafe::construct_from(&raw mut (*this).x, &(*_a0).x); + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const OutOfLineDefaulted); + CopyConstructibleUnsafe::copy_constructor( + &raw mut (*this).x, + LvalueRefUnsafe::bind(&(*_a0).x), + ); (&raw mut (*this).v).write((*_a0).v); } } @@ -509,23 +531,31 @@ impl Default for OutOfLineAssign { } } impl CopyAssignableUnsafe for OutOfLineAssign { - unsafe fn copy_assign(this: *mut Self, _a0: *const OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn copy_assign( + this: *mut Self, + _a0: LvalueRefUnsafe>, + ) -> *mut OutOfLineAssign { + let _a0 = (_a0.as_ptr() as *const OutOfLineAssign); (unsafe { let _arg0: *const SeesThis = &(*_a0).s; assign_unsafe!((*this).s = *_arg0) }); (*this).v = (*_a0).v; { - AssignFromUnsafe::assign_from(&raw mut (*this).w, &(*_a0).w); + CopyAssignableUnsafe::copy_assign(&raw mut (*this).w, LvalueRefUnsafe::bind(&(*_a0).w)); }; return &mut (*this); } } impl MoveAssignableUnsafe for OutOfLineAssign { - unsafe fn move_assign(this: *mut Self, _a0: *mut OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn move_assign( + this: *mut Self, + _a0: RvalueRefUnsafe, + ) -> *mut OutOfLineAssign { + let _a0 = (_a0.as_ptr() as *mut OutOfLineAssign); (unsafe { let _arg0: *mut SeesThis = &mut (*_a0).s; - assign_unsafe!((*this).s = Moved(*_arg0)) + assign_unsafe!((*this).s = RvalueRefUnsafe(*_arg0)) }); (*this).v = (*_a0).v; { @@ -561,7 +591,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(e, Explicit(2)); object_unsafe!(f, Explicit(3)); assign_unsafe!(e = b); - assign_unsafe!(f = Moved(c)); + assign_unsafe!(f = RvalueRefUnsafe(c)); assert!((unsafe { same_0(&e, &b,) }) && (unsafe { same_0(&f, &c,) })); object_unsafe!(g, Explicit(4)); assign_unsafe!(g = (*assign_unsafe!(e = f))); @@ -595,30 +625,30 @@ unsafe fn main_0() -> i32 { assert!(((vec_[(0_usize)].v) == (1)) && ((vec_[(1_usize)].v) == (9))); object_unsafe!(m, DefaultCopyUserMove(7)); let mut m1: DefaultCopyUserMove = m; - object_unsafe!(m2, DefaultCopyUserMove, Moved(&mut m)); + object_unsafe!(m2, DefaultCopyUserMove, RvalueRefUnsafe::bind(&mut m)); assert!((((m1.v) == (7)) && ((m2.v) == (7))) && ((m.v) == (0))); object_unsafe!(m3, DefaultCopyUserMove(1)); object_unsafe!(m4, DefaultCopyUserMove(1)); assign_unsafe!(m3 = m1); - assign_unsafe!(m4 = Moved(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, &u); - object_unsafe!(u2, UserCopyDefaultMove, Moved(&mut u)); + object_unsafe!(u1, UserCopyDefaultMove, LvalueRefUnsafe::bind(&u)); + object_unsafe!(u2, UserCopyDefaultMove, RvalueRefUnsafe::bind(&mut u)); assert!((((u1.v) == (108)) && ((u2.v) == (8))) && ((u.v) == (8))); object_unsafe!(u3, UserCopyDefaultMove(1)); object_unsafe!(u4, UserCopyDefaultMove(1)); assign_unsafe!(u3 = u2); - assign_unsafe!(u4 = Moved(u2)); + assign_unsafe!(u4 = RvalueRefUnsafe(u2)); assert!(((u3.v) == (108)) && ((u4.v) == (8))); object_unsafe!(p, Buffer(3)); - object_unsafe!(q, Buffer, Moved(&mut p)); + object_unsafe!(q, Buffer, 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)); - assign_unsafe!(r = Moved(q)); + assign_unsafe!(r = RvalueRefUnsafe(q)); assert!( ((((r.n) == (3)) && ((r.data.len()) == (3_usize))) && ((r.arr[(1) as usize]) == (4))) && (q.data.is_empty()) @@ -633,7 +663,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { { let mut __v: Buffer = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut bufs[(0_usize)])); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut bufs[(0_usize)]), + ); __v } }; @@ -659,7 +692,7 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(__tmp_3)) } }; - object_unsafe!(o2, Owner, Moved(&mut o1)); + object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o1)); assert!( ((((o2.n) == (5)) && ((o2.data.len()) == (1_usize))) && ((o2.arr[(1) as usize]) == (6))) && ((*o2 @@ -677,7 +710,7 @@ unsafe fn main_0() -> i32 { .is_null()) ); object_unsafe!(o3, Owner); - assign_unsafe!(o3 = Moved(o2)); + assign_unsafe!(o3 = RvalueRefUnsafe(o2)); assert!( ((((o3.n) == (5)) && ((o3.data[(0_usize)]) == (5))) && ((o3.arr[(0) as usize]) == (5))) && ((*o3 @@ -698,11 +731,11 @@ unsafe fn main_0() -> i32 { data: Vec::from([1, 2]), }; let mut c2: Copyable = c1.clone(); - object_unsafe!(c3, Copyable, Moved(&mut c1)); + object_unsafe!(c3, Copyable, RvalueRefUnsafe::bind(&mut c1)); assert!(((c2.data.len()) == (2_usize)) && ((c3.data.len()) == (2_usize))); assert!(c1.data.is_empty()); object_unsafe!(c4, Copyable); - assign_unsafe!(c4 = Moved(c3)); + assign_unsafe!(c4 = RvalueRefUnsafe(c3)); assert!(((c4.data[(1_usize)]) == (2)) && (c3.data.is_empty())); object_unsafe!(h1, Holder(4)); { @@ -713,7 +746,7 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(__tmp_4)) } }; - object_unsafe!(h2, Holder, Moved(&mut h1)); + object_unsafe!(h2, Holder, RvalueRefUnsafe::bind(&mut h1)); assert!( ((((h2.inner.x) == (4)) && ((h2.e.v) == (4))) && ((*h2 @@ -728,7 +761,7 @@ unsafe fn main_0() -> i32 { .is_null()) ); object_unsafe!(h3, Holder(1)); - assign_unsafe!(h3 = Moved(h2)); + assign_unsafe!(h3 = RvalueRefUnsafe(h2)); assert!( ((((h3.inner.x) == (4)) && ((h3.e.arr[(1) as usize]) == (5))) && ((*h3 @@ -745,30 +778,30 @@ unsafe fn main_0() -> i32 { object_unsafe!(t1, HasSeesThis); object_unsafe!(t2, HasSeesThis); object_unsafe!(t3, HasSeesThis); - assign_unsafe!(t2 = Moved(t1)); + 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, Moved(&mut k1)); + object_unsafe!(k2, HasCounted, RvalueRefUnsafe::bind(&mut k1)); assert!(((k2.c.moves) == (1))); object_unsafe!(k3, HasCounted); - assign_unsafe!(k3 = Moved(k2)); + assign_unsafe!(k3 = RvalueRefUnsafe(k2)); assert!(((k3.c.moves) == (2))); { object_unsafe!(d, CtorSeesThis); assert!(((d.self_) == (&mut d as *mut CtorSeesThis))); - object_unsafe!(e, CtorSeesThis, &d); + object_unsafe!(e, CtorSeesThis, LvalueRefUnsafe::bind(&d)); assert!(((e.self_) == (&mut e as *mut CtorSeesThis))); object_unsafe!(f, CtorSeesThis::construct_1(3)); assert!(((f.self_) == (&mut f as *mut CtorSeesThis)) && ((f.id) == (3))); object_unsafe!(h1, HasCtorSeesThis); assert!(((h1.x.self_) == (&mut h1.x as *mut CtorSeesThis))); - object_unsafe!(h2, HasCtorSeesThis, &h1); + object_unsafe!(h2, HasCtorSeesThis, LvalueRefUnsafe::bind(&h1)); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); - object_unsafe!(h3, HasCtorSeesThis, Moved(&mut h1)); + object_unsafe!(h3, HasCtorSeesThis, RvalueRefUnsafe::bind(&mut h1)); assert!(((h3.x.self_) == (&mut h3.x as *mut CtorSeesThis))); - assign_unsafe!(h2 = Moved(h3)); + 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))); @@ -790,7 +823,7 @@ 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, &o1); + object_unsafe!(o2, OutOfLineDefaulted, LvalueRefUnsafe::bind(&o1)); assert!(((o2.v) == (2)) && ((o2.x.self_) == (&mut o2.x as *mut CtorSeesThis))); object_unsafe!(a1, OutOfLineAssign); object_unsafe!(a2, OutOfLineAssign); @@ -803,7 +836,7 @@ unsafe fn main_0() -> i32 { assign_unsafe!(a2 = a1); assert!((((a2.v) == (3)) && ((a2.w.len()) == (1_usize))) && ((a1.w.len()) == (1_usize))); assert!(((a2.s.self_) == (&mut a2.s as *mut SeesThis))); - assign_unsafe!(a3 = Moved(a2)); + assign_unsafe!(a3 = RvalueRefUnsafe(a2)); assert!( (((a3.v) == (3)) && ((a3.w.len()) == (1_usize))) && ((a3.s.self_) == (&mut a3.s as *mut SeesThis)) diff --git a/tests/unit/out/unsafe/copy_move_deleted.rs b/tests/unit/out/unsafe/copy_move_deleted.rs index d2aebc4c55..be888a3cd0 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.rs @@ -25,13 +25,15 @@ impl NoCopy { } } impl MoveConstructibleUnsafe for NoCopy { - unsafe fn move_constructor(this: *mut Self, o: *mut NoCopy) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut NoCopy); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for NoCopy { - unsafe fn move_assign(this: *mut Self, o: *mut NoCopy) -> *mut NoCopy { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut NoCopy { + let o = (o.as_ptr() as *mut NoCopy); (*this).v = (*o).v; (*o).v = 0; return &mut (*this); @@ -48,13 +50,15 @@ impl DefaultConstructibleUnsafe for PrivateCopy { } } impl MoveConstructibleUnsafe for PrivateCopy { - unsafe fn move_constructor(this: *mut Self, o: *mut PrivateCopy) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut PrivateCopy); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for PrivateCopy { - unsafe fn move_assign(this: *mut Self, o: *mut PrivateCopy) -> *mut PrivateCopy { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut PrivateCopy { + let o = (o.as_ptr() as *mut PrivateCopy); (*this).v = (*o).v; (*o).v = 0; return &mut (*this); @@ -138,17 +142,17 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(a, NoCopy(1)); - object_unsafe!(b, NoCopy, Moved(&mut a)); + object_unsafe!(b, NoCopy, RvalueRefUnsafe::bind(&mut a)); assert!(((b.v) == (1)) && ((a.v) == (0))); - assign_unsafe!(a = Moved(b)); + 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); p.v = 3; - object_unsafe!(q, PrivateCopy, Moved(&mut p)); + object_unsafe!(q, PrivateCopy, RvalueRefUnsafe::bind(&mut p)); assert!(((q.v) == (3)) && ((p.v) == (0))); - assign_unsafe!(p = Moved(q)); + assign_unsafe!(p = RvalueRefUnsafe(q)); assert!(((p.v) == (3)) && ((q.v) == (0))); object_unsafe!(im, Immovable); im.v = 4; @@ -163,20 +167,20 @@ unsafe fn main_0() -> i32 { }, tag: 7, }; - object_unsafe!(d, Container, Moved(&mut c)); + object_unsafe!(d, Container, RvalueRefUnsafe::bind(&mut c)); assert!((((d.inner.v) == (6)) && ((d.tag) == (7))) && ((c.inner.v) == (0))); object_unsafe!(h, VecHolder); - object_unsafe!(h2, VecHolder, Moved(&mut h)); + object_unsafe!(h2, VecHolder, RvalueRefUnsafe::bind(&mut h)); assert!(((h2.items.len()) == (0_usize))); return 0; } impl CopyAssignableUnsafe for PrivateCopy { - unsafe fn copy_assign(this: *mut Self, _: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, _: LvalueRefUnsafe>) -> *mut Self { unreachable!("PrivateCopy::copy_assign is never defined") } } impl CopyConstructibleUnsafe for PrivateCopy { - unsafe fn copy_constructor(this: *mut Self, _: *const Self) { + unsafe fn copy_constructor(this: *mut Self, _: LvalueRefUnsafe>) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index 02770b369d..dfedc383e9 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -67,7 +67,8 @@ impl MoveOnly { } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, x: *mut MoveOnly) { + unsafe fn move_constructor(this: *mut Self, x: RvalueRefUnsafe) { + let x = (x.as_ptr() as *mut MoveOnly); (&raw mut (*this).data_).write((*x).data_); (*x).data_ = 0; } @@ -120,7 +121,7 @@ unsafe fn main_0() -> i32 { let mut sc: Option = Some(scale_move_only_3); object_unsafe!(n, MoveOnly, |n| (unsafe { let mut _arg0: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut _arg0, Moved(&mut m)); + MoveConstructibleUnsafe::move_constructor(&raw mut _arg0, RvalueRefUnsafe::bind(&mut m)); (sc).unwrap()(n, &mut _arg0) })); assert!(((unsafe { MoveOnly::get(&raw const n,) }) == (40))); diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 36855b01cc..a6c2edcaf1 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -27,14 +27,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(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: *mut Tracked) { + unsafe fn move_constructor(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); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -49,12 +51,12 @@ pub unsafe fn chosen_overload_1(_a0: *mut Tracked) -> Overload { } impl Holder { pub unsafe fn construct_1(this: *mut Self, x: *mut Tracked) { - ConstructFromUnsafe::construct_from(&raw mut (*this).t, x); + CopyConstructibleUnsafe::copy_constructor(&raw mut (*this).t, LvalueRefUnsafe::bind(x)); } } impl Holder { pub unsafe fn construct_2(this: *mut Self, x: *mut Tracked) { - ConstructFromUnsafe::construct_from(&raw mut (*this).t, Moved(x)); + MoveConstructibleUnsafe::move_constructor(&raw mut (*this).t, RvalueRefUnsafe::bind(x)); } } #[repr(C)] diff --git a/tests/unit/out/unsafe/forward_decltype.rs b/tests/unit/out/unsafe/forward_decltype.rs index 719d60dd5d..6c78d55ef1 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -27,14 +27,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(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: *mut Tracked) { + unsafe fn move_constructor(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); (&raw mut (*this).moves).write((((*o).moves) + (1))); diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index d787f5307c..e5f675c7ce 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -29,14 +29,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(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: *mut Tracked) { + unsafe fn move_constructor(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); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -56,7 +58,7 @@ 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) { - ConstructFromUnsafe::construct_from(__return, Moved(t)); + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(t)); return; } pub fn main() { @@ -76,7 +78,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(b, Tracked(6)); object_unsafe!(moved, Tracked, |moved| (unsafe { let mut _t: Tracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut _t, Moved(&mut b)); + MoveConstructibleUnsafe::move_constructor(&raw mut _t, RvalueRefUnsafe::bind(&mut b)); copy_or_move_into_param_4(moved, &mut _t) })); assert!(((moved.v) == (6))); @@ -86,7 +88,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(c, Tracked(7)); object_unsafe!(copied, Tracked, |copied| (unsafe { let mut _t: Tracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut _t, &c); + CopyConstructibleUnsafe::copy_constructor(&raw mut _t, LvalueRefUnsafe::bind(&c)); copy_or_move_into_param_4(copied, &mut _t) })); assert!(((copied.v) == (7))); diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index f848da77e0..5b7c949f79 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -29,14 +29,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(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: *mut Tracked) { + unsafe fn move_constructor(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); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -91,8 +93,8 @@ pub unsafe fn forward_pack_7( } impl Pair { pub unsafe fn construct(this: *mut Self, x: *mut Tracked, y: *mut Tracked) { - ConstructFromUnsafe::construct_from(&raw mut (*this).a, x); - ConstructFromUnsafe::construct_from(&raw mut (*this).b, Moved(y)); + CopyConstructibleUnsafe::copy_constructor(&raw mut (*this).a, LvalueRefUnsafe::bind(x)); + MoveConstructibleUnsafe::move_constructor(&raw mut (*this).b, RvalueRefUnsafe::bind(y)); } } #[repr(C)] diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index 47a07f2ea9..ff19c40209 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -148,27 +148,31 @@ impl DefaultConstructibleUnsafe for Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: *const Counted) { + unsafe fn copy_constructor(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: *mut Counted) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Counted); (&raw mut (*this).v).write((*o).v); (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); } } impl CopyAssignableUnsafe for Counted { - unsafe fn copy_assign(this: *mut Self, o: *const Counted) -> *mut Counted { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Counted { + let o = (o.as_ptr() as *const Counted); (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_assigns_4)).prefix_inc(); return &mut (*this); } } impl MoveAssignableUnsafe for Counted { - unsafe fn move_assign(this: *mut Self, o: *mut Counted) -> *mut Counted { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Counted { + let o = (o.as_ptr() as *mut Counted); (*this).v = (*o).v; (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_5)).prefix_inc(); @@ -249,7 +253,7 @@ unsafe fn main_0() -> i32 { assert!( ((elems[(1_usize)].hist[(2) as usize]) == (5)) && (((*first).hist[(2) as usize]) == (0)) ); - object_unsafe!(moved, State, Moved(&mut t)); + object_unsafe!(moved, State, RvalueRefUnsafe::bind(&mut t)); assert!( ((moved.grid[(0) as usize][(0) as usize]) == (100)) && ((moved.grid[(1) as usize][(2) as usize]) == (5)) @@ -257,7 +261,7 @@ unsafe fn main_0() -> i32 { assert!((((moved.elems.len()) == (4_usize)) && (t.elems.is_empty())) && (t.rows.is_empty())); assert!(((moved.arr[(1_usize)]) == (7)) && ((t.arr[(1_usize)]) == (7))); let mut assigned: State = ::default(); - assign_unsafe!(assigned = Moved(moved)); + assign_unsafe!(assigned = RvalueRefUnsafe(moved)); assert!( ((assigned.grid[(0) as usize][(0) as usize]) == (100)) && ((assigned.grid[(1) as usize][(1) as usize]) == (4)) @@ -295,7 +299,7 @@ unsafe fn main_0() -> i32 { ); { for __i in 0..3 { - assign_unsafe!(ca[__i] = Moved(cb[__i])); + assign_unsafe!(ca[__i] = RvalueRefUnsafe(cb[__i])); } }; assert!( @@ -319,7 +323,7 @@ unsafe fn main_0() -> i32 { let mut vc: [Vec; 2] = std::array::from_fn::<_, 2, _>(|_| Default::default()); { for __i in 0..2 { - assign_unsafe!(vc[__i] = Moved(vb[__i])); + assign_unsafe!(vc[__i] = RvalueRefUnsafe(vb[__i])); } }; assert!(((vc[(0_usize)].len()) == (1_usize)) && (vb[(0_usize)].is_empty())); diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index 9427def813..509d44bfd8 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -107,8 +107,9 @@ impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { impl MoveConstructibleUnsafe for Moving__lambda_at_lambda_as_field_cpp_64_12__ { unsafe fn move_constructor( this: *mut Self, - o: *mut Moving__lambda_at_lambda_as_field_cpp_64_12__, + o: RvalueRefUnsafe, ) { + let o = (o.as_ptr() as *mut Moving__lambda_at_lambda_as_field_cpp_64_12__); (&raw mut (*this).f).write((*o).f.move_from()); (&raw mut (*this).moves).write((((*o).moves) + (1))); } @@ -239,7 +240,7 @@ unsafe fn main_0() -> i32 { object_unsafe!( m2, Moving__lambda_at_lambda_as_field_cpp_64_12__, - Moved(&mut m) + 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 9fdb98268b..122501d962 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -19,13 +19,15 @@ impl DefaultConstructibleUnsafe for Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: *const Counted) { + unsafe fn copy_constructor(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: *mut Counted) { + unsafe fn move_constructor(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))); } @@ -49,10 +51,14 @@ impl DefaultConstructibleUnsafe for Dropped { unsafe fn default_constructor(this: *mut Self) {} } impl CopyConstructibleUnsafe for Dropped { - unsafe fn copy_constructor(this: *mut Self, _a0: *const Dropped) {} + unsafe fn copy_constructor(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: *mut Dropped) {} + unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { + let _a0 = (_a0.as_ptr() as *mut Dropped); + } } impl DestructibleUnsafe for Dropped { unsafe fn destroy(this: *mut Self) { @@ -71,7 +77,7 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &c); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&c)); __v }; }, @@ -93,12 +99,18 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &c); + CopyConstructibleUnsafe::copy_constructor( + &raw mut __v, + LvalueRefUnsafe::bind(&c), + ); __v }; }, |__return: *mut Counted| { - ConstructFromUnsafe::construct_from(__return, &c); + CopyConstructibleUnsafe::copy_constructor( + __return, + LvalueRefUnsafe::bind(&c), + ); return; } ) @@ -118,7 +130,10 @@ unsafe fn main_0() -> i32 { { let arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|__i: usize| { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &arr[(__i)]); + CopyConstructibleUnsafe::copy_constructor( + &raw mut __v, + LvalueRefUnsafe::bind(&arr[(__i)]), + ); __v }); }, diff --git a/tests/unit/out/unsafe/lambda_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index 1c66791fba..465e9ffbb8 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -21,7 +21,10 @@ impl Owner { { let self_: Owner = { let mut __v: Owner = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut (*this))); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut (*this)), + ); __v }; }, @@ -32,7 +35,8 @@ impl Owner { } } impl MoveConstructibleUnsafe for Owner { - unsafe fn move_constructor(this: *mut Self, o: *mut 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(); } @@ -59,7 +63,10 @@ unsafe fn main_0() -> i32 { { let h: Owner = { let mut __v: Owner = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut o)); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut o), + ); __v }; }, diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 25fd06ce01..6079a7fda5 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -23,13 +23,15 @@ impl Key { } } impl CopyConstructibleUnsafe for Key { - unsafe fn copy_constructor(this: *mut Self, o: *const Key) { + unsafe fn copy_constructor(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: *mut Key) { + unsafe fn move_constructor(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(); } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index a752caad76..9e806e81cf 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -28,13 +28,15 @@ impl DefaultConstructibleUnsafe for Item { } } impl CopyConstructibleUnsafe for Item { - unsafe fn copy_constructor(this: *mut Self, other: *const Item) { + unsafe fn copy_constructor(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: *mut Item) { + unsafe fn move_constructor(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(); (*other).value = -1_i32; @@ -266,14 +268,16 @@ 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(); - ConstructFromUnsafe::construct_from(&raw mut __v, __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 = ::zero_init(); + CopyConstructibleUnsafe::copy_constructor(&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))) @@ -282,14 +286,17 @@ 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(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__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 = ::zero_init(); + MoveConstructibleUnsafe::move_constructor(&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))) @@ -299,14 +306,16 @@ 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(); - ConstructFromUnsafe::construct_from(&raw mut __v, __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 = ::zero_init(); + CopyConstructibleUnsafe::copy_constructor(&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))) @@ -316,14 +325,16 @@ 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(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__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 = ::zero_init(); + MoveConstructibleUnsafe::move_constructor(&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))) @@ -394,7 +405,10 @@ unsafe fn main_0() -> i32 { { (__tmp_12,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_12)); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(__tmp_12), + ); __v }), } @@ -417,7 +431,10 @@ unsafe fn main_0() -> i32 { { (__tmp_14,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_14)); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(__tmp_14), + ); __v }), } diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 167feb8bec..927725fa71 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -39,7 +39,8 @@ impl Bag { } } impl CopyConstructibleUnsafe for Bag { - unsafe fn copy_constructor(this: *mut Self, o: *const Bag) { + unsafe fn copy_constructor(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(); } diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index d8a0ea3fa0..dd069c5785 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -25,13 +25,15 @@ impl MoveOnly { } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, o: *mut MoveOnly) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut MoveOnly); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for MoveOnly { - unsafe fn move_assign(this: *mut Self, o: *mut MoveOnly) -> *mut MoveOnly { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut MoveOnly { + let o = (o.as_ptr() as *mut MoveOnly); if ((this) == (o)) { return &mut (*this); } @@ -79,7 +81,7 @@ impl Default for ConstMoveAssign { } pub unsafe fn make_0(__return: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(__return, Moved(&mut m)); + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -92,31 +94,31 @@ unsafe fn main_0() -> i32 { object_unsafe!(a, MoveOnly(1)); object_unsafe!(b, MoveOnly(2)); object_unsafe!(c, MoveOnly(3)); - assign_unsafe!(a = Moved(b)); + 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); - assign_unsafe!(b = Moved(_o)) + assign_unsafe!(b = RvalueRefUnsafe(_o)) }); - assign_unsafe!(c = Moved((*assign_unsafe!(a = Moved(b))))); + 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); - assign_unsafe!(a = Moved(_o)) + assign_unsafe!(a = RvalueRefUnsafe(_o)) }); assert!(((a.v) == (5))); (unsafe { let mut _o: MoveOnly = ::zero_init(); (unsafe { make_0(&raw mut _o, 6) }); - assign_unsafe!(a = Moved(_o)) + assign_unsafe!(a = RvalueRefUnsafe(_o)) }); assert!(((a.v) == (6))); (unsafe { let _o: *mut MoveOnly = &mut a; - assign_unsafe!(a = Moved(*_o)) + assign_unsafe!(a = RvalueRefUnsafe(*_o)) }); assert!(((a.v) == (6))); let mut vec_: Vec = Vec::new(); @@ -131,7 +133,7 @@ unsafe fn main_0() -> i32 { } }; object_unsafe!(d, MoveOnly(8)); - assign_unsafe!(vec_[(0_usize)] = Moved(d)); + assign_unsafe!(vec_[(0_usize)] = RvalueRefUnsafe(d)); assert!(((vec_[(0_usize)].v) == (8))); assert!(((d.v) == (0))); object_unsafe!(m, ConstMoveAssign); diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index 314099031b..19b86d5dfd 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -20,7 +20,8 @@ impl MoveOnly { } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, o: *mut MoveOnly) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut MoveOnly); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } @@ -72,14 +73,16 @@ impl ThrowingMove { } } impl CopyConstructibleUnsafe for ThrowingMove { - unsafe fn copy_constructor(this: *mut Self, o: *const ThrowingMove) { + unsafe fn copy_constructor(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: *mut ThrowingMove) { + unsafe fn move_constructor(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); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -104,14 +107,16 @@ impl NoexceptMove { } } impl CopyConstructibleUnsafe for NoexceptMove { - unsafe fn copy_constructor(this: *mut Self, o: *const NoexceptMove) { + unsafe fn copy_constructor(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: *mut NoexceptMove) { + unsafe fn move_constructor(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); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -123,7 +128,7 @@ pub unsafe fn by_value_0(m: *mut MoveOnly) -> i32 { } pub unsafe fn make_1(__return: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(__return, Moved(&mut m)); + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -134,13 +139,13 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(a, MoveOnly(1)); - object_unsafe!(b, MoveOnly, Moved(&mut a)); + object_unsafe!(b, MoveOnly, RvalueRefUnsafe::bind(&mut a)); assert!(((b.v) == (1))); assert!(((a.v) == (0))); - object_unsafe!(c, MoveOnly, Moved(&mut b)); + object_unsafe!(c, MoveOnly, RvalueRefUnsafe::bind(&mut b)); assert!(((c.v) == (1))); assert!(((b.v) == (0))); - object_unsafe!(d, MoveOnly, Moved(&mut c)); + object_unsafe!(d, MoveOnly, RvalueRefUnsafe::bind(&mut c)); assert!(((d.v) == (1))); assert!(((c.v) == (0))); object_unsafe!(e, MoveOnly, |e| (unsafe { make_1(e, 5,) })); @@ -155,7 +160,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _m: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut _m, Moved(&mut e)); + MoveConstructibleUnsafe::move_constructor(&raw mut _m, RvalueRefUnsafe::bind(&mut e)); by_value_0(&mut _m) }) == (5)) ); @@ -182,19 +187,19 @@ unsafe fn main_0() -> i32 { assert!(((m1.mark) == (1))); assert!(((m2.mark) == (10))); object_unsafe!(t, ThrowingMove(1)); - object_unsafe!(t1, ThrowingMove, &t); + object_unsafe!(t1, ThrowingMove, 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, Moved(&mut n)); + object_unsafe!(n1, NoexceptMove, 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, Moved(&mut g)); + object_unsafe!(g1, MoveOnly, RvalueRefUnsafe::bind(&mut g)); assert!(((g1.v) == (3))); assert!(((g.v) == (0))); let mut nv: Vec = Vec::new(); diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index 65caaec186..ef8486e171 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -27,11 +27,11 @@ impl Chain { return &mut (*this); } pub unsafe fn take(this: *mut Self, __return: *mut Chain) { - ConstructFromUnsafe::construct_from(__return, Moved(&mut (*this))); + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut (*this))); return; } pub unsafe fn copy(this: *const Self, __return: *mut Chain) { - ConstructFromUnsafe::construct_from(__return, &(*this)); + CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(&(*this))); return; } pub unsafe fn self_(this: *mut Self) -> *mut Chain { @@ -39,12 +39,14 @@ impl Chain { } } impl CopyConstructibleUnsafe for Chain { - unsafe fn copy_constructor(this: *mut Self, o: *const 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: *mut 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; } @@ -66,7 +68,9 @@ unsafe fn main_0() -> i32 { object_unsafe!( b, Chain, - Moved((unsafe { Chain::add_5(&mut (*(unsafe { Chain::add_5(&raw mut b0, 1,) })), 1,) })) + 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| { @@ -88,9 +92,9 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _c: Chain = ::zero_init(); - ConstructFromUnsafe::construct_from( + MoveConstructibleUnsafe::move_constructor( &raw mut _c, - Moved((unsafe { Chain::self_(&raw mut g) })), + RvalueRefUnsafe::bind((unsafe { Chain::self_(&raw mut g) })), ); consume_0(&mut _c) }) == (21)) diff --git a/tests/unit/out/unsafe/pair.rs b/tests/unit/out/unsafe/pair.rs index 281a52e939..ea56436da7 100644 --- a/tests/unit/out/unsafe/pair.rs +++ b/tests/unit/out/unsafe/pair.rs @@ -67,8 +67,8 @@ unsafe fn main_0() -> i32 { let mut pd: *mut i32 = (&mut d.0 as *mut i32); let mut ps: *mut i32 = (&mut s.0 as *mut i32); { - assign_unsafe!(d.0 = Moved(s.0)); - assign_unsafe!(d.1 = Moved(s.1)); + assign_unsafe!(d.0 = RvalueRefUnsafe(s.0)); + assign_unsafe!(d.1 = RvalueRefUnsafe(s.1)); }; assert!(((*pd) == (3))); (*ps) = 5; @@ -94,8 +94,8 @@ unsafe fn main_0() -> i32 { .1 = 7; assert!(((p.1) == (7)) && ((q.1) == (4))); (*{ - assign_unsafe!(d.0 = Moved(q.0)); - assign_unsafe!(d.1 = Moved(q.1)); + assign_unsafe!(d.0 = RvalueRefUnsafe(q.0)); + assign_unsafe!(d.1 = RvalueRefUnsafe(q.1)); &mut d }) .0 = 8; diff --git a/tests/unit/out/unsafe/rule_of_five.rs b/tests/unit/out/unsafe/rule_of_five.rs index 118d336ff1..22858790f7 100644 --- a/tests/unit/out/unsafe/rule_of_five.rs +++ b/tests/unit/out/unsafe/rule_of_five.rs @@ -40,7 +40,8 @@ impl DestructibleUnsafe for Buffer { } } impl CopyConstructibleUnsafe for Buffer { - unsafe fn copy_constructor(this: *mut Self, o: *const Buffer) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Buffer); (&raw mut (*this).data).write([0_i32; 4]); (&raw mut (*this).size).write((*o).size); { @@ -57,7 +58,8 @@ impl CopyConstructibleUnsafe for Buffer { } } impl MoveConstructibleUnsafe for Buffer { - unsafe fn move_constructor(this: *mut Self, o: *mut Buffer) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Buffer); (&raw mut (*this).data).write([0_i32; 4]); (&raw mut (*this).size).write((*o).size); { @@ -76,7 +78,8 @@ impl MoveConstructibleUnsafe for Buffer { } } impl CopyAssignableUnsafe for Buffer { - unsafe fn copy_assign(this: *mut Self, o: *const Buffer) -> *mut Buffer { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Buffer { + let o = (o.as_ptr() as *const Buffer); if (((this).cast_const()) == (o)) { return &mut (*this); } @@ -95,7 +98,8 @@ impl CopyAssignableUnsafe for Buffer { } } impl MoveAssignableUnsafe for Buffer { - unsafe fn move_assign(this: *mut Self, o: *mut Buffer) -> *mut Buffer { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Buffer { + let o = (o.as_ptr() as *mut Buffer); if ((this) == (o)) { return &mut (*this); } @@ -117,7 +121,7 @@ impl MoveAssignableUnsafe for Buffer { } pub unsafe fn make_3(__return: *mut Buffer, mut size: i32) { object_unsafe!(b, Buffer(size)); - ConstructFromUnsafe::construct_from(__return, Moved(&mut b)); + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut b)); return; } pub fn main() { @@ -129,7 +133,7 @@ pub fn main() { unsafe fn main_0() -> i32 { { object_unsafe!(a, Buffer(4)); - object_unsafe!(b, Buffer, &a); + object_unsafe!(b, Buffer, LvalueRefUnsafe::bind(&a)); assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (1))) @@ -137,7 +141,7 @@ unsafe fn main_0() -> i32 { ); b.data[(0) as usize] = 100; assert!(((a.data[(0) as usize]) == (0))); - object_unsafe!(c, Buffer, Moved(&mut a)); + object_unsafe!(c, Buffer, RvalueRefUnsafe::bind(&mut a)); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (3)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (1)) @@ -153,14 +157,14 @@ unsafe fn main_0() -> i32 { (((d.size) == (4)) && ((d.data[(0) as usize]) == (100))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (2)) ); - assign_unsafe!(d = Moved(c)); + assign_unsafe!(d = RvalueRefUnsafe(c)); assert!( (((d.data[(0) as usize]) == (0)) && ((c.size) == (0))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (3)) ); (unsafe { let _o: *mut Buffer = &mut d; - assign_unsafe!(d = Moved(*_o)) + assign_unsafe!(d = RvalueRefUnsafe(*_o)) }); assert!( ((d.size) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (3)) diff --git a/tests/unit/out/unsafe/rule_of_three.rs b/tests/unit/out/unsafe/rule_of_three.rs index b616469915..2f80927abb 100644 --- a/tests/unit/out/unsafe/rule_of_three.rs +++ b/tests/unit/out/unsafe/rule_of_three.rs @@ -45,7 +45,8 @@ impl DestructibleUnsafe for Buffer { } } impl CopyConstructibleUnsafe for Buffer { - unsafe fn copy_constructor(this: *mut Self, o: *const Buffer) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Buffer); (&raw mut (*this).data).write([0_i32; 4]); (&raw mut (*this).size).write((*o).size); { @@ -62,7 +63,8 @@ impl CopyConstructibleUnsafe for Buffer { } } impl CopyAssignableUnsafe for Buffer { - unsafe fn copy_assign(this: *mut Self, o: *const Buffer) -> *mut Buffer { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Buffer { + let o = (o.as_ptr() as *const Buffer); if (((this).cast_const()) == (o)) { return &mut (*this); } @@ -102,7 +104,7 @@ pub fn main() { unsafe fn main_0() -> i32 { { object_unsafe!(a, Buffer(4)); - object_unsafe!(b, Buffer, &a); + object_unsafe!(b, Buffer, LvalueRefUnsafe::bind(&a)); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (1)) @@ -123,7 +125,7 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (2))); assert!(((unsafe { sum_2(&a,) }) == (6))); assert!(((unsafe { sum_2(&b,) }) == (106))); - object_unsafe!(d, Buffer, &a); + object_unsafe!(d, Buffer, LvalueRefUnsafe::bind(&a)); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (3)) diff --git a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs index eadfe793de..26d09160bc 100644 --- a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs +++ b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs @@ -29,13 +29,15 @@ impl Elem { } } impl CopyConstructibleUnsafe for Elem { - unsafe fn copy_constructor(this: *mut Self, o: *const Elem) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Elem); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Elem { - unsafe fn move_constructor(this: *mut Self, o: *mut Elem) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Elem); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); } diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 5c80a1e374..06ea16e38f 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -54,7 +54,7 @@ pub unsafe fn size_t_in_rules_3() { let mut ar3: [u64; 3] = ar2.clone(); { for __i in 0..3 { - assign_unsafe!(ar3[__i] = Moved(ar[__i])); + assign_unsafe!(ar3[__i] = RvalueRefUnsafe(ar[__i])); } }; assert!(((ar3[1]) == (2_u64))); diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index cbbd9c9c64..ceca9eba85 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -26,25 +26,29 @@ impl DefaultConstructibleUnsafe for Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); } } impl CopyAssignableUnsafe for Tracked { - unsafe fn copy_assign(this: *mut Self, o: *const Tracked) -> *mut Tracked { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Tracked { + let o = (o.as_ptr() as *const Tracked); (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*this); } } impl MoveAssignableUnsafe for Tracked { - unsafe fn move_assign(this: *mut Self, o: *mut Tracked) -> *mut Tracked { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Tracked { + let o = (o.as_ptr() as *mut Tracked); (*this).v = (*o).v; return &mut (*this); } diff --git a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs index 68b884c264..e56c7afd7e 100644 --- a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs @@ -30,7 +30,8 @@ impl Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, other: *const Counted) { + unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const Counted); (&raw mut (*this).x).write((((*other).x) * (2))); (&raw mut (*this).y).write((((*other).y) * (2))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); @@ -50,7 +51,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(s, Counted(1, 2)); let mut __decomp_2: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &s); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&s)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); diff --git a/tests/unit/out/unsafe/structured_binding_element_ctor.rs b/tests/unit/out/unsafe/structured_binding_element_ctor.rs index 6340174390..5a8348d585 100644 --- a/tests/unit/out/unsafe/structured_binding_element_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_element_ctor.rs @@ -22,13 +22,15 @@ impl Elem { } } impl CopyConstructibleUnsafe for Elem { - unsafe fn copy_constructor(this: *mut Self, other: *const Elem) { + unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const Elem); (&raw mut (*this).v).write((((*other).v) + (100))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Elem { - unsafe fn move_constructor(this: *mut Self, other: *mut Elem) { + unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut Elem); (&raw mut (*this).v).write((((*other).v) + (1000))); (*other).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); @@ -81,7 +83,7 @@ unsafe fn main_0() -> i32 { let mut base_moves: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)); let mut __decomp_3: Two = { let mut __v: Two = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &t); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&t)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((base_copies) + (2)))); @@ -95,7 +97,7 @@ unsafe fn main_0() -> i32 { assert!(((t.a.v) == (50))); let mut __decomp_5: Two = { let mut __v: Two = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut t)); + MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(&mut t)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == ((base_moves) + (2)))); @@ -118,7 +120,10 @@ unsafe fn main_0() -> i32 { Elem::construct(&raw mut __tmp_0, 7); { let mut __v: Elem = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut __tmp_0)); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut __tmp_0), + ); __v } }, @@ -127,7 +132,10 @@ unsafe fn main_0() -> i32 { Elem::construct(&raw mut __tmp_1, 8); { let mut __v: Elem = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut __tmp_1)); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut __tmp_1), + ); __v } }, diff --git a/tests/unit/out/unsafe/structured_binding_move_ctor.rs b/tests/unit/out/unsafe/structured_binding_move_ctor.rs index 97dd30545a..1d18fde0d8 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -21,14 +21,16 @@ impl Movable { } } impl CopyConstructibleUnsafe for Movable { - unsafe fn copy_constructor(this: *mut Self, other: *const Movable) { + unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const Movable); (&raw mut (*this).x).write((*other).x); (&raw mut (*this).y).write((*other).y); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Movable { - unsafe fn move_constructor(this: *mut Self, other: *mut Movable) { + unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut Movable); (&raw mut (*this).x).write((*other).x); (&raw mut (*this).y).write((*other).y); (*other).x = 0; @@ -78,7 +80,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(m, Movable(3, 4)); let mut __decomp_2: Movable = { let mut __v: Movable = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut m)); + MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(&mut m)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (1))); diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index 492d0473ee..d802de8c86 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -26,25 +26,29 @@ impl DefaultConstructibleUnsafe for Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); } } impl CopyAssignableUnsafe for Tracked { - unsafe fn copy_assign(this: *mut Self, o: *const Tracked) -> *mut Tracked { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Tracked { + let o = (o.as_ptr() as *const Tracked); (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*this); } } impl MoveAssignableUnsafe for Tracked { - unsafe fn move_assign(this: *mut Self, o: *mut Tracked) -> *mut Tracked { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Tracked { + let o = (o.as_ptr() as *mut Tracked); (*this).v = (*o).v; return &mut (*this); } @@ -132,7 +136,8 @@ impl CopyOnly { } } impl CopyConstructibleUnsafe for CopyOnly { - unsafe fn copy_constructor(this: *mut Self, o: *const CopyOnly) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const CopyOnly); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)).prefix_inc(); } @@ -143,7 +148,8 @@ impl DestructibleUnsafe for CopyOnly { } } impl CopyAssignableUnsafe for CopyOnly { - unsafe fn copy_assign(this: *mut Self, o: *const CopyOnly) -> *mut CopyOnly { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut CopyOnly { + let o = (o.as_ptr() as *const CopyOnly); (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)).prefix_inc(); return &mut (*this); @@ -181,27 +187,31 @@ impl Moved { } } impl CopyConstructibleUnsafe for Moved { - unsafe fn copy_constructor(this: *mut Self, o: *const Moved) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Moved); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Moved { - unsafe fn move_constructor(this: *mut Self, o: *mut Moved) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Moved); (&raw mut (*this).v).write((*o).v); (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); } } impl CopyAssignableUnsafe for Moved { - unsafe fn copy_assign(this: *mut Self, o: *const Moved) -> *mut Moved { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Moved { + let o = (o.as_ptr() as *const Moved); (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*this); } } impl MoveAssignableUnsafe for Moved { - unsafe fn move_assign(this: *mut Self, o: *mut Moved) -> *mut Moved { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Moved { + let o = (o.as_ptr() as *mut Moved); (*this).v = (*o).v; (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)).prefix_inc(); @@ -289,7 +299,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -306,7 +316,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -324,7 +334,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -598,7 +608,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -615,7 +625,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; diff --git a/tests/unit/out/unsafe/vector2.rs b/tests/unit/out/unsafe/vector2.rs index 69dde434ba..723493103b 100644 --- a/tests/unit/out/unsafe/vector2.rs +++ b/tests/unit/out/unsafe/vector2.rs @@ -34,7 +34,7 @@ pub unsafe fn fn_0(v: *mut Vec, mut v3: Vec) { (v) }))[(0_usize)] = 7; { - AssignFromUnsafe::assign_from(&raw mut v2, v); + CopyAssignableUnsafe::copy_assign(&raw mut v2, LvalueRefUnsafe::bind(v)); }; (&mut (*v4))[(1_usize)] = 13; assert!(((x) == (6)));