diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 83a2225e74..72af86963a 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -816,11 +816,10 @@ void Converter::EmitScopedDestructor(const clang::VarDecl *decl) { if (!NeedsScopedDestructor(decl)) { return; } - StrCat( - token::kSemiColon, - std::format("let _dtor_{0} = std::mem::DropGuard::new(&raw mut {0}, " - "|__p| unsafe {{ DestructibleUnsafe::destroy(&mut *__p) }})", - GetNamedDeclAsString(decl))); + StrCat(token::kSemiColon, + std::format("let _dtor_{0} = std::mem::DropGuard::new(&raw mut {0}, " + "|__p| unsafe {{ DestructibleUnsafe::destroy(__p) }})", + GetNamedDeclAsString(decl))); } bool Converter::RecordDerivesDefault(const clang::RecordDecl *decl) { @@ -1087,7 +1086,7 @@ void Converter::AddAssignmentTraits(const clang::CXXRecordDecl *decl) { std::string Converter::GetAssignmentTraitSignature(const RecordTrait &trait) const { - return std::format("unsafe fn {}(&mut self, src: {} Self) -> *mut Self", + return std::format("unsafe fn {}(this: *mut Self, src: {} Self) -> *mut Self", trait.method, &trait == &kMoveAssignable ? "*mut" : "*const"); } @@ -1154,7 +1153,8 @@ std::string Converter::DestroyMembers(const clang::CXXRecordDecl *decl) { std::string out; for (auto *field : FieldsToDestroy(decl)) { auto name = GetNamedDeclAsString(field); - out += std::format("DestructibleUnsafe::destroy(&mut self.{});\n", name); + out += std::format("DestructibleUnsafe::destroy(&raw mut (*this).{});\n", + name); } return out; } @@ -1359,7 +1359,7 @@ bool Converter::ConvertCXXMethodDecl(clang::CXXMethodDecl *decl) { return VisitCXXConstructorDecl(ctor); } - if (method_target_ == MethodTarget::ValueImpl && !GetRecordTrait(decl) && + if (!GetRecordTrait(decl) && (decl->isStatic() || (!decl->isVirtual() && !decl->getParent()->isAbstract()))) { StrCat(AccessSpecifierAsString(decl->getAccess())); @@ -1374,11 +1374,8 @@ bool Converter::ConvertCXXMethodDecl(clang::CXXMethodDecl *decl) { ConvertFunctionParameters(decl); } ConvertFunctionReturnType(decl); - if (decl->isPureVirtual() || method_target_ == MethodTarget::TraitDecl) { + if (decl->isPureVirtual()) { StrCat(token::kSemiColon); - } else if (method_target_ == MethodTarget::TraitDefault) { - PushBrace body(*this); - StrCat("unimplemented!()"); } else { PushBrace body(*this); EmitFunctionPreamble(decl); @@ -1388,7 +1385,11 @@ bool Converter::ConvertCXXMethodDecl(clang::CXXMethodDecl *decl) { } std::string Converter::GetSelfMaybeWithMut(const clang::CXXMethodDecl *decl) { - return MethodNeedsMutableReceiver(decl) ? "&mut self" : "&self"; + bool is_mut = MethodNeedsMutableReceiver(decl); + if (GetRecordTrait(decl) || IsMethodOnPtr(decl)) { + return is_mut ? "this: *mut Self" : "this: *const Self"; + } + return is_mut ? "&mut self" : "&self"; } std::string Converter::GetCtorName(clang::CXXConstructorDecl *decl) { @@ -1413,7 +1414,7 @@ bool Converter::VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl) { } ScopedValue push_fn(curr_function_, decl); - if (method_target_ == MethodTarget::ValueImpl && !GetRecordTrait(decl)) { + if (!GetRecordTrait(decl)) { StrCat(AccessSpecifierAsString(decl->getAccess())); } StrCat(keyword_unsafe_, keyword::kFn, GetCtorName(decl)); @@ -1422,17 +1423,9 @@ bool Converter::VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl) { StrCat(GetConstructorSelf(), token::kComma); ConvertFunctionParameters(decl); } - if (method_target_ == MethodTarget::TraitDecl) { - StrCat(token::kSemiColon); - return false; - } { PushBrace brace(*this); - if (method_target_ == MethodTarget::TraitDefault) { - StrCat("unimplemented!()"); - } else { - ConvertCXXConstructorBody(decl); - } + ConvertCXXConstructorBody(decl); } return false; @@ -1497,7 +1490,7 @@ void Converter::EmitConstructorFieldInits(clang::CXXConstructorDecl *decl) { std::string Converter::ConvertConstructorFieldWrite(const std::string &field_name, const std::string &value) { - return std::format("(&raw mut self.{}).write({});", field_name, value); + return std::format("(&raw mut (*this).{}).write({});", field_name, value); } bool Converter::VisitFieldDecl(clang::FieldDecl *decl) { @@ -1660,7 +1653,7 @@ bool Converter::VisitReturnStmt(clang::ReturnStmt *stmt) { ConstructInPlace(value, construct, GetReturnSlotReceiver()); } else { HoistMaterializedTempBindings hoist_temps(*this); - StrCat("this.write"); + StrCat("__return.write"); { PushParen paren(*this); ConvertVarInit(return_type, value); @@ -4293,14 +4286,26 @@ bool Converter::VisitMemberExpr(clang::MemberExpr *expr) { void Converter::SetUFCSReceiver(clang::Expr *base, bool is_arrow, const clang::CXXMethodDecl *method) { + bool is_mut = MethodNeedsMutableReceiver(method); + bool takes_pointer = GetRecordTrait(method) || IsMethodOnPtr(method); if (clang::isa(base->IgnoreParenImpCasts()) && !AsLambdaOperatorCall(curr_function_)) { - ufcs_receiver_ = keyword::kSelfValue; - return; + if (takes_pointer) { + ufcs_receiver_ = ConvertFreshRValue(base); + return; + } + if (!ThisIsRustPtr()) { + ufcs_receiver_ = keyword::kSelfValue; + return; + } } Buffer buf(*this); PushExprKind push(*this, ExprKind::LValue); - StrCat(MethodNeedsMutableReceiver(method) ? "&mut" : "&"); + if (takes_pointer && (is_arrow || !IsTemporaryObject(ctx_, base))) { + StrCat(is_mut ? "&raw mut" : "&raw const"); + } else { + StrCat(is_mut ? "&mut" : "&"); + } if (is_arrow) { ConvertArrow(base); } else { @@ -4388,6 +4393,12 @@ const clang::Expr *Converter::GetFieldReadCall(const clang::MemberExpr *expr) { return clang::isa(base) ? base : nullptr; } +bool Converter::ThisIsRustPtr() const { + auto *method = clang::dyn_cast_or_null(curr_function_); + return method && (GetRecordTrait(method) || IsMethodOnPtr(method) || + clang::isa(method)); +} + bool Converter::VisitCXXThisExpr(clang::CXXThisExpr *expr) { if (auto field = AsLambdaCaptureThis(curr_function_)) { auto name = GetNamedDeclAsString(field); @@ -4396,7 +4407,9 @@ bool Converter::VisitCXXThisExpr(clang::CXXThisExpr *expr) { : std::format("(&raw mut {})", name)); return false; } - { + if (ThisIsRustPtr()) { + StrCat("this"); + } else { PushParen paren(*this); StrCat(keyword::kSelfValue, keyword::kAs, ToString(expr->getType())); } @@ -4671,7 +4684,7 @@ bool Converter::VisitCXXNewExpr(clang::CXXNewExpr *expr) { std::format("let __p: *mut {0} = Box::leak(Box::new(<{0}>::" "zero_init()));", GetRecordName(construct->getType()->getAsCXXRecordDecl()))); - ConstructInPlace(expr->getInitializer(), construct, "&mut *__p"); + ConstructInPlace(expr->getInitializer(), construct, "__p"); StrCat("__p"); } else if (pointee) { StrCat( @@ -4711,10 +4724,10 @@ bool Converter::VisitCXXDeleteExpr(clang::CXXDeleteExpr *expr) { StrCat( std::format("for __i in (0..libcc2rs::malloc_usable_size(__p as *mut " "::libc::c_void) / ::std::mem::size_of::<{0}>()).rev() {{ " - "DestructibleUnsafe::destroy(&mut *__p.add(__i)); }}", + "DestructibleUnsafe::destroy(__p.add(__i)); }}", record_name)); } else { - StrCat("DestructibleUnsafe::destroy(&mut *__p)", token::kSemiColon); + StrCat("DestructibleUnsafe::destroy(__p)", token::kSemiColon); } EmitDeallocation(expr, "__p"); return false; @@ -4839,7 +4852,8 @@ void Converter::EmitLocalObject(clang::VarDecl *decl, // call (parentheses, casts to its type) emit nothing else. ScopedValue scope(full_expression_temporaries_, &declarations); // Any other construction gets the storage as a reference named name. - ScopedValue in_place(in_place_, {construct, name, &tail}); + ScopedValue in_place(in_place_, + {construct, GetStorageReceiver(name), &tail}); auto *init_expr = clang::isa(construct) ? const_cast(construct) : decl->getInit(); @@ -4858,6 +4872,10 @@ void Converter::EmitLocalObject(clang::VarDecl *decl, const char *Converter::GetObjectMacro() const { return "object_unsafe!"; } +std::string Converter::GetStorageReceiver(std::string_view name) const { + return std::string(name); +} + const char *Converter::GetAssignMacro() const { return "assign_unsafe!"; } std::string Converter::ConvertObjectOperand(clang::Expr *expr, bool is_arrow) { @@ -4871,11 +4889,9 @@ std::string Converter::ConvertObjectOperand(clang::Expr *expr, bool is_arrow) { return std::move(buf).str(); } -const char *Converter::GetConstructorSelf() const { return "&mut self"; } +const char *Converter::GetConstructorSelf() const { return "this: *mut Self"; } -const char *Converter::GetConstructorWrite() const { - return "(self as *mut Self).write"; -} +const char *Converter::GetConstructorWrite() const { return "this.write"; } std::string Converter::GetConstructorPath(const clang::CXXConstructorDecl *ctor) const { @@ -4892,14 +4908,14 @@ std::string Converter::CreatePlacementStorage(const std::string &record_name, } std::string Converter::GetPlacementReceiver(std::string_view name) const { - return std::format("&mut {}", name); + return std::format("&raw mut {}", name); } std::string Converter::GetFieldPlacementReceiver(std::string_view field) const { - return std::format("&mut self.{}", field); + return std::format("&raw mut (*this).{}", field); } -const char *Converter::GetDelegatingReceiver() const { return "&mut *self"; } +const char *Converter::GetDelegatingReceiver() const { return "this"; } bool Converter::CanConstructVarInPlace(const clang::VarDecl *decl) const { return true; @@ -4907,14 +4923,14 @@ bool Converter::CanConstructVarInPlace(const clang::VarDecl *decl) const { const char *Converter::TakePlacementValue() const { return "__v"; } -const char *Converter::GetReturnSlotReceiver() const { return "&mut *this"; } +const char *Converter::GetReturnSlotReceiver() const { return "__return"; } std::string Converter::GetReturnSlotArg(std::string_view receiver) const { return std::string(receiver); } std::string Converter::GetReturnSlotParam(clang::QualType type) { - return std::format("this: {},", + return std::format("__return: {},", ToString(ctx_.getPointerType(type.getUnqualifiedType()))); } @@ -5882,7 +5898,10 @@ std::string Converter::GetComparisonReceiver(const clang::CXXMethodDecl *method, if (!MethodNeedsMutableReceiver(method)) { return std::string(lhs); } - return std::format("&mut *(&raw const *{}).cast_mut()", lhs); + if (!IsMethodOnPtr(method)) { + return std::format("&mut *(&raw const *{}).cast_mut()", lhs); + } + return std::format("(&raw const *{}).cast_mut()", lhs); } std::string Converter::GetEqBody(const clang::CXXRecordDecl *decl, diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index d80b182d0b..ef5f2b43a6 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -244,7 +244,7 @@ class Converter : public clang::RecursiveASTVisitor { virtual std::string GetUFCSName(const clang::CXXMethodDecl *method) const; - virtual bool ThisIsRustPtr() const { return false; } + virtual bool ThisIsRustPtr() const; void ConvertCXXConstructorBody(clang::CXXConstructorDecl *decl); // The object that decl constructs, before its body runs. @@ -395,6 +395,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual const char *GetObjectMacro() const; + virtual std::string GetStorageReceiver(std::string_view name) const; + // The macro that calls the copy or the move operator= of a class. virtual const char *GetAssignMacro() const; @@ -1207,13 +1209,6 @@ class Converter : public clang::RecursiveASTVisitor { clang::FunctionDecl *curr_function_ = nullptr; clang::Expr *return_value_ = nullptr; bool in_function_formals_ = false; - enum class MethodTarget : uint8_t { - ValueImpl, - TraitDecl, - TraitDefault, - PtrImpl, - }; - MethodTarget method_target_ = MethodTarget::ValueImpl; std::string ufcs_receiver_; bool in_const_initializer_ = false; diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 923520f3e3..c89d862b37 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -119,49 +119,51 @@ struct RecordTrait { inline constexpr RecordTrait kDefaultConstructible{ "default_constructor", - {"DefaultConstructible", "fn default_constructor(this: &Ptr)", - "this"}, - {"DefaultConstructibleUnsafe", "unsafe fn default_constructor(&mut self)", - "&mut *self"}}; + {"DefaultConstructible", "fn default_constructor(this: Ptr)", + "this.clone()"}, + {"DefaultConstructibleUnsafe", + "unsafe fn default_constructor(this: *mut Self)", "this"}}; inline constexpr RecordTrait kCopyConstructible{ "copy_constructor", - {"CopyConstructible", "fn copy_constructor(this: &Ptr, _: Ptr)", - "this"}, + {"CopyConstructible", "fn copy_constructor(this: Ptr, _: Ptr)", + "this.clone()"}, {"CopyConstructibleUnsafe", - "unsafe fn copy_constructor(&mut self, _: *const Self)", "&mut *self"}}; + "unsafe fn copy_constructor(this: *mut Self, _: *const Self)", "this"}}; inline constexpr RecordTrait kMoveConstructible{ "move_constructor", - {"MoveConstructible", "fn move_constructor(this: &Ptr, _: Ptr)", - "this"}, + {"MoveConstructible", "fn move_constructor(this: Ptr, _: Ptr)", + "this.clone()"}, {"MoveConstructibleUnsafe", - "unsafe fn move_constructor(&mut self, _: *mut Self)", "&mut *self"}}; + "unsafe fn move_constructor(this: *mut Self, _: *mut Self)", "this"}}; inline constexpr RecordTrait kCopyAssignable{ "copy_assign", {"CopyAssignable", - "fn copy_assign(this: &Ptr, _: Ptr) -> Ptr", "this"}, + "fn copy_assign(this: Ptr, _: Ptr) -> Ptr", + "this.clone()"}, {"CopyAssignableUnsafe", - "unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self", - "&mut *self"}}; + "unsafe fn copy_assign(this: *mut Self, _: *const Self) -> *mut Self", + "this"}}; inline constexpr RecordTrait kMoveAssignable{ "move_assign", {"MoveAssignable", - "fn move_assign(this: &Ptr, _: Ptr) -> Ptr", "this"}, + "fn move_assign(this: Ptr, _: Ptr) -> Ptr", + "this.clone()"}, {"MoveAssignableUnsafe", - "unsafe fn move_assign(&mut self, _: *mut Self) -> *mut Self", - "&mut *self"}}; + "unsafe fn move_assign(this: *mut Self, _: *mut Self) -> *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"}, - {"SwappableUnsafe", "unsafe fn swap(&mut self, _: *mut Self)", - "&mut *self"}}; + {"Swappable", "fn swap(this: Ptr, _: Ptr)", "this.clone()"}, + {"SwappableUnsafe", "unsafe fn swap(this: *mut Self, _: *mut Self)", + "this"}}; inline constexpr RecordTrait kDestructible{ "destroy", - {"Destructible", "fn destroy(this: &Ptr)", "this"}, - {"DestructibleUnsafe", "unsafe fn destroy(&mut self)", "&mut *self"}}; + {"Destructible", "fn destroy(this: Ptr)", "this.clone()"}, + {"DestructibleUnsafe", "unsafe fn destroy(this: *mut Self)", "this"}}; inline constexpr RecordTrait kTriviallyDefaultConstructible{ nullptr, {"TriviallyDefaultConstructible"}, diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 3f1c01d821..8a6d96c9d8 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -20,16 +20,6 @@ #include "converter/rules/registry.h" namespace cpp2rust { -std::map - ConverterRefCount::methods_on_ptr_; - -void ConverterRefCount::EmitMethodsOnPtr(std::string &out) { - for (const auto &[name, methods] : methods_on_ptr_) { - EmitDeferredBlock(methods.trait, out); - EmitDeferredBlock(methods.impl, out); - } -} - ConverterRefCount::ConverterRefCount(std::string &rs_code, clang::ASTContext &ctx) : ConverterRefCount(rs_code, ctx, std::make_shared(ctx)) {} @@ -161,8 +151,7 @@ bool ConverterRefCount::NeedsMut(const clang::VarDecl *decl, // without a body, which can't be mutable. auto *param = clang::cast(decl); auto *function = clang::cast(param->getDeclContext()); - return !function->isPureVirtual() && - method_target_ != MethodTarget::TraitDecl; + return !function->isPureVirtual(); } bool ConverterRefCount::IsUnboxedVar(const clang::ValueDecl *decl) const { @@ -663,16 +652,16 @@ ConverterRefCount::GetComparisonArg(const clang::ParmVarDecl *param, std::string ConverterRefCount::GetComparisonResultReceiver( const clang::CXXMethodDecl *, bool returns_ref, std::string_view result) { if (returns_ref) { - return std::format("&{}", result); + return std::format("{}.clone()", result); } PushConversionKind push(*this, ConversionKind::FullRefCount); - return std::format("&{}.as_pointer()", BoxValue(std::string(result))); + return std::format("{}.as_pointer()", BoxValue(std::string(result))); } std::string ConverterRefCount::GetComparisonReceiver(const clang::CXXMethodDecl *, std::string_view lhs) { - return std::string(lhs); + return std::format("{}.clone()", lhs); } // Records implement the comparisons of the standard library (CppLess and @@ -685,8 +674,8 @@ void ConverterRefCount::ConvertOrdAndPartialOrdTraits( auto record_name = GetRecordName(decl); auto emit = [&](std::string_view trait, std::string_view fn, std::string_view body) { - StrCat(std::format("impl {} for {} {{ fn {}(__lhs: &Ptr, " - "__rhs: &Ptr) -> bool {{ {} }} }}", + StrCat(std::format("impl {} for {} {{ fn {}(__lhs: Ptr, " + "__rhs: Ptr) -> bool {{ {} }} }}", trait, record_name, fn, body)); }; if (lt) { @@ -811,7 +800,10 @@ void ConverterRefCount::EmitByteSizeAttr(const clang::RecordDecl *decl) { std::string ConverterRefCount::GetSelfMaybeWithMut(const clang::CXXMethodDecl *decl) { if (GetRecordTrait(decl)) { - return "this: &Ptr"; + return "this: Ptr"; + } + if (IsMethodOnPtr(decl)) { + return "this: Ptr"; } return NeedsMutAccess(decl, decl->getThisType()->getPointeeType()) ? "&mut self" @@ -948,14 +940,14 @@ void ConverterRefCount::EmitScopedDestructor(const clang::VarDecl *decl) { } StrCat(token::kSemiColon, std::format("let _dtor_{0} = std::mem::DropGuard::new({0}.clone(), " - "|__p| Destructible::destroy(&__p.as_pointer()))", + "|__p| Destructible::destroy(__p.as_pointer()))", GetNamedDeclAsString(decl))); } std::string ConverterRefCount::StaticDestructorCall(const clang::VarDecl *decl) { return std::format( - "Destructible::destroy(&{}.with(Value::clone).as_pointer())", + "Destructible::destroy({}.with(Value::clone).as_pointer())", GetNamedDeclAsString(decl)); } @@ -2043,7 +2035,7 @@ bool ConverterRefCount::VisitCXXNewExpr(clang::CXXNewExpr *expr) { StrCat( std::format("let __p = Ptr::alloc(<{}>::zero_init());", GetRecordName(construct->getType()->getAsCXXRecordDecl()))); - ConstructInPlace(expr->getInitializer(), construct, "&__p"); + ConstructInPlace(expr->getInitializer(), construct, "__p.clone()"); StrCat("__p"); } else { StrCat("Ptr::alloc("); @@ -2073,9 +2065,9 @@ bool ConverterRefCount::VisitCXXDeleteExpr(clang::CXXDeleteExpr *expr) { token::kSemiColon); if (expr->isArrayForm()) { StrCat("for __i in (0..__p.len()).rev() { " - "Destructible::destroy(&__p.offset(__i as isize)); }"); + "Destructible::destroy(__p.offset(__i as isize)); }"); } else { - StrCat("Destructible::destroy(&__p);"); + StrCat("Destructible::destroy(__p.clone());"); } StrCat("__p.delete();"); return false; @@ -3566,14 +3558,13 @@ bool ConverterRefCount::ShouldConvertMethod(const clang::CXXMethodDecl *decl) { return Converter::ShouldConvertMethod(decl); } -// TODO: every trait on a Ptr should receive `this`. bool ConverterRefCount::ReceivesThis() const { auto *method = clang::dyn_cast_or_null(curr_function_); return method && GetRecordTrait(method); } const char *ConverterRefCount::SelfName() const { - return ReceivesThis() ? "this" : keyword::kSelfValue; + return ReceivesThis() || ThisIsRustPtr() ? "this" : keyword::kSelfValue; } bool ConverterRefCount::ThisIsRustPtr() const { @@ -3593,166 +3584,36 @@ void ConverterRefCount::SetUFCSReceiver(clang::Expr *base, bool is_arrow, if (clang::isa(base->IgnoreParenImpCasts()) && !AsLambdaOperatorCall(curr_function_)) { if (ThisIsRustPtr()) { - ufcs_receiver_ = SelfName(); + ufcs_receiver_ = std::format("{}.clone()", SelfName()); } else { - ufcs_receiver_ = token::kRef + ConvertPointer(base); + ufcs_receiver_ = ConvertFreshPointer(base); } return; } if (IsTemporaryObject(ctx_, base) && base->getType()->isRecordType() && !IsReferenceType(base->IgnoreImplicit())) { if (KeepsTemporaryOwner(base)) { - ufcs_receiver_ = token::kRef + ConvertTemporaryPointer(base, {}); + ufcs_receiver_ = ConvertTemporaryPointer(base, {}); return; } PushConversionKind push(*this, ConversionKind::FullRefCount); - ufcs_receiver_ = - token::kRef + BoxValue(ConvertRValue(base)) + ".as_pointer()"; - return; - } - ufcs_receiver_ = token::kRef + (base_is_pointer ? ConvertRValue(base) - : ConvertPointer(base)); -} - -std::string -ConverterRefCount::GetUFCSName(const clang::CXXMethodDecl *method) const { - if (auto *trait = GetRecordTrait(method)) { - return GetCopyOrMoveTraitName(*trait); - } - if (!IsMethodOnPtr(method)) { - return GetRecordName(method->getParent()); - } - if (method->isExplicitObjectMemberFunction()) { - return std::format(" as {}>", GetRecordName(method->getParent()), - TraitName(method->getParent())); - } - return TraitName(method->getParent()); -} - -std::string -ConverterRefCount::TraitName(const clang::CXXRecordDecl *decl) const { - return GetRecordName(decl) + "Impl"; -} - -ConverterRefCount::MethodsOnPtr & -ConverterRefCount::MethodsOnPtrFor(const clang::CXXRecordDecl *decl) { - auto name = GetRecordName(decl); - auto [it, inserted] = methods_on_ptr_.try_emplace(name); - if (inserted) { - it->second.trait.header = std::format("pub trait {}", TraitName(decl)); - it->second.impl.header = - std::format("impl {} for Ptr<{}>", TraitName(decl), name); - } - return it->second; -} - -bool ConverterRefCount::ConvertOutOfLineMethod(clang::CXXMethodDecl *decl) { - if (!IsMethodOnPtr(decl)) { - return Converter::ConvertOutOfLineMethod(decl); - } - Buffer buf(*this); - { - ScopedValue push(method_target_, MethodTarget::PtrImpl); - ConvertCXXMethodDecl(decl); - } - MethodsOnPtrFor(decl->getParent()).impl.body += std::move(buf).str(); - return false; -} - -void ConverterRefCount::ConvertMethodOnPtrTraitDecl( - clang::CXXMethodDecl *method) { - if (GetRecordTrait(method)) { - return; - } - Buffer buf(*this); - { - ScopedValue push_fn(curr_function_, method); - ScopedValue push(method_target_, method->getDefinition() - ? MethodTarget::TraitDecl - : MethodTarget::TraitDefault); - ConvertCXXMethodDecl(method); - } - MethodsOnPtrFor(method->getParent()).trait.body += std::move(buf).str(); -} - -void ConverterRefCount::ConvertMethodOnPtr(clang::CXXMethodDecl *method) { - if ((!method->isThisDeclarationADefinition() && - !clang::isa(method)) || - GetRecordTrait(method)) { + ufcs_receiver_ = BoxValue(ConvertRValue(base)) + ".as_pointer()"; return; } - Buffer buf(*this); - { - ScopedValue push(method_target_, MethodTarget::PtrImpl); - VisitCXXMethodDecl(method); - } - MethodsOnPtrFor(method->getParent()).impl.body += std::move(buf).str(); -} - -void ConverterRefCount::ConvertTemplateInstantiatedCtors( - clang::CXXRecordDecl *decl) { - for (auto c : GetTemplateInstantiatedCtors(decl)) { - if (!decl_ids_.contains(GetID(c))) { - ConvertMethodOnPtrTraitDecl(c); - ConvertMethodOnPtr(c); - } + bool outer_borrows = std::exchange(borrows_, false); + ufcs_receiver_ = + base_is_pointer ? ConvertFreshRValue(base) : ConvertFreshPointer(base); + if (borrows_) { + ufcs_receiver_ = std::format("{{ {} }}", ufcs_receiver_); } -} - -void ConverterRefCount::ConvertLateInstantiatedMethods( - clang::CXXRecordDecl *decl) { - Converter::ConvertCXXMethodDecls( - decl, std::format("{} {}", keyword::kImpl, GetRecordName(decl)), - [](auto *method) { - return IsEmittableMethod(method) && method->hasBody() && - !IsMethodOnPtr(method) && - !clang::isa(method) && - !decl_ids_.contains(GetMethodID(method)); - }); - ForEachMethod(decl, [&](clang::CXXMethodDecl *method) { - if (IsEmittableMethod(method) && method->hasBody() && - (IsMethodOnPtr(method) || - clang::isa(method)) && - !decl_ids_.contains(GetMethodID(method))) { - ConvertMethodOnPtr(method); - } - }); - ConvertCopyOrMoveTraitImpls(decl, [](clang::CXXMethodDecl *method) { - return IsEmittableMethod(method) && method->hasBody() && - !decl_ids_.contains(GetMethodID(method)); - }); -} - -void ConverterRefCount::ConvertCXXRecordMethods(clang::CXXRecordDecl *decl) { - auto struct_name = GetRecordName(decl); - - ConvertCXXMethodDecls(decl, std::format("{} {}", keyword::kImpl, struct_name), - [](auto *method) { - return IsEmittableMethod(method) && - !IsMethodOnPtr(method) && - !clang::isa(method); - }); - - ForEachMethod(decl, [&](clang::CXXMethodDecl *method) { - if (auto *ctor = clang::dyn_cast(method); - ctor && IsEmittableMethod(ctor) && IsConvertedConstructor(ctor) && - !ctor->isDependentContext()) { - ConvertMethodOnPtrTraitDecl(ctor); - ConvertMethodOnPtr(ctor); - } - if (IsMethodOnPtr(method) && !method->getReturnType()->isUndeducedType()) { - ConvertMethodOnPtrTraitDecl(method); - ConvertMethodOnPtr(method); - } - }); - ConvertCopyOrMoveTraitImpls(decl, IsEmittableMethod); + borrows_ = outer_borrows; } std::string ConverterRefCount::DestroyMembers(const clang::CXXRecordDecl *decl) { std::string out; for (auto *field : FieldsToDestroy(decl)) { - out += std::format("Destructible::destroy(&field_ptr!(this, {}));\n", + out += std::format("Destructible::destroy(field_ptr!(this, {}));\n", GetNamedDeclAsString(field)); } return out; @@ -3760,6 +3621,10 @@ ConverterRefCount::DestroyMembers(const clang::CXXRecordDecl *decl) { const char *ConverterRefCount::GetObjectMacro() const { return "object!"; } +std::string ConverterRefCount::GetStorageReceiver(std::string_view name) const { + return std::format("{}.clone()", name); +} + const char *ConverterRefCount::GetAssignMacro() const { return "assign!"; } std::string ConverterRefCount::ConvertObjectOperand(clang::Expr *expr, @@ -3775,31 +3640,23 @@ std::string ConverterRefCount::ConvertObjectOperand(clang::Expr *expr, std::string ConverterRefCount::GetAssignmentTraitSignature(const RecordTrait &trait) const { - return std::format("fn {}(this: &Ptr, src: Ptr) -> Ptr", + return std::format("fn {}(this: Ptr, src: Ptr) -> Ptr", trait.method); } const char *ConverterRefCount::GetConstructorSelf() const { - return ReceivesThis() ? "this: &Ptr" : "&self"; + return "this: Ptr"; } std::string ConverterRefCount::ConvertConstructorFieldWrite(const std::string &field_name, const std::string &value) { - return std::format("field!((*{}), {}).write({});", SelfName(), field_name, + return std::format("field!({}, {}).write({});", SelfName(), field_name, value); } const char *ConverterRefCount::GetConstructorWrite() const { - return ReceivesThis() ? "this.write" : "self.write"; -} - -std::string ConverterRefCount::GetConstructorPath( - const clang::CXXConstructorDecl *ctor) const { - if (auto *trait = GetRecordTrait(ctor)) { - return GetCopyOrMoveTraitName(*trait); - } - return TraitName(ctor->getParent()); + return "this.write"; } std::string @@ -3812,16 +3669,16 @@ ConverterRefCount::CreatePlacementStorage(const std::string &record_name, std::string ConverterRefCount::GetPlacementReceiver(std::string_view name) const { - return std::format("&{}.as_pointer()", name); + return std::format("{}.as_pointer()", name); } std::string ConverterRefCount::GetFieldPlacementReceiver(std::string_view field) const { - return std::format("&field_ptr!({}, {})", SelfName(), field); + return std::format("field_ptr!({}, {})", SelfName(), field); } const char *ConverterRefCount::GetDelegatingReceiver() const { - return SelfName(); + return "this.clone()"; } // An unboxed variable has no storage to construct in. @@ -3834,11 +3691,13 @@ const char *ConverterRefCount::TakePlacementValue() const { return "Rc::try_unwrap(__v).ok().unwrap().into_inner()"; } -const char *ConverterRefCount::GetReturnSlotReceiver() const { return "&this"; } +const char *ConverterRefCount::GetReturnSlotReceiver() const { + return "__return.clone()"; +} std::string ConverterRefCount::GetReturnSlotArg(std::string_view receiver) const { - return std::format("Ptr::clone({})", receiver); + return std::format("Ptr::clone(&{})", receiver); } bool ConverterRefCount::VisitCXXThisExpr( @@ -3854,7 +3713,11 @@ bool ConverterRefCount::VisitCXXThisExpr( } return false; } - StrCat("(*", SelfName(), ')'); + if (ReceivesThis() || ThisIsRustPtr()) { + StrCat(SelfName()); + } else { + StrCat("(*", SelfName(), ')'); + } MarkNotFresh(); return false; } diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 1d9fb0d900..d824157de8 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -21,8 +21,6 @@ class ConverterRefCount final : public Converter { std::string GetUnboxedDefaultAsString(clang::QualType qual_type) override; - static void EmitMethodsOnPtr(std::string &out); - bool VisitRecordType(clang::RecordType *type) override; bool VisitConstantArrayType(clang::ConstantArrayType *type) override; @@ -79,12 +77,12 @@ class ConverterRefCount final : public Converter { bool ShouldConvertMethod(const clang::CXXMethodDecl *decl) override; - bool ConvertOutOfLineMethod(clang::CXXMethodDecl *decl) override; - const char *GetConstructorSelf() const override; const char *GetObjectMacro() const override; + std::string GetStorageReceiver(std::string_view name) const override; + const char *GetAssignMacro() const override; std::string ConvertObjectOperand(clang::Expr *expr, bool is_arrow) override; @@ -97,9 +95,6 @@ class ConverterRefCount final : public Converter { std::string ConvertConstructorFieldWrite(const std::string &field_name, const std::string &value) override; - std::string - GetConstructorPath(const clang::CXXConstructorDecl *ctor) const override; - std::string CreatePlacementStorage(const std::string &record_name, std::string_view name = "__v") const override; @@ -119,15 +114,6 @@ class ConverterRefCount final : public Converter { std::string GetReturnSlotArg(std::string_view receiver) const override; - void ConvertCXXRecordMethods(clang::CXXRecordDecl *decl) override; - - void ConvertLateInstantiatedMethods(clang::CXXRecordDecl *decl) override; - - void ConvertTemplateInstantiatedCtors(clang::CXXRecordDecl *decl) override; - - void ConvertMethodOnPtrTraitDecl(clang::CXXMethodDecl *method); - void ConvertMethodOnPtr(clang::CXXMethodDecl *method); - bool VisitCXXThisExpr(clang::CXXThisExpr *expr) override; bool ThisIsRustPtr() const override; @@ -435,21 +421,6 @@ class ConverterRefCount final : public Converter { void SetUFCSReceiver(clang::Expr *base, bool is_arrow, const clang::CXXMethodDecl *method) override; - std::string GetUFCSName(const clang::CXXMethodDecl *method) const override; - - std::string TraitName(const clang::CXXRecordDecl *decl) const; - - struct MethodsOnPtr { - DeferredBlock trait; - DeferredBlock impl; - }; - - // record name -> trait and impl for Ptr, emitted after all - // translation units. - static std::map methods_on_ptr_; - - MethodsOnPtr &MethodsOnPtrFor(const clang::CXXRecordDecl *decl); - bool ReceivesThis() const; const char *SelfName() const; diff --git a/cpp2rust/cpp2rust_lib.cpp b/cpp2rust/cpp2rust_lib.cpp index 4196e5af85..605e46ba59 100644 --- a/cpp2rust/cpp2rust_lib.cpp +++ b/cpp2rust/cpp2rust_lib.cpp @@ -34,9 +34,6 @@ std::string TranspileSrc(std::string_view cc_code, Model model, Converter::EmitOpaqueRecords(model, rs_code); Converter::EmitVirtualMethods(rs_code); Converter::EmitUndefinedRecordTraits(model, rs_code); - if (model == Model::kRefCount) { - ConverterRefCount::EmitMethodsOnPtr(rs_code); - } Converter::EmitGlobalInits(model, rs_code); return rs_code; } @@ -80,9 +77,6 @@ std::string TranspileDir(std::string_view build_dir, Model model, Converter::EmitOpaqueRecords(model, rs_code); Converter::EmitVirtualMethods(rs_code); Converter::EmitUndefinedRecordTraits(model, rs_code); - if (model == Model::kRefCount) { - ConverterRefCount::EmitMethodsOnPtr(rs_code); - } Converter::EmitGlobalInits(model, rs_code); return rs_code; } diff --git a/libcc2rs-macros/src/assign.rs b/libcc2rs-macros/src/assign.rs index 8b5387f5e2..a374c0b6f1 100644 --- a/libcc2rs-macros/src/assign.rs +++ b/libcc2rs-macros/src/assign.rs @@ -41,7 +41,7 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { quote! { unsafe { let #src_name = #src; - ::libcc2rs::AssignFromUnsafe::assign_from(&mut #left, #src_name) + ::libcc2rs::AssignFromUnsafe::assign_from(&raw mut #left, #src_name) } } } else { @@ -56,7 +56,7 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { quote! { { let #src_name = #src; - ::libcc2rs::AssignFrom::assign_from(&#dst, #src_name) + ::libcc2rs::AssignFrom::assign_from(#dst, #src_name) } } }; diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index 31a3815023..33d68ff76a 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -55,10 +55,10 @@ pub fn expand_default_constructible(input: TokenStream, is_unsafe: bool) -> Toke if is_unsafe { quote! { impl #impl_generics ::libcc2rs::DefaultConstructibleUnsafe for #name #ty_generics #where_clause { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { unsafe { ::std::ptr::write( - self, + this, ::zero_init(), ) } @@ -68,7 +68,7 @@ pub fn expand_default_constructible(input: TokenStream, is_unsafe: bool) -> Toke } else { quote! { impl #impl_generics ::libcc2rs::DefaultConstructible for #name #ty_generics #where_clause { - fn default_constructor(this: &::libcc2rs::Ptr) { + fn default_constructor(this: ::libcc2rs::Ptr) { this.write(::zero_init()); } } @@ -88,15 +88,15 @@ fn impl_swap(input: &DeriveInput, is_unsafe: bool) -> TokenStream2 { if is_unsafe { quote! { impl #impl_generics ::libcc2rs::SwappableUnsafe for #name #ty_generics #where_clause { - unsafe fn swap(&mut self, other: *mut Self) { - unsafe { ::libcc2rs::swap_by_move_unsafe(self, other) } + unsafe fn swap(this: *mut Self, other: *mut Self) { + unsafe { ::libcc2rs::swap_by_move_unsafe(this, other) } } } } } else { quote! { impl #impl_generics ::libcc2rs::Swappable for #name #ty_generics #where_clause { - fn swap(this: &::libcc2rs::Ptr, other: ::libcc2rs::Ptr) { + fn swap(this: ::libcc2rs::Ptr, other: ::libcc2rs::Ptr) { ::libcc2rs::swap_by_move(this, other) } } @@ -144,14 +144,14 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - quote!(*const Self) }; let body = if is_move { - quote!(unsafe { ::libcc2rs::#copy_trait::#copy_method(self, src) }) + quote!(unsafe { ::libcc2rs::#copy_trait::#copy_method(this, src) }) } else if is_assign { quote! { - unsafe { *self = (*src).clone() }; - self + unsafe { *this = (*src).clone() }; + this } } else { - quote!(unsafe { ::std::ptr::write(self, (*src).clone()) }) + quote!(unsafe { ::std::ptr::write(this, (*src).clone()) }) }; let ret = if is_assign { quote!(-> *mut Self) @@ -160,7 +160,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 { - unsafe fn #method(&mut self, src: #src_ty) #ret { + unsafe fn #method(this: *mut Self, src: #src_ty) #ret { #body } } @@ -175,17 +175,17 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - quote!(::libcc2rs::#copy_trait::#copy_method(this, src)) } else if is_assign { quote! { - this.write(src.with(Self::clone)); + this.write(src.with(::clone)); this.clone() } } else { - quote!(this.write(src.with(Self::clone));) + quote!(this.write(src.with(::clone));) }; // The copy of a type with Clone is a clone, and its move is its copy. let copied = match (is_move, is_assign) { (false, false) => Some(quote! { fn copied(src: ::libcc2rs::Ptr) -> Self { - src.with(Self::clone) + src.with(::clone) } fn copied_elems(src: &::libcc2rs::Ptr>) -> Vec { @@ -193,7 +193,7 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - } fn push_copied(v: &::libcc2rs::Ptr>, src: ::libcc2rs::Ptr) { - let value = src.with(Self::clone); + let value = src.with(::clone); v.with_mut(|elems| elems.push(value)); } }), @@ -209,7 +209,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: ::libcc2rs::Ptr) #ret { #body } #copied @@ -269,13 +269,13 @@ pub fn expand_trivially_copyable(input: TokenStream, is_unsafe: bool) -> TokenSt let destroy = if is_unsafe { quote! { impl #impl_generics ::libcc2rs::DestructibleUnsafe for #name #ty_generics #where_clause { - unsafe fn destroy(&mut self) {} + unsafe fn destroy(_: *mut Self) {} } } } else { quote! { impl #impl_generics ::libcc2rs::Destructible for #name #ty_generics #where_clause { - fn destroy(_: &::libcc2rs::Ptr) {} + fn destroy(_: ::libcc2rs::Ptr) {} } } }; @@ -362,14 +362,14 @@ fn impl_memberwise( (quote!(*const Self), quote!(&raw const)) }; let (ret, tail) = if is_assign { - (quote!(-> *mut Self), quote!(self)) + (quote!(-> *mut Self), quote!(this)) } else { (quote!(), quote!()) }; return quote! { impl #impl_generics #tr for #name #ty_generics #where_clause { - unsafe fn #method(&mut self, src: #src_ty) #ret { - #(unsafe { #tr::#method(&mut self.#members, #src_field (*src).#members) };)* + unsafe fn #method(this: *mut Self, src: #src_ty) #ret { + #(unsafe { #tr::#method(&raw mut (*this).#members, #src_field (*src).#members) };)* #tail } } @@ -382,9 +382,9 @@ 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: ::libcc2rs::Ptr) #ret { #(#tr::#method( - &::libcc2rs::field_ptr!(this, #members), + ::libcc2rs::field_ptr!(this, #members), ::libcc2rs::field_ptr!(src, #members), );)* #tail diff --git a/libcc2rs-macros/src/cpp_from.rs b/libcc2rs-macros/src/cpp_from.rs index 0ad9cc8b70..0f3d39bd1d 100644 --- a/libcc2rs-macros/src/cpp_from.rs +++ b/libcc2rs-macros/src/cpp_from.rs @@ -3,7 +3,7 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; -use quote::{format_ident, quote}; +use quote::quote; use syn::parse::{Parse, ParseStream}; use syn::{DeriveInput, Ident, Token, Type, parse_macro_input}; @@ -172,18 +172,15 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } }); - let impl_trait = format_ident!("{}Impl", name); let into_impls = intos.iter().map(|conversion| { let ty = &conversion.ty; let op = &conversion.method; let self_ty = quote!(#name #ty_generics); let src = pointer(&syn::parse_quote!(#self_ty), false); let body = if is_unsafe && matches!(conversion.kind, Kind::MutPtr) { - quote!((*src.cast_mut()).#op()) - } else if is_unsafe { - quote!((*src).#op()) + quote!(#name::#op(src.cast_mut())) } else { - quote!(#impl_trait::#op(&src)) + quote!(#name::#op(src)) }; let from_fn = method(is_unsafe, quote!(fn cpp_from(src: #src) -> Self), body); quote! { diff --git a/libcc2rs-macros/src/destructor.rs b/libcc2rs-macros/src/destructor.rs index 2ff90cf8c7..442354bafa 100644 --- a/libcc2rs-macros/src/destructor.rs +++ b/libcc2rs-macros/src/destructor.rs @@ -30,8 +30,8 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let destroy = if is_unsafe { quote! { impl #impl_generics ::libcc2rs::DestructibleUnsafe for #name #ty_generics #where_clause { - unsafe fn destroy(&mut self) { - #(unsafe { ::libcc2rs::DestructibleUnsafe::destroy(&mut self.#destroyed) };)* + unsafe fn destroy(this: *mut Self) { + #(unsafe { ::libcc2rs::DestructibleUnsafe::destroy(&raw mut (*this).#destroyed) };)* } } } @@ -43,8 +43,8 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { }; quote! { impl #impl_generics ::libcc2rs::Destructible for #name #ty_generics #where_clause { - fn destroy(#this: &::libcc2rs::Ptr) { - #(::libcc2rs::Destructible::destroy(&::libcc2rs::field_ptr!(this, #destroyed));)* + fn destroy(#this: ::libcc2rs::Ptr) { + #(::libcc2rs::Destructible::destroy(::libcc2rs::field_ptr!(this, #destroyed));)* } } } diff --git a/libcc2rs-macros/src/initialization.rs b/libcc2rs-macros/src/initialization.rs index c03fc25495..cc7eb3c7cf 100644 --- a/libcc2rs-macros/src/initialization.rs +++ b/libcc2rs-macros/src/initialization.rs @@ -3,7 +3,7 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; -use quote::{format_ident, quote}; +use quote::quote; use syn::punctuated::Punctuated; use syn::{Data, DeriveInput, Expr, Field, Fields, Ident, Index, Token, parse_macro_input}; @@ -78,16 +78,15 @@ pub(crate) fn construct( if is_unsafe { quote! {{ let mut __v: Self = ::zero_init(); - #name::#method(&mut __v, #args); + #name::#method(&raw mut __v, #args); __v }} } else { - let impl_trait = format_ident!("{}Impl", name); quote! {{ let __v: ::libcc2rs::Value = ::std::rc::Rc::new(::std::cell::RefCell::new( ::zero_init(), )); - #impl_trait::#method(&::libcc2rs::AsPointer::as_pointer(&__v), #args); + #name::#method(::libcc2rs::AsPointer::as_pointer(&__v), #args); ::std::rc::Rc::try_unwrap(__v).ok().unwrap().into_inner() }} } diff --git a/libcc2rs/src/capture.rs b/libcc2rs/src/capture.rs index 5e7445edf5..b1fcc4473d 100644 --- a/libcc2rs/src/capture.rs +++ b/libcc2rs/src/capture.rs @@ -32,14 +32,14 @@ use crate::reinterpret::ByteRepr; // The C++ destructor of a type, in the refcount model. pub trait Destructible: Sized { - fn destroy(this: &Ptr); + fn destroy(this: Ptr); } // The C++ destructor of a type, in the unsafe model. pub trait DestructibleUnsafe: Sized { /// # Safety /// `self` must be a live value. - unsafe fn destroy(&mut self); + unsafe fn destroy(this: *mut Self); } pub trait TriviallyDestructible: Destructible {} @@ -47,7 +47,7 @@ pub trait TriviallyDestructible: Destructible {} pub trait TriviallyDestructibleUnsafe: DestructibleUnsafe {} impl Destructible for FnPtr { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { this.with(|f| f.destroy()) } } @@ -55,18 +55,18 @@ impl Destructible for FnPtr { impl TriviallyDestructible for FnPtr {} impl DestructibleUnsafe for FnPtr { - unsafe fn destroy(&mut self) { - FnPtr::destroy(self) + unsafe fn destroy(this: *mut Self) { + unsafe { FnPtr::destroy(&*this) } } } impl TriviallyDestructibleUnsafe for FnPtr {} impl Destructible for Box<[T]> { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { let elems = this.decay(); for i in (0..elems.len()).rev() { - T::destroy(&elems.offset(i)); + T::destroy(elems.offset(i)); } } } @@ -74,9 +74,10 @@ impl Destructible for Box<[T]> { impl TriviallyDestructible for Box<[T]> {} impl DestructibleUnsafe for [T; N] { - unsafe fn destroy(&mut self) { - for elem in self.iter_mut().rev() { - unsafe { DestructibleUnsafe::destroy(elem) } + unsafe fn destroy(this: *mut Self) { + let elems = this as *mut T; + for i in (0..N).rev() { + unsafe { DestructibleUnsafe::destroy(elems.add(i)) } } } } @@ -94,7 +95,7 @@ impl CopyLambda>> for &&&Capture<'_, Value>> { fn copy_capture(&self) -> Value> { let dst: Value> = Rc::new(RefCell::new(FnPtr::zero_init())); CopyConstructible::copy_constructor( - &AsPointer::>::as_pointer(&dst), + AsPointer::>::as_pointer(&dst), AsPointer::>::as_pointer(self.0), ); dst @@ -126,7 +127,7 @@ impl CopyCtor> for &Capture< fn copy_capture(&self) -> Value { let dst: Value = Rc::new(RefCell::new(T::zero_init())); T::copy_constructor( - &AsPointer::::as_pointer(&dst), + AsPointer::::as_pointer(&dst), AsPointer::::as_pointer(self.0), ); dst @@ -151,7 +152,7 @@ impl MoveWithCtor> for &&Cap fn move_capture(&self) -> Value { let dst: Value = Rc::new(RefCell::new(T::zero_init())); T::move_constructor( - &AsPointer::::as_pointer(&dst), + AsPointer::::as_pointer(&dst), AsPointer::::as_pointer(self.0), ); dst @@ -192,7 +193,7 @@ impl DestroyElems for &&Capture<'_, Value>> { fn destroy_capture(&self) { let p: Ptr = self.0.decay(); for i in (0..self.0.borrow().len()).rev() { - T::destroy(&p.offset(i)); + T::destroy(p.offset(i)); } } } @@ -203,7 +204,7 @@ pub trait DestroyWithDtor { impl DestroyWithDtor for &Capture<'_, Value> { fn destroy_capture(&self) { - T::destroy(&AsPointer::::as_pointer(self.0)) + T::destroy(AsPointer::::as_pointer(self.0)) } } @@ -227,7 +228,7 @@ impl CopyLambdaUnsafe> for &&&CaptureUnsafe> { unsafe fn copy_capture(&self) -> FnPtr { let mut dst = std::mem::MaybeUninit::>::uninit(); unsafe { - (*dst.as_mut_ptr()).copy_constructor(self.0); + CopyConstructibleUnsafe::copy_constructor(dst.as_mut_ptr(), self.0); dst.assume_init() } } @@ -251,7 +252,7 @@ impl CopyCtorUnsafe for &CaptureUnsafe { unsafe fn copy_capture(&self) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - (*dst.as_mut_ptr()).copy_constructor(self.0); + T::copy_constructor(dst.as_mut_ptr(), self.0); dst.assume_init() } } @@ -275,7 +276,7 @@ impl MoveWithCtorUnsafe for &&CaptureUnsafe { unsafe fn move_capture(&self) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - (*dst.as_mut_ptr()).move_constructor(self.0); + T::move_constructor(dst.as_mut_ptr(), self.0); dst.assume_init() } } diff --git a/libcc2rs/src/cmp.rs b/libcc2rs/src/cmp.rs index 427fdf1a0c..1b747a5be4 100644 --- a/libcc2rs/src/cmp.rs +++ b/libcc2rs/src/cmp.rs @@ -11,31 +11,31 @@ use crate::reinterpret::ByteRepr; // operator<. Records implement it with their comparison operators. pub trait CppLess: Sized { - fn less(lhs: &Ptr, rhs: &Ptr) -> bool; + fn less(lhs: Ptr, rhs: Ptr) -> bool; } // operator==. Records implement it with their comparison operators. pub trait CppEq: Sized { - fn equal(lhs: &Ptr, rhs: &Ptr) -> bool; + fn equal(lhs: Ptr, rhs: Ptr) -> bool; } impl CppLess for T { - fn less(lhs: &Ptr, rhs: &Ptr) -> bool { + fn less(lhs: Ptr, rhs: Ptr) -> bool { lhs.with(|a| rhs.with(|b| a < b)) } } impl + ByteRepr, U: ByteRepr> CppEq for T { - fn equal(lhs: &Ptr, rhs: &Ptr) -> bool { + fn equal(lhs: Ptr, rhs: Ptr) -> bool { lhs.with(|a| rhs.with(|b| a == b)) } } // The order of two values that std::sort and std::map derive from operator<. pub fn cpp_cmp(lhs: &Ptr, rhs: &Ptr) -> Ordering { - if T::less(lhs, rhs) { + if T::less(lhs.clone(), rhs.clone()) { Ordering::Less - } else if T::less(rhs, lhs) { + } else if T::less(rhs.clone(), lhs.clone()) { Ordering::Greater } else { Ordering::Equal diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index 7913dc19b3..1cbedde0c1 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -11,7 +11,7 @@ use crate::reinterpret::ByteRepr; use crate::void::AnyPtr; pub trait DefaultConstructible: Sized { - fn default_constructor(this: &Ptr); + fn default_constructor(this: Ptr); // TODO: remove default_constructed. fn default_constructed() -> Self @@ -19,13 +19,13 @@ pub trait DefaultConstructible: Sized { Self: ZeroInitialization, { let dst: Value = std::rc::Rc::new(std::cell::RefCell::new(Self::zero_init())); - Self::default_constructor(&AsPointer::::as_pointer(&dst)); + Self::default_constructor(AsPointer::::as_pointer(&dst)); std::rc::Rc::try_unwrap(dst).ok().unwrap().into_inner() } } pub trait MoveConstructible: Sized { - fn move_constructor(this: &Ptr, src: Ptr); + fn move_constructor(this: Ptr, src: Ptr); // 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 +38,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), src); } } @@ -47,7 +47,7 @@ pub trait TriviallyMoveConstructible: MoveConstructible { } pub trait CopyConstructible: MoveConstructible { - fn copy_constructor(this: &Ptr, src: Ptr); + fn copy_constructor(this: Ptr, src: Ptr); // A copy of the value that src points to, made by the copy constructor, // which a type with Clone clones. @@ -69,7 +69,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), src); } // A copy of the elements of the vector that src points to, made by the @@ -89,19 +89,19 @@ pub trait TriviallyCopyConstructible: CopyConstructible { } pub trait CopyAssignable: MoveAssignable { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr; + fn copy_assign(this: Ptr, src: Ptr) -> Ptr; } pub trait TriviallyCopyAssignable: CopyAssignable {} pub trait MoveAssignable: Sized { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr; + fn move_assign(this: Ptr, src: Ptr) -> Ptr; } pub trait TriviallyMoveAssignable: MoveAssignable {} pub trait Swappable: Sized { - fn swap(this: &Ptr, other: Ptr); + fn swap(this: Ptr, other: Ptr); } pub trait TriviallyDefaultConstructible: DefaultConstructible {} @@ -140,7 +140,7 @@ impl< pub trait DefaultConstructibleUnsafe { /// # Safety /// `self` must be valid for writes. - unsafe fn default_constructor(&mut self); + unsafe fn default_constructor(this: *mut Self); // TODO: remove default_constructed. fn default_constructed() -> Self @@ -149,7 +149,7 @@ pub trait DefaultConstructibleUnsafe { { let mut dst = std::mem::MaybeUninit::::zeroed(); unsafe { - (*dst.as_mut_ptr()).default_constructor(); + Self::default_constructor(dst.as_mut_ptr()); dst.assume_init() } } @@ -158,13 +158,13 @@ pub trait DefaultConstructibleUnsafe { pub trait MoveConstructibleUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn move_constructor(&mut self, src: *mut Self); + unsafe fn move_constructor(this: *mut Self, src: *mut Self); } pub trait CopyConstructibleUnsafe: MoveConstructibleUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn copy_constructor(&mut self, src: *const Self); + unsafe fn copy_constructor(this: *mut Self, src: *const Self); } pub trait TriviallyMoveConstructibleUnsafe: MoveConstructibleUnsafe { @@ -182,7 +182,7 @@ pub trait TriviallyCopyConstructibleUnsafe: CopyConstructibleUnsafe { pub trait CopyAssignableUnsafe: MoveAssignableUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self; + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self; } pub trait TriviallyCopyAssignableUnsafe: CopyAssignableUnsafe {} @@ -190,7 +190,7 @@ pub trait TriviallyCopyAssignableUnsafe: CopyAssignableUnsafe {} pub trait MoveAssignableUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self; + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self; } pub trait TriviallyMoveAssignableUnsafe: MoveAssignableUnsafe {} @@ -198,7 +198,7 @@ pub trait TriviallyMoveAssignableUnsafe: MoveAssignableUnsafe {} pub trait SwappableUnsafe { /// # Safety /// `other` must point to a live value. - unsafe fn swap(&mut self, other: *mut Self); + unsafe fn swap(this: *mut Self, other: *mut Self); } pub trait TriviallyDefaultConstructibleUnsafe: DefaultConstructibleUnsafe {} @@ -246,7 +246,7 @@ macro_rules! impl_copy_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn copy_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + fn copy_constructor(this: $crate::Ptr, src: $crate::Ptr) { this.write(src.with(Self::clone)); } @@ -268,7 +268,7 @@ macro_rules! impl_copy_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn copy_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + fn copy_assign(this: $crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { this.write(src.with(Self::clone)); this.clone() } @@ -278,8 +278,8 @@ macro_rules! impl_copy_by_clone { where $ty: Clone, { - unsafe fn copy_constructor(&mut self, src: *const Self) { - unsafe { std::ptr::write(self, (*src).clone()) } + unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + unsafe { std::ptr::write(this, (*src).clone()) } } } @@ -287,9 +287,9 @@ macro_rules! impl_copy_by_clone { where $ty: Clone, { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - unsafe { *self = (*src).clone() }; - self + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe { *this = (*src).clone() }; + this } } )*}; @@ -302,7 +302,7 @@ macro_rules! impl_move_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn move_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + fn move_constructor(this: $crate::Ptr, src: $crate::Ptr) { this.write(src.with(Self::clone)); } @@ -316,7 +316,7 @@ macro_rules! impl_move_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn move_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + fn move_assign(this: $crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { this.write(src.with(Self::clone)); this.clone() } @@ -326,8 +326,8 @@ macro_rules! impl_move_by_clone { where $ty: Clone, { - unsafe fn move_constructor(&mut self, src: *mut Self) { - unsafe { std::ptr::write(self, (*src).clone()) } + unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe { std::ptr::write(this, (*src).clone()) } } } @@ -335,9 +335,9 @@ macro_rules! impl_move_by_clone { where $ty: Clone, { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - unsafe { *self = (*src).clone() }; - self + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe { *this = (*src).clone() }; + this } } @@ -345,14 +345,14 @@ macro_rules! impl_move_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn swap(this: &$crate::Ptr, other: $crate::Ptr) { + fn swap(this: $crate::Ptr, other: $crate::Ptr) { this.swap_with(&other, |p| p.with(Self::clone)); } } impl<$($param),*> $crate::SwappableUnsafe for $ty { - unsafe fn swap(&mut self, other: *mut Self) { - unsafe { std::ptr::swap(self, other) } + unsafe fn swap(this: *mut Self, other: *mut Self) { + unsafe { std::ptr::swap(this, other) } } } )*}; @@ -422,11 +422,11 @@ macro_rules! impl_trivially_copyable_by_clone { } impl<$($param),*> $crate::Destructible for $ty { - fn destroy(_this: &$crate::Ptr) {} + fn destroy(_this: $crate::Ptr) {} } impl<$($param),*> $crate::DestructibleUnsafe for $ty { - unsafe fn destroy(&mut self) {} + unsafe fn destroy(_this: *mut Self) {} } impl<$($param),*> $crate::capture::TriviallyDestructible for $ty {} @@ -455,7 +455,7 @@ macro_rules! impl_move_by_take { where $ty: Default + $crate::ByteRepr, { - fn move_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + fn move_constructor(this: $crate::Ptr, src: $crate::Ptr) { let value = src.with_mut(std::mem::take); this.with_mut(|dst| *dst = value); } @@ -470,7 +470,7 @@ macro_rules! impl_move_by_take { where $ty: Default + $crate::ByteRepr, { - fn move_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + fn move_assign(this: $crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { let value = src.with_mut(std::mem::take); this.with_mut(|dst| *dst = value); this.clone() @@ -481,8 +481,8 @@ macro_rules! impl_move_by_take { where $ty: Default, { - unsafe fn move_constructor(&mut self, src: *mut Self) { - unsafe { std::ptr::write(self, std::mem::take(&mut *src)) } + unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe { std::ptr::write(this, std::mem::take(&mut *src)) } } } @@ -490,9 +490,9 @@ macro_rules! impl_move_by_take { where $ty: Default, { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - unsafe { *self = std::mem::take(&mut *src) }; - self + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe { *this = std::mem::take(&mut *src) }; + this } } @@ -500,14 +500,14 @@ macro_rules! impl_move_by_take { where $ty: Default + $crate::ByteRepr, { - fn swap(this: &$crate::Ptr, other: $crate::Ptr) { + fn swap(this: $crate::Ptr, other: $crate::Ptr) { this.swap_with(&other, |p| p.with_mut(std::mem::take)); } } impl<$($param),*> $crate::SwappableUnsafe for $ty { - unsafe fn swap(&mut self, other: *mut Self) { - unsafe { std::ptr::swap(self, other) } + unsafe fn swap(this: *mut Self, other: *mut Self) { + unsafe { std::ptr::swap(this, other) } } } )*}; @@ -517,8 +517,8 @@ pub(crate) use impl_move_by_take; macro_rules! impl_default_by_zeroed { ($($ty:ty),* $(,)?) => {$( impl $crate::DefaultConstructibleUnsafe for $ty { - unsafe fn default_constructor(&mut self) { - unsafe { std::ptr::write(self, std::mem::zeroed()) } + unsafe fn default_constructor(this: *mut Self) { + unsafe { std::ptr::write(this, std::mem::zeroed()) } } } @@ -533,7 +533,7 @@ macro_rules! impl_trivially_default_constructible { where $ty: Default + ByteRepr, { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { this.write(Self::default()); } } @@ -544,8 +544,8 @@ macro_rules! impl_trivially_default_constructible { where $ty: Default, { - unsafe fn default_constructor(&mut self) { - unsafe { std::ptr::write(self, Self::default()) } + unsafe fn default_constructor(this: *mut Self) { + unsafe { std::ptr::write(this, Self::default()) } } } @@ -590,44 +590,45 @@ impl TriviallyDefaultConstructibleUnsafe for *mut T {} impl TriviallyDefaultConstructibleUnsafe for *const T {} impl DefaultConstructible for FnPtr { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { this.with_mut(|dst| *dst = ::zero_init()); } } impl DefaultConstructibleUnsafe for FnPtr { - unsafe fn default_constructor(&mut self) { - unsafe { std::ptr::write(self, ::zero_init()) } + unsafe fn default_constructor(this: *mut Self) { + unsafe { std::ptr::write(this, ::zero_init()) } } } impl DefaultConstructible for Box<[T]> { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { let len = this.with(|elems| elems.len()); let dst = this.decay(); for i in 0..len { - T::default_constructor(&dst.offset(i)); + T::default_constructor(dst.offset(i)); } } } impl DefaultConstructibleUnsafe for [T; N] { - unsafe fn default_constructor(&mut self) { - for elem in self.iter_mut() { - unsafe { elem.default_constructor() } + unsafe fn default_constructor(this: *mut Self) { + let this = this as *mut T; + for i in 0..N { + unsafe { T::default_constructor(this.add(i)) } } } } impl DefaultConstructibleUnsafe for *mut T { - unsafe fn default_constructor(&mut self) { - unsafe { std::ptr::write(self, std::ptr::null_mut()) } + unsafe fn default_constructor(this: *mut Self) { + unsafe { std::ptr::write(this, std::ptr::null_mut()) } } } impl DefaultConstructibleUnsafe for *const T { - unsafe fn default_constructor(&mut self) { - unsafe { std::ptr::write(self, std::ptr::null()) } + unsafe fn default_constructor(this: *mut Self) { + unsafe { std::ptr::write(this, std::ptr::null()) } } } @@ -734,13 +735,13 @@ where } impl Destructible for (A, B) { - fn destroy(_this: &Ptr) {} + fn destroy(_this: Ptr) {} } impl TriviallyDestructible for (A, B) {} impl DestructibleUnsafe for (A, B) { - unsafe fn destroy(&mut self) {} + unsafe fn destroy(_this: *mut Self) {} } impl TriviallyDestructibleUnsafe @@ -749,7 +750,7 @@ impl TriviallyDe } impl MoveConstructible for FnPtr { - fn move_constructor(this: &Ptr, src: Ptr) { + fn move_constructor(this: Ptr, src: Ptr) { let value = src.with(FnPtr::move_from); this.with_mut(|dst| *dst = value); } @@ -762,7 +763,7 @@ impl TriviallyMoveConstructible for FnPtr { } impl CopyConstructible for FnPtr { - fn copy_constructor(this: &Ptr, src: Ptr) { + fn copy_constructor(this: Ptr, src: Ptr) { let value = src.with(FnPtr::copy_from); this.with_mut(|dst| *dst = value); } @@ -775,44 +776,44 @@ impl TriviallyCopyConstructible for FnPtr { } impl MoveAssignable for FnPtr { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr { - ::move_constructor(this, src); - this.clone() + fn move_assign(this: Ptr, src: Ptr) -> Ptr { + ::move_constructor(this.clone(), src); + this } } impl TriviallyMoveAssignable for FnPtr {} impl CopyAssignable for FnPtr { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { - ::copy_constructor(this, src); - this.clone() + fn copy_assign(this: Ptr, src: Ptr) -> Ptr { + ::copy_constructor(this.clone(), src); + this } } impl TriviallyCopyAssignable for FnPtr {} impl Swappable for FnPtr { - fn swap(this: &Ptr, other: Ptr) { + fn swap(this: Ptr, other: Ptr) { this.swap_with(&other, |p| p.with(FnPtr::move_from)); } } impl SwappableUnsafe for FnPtr { - unsafe fn swap(&mut self, other: *mut Self) { - unsafe { std::ptr::swap(self, other) } + unsafe fn swap(this: *mut Self, other: *mut Self) { + unsafe { std::ptr::swap(this, other) } } } impl MoveConstructibleUnsafe for FnPtr { - unsafe fn move_constructor(&mut self, src: *mut Self) { - unsafe { std::ptr::write(self, (*src).move_from()) } + unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe { std::ptr::write(this, (*src).move_from()) } } } impl CopyConstructibleUnsafe for FnPtr { - unsafe fn copy_constructor(&mut self, src: *const Self) { - unsafe { std::ptr::write(self, (*src).copy_from()) } + unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + unsafe { std::ptr::write(this, (*src).copy_from()) } } } @@ -829,16 +830,16 @@ impl TriviallyCopyConstructibleUnsafe for FnPtr { } impl MoveAssignableUnsafe for FnPtr { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - unsafe { *self = (*src).move_from() }; - self + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe { *this = (*src).move_from() }; + this } } impl CopyAssignableUnsafe for FnPtr { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - unsafe { *self = (*src).copy_from() }; - self + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe { *this = (*src).copy_from() }; + this } } @@ -849,32 +850,32 @@ impl TriviallyCopyAssignableUnsafe for FnPtr {} fn construct_elems( this: &Ptr>, src: &Ptr>, - construct: fn(&Ptr, Ptr), + construct: fn(Ptr, Ptr), ) { let len = src.with(|elems| elems.len()); this.with_mut(|elems| *elems = (0..len).map(|_| T::zero_init()).collect()); let (dst, src) = (this.decay(), src.decay()); for i in 0..len { - construct(&dst.offset(i), src.offset(i)); + construct(dst.offset(i), src.offset(i)); } } fn assign_elems( this: &Ptr>, src: &Ptr>, - assign: fn(&Ptr, Ptr) -> Ptr, + assign: fn(Ptr, Ptr) -> Ptr, ) -> Ptr> { let len = src.with(|elems| elems.len()); let (dst, src) = (this.decay(), src.decay()); for i in 0..len { - assign(&dst.offset(i), src.offset(i)); + assign(dst.offset(i), src.offset(i)); } this.clone() } impl MoveConstructible for Box<[T]> { - fn move_constructor(this: &Ptr, src: Ptr) { - construct_elems(this, &src, T::move_constructor); + fn move_constructor(this: Ptr, src: Ptr) { + construct_elems(&this, &src, T::move_constructor); } } @@ -887,8 +888,8 @@ 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: Ptr) { + construct_elems(&this, &src, T::copy_constructor); } } @@ -901,54 +902,57 @@ 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: Ptr) -> Ptr { + assign_elems(&this, &src, T::move_assign) } } 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: Ptr) -> Ptr { + assign_elems(&this, &src, T::copy_assign) } } impl TriviallyCopyAssignable for Box<[T]> {} impl Swappable for Box<[T]> { - fn swap(this: &Ptr, other: Ptr) { + fn swap(this: Ptr, other: Ptr) { let len = other.with(|elems| elems.len()); let (dst, src) = (this.decay(), other.decay()); for i in 0..len { - T::swap(&dst.offset(i), src.offset(i)); + T::swap(dst.offset(i), src.offset(i)); } } } impl SwappableUnsafe for [T; N] { - unsafe fn swap(&mut self, other: *mut Self) { + unsafe fn swap(this: *mut Self, other: *mut Self) { let other = other as *mut T; - for (i, elem) in self.iter_mut().enumerate() { - unsafe { SwappableUnsafe::swap(elem, other.add(i)) } + let this = this as *mut T; + for i in 0..N { + unsafe { SwappableUnsafe::swap(this.add(i), other.add(i)) } } } } impl MoveConstructibleUnsafe for [T; N] { - unsafe fn move_constructor(&mut self, src: *mut Self) { + unsafe fn move_constructor(this: *mut Self, src: *mut Self) { let src = src as *mut T; - for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.move_constructor(src.add(i)) } + let this = this as *mut T; + for i in 0..N { + unsafe { T::move_constructor(this.add(i), src.add(i)) } } } } impl CopyConstructibleUnsafe for [T; N] { - unsafe fn copy_constructor(&mut self, src: *const Self) { + unsafe fn copy_constructor(this: *mut Self, src: *const Self) { let src = src as *const T; - for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.copy_constructor(src.add(i)) } + let this = this as *mut T; + for i in 0..N { + unsafe { T::copy_constructor(this.add(i), src.add(i)) } } } } @@ -972,22 +976,24 @@ impl TriviallyCopyConstruct } impl MoveAssignableUnsafe for [T; N] { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { let src = src as *mut T; - for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.move_assign(src.add(i)) }; + let dst = this as *mut T; + for i in 0..N { + unsafe { T::move_assign(dst.add(i), src.add(i)) }; } - self + this } } impl CopyAssignableUnsafe for [T; N] { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { let src = src as *const T; - for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.copy_assign(src.add(i)) }; + let dst = this as *mut T; + for i in 0..N { + unsafe { T::copy_assign(dst.add(i), src.add(i)) }; } - self + this } } diff --git a/libcc2rs/src/object.rs b/libcc2rs/src/object.rs index 37027338a2..fc0575a955 100644 --- a/libcc2rs/src/object.rs +++ b/libcc2rs/src/object.rs @@ -45,38 +45,38 @@ 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); + fn construct_from(self, src: S); } impl ConstructFrom> for Ptr { #[inline(always)] - fn construct_from(&self, src: Ptr) { + fn construct_from(self, src: Ptr) { T::copy_constructor(self, src) } } impl ConstructFrom>> for Ptr { #[inline(always)] - fn construct_from(&self, src: Moved>) { + 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; + fn assign_from(self, src: S) -> Self; } impl AssignFrom> for Ptr { #[inline(always)] - fn assign_from(&self, src: Ptr) -> Ptr { + 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 { + fn assign_from(self, src: Moved>) -> Ptr { T::move_assign(self, src.0) } } @@ -86,14 +86,14 @@ impl AssignFrom>> for Ptr { pub trait ConstructFromUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn construct_from(&mut self, src: S); + 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(&mut self, src: S) -> *mut Self; + 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 @@ -102,15 +102,15 @@ macro_rules! unsafe_sources { ($($src:ty),*) => {$( impl<'a, T: CopyConstructibleUnsafe> ConstructFromUnsafe<$src> for T { #[inline(always)] - unsafe fn construct_from(&mut self, src: $src) { - unsafe { T::copy_constructor(self, src) } + 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(&mut self, src: $src) -> *mut T { - unsafe { T::copy_assign(self, src) } + unsafe fn assign_from(this: *mut Self, src: $src) -> *mut T { + unsafe { T::copy_assign(this, src) } } } )*}; @@ -122,15 +122,15 @@ macro_rules! unsafe_moved_sources { ($($src:ty),*) => {$( impl<'a, T: MoveConstructibleUnsafe> ConstructFromUnsafe> for T { #[inline(always)] - unsafe fn construct_from(&mut self, src: Moved<$src>) { - unsafe { T::move_constructor(self, src.0) } + 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(&mut self, src: Moved<$src>) -> *mut T { - unsafe { T::move_assign(self, src.0) } + unsafe fn assign_from(this: *mut Self, src: Moved<$src>) -> *mut T { + unsafe { T::move_assign(this, src.0) } } } )*}; @@ -172,7 +172,7 @@ pub struct DestroyGuard<'a, T: Destructible>(&'a Value); impl Drop for DestroyGuard<'_, T> { #[inline(always)] fn drop(&mut self) { - T::destroy(&self.0.as_pointer()) + T::destroy(self.0.as_pointer()) } } @@ -208,7 +208,7 @@ pub struct DestroyGuardUnsafe(*mut T); impl Drop for DestroyGuardUnsafe { #[inline(always)] fn drop(&mut self) { - unsafe { DestructibleUnsafe::destroy(&mut *self.0) } + unsafe { DestructibleUnsafe::destroy(self.0) } } } @@ -241,7 +241,7 @@ impl GuardNoneUnsafe for LocalUnsafe {} macro_rules! object { ($name:ident, $ty:ident :: $ctor:ident ($($arg:expr),* $(,)?)) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); - <$crate::Ptr<$ty>>::$ctor(&$crate::AsPointer::<$ty>::as_pointer(&$name), $($arg),*); + $ty::$ctor($crate::AsPointer::<$ty>::as_pointer(&$name), $($arg),*); $crate::object!(@guard $name); }; ($name:ident, $ty:ident ($($arg:expr),* $(,)?)) => { @@ -250,7 +250,7 @@ macro_rules! object { ($name:ident, $ty:ty, |$this:ident| $init:expr) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); { - let $this: &$crate::Ptr<$ty> = &$crate::AsPointer::<$ty>::as_pointer(&$name); + let $this: $crate::Ptr<$ty> = $crate::AsPointer::<$ty>::as_pointer(&$name); $init; } $crate::object!(@guard $name); @@ -258,7 +258,7 @@ macro_rules! object { ($name:ident, $ty:ty, $src:expr) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); $crate::ConstructFrom::construct_from( - &$crate::AsPointer::<$ty>::as_pointer(&$name), + $crate::AsPointer::<$ty>::as_pointer(&$name), $src, ); $crate::object!(@guard $name); @@ -266,7 +266,7 @@ macro_rules! object { ($name:ident, $ty:ty) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); $crate::DefaultConstructible::default_constructor( - &$crate::AsPointer::<$ty>::as_pointer(&$name), + $crate::AsPointer::<$ty>::as_pointer(&$name), ); $crate::object!(@guard $name); }; @@ -283,7 +283,7 @@ macro_rules! object_unsafe { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - <$ty>::$ctor(&mut $name, $($arg),*) + <$ty>::$ctor(&raw mut $name, $($arg),*) }; $crate::object_unsafe!(@guard $name); }; @@ -293,7 +293,7 @@ macro_rules! object_unsafe { ($name:ident, $ty:ty, |$this:ident| $init:expr) => { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); { - let $this: &mut $ty = &mut $name; + let $this: *mut $ty = &raw mut $name; $init; } $crate::object_unsafe!(@guard $name); @@ -302,7 +302,7 @@ macro_rules! object_unsafe { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - $crate::ConstructFromUnsafe::construct_from(&mut $name, $src) + $crate::ConstructFromUnsafe::construct_from(&raw mut $name, $src) }; $crate::object_unsafe!(@guard $name); }; @@ -310,7 +310,7 @@ macro_rules! object_unsafe { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - $crate::DefaultConstructibleUnsafe::default_constructor(&mut $name) + $crate::DefaultConstructibleUnsafe::default_constructor(&raw mut $name) }; $crate::object_unsafe!(@guard $name); }; diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index d23affb9cc..3928183a5a 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), 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), 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 { - (*dst.as_mut_ptr()).copy_constructor(src); + T::copy_constructor(dst.as_mut_ptr(), 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 { - (*dst.as_mut_ptr()).move_constructor(src); + T::move_constructor(dst.as_mut_ptr(), src); dst.assume_init() } } @@ -150,30 +150,29 @@ impl ConstructNoneUnsafe for &ConstructUnsafe { } } -pub fn swap_by_move(this: &Ptr, other: Ptr) +pub fn swap_by_move(this: Ptr, other: Ptr) where T: MoveConstructible + MoveAssignable + Destructible + ZeroInitialization, { let storage: Value = Rc::new(RefCell::new(T::zero_init())); let tmp = AsPointer::::as_pointer(&storage); - T::move_constructor(&tmp, this.clone()); + T::move_constructor(tmp.clone(), this.clone()); T::move_assign(this, other.clone()); - T::move_assign(&other, tmp.clone()); - T::destroy(&tmp); + T::move_assign(other.clone(), tmp.clone()); + T::destroy(tmp.clone()); } /// # Safety /// `other` must point to a live value. -pub unsafe fn swap_by_move_unsafe(this: &mut T, other: *mut T) +pub unsafe fn swap_by_move_unsafe(this: *mut T, other: *mut T) where T: MoveConstructibleUnsafe + MoveAssignableUnsafe + DestructibleUnsafe, { - let this: *mut T = this; let mut tmp = MaybeUninit::::uninit(); unsafe { - MoveConstructibleUnsafe::move_constructor(&mut *tmp.as_mut_ptr(), this); - MoveAssignableUnsafe::move_assign(&mut *this, other); - MoveAssignableUnsafe::move_assign(&mut *other, tmp.as_mut_ptr()); - DestructibleUnsafe::destroy(&mut *tmp.as_mut_ptr()); + MoveConstructibleUnsafe::move_constructor(tmp.as_mut_ptr(), this); + MoveAssignableUnsafe::move_assign(this, other); + MoveAssignableUnsafe::move_assign(other, tmp.as_mut_ptr()); + DestructibleUnsafe::destroy(tmp.as_mut_ptr()); } } diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index e63cd19bb5..c4e8e12b6b 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -35,7 +35,7 @@ fn f2< fn f3, T2, T3: CppEq>(a0: T1, a1: T1, a2: Ptr) -> T1 { let mut __it = a0; - while __it != a1 && !CppEq::equal(&__it.iter_deref(), &a2) { + while __it != a1 && !CppEq::equal(__it.iter_deref(), a2.clone()) { __it.iter_inc(); } __it @@ -67,7 +67,7 @@ fn f8, T2: CppLess>(a0: T1, a1: T1) -> T1 { let mut __it = a0; __it.iter_inc(); while __it != a1 { - if CppLess::less(&__best.iter_deref(), &__it.iter_deref()) { + if CppLess::less(__best.iter_deref(), __it.iter_deref()) { __best = __it.clone(); } __it.iter_inc(); @@ -77,7 +77,7 @@ fn f8, T2: CppLess>(a0: T1, a1: T1) -> T1 { } fn f9(a0: Ptr, a1: Ptr) { - Swappable::swap(&a0, a1) + Swappable::swap(a0, a1) } fn f10, T2: CppEq + TriviallyCopyable + ByteRepr>( @@ -91,7 +91,7 @@ fn f10, T2: CppEq + TriviallyCopyable + ByteRepr>( let mut __it = a0; __it.iter_inc(); while __it != a1 { - if !CppEq::equal(&__write.iter_deref(), &__it.iter_deref()) { + if !CppEq::equal(__write.iter_deref(), __it.iter_deref()) { __write.iter_inc(); __write.iter_deref().write(__it.iter_deref().read()); } @@ -143,11 +143,11 @@ where } fn f16(a0: Ptr, a1: Ptr) -> Ptr { - if CppLess::less(&a1, &a0) { a1 } else { a0 } + if CppLess::less(a1.clone(), a0.clone()) { a1 } else { a0 } } fn f17(a0: Ptr, a1: Ptr) -> Ptr { - if CppLess::less(&a0, &a1) { a1 } else { a0 } + if CppLess::less(a0.clone(), a1.clone()) { a1 } else { a0 } } fn f18, T2: Swappable>(a0: T1, a1: T1) { @@ -155,6 +155,6 @@ fn f18, T2: Swappable>(a0: T1, a1: T1) { let __random = std::hash::RandomState::new(); for __i in (1..__n).rev() { let __j = (std::hash::BuildHasher::hash_one(&__random, __i) % (__i + 1) as u64) as isize; - Swappable::swap(&a0.iter_at(__i), a0.iter_at(__j)); + Swappable::swap(a0.iter_at(__i), a0.iter_at(__j)); } } diff --git a/rules/deque/tgt_unsafe.rs b/rules/deque/tgt_unsafe.rs index d2b5a47390..7ef71bfc24 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 { - a0.assign_from(a1); + AssignFromUnsafe::assign_from(&raw mut *a0, a1); a0 } diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index 7fcaaeedd4..ee31e5ba33 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -7,7 +7,9 @@ use std::marker::PhantomData; use std::rc::Rc; -use crate::{ByteRepr, MapNode, PostfixDec, PostfixInc, PrefixDec, PrefixInc, Ptr, UnsafeMapNode, Value}; +use crate::{ + ByteRepr, MapNode, PostfixDec, PostfixInc, PrefixDec, PrefixInc, Ptr, UnsafeMapNode, Value, +}; pub trait CppIterator: Clone { fn iter_deref(&self) -> Ptr; @@ -42,9 +44,7 @@ pub trait UnsafeCppBidirectionalIterator: UnsafeCppInputIterator { fn iter_post_dec(&mut self) -> Self; } -pub trait UnsafeCppRandomAccessIterator: - UnsafeCppBidirectionalIterator + PartialOrd -{ +pub trait UnsafeCppRandomAccessIterator: UnsafeCppBidirectionalIterator + PartialOrd { fn iter_add(&self, n: isize) -> Self; fn iter_add_assign(&mut self, n: isize) -> Self; fn iter_distance(&self, from: &Self) -> isize; diff --git a/rules/map/shim.rs b/rules/map/shim.rs index 94de6738cf..b907981b15 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -10,8 +10,8 @@ use std::rc::{Rc, Weak}; use crate::{ AsPointer, BidirectionalIterator, ByteRepr, CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, CppIterator, CppLess, Ptr, - UnsafeBidirectionalIterator, UnsafeCppIterator, Value, ZeroInitialization, - copy_constructed, copy_constructed_unsafe, cpp_cmp, + UnsafeBidirectionalIterator, UnsafeCppIterator, Value, ZeroInitialization, copy_constructed, + copy_constructed_unsafe, cpp_cmp, }; impl ByteRepr for BTreeMap {} @@ -115,7 +115,7 @@ where K: CppLess + CopyConstructible + ZeroInitialization + 'static, V: CopyConstructible + ZeroInitialization + 'static, { - fn copy_constructor(this: &Ptr, src: Ptr) { + fn copy_constructor(this: Ptr, src: Ptr) { this.write(Self::copied(src)); } @@ -147,7 +147,7 @@ where K: CppLess + CopyConstructible + ZeroInitialization + 'static, V: CopyConstructible + ZeroInitialization + 'static, { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { + fn copy_assign(this: Ptr, src: Ptr) -> Ptr { let map = Self::copied(src); this.write(map); this.clone() @@ -273,7 +273,6 @@ impl Map> { next.borrow_mut().prev = Rc::downgrade(&prev); next } - } // The functions that modify a map take a pointer to it, and borrow it after @@ -315,7 +314,10 @@ impl Map> { ) -> (BidirectionalIterator>, bool) { map.with_mut(|map| match map.search(key) { Ok(node) => (BidirectionalIterator::Map(node), false), - Err(prev) => (BidirectionalIterator::Map(map.link_after(prev, entry())), true), + Err(prev) => ( + BidirectionalIterator::Map(map.link_after(prev, entry())), + true, + ), }) } @@ -466,17 +468,17 @@ impl UnsafeMap CopyConstructibleUnsafe for UnsafeMap { - unsafe fn copy_constructor(&mut self, src: *const Self) { - unsafe { std::ptr::write(self, (*src).copied()) } + unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + unsafe { std::ptr::write(this, (*src).copied()) } } } impl CopyAssignableUnsafe for UnsafeMap { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - unsafe { *self = (*src).copied() }; - self + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe { *this = (*src).copied() }; + this } } @@ -607,7 +609,10 @@ impl UnsafeMap { pub fn emplace(&mut self, entry: (K, V)) -> (UnsafeBidirectionalIterator<(K, V)>, bool) { match self.search(&entry.0) { Ok(node) => (UnsafeBidirectionalIterator::Map(node), false), - Err(prev) => (UnsafeBidirectionalIterator::Map(self.link_after(prev, entry)), true), + Err(prev) => ( + UnsafeBidirectionalIterator::Map(self.link_after(prev, entry)), + true, + ), } } @@ -627,7 +632,9 @@ impl UnsafeMap { pub fn get(&self, key: &K) -> Option<*mut (K, V)> { self.nodes.get(&UnsafeMapKey(key)).map(|node| { - UnsafeMapNode::value(&**node as *const UnsafeMapNode<(K, V)> as *mut UnsafeMapNode<(K, V)>) + UnsafeMapNode::value( + &**node as *const UnsafeMapNode<(K, V)> as *mut UnsafeMapNode<(K, V)>, + ) }) } diff --git a/rules/map/tgt_unsafe.rs b/rules/map/tgt_unsafe.rs index e9de45d444..ef84fb347d 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: Ord + CopyConstructibleUnsafe, T2: CopyConstructibleUnsafe>(a0: &'a mut UnsafeMap, a1: *const UnsafeMap) -> &'a mut UnsafeMap { - a0.assign_from(a1); + AssignFromUnsafe::assign_from(&raw mut *a0, a1); a0 } diff --git a/rules/unique_ptr/shim.rs b/rules/unique_ptr/shim.rs index 264aad2598..bba738f7c5 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -12,7 +12,7 @@ impl MoveConstructible for Option> where Self: ByteRepr, { - fn move_constructor(this: &Ptr, src: Ptr) { + fn move_constructor(this: Ptr, src: Ptr) { let value = src.with_mut(Option::take); this.with_mut(|dst| *dst = value); } @@ -22,7 +22,7 @@ impl MoveAssignable for Option> where Self: ByteRepr, { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr { + fn move_assign(this: Ptr, src: Ptr) -> Ptr { let value = src.with_mut(Option::take); this.with_mut(|dst| *dst = value); this.clone() @@ -30,15 +30,15 @@ where } impl MoveConstructibleUnsafe for Option> { - unsafe fn move_constructor(&mut self, src: *mut Self) { - unsafe { std::ptr::write(self, (*src).take()) } + unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe { std::ptr::write(this, (*src).take()) } } } impl MoveAssignableUnsafe for Option> { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - unsafe { *self = (*src).take() }; - self + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe { *this = (*src).take() }; + this } } @@ -46,13 +46,13 @@ impl Swappable for Option> where Self: ByteRepr, { - fn swap(this: &Ptr, other: Ptr) { + fn swap(this: Ptr, other: Ptr) { this.swap_with(&other, |p| p.with_mut(Option::take)); } } impl SwappableUnsafe for Option> { - unsafe fn swap(&mut self, other: *mut Self) { - unsafe { std::ptr::swap(self, other) } + unsafe fn swap(this: *mut Self, other: *mut Self) { + unsafe { std::ptr::swap(this, other) } } } diff --git a/rules/vector/shim.rs b/rules/vector/shim.rs index 5dd36017b1..f3047eaaf3 100644 --- a/rules/vector/shim.rs +++ b/rules/vector/shim.rs @@ -23,7 +23,7 @@ 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) { + fn copy_constructor(this: Ptr, src: Ptr) { this.write(T::copied_elems(&src)); } @@ -33,7 +33,7 @@ impl CopyConstructible for } impl CopyAssignable for Vec { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { + fn copy_assign(this: Ptr, src: Ptr) -> Ptr { this.write(T::copied_elems(&src)); this.clone() } @@ -41,7 +41,7 @@ impl CopyAssignable for Ve // Pushes to v an element that construct constructs in place from src, which // may point into v, and so into the storage that the push reallocates. -unsafe fn push_constructed(v: &mut Vec, src: *mut T, construct: impl FnOnce(&mut T, *mut T)) { +unsafe fn push_constructed(v: &mut Vec, src: *mut T, construct: impl FnOnce(*mut T, *mut T)) { let len = v.len(); let size = std::mem::size_of::(); let offset = (src as usize).wrapping_sub(v.as_ptr() as usize); @@ -52,7 +52,7 @@ unsafe fn push_constructed(v: &mut Vec, src: *mut T, construct: impl FnOnc None => src, }; unsafe { - construct(&mut *v.as_mut_ptr().add(len), src); + construct(v.as_mut_ptr().add(len), src); v.set_len(len + 1); } } @@ -84,7 +84,7 @@ impl PushConstructedUnsafe for Vec { { unsafe { push_constructed(self, src.cast_mut(), |dst, src| { - dst.construct_from(src.cast_const()) + ConstructFromUnsafe::construct_from(dst, src.cast_const()) }) } } @@ -93,23 +93,32 @@ impl PushConstructedUnsafe for Vec { where T: MoveConstructibleUnsafe, { - unsafe { push_constructed(self, src, |dst, src| dst.construct_from(Moved(src))) } + unsafe { + push_constructed(self, src, |dst, src| { + ConstructFromUnsafe::construct_from(dst, Moved(src)) + }) + } } } unsafe fn copied_elems_unsafe(src: *const Vec) -> Vec { - unsafe { (*src).iter().map(|elem| copy_constructed_unsafe(elem)).collect() } + unsafe { + (*src) + .iter() + .map(|elem| copy_constructed_unsafe(elem)) + .collect() + } } impl CopyConstructibleUnsafe for Vec { - unsafe fn copy_constructor(&mut self, src: *const Self) { - unsafe { std::ptr::write(self, copied_elems_unsafe(src)) } + unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + unsafe { std::ptr::write(this, copied_elems_unsafe(src)) } } } impl CopyAssignableUnsafe for Vec { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - unsafe { *self = copied_elems_unsafe(src) }; - self + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe { *this = copied_elems_unsafe(src) }; + this } } diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index 99f8530687..c10cb2cb55 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 { - a0.assign_from(a1); + AssignFromUnsafe::assign_from(&raw mut *a0, 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 d5eb4a1c5f..f9bffd1c6b 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 @@ -28,6 +28,17 @@ pub struct S { #[array_len(2)] pub n: Box<[i32]>, } +impl S { + pub fn construct(this: Ptr, x: i32) { + let x: Value = Rc::new(RefCell::new(x)); + field!(this, v).write( + (0..({ ((*x.borrow()) as usize) })) + .map(|_| copy_constructed(x.as_pointer().clone())) + .collect(), + ); + field!(this, n).write(Box::new([(*x.borrow()), ((*x.borrow()) + 1)])); + } +} impl Default for S { fn default() -> Self { { ::zero_init() } @@ -53,9 +64,14 @@ pub struct T { #[byte_size(24)] pub v: Vec, } +impl T { + pub fn size(this: Ptr) -> i32 { + return (((*this.upgrade().deref()).v.len()) as i32); + } +} impl DefaultConstructible for T { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, v).write(Vec::new()); } } pub fn sum_0(s: Ptr) -> i32 { @@ -74,7 +90,7 @@ fn main_0() -> i32 { let t: Value = Rc::new(RefCell::new(T { v: Vec::from([1, 2]), })); - assert!((({ TImpl::size(&t.as_pointer(),) }) == 2)); + assert!((({ T::size(t.as_pointer(),) }) == 2)); return 0; } pub fn shuffle_1(mut x: i32) -> i32 { @@ -89,31 +105,9 @@ pub fn shuffle_1(mut x: i32) -> i32 { object!(w, T); assign!(w = Moved(u)); assert!( - ((({ TImpl::size(&t.as_pointer(),) }) == 0) && (({ TImpl::size(&u.as_pointer(),) }) == 0)) - && (({ TImpl::size(&w.as_pointer(),) }) == 1) + ((({ T::size(t.as_pointer(),) }) == 0) && (({ T::size(u.as_pointer(),) }) == 0)) + && (({ T::size(w.as_pointer(),) }) == 1) ); return ({ sum_0(c.as_pointer()) }); } -pub trait SImpl { - fn construct(&self, x: i32); -} -impl SImpl for Ptr { - fn construct(&self, x: i32) { - let x: Value = Rc::new(RefCell::new(x)); - field!((*self), v).write( - (0..({ ((*x.borrow()) as usize) })) - .map(|_| copy_constructed(x.as_pointer().clone())) - .collect(), - ); - field!((*self), n).write(Box::new([(*x.borrow()), ((*x.borrow()) + 1)])); - } -} -pub trait TImpl { - fn size(&self) -> i32; -} -impl TImpl for Ptr { - fn size(&self) -> i32 { - return (((*(*self).upgrade().deref()).v.len()) as i32); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs index ec85bb481c..e9e6c05d71 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 @@ -23,11 +23,11 @@ pub struct S { pub n: [i32; 2], } impl S { - pub unsafe fn construct(&mut self, mut x: i32) { - (&raw mut self.v).write(Vec::from_fn((x as usize), |_| { + pub unsafe fn construct(this: *mut Self, mut x: i32) { + (&raw mut (*this).v).write(Vec::from_fn((x as usize), |_| { copy_constructed_unsafe(&mut x) })); - (&raw mut self.n).write([x, ((x) + (1))]); + (&raw mut (*this).n).write([x, ((x) + (1))]); } } #[repr(C)] @@ -47,13 +47,13 @@ pub struct T { pub v: Vec, } impl T { - pub unsafe fn size(&self) -> i32 { - return ((self.v.len()) as i32); + pub unsafe fn size(this: *const Self) -> i32 { + return (((*this).v.len()) as i32); } } impl DefaultConstructibleUnsafe for T { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(Vec::new()); } } pub unsafe fn sum_0(s: *const S) -> i32 { @@ -72,7 +72,7 @@ unsafe fn main_0() -> i32 { let mut t: T = T { v: Vec::from([1, 2]), }; - assert!(((unsafe { T::size(&t,) }) == (2))); + assert!(((unsafe { T::size(&raw const t,) }) == (2))); return 0; } pub unsafe fn shuffle_1(mut x: i32) -> i32 { @@ -87,8 +87,9 @@ pub unsafe fn shuffle_1(mut x: i32) -> i32 { object_unsafe!(w, T); assign_unsafe!(w = Moved(u)); assert!( - (((unsafe { T::size(&t,) }) == (0)) && ((unsafe { T::size(&u,) }) == (0))) - && ((unsafe { T::size(&w,) }) == (1)) + (((unsafe { T::size(&raw const t,) }) == (0)) + && ((unsafe { T::size(&raw const u,) }) == (0))) + && ((unsafe { T::size(&raw const w,) }) == (1)) ); return (unsafe { sum_0(&c) }); } 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 3648091c45..ce8d8c60c4 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 @@ -24,12 +24,18 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.v); + } +} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default)] #[byte_size(4)] pub struct M { #[offset(0)] pub v: i32, } +impl M {} pub trait Base { fn apply(&mut self, x: i32) -> i32; } @@ -50,6 +56,7 @@ pub struct Derived { #[offset(8)] pub factor: i32, } +impl Derived {} #[derive( Copy, Clone, @@ -78,10 +85,10 @@ pub fn main() { } fn main_0() -> i32 { object!(s, S(1)); - assert!((({ SImpl::get(&s.as_pointer(),) }) == 1)); - ({ SImpl::set(&s.as_pointer(), 4) }); - assert!((({ SImpl::get(&s.as_pointer(),) }) == 4)); - assert!((({ SImpl::add(&s.as_pointer(), 2,) }) == 6)); + assert!((({ S::get(s.as_pointer(),) }) == 1)); + ({ S::set(s.as_pointer(), 4) }); + assert!((({ S::get(s.as_pointer(),) }) == 4)); + assert!((({ S::add(s.as_pointer(), 2,) }) == 6)); object!(m, M(2)); object!(n, M, Moved(m.as_pointer())); assert!(({ (*n.borrow()).v } == 2)); @@ -99,19 +106,47 @@ fn main_0() -> i32 { assert!((({ pair_diff_0((pair.as_pointer()),) }) == 4)); return 0; } +impl S { + pub fn construct(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } +} +impl M { + pub fn construct(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } +} impl MoveConstructible for M { - fn move_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), v).write({ (*_a0.upgrade().deref()).v }); + fn move_constructor(this: Ptr, _a0: Ptr) { + field!(this, v).write({ (*_a0.upgrade().deref()).v }); } } impl CopyConstructible for M { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write((o.with(|__s| __s.v) + 1)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write((o.with(|__s| __s.v) + 1)); + } +} +impl Derived { + pub fn construct(this: Ptr, mut factor: i32) { + field!(this, factor).write(factor); } } impl S {} impl Destructible for S { - fn destroy(this: &Ptr) {} + fn destroy(this: Ptr) {} +} +impl S { + pub fn set(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } +} +impl S { + pub fn add(this: Ptr, mut x: i32) -> i32 { + { + field!(this, v).with_mut(|__v| *__v = *__v + x) + }; + return this.with(|__s| __s.v); + } } impl M {} pub fn move_m_1(mut x: i32) -> i32 { @@ -128,53 +163,4 @@ impl Base for Derived { return ({ self.factor } * x); } } -pub trait DerivedImpl { - fn construct(&self, mut factor: i32) { - unimplemented!() - } -} -impl DerivedImpl for Ptr { - fn construct(&self, mut factor: i32) { - field!((*self), factor).write(factor); - } -} -pub trait MImpl { - fn construct(&self, mut x: i32) { - unimplemented!() - } -} -impl MImpl for Ptr { - fn construct(&self, mut x: i32) { - field!((*self), v).write(x); - } -} -pub trait SImpl { - fn construct(&self, mut x: i32) { - unimplemented!() - } - fn get(&self) -> i32; - fn set(&self, mut x: i32) { - unimplemented!() - } - fn add(&self, mut x: i32) -> i32 { - unimplemented!() - } -} -impl SImpl for Ptr { - fn get(&self) -> i32 { - return (*self).with(|__s| __s.v); - } - fn construct(&self, mut x: i32) { - field!((*self), v).write(x); - } - fn set(&self, mut x: i32) { - field!((*self), v).write(x); - } - fn add(&self, mut x: i32) -> i32 { - { - field!((*self), v).with_mut(|__v| *__v = *__v + x) - }; - return (*self).with(|__s| __s.v); - } -} pub fn __cpp2rust_init_globals() {} 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 5f7baa55a3..b8cec259eb 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 @@ -22,8 +22,8 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn get(&self) -> i32 { - return self.v; + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).v; } } #[repr(C)] @@ -76,10 +76,10 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(s, S(1)); - assert!(((unsafe { S::get(&s,) }) == (1))); - (unsafe { S::set(&mut s, 4) }); - assert!(((unsafe { S::get(&s,) }) == (4))); - assert!(((unsafe { S::add(&mut s, 2,) }) == (6))); + assert!(((unsafe { S::get(&raw const s,) }) == (1))); + (unsafe { S::set(&raw mut s, 4) }); + assert!(((unsafe { S::get(&raw const s,) }) == (4))); + assert!(((unsafe { S::add(&raw mut s, 2,) }) == (6))); object_unsafe!(m, M(2)); object_unsafe!(n, M, Moved(&mut m)); assert!(((n.v) == (2))); @@ -98,43 +98,43 @@ unsafe fn main_0() -> i32 { return 0; } impl S { - pub unsafe fn construct(&mut self, mut x: i32) { - (&raw mut self.v).write(x); + pub unsafe fn construct(this: *mut Self, mut x: i32) { + (&raw mut (*this).v).write(x); } } impl M { - pub unsafe fn construct(&mut self, mut x: i32) { - (&raw mut self.v).write(x); + pub unsafe fn construct(this: *mut Self, mut x: i32) { + (&raw mut (*this).v).write(x); } } impl MoveConstructibleUnsafe for M { - unsafe fn move_constructor(&mut self, _a0: *mut M) { - (&raw mut self.v).write((*_a0).v); + unsafe fn move_constructor(this: *mut Self, _a0: *mut M) { + (&raw mut (*this).v).write((*_a0).v); } } impl CopyConstructibleUnsafe for M { - unsafe fn copy_constructor(&mut self, o: *const M) { - (&raw mut self.v).write((((*o).v) + (1))); + unsafe fn copy_constructor(this: *mut Self, o: *const M) { + (&raw mut (*this).v).write((((*o).v) + (1))); } } impl Derived { - pub unsafe fn construct(&mut self, mut factor: i32) { - (&raw mut self.factor).write(factor); + pub unsafe fn construct(this: *mut Self, mut factor: i32) { + (&raw mut (*this).factor).write(factor); } } impl S {} impl DestructibleUnsafe for S { - unsafe fn destroy(&mut self) {} + unsafe fn destroy(this: *mut Self) {} } impl S { - pub unsafe fn set(&mut self, mut x: i32) { - self.v = x; + pub unsafe fn set(this: *mut Self, mut x: i32) { + (*this).v = x; } } impl S { - pub unsafe fn add(&mut self, mut x: i32) -> i32 { - self.v += x; - return self.v; + pub unsafe fn add(this: *mut Self, mut x: i32) -> i32 { + (*this).v += x; + return (*this).v; } } impl M {} diff --git a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs index 8db93d594b..09b91429d0 100644 --- a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs @@ -12,9 +12,14 @@ pub struct S_int_ { #[offset(0)] pub x: i32, } +impl S_int_ { + pub fn set(this: Ptr, mut v: i32) { + field!(this, x).write(v); + } +} impl DefaultConstructible for S_int_ { - fn default_constructor(this: &Ptr) { - field!((*this), x).write(0); + fn default_constructor(this: Ptr) { + field!(this, x).write(0); } } impl Default for S_int_ { @@ -28,25 +33,16 @@ pub fn main() { } fn main_0() -> i32 { object!(p, S_int_); - ({ S_int_Impl::set(&p.as_pointer(), 3) }); + ({ S_int_::set(p.as_pointer(), 3) }); assert!((({ f_0((p.as_pointer()),) }) == 3)); return 0; } -pub fn f_0(mut p: Ptr) -> i32 { - return ({ S_int_Impl::get(&p) }); -} -pub trait S_int_Impl { - fn set(&self, v: i32); - fn get(&self) -> i32 { - unimplemented!() +impl S_int_ { + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.x); } } -impl S_int_Impl for Ptr { - fn set(&self, mut v: i32) { - field!((*self), x).write(v); - } - fn get(&self) -> i32 { - return (*self).with(|__s| __s.x); - } +pub fn f_0(mut p: Ptr) -> i32 { + return ({ S_int_::get(p) }); } pub fn __cpp2rust_init_globals() {} diff --git a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs index 8e77fce3de..71c5b881a5 100644 --- a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs @@ -12,13 +12,13 @@ pub struct S_int_ { pub x: i32, } impl S_int_ { - pub unsafe fn set(&mut self, mut v: i32) { - self.x = v; + pub unsafe fn set(this: *mut Self, mut v: i32) { + (*this).x = v; } } impl DefaultConstructibleUnsafe for S_int_ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.x).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).x).write(0); } } impl Default for S_int_ { @@ -34,16 +34,16 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(p, S_int_); - (unsafe { S_int_::set(&mut p, 3) }); + (unsafe { S_int_::set(&raw mut p, 3) }); assert!(((unsafe { f_0((&mut p as *mut S_int_),) }) == (3))); return 0; } impl S_int_ { - pub unsafe fn get(&mut self) -> i32 { - return self.x; + pub unsafe fn get(this: *mut Self) -> i32 { + return (*this).x; } } pub unsafe fn f_0(mut p: *mut S_int_) -> i32 { - return (unsafe { S_int_::get(&mut (*p)) }); + return (unsafe { S_int_::get(&raw mut (*p)) }); } pub unsafe fn __cpp2rust_init_globals() {} 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 ab50e8b772..79458eb9a7 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 @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,15 +96,15 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } thread_local!( pub static check_4: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 2 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_4.with(Value::clone).as_pointer()) + Destructible::destroy(check_4.with(Value::clone).as_pointer()) }); __static }; @@ -107,11 +113,11 @@ thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&shared_5.with(Value::clone).as_pointer()) + Destructible::destroy(shared_5.with(Value::clone).as_pointer()) }); __static }; @@ -139,11 +145,11 @@ thread_local!( static local_6: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&local_6.with(Value::clone).as_pointer()) + Destructible::destroy(local_6.with(Value::clone).as_pointer()) }); __static }; @@ -153,8 +159,8 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); - ({ LifetimeTrackedImpl::use_(&({ HasInlineMembers::instance() })) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(({ HasInlineMembers::instance() })) }); ({ b_use_7() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); assert!(({ (*shared_5.with(Value::clone).borrow()).uses } == 2)); @@ -165,8 +171,8 @@ fn main_0() -> i32 { return 0; } pub fn b_use_7() { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); - ({ LifetimeTrackedImpl::use_(&({ HasInlineMembers::instance() })) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(({ HasInlineMembers::instance() })) }); } pub fn b_shared_address_8() -> Ptr { return (shared_5.with(|v| v.as_pointer())); @@ -174,17 +180,6 @@ pub fn b_shared_address_8() -> Ptr { pub fn b_instance_address_9() -> Ptr { return ({ HasInlineMembers::instance() }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index dd845ee0e4..eac9cfd4f8 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 @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub static mut check_4: std::cell::LazyCell = @@ -93,7 +95,7 @@ pub static mut shared_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -123,7 +125,7 @@ static mut local_6: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -139,8 +141,10 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); - (unsafe { LifetimeTracked::use_(&(*(unsafe { HasInlineMembers::instance() }))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { HasInlineMembers::instance() }))) }); (unsafe { b_use_7() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)).uses) == (2))); @@ -155,8 +159,10 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_7() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); - (unsafe { LifetimeTracked::use_(&(*(unsafe { HasInlineMembers::instance() }))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { HasInlineMembers::instance() }))) }); } pub unsafe fn b_shared_address_8() -> *mut LifetimeTracked { return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) 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 d8b659e11f..4c20fca662 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 @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -75,11 +81,11 @@ thread_local!( pub static member_4: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&member_4.with(Value::clone).as_pointer()) + Destructible::destroy(member_4.with(Value::clone).as_pointer()) }); __static }; @@ -102,11 +108,11 @@ thread_local!( pub static member_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&member_5.with(Value::clone).as_pointer()) + Destructible::destroy(member_5.with(Value::clone).as_pointer()) }); __static }; @@ -130,7 +136,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&member_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(member_4.with(|v| v.as_pointer())) }); ({ b_use_int_6() }); ({ b_use_long_7() }); assert!(({ (*member_4.with(Value::clone).borrow()).uses } == 2)); @@ -141,25 +147,14 @@ fn main_0() -> i32 { return 0; } pub fn b_use_int_6() { - ({ LifetimeTrackedImpl::use_(&member_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(member_4.with(|v| v.as_pointer())) }); } pub fn b_use_long_7() { - ({ LifetimeTrackedImpl::use_(&member_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(member_5.with(|v| v.as_pointer())) }); } pub fn b_int_address_8() -> Ptr { return (member_4.with(|v| v.as_pointer())); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index 8682ae7d9d..f7bd50ec67 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 @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -63,7 +63,7 @@ pub static mut member_4: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -89,7 +89,7 @@ pub static mut member_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -117,7 +117,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) + }); (unsafe { b_use_int_6() }); (unsafe { b_use_long_7() }); assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut member_4)).uses) == (2))); @@ -132,10 +134,14 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_int_6() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) + }); } pub unsafe fn b_use_long_7() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_5))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut member_5))) + }); } pub unsafe fn b_int_address_8() -> *mut LifetimeTracked { return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4)) 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 074fbc99d8..ff95817e92 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 @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,8 +96,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } pub fn count_4() -> i32 { @@ -107,11 +113,11 @@ thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_5.with(Value::clone).as_pointer()) + Destructible::destroy(t_5.with(Value::clone).as_pointer()) }); __static }; @@ -123,11 +129,11 @@ thread_local!( static t_8: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_8.with(Value::clone).as_pointer()) + Destructible::destroy(t_8.with(Value::clone).as_pointer()) }); __static }; @@ -139,11 +145,11 @@ thread_local!( static t_11: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_11.with(Value::clone).as_pointer()) + Destructible::destroy(t_11.with(Value::clone).as_pointer()) }); __static }; @@ -155,7 +161,7 @@ thread_local!( pub static check_13: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 4 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_13.with(Value::clone).as_pointer()) + Destructible::destroy(check_13.with(Value::clone).as_pointer()) }); __static }; @@ -199,11 +205,11 @@ thread_local!( static t_19: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_19.with(Value::clone).as_pointer()) + Destructible::destroy(t_19.with(Value::clone).as_pointer()) }); __static }; @@ -234,17 +240,6 @@ pub fn b_count_local_15() -> i32 { )] #[byte_size(1)] pub struct S_21 {} -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index 240049d3f0..27a7a19458 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 @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub unsafe fn count_4() -> i32 { @@ -91,7 +93,7 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -105,7 +107,7 @@ static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -119,7 +121,7 @@ static mut t_11: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -178,7 +180,7 @@ static mut t_19: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 1ccf381543..5cfa74c365 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 @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,8 +96,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } pub fn instance_4() -> Ptr { @@ -101,11 +107,11 @@ thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_5.with(Value::clone).as_pointer()) + Destructible::destroy(t_5.with(Value::clone).as_pointer()) }); __static }; @@ -114,7 +120,7 @@ thread_local!( pub static check_6: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_6.with(Value::clone).as_pointer()) + Destructible::destroy(check_6.with(Value::clone).as_pointer()) }); __static }; @@ -125,7 +131,7 @@ pub fn main() { } fn main_0() -> i32 { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); - ({ LifetimeTrackedImpl::use_(&({ instance_4() })) }); + ({ LifetimeTracked::use_(({ instance_4() })) }); ({ b_use_7() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); @@ -136,22 +142,11 @@ fn main_0() -> i32 { return 0; } pub fn b_use_7() { - ({ LifetimeTrackedImpl::use_(&({ instance_4() })) }); + ({ LifetimeTracked::use_(({ instance_4() })) }); } pub fn b_address_8() -> Ptr { return ({ instance_4() }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs index b89d4469b2..5b95a4faa2 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 @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub unsafe fn instance_4() -> *mut LifetimeTracked { @@ -85,7 +87,7 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -112,7 +114,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); - (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_4() }))) }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { instance_4() }))) }); (unsafe { b_use_7() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); @@ -123,7 +125,7 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_7() { - (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_4() }))) }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { instance_4() }))) }); } pub unsafe fn b_address_8() -> *mut LifetimeTracked { return (unsafe { instance_4() }); 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 9985dcd727..cc25f1572b 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 @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,15 +96,15 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } thread_local!( pub static check_4: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_4.with(Value::clone).as_pointer()) + Destructible::destroy(check_4.with(Value::clone).as_pointer()) }); __static }; @@ -107,11 +113,11 @@ thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&shared_5.with(Value::clone).as_pointer()) + Destructible::destroy(shared_5.with(Value::clone).as_pointer()) }); __static }; @@ -121,7 +127,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); ({ b_use_6() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); @@ -131,22 +137,11 @@ fn main_0() -> i32 { return 0; } pub fn b_use_6() { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); } pub fn b_address_7() -> Ptr { return (shared_5.with(|v| v.as_pointer())); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index 8dc8692001..947b8ea2a9 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 @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub static mut check_4: std::cell::LazyCell = @@ -93,7 +95,7 @@ pub static mut shared_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -109,7 +111,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); (unsafe { b_use_6() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); @@ -123,7 +127,9 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_6() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); } pub unsafe fn b_address_7() -> *mut LifetimeTracked { return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) 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 cb38081e40..0e2f2cdacd 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 @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,8 +96,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } #[derive( @@ -108,15 +114,32 @@ impl Destructible for AssertsDtorCountAtExit { )] #[byte_size(1)] pub struct X {} +impl X { + pub fn h(this: Ptr, mut cond: bool, mut p: FnPtr) { + if cond { + ({ + X::h( + this.clone(), + false, + FnPtr::::new(|| { + ({ LifetimeTracked::use_(local_4.with(|v| v.as_pointer())) }); + }), + ) + }); + } else { + ({ p.call() }); + } + } +} thread_local!( static local_4: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&local_4.with(Value::clone).as_pointer()) + Destructible::destroy(local_4.with(Value::clone).as_pointer()) }); __static }; @@ -125,7 +148,7 @@ thread_local!( pub static check_5: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_5.with(Value::clone).as_pointer()) + Destructible::destroy(check_5.with(Value::clone).as_pointer()) }); __static }; @@ -138,11 +161,11 @@ fn main_0() -> i32 { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); let x: Value = Rc::new(RefCell::new(::default())); ({ - XImpl::h( - &x.as_pointer(), + X::h( + x.as_pointer(), true, FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(local_4.with(|v| v.as_pointer())) }); }), ) }); @@ -156,46 +179,15 @@ fn main_0() -> i32 { pub fn b_call_6() { let x: Value = Rc::new(RefCell::new(::default())); ({ - XImpl::h( - &x.as_pointer(), + X::h( + x.as_pointer(), true, FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(local_4.with(|v| v.as_pointer())) }); }), ) }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait XImpl { - fn h(&self, cond: bool, p: FnPtr); -} -impl XImpl for Ptr { - fn h(&self, mut cond: bool, mut p: FnPtr) { - if cond { - ({ - XImpl::h( - self, - false, - FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_4.with(|v| v.as_pointer())) }); - }), - ) - }); - } else { - ({ p.call() }); - } - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); 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 ca65a2f79b..e64c52a6e7 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 @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } #[repr(C)] @@ -91,16 +93,18 @@ impl DestructibleUnsafe for AssertsDtorCountAtExit { )] pub struct X {} impl X { - pub unsafe fn h(&mut self, mut cond: bool, mut p: Option) { + pub unsafe fn h(this: *mut Self, mut cond: bool, mut p: Option) { if cond { (unsafe { X::h( - self, + this, false, Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), + &raw const (*std::cell::LazyCell::force_mut( + &mut *&raw mut local_4, + )), ) }); }), @@ -115,7 +119,7 @@ static mut local_4: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -145,12 +149,12 @@ unsafe fn main_0() -> i32 { let mut x: X = ::default(); (unsafe { X::h( - &mut x, + &raw mut x, true, Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), ) }); }), @@ -167,12 +171,12 @@ pub unsafe fn b_call_6() { let mut x: X = ::default(); (unsafe { X::h( - &mut x, + &raw mut x, true, Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), ) }); }), 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 51594617c5..38f3a11bae 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 @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,8 +96,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } pub fn f_4(mut cond: bool, mut p: FnPtr) { @@ -100,7 +106,7 @@ pub fn f_4(mut cond: bool, mut p: FnPtr) { f_4( false, FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(local_5.with(|v| v.as_pointer())) }); }), ) }); @@ -112,11 +118,11 @@ thread_local!( static local_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&local_5.with(Value::clone).as_pointer()) + Destructible::destroy(local_5.with(Value::clone).as_pointer()) }); __static }; @@ -125,7 +131,7 @@ thread_local!( pub static check_6: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_6.with(Value::clone).as_pointer()) + Destructible::destroy(check_6.with(Value::clone).as_pointer()) }); __static }; @@ -147,17 +153,6 @@ fn main_0() -> i32 { pub fn b_call_7() { ({ f_4(true, FnPtr::::null()) }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index 605541690b..8d40bf22f8 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 @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub unsafe fn f_4(mut cond: bool, mut p: Option) { @@ -86,7 +88,7 @@ pub unsafe fn f_4(mut cond: bool, mut p: Option) { Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_5)), + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut local_5)), ) }); }), @@ -100,7 +102,7 @@ static mut local_5: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs index ccf5fccdfa..9bcb8c525a 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -82,8 +82,8 @@ pub struct Record_19 { pub id: i32, } impl DefaultConstructible for Record_19 { - fn default_constructor(this: &Ptr) { - field!((*this), id).write(100); + fn default_constructor(this: Ptr) { + field!(this, id).write(100); } } impl Default for Record_19 { @@ -130,12 +130,18 @@ pub fn test_29() { )] #[byte_size(1)] pub struct Tally_31 {} +impl Tally_31 { + pub fn add(this: Ptr, mut amount: i32) -> i32 { + total_32.with(|rc| *rc.borrow_mut() += amount); + return total_32.with(|rc| *rc.borrow()); + } +} thread_local!( pub static total_32: Value = Rc::new(RefCell::new(10)); ); pub fn test_33() { let tally: Value = Rc::new(RefCell::new(::default())); - assert!((({ Tally_31Impl::add(&tally.as_pointer(), 1,) }) == 11)); + assert!((({ Tally_31::add(tally.as_pointer(), 1,) }) == 11)); assert!((({ add_in_b_34(1,) }) == 102)); assert!((total_32.with(|rc| *rc.borrow()) == 11)); } @@ -225,8 +231,8 @@ pub struct Entry_52 { pub key: i32, } impl DefaultConstructible for Entry_52 { - fn default_constructor(this: &Ptr) { - field!((*this), key).write(1); + fn default_constructor(this: Ptr) { + field!(this, key).write(1); } } impl Default for Entry_52 { @@ -243,9 +249,9 @@ pub struct Entry_54 { pub value: i32, } impl DefaultConstructible for Entry_54 { - fn default_constructor(this: &Ptr) { - field!((*this), key).write(2); - field!((*this), value).write(30); + fn default_constructor(this: Ptr) { + field!(this, key).write(2); + field!(this, value).write(30); } } impl Default for Entry_54 { @@ -367,9 +373,9 @@ pub struct Record_65 { pub extra: i32, } impl DefaultConstructible for Record_65 { - fn default_constructor(this: &Ptr) { - field!((*this), id).write(200_i64); - field!((*this), extra).write(1); + fn default_constructor(this: Ptr) { + field!(this, id).write(200_i64); + field!(this, extra).write(1); } } impl Default for Record_65 { @@ -422,12 +428,18 @@ pub fn raise_30(mut by: i32) -> i32 { )] #[byte_size(1)] pub struct Tally_67 {} +impl Tally_67 { + pub fn add(this: Ptr, mut amount: i32) -> i32 { + total_68.with(|rc| *rc.borrow_mut() += (amount * 2)); + return total_68.with(|rc| *rc.borrow()); + } +} thread_local!( pub static total_68: Value = Rc::new(RefCell::new(100)); ); pub fn add_in_b_34(mut amount: i32) -> i32 { let tally: Value = Rc::new(RefCell::new(::default())); - return ({ Tally_67Impl::add(&tally.as_pointer(), amount) }); + return ({ Tally_67::add(tally.as_pointer(), amount) }); } thread_local!( pub static balance_35: Value = Rc::new(RefCell::new(50)); @@ -468,8 +480,8 @@ pub struct Entry_71 { pub key: i64, } impl DefaultConstructible for Entry_71 { - fn default_constructor(this: &Ptr) { - field!((*this), key).write(400_i64); + fn default_constructor(this: Ptr) { + field!(this, key).write(400_i64); } } impl Default for Entry_71 { @@ -492,24 +504,6 @@ pub fn table_sum_in_b_59() -> i32 { table_57.with(|rc| rc.borrow()[__idx0]) })); } -pub trait Tally_31Impl { - fn add(&self, amount: i32) -> i32; -} -impl Tally_31Impl for Ptr { - fn add(&self, mut amount: i32) -> i32 { - total_32.with(|rc| *rc.borrow_mut() += amount); - return total_32.with(|rc| *rc.borrow()); - } -} -pub trait Tally_67Impl { - fn add(&self, amount: i32) -> i32; -} -impl Tally_67Impl for Ptr { - fn add(&self, mut amount: i32) -> i32 { - total_68.with(|rc| *rc.borrow_mut() += (amount * 2)); - return total_68.with(|rc| *rc.borrow()); - } -} pub fn __cpp2rust_init_globals() { let _ = limit_3.with(|_| ()); let _ = anon_13.with(|_| ()); diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs index 81795fc7bc..401a10dbee 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -73,8 +73,8 @@ pub struct Record_19 { pub id: i32, } impl DefaultConstructibleUnsafe for Record_19 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.id).write(100); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).id).write(100); } } impl Default for Record_19 { @@ -118,7 +118,7 @@ pub unsafe fn test_29() { )] pub struct Tally_31 {} impl Tally_31 { - pub unsafe fn add(&mut self, mut amount: i32) -> i32 { + pub unsafe fn add(this: *mut Self, mut amount: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)) += amount; return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)); } @@ -126,7 +126,7 @@ impl Tally_31 { pub static mut total_32: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); pub unsafe fn test_33() { let mut tally: Tally_31 = ::default(); - assert!(((unsafe { Tally_31::add(&mut tally, 1,) }) == (11))); + assert!(((unsafe { Tally_31::add(&raw mut tally, 1,) }) == (11))); assert!(((unsafe { add_in_b_34(1,) }) == (102))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)) == (11))); } @@ -207,8 +207,8 @@ pub struct Entry_52 { pub key: i32, } impl DefaultConstructibleUnsafe for Entry_52 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.key).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).key).write(1); } } impl Default for Entry_52 { @@ -223,9 +223,9 @@ pub struct Entry_54 { pub value: i32, } impl DefaultConstructibleUnsafe for Entry_54 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.key).write(2); - (&raw mut self.value).write(30); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).key).write(2); + (&raw mut (*this).value).write(30); } } impl Default for Entry_54 { @@ -322,9 +322,9 @@ pub struct Record_65 { pub extra: i32, } impl DefaultConstructibleUnsafe for Record_65 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.id).write(200_i64); - (&raw mut self.extra).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).id).write(200_i64); + (&raw mut (*this).extra).write(1); } } impl Default for Record_65 { @@ -371,7 +371,7 @@ pub unsafe fn raise_30(mut by: i32) -> i32 { )] pub struct Tally_67 {} impl Tally_67 { - pub unsafe fn add(&mut self, mut amount: i32) -> i32 { + pub unsafe fn add(this: *mut Self, mut amount: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_68)) += ((amount) * (2)); return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_68)); } @@ -379,7 +379,7 @@ impl Tally_67 { pub static mut total_68: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); pub unsafe fn add_in_b_34(mut amount: i32) -> i32 { let mut tally: Tally_67 = ::default(); - return (unsafe { Tally_67::add(&mut tally, amount) }); + return (unsafe { Tally_67::add(&raw mut tally, amount) }); } pub static mut balance_35: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); impl p5_members_of_class_with_external_linkage_Ledger { @@ -411,8 +411,8 @@ pub struct Entry_71 { pub key: i64, } impl DefaultConstructibleUnsafe for Entry_71 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.key).write(400_i64); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).key).write(400_i64); } } impl Default for Entry_71 { 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 105c978f15..1099fd29ae 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 @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -98,8 +104,13 @@ pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] pub value: i32, } +impl p1_1_condition_variable_visible_in_else_ConvertsToBool { + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.value) != 0); + } +} impl Destructible for p1_1_condition_variable_visible_in_else_ConvertsToBool { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -109,12 +120,10 @@ pub fn test_7() { RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }), ); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if ({ - p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(condition.as_pointer()) }) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); } else { @@ -131,12 +140,10 @@ pub fn test_7() { RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }), ); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if ({ - p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(condition.as_pointer()) }) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); assert!(({ (*condition.borrow()).value } == 6)); @@ -193,7 +200,7 @@ pub fn test_9() { } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 6)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 5)); - ({ LifetimeTrackedImpl::use_(&scoped.as_pointer()) }); + ({ LifetimeTracked::use_(scoped.as_pointer()) }); assert!(({ (*scoped.borrow()).uses } == 1)); } pub fn test_10() { @@ -222,13 +229,13 @@ pub fn test_11() { { object!(tracked, LifetimeTracked); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); - ({ LifetimeTrackedImpl::use_(&tracked.as_pointer()) }); + ({ LifetimeTracked::use_(tracked.as_pointer()) }); assert!(({ (*tracked.borrow()).uses } == 1)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); } assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); assert!(({ (*tracked.borrow()).uses } == 0)); - ({ LifetimeTrackedImpl::use_(&tracked.as_pointer()) }); + ({ LifetimeTracked::use_(tracked.as_pointer()) }); assert!(({ (*tracked.borrow()).uses } == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); } @@ -306,27 +313,6 @@ fn main_0() -> i32 { ({ test_16() }); return 0; } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl { - fn to_bool(&self) -> bool; -} -impl p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl - for Ptr -{ - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.value) != 0); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs index 9e43302a64..af9f7a8896 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs @@ -15,9 +15,21 @@ pub struct p1_member_hides_namespace_variable_HasBalance { #[offset(0)] pub balance: i32, } +impl p1_member_hides_namespace_variable_HasBalance { + pub fn deposit(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, balance).with_mut(|__v| *__v = *__v + amount) + }; + return this.with(|__s| __s.balance); + } + pub fn deposit_globally(this: Ptr, mut amount: i32) -> i32 { + balance_0.with(|rc| *rc.borrow_mut() += amount); + return balance_0.with(|rc| *rc.borrow()); + } +} impl DefaultConstructible for p1_member_hides_namespace_variable_HasBalance { - fn default_constructor(this: &Ptr) { - field!((*this), balance).write(7); + fn default_constructor(this: Ptr) { + field!(this, balance).write(7); } } impl Default for p1_member_hides_namespace_variable_HasBalance { @@ -28,18 +40,14 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { pub fn test_1() { object!(object, p1_member_hides_namespace_variable_HasBalance); assert!( - (({ - p1_member_hides_namespace_variable_HasBalanceImpl::deposit(&object.as_pointer(), 3) - }) == 10) + (({ p1_member_hides_namespace_variable_HasBalance::deposit(object.as_pointer(), 3,) }) + == 10) ); assert!(({ (*object.borrow()).balance } == 10)); assert!((balance_0.with(|rc| *rc.borrow()) == 50)); assert!( (({ - p1_member_hides_namespace_variable_HasBalanceImpl::deposit_globally( - &object.as_pointer(), - 4, - ) + p1_member_hides_namespace_variable_HasBalance::deposit_globally(object.as_pointer(), 4) }) == 54) ); assert!(({ (*object.borrow()).balance } == 10)); @@ -55,8 +63,8 @@ pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub held: i32, } impl DefaultConstructible for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - fn default_constructor(this: &Ptr) { - field!((*this), held).write(1); + fn default_constructor(this: Ptr) { + field!(this, held).write(1); } } impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { @@ -70,6 +78,15 @@ thread_local!( thread_local!( pub static total_4: Value = Rc::new(RefCell::new((initial_3.with(|rc| *rc.borrow()) + 1))); ); +impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + pub fn add(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, held).with_mut(|__v| *__v = *__v + amount) + }; + total_4.with(|rc| *rc.borrow_mut() += initial_3.with(|rc| *rc.borrow())); + return this.with(|__s| __s.held); + } +} pub fn test_5() { assert!((total_4.with(|rc| *rc.borrow()) == 7)); object!( @@ -78,10 +95,7 @@ pub fn test_5() { ); assert!( (({ - p1_out_of_class_definition_is_in_class_scope_HasStaticTotalImpl::add( - &object.as_pointer(), - 4, - ) + p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::add(object.as_pointer(), 4) }) == 5) ); assert!((total_4.with(|rc| *rc.borrow()) == 13)); @@ -97,38 +111,6 @@ fn main_0() -> i32 { ({ test_5() }); return 0; } -pub trait p1_member_hides_namespace_variable_HasBalanceImpl { - fn deposit(&self, amount: i32) -> i32; - fn deposit_globally(&self, amount: i32) -> i32; -} -impl p1_member_hides_namespace_variable_HasBalanceImpl - for Ptr -{ - fn deposit(&self, mut amount: i32) -> i32 { - { - field!((*self), balance).with_mut(|__v| *__v = *__v + amount) - }; - return (*self).with(|__s| __s.balance); - } - fn deposit_globally(&self, mut amount: i32) -> i32 { - balance_0.with(|rc| *rc.borrow_mut() += amount); - return balance_0.with(|rc| *rc.borrow()); - } -} -pub trait p1_out_of_class_definition_is_in_class_scope_HasStaticTotalImpl { - fn add(&self, amount: i32) -> i32; -} -impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotalImpl - for Ptr -{ - fn add(&self, mut amount: i32) -> i32 { - { - field!((*self), held).with_mut(|__v| *__v = *__v + amount) - }; - total_4.with(|rc| *rc.borrow_mut() += initial_3.with(|rc| *rc.borrow())); - return (*self).with(|__s| __s.held); - } -} pub fn __cpp2rust_init_globals() { let _ = balance_0.with(|_| ()); let _ = initial_2.with(|_| ()); diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs index 6942fe2142..51f3d0b9df 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs @@ -25,6 +25,17 @@ pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParamete #[offset(0)] pub amount: i32, } +impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { + pub fn construct(this: Ptr, mut amount: i32) { + field!(this, amount).write((amount + 1)); + amount += 10; + assert!((amount == 14)); + assert!((this.with(|__s| __s.amount) == 5)); + } + pub fn add(this: Ptr, mut amount: i32) -> i32 { + return (this.with(|__s| __s.amount) + amount); + } +} pub fn test_0() { object!( object, @@ -33,8 +44,8 @@ pub fn test_0() { assert!(({ (*object.borrow()).amount } == 5)); assert!( (({ - p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameterImpl::add( - &object.as_pointer(), + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::add( + object.as_pointer(), 20, ) }) == 25) @@ -85,23 +96,6 @@ fn main_0() -> i32 { ({ test_5() }); return 0; } -pub trait p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameterImpl { - fn construct(&self, amount: i32); - fn add(&self, amount: i32) -> i32; -} -impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameterImpl - for Ptr -{ - fn construct(&self, mut amount: i32) { - field!((*self), amount).write((amount + 1)); - amount += 10; - assert!((amount == 14)); - assert!(((*self).with(|__s| __s.amount) == 5)); - } - fn add(&self, mut amount: i32) -> i32 { - return ((*self).with(|__s| __s.amount) + amount); - } -} pub fn __cpp2rust_init_globals() { let _ = rate_1.with(|_| ()); } diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs index 7d4bc28b97..fcfaeefccc 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs @@ -91,10 +91,10 @@ pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: Ptr, } impl DefaultConstructible for p9_func_declared_before_function_body_RecordsConstructorName { - fn default_constructor(this: &Ptr) { - field!((*this), name).write(Ptr::::from_string_literal(b"RecordsConstructorName")); + fn default_constructor(this: Ptr) { + field!(this, name).write(Ptr::::from_string_literal(b"RecordsConstructorName")); assert!( - ((*this).with(|__s| __s.name.clone()) + (this.with(|__s| __s.name.clone()) == Ptr::::from_string_literal(b"RecordsConstructorName")) ); } @@ -107,7 +107,7 @@ impl Default for p9_func_declared_before_function_body_RecordsConstructorName { Rc::new(RefCell::new( ::zero_init(), )); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs index 61044feeba..f2e8701287 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs @@ -58,6 +58,12 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: )] #[byte_size(1)] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} +impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum { + pub fn scale(this: Ptr, mut count: i32) -> i32 { + return (count + * (p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32)); + } +} pub fn test_5() { assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_north as i32) == 4)); assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_north as i32) == 4)); @@ -72,10 +78,7 @@ pub fn test_5() { ); assert!( (({ - p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnumImpl::scale( - &object.as_pointer(), - 2, - ) + p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum::scale(object.as_pointer(), 2) }) == 16) ); assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small as i32) == 3)); @@ -194,6 +197,11 @@ pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { #[byte_size(8)] pub anon_9: anon_9, } +impl p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { + pub fn read_count(this: Ptr) -> i32 { + return (anon_9::member_count(field_ptr!(this, anon_9)).read()); + } +} pub fn test_10() { anon_8::namespace_count(anon_8.with(|v| v.as_pointer())).write(4); assert!(((anon_8::namespace_count(anon_8.with(|v| v.as_pointer())).read()) == 4)); @@ -207,8 +215,8 @@ pub fn test_10() { assert!(((anon_9::member_count(field_ptr!(object.as_pointer(), anon_9)).read()) == 6)); assert!( (({ - p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnionImpl::read_count( - &object.as_pointer(), + p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion::read_count( + object.as_pointer(), ) }) == 6) ); @@ -260,10 +268,24 @@ pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { #[offset(4)] pub const_calls: i32, } +impl p3_2_const_qualified_member_is_distinct_HasConstOverload { + pub fn get_1(this: Ptr) -> i32 { + field!(this, plain_calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return 1; + } + pub fn get_2(this: Ptr) -> i32 { + field!(this, const_calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return 2; + } +} impl DefaultConstructible for p3_2_const_qualified_member_is_distinct_HasConstOverload { - fn default_constructor(this: &Ptr) { - field!((*this), plain_calls).write(0); - field!((*this), const_calls).write(0); + fn default_constructor(this: Ptr) { + field!(this, plain_calls).write(0); + field!(this, const_calls).write(0); } } impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { @@ -284,15 +306,14 @@ pub fn test_12() { let view: Ptr = object.as_pointer(); assert!( (({ - p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl::get_1( - &object.as_pointer(), - ) + p3_2_const_qualified_member_is_distinct_HasConstOverload::get_1(object.as_pointer()) }) == 1) ); assert!(({ (*object.borrow()).plain_calls } == 1)); assert!(({ (*object.borrow()).const_calls } == 0)); assert!( - (({ p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl::get_2(&view,) }) == 2) + (({ p3_2_const_qualified_member_is_distinct_HasConstOverload::get_2((view).clone(),) }) + == 2) ); assert!(({ (*object.borrow()).plain_calls } == 1)); assert!(({ (*object.borrow()).const_calls } == 1)); @@ -309,11 +330,24 @@ pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjec #[offset(0)] pub base: i32, } +impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { + pub fn pick_1( + self_: Ptr, + mut amount: i32, + ) -> i32 { + (*explicit_calls_13.with(Value::clone).borrow_mut()).prefix_inc(); + return ({ self_.with(|__s| __s.base) } + { amount }); + } + pub fn pick_2(this: Ptr, mut amount: i32) -> i32 { + (*rvalue_calls_14.with(Value::clone).borrow_mut()).prefix_inc(); + return ((this.with(|__s| __s.base) + amount) + 100); + } +} impl DefaultConstructible for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { - fn default_constructor(this: &Ptr) { - field!((*this), base).write(10); + fn default_constructor(this: Ptr) { + field!(this, base).write(10); } } impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { @@ -332,7 +366,10 @@ pub fn test_15() { ); assert!( (({ - as p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl>::pick_1 ( object .as_pointer() , 1 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::pick_1( + object.as_pointer(), + 1, + ) }) == 11) ); assert!((explicit_calls_13.with(|rc| *rc.borrow()) == 1)); @@ -341,7 +378,7 @@ pub fn test_15() { let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); assert!( (({ - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl :: pick_2 ( &{ DefaultConstructible::default_constructor(&__tmp_0.as_pointer()) ; __tmp_0.as_pointer() } , 2 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( { DefaultConstructible::default_constructor(__tmp_0.as_pointer()) ; __tmp_0.as_pointer() } , 2 , ) }) == 112) ) }; @@ -368,14 +405,24 @@ thread_local!( )] #[byte_size(1)] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} +impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads { + pub fn get_1(this: Ptr) -> i32 { + (*lvalue_calls_16.with(Value::clone).borrow_mut()).prefix_inc(); + return 3; + } + pub fn get_2(this: Ptr) -> i32 { + (*rvalue_calls_17.with(Value::clone).borrow_mut()).prefix_inc(); + return 4; + } +} pub fn test_18() { let object: Value = Rc::new( RefCell::new(::default()), ); assert!( (({ - p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl::get_1( - &object.as_pointer(), + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_1( + object.as_pointer(), ) }) == 3) ); @@ -383,8 +430,8 @@ pub fn test_18() { assert!((rvalue_calls_17.with(|rc| *rc.borrow()) == 0)); assert!( (({ - p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl::get_2( - &Rc::new(RefCell::new( + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_2( + Rc::new(RefCell::new( ::default(), )) .as_pointer(), @@ -395,8 +442,8 @@ pub fn test_18() { assert!((rvalue_calls_17.with(|rc| *rc.borrow()) == 1)); assert!( (({ - p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl::get_2( - &object.as_pointer(), + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_2( + object.as_pointer(), ) }) == 4) ); @@ -411,12 +458,26 @@ pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOv #[offset(4)] pub const_calls: i32, } +impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + pub fn get_1_int(this: Ptr, mut value: i32) -> i32 { + field!(this, plain_calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return (value + 1); + } + pub fn get_2_int(this: Ptr, mut value: i32) -> i32 { + field!(this, const_calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return (value + 2); + } +} impl DefaultConstructible for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { - fn default_constructor(this: &Ptr) { - field!((*this), plain_calls).write(0); - field!((*this), const_calls).write(0); + fn default_constructor(this: Ptr) { + field!(this, plain_calls).write(0); + field!(this, const_calls).write(0); } } impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { @@ -438,14 +499,20 @@ pub fn test_19() { object.as_pointer(); assert!( (({ - p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl :: get_1_int ( &object .as_pointer() , 10 , ) + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::get_1_int( + object.as_pointer(), + 10, + ) }) == 11) ); assert!(({ (*object.borrow()).plain_calls } == 1)); assert!(({ (*object.borrow()).const_calls } == 0)); assert!( (({ - p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl :: get_2_int ( &view , 10 , ) + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::get_2_int( + (view).clone(), + 10, + ) }) == 12) ); assert!(({ (*object.borrow()).plain_calls } == 1)); @@ -471,25 +538,35 @@ thread_local!( )] #[byte_size(1)] pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} +impl p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads { + pub fn get_1_int(this: Ptr, mut value: i32) -> i32 { + (*lvalue_calls_20.with(Value::clone).borrow_mut()).prefix_inc(); + return (value + 3); + } + pub fn get_2_int(this: Ptr, mut value: i32) -> i32 { + (*rvalue_calls_21.with(Value::clone).borrow_mut()).prefix_inc(); + return (value + 4); + } +} pub fn test_22() { let object : Value = Rc::new(RefCell::new(::default() )) ; assert!( (({ - p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl :: get_1_int ( &object .as_pointer() , 10 , ) + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_1_int ( object .as_pointer() , 10 , ) }) == 13) ); assert!((lvalue_calls_20.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_21.with(|rc| *rc.borrow()) == 0)); assert!( (({ - p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl :: get_2_int ( &Rc::new(RefCell::new(::default() )).as_pointer() , 10 , ) + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_2_int ( Rc::new(RefCell::new(::default() )).as_pointer() , 10 , ) }) == 14) ); assert!((lvalue_calls_20.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_21.with(|rc| *rc.borrow()) == 1)); assert!( (({ - p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl :: get_2_int ( &object .as_pointer() , 10 , ) + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_2_int ( object .as_pointer() , 10 , ) }) == 14) ); assert!((lvalue_calls_20.with(|rc| *rc.borrow()) == 1)); @@ -775,121 +852,6 @@ fn main_0() -> i32 { ({ test_64() }); return 0; } -pub trait p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnumImpl { - fn scale(&self, count: i32) -> i32; -} -impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnumImpl - for Ptr -{ - fn scale(&self, mut count: i32) -> i32 { - return (count - * (p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32)); - } -} -pub trait p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnionImpl { - fn read_count(&self) -> i32; -} -impl p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnionImpl - for Ptr -{ - fn read_count(&self) -> i32 { - return (anon_9::member_count(field_ptr!((*self), anon_9)).read()); - } -} -pub trait p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl { - fn get_1(&self) -> i32; - fn get_2(&self) -> i32; -} -impl p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl - for Ptr -{ - fn get_1(&self) -> i32 { - field!((*self), plain_calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return 1; - } - fn get_2(&self) -> i32 { - field!((*self), const_calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return 2; - } -} -pub trait p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl { - fn pick_1( - self_: Ptr, - amount: i32, - ) -> i32; - fn pick_2(&self, amount: i32) -> i32; -} -impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl - for Ptr -{ - fn pick_1( - self_: Ptr, - mut amount: i32, - ) -> i32 { - (*explicit_calls_13.with(Value::clone).borrow_mut()).prefix_inc(); - return ({ self_.with(|__s| __s.base) } + { amount }); - } - fn pick_2(&self, mut amount: i32) -> i32 { - (*rvalue_calls_14.with(Value::clone).borrow_mut()).prefix_inc(); - return (((*self).with(|__s| __s.base) + amount) + 100); - } -} -pub trait p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl { - fn get_1(&self) -> i32; - fn get_2(&self) -> i32; -} -impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl - for Ptr -{ - fn get_1(&self) -> i32 { - (*lvalue_calls_16.with(Value::clone).borrow_mut()).prefix_inc(); - return 3; - } - fn get_2(&self) -> i32 { - (*rvalue_calls_17.with(Value::clone).borrow_mut()).prefix_inc(); - return 4; - } -} -pub trait p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl { - fn get_1_int(&self, value: i32) -> i32; - fn get_2_int(&self, value: i32) -> i32; -} -impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl - for Ptr -{ - fn get_1_int(&self, mut value: i32) -> i32 { - field!((*self), plain_calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return (value + 1); - } - fn get_2_int(&self, mut value: i32) -> i32 { - field!((*self), const_calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return (value + 2); - } -} -pub trait p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl { - fn get_1_int(&self, value: i32) -> i32; - fn get_2_int(&self, value: i32) -> i32; -} -impl p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl - for Ptr -{ - fn get_1_int(&self, mut value: i32) -> i32 { - (*lvalue_calls_20.with(Value::clone).borrow_mut()).prefix_inc(); - return (value + 3); - } - fn get_2_int(&self, mut value: i32) -> i32 { - (*rvalue_calls_21.with(Value::clone).borrow_mut()).prefix_inc(); - return (value + 4); - } -} pub fn __cpp2rust_init_globals() { let _ = level_0.with(|_| ()); let _ = function_calls_2.with(|_| ()); 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 fe6fa8f0ec..4b2bbc17d3 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 @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -79,12 +79,12 @@ pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { pub value: i32, } impl p1_1_condition_variable_visible_in_else_ConvertsToBool { - pub unsafe fn to_bool(&self) -> bool { - return ((self.value) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).value) != (0)); } } impl DestructibleUnsafe for p1_1_condition_variable_visible_in_else_ConvertsToBool { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); } } @@ -93,10 +93,11 @@ pub unsafe fn test_7() { let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); - if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) - { + if (unsafe { + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&raw const condition) + }) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); } else { (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); @@ -111,10 +112,11 @@ pub unsafe fn test_7() { let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); - if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) - { + if (unsafe { + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&raw const condition) + }) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); assert!(((condition.value) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)) == (1))); @@ -170,7 +172,7 @@ pub unsafe fn test_9() { } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (5))); - (unsafe { LifetimeTracked::use_(&scoped) }); + (unsafe { LifetimeTracked::use_(&raw const scoped) }); assert!(((scoped.uses) == (1))); } pub unsafe fn test_10() { @@ -195,13 +197,13 @@ pub unsafe fn test_11() { { object_unsafe!(tracked, LifetimeTracked); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); - (unsafe { LifetimeTracked::use_(&tracked) }); + (unsafe { LifetimeTracked::use_(&raw const tracked) }); assert!(((tracked.uses) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); assert!(((tracked.uses) == (0))); - (unsafe { LifetimeTracked::use_(&tracked) }); + (unsafe { LifetimeTracked::use_(&raw const tracked) }); assert!(((tracked.uses) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs index f6bfd2af94..074260bb41 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs @@ -13,18 +13,18 @@ pub struct p1_member_hides_namespace_variable_HasBalance { pub balance: i32, } impl p1_member_hides_namespace_variable_HasBalance { - pub unsafe fn deposit(&mut self, mut amount: i32) -> i32 { - self.balance += amount; - return self.balance; + pub unsafe fn deposit(this: *mut Self, mut amount: i32) -> i32 { + (*this).balance += amount; + return (*this).balance; } - pub unsafe fn deposit_globally(&mut self, mut amount: i32) -> i32 { + pub unsafe fn deposit_globally(this: *mut Self, mut amount: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)) += amount; return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)); } } impl DefaultConstructibleUnsafe for p1_member_hides_namespace_variable_HasBalance { - unsafe fn default_constructor(&mut self) { - (&raw mut self.balance).write(7); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).balance).write(7); } } impl Default for p1_member_hides_namespace_variable_HasBalance { @@ -35,14 +35,14 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { pub unsafe fn test_1() { object_unsafe!(object, p1_member_hides_namespace_variable_HasBalance); assert!( - ((unsafe { p1_member_hides_namespace_variable_HasBalance::deposit(&mut object, 3,) }) + ((unsafe { p1_member_hides_namespace_variable_HasBalance::deposit(&raw mut object, 3,) }) == (10)) ); assert!(((object.balance) == (10))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)) == (50))); assert!( ((unsafe { - p1_member_hides_namespace_variable_HasBalance::deposit_globally(&mut object, 4) + p1_member_hides_namespace_variable_HasBalance::deposit_globally(&raw mut object, 4) }) == (54)) ); assert!(((object.balance) == (10))); @@ -55,8 +55,8 @@ pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub held: i32, } impl DefaultConstructibleUnsafe for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - unsafe fn default_constructor(&mut self) { - (&raw mut self.held).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).held).write(1); } } impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { @@ -69,11 +69,11 @@ pub static mut total_4: std::cell::LazyCell = std::cell::LazyCell::new(|| u ((*std::cell::LazyCell::force_mut(&mut *&raw mut initial_3)) + (1)) }); impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - pub unsafe fn add(&mut self, mut amount: i32) -> i32 { - self.held += amount; + pub unsafe fn add(this: *mut Self, mut amount: i32) -> i32 { + (*this).held += amount; (*std::cell::LazyCell::force_mut(&mut *&raw mut total_4)) += (*std::cell::LazyCell::force_mut(&mut *&raw mut initial_3)); - return self.held; + return (*this).held; } } pub unsafe fn test_5() { @@ -84,7 +84,7 @@ pub unsafe fn test_5() { ); assert!( ((unsafe { - p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::add(&mut object, 4) + p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::add(&raw mut object, 4) }) == (5)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_4)) == (13))); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs index 9d1af9da89..fab158ea2c 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs @@ -23,14 +23,14 @@ pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParamete pub amount: i32, } impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { - pub unsafe fn construct(&mut self, mut amount: i32) { - (&raw mut self.amount).write(((amount) + (1))); + pub unsafe fn construct(this: *mut Self, mut amount: i32) { + (&raw mut (*this).amount).write(((amount) + (1))); amount += 10; assert!(((amount) == (14))); - assert!(((self.amount) == (5))); + assert!((((*this).amount) == (5))); } - pub unsafe fn add(&self, mut amount: i32) -> i32 { - return ((self.amount) + (amount)); + pub unsafe fn add(this: *const Self, mut amount: i32) -> i32 { + return (((*this).amount) + (amount)); } } pub unsafe fn test_0() { @@ -41,7 +41,10 @@ pub unsafe fn test_0() { assert!(((object.amount) == (5))); assert!( ((unsafe { - p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::add(&object, 20) + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::add( + &raw const object, + 20, + ) }) == (25)) ); assert!(((object.amount) == (5))); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs index 39cdf52ee8..c19845dfca 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs @@ -86,9 +86,9 @@ pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: *const libc::c_char, } impl DefaultConstructibleUnsafe for p9_func_declared_before_function_body_RecordsConstructorName { - unsafe fn default_constructor(&mut self) { - (&raw mut self.name).write(c"RecordsConstructorName".as_ptr()); - assert!(((self.name) == (c"RecordsConstructorName".as_ptr()))); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).name).write(c"RecordsConstructorName".as_ptr()); + assert!((((*this).name) == (c"RecordsConstructorName".as_ptr()))); } } impl Default for p9_func_declared_before_function_body_RecordsConstructorName { @@ -97,7 +97,7 @@ impl Default for p9_func_declared_before_function_body_RecordsConstructorName { { let mut __v: p9_func_declared_before_function_body_RecordsConstructorName = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs index ee2c27079b..55ac501b18 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs @@ -54,7 +54,7 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: )] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum { - pub unsafe fn scale(&self, mut count: i32) -> i32 { + pub unsafe fn scale(this: *const Self, mut count: i32) -> i32 { return ((count) * (p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32)); } @@ -71,8 +71,9 @@ pub unsafe fn test_5() { let mut object: p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum = ::default(); assert!( - ((unsafe { p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum::scale(&object, 2,) }) - == (16)) + ((unsafe { + p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum::scale(&raw const object, 2) + }) == (16)) ); assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small as i32) == (3))); } @@ -158,8 +159,8 @@ pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { pub anon_9: anon_9, } impl p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { - pub unsafe fn read_count(&self) -> i32 { - return self.anon_9.member_count; + pub unsafe fn read_count(this: *const Self) -> i32 { + return (*this).anon_9.member_count; } } pub unsafe fn test_10() { @@ -176,7 +177,9 @@ pub unsafe fn test_10() { assert!(((object.anon_9.member_count) == (6))); assert!( ((unsafe { - p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion::read_count(&object) + p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion::read_count( + &raw const object, + ) }) == (6)) ); object.anon_9.member_ratio = 0.5_f64; @@ -214,19 +217,19 @@ pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { pub const_calls: i32, } impl p3_2_const_qualified_member_is_distinct_HasConstOverload { - pub unsafe fn get_1(&mut self) -> i32 { - self.plain_calls.prefix_inc(); + pub unsafe fn get_1(this: *mut Self) -> i32 { + (*this).plain_calls.prefix_inc(); return 1; } - pub unsafe fn get_2(&self) -> i32 { - (*(&raw const self.const_calls).cast_mut()).prefix_inc(); + pub unsafe fn get_2(this: *const Self) -> i32 { + (*(&raw const (*this).const_calls).cast_mut()).prefix_inc(); return 2; } } impl DefaultConstructibleUnsafe for p3_2_const_qualified_member_is_distinct_HasConstOverload { - unsafe fn default_constructor(&mut self) { - (&raw mut self.plain_calls).write(0); - (&raw mut self.const_calls).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).plain_calls).write(0); + (&raw mut (*this).const_calls).write(0); } } impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { @@ -247,14 +250,15 @@ pub unsafe fn test_12() { let view: *const p3_2_const_qualified_member_is_distinct_HasConstOverload = &object; assert!( ((unsafe { - p3_2_const_qualified_member_is_distinct_HasConstOverload::get_1(&mut object) + p3_2_const_qualified_member_is_distinct_HasConstOverload::get_1(&raw mut object) }) == (1)) ); assert!(((object.plain_calls) == (1))); assert!(((object.const_calls) == (0))); assert!( - ((unsafe { p3_2_const_qualified_member_is_distinct_HasConstOverload::get_2(&(*view),) }) - == (2)) + ((unsafe { + p3_2_const_qualified_member_is_distinct_HasConstOverload::get_2(&raw const (*view)) + }) == (2)) ); assert!(((object.plain_calls) == (1))); assert!(((object.const_calls) == (1))); @@ -276,16 +280,16 @@ impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverl (*std::cell::LazyCell::force_mut(&mut *&raw mut explicit_calls_13)).prefix_inc(); return (((*self_).base) + (amount)); } - pub unsafe fn pick_2(&mut self, mut amount: i32) -> i32 { + pub unsafe fn pick_2(this: *mut Self, mut amount: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_14)).prefix_inc(); - return (((self.base) + (amount)) + (100)); + return ((((*this).base) + (amount)) + (100)); } } impl DefaultConstructibleUnsafe for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { - unsafe fn default_constructor(&mut self) { - (&raw mut self.base).write(10); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).base).write(10); } } impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { @@ -316,7 +320,7 @@ pub unsafe fn test_15() { let mut __tmp_0: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = ::zero_init(); assert!( ((unsafe { - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ DefaultConstructibleUnsafe::default_constructor(&mut __tmp_0) ; & mut __tmp_0 } ) , 2 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ DefaultConstructibleUnsafe::default_constructor(&raw mut __tmp_0) ; & mut __tmp_0 } ) , 2 , ) }) == (112)) ) }; @@ -340,11 +344,11 @@ pub static mut rvalue_calls_17: std::cell::LazyCell = )] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads { - pub unsafe fn get_1(&mut self) -> i32 { + pub unsafe fn get_1(this: *mut Self) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_16)).prefix_inc(); return 3; } - pub unsafe fn get_2(&mut self) -> i32 { + pub unsafe fn get_2(this: *mut Self) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_17)).prefix_inc(); return 4; } @@ -354,7 +358,7 @@ pub unsafe fn test_18() { ::default(); assert!( ((unsafe { - p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_1(&mut object) + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_1(&raw mut object) }) == (3)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_16)) == (1))); @@ -370,7 +374,7 @@ pub unsafe fn test_18() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_17)) == (1))); assert!( ((unsafe { - p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_2(&mut object) + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_2(&raw mut object) }) == (4)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_16)) == (1))); @@ -383,21 +387,21 @@ pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOv pub const_calls: i32, } impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { - pub unsafe fn get_1_int(&mut self, mut value: i32) -> i32 { - self.plain_calls.prefix_inc(); + pub unsafe fn get_1_int(this: *mut Self, mut value: i32) -> i32 { + (*this).plain_calls.prefix_inc(); return ((value) + (1)); } - pub unsafe fn get_2_int(&self, mut value: i32) -> i32 { - (*(&raw const self.const_calls).cast_mut()).prefix_inc(); + pub unsafe fn get_2_int(this: *const Self, mut value: i32) -> i32 { + (*(&raw const (*this).const_calls).cast_mut()).prefix_inc(); return ((value) + (2)); } } impl DefaultConstructibleUnsafe for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { - unsafe fn default_constructor(&mut self) { - (&raw mut self.plain_calls).write(0); - (&raw mut self.const_calls).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).plain_calls).write(0); + (&raw mut (*this).const_calls).write(0); } } impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { @@ -420,7 +424,7 @@ pub unsafe fn test_19() { assert!( ((unsafe { p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::get_1_int( - &mut object, + &raw mut object, 10, ) }) == (11)) @@ -430,7 +434,7 @@ pub unsafe fn test_19() { assert!( ((unsafe { p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::get_2_int( - &(*view), + &raw const (*view), 10, ) }) == (12)) @@ -455,11 +459,11 @@ pub static mut rvalue_calls_21: std::cell::LazyCell = )] pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} impl p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads { - pub unsafe fn get_1_int(&mut self, mut value: i32) -> i32 { + pub unsafe fn get_1_int(this: *mut Self, mut value: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_20)).prefix_inc(); return ((value) + (3)); } - pub unsafe fn get_2_int(&mut self, mut value: i32) -> i32 { + pub unsafe fn get_2_int(this: *mut Self, mut value: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_21)).prefix_inc(); return ((value) + (4)); } @@ -468,7 +472,7 @@ pub unsafe fn test_22() { let mut object : p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads = ::default() ; assert!( ((unsafe { - p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_1_int ( &mut object , 10 , ) + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_1_int ( &raw mut object , 10 , ) }) == (13)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_20)) == (1))); @@ -482,7 +486,7 @@ pub unsafe fn test_22() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_21)) == (1))); assert!( ((unsafe { - p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_2_int ( &mut object , 10 , ) + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_2_int ( &raw mut object , 10 , ) }) == (14)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_20)) == (1))); diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs index d9091a2f10..348c1b15be 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs @@ -24,20 +24,26 @@ pub struct Tracker { #[offset(0)] pub tag: i32, } +impl Tracker { + pub fn construct(this: Ptr, mut tag: i32) { + field!(this, tag).write(tag); + printf!(b"construct %d\n", tag); + } +} impl Destructible for Tracker { - fn destroy(this: &Ptr) { - printf!(b"destroy %d\n", (*this).with(|__s| __s.tag)); + fn destroy(this: Ptr) { + printf!(b"destroy %d\n", this.with(|__s| __s.tag)); } } thread_local!( pub static global_0: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 1); + Tracker::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&global_0.with(Value::clone).as_pointer()) + Destructible::destroy(global_0.with(Value::clone).as_pointer()) }); __static }; @@ -53,11 +59,11 @@ thread_local!( static local_static_2: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 2); + Tracker::construct(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&local_static_2.with(Value::clone).as_pointer()) + Destructible::destroy(local_static_2.with(Value::clone).as_pointer()) }); __static }; @@ -71,15 +77,6 @@ fn main_0() -> i32 { printf!(b"not reached\n"); return 0; } -pub trait TrackerImpl { - fn construct(&self, tag: i32); -} -impl TrackerImpl for Ptr { - fn construct(&self, mut tag: i32) { - field!((*self), tag).write(tag); - printf!(b"construct %d\n", tag); - } -} pub fn __cpp2rust_init_globals() { let _ = global_0.with(|_| ()); } diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs index 4aa908f4f4..6b1d94835e 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs @@ -24,9 +24,18 @@ pub struct Tracker { #[offset(0)] pub tag: i32, } +impl Tracker { + pub fn construct(this: Ptr, mut tag: i32) { + field!(this, tag).write(tag); + printf!(b"construct %d\n", tag); + } + pub fn touch(this: Ptr) { + printf!(b"touch %d\n", this.with(|__s| __s.tag)); + } +} impl Destructible for Tracker { - fn destroy(this: &Ptr) { - printf!(b"destroy %d\n", (*this).with(|__s| __s.tag)); + fn destroy(this: Ptr) { + printf!(b"destroy %d\n", this.with(|__s| __s.tag)); } } #[derive( @@ -71,30 +80,30 @@ thread_local!( pub static global_0: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 1); + Tracker::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&global_0.with(Value::clone).as_pointer()) + Destructible::destroy(global_0.with(Value::clone).as_pointer()) }); __static }; ); pub fn never_called_1() { - ({ TrackerImpl::touch(&never_constructed_2.with(|v| v.as_pointer())) }); + ({ Tracker::touch(never_constructed_2.with(|v| v.as_pointer())) }); } pub fn test_3() { - ({ TrackerImpl::touch(&global_0.with(|v| v.as_pointer())) }); + ({ Tracker::touch(global_0.with(|v| v.as_pointer())) }); } thread_local!( static never_constructed_2: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 100); + Tracker::construct(__v.as_pointer(), 100); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&never_constructed_2.with(Value::clone).as_pointer()) + Destructible::destroy(never_constructed_2.with(Value::clone).as_pointer()) }); __static }; @@ -106,11 +115,11 @@ thread_local!( pub static before_6: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 2); + Tracker::construct(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&before_6.with(Value::clone).as_pointer()) + Destructible::destroy(before_6.with(Value::clone).as_pointer()) }); __static }; @@ -119,14 +128,14 @@ thread_local!( pub static after_7: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct( - &__v.as_pointer(), + Tracker::construct( + __v.as_pointer(), (({ local_static_during_global_init_4() }).with(|__s| __s.tag) + 1), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&after_7.with(Value::clone).as_pointer()) + Destructible::destroy(after_7.with(Value::clone).as_pointer()) }); __static }; @@ -136,12 +145,12 @@ thread_local!( let __static = Rc::new(RefCell::new(HoldsTracker { member: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 5); + Tracker::construct(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&holder_8.with(Value::clone).as_pointer()) + Destructible::destroy(holder_8.with(Value::clone).as_pointer()) }); __static }; @@ -168,11 +177,11 @@ thread_local!( pub static member_10: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 7); + Tracker::construct(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&member_10.with(Value::clone).as_pointer()) + Destructible::destroy(member_10.with(Value::clone).as_pointer()) }); __static }; @@ -183,7 +192,7 @@ thread_local!( { let captured: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 8); + Tracker::construct(__v.as_pointer(), 8); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -192,20 +201,20 @@ thread_local!( } ))); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&capturing_11.with(Value::clone).as_pointer()) + Destructible::destroy(capturing_11.with(Value::clone).as_pointer()) }); __static }; ); pub fn run_local_static_12() { - ({ TrackerImpl::touch(&during_main_13.with(|v| v.as_pointer())) }); + ({ Tracker::touch(during_main_13.with(|v| v.as_pointer())) }); } pub fn test_14() { ({ run_local_static_12() }); ({ run_local_static_12() }); - ({ TrackerImpl::touch(&({ local_static_during_global_init_4() })) }); + ({ Tracker::touch(({ local_static_during_global_init_4() })) }); printf!(b"trivial %d\n", { trivial_9.with(|rc| *rc.borrow()).value }); - ({ TrackerImpl::touch(&member_10.with(|v| v.as_pointer())) }); + ({ Tracker::touch(member_10.with(|v| v.as_pointer())) }); printf!( b"captured %d\n", ({ (*capturing_11.with(Value::clone).borrow()).call() }) @@ -215,11 +224,11 @@ thread_local!( static during_init_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 3); + Tracker::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&during_init_5.with(Value::clone).as_pointer()) + Destructible::destroy(during_init_5.with(Value::clone).as_pointer()) }); __static }; @@ -228,11 +237,11 @@ thread_local!( static during_main_13: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 9); + Tracker::construct(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&during_main_13.with(Value::clone).as_pointer()) + Destructible::destroy(during_main_13.with(Value::clone).as_pointer()) }); __static }; @@ -247,19 +256,6 @@ fn main_0() -> i32 { printf!(b"return from main\n"); return 0; } -pub trait TrackerImpl { - fn construct(&self, tag: i32); - fn touch(&self); -} -impl TrackerImpl for Ptr { - fn construct(&self, mut tag: i32) { - field!((*self), tag).write(tag); - printf!(b"construct %d\n", tag); - } - fn touch(&self) { - printf!(b"touch %d\n", (*self).with(|__s| __s.tag)); - } -} pub fn __cpp2rust_init_globals() { let _ = global_0.with(|_| ()); let _ = before_6.with(|_| ()); diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs index a4bb703216..1c893a7688 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs @@ -22,21 +22,26 @@ pub struct Tracker { pub tag: i32, } impl Tracker { - pub unsafe fn construct(&mut self, mut tag: i32) { - (&raw mut self.tag).write(tag); + pub unsafe fn construct(this: *mut Self, mut tag: i32) { + (&raw mut (*this).tag).write(tag); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); } } impl DestructibleUnsafe for Tracker { - unsafe fn destroy(&mut self) { - (unsafe { libc::printf(c"destroy %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); + unsafe fn destroy(this: *mut Self) { + (unsafe { + libc::printf( + c"destroy %d\n".as_ptr() as *const libc::c_char, + ((*this).tag), + ) + }); } } pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 1); + Tracker::construct(&raw mut __v, 1); __v }; libcc2rs::register_static_destructor(|| { @@ -59,7 +64,7 @@ static mut local_static_2: std::cell::LazyCell = std::cell::LazyCell::n { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 2); + Tracker::construct(&raw mut __v, 2); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs index 1dd4b73a5b..19cda7aef8 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs @@ -22,17 +22,22 @@ pub struct Tracker { pub tag: i32, } impl Tracker { - pub unsafe fn construct(&mut self, mut tag: i32) { - (&raw mut self.tag).write(tag); + pub unsafe fn construct(this: *mut Self, mut tag: i32) { + (&raw mut (*this).tag).write(tag); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); } - pub unsafe fn touch(&self) { - (unsafe { libc::printf(c"touch %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); + pub unsafe fn touch(this: *const Self) { + (unsafe { libc::printf(c"touch %d\n".as_ptr() as *const libc::c_char, ((*this).tag)) }); } } impl DestructibleUnsafe for Tracker { - unsafe fn destroy(&mut self) { - (unsafe { libc::printf(c"destroy %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); + unsafe fn destroy(this: *mut Self) { + (unsafe { + libc::printf( + c"destroy %d\n".as_ptr() as *const libc::c_char, + ((*this).tag), + ) + }); } } #[repr(C)] @@ -70,7 +75,7 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 1); + Tracker::construct(&raw mut __v, 1); __v }; libcc2rs::register_static_destructor(|| { @@ -81,18 +86,22 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new }); pub unsafe fn never_called_1() { (unsafe { - Tracker::touch(&(*std::cell::LazyCell::force_mut(&mut *&raw mut never_constructed_2))) + Tracker::touch( + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut never_constructed_2)), + ) }); } pub unsafe fn test_3() { - (unsafe { Tracker::touch(&(*std::cell::LazyCell::force_mut(&mut *&raw mut global_0))) }); + (unsafe { + Tracker::touch(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0))) + }); } static mut never_constructed_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 100); + Tracker::construct(&raw mut __v, 100); __v }; libcc2rs::register_static_destructor(|| { @@ -110,7 +119,7 @@ pub static mut before_6: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 2); + Tracker::construct(&raw mut __v, 2); __v }; libcc2rs::register_static_destructor(|| { @@ -124,7 +133,7 @@ pub static mut after_7: std::cell::LazyCell = std::cell::LazyCell::new( let __static = { let mut __v: Tracker = ::zero_init(); Tracker::construct( - &mut __v, + &raw mut __v, (((*(unsafe { local_static_during_global_init_4() })).tag) + (1)), ); __v @@ -140,7 +149,7 @@ pub static mut holder_8: std::cell::LazyCell = std::cell::LazyCell let __static = HoldsTracker { member: { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 5); + Tracker::construct(&raw mut __v, 5); __v }, }; @@ -168,7 +177,7 @@ pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::ne { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 7); + Tracker::construct(&raw mut __v, 7); __v }; libcc2rs::register_static_destructor(|| { @@ -184,7 +193,7 @@ pub static mut capturing_11: std::cell::LazyCell i32>> = { let captured: Tracker = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 8); + Tracker::construct(&raw mut __v, 8); __v }; }, @@ -201,19 +210,23 @@ pub static mut capturing_11: std::cell::LazyCell i32>> = } }); pub unsafe fn run_local_static_12() { - (unsafe { Tracker::touch(&(*std::cell::LazyCell::force_mut(&mut *&raw mut during_main_13))) }); + (unsafe { + Tracker::touch(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut during_main_13))) + }); } pub unsafe fn test_14() { (unsafe { run_local_static_12() }); (unsafe { run_local_static_12() }); - (unsafe { Tracker::touch(&(*(unsafe { local_static_during_global_init_4() }))) }); + (unsafe { Tracker::touch(&raw const (*(unsafe { local_static_during_global_init_4() }))) }); (unsafe { libc::printf( c"trivial %d\n".as_ptr() as *const libc::c_char, ((*std::cell::LazyCell::force_mut(&mut *&raw mut trivial_9)).value), ) }); - (unsafe { Tracker::touch(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_10))) }); + (unsafe { + Tracker::touch(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut member_10))) + }); (unsafe { libc::printf( c"captured %d\n".as_ptr() as *const libc::c_char, @@ -225,7 +238,7 @@ static mut during_init_5: std::cell::LazyCell = std::cell::LazyCell::ne { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 3); + Tracker::construct(&raw mut __v, 3); __v }; libcc2rs::register_static_destructor(|| { @@ -240,7 +253,7 @@ static mut during_main_13: std::cell::LazyCell = std::cell::LazyCell::n { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 9); + Tracker::construct(&raw mut __v, 9); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index c9407dca3a..80212c0812 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -33,10 +33,13 @@ impl HasConstexprCtor { pub fn reset() { copyCount_0.with(|rc| *rc.borrow_mut() = 0); } + pub fn construct(this: Ptr, mut v: i32) { + field!(this, m).write(v); + } } impl CopyConstructible for HasConstexprCtor { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), m).write(o.with(|__s| __s.m)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, m).write(o.with(|__s| __s.m)); (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -87,21 +90,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -111,13 +120,13 @@ pub fn test_5() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 3); + HasConstexprCtor::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 4); + HasConstexprCtor::construct(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]; @@ -128,13 +137,13 @@ pub fn test_5() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 3); + HasConstexprCtor::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 4); + HasConstexprCtor::construct(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ][(1) as usize] @@ -155,7 +164,7 @@ pub fn test_6() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 5); + HasConstexprCtor::construct(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } .m @@ -178,14 +187,14 @@ pub fn test_7() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 7); + HasConstexprCtor::construct(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } else { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 9); + HasConstexprCtor::construct(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }) @@ -214,7 +223,7 @@ pub fn test_9() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 5); + HasConstexprCtor::construct(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -261,11 +270,11 @@ thread_local!( pub static global_12: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&global_12.with(Value::clone).as_pointer()) + Destructible::destroy(global_12.with(Value::clone).as_pointer()) }); __static }; @@ -274,7 +283,7 @@ pub fn test_13() { ({ LifetimeTracked::reset() }); let r: Ptr = global_12.with(|v| v.as_pointer()); let f: Value> = Rc::new(RefCell::new(FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&global_12.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(global_12.with(|v| v.as_pointer())) }); }))); assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); ({ (*f.borrow()).call() }); @@ -291,16 +300,16 @@ 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()); + ConstructFrom::construct_from(__v.as_pointer(), (r).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || { - ({ LifetimeTrackedImpl::use_(&r.as_pointer()) }); + ({ LifetimeTracked::use_(r.as_pointer()) }); } ))); let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); ({ (*f.borrow()).call() }); assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); @@ -328,7 +337,7 @@ 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()); + ConstructFrom::construct_from(__v.as_pointer(), k.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -376,13 +385,19 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { #[offset(4)] pub scratch: i32, } +impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, value).write(v); + field!(this, scratch).write(0); + } +} impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember { fn copy_constructor( - this: &Ptr, + this: Ptr, o: Ptr, ) { - field!((*this), value).write(o.with(|__s| __s.value)); - field!((*this), scratch).write(o.with(|__s| __s.scratch)); + 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(); } } @@ -396,7 +411,7 @@ pub fn test_19() { Rc::new(RefCell::new( ::zero_init(), )); - ConstructFrom::construct_from(&__v.as_pointer(), k.as_pointer()); + ConstructFrom::construct_from(__v.as_pointer(), k.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -422,9 +437,9 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { pub b: LifetimeTracked, } impl DefaultConstructible for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, a)); - DefaultConstructible::default_constructor(&field_ptr!(this, b)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, a)); + DefaultConstructible::default_constructor(field_ptr!(this, b)); } } pub fn test_20() { @@ -434,19 +449,19 @@ pub fn test_20() { a: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, b: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, }, )); let _dtor_p = - std::mem::DropGuard::new(p.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(p.clone(), |__p| Destructible::destroy(__p.as_pointer())); let __decomp_21: Ptr = p.as_pointer(); let f: Value usize>> = Rc::new(RefCell::new(FnPtr:: usize>::new(|| -> usize { @@ -470,17 +485,31 @@ pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(4)] pub n: i32, } +impl p7_member_access_captures_this_HasMemberUsedInLambda { + pub fn makeLambda(this: Ptr) -> FnPtr i32> { + return lambda!( + { + let this_: Value> = + Rc::new(RefCell::new((this).clone())); + }, + || -> i32 { + ({ LifetimeTracked::use_({ field_ptr!((*this_.borrow()), x) }) }); + return (*this_.borrow()).with(|__s| __s.n); + } + ); + } +} impl DefaultConstructible for p7_member_access_captures_this_HasMemberUsedInLambda { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, x)); - field!((*this), n).write(1); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, x)); + field!(this, n).write(1); } } pub fn test_22() { ({ LifetimeTracked::reset() }); object!(c, p7_member_access_captures_this_HasMemberUsedInLambda); let f: Value i32>> = Rc::new(RefCell::new( - ({ p7_member_access_captures_this_HasMemberUsedInLambdaImpl::makeLambda(&c.as_pointer()) }), + ({ p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(c.as_pointer()) }), )); assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); assert!(({ (({ (*f.borrow()).call() }) == 1) })); @@ -499,9 +528,18 @@ pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, } +impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + pub fn sizer(this: Ptr) -> FnPtr usize> { + return FnPtr:: usize>::new(|| -> usize { + { + return 4usize; + } + }); + } +} impl DefaultConstructible for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, x)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, x)); } } pub fn test_23() { @@ -511,9 +549,7 @@ pub fn test_23() { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda ); let f: Value usize>> = Rc::new(RefCell::new( - ({ - p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl::sizer(&c.as_pointer()) - }), + ({ p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(c.as_pointer()) }), )); assert!(({ (({ (*f.borrow()).call() }) == 4usize) })); assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); @@ -557,7 +593,7 @@ thread_local!( #[byte_size(1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl DefaultConstructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { (*t_ctors_27.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -565,7 +601,7 @@ pub fn test_28() { let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + DefaultConstructible::default_constructor(__p.clone()); __p }; assert!(!((p).is_null())); @@ -592,8 +628,8 @@ pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } impl DefaultConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(3); + fn default_constructor(this: Ptr) { + field!(this, value).write(3); (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -604,7 +640,7 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -636,7 +672,7 @@ thread_local!( #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl DefaultConstructible for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -648,7 +684,7 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { Rc::new(RefCell::new( ::zero_init(), )); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -673,8 +709,8 @@ pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } impl DefaultConstructible for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, m)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, m)); } } pub fn test_33() { @@ -820,89 +856,26 @@ impl p4_1_pure_virtual_without_definition_HasPureVirtual } } impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { unreachable!( "p9_destructor_not_potentially_invoked_HasUndefinedDestructor::destroy is never defined" ) } } impl CopyConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn copy_constructor(this: &Ptr, _: Ptr) { + fn copy_constructor(this: Ptr, _: Ptr) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } impl CopyAssignable for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn copy_assign(this: &Ptr, _: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _: Ptr) -> Ptr { unreachable!( "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" ) } } -pub trait HasConstexprCtorImpl { - fn construct(&self, v: i32); -} -impl HasConstexprCtorImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), m).write(v); - } -} -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl { - fn construct(&self, v: i32); -} -impl p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl - for Ptr -{ - fn construct(&self, mut v: i32) { - field!((*self), value).write(v); - field!((*self), scratch).write(0); - } -} -pub trait p7_member_access_captures_this_HasMemberUsedInLambdaImpl { - fn makeLambda(&self) -> FnPtr i32>; -} -impl p7_member_access_captures_this_HasMemberUsedInLambdaImpl - for Ptr -{ - fn makeLambda(&self) -> FnPtr i32> { - return lambda!( - { - let this_: Value> = - Rc::new(RefCell::new((*self).clone())); - }, - || -> i32 { - ({ LifetimeTrackedImpl::use_(&field_ptr!((*this_.borrow()), x)) }); - return (*this_.borrow()).with(|__s| __s.n); - } - ); - } -} -pub trait p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl { - fn sizer(&self) -> FnPtr usize>; -} -impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl - for Ptr -{ - fn sizer(&self) -> FnPtr usize> { - return FnPtr:: usize>::new(|| -> usize { - { - return 4usize; - } - }); - } -} pub fn __cpp2rust_init_globals() { let _ = copyCount_0.with(|_| ()); let _ = ctorCount_1.with(|_| ()); diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 1dba12b2f0..9b239de46c 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -28,13 +28,13 @@ impl HasConstexprCtor { pub unsafe fn reset() { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) = 0; } - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.m).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).m).write(v); } } impl CopyConstructibleUnsafe for HasConstexprCtor { - unsafe fn copy_constructor(&mut self, o: *const HasConstexprCtor) { - (&raw mut self.m).write((*o).m); + unsafe fn copy_constructor(this: *mut Self, o: *const HasConstexprCtor) { + (&raw mut (*this).m).write((*o).m); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); } } @@ -68,25 +68,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)).prefix_inc(); } } @@ -95,12 +95,12 @@ pub unsafe fn test_5() { let arr: [HasConstexprCtor; 2] = [ { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 3); + HasConstexprCtor::construct(&raw mut __v, 3); __v }, { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 4); + HasConstexprCtor::construct(&raw mut __v, 4); __v }, ]; @@ -109,12 +109,12 @@ pub unsafe fn test_5() { return [ { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 3); + HasConstexprCtor::construct(&raw mut __v, 3); __v }, { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 4); + HasConstexprCtor::construct(&raw mut __v, 4); __v }, ][(1) as usize] @@ -132,7 +132,7 @@ pub unsafe fn test_6() { unsafe { return { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 5); + HasConstexprCtor::construct(&raw mut __v, 5); __v } .m; @@ -151,13 +151,13 @@ pub unsafe fn test_7() { return (if b { { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 7); + HasConstexprCtor::construct(&raw mut __v, 7); __v } } else { { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 9); + HasConstexprCtor::construct(&raw mut __v, 9); __v } }) @@ -179,7 +179,7 @@ pub unsafe fn test_9() { (*std::cell::LazyCell::force_mut(&mut *&raw mut left_8)).prefix_inc(); { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 5); + HasConstexprCtor::construct(&raw mut __v, 5); __v } } @@ -222,7 +222,7 @@ pub static mut global_12: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -238,7 +238,9 @@ pub unsafe fn test_13() { let r: *mut LifetimeTracked = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_12)); let mut f: FnPtr = FnPtr::::new(|| unsafe { (unsafe { - LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut global_12))) + LifetimeTracked::use_( + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut global_12)), + ) }); }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); @@ -255,16 +257,16 @@ pub unsafe fn test_14() { { let r: LifetimeTracked = { let mut __v: LifetimeTracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, r); + ConstructFromUnsafe::construct_from(&raw mut __v, r); __v }; }, || { - (unsafe { LifetimeTracked::use_(&r) }); + (unsafe { LifetimeTracked::use_(&raw const r) }); } ); let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (1))); (unsafe { f.call() }); @@ -292,7 +294,7 @@ pub unsafe fn test_16() { { let k: HasConstexprCtor = { let mut __v: HasConstexprCtor = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &k); + ConstructFromUnsafe::construct_from(&raw mut __v, &k); __v }; }, @@ -334,18 +336,18 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { pub scratch: i32, } impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.value).write(v); - (&raw mut self.scratch).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); + (&raw mut (*this).scratch).write(0); } } impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMember { unsafe fn copy_constructor( - &mut self, + this: *mut Self, o: *const p5_2_mutable_subobject_is_odr_used_HasMutableMember, ) { - (&raw mut self.value).write((*o).value); - (&raw mut self.scratch).write((*o).scratch); + (&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(); } } @@ -356,7 +358,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(&mut __v, &k); + ConstructFromUnsafe::construct_from(&raw mut __v, &k); __v }; }, @@ -380,9 +382,9 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { pub b: LifetimeTracked, } impl DefaultConstructibleUnsafe for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.a); - DefaultConstructibleUnsafe::default_constructor(&mut self.b); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).a); + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).b); } } pub unsafe fn test_20() { @@ -391,17 +393,17 @@ pub unsafe fn test_20() { p6_unevaluated_binding_needs_no_capture_HasTwoMembers { a: { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }, b: { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }, }; let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let __decomp_21: *mut p6_unevaluated_binding_needs_no_capture_HasTwoMembers = &mut p; let mut f: FnPtr usize> = FnPtr:: usize>::new(|| -> usize { @@ -425,30 +427,29 @@ pub struct p7_member_access_captures_this_HasMemberUsedInLambda { pub n: i32, } impl p7_member_access_captures_this_HasMemberUsedInLambda { - pub unsafe fn makeLambda(&mut self) -> FnPtr i32> { + pub unsafe fn makeLambda(this: *mut Self) -> FnPtr i32> { return lambda_unsafe!( { - let this_: *mut p7_member_access_captures_this_HasMemberUsedInLambda = - (self as *mut p7_member_access_captures_this_HasMemberUsedInLambda); + let this_: *mut p7_member_access_captures_this_HasMemberUsedInLambda = this; }, || -> i32 { - (unsafe { LifetimeTracked::use_(&(*this_).x) }); + (unsafe { LifetimeTracked::use_(&raw const (*this_).x) }); return (*this_).n; } ); } } impl DefaultConstructibleUnsafe for p7_member_access_captures_this_HasMemberUsedInLambda { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.x); - (&raw mut self.n).write(1); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + (&raw mut (*this).n).write(1); } } pub unsafe fn test_22() { (unsafe { LifetimeTracked::reset() }); object_unsafe!(c, p7_member_access_captures_this_HasMemberUsedInLambda); let mut f: FnPtr i32> = - (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&mut c) }); + (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&raw mut c) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); assert!(((unsafe { f.call() }) == (1))); assert!(((c.x.uses) == (1))); @@ -467,7 +468,7 @@ pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { pub x: LifetimeTracked, } impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - pub unsafe fn sizer(&mut self) -> FnPtr usize> { + pub unsafe fn sizer(this: *mut Self) -> FnPtr usize> { return FnPtr:: usize>::new(|| -> usize { unsafe { return ::std::mem::size_of::(); @@ -476,8 +477,8 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } } impl DefaultConstructibleUnsafe for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.x); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); } } pub unsafe fn test_23() { @@ -487,7 +488,7 @@ pub unsafe fn test_23() { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda ); let mut f: FnPtr usize> = - (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&mut c) }); + (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&raw mut c) }); assert!(((unsafe { f.call() }) == (::std::mem::size_of::()))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) == (0))); @@ -527,7 +528,7 @@ pub static mut t_ctors_27: std::cell::LazyCell = std::cell::LazyCell::new(| #[memberwise(copy_assign)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl DefaultConstructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)).prefix_inc(); } } @@ -536,7 +537,7 @@ pub unsafe fn test_28() { let __p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = Box::leak( Box::new(::zero_init()), ); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + DefaultConstructibleUnsafe::default_constructor(__p); __p }; assert!(!((p).is_null())); @@ -559,8 +560,8 @@ pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } impl DefaultConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(3); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(3); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)).prefix_inc(); } } @@ -570,7 +571,7 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { { let mut __v: p9_unused_copy_constructor_HasUndefinedCopyCtor = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -598,7 +599,7 @@ pub static mut m_ctors_32: std::cell::LazyCell = std::cell::LazyCell::new(| )] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl DefaultConstructibleUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)).prefix_inc(); } } @@ -608,7 +609,7 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { { let mut __v: p9_unused_implicit_assignment_HasUndefinedCopyAssignment = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -631,8 +632,8 @@ pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { impl DefaultConstructibleUnsafe for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.m); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).m); } } pub unsafe fn test_33() { @@ -765,21 +766,21 @@ unsafe impl p4_1_pure_virtual_without_definition_HasPureVirtual } } impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { unreachable!( "p9_destructor_not_potentially_invoked_HasUndefinedDestructor::destroy is never defined" ) } } impl CopyConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn copy_constructor(&mut self, _: *const Self) { + unsafe fn copy_constructor(this: *mut Self, _: *const Self) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } impl CopyAssignableUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, _: *const Self) -> *mut Self { unreachable!( "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" ) diff --git a/tests/std/class/class.init/out/refcount/class.base.init.rs b/tests/std/class/class.init/out/refcount/class.base.init.rs index 2534e5dade..2acd1ac802 100644 --- a/tests/std/class/class.init/out/refcount/class.base.init.rs +++ b/tests/std/class/class.init/out/refcount/class.base.init.rs @@ -27,6 +27,12 @@ pub struct p13_3_member_reads_earlier_member_Pair { #[offset(4)] pub second: i32, } +impl p13_3_member_reads_earlier_member_Pair { + pub fn construct(this: Ptr, mut first: i32) { + field!(this, first).write(first); + field!(this, second).write((this.with(|__s| __s.first) + 1)); + } +} pub fn test_0() { object!(pair, p13_3_member_reads_earlier_member_Pair(5)); assert!(({ (*pair.borrow()).first } == 5)); @@ -40,13 +46,4 @@ fn main_0() -> i32 { ({ test_0() }); return 0; } -pub trait p13_3_member_reads_earlier_member_PairImpl { - fn construct(&self, first: i32); -} -impl p13_3_member_reads_earlier_member_PairImpl for Ptr { - fn construct(&self, mut first: i32) { - field!((*self), first).write(first); - field!((*self), second).write(((*self).with(|__s| __s.first) + 1)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.init/out/unsafe/class.base.init.rs b/tests/std/class/class.init/out/unsafe/class.base.init.rs index 6f3620e491..49daa0771f 100644 --- a/tests/std/class/class.init/out/unsafe/class.base.init.rs +++ b/tests/std/class/class.init/out/unsafe/class.base.init.rs @@ -24,9 +24,9 @@ pub struct p13_3_member_reads_earlier_member_Pair { pub second: i32, } impl p13_3_member_reads_earlier_member_Pair { - pub unsafe fn construct(&mut self, mut first: i32) { - (&raw mut self.first).write(first); - (&raw mut self.second).write(((self.first) + (1))); + pub unsafe fn construct(this: *mut Self, mut first: i32) { + (&raw mut (*this).first).write(first); + (&raw mut (*this).second).write((((*this).first) + (1))); } } pub unsafe fn test_0() { diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs index fa63940b66..039b106303 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs @@ -6,6 +6,11 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; +impl p1_template_constructor_from_own_type_Probe { + pub fn construct_1(this: Ptr, u: Ptr) { + field!(this, value).write((u.with(|__s| __s.value) + 1)); + } +} #[derive( Copy, Clone, @@ -25,6 +30,11 @@ pub struct p1_template_constructor_from_own_type_Probe { #[offset(0)] pub value: i32, } +impl p1_template_constructor_from_own_type_Probe { + pub fn construct_2(this: Ptr, mut v: i32) { + field!(this, value).write(v); + } +} pub fn test_0() { object!( probe, @@ -44,18 +54,4 @@ fn main_0() -> i32 { ({ test_0() }); return 0; } -pub trait p1_template_constructor_from_own_type_ProbeImpl { - fn construct_1(&self, u: Ptr); - fn construct_2(&self, v: i32); -} -impl p1_template_constructor_from_own_type_ProbeImpl - for Ptr -{ - fn construct_1(&self, u: Ptr) { - field!((*self), value).write((u.with(|__s| __s.value) + 1)); - } - fn construct_2(&self, mut v: i32) { - field!((*self), value).write(v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs index 23cb1a23dc..5a5238fcda 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs @@ -25,13 +25,18 @@ pub struct p2_non_const_conversion_function_Gauge { #[offset(0)] pub value: i64, } +impl p2_non_const_conversion_function_Gauge { + pub fn to_i64(this: Ptr) -> i64 { + return field!(this, value).with_mut(|__v| __v.prefix_inc().clone()); + } +} pub fn test_0() { let gauge: Value = Rc::new(RefCell::new(p2_non_const_conversion_function_Gauge { value: 20_i64, })); let mut converted: i64 = - ({ p2_non_const_conversion_function_GaugeImpl::to_i64(&gauge.as_pointer()) }); + ({ p2_non_const_conversion_function_Gauge::to_i64(gauge.as_pointer()) }); assert!((converted == 21_i64)); assert!(({ (*gauge.borrow()).value } == 21_i64)); } @@ -43,12 +48,4 @@ fn main_0() -> i32 { ({ test_0() }); return 0; } -pub trait p2_non_const_conversion_function_GaugeImpl { - fn to_i64(&self) -> i64; -} -impl p2_non_const_conversion_function_GaugeImpl for Ptr { - fn to_i64(&self) -> i64 { - return field!((*self), value).with_mut(|__v| __v.prefix_inc().clone()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs index 696f420f4b..22ce4586f5 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs @@ -7,8 +7,11 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; impl p1_template_constructor_from_own_type_Probe { - pub unsafe fn construct_1(&mut self, u: *mut p1_template_constructor_from_own_type_Probe) { - (&raw mut self.value).write((((*u).value) + (1))); + pub unsafe fn construct_1( + this: *mut Self, + u: *mut p1_template_constructor_from_own_type_Probe, + ) { + (&raw mut (*this).value).write((((*u).value) + (1))); } } #[repr(C)] @@ -28,8 +31,8 @@ pub struct p1_template_constructor_from_own_type_Probe { pub value: i32, } impl p1_template_constructor_from_own_type_Probe { - pub unsafe fn construct_2(&mut self, mut v: i32) { - (&raw mut self.value).write(v); + pub unsafe fn construct_2(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); } } pub unsafe fn test_0() { diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs index 0688a1be3f..ef93a9bc00 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs @@ -23,15 +23,15 @@ pub struct p2_non_const_conversion_function_Gauge { pub value: i64, } impl p2_non_const_conversion_function_Gauge { - pub unsafe fn to_i64(&mut self) -> i64 { - return (*self.value.prefix_inc()); + pub unsafe fn to_i64(this: *mut Self) -> i64 { + return (*(*this).value.prefix_inc()); } } pub unsafe fn test_0() { let mut gauge: p2_non_const_conversion_function_Gauge = p2_non_const_conversion_function_Gauge { value: 20_i64 }; let mut converted: i64 = - (unsafe { p2_non_const_conversion_function_Gauge::to_i64(&mut gauge) }); + (unsafe { p2_non_const_conversion_function_Gauge::to_i64(&raw mut gauge) }); assert!(((converted) == (21_i64))); assert!(((gauge.value) == (21_i64))); } diff --git a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs index ca0bfcf7da..0b4938b1d8 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 @@ -23,6 +23,11 @@ pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { #[offset(0)] pub value: i32, } +impl p11_defaulted_move_constructor_is_trivial_MoveOnly { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} pub fn pass_0( object: p11_defaulted_move_constructor_is_trivial_MoveOnly, ) -> p11_defaulted_move_constructor_is_trivial_MoveOnly { @@ -32,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())); + ConstructFrom::construct_from(__v.as_pointer(), Moved(object.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -42,7 +47,7 @@ pub fn test_1() { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl::construct(&__v.as_pointer(), 7); + p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }); @@ -74,14 +79,4 @@ fn main_0() -> i32 { ({ test_3() }); return 0; } -pub trait p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl { - fn construct(&self, value: i32); -} -impl p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl - for Ptr -{ - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs index 46f516516e..6bdefc877d 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 @@ -21,8 +21,8 @@ pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { pub value: i32, } impl p11_defaulted_move_constructor_is_trivial_MoveOnly { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } pub unsafe fn pass_0( @@ -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(&mut __v, Moved(&mut object)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut object)); __v }; } @@ -40,7 +40,7 @@ pub unsafe fn test_1() { pass_0({ let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = ::zero_init(); - p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(&mut __v, 7); + p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(&raw mut __v, 7); __v }) }); diff --git a/tests/std/class/class.mem/out/refcount/class.mem.general.rs b/tests/std/class/class.mem/out/refcount/class.mem.general.rs index c0d307643a..d33d83e7b8 100644 --- a/tests/std/class/class.mem/out/refcount/class.mem.general.rs +++ b/tests/std/class/class.mem/out/refcount/class.mem.general.rs @@ -20,9 +20,22 @@ pub struct p7_1_function_body_names_later_member_HasLaterMembers { #[offset(0)] pub stock: i32, } +impl p7_1_function_body_names_later_member_HasLaterMembers { + pub fn take(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, stock).with_mut(|__v| *__v = *__v - amount) + }; + return ((this.with(|__s| __s.stock) + + ({ p7_1_function_body_names_later_member_HasLaterMembers::minimum(this.clone()) })) + + (anon_2_reserve as i32)); + } + pub fn minimum(this: Ptr) -> i32 { + return 2; + } +} impl DefaultConstructible for p7_1_function_body_names_later_member_HasLaterMembers { - fn default_constructor(this: &Ptr) { - field!((*this), stock).write(9); + fn default_constructor(this: Ptr) { + field!(this, stock).write(9); } } impl Default for p7_1_function_body_names_later_member_HasLaterMembers { @@ -37,7 +50,7 @@ pub fn test_3() { ); assert!( (({ - p7_1_function_body_names_later_member_HasLaterMembersImpl::take(&object.as_pointer(), 3) + p7_1_function_body_names_later_member_HasLaterMembers::take(object.as_pointer(), 3) }) == 38) ); assert!(({ (*object.borrow()).stock } == 6)); @@ -55,9 +68,17 @@ pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { #[offset(0)] pub total: i32, } +impl p7_2_default_argument_names_later_member_HasLaterStaticStep { + pub fn advance(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, total).with_mut(|__v| *__v = *__v + amount) + }; + return this.with(|__s| __s.total); + } +} impl DefaultConstructible for p7_2_default_argument_names_later_member_HasLaterStaticStep { - fn default_constructor(this: &Ptr) { - field!((*this), total).write(1); + fn default_constructor(this: Ptr) { + field!(this, total).write(1); } } impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { @@ -72,16 +93,16 @@ pub fn test_6() { ); assert!( (({ - p7_2_default_argument_names_later_member_HasLaterStaticStepImpl::advance( - &object.as_pointer(), + p7_2_default_argument_names_later_member_HasLaterStaticStep::advance( + object.as_pointer(), step_5.with(|rc| *rc.borrow()), ) }) == 5) ); assert!( (({ - p7_2_default_argument_names_later_member_HasLaterStaticStepImpl::advance( - &object.as_pointer(), + p7_2_default_argument_names_later_member_HasLaterStaticStep::advance( + object.as_pointer(), 2, ) }) == 7) @@ -97,38 +118,6 @@ fn main_0() -> i32 { ({ test_6() }); return 0; } -pub trait p7_1_function_body_names_later_member_HasLaterMembersImpl { - fn take(&self, amount: i32) -> i32; - fn minimum(&self) -> i32; -} -impl p7_1_function_body_names_later_member_HasLaterMembersImpl - for Ptr -{ - fn take(&self, mut amount: i32) -> i32 { - { - field!((*self), stock).with_mut(|__v| *__v = *__v - amount) - }; - return (((*self).with(|__s| __s.stock) - + ({ p7_1_function_body_names_later_member_HasLaterMembersImpl::minimum(self) })) - + (anon_2_reserve as i32)); - } - fn minimum(&self) -> i32 { - return 2; - } -} -pub trait p7_2_default_argument_names_later_member_HasLaterStaticStepImpl { - fn advance(&self, amount: i32) -> i32; -} -impl p7_2_default_argument_names_later_member_HasLaterStaticStepImpl - for Ptr -{ - fn advance(&self, mut amount: i32) -> i32 { - { - field!((*self), total).with_mut(|__v| *__v = *__v + amount) - }; - return (*self).with(|__s| __s.total); - } -} pub fn __cpp2rust_init_globals() { let _ = stock_0.with(|_| ()); let _ = step_4.with(|_| ()); diff --git a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs index dd49b62cf0..f67e1176e4 100644 --- a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs +++ b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs @@ -18,19 +18,21 @@ pub struct p7_1_function_body_names_later_member_HasLaterMembers { pub stock: i32, } impl p7_1_function_body_names_later_member_HasLaterMembers { - pub unsafe fn take(&mut self, mut amount: i32) -> i32 { - self.stock -= amount; - return (((self.stock) - + (unsafe { p7_1_function_body_names_later_member_HasLaterMembers::minimum(self) })) + pub unsafe fn take(this: *mut Self, mut amount: i32) -> i32 { + (*this).stock -= amount; + return ((((*this).stock) + + (unsafe { + p7_1_function_body_names_later_member_HasLaterMembers::minimum((this).cast_const()) + })) + (anon_2_reserve as i32)); } - pub unsafe fn minimum(&self) -> i32 { + pub unsafe fn minimum(this: *const Self) -> i32 { return 2; } } impl DefaultConstructibleUnsafe for p7_1_function_body_names_later_member_HasLaterMembers { - unsafe fn default_constructor(&mut self) { - (&raw mut self.stock).write(9); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).stock).write(9); } } impl Default for p7_1_function_body_names_later_member_HasLaterMembers { @@ -44,8 +46,9 @@ pub unsafe fn test_3() { p7_1_function_body_names_later_member_HasLaterMembers ); assert!( - ((unsafe { p7_1_function_body_names_later_member_HasLaterMembers::take(&mut object, 3,) }) - == (38)) + ((unsafe { + p7_1_function_body_names_later_member_HasLaterMembers::take(&raw mut object, 3) + }) == (38)) ); assert!(((object.stock) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut stock_0)) == (100))); @@ -58,14 +61,14 @@ pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { pub total: i32, } impl p7_2_default_argument_names_later_member_HasLaterStaticStep { - pub unsafe fn advance(&mut self, mut amount: i32) -> i32 { - self.total += amount; - return self.total; + pub unsafe fn advance(this: *mut Self, mut amount: i32) -> i32 { + (*this).total += amount; + return (*this).total; } } impl DefaultConstructibleUnsafe for p7_2_default_argument_names_later_member_HasLaterStaticStep { - unsafe fn default_constructor(&mut self) { - (&raw mut self.total).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).total).write(1); } } impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { @@ -81,14 +84,14 @@ pub unsafe fn test_6() { assert!( ((unsafe { p7_2_default_argument_names_later_member_HasLaterStaticStep::advance( - &mut object, + &raw mut object, (*std::cell::LazyCell::force_mut(&mut *&raw mut step_5)), ) }) == (5)) ); assert!( ((unsafe { - p7_2_default_argument_names_later_member_HasLaterStaticStep::advance(&mut object, 2) + p7_2_default_argument_names_later_member_HasLaterStaticStep::advance(&raw mut object, 2) }) == (7)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut step_4)) == (100))); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs index f61413b802..f960eaddcf 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs @@ -402,9 +402,9 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { pub five: i32, } impl DefaultConstructible for p9_1_2_zero_then_default_initialized_WithDefaultMember { - fn default_constructor(this: &Ptr) { - field!((*this), zeroed).write(0_i32); - field!((*this), five).write(5); + fn default_constructor(this: Ptr) { + field!(this, zeroed).write(0_i32); + field!(this, five).write(5); } } impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { @@ -424,8 +424,8 @@ pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } impl DefaultConstructible for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - fn default_constructor(this: &Ptr) { - field!((*this), untouched).write(0_i32); + fn default_constructor(this: Ptr) { + field!(this, untouched).write(0_i32); } } impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { @@ -436,7 +436,7 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { Rc::new(RefCell::new( ::zero_init(), )); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -454,9 +454,9 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } impl DefaultConstructible for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { - fn default_constructor(this: &Ptr) { - field!((*this), number).write(0_i32); - DefaultConstructible::default_constructor(&field_ptr!(this, member)); + fn default_constructor(this: Ptr) { + field!(this, number).write(0_i32); + DefaultConstructible::default_constructor(field_ptr!(this, member)); } } pub fn test_22() { @@ -468,7 +468,7 @@ pub fn test_22() { assert!(({ (*value.borrow()).five } == 5)); let mut heap: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + DefaultConstructible::default_constructor(__p.clone()); __p }; assert!((heap.with(|__s| __s.zeroed) == 0)); @@ -483,7 +483,7 @@ pub fn test_22() { let mut heap_holder: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + DefaultConstructible::default_constructor(__p.clone()); __p }; assert!((heap_holder.with(|__s| __s.number) == 0)); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs index cef1096ddd..8b2c7d2d64 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs @@ -333,9 +333,9 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { pub five: i32, } impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_WithDefaultMember { - unsafe fn default_constructor(&mut self) { - (&raw mut self.zeroed).write(0_i32); - (&raw mut self.five).write(5); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).zeroed).write(0_i32); + (&raw mut (*this).five).write(5); } } impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { @@ -354,8 +354,8 @@ pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - unsafe fn default_constructor(&mut self) { - (&raw mut self.untouched).write(0_i32); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).untouched).write(0_i32); } } impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { @@ -364,7 +364,7 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { { let mut __v: p9_1_2_zero_then_default_initialized_LeavesMemberAlone = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -379,9 +379,9 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { - unsafe fn default_constructor(&mut self) { - (&raw mut self.number).write(0_i32); - DefaultConstructibleUnsafe::default_constructor(&mut self.member); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).number).write(0_i32); + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).member); } } pub unsafe fn test_22() { @@ -395,7 +395,7 @@ pub unsafe fn test_22() { let __p: *mut p9_1_2_zero_then_default_initialized_WithDefaultMember = Box::leak(Box::new( ::zero_init(), )); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + DefaultConstructibleUnsafe::default_constructor(__p); __p }; assert!((((*heap).zeroed) == (0))); @@ -416,7 +416,7 @@ pub unsafe fn test_22() { let __p: *mut p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = Box::leak( Box::new(::zero_init()), ); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + DefaultConstructibleUnsafe::default_constructor(__p); __p }; assert!((((*heap_holder).number) == (0))); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs index 16cf0ed793..16a6d8f105 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs @@ -60,9 +60,17 @@ pub struct p9_static_member_hides_namespace_variable_HasStaticStep { #[offset(0)] pub total: i32, } +impl p9_static_member_hides_namespace_variable_HasStaticStep { + pub fn advance(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, total).with_mut(|__v| *__v = *__v + amount) + }; + return this.with(|__s| __s.total); + } +} impl DefaultConstructible for p9_static_member_hides_namespace_variable_HasStaticStep { - fn default_constructor(this: &Ptr) { - field!((*this), total).write(1); + fn default_constructor(this: Ptr) { + field!(this, total).write(1); } } impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { @@ -77,8 +85,8 @@ pub fn test_11() { ); assert!( (({ - p9_static_member_hides_namespace_variable_HasStaticStepImpl::advance( - &object.as_pointer(), + p9_static_member_hides_namespace_variable_HasStaticStep::advance( + object.as_pointer(), step_10.with(|rc| *rc.borrow()), ) }) == 5) @@ -86,18 +94,15 @@ pub fn test_11() { step_10.with(|rc| *rc.borrow_mut() = 6); assert!( (({ - p9_static_member_hides_namespace_variable_HasStaticStepImpl::advance( - &object.as_pointer(), + p9_static_member_hides_namespace_variable_HasStaticStep::advance( + object.as_pointer(), step_10.with(|rc| *rc.borrow()), ) }) == 11) ); assert!( (({ - p9_static_member_hides_namespace_variable_HasStaticStepImpl::advance( - &object.as_pointer(), - 2, - ) + p9_static_member_hides_namespace_variable_HasStaticStep::advance(object.as_pointer(), 2) }) == 13) ); assert!((step_9.with(|rc| *rc.borrow()) == 100)); @@ -120,10 +125,15 @@ pub struct p9_evaluated_each_time_called_Widget { #[offset(0)] pub id: i32, } +impl p9_evaluated_each_time_called_Widget { + pub fn construct(this: Ptr, mut id: i32) { + field!(this, id).write(id); + } +} impl DefaultConstructible for p9_evaluated_each_time_called_Widget { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { { - p9_evaluated_each_time_called_WidgetImpl::construct(this, ({ count_default_13() })); + p9_evaluated_each_time_called_Widget::construct(this.clone(), ({ count_default_13() })); } } } @@ -134,8 +144,8 @@ impl Default for p9_evaluated_each_time_called_Widget { let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - p9_evaluated_each_time_called_WidgetImpl::construct( - &__v.as_pointer(), + p9_evaluated_each_time_called_Widget::construct( + __v.as_pointer(), ({ count_default_13() }), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -158,13 +168,19 @@ impl p9_evaluated_each_time_called_Account { fn twice(mut value: i32) -> i32 { return (2 * value); } + pub fn deposit(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, balance).with_mut(|__v| *__v = *__v + amount) + }; + return this.with(|__s| __s.balance); + } pub fn set_base(mut value: i32) { base_15.with(|rc| *rc.borrow_mut() = value); } } impl DefaultConstructible for p9_evaluated_each_time_called_Account { - fn default_constructor(this: &Ptr) { - field!((*this), balance).write(0); + fn default_constructor(this: Ptr) { + field!(this, balance).write(0); } } impl Default for p9_evaluated_each_time_called_Account { @@ -198,8 +214,8 @@ pub fn test_17() { object!(account, p9_evaluated_each_time_called_Account); assert!( (({ - p9_evaluated_each_time_called_AccountImpl::deposit( - &account.as_pointer(), + p9_evaluated_each_time_called_Account::deposit( + account.as_pointer(), (({ p9_evaluated_each_time_called_Account::twice(base_15.with(|rc| *rc.borrow())) }) + (anon_16_kBonus as i32)), @@ -209,17 +225,15 @@ pub fn test_17() { ({ p9_evaluated_each_time_called_Account::set_base(1) }); assert!( (({ - p9_evaluated_each_time_called_AccountImpl::deposit( - &account.as_pointer(), + p9_evaluated_each_time_called_Account::deposit( + account.as_pointer(), (({ p9_evaluated_each_time_called_Account::twice(base_15.with(|rc| *rc.borrow())) }) + (anon_16_kBonus as i32)), ) }) == 32) ); - assert!( - (({ p9_evaluated_each_time_called_AccountImpl::deposit(&account.as_pointer(), 3,) }) == 35) - ); + assert!((({ p9_evaluated_each_time_called_Account::deposit(account.as_pointer(), 3,) }) == 35)); } pub fn add_18(mut a: i32, mut b: i32) -> i32 { return (a + b); @@ -307,38 +321,6 @@ fn main_0() -> i32 { ({ test_20() }); return 0; } -pub trait p9_evaluated_each_time_called_AccountImpl { - fn deposit(&self, amount: i32) -> i32; -} -impl p9_evaluated_each_time_called_AccountImpl for Ptr { - fn deposit(&self, mut amount: i32) -> i32 { - { - field!((*self), balance).with_mut(|__v| *__v = *__v + amount) - }; - return (*self).with(|__s| __s.balance); - } -} -pub trait p9_evaluated_each_time_called_WidgetImpl { - fn construct(&self, id: i32); -} -impl p9_evaluated_each_time_called_WidgetImpl for Ptr { - fn construct(&self, mut id: i32) { - field!((*self), id).write(id); - } -} -pub trait p9_static_member_hides_namespace_variable_HasStaticStepImpl { - fn advance(&self, amount: i32) -> i32; -} -impl p9_static_member_hides_namespace_variable_HasStaticStepImpl - for Ptr -{ - fn advance(&self, mut amount: i32) -> i32 { - { - field!((*self), total).with_mut(|__v| *__v = *__v + amount) - }; - return (*self).with(|__s| __s.total); - } -} pub fn __cpp2rust_init_globals() { let _ = scaled_calls_0.with(|_| ()); let _ = rate_1.with(|_| ()); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs index eae9df980c..8ba134d982 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs @@ -59,14 +59,14 @@ pub struct p9_static_member_hides_namespace_variable_HasStaticStep { pub total: i32, } impl p9_static_member_hides_namespace_variable_HasStaticStep { - pub unsafe fn advance(&mut self, mut amount: i32) -> i32 { - self.total += amount; - return self.total; + pub unsafe fn advance(this: *mut Self, mut amount: i32) -> i32 { + (*this).total += amount; + return (*this).total; } } impl DefaultConstructibleUnsafe for p9_static_member_hides_namespace_variable_HasStaticStep { - unsafe fn default_constructor(&mut self) { - (&raw mut self.total).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).total).write(1); } } impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { @@ -82,7 +82,7 @@ pub unsafe fn test_11() { assert!( ((unsafe { p9_static_member_hides_namespace_variable_HasStaticStep::advance( - &mut object, + &raw mut object, (*std::cell::LazyCell::force_mut(&mut *&raw mut step_10)), ) }) == (5)) @@ -91,14 +91,14 @@ pub unsafe fn test_11() { assert!( ((unsafe { p9_static_member_hides_namespace_variable_HasStaticStep::advance( - &mut object, + &raw mut object, (*std::cell::LazyCell::force_mut(&mut *&raw mut step_10)), ) }) == (11)) ); assert!( ((unsafe { - p9_static_member_hides_namespace_variable_HasStaticStep::advance(&mut object, 2) + p9_static_member_hides_namespace_variable_HasStaticStep::advance(&raw mut object, 2) }) == (13)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut step_9)) == (100))); @@ -120,17 +120,14 @@ pub struct p9_evaluated_each_time_called_Widget { pub id: i32, } impl p9_evaluated_each_time_called_Widget { - pub unsafe fn construct(&mut self, mut id: i32) { - (&raw mut self.id).write(id); + pub unsafe fn construct(this: *mut Self, mut id: i32) { + (&raw mut (*this).id).write(id); } } impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Widget { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { unsafe { - p9_evaluated_each_time_called_Widget::construct( - &mut *self, - (unsafe { count_default_13() }), - ); + p9_evaluated_each_time_called_Widget::construct(this, (unsafe { count_default_13() })); } } } @@ -141,7 +138,7 @@ impl Default for p9_evaluated_each_time_called_Widget { let mut __v: p9_evaluated_each_time_called_Widget = ::zero_init(); p9_evaluated_each_time_called_Widget::construct( - &mut __v, + &raw mut __v, (unsafe { count_default_13() }), ); __v @@ -161,17 +158,17 @@ impl p9_evaluated_each_time_called_Account { unsafe fn twice(mut value: i32) -> i32 { return ((2) * (value)); } - pub unsafe fn deposit(&mut self, mut amount: i32) -> i32 { - self.balance += amount; - return self.balance; + pub unsafe fn deposit(this: *mut Self, mut amount: i32) -> i32 { + (*this).balance += amount; + return (*this).balance; } pub unsafe fn set_base(mut value: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut base_15)) = value; } } impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Account { - unsafe fn default_constructor(&mut self) { - (&raw mut self.balance).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).balance).write(0); } } impl Default for p9_evaluated_each_time_called_Account { @@ -208,7 +205,7 @@ pub unsafe fn test_17() { assert!( ((unsafe { p9_evaluated_each_time_called_Account::deposit( - &mut account, + &raw mut account, ((unsafe { p9_evaluated_each_time_called_Account::twice( (*std::cell::LazyCell::force_mut(&mut *&raw mut base_15)), @@ -221,7 +218,7 @@ pub unsafe fn test_17() { assert!( ((unsafe { p9_evaluated_each_time_called_Account::deposit( - &mut account, + &raw mut account, ((unsafe { p9_evaluated_each_time_called_Account::twice( (*std::cell::LazyCell::force_mut(&mut *&raw mut base_15)), @@ -231,7 +228,7 @@ pub unsafe fn test_17() { }) == (32)) ); assert!( - ((unsafe { p9_evaluated_each_time_called_Account::deposit(&mut account, 3,) }) == (35)) + ((unsafe { p9_evaluated_each_time_called_Account::deposit(&raw mut account, 3,) }) == (35)) ); } pub unsafe fn add_18(mut a: i32, mut b: i32) -> i32 { diff --git a/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs index f47f6c147a..c02a9cd9a1 100644 --- a/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs +++ b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs @@ -58,8 +58,26 @@ pub struct p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMemb #[offset(0)] pub base: i32, } +impl p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { + pub fn add( + self_: Ptr, + mut amount: i32, + ) -> i32 { + return ({ self_.with(|__s| __s.base) } + { amount }); + } +} pub fn test_3() { - let mut function_pointer : FnPtr ,i32 ,) -> i32 > = ( FnPtr:: ,i32 ,) -> i32 >::new( as p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMemberImpl>::add) ) ; + let mut function_pointer: FnPtr< + fn( + Ptr, + i32, + ) -> i32, + > = (FnPtr::< + fn( + Ptr, + i32, + ) -> i32, + >::new(p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember::add)); let object: Value = Rc::new(RefCell::new( p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { base: 3 }, @@ -85,6 +103,14 @@ pub struct p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemb #[offset(0)] pub value: i32, } +impl p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { + pub fn parenthesized(this: Ptr) -> Ptr { + return (field_ptr!(this, value)); + } + pub fn unqualified(this: Ptr) -> Ptr { + return (field_ptr!(this, value)); + } +} pub fn test_4() { let first: Value = Rc::new(RefCell::new( @@ -95,8 +121,8 @@ pub fn test_4() { p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { value: 4 }, )); let mut p: Ptr = ({ - p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemberImpl::parenthesized( - &first.as_pointer(), + p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember::parenthesized( + first.as_pointer(), ) }); assert!(({ (p).clone() } == { (field_ptr!(first.as_pointer(), value)) })); @@ -104,8 +130,8 @@ pub fn test_4() { assert!(({ (*first.borrow()).value } == 5)); assert!(({ (*second.borrow()).value } == 4)); let mut q: Ptr = ({ - p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemberImpl::unqualified( - &second.as_pointer(), + p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember::unqualified( + second.as_pointer(), ) }); assert!(({ (q).clone() } == { (field_ptr!(second.as_pointer(), value)) })); @@ -123,36 +149,6 @@ fn main_0() -> i32 { ({ test_4() }); return 0; } -pub trait p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMemberImpl { - fn add( - self_: Ptr, - amount: i32, - ) -> i32; -} -impl p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMemberImpl - for Ptr -{ - fn add( - self_: Ptr, - mut amount: i32, - ) -> i32 { - return ({ self_.with(|__s| __s.base) } + { amount }); - } -} -pub trait p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemberImpl { - fn parenthesized(&self) -> Ptr; - fn unqualified(&self) -> Ptr; -} -impl p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemberImpl - for Ptr -{ - fn parenthesized(&self) -> Ptr { - return (field_ptr!((*self), value)); - } - fn unqualified(&self) -> Ptr { - return (field_ptr!((*self), value)); - } -} pub fn __cpp2rust_init_globals() { let _ = shared_0.with(|_| ()); let _ = calls_1.with(|_| ()); diff --git a/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs b/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs index d6ab330b13..47ba7f3017 100644 --- a/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs +++ b/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs @@ -86,11 +86,11 @@ pub struct p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemb pub value: i32, } impl p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { - pub unsafe fn parenthesized(&mut self) -> *mut i32 { - return (&mut (self.value) as *mut i32); + pub unsafe fn parenthesized(this: *mut Self) -> *mut i32 { + return (&mut ((*this).value) as *mut i32); } - pub unsafe fn unqualified(&mut self) -> *mut i32 { - return (&mut self.value as *mut i32); + pub unsafe fn unqualified(this: *mut Self) -> *mut i32 { + return (&mut (*this).value as *mut i32); } } pub unsafe fn test_4() { @@ -100,7 +100,7 @@ pub unsafe fn test_4() { p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { value: 4 }; let mut p: *mut i32 = (unsafe { p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember::parenthesized( - &mut first, + &raw mut first, ) }); assert!(((p) == (&mut first.value as *mut i32))); @@ -109,7 +109,7 @@ pub unsafe fn test_4() { assert!(((second.value) == (4))); let mut q: *mut i32 = (unsafe { p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember::unqualified( - &mut second, + &raw mut second, ) }); assert!(((q) == (&mut second.value as *mut i32))); 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 b79799d018..623ff80f49 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 @@ -144,7 +144,7 @@ thread_local!( 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, + this: Ptr, _a0: Ptr, ) { (*copyCount_9.with(Value::clone).borrow_mut()).prefix_inc(); @@ -152,7 +152,7 @@ impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMov } impl MoveConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { fn move_constructor( - this: &Ptr, + this: Ptr, _a0: Ptr, ) { (*moveCount_10.with(Value::clone).borrow_mut()).prefix_inc(); 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 ec45af9fb2..94eb7fbc68 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 @@ -131,7 +131,7 @@ pub static mut moveCount_10: std::cell::LazyCell = std::cell::LazyCell::new 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( - &mut self, + this: *mut Self, _a0: *const p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, ) { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)).prefix_inc(); @@ -139,7 +139,7 @@ impl CopyConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopies } impl MoveConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { unsafe fn move_constructor( - &mut self, + this: *mut Self, _a0: *mut p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, ) { (*std::cell::LazyCell::force_mut(&mut *&raw mut moveCount_10)).prefix_inc(); diff --git a/tests/std/expr/expr.prim/expr.prim.this.cpp b/tests/std/expr/expr.prim/expr.prim.this.cpp index 566c58b062..38db1a88b0 100644 --- a/tests/std/expr/expr.prim/expr.prim.this.cpp +++ b/tests/std/expr/expr.prim/expr.prim.this.cpp @@ -38,8 +38,31 @@ void test() { } } // namespace p1_mem_initializer_names_object +// N4950 [expr.prim.this]/1: this is a prvalue. Its value is the pointer the +// function was called with, also after the function changes the pointer +// object that the call was made through. +namespace p1_this_is_a_copy_of_the_pointer { +struct Node { + int value; + Node *next; + int advance(Node *&cursor) { + cursor = next; + return value; + } +}; + +void test() { + Node second{2, nullptr}; + Node first{1, &second}; + Node *cursor = &first; + assert(cursor->advance(cursor) == 1); + assert(cursor == &second); +} +} // namespace p1_this_is_a_copy_of_the_pointer + int main() { p1_default_member_initializer_names_object::test(); p1_mem_initializer_names_object::test(); + p1_this_is_a_copy_of_the_pointer::test(); return 0; } diff --git a/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs b/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs index 8e44300e24..5b0d9df9f2 100644 --- a/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs +++ b/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs @@ -26,6 +26,14 @@ pub struct p1_default_member_initializer_names_object_Holder { #[offset(8)] pub value: i32, } +impl p1_default_member_initializer_names_object_Holder { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, self_).write((this).clone()); + field!(this, value).write(value); + assert!((this.with(|__s| __s.self_.clone()) == this)); + assert!(({ this.with(|__s| __s.self_.clone()).with(|__s| __s.value) } == { value })); + } +} impl Default for p1_default_member_initializer_names_object_Holder { fn default() -> Self { { ::zero_init() } @@ -56,10 +64,72 @@ pub struct p1_mem_initializer_names_object_Holder { #[offset(8)] pub value: i32, } +impl p1_mem_initializer_names_object_Holder { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, self_).write((this).clone()); + field!(this, value).write(value); + assert!((this.with(|__s| __s.self_.clone()) == this)); + { + field!(this.with(|__s| __s.self_.clone()), value).with_mut(|__v| *__v = *__v + 1) + }; + assert!((this.with(|__s| __s.value) == (value + 1))); + } +} pub fn test_1() { object!(holder, p1_mem_initializer_names_object_Holder(4)); assert!(({ (*holder.borrow()).value } == 5)); } +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, +)] +#[byte_size(16)] +pub struct p1_this_is_a_copy_of_the_pointer_Node { + #[offset(0)] + pub value: i32, + #[offset(8)] + #[byte_size(8)] + pub next: Ptr, +} +impl p1_this_is_a_copy_of_the_pointer_Node { + pub fn advance( + this: Ptr, + cursor: Ptr>, + ) -> i32 { + cursor.write(this.with(|__s| __s.next.clone())); + return this.with(|__s| __s.value); + } +} +pub fn test_2() { + let second: Value = + Rc::new(RefCell::new(p1_this_is_a_copy_of_the_pointer_Node { + value: 2, + next: Ptr::::null(), + })); + let first: Value = + Rc::new(RefCell::new(p1_this_is_a_copy_of_the_pointer_Node { + value: 1, + next: (second.as_pointer()), + })); + let cursor: Value> = + Rc::new(RefCell::new((first.as_pointer()))); + assert!( + (({ + p1_this_is_a_copy_of_the_pointer_Node::advance( + { (*cursor.borrow()).clone() }, + cursor.as_pointer(), + ) + }) == 1) + ); + assert!(({ ({ (*cursor.borrow()).clone() } == { (second.as_pointer()) }) })); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -67,33 +137,7 @@ pub fn main() { fn main_0() -> i32 { ({ test_0() }); ({ test_1() }); + ({ test_2() }); return 0; } -pub trait p1_default_member_initializer_names_object_HolderImpl { - fn construct(&self, value: i32); -} -impl p1_default_member_initializer_names_object_HolderImpl - for Ptr -{ - fn construct(&self, mut value: i32) { - field!((*self), self_).write((*self).clone()); - field!((*self), value).write(value); - assert!(((*self).with(|__s| __s.self_.clone()) == (*self))); - assert!(({ (*self).with(|__s| __s.self_.clone()).with(|__s| __s.value) } == { value })); - } -} -pub trait p1_mem_initializer_names_object_HolderImpl { - fn construct(&self, value: i32); -} -impl p1_mem_initializer_names_object_HolderImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), self_).write((*self).clone()); - field!((*self), value).write(value); - assert!(((*self).with(|__s| __s.self_.clone()) == (*self))); - { - field!((*self).with(|__s| __s.self_.clone()), value).with_mut(|__v| *__v = *__v + 1) - }; - assert!(((*self).with(|__s| __s.value) == (value + 1))); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs b/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs index 6e57a8515a..9f76306c66 100644 --- a/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs +++ b/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs @@ -23,12 +23,11 @@ pub struct p1_default_member_initializer_names_object_Holder { pub value: i32, } impl p1_default_member_initializer_names_object_Holder { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.self_) - .write((self as *mut p1_default_member_initializer_names_object_Holder)); - (&raw mut self.value).write(value); - assert!(((self.self_) == (self as *mut p1_default_member_initializer_names_object_Holder))); - assert!((((*self.self_).value) == (value))); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).self_).write(this); + (&raw mut (*this).value).write(value); + assert!((((*this).self_) == (this))); + assert!((((*(*this).self_).value) == (value))); } } impl Default for p1_default_member_initializer_names_object_Holder { @@ -58,18 +57,61 @@ pub struct p1_mem_initializer_names_object_Holder { pub value: i32, } impl p1_mem_initializer_names_object_Holder { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.self_).write((self as *mut p1_mem_initializer_names_object_Holder)); - (&raw mut self.value).write(value); - assert!(((self.self_) == (self as *mut p1_mem_initializer_names_object_Holder))); - (*self.self_).value += 1; - assert!(((self.value) == ((value) + (1)))); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).self_).write(this); + (&raw mut (*this).value).write(value); + assert!((((*this).self_) == (this))); + (*(*this).self_).value += 1; + assert!((((*this).value) == ((value) + (1)))); } } pub unsafe fn test_1() { object_unsafe!(holder, p1_mem_initializer_names_object_Holder(4)); assert!(((holder.value) == (5))); } +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, +)] +pub struct p1_this_is_a_copy_of_the_pointer_Node { + pub value: i32, + pub next: *mut p1_this_is_a_copy_of_the_pointer_Node, +} +impl p1_this_is_a_copy_of_the_pointer_Node { + pub unsafe fn advance( + this: *mut Self, + cursor: *mut *mut p1_this_is_a_copy_of_the_pointer_Node, + ) -> i32 { + (*cursor) = (*this).next; + return (*this).value; + } +} +pub unsafe fn test_2() { + let mut second: p1_this_is_a_copy_of_the_pointer_Node = p1_this_is_a_copy_of_the_pointer_Node { + value: 2, + next: std::ptr::null_mut(), + }; + let mut first: p1_this_is_a_copy_of_the_pointer_Node = p1_this_is_a_copy_of_the_pointer_Node { + value: 1, + next: (&mut second as *mut p1_this_is_a_copy_of_the_pointer_Node), + }; + let mut cursor: *mut p1_this_is_a_copy_of_the_pointer_Node = + (&mut first as *mut p1_this_is_a_copy_of_the_pointer_Node); + assert!( + ((unsafe { + let _cursor: *mut *mut p1_this_is_a_copy_of_the_pointer_Node = &mut cursor; + p1_this_is_a_copy_of_the_pointer_Node::advance(&raw mut (*cursor), _cursor) + }) == (1)) + ); + assert!(((cursor) == (&mut second as *mut p1_this_is_a_copy_of_the_pointer_Node))); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -79,6 +121,7 @@ pub fn main() { unsafe fn main_0() -> i32 { (unsafe { test_0() }); (unsafe { test_1() }); + (unsafe { test_2() }); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs index 31cf739d9f..57f81a7b45 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs @@ -27,8 +27,8 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { pub id: i32, } impl DefaultConstructible for p16_rebind_member_Alloc_std_pair_const_int__int__ { - fn default_constructor(this: &Ptr) { - field!((*this), id).write(0); + fn default_constructor(this: Ptr) { + field!(this, id).write(0); } } impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { @@ -101,28 +101,4 @@ fn main_0() -> i32 { ({ test_1() }); return 0; } -pub trait p16_rebind_member_Alloc_std_pair_const_int__int__Impl { - fn allocate(&self, mut n: usize) -> Ptr<(Value, Value)> { - unimplemented!() - } - fn deallocate(&self, mut p: Ptr<(Value, Value)>, mut n: usize) { - unimplemented!() - } -} -impl p16_rebind_member_Alloc_std_pair_const_int__int__Impl - for Ptr -{ -} -pub trait p18_rebind_to_container_node_Alloc_std_pair_const_int__int__Impl { - fn allocate(&self, mut n: usize) -> Ptr<(Value, Value)> { - unimplemented!() - } - fn deallocate(&self, mut p: Ptr<(Value, Value)>, mut n: usize) { - unimplemented!() - } -} -impl p18_rebind_to_container_node_Alloc_std_pair_const_int__int__Impl - for Ptr -{ -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs index 24bd0567b2..0f080d78b2 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs @@ -24,8 +24,8 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { pub id: i32, } impl DefaultConstructibleUnsafe for p16_rebind_member_Alloc_std_pair_const_int__int__ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.id).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).id).write(0); } } impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { diff --git a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs index 08befc644a..5a09259fc5 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs @@ -32,8 +32,17 @@ pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { #[offset(0)] pub value: i32, } +impl p2_condition_variable_created_each_iteration_ConvertsToBool { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.value) != 0); + } +} impl Destructible for p2_condition_variable_created_each_iteration_ConvertsToBool { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -46,8 +55,8 @@ pub fn test_2() { p2_condition_variable_created_each_iteration_ConvertsToBool(remaining) ); if !({ - p2_condition_variable_created_each_iteration_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), + p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool( + condition.as_pointer(), ) }) { break; @@ -88,8 +97,17 @@ pub struct p2_continue_destroys_condition_variable_ConvertsToBool { #[offset(0)] pub value: i32, } +impl p2_continue_destroys_condition_variable_ConvertsToBool { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + (*ctorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.value) != 0); + } +} impl Destructible for p2_continue_destroys_condition_variable_ConvertsToBool { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_4.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -103,9 +121,7 @@ pub fn test_5() { p2_continue_destroys_condition_variable_ConvertsToBool(remaining) ); if !({ - p2_continue_destroys_condition_variable_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) + p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(condition.as_pointer()) }) { break; } @@ -134,36 +150,6 @@ fn main_0() -> i32 { ({ test_5() }); return 0; } -pub trait p2_condition_variable_created_each_iteration_ConvertsToBoolImpl { - fn construct(&self, value: i32); - fn to_bool(&self) -> bool; -} -impl p2_condition_variable_created_each_iteration_ConvertsToBoolImpl - for Ptr -{ - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.value) != 0); - } -} -pub trait p2_continue_destroys_condition_variable_ConvertsToBoolImpl { - fn construct(&self, value: i32); - fn to_bool(&self) -> bool; -} -impl p2_continue_destroys_condition_variable_ConvertsToBoolImpl - for Ptr -{ - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - (*ctorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.value) != 0); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = dtorCount_1.with(|_| ()); diff --git a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs index 68d9d72333..4a245a6df0 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs @@ -26,16 +26,16 @@ pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { pub value: i32, } impl p2_condition_variable_created_each_iteration_ConvertsToBool { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn to_bool(&self) -> bool { - return ((self.value) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).value) != (0)); } } impl DestructibleUnsafe for p2_condition_variable_created_each_iteration_ConvertsToBool { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_1)).prefix_inc(); } } @@ -48,7 +48,9 @@ pub unsafe fn test_2() { p2_condition_variable_created_each_iteration_ConvertsToBool(remaining) ); if !(unsafe { - p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool(&condition) + p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool( + &raw const condition, + ) }) { break; } @@ -84,16 +86,16 @@ pub struct p2_continue_destroys_condition_variable_ConvertsToBool { pub value: i32, } impl p2_continue_destroys_condition_variable_ConvertsToBool { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_3)).prefix_inc(); } - pub unsafe fn to_bool(&self) -> bool { - return ((self.value) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).value) != (0)); } } impl DestructibleUnsafe for p2_continue_destroys_condition_variable_ConvertsToBool { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_4)).prefix_inc(); } } @@ -106,8 +108,9 @@ pub unsafe fn test_5() { condition, p2_continue_destroys_condition_variable_ConvertsToBool(remaining) ); - if !(unsafe { p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(&condition) }) - { + if !(unsafe { + p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(&raw const condition) + }) { break; } remaining.prefix_dec(); 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 1bd4dc7a47..c9707c9790 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 @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -87,7 +93,7 @@ pub fn test_6() { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); } else { (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); - ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + ({ LifetimeTracked::use_(guard.as_pointer()) }); assert!(({ (*guard.borrow()).uses } == 1)); assert!((choice == 0)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); @@ -101,7 +107,7 @@ pub fn test_6() { let mut choice: i32 = 4; if (choice != 0) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); - ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + ({ LifetimeTracked::use_(guard.as_pointer()) }); assert!(({ (*guard.borrow()).uses } == 1)); assert!((choice == 4)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); @@ -191,17 +197,6 @@ fn main_0() -> i32 { ({ test_12() }); return 0; } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index 83a6535236..87f2db939c 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 @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -100,8 +106,13 @@ pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { #[offset(0)] pub value: i32, } +impl p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.value); + } +} impl Destructible for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -112,13 +123,13 @@ pub fn test_7() { p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }, )); let _dtor_selector = std::mem::DropGuard::new(selector.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); 'switch: { match { ({ - p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl::to_i32( - &selector.as_pointer(), + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + selector.as_pointer(), ) }) } { @@ -155,7 +166,7 @@ pub fn test_10() { match { selector } { __v if __v == 2 => { (*matching_case_runs_8.with(Value::clone).borrow_mut()).prefix_inc(); - ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + ({ LifetimeTracked::use_(guard.as_pointer()) }); assert!(({ (*guard.borrow()).uses } == 1)); assert!((selector == 2)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); @@ -220,27 +231,6 @@ fn main_0() -> i32 { ({ test_10() }); return 0; } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl { - fn to_i32(&self) -> i32; -} -impl p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl - for Ptr -{ - fn to_i32(&self) -> i32 { - return (*self).with(|__s| __s.value); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs index 0712640fcc..1d35d3d76e 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 @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -72,7 +72,7 @@ pub unsafe fn test_6() { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); } else { (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); - (unsafe { LifetimeTracked::use_(&guard) }); + (unsafe { LifetimeTracked::use_(&raw const guard) }); assert!(((guard.uses) == (1))); assert!(((choice) == (0))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); @@ -86,7 +86,7 @@ pub unsafe fn test_6() { let mut choice: i32 = 4; if (choice != 0) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); - (unsafe { LifetimeTracked::use_(&guard) }); + (unsafe { LifetimeTracked::use_(&raw const guard) }); assert!(((guard.uses) == (1))); assert!(((choice) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); 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 1b4268c052..e8d742890a 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 @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -81,12 +81,12 @@ pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { pub value: i32, } impl p2_condition_variable_lives_for_whole_statement_ConvertsToInt { - pub unsafe fn to_i32(&self) -> i32 { - return self.value; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).value; } } impl DestructibleUnsafe for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); } } @@ -95,12 +95,14 @@ pub unsafe fn test_7() { let mut selector: p2_condition_variable_lives_for_whole_statement_ConvertsToInt = p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }; let _dtor_selector = std::mem::DropGuard::new(&raw mut selector, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); 'switch: { match { (unsafe { - p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32(&selector) + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const selector, + ) }) } { __v if __v == 2 => { @@ -137,7 +139,7 @@ pub unsafe fn test_10() { __v if __v == 2 => { (*std::cell::LazyCell::force_mut(&mut *&raw mut matching_case_runs_8)) .prefix_inc(); - (unsafe { LifetimeTracked::use_(&guard) }); + (unsafe { LifetimeTracked::use_(&raw const guard) }); assert!(((guard.uses) == (1))); assert!(((selector) == (2))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); diff --git a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs index 2e58366380..010980f4d9 100644 --- a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs @@ -12,9 +12,14 @@ pub struct p2_reference_does_not_instantiate_Member { #[offset(0)] pub value: i32, } +impl p2_reference_does_not_instantiate_Member { + pub fn construct_1(this: Ptr, _a0: Ptr) { + field!(this, value).write(2); + } +} impl DefaultConstructible for p2_reference_does_not_instantiate_Member { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(1); + fn default_constructor(this: Ptr) { + field!(this, value).write(1); } } impl Default for p2_reference_does_not_instantiate_Member { @@ -31,8 +36,8 @@ pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } impl DefaultConstructible for p2_reference_does_not_instantiate_Holder { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, member)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, member)); } } pub fn test_0() { @@ -52,14 +57,4 @@ fn main_0() -> i32 { #[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] #[byte_size(1)] pub struct p2_reference_does_not_instantiate_Wrapper_int_; -pub trait p2_reference_does_not_instantiate_MemberImpl { - fn construct_1(&self, _a0: Ptr); -} -impl p2_reference_does_not_instantiate_MemberImpl - for Ptr -{ - fn construct_1(&self, _a0: Ptr) { - field!((*self), value).write(2); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs index 03363dd36a..f438666927 100644 --- a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs @@ -13,15 +13,15 @@ pub struct p2_reference_does_not_instantiate_Member { } impl p2_reference_does_not_instantiate_Member { pub unsafe fn construct_1( - &mut self, + this: *mut Self, _a0: *const p2_reference_does_not_instantiate_Wrapper_int_, ) { - (&raw mut self.value).write(2); + (&raw mut (*this).value).write(2); } } impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Member { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(1); } } impl Default for p2_reference_does_not_instantiate_Member { @@ -36,8 +36,8 @@ pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Holder { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.member); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).member); } } pub unsafe fn test_0() { diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 725b0a0dd3..5d5204134d 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -23,14 +23,19 @@ pub struct p6_forward_like_Movable { #[offset(0)] pub value: i32, } +impl p6_forward_like_Movable { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl CopyConstructible for p6_forward_like_Movable { - fn copy_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn copy_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p6_forward_like_Movable { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -43,8 +48,8 @@ pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } impl DefaultConstructible for p6_forward_like_Holder { - fn default_constructor(this: &Ptr) { - p6_forward_like_MovableImpl::construct(&field_ptr!(this, member), 1); + fn default_constructor(this: Ptr) { + p6_forward_like_Movable::construct(field_ptr!(this, member), 1); } } impl Default for p6_forward_like_Holder { @@ -54,29 +59,29 @@ impl Default for p6_forward_like_Holder { member: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - p6_forward_like_MovableImpl::construct(&__v.as_pointer(), 1); + p6_forward_like_Movable::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, } } } } -pub fn take_1(this: Ptr, self_: Ptr) { - ConstructFrom::construct_from(&this, field_ptr!(self_, member)); +pub fn take_1(__return: Ptr, self_: Ptr) { + ConstructFrom::construct_from(__return.clone(), field_ptr!(self_, member)); return; } -pub fn take_2(this: Ptr, self_: Ptr) { - ConstructFrom::construct_from(&this, Moved(field_ptr!(self_, member))); +pub fn take_2(__return: Ptr, self_: Ptr) { + ConstructFrom::construct_from(__return.clone(), Moved(field_ptr!(self_, member))); return; } pub fn test_3() { object!(holder, p6_forward_like_Holder); object!(copied, p6_forward_like_Movable, |copied| ({ - take_1(Ptr::clone(copied), holder.as_pointer()) + take_1(Ptr::clone(&copied.clone()), holder.as_pointer()) })); assert!(({ (*copied.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 1)); object!(moved, p6_forward_like_Movable, |moved| ({ - take_2(Ptr::clone(moved), holder.as_pointer()) + take_2(Ptr::clone(&moved.clone()), holder.as_pointer()) })); assert!(({ (*moved.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 0)); } @@ -89,9 +94,14 @@ pub struct p9_move_Movable { #[offset(0)] pub value: i32, } +impl p9_move_Movable { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl MoveConstructible for p9_move_Movable { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -139,18 +149,25 @@ pub struct p10_forward_in_template_A { #[offset(8)] pub moves: i32, } +impl p10_forward_in_template_A { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for p10_forward_in_template_A { - fn copy_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); - field!((*this), copies).write((other.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(0); + fn copy_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); + field!(this, copies).write((other.with(|__s| __s.copies) + 1)); + field!(this, moves).write(0); } } impl MoveConstructible for p10_forward_in_template_A { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); - field!((*this), copies).write(0); - field!((*this), moves).write((other.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); + field!(this, copies).write(0); + field!(this, moves).write((other.with(|__s| __s.moves) + 1)); field!(other, value).write(0); } } @@ -159,18 +176,18 @@ impl Default for p10_forward_in_template_A { { ::zero_init() } } } -pub fn make_5(this: Ptr, source: Ptr) { - ConstructFrom::construct_from(&this, (source).clone()); +pub fn make_5(__return: Ptr, source: Ptr) { + ConstructFrom::construct_from(__return.clone(), (source).clone()); return; } -pub fn make_6(this: Ptr, source: Ptr) { - ConstructFrom::construct_from(&this, Moved((source).clone())); +pub fn make_6(__return: Ptr, source: Ptr) { + ConstructFrom::construct_from(__return.clone(), Moved((source).clone())); return; } pub fn test_7() { object!(a, p10_forward_in_template_A(1)); object!(copied, p10_forward_in_template_A, |copied| ({ - make_5(Ptr::clone(copied), a.as_pointer()) + make_5(Ptr::clone(&copied.clone()), a.as_pointer()) })); assert!( (({ (*copied.borrow()).value } == 1) && ({ (*copied.borrow()).copies } == 1)) @@ -178,7 +195,7 @@ pub fn test_7() { ); assert!(({ (*a.borrow()).value } == 1)); object!(moved, p10_forward_in_template_A, |moved| ({ - make_6(Ptr::clone(moved), a.as_pointer()) + make_6(Ptr::clone(&moved.clone()), a.as_pointer()) })); assert!( (({ (*moved.borrow()).value } == 1) && ({ (*moved.borrow()).copies } == 0)) @@ -195,14 +212,19 @@ pub struct p11_move_if_noexcept_NoexceptMove { #[offset(0)] pub value: i32, } +impl p11_move_if_noexcept_NoexceptMove { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl CopyConstructible for p11_move_if_noexcept_NoexceptMove { - fn copy_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn copy_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p11_move_if_noexcept_NoexceptMove { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -215,14 +237,19 @@ pub struct p11_move_if_noexcept_ThrowingMove { #[offset(0)] pub value: i32, } +impl p11_move_if_noexcept_ThrowingMove { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl CopyConstructible for p11_move_if_noexcept_ThrowingMove { - fn copy_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn copy_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p11_move_if_noexcept_ThrowingMove { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -254,46 +281,4 @@ fn main_0() -> i32 { ({ test_8() }); return 0; } -pub trait p10_forward_in_template_AImpl { - fn construct(&self, value: i32); -} -impl p10_forward_in_template_AImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} -pub trait p11_move_if_noexcept_NoexceptMoveImpl { - fn construct(&self, value: i32); -} -impl p11_move_if_noexcept_NoexceptMoveImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} -pub trait p11_move_if_noexcept_ThrowingMoveImpl { - fn construct(&self, value: i32); -} -impl p11_move_if_noexcept_ThrowingMoveImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} -pub trait p6_forward_like_MovableImpl { - fn construct(&self, value: i32); -} -impl p6_forward_like_MovableImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} -pub trait p9_move_MovableImpl { - fn construct(&self, value: i32); -} -impl p9_move_MovableImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index 9c74c2ab38..e38d344304 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -66,9 +66,14 @@ pub struct p10_move_constructor_A { #[offset(0)] pub value: i32, } +impl p10_move_constructor_A { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl MoveConstructible for p10_move_constructor_A { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -93,12 +98,4 @@ fn main_0() -> i32 { ({ test_2() }); return 0; } -pub trait p10_move_constructor_AImpl { - fn construct(&self, value: i32); -} -impl p10_move_constructor_AImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/utility/out/refcount/utility.as.const.rs b/tests/std/utilities/utility/out/refcount/utility.as.const.rs index a5a0bb1817..d2081106fc 100644 --- a/tests/std/utilities/utility/out/refcount/utility.as.const.rs +++ b/tests/std/utilities/utility/out/refcount/utility.as.const.rs @@ -23,6 +23,14 @@ pub struct p1_as_const_Counter { #[offset(0)] pub value: i32, } +impl p1_as_const_Counter { + pub fn get_1(this: Ptr) -> i32 { + return (this.with(|__s| __s.value) + 1); + } + pub fn get_2(this: Ptr) -> i32 { + return this.with(|__s| __s.value); + } +} pub fn test_0() { let number: Value = Rc::new(RefCell::new(3)); let ref_: Ptr = number.as_pointer(); @@ -34,8 +42,8 @@ pub fn test_0() { assert!(({ (pointer).clone() } == { (number.as_pointer()) })); let counter: Value = Rc::new(RefCell::new(p1_as_const_Counter { value: 5 })); - assert!((({ p1_as_const_CounterImpl::get_2(&counter.as_pointer(),) }) == 5)); - assert!((({ p1_as_const_CounterImpl::get_1(&counter.as_pointer(),) }) == 6)); + assert!((({ p1_as_const_Counter::get_2(counter.as_pointer(),) }) == 5)); + assert!((({ p1_as_const_Counter::get_1(counter.as_pointer(),) }) == 6)); } pub fn main() { __cpp2rust_init_globals(); @@ -45,16 +53,4 @@ fn main_0() -> i32 { ({ test_0() }); return 0; } -pub trait p1_as_const_CounterImpl { - fn get_1(&self) -> i32; - fn get_2(&self) -> i32; -} -impl p1_as_const_CounterImpl for Ptr { - fn get_1(&self) -> i32 { - return ((*self).with(|__s| __s.value) + 1); - } - fn get_2(&self) -> i32 { - return (*self).with(|__s| __s.value); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index f4d8e19b1d..c670d40b34 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -23,18 +23,18 @@ pub struct p6_forward_like_Movable { pub value: i32, } impl p6_forward_like_Movable { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl CopyConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn copy_constructor(&mut self, other: *const p6_forward_like_Movable) { - (&raw mut self.value).write((*other).value); + unsafe fn copy_constructor(this: *mut Self, other: *const p6_forward_like_Movable) { + (&raw mut (*this).value).write((*other).value); } } impl MoveConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn move_constructor(&mut self, other: *mut p6_forward_like_Movable) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *mut p6_forward_like_Movable) { + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } @@ -45,8 +45,8 @@ pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } impl DefaultConstructibleUnsafe for p6_forward_like_Holder { - unsafe fn default_constructor(&mut self) { - p6_forward_like_Movable::construct(&mut self.member, 1); + unsafe fn default_constructor(this: *mut Self) { + p6_forward_like_Movable::construct(&raw mut (*this).member, 1); } } impl Default for p6_forward_like_Holder { @@ -55,19 +55,19 @@ impl Default for p6_forward_like_Holder { p6_forward_like_Holder { member: { let mut __v: p6_forward_like_Movable = ::zero_init(); - p6_forward_like_Movable::construct(&mut __v, 1); + p6_forward_like_Movable::construct(&raw mut __v, 1); __v }, } } } } -pub unsafe fn take_1(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - ConstructFromUnsafe::construct_from(&mut *this, &(*self_).member); +pub unsafe fn take_1(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { + ConstructFromUnsafe::construct_from(__return, &(*self_).member); return; } -pub unsafe fn take_2(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut (*self_).member)); +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)); return; } pub unsafe fn test_3() { @@ -90,13 +90,13 @@ pub struct p9_move_Movable { pub value: i32, } impl p9_move_Movable { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl MoveConstructibleUnsafe for p9_move_Movable { - unsafe fn move_constructor(&mut self, other: *mut p9_move_Movable) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *mut p9_move_Movable) { + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } @@ -139,24 +139,24 @@ pub struct p10_forward_in_template_A { pub moves: i32, } impl p10_forward_in_template_A { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn copy_constructor(&mut self, other: *const p10_forward_in_template_A) { - (&raw mut self.value).write((*other).value); - (&raw mut self.copies).write((((*other).copies) + (1))); - (&raw mut self.moves).write(0); + unsafe fn copy_constructor(this: *mut Self, other: *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(&mut self, other: *mut p10_forward_in_template_A) { - (&raw mut self.value).write((*other).value); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write((((*other).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, other: *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))); (*other).value = 0; } } @@ -165,12 +165,18 @@ impl Default for p10_forward_in_template_A { unsafe { ::zero_init() } } } -pub unsafe fn make_5(this: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A) { - ConstructFromUnsafe::construct_from(&mut *this, source); +pub unsafe fn make_5( + __return: *mut p10_forward_in_template_A, + source: *mut p10_forward_in_template_A, +) { + ConstructFromUnsafe::construct_from(__return, source); return; } -pub unsafe fn make_6(this: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A) { - ConstructFromUnsafe::construct_from(&mut *this, Moved(source)); +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)); return; } pub unsafe fn test_7() { @@ -195,18 +201,18 @@ pub struct p11_move_if_noexcept_NoexceptMove { pub value: i32, } impl p11_move_if_noexcept_NoexceptMove { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl CopyConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { - unsafe fn copy_constructor(&mut self, other: *const p11_move_if_noexcept_NoexceptMove) { - (&raw mut self.value).write((*other).value); + unsafe fn copy_constructor(this: *mut Self, other: *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(&mut self, other: *mut p11_move_if_noexcept_NoexceptMove) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *mut p11_move_if_noexcept_NoexceptMove) { + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } @@ -219,18 +225,18 @@ pub struct p11_move_if_noexcept_ThrowingMove { pub value: i32, } impl p11_move_if_noexcept_ThrowingMove { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl CopyConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { - unsafe fn copy_constructor(&mut self, other: *const p11_move_if_noexcept_ThrowingMove) { - (&raw mut self.value).write((*other).value); + unsafe fn copy_constructor(this: *mut Self, other: *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(&mut self, other: *mut p11_move_if_noexcept_ThrowingMove) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *mut p11_move_if_noexcept_ThrowingMove) { + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index 41d519b89c..e9ed628da7 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -56,13 +56,13 @@ pub struct p10_move_constructor_A { pub value: i32, } impl p10_move_constructor_A { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl MoveConstructibleUnsafe for p10_move_constructor_A { - unsafe fn move_constructor(&mut self, other: *mut p10_move_constructor_A) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *mut p10_move_constructor_A) { + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } diff --git a/tests/std/utilities/utility/out/unsafe/utility.as.const.rs b/tests/std/utilities/utility/out/unsafe/utility.as.const.rs index 9e25c6649a..3968b3170c 100644 --- a/tests/std/utilities/utility/out/unsafe/utility.as.const.rs +++ b/tests/std/utilities/utility/out/unsafe/utility.as.const.rs @@ -21,11 +21,11 @@ pub struct p1_as_const_Counter { pub value: i32, } impl p1_as_const_Counter { - pub unsafe fn get_1(&mut self) -> i32 { - return ((self.value) + (1)); + pub unsafe fn get_1(this: *mut Self) -> i32 { + return (((*this).value) + (1)); } - pub unsafe fn get_2(&self) -> i32 { - return self.value; + pub unsafe fn get_2(this: *const Self) -> i32 { + return (*this).value; } } pub unsafe fn test_0() { @@ -38,8 +38,8 @@ pub unsafe fn test_0() { let mut pointer: *mut i32 = (&mut number as *mut i32); assert!(((pointer) == (&mut number as *mut i32))); let mut counter: p1_as_const_Counter = p1_as_const_Counter { value: 5 }; - assert!(((unsafe { p1_as_const_Counter::get_2(&counter,) }) == (5))); - assert!(((unsafe { p1_as_const_Counter::get_1(&mut counter,) }) == (6))); + assert!(((unsafe { p1_as_const_Counter::get_2(&raw const counter,) }) == (5))); + assert!(((unsafe { p1_as_const_Counter::get_1(&raw mut counter,) }) == (6))); } pub fn main() { unsafe { diff --git a/tests/ub/out/refcount/ctor_ref_member.rs b/tests/ub/out/refcount/ctor_ref_member.rs index 2e50bec5e7..bdf13b0f8f 100644 --- a/tests/ub/out/refcount/ctor_ref_member.rs +++ b/tests/ub/out/refcount/ctor_ref_member.rs @@ -25,6 +25,11 @@ pub struct S { #[byte_size(8)] pub r: Ptr, } +impl S { + pub fn construct(this: Ptr, x: Ptr) { + field!(this, r).write((x).clone()); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -32,17 +37,9 @@ pub fn main() { fn main_0() -> i32 { object!(s, S, |s| { let __tmp_0: Value = Rc::new(RefCell::new(5)); - SImpl::construct(s, __tmp_0.as_pointer()) + S::construct(s.clone(), __tmp_0.as_pointer()) }); assert!((({ (*s.borrow()).r.clone() }.read()) == 5)); return 0; } -pub trait SImpl { - fn construct(&self, x: Ptr); -} -impl SImpl for Ptr { - fn construct(&self, x: Ptr) { - field!((*self), r).write((x).clone()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/ub/out/refcount/max.rs b/tests/ub/out/refcount/max.rs index eca57caaf2..3cc11db765 100644 --- a/tests/ub/out/refcount/max.rs +++ b/tests/ub/out/refcount/max.rs @@ -14,7 +14,7 @@ fn main_0() -> i32 { let a: Ptr = ({ let __tmp_0: Value = Rc::new(RefCell::new(2)); let __tmp_1: Value = Rc::new(RefCell::new(1)); - if CppLess::less(&__tmp_0.as_pointer(), &__tmp_1.as_pointer()) { + if CppLess::less(__tmp_0.as_pointer().clone(), __tmp_1.as_pointer().clone()) { __tmp_0.as_pointer() } else { __tmp_1.as_pointer() @@ -23,7 +23,7 @@ fn main_0() -> i32 { let b: Ptr = ({ let __tmp_2: Value = Rc::new(RefCell::new(1)); let __tmp_3: Value = Rc::new(RefCell::new(2)); - if CppLess::less(&__tmp_2.as_pointer(), &__tmp_3.as_pointer()) { + if CppLess::less(__tmp_2.as_pointer().clone(), __tmp_3.as_pointer().clone()) { __tmp_3.as_pointer() } else { __tmp_2.as_pointer() diff --git a/tests/ub/out/unsafe/ctor_ref_member.rs b/tests/ub/out/unsafe/ctor_ref_member.rs index 3c1669bbb0..df6ec800d2 100644 --- a/tests/ub/out/unsafe/ctor_ref_member.rs +++ b/tests/ub/out/unsafe/ctor_ref_member.rs @@ -23,8 +23,8 @@ pub struct S { pub r: *const i32, } impl S { - pub unsafe fn construct(&mut self, x: *const i32) { - (&raw mut self.r).write(x); + pub unsafe fn construct(this: *mut Self, x: *const i32) { + (&raw mut (*this).r).write(x); } } pub fn main() { diff --git a/tests/unit/out/refcount/05_new.rs b/tests/unit/out/refcount/05_new.rs index e97d3bef1c..9f515fbe1b 100644 --- a/tests/unit/out/refcount/05_new.rs +++ b/tests/unit/out/refcount/05_new.rs @@ -34,6 +34,11 @@ pub struct A {} )] #[byte_size(1)] pub struct D {} +impl D { + pub fn operator_call(this: Ptr, mut ptr: Ptr) { + ptr.delete(); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -44,18 +49,10 @@ fn main_0() -> i32 { d.delete(); let mut c: Ptr = Ptr::alloc(3); c.delete(); - DImpl::operator_call( - &Rc::new(RefCell::new(::default())).as_pointer(), + D::operator_call( + Rc::new(RefCell::new(::default())).as_pointer(), Ptr::alloc(::default()), ); return 0; } -pub trait DImpl { - fn operator_call(&self, ptr: Ptr); -} -impl DImpl for Ptr { - fn operator_call(&self, mut ptr: Ptr) { - ptr.delete(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index d46dea05b5..4970fbf2f9 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.rs @@ -44,6 +44,18 @@ pub struct Graph { #[byte_size(8)] pub adj: Ptr>, } +impl Graph { + pub fn push(this: Ptr, mut src: u32, mut dst: u32) { + elem!(this.with(|__s| __s.adj.clone()), src).write(Ptr::alloc(GraphNode { + dst: dst, + next: (elem!(this.with(|__s| __s.adj.clone()), src).read()), + })); + elem!(this.with(|__s| __s.adj.clone()), dst).write(Ptr::alloc(GraphNode { + dst: src, + next: (elem!(this.with(|__s| __s.adj.clone()), dst).read()), + })); + } +} #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] #[byte_size(8)] pub struct Partial { @@ -51,9 +63,14 @@ pub struct Partial { #[byte_size(8)] pub p: Ptr, } +impl Partial { + pub fn construct_1(this: Ptr, mut q: Ptr) { + field!(this, p).write((q).clone()); + } +} impl DefaultConstructible for Partial { - fn default_constructor(this: &Ptr) { - field!((*this), p).write(Ptr::::null()); + fn default_constructor(this: Ptr) { + field!(this, p).write(Ptr::::null()); } } impl Default for Partial { @@ -79,6 +96,7 @@ impl Default for Partial { )] #[byte_size(1)] pub struct Declared {} +impl Declared {} #[derive( Clone, Record, @@ -125,42 +143,4 @@ fn main_0() -> i32 { } return 0; } -pub trait DeclaredImpl { - fn construct(&self, mut _a0: i32) { - unimplemented!() - } -} -impl DeclaredImpl for Ptr {} -pub trait GraphImpl { - fn push(&self, src: u32, dst: u32); -} -impl GraphImpl for Ptr { - fn push(&self, mut src: u32, mut dst: u32) { - elem!((*self).with(|__s| __s.adj.clone()), src).write(Ptr::alloc(GraphNode { - dst: dst, - next: (elem!((*self).with(|__s| __s.adj.clone()), src).read()), - })); - elem!((*self).with(|__s| __s.adj.clone()), dst).write(Ptr::alloc(GraphNode { - dst: src, - next: (elem!((*self).with(|__s| __s.adj.clone()), dst).read()), - })); - } -} -pub trait PartialImpl { - fn construct_1(&self, q: Ptr); - fn get(&self) -> Ptr { - unimplemented!() - } - fn next_4(&self) -> Ptr { - unimplemented!() - } - fn next_5(&self, mut _a0: i32) -> Partial { - unimplemented!() - } -} -impl PartialImpl for Ptr { - fn construct_1(&self, mut q: Ptr) { - field!((*self), p).write((q).clone()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/any.rs b/tests/unit/out/refcount/any.rs index 466060af08..a7d9a13ee8 100644 --- a/tests/unit/out/refcount/any.rs +++ b/tests/unit/out/refcount/any.rs @@ -25,6 +25,12 @@ pub struct Point { #[offset(4)] pub y: i32, } +impl Point { + pub fn construct(this: Ptr, mut x: i32, mut y: i32) { + field!(this, x).write(x); + field!(this, y).write(y); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -33,7 +39,7 @@ fn main_0() -> i32 { let a: Value>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct(&__v.as_pointer(), 3, 4); + Point::construct(__v.as_pointer(), 3, 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); assert!(({ (*a.borrow()).is_some() })); @@ -73,7 +79,7 @@ fn main_0() -> i32 { let mut __tmp_2 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct(&__v.as_pointer(), 5, 6); + Point::construct(__v.as_pointer(), 5, 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -153,13 +159,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait PointImpl { - fn construct(&self, x: i32, y: i32); -} -impl PointImpl for Ptr { - fn construct(&self, mut x: i32, mut y: i32) { - field!((*self), x).write(x); - field!((*self), y).write(y); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index 00a96f3d1d..a55ac2883a 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -28,9 +28,9 @@ pub struct NonCopy { pub tag: i32, } impl DefaultConstructible for NonCopy { - fn default_constructor(this: &Ptr) { - field!((*this), data).write(Vec::new()); - field!((*this), tag).write(0); + fn default_constructor(this: Ptr) { + field!(this, data).write(Vec::new()); + field!(this, tag).write(0); } } impl Default for NonCopy { @@ -51,7 +51,7 @@ fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 3, _>(|_| { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); diff --git a/tests/unit/out/refcount/as_const.rs b/tests/unit/out/refcount/as_const.rs index cdddf6c9c4..d5a2db82e3 100644 --- a/tests/unit/out/refcount/as_const.rs +++ b/tests/unit/out/refcount/as_const.rs @@ -26,6 +26,20 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn f_1(this: Ptr) -> Overload { + return Overload_kMutableOverload; + } + pub fn f_2(this: Ptr) -> Overload { + return Overload_kConstOverload; + } + pub fn value_ref_3(this: Ptr) -> Ptr { + return field_ptr!(this, v); + } + pub fn value_ref_4(this: Ptr) -> Ptr { + return field_ptr!(this, v); + } +} pub fn g_0(_a0: Ptr) -> Overload { return Overload_kMutableOverload; } @@ -38,40 +52,20 @@ pub fn main() { } fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 7 })); - assert!(((({ SImpl::f_1(&s.as_pointer(),) }) as i32) == (Overload_kMutableOverload as i32))); - assert!(((({ SImpl::f_2(&s.as_pointer(),) }) as i32) == (Overload_kConstOverload as i32))); + assert!(((({ S::f_1(s.as_pointer(),) }) as i32) == (Overload_kMutableOverload as i32))); + assert!(((({ S::f_2(s.as_pointer(),) }) as i32) == (Overload_kConstOverload as i32))); assert!(((({ g_0(s.as_pointer(),) }) as i32) == (Overload_kMutableOverload as i32))); assert!(((({ g_1(s.as_pointer(),) }) as i32) == (Overload_kConstOverload as i32))); - ({ SImpl::value_ref_3(&s.as_pointer()) }).write(9); + ({ S::value_ref_3(s.as_pointer()) }).write(9); assert!(({ (*s.borrow()).v } == 9)); - assert!(((({ SImpl::value_ref_4(&s.as_pointer(),) }).read()) == 9)); + assert!(((({ S::value_ref_4(s.as_pointer(),) }).read()) == 9)); let cs: Ptr = s.as_pointer(); - assert!(((({ SImpl::f_2(&cs,) }) as i32) == (Overload_kConstOverload as i32))); + assert!(((({ S::f_2((cs).clone(),) }) as i32) == (Overload_kConstOverload as i32))); assert!((cs.with(|__s| __s.v) == 9)); let mut p: Ptr = (s.as_pointer()); field!(p, v).write(11); assert!(({ (*s.borrow()).v } == 11)); - assert!(((({ SImpl::f_1(&p,) }) as i32) == (Overload_kMutableOverload as i32))); + assert!(((({ S::f_1((p).clone(),) }) as i32) == (Overload_kMutableOverload as i32))); return 0; } -pub trait SImpl { - fn f_1(&self) -> Overload; - fn f_2(&self) -> Overload; - fn value_ref_3(&self) -> Ptr; - fn value_ref_4(&self) -> Ptr; -} -impl SImpl for Ptr { - fn f_1(&self) -> Overload { - return Overload_kMutableOverload; - } - fn f_2(&self) -> Overload { - return Overload_kConstOverload; - } - fn value_ref_3(&self) -> Ptr { - return field_ptr!((*self), v); - } - fn value_ref_4(&self) -> Ptr { - return field_ptr!((*self), v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index e5b2bcdcc9..b70578b8ec 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -1498,13 +1498,23 @@ thread_local!( )] #[byte_size(1)] pub struct IndexedBinding {} +impl IndexedBinding { + pub fn get_1_0(this: Ptr) -> Ptr { + return selected_values_34.with(|v| v.decay()).offset( + ({ + let __idx0 = (0) as usize; + selected_values_34.with(|rc| rc.borrow()[__idx0]) + }), + ); + } +} pub fn test_binding_35() { let owner: Value = Rc::new(RefCell::new(::default())); let __decomp_36: Ptr = owner.as_pointer(); - let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_36) }); + let value: Ptr = ({ IndexedBinding::get_1_0((__decomp_36).clone()) }); let mut result: u32 = ({ match ({ 1_u32 }, { - ({ IndexedBindingImpl::get_1_0(&__decomp_36) }) + ({ IndexedBinding::get_1_0((__decomp_36).clone()) }) }) { (__tmp_97, __tmp_98) => __tmp_98.with_mut(|__tmp_98| { (*__tmp_98) = (*__tmp_98).wrapping_add(__tmp_97); @@ -2362,8 +2372,8 @@ pub struct Counts_59 { pub counts: Vec, } impl DefaultConstructible for Counts_59 { - fn default_constructor(this: &Ptr) { - field!((*this), counts).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, counts).write(Vec::new()); } } #[derive( @@ -2734,19 +2744,6 @@ impl Default for Owner_63 { } } } -pub trait IndexedBindingImpl { - fn get_1_0(&self) -> Ptr; -} -impl IndexedBindingImpl for Ptr { - fn get_1_0(&self) -> Ptr { - return selected_values_34.with(|v| v.decay()).offset( - ({ - let __idx0 = (0) as usize; - selected_values_34.with(|rc| rc.borrow()[__idx0]) - }), - ); - } -} pub fn __cpp2rust_init_globals() { let _ = global_22.with(|_| ()); let _ = global_record_25.with(|_| ()); diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index 8d9c103416..8749aed227 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -106,9 +106,9 @@ pub struct Bag { pub items: Vec, } impl DefaultConstructible for Bag { - fn default_constructor(this: &Ptr) { - field!((*this), n).write(0_i32); - field!((*this), items).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, n).write(0_i32); + field!(this, items).write(Vec::new()); } } pub fn adjacent_arrays_0() { diff --git a/tests/unit/out/refcount/class.rs b/tests/unit/out/refcount/class.rs index 6f965ac019..b74e57284a 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -25,6 +25,29 @@ pub struct Pair { #[offset(4)] pub second: i32, } +impl Pair { + pub fn NOP(this: Ptr) {} + pub fn GetFirst(this: Ptr) -> i32 { + return this.with(|__s| __s.first); + } + pub fn GetSecond(this: Ptr) -> i32 { + return this.with(|__s| __s.second); + } + pub fn Set(this: Ptr, field: Ptr, mut new_val: i32) -> i32 { + ({ Pair::NOP(this.clone()) }); + let mut old_val: i32 = (field.read()); + field.write(new_val); + return old_val; + } + pub fn SetFirst(this: Ptr, mut new_first: i32) -> i32 { + return (({ Pair::GetFirst(this.clone()) }) + + ({ Pair::Set(this.clone(), field_ptr!(this, first), new_first) })); + } + pub fn SetSecond(this: Ptr, mut new_second: i32) -> i32 { + return (({ Pair::GetSecond(this.clone()) }) + + ({ Pair::Set(this.clone(), field_ptr!(this, second), new_second) })); + } +} #[derive( Copy, Clone, @@ -45,6 +68,13 @@ pub struct Route { #[offset(8)] pub cost: f64, } +impl Route { + pub fn SetCost(this: Ptr, mut new_cost: f64) -> f64 { + let mut old_cost: f64 = this.with(|__s| __s.cost); + field!(this, cost).write(new_cost); + return old_cost; + } +} #[derive( Copy, Clone, @@ -64,9 +94,23 @@ pub struct Counter { #[offset(4)] pub calls: i32, } +impl Counter { + pub fn Get(this: Ptr) -> i32 { + field!(this, calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return this.with(|__s| __s.v); + } + pub fn operator_eq(this: Ptr, o: Ptr) -> bool { + field!(this, calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} impl CppEq for Counter { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - CounterImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Counter::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -86,19 +130,33 @@ pub struct Tally { #[offset(0)] pub calls: i32, } +impl Tally { + pub fn SameNameBetweenConstAndNonConst_1(this: Ptr) -> i32 { + { + field!(this, calls).with_mut(|__v| *__v = *__v + 1) + }; + return 1; + } + pub fn SameNameBetweenConstAndNonConst_2(this: Ptr) -> i32 { + { + field!(this, calls).with_mut(|__v| *__v = *__v + 10) + }; + return 2; + } +} pub fn RandomRoute_0(route: Ptr) -> i32 { if ((route.with(|__s| __s.path.first) % 2) != 0) { return ({ - PairImpl::SetFirst( - &field_ptr!(route, path), - ({ PairImpl::SetSecond(&field_ptr!(route, path), 10) }), + Pair::SetFirst( + field_ptr!(route, path), + ({ Pair::SetSecond(field_ptr!(route, path), 10) }), ) }); } else { return ({ - PairImpl::SetSecond( - &field_ptr!(route, path), - ({ PairImpl::SetFirst(&field_ptr!(route, path), -10_i32) }), + Pair::SetSecond( + field_ptr!(route, path), + ({ Pair::SetFirst(field_ptr!(route, path), -10_i32) }), ) }); } @@ -124,9 +182,9 @@ fn main_0() -> i32 { cost: 10_f64, })); let mut old_cost: f64 = ({ - RouteImpl::SetCost( - &route1.as_pointer(), - ({ RouteImpl::SetCost(&route2.as_pointer(), 15_f64) }), + Route::SetCost( + route1.as_pointer(), + ({ Route::SetCost(route2.as_pointer(), 15_f64) }), ) }); assert!( @@ -138,98 +196,21 @@ fn main_0() -> i32 { let c1: Value = Rc::new(RefCell::new(Counter { v: 3, calls: 0 })); let c2: Value = Rc::new(RefCell::new(Counter { v: 3, calls: 0 })); let mut pc: Ptr = (c1.as_pointer()); - assert!((({ CounterImpl::Get(&c1.as_pointer(),) }) == 3)); - assert!((({ CounterImpl::Get(&c2.as_pointer(),) }) == 3)); - assert!((({ CounterImpl::Get(&pc,) }) == 3)); - assert!(({ CounterImpl::operator_eq(&c1.as_pointer(), c2.as_pointer(),) })); - assert!(({ CounterImpl::operator_eq(&c2.as_pointer(), c1.as_pointer(),) })); + assert!((({ Counter::Get(c1.as_pointer(),) }) == 3)); + assert!((({ Counter::Get(c2.as_pointer(),) }) == 3)); + assert!((({ Counter::Get((pc).clone(),) }) == 3)); + assert!(({ Counter::operator_eq(c1.as_pointer(), c2.as_pointer(),) })); + assert!(({ Counter::operator_eq(c2.as_pointer(), c1.as_pointer(),) })); assert!(({ (*c1.borrow()).calls } == 3)); assert!(({ (*c2.borrow()).calls } == 2)); let t: Value = Rc::new(RefCell::new(Tally { calls: 0 })); let ct: Value = Rc::new(RefCell::new(Tally { calls: 0 })); let rt: Ptr = t.as_pointer(); - assert!((({ TallyImpl::SameNameBetweenConstAndNonConst_1(&t.as_pointer(),) }) == 1)); - assert!((({ TallyImpl::SameNameBetweenConstAndNonConst_2(&ct.as_pointer(),) }) == 2)); - assert!((({ TallyImpl::SameNameBetweenConstAndNonConst_2(&rt,) }) == 2)); + assert!((({ Tally::SameNameBetweenConstAndNonConst_1(t.as_pointer(),) }) == 1)); + assert!((({ Tally::SameNameBetweenConstAndNonConst_2(ct.as_pointer(),) }) == 2)); + assert!((({ Tally::SameNameBetweenConstAndNonConst_2((rt).clone(),) }) == 2)); assert!(({ (*t.borrow()).calls } == 11)); assert!(({ (*ct.borrow()).calls } == 10)); return 0; } -pub trait CounterImpl { - fn Get(&self) -> i32; - fn operator_eq(&self, o: Ptr) -> bool; -} -impl CounterImpl for Ptr { - fn Get(&self) -> i32 { - field!((*self), calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return (*self).with(|__s| __s.v); - } - fn operator_eq(&self, o: Ptr) -> bool { - field!((*self), calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} -pub trait PairImpl { - fn NOP(&self); - fn GetFirst(&self) -> i32; - fn GetSecond(&self) -> i32; - fn Set(&self, field: Ptr, new_val: i32) -> i32; - fn SetFirst(&self, new_first: i32) -> i32; - fn SetSecond(&self, new_second: i32) -> i32; -} -impl PairImpl for Ptr { - fn NOP(&self) {} - fn GetFirst(&self) -> i32 { - return (*self).with(|__s| __s.first); - } - fn GetSecond(&self) -> i32 { - return (*self).with(|__s| __s.second); - } - fn Set(&self, field: Ptr, mut new_val: i32) -> i32 { - ({ PairImpl::NOP(self) }); - let mut old_val: i32 = (field.read()); - field.write(new_val); - return old_val; - } - fn SetFirst(&self, mut new_first: i32) -> i32 { - return (({ PairImpl::GetFirst(self) }) - + ({ PairImpl::Set(self, field_ptr!((*self), first), new_first) })); - } - fn SetSecond(&self, mut new_second: i32) -> i32 { - return (({ PairImpl::GetSecond(self) }) - + ({ PairImpl::Set(self, field_ptr!((*self), second), new_second) })); - } -} -pub trait RouteImpl { - fn SetCost(&self, new_cost: f64) -> f64; -} -impl RouteImpl for Ptr { - fn SetCost(&self, mut new_cost: f64) -> f64 { - let mut old_cost: f64 = (*self).with(|__s| __s.cost); - field!((*self), cost).write(new_cost); - return old_cost; - } -} -pub trait TallyImpl { - fn SameNameBetweenConstAndNonConst_1(&self) -> i32; - fn SameNameBetweenConstAndNonConst_2(&self) -> i32; -} -impl TallyImpl for Ptr { - fn SameNameBetweenConstAndNonConst_1(&self) -> i32 { - { - field!((*self), calls).with_mut(|__v| *__v = *__v + 1) - }; - return 1; - } - fn SameNameBetweenConstAndNonConst_2(&self) -> i32 { - { - field!((*self), calls).with_mut(|__v| *__v = *__v + 10) - }; - return 2; - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/class_template_lazy_member.rs b/tests/unit/out/refcount/class_template_lazy_member.rs index 59afd97391..ebd24b3d08 100644 --- a/tests/unit/out/refcount/class_template_lazy_member.rs +++ b/tests/unit/out/refcount/class_template_lazy_member.rs @@ -40,6 +40,11 @@ pub struct Box_int_ { #[offset(0)] pub val: i32, } +impl Box_int_ { + pub fn twice(this: Ptr) -> i32 { + return (this.with(|__s| __s.val) + this.with(|__s| __s.val)); + } +} #[derive( Copy, Clone, @@ -58,6 +63,11 @@ pub struct Box_Point_ { #[byte_size(4)] pub val: Point, } +impl Box_Point_ { + pub fn get(this: Ptr) -> Point { + return this.with(|__s| __s.val); + } +} #[derive( Copy, Clone, @@ -75,6 +85,11 @@ pub struct Deduced_int_ { #[offset(0)] pub val: i32, } +impl Deduced_int_ { + pub fn twice(this: Ptr) -> i32 { + return (this.with(|__s| __s.val) + this.with(|__s| __s.val)); + } +} #[derive( Copy, Clone, @@ -93,61 +108,28 @@ pub struct Deduced_Point_ { #[byte_size(4)] pub val: Point, } +impl Deduced_Point_ { + pub fn get(this: Ptr) -> Point { + return this.with(|__s| __s.val); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { let i: Value = Rc::new(RefCell::new(Box_int_ { val: 3 })); - assert!((({ Box_int_Impl::twice(&i.as_pointer(),) }) == 6)); + assert!((({ Box_int_::twice(i.as_pointer(),) }) == 6)); let p: Value = Rc::new(RefCell::new(Box_Point_ { val: Point { x: 4 }, })); - assert!(({ ({ Box_Point_Impl::get(&p.as_pointer(),) }).x } == 4)); + assert!(({ ({ Box_Point_::get(p.as_pointer(),) }).x } == 4)); let d: Value = Rc::new(RefCell::new(Deduced_int_ { val: 5 })); - assert!((({ Deduced_int_Impl::twice(&d.as_pointer(),) }) == 10)); + assert!((({ Deduced_int_::twice(d.as_pointer(),) }) == 10)); let dp: Value = Rc::new(RefCell::new(Deduced_Point_ { val: Point { x: 6 }, })); - assert!(({ ({ Deduced_Point_Impl::get(&dp.as_pointer(),) }).x } == 6)); + assert!(({ ({ Deduced_Point_::get(dp.as_pointer(),) }).x } == 6)); return 0; } -pub trait Box_Point_Impl { - fn get(&self) -> Point; - fn twice(&self) -> Point { - unimplemented!() - } -} -impl Box_Point_Impl for Ptr { - fn get(&self) -> Point { - return (*self).with(|__s| __s.val); - } -} -pub trait Box_int_Impl { - fn get(&self) -> i32 { - unimplemented!() - } - fn twice(&self) -> i32; -} -impl Box_int_Impl for Ptr { - fn twice(&self) -> i32 { - return ((*self).with(|__s| __s.val) + (*self).with(|__s| __s.val)); - } -} -pub trait Deduced_Point_Impl { - fn get(&self) -> Point; -} -impl Deduced_Point_Impl for Ptr { - fn get(&self) -> Point { - return (*self).with(|__s| __s.val); - } -} -pub trait Deduced_int_Impl { - fn twice(&self) -> i32; -} -impl Deduced_int_Impl for Ptr { - fn twice(&self) -> i32 { - return ((*self).with(|__s| __s.val) + (*self).with(|__s| __s.val)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index f106590fc7..8eee2dcecd 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -26,9 +26,30 @@ pub struct MyContainer_int_ { #[byte_size(24)] vec_: Vec, } +impl MyContainer_int_ { + pub fn empty(this: Ptr) -> bool { + return (*this.upgrade().deref()).vec_.is_empty(); + } + pub fn size(this: Ptr) -> usize { + return (*this.upgrade().deref()).vec_.len(); + } + pub fn back_4(this: Ptr) -> Ptr { + return { + let __n = (*this.upgrade().deref()).vec_.len() - 1; + field_ref!(this, vec_).decay().offset((__n) as isize) + }; + } + pub fn pop_back(this: Ptr) { + field!(this, vec_).with_mut(|__v: &mut Vec| __v.pop()); + return; + } + pub fn push_back(this: Ptr, item: Ptr) { + CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); + } +} impl DefaultConstructible for MyContainer_int_ { - fn default_constructor(this: &Ptr) { - field!((*this), vec_).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, vec_).write(Vec::new()); } } #[derive( @@ -51,9 +72,30 @@ pub struct MyContainer_char_ { #[byte_size(24)] vec_: Vec, } +impl MyContainer_char_ { + pub fn empty(this: Ptr) -> bool { + return (*this.upgrade().deref()).vec_.is_empty(); + } + pub fn size(this: Ptr) -> usize { + return (*this.upgrade().deref()).vec_.len(); + } + pub fn back_4(this: Ptr) -> Ptr { + return { + let __n = (*this.upgrade().deref()).vec_.len() - 1; + field_ref!(this, vec_).decay().offset((__n) as isize) + }; + } + pub fn pop_back(this: Ptr) { + field!(this, vec_).with_mut(|__v: &mut Vec| __v.pop()); + return; + } + pub fn push_back(this: Ptr, item: Ptr) { + CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); + } +} impl DefaultConstructible for MyContainer_char_ { - fn default_constructor(this: &Ptr) { - field!((*this), vec_).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, vec_).write(Vec::new()); } } #[derive( @@ -76,9 +118,30 @@ pub struct MyContainer_float_ { #[byte_size(24)] vec_: Vec, } +impl MyContainer_float_ { + pub fn empty(this: Ptr) -> bool { + return (*this.upgrade().deref()).vec_.is_empty(); + } + pub fn size(this: Ptr) -> usize { + return (*this.upgrade().deref()).vec_.len(); + } + pub fn back_4(this: Ptr) -> Ptr { + return { + let __n = (*this.upgrade().deref()).vec_.len() - 1; + field_ref!(this, vec_).decay().offset((__n) as isize) + }; + } + pub fn pop_back(this: Ptr) { + field!(this, vec_).with_mut(|__v: &mut Vec| __v.pop()); + return; + } + pub fn push_back(this: Ptr, item: Ptr) { + CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); + } +} impl DefaultConstructible for MyContainer_float_ { - fn default_constructor(this: &Ptr) { - field!((*this), vec_).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, vec_).write(Vec::new()); } } #[derive( @@ -102,6 +165,9 @@ impl Boxed_short_ { pub fn twice(mut v: i16) -> i16 { return (((v as i32) + (v as i32)) as i16); } + pub fn plus(this: Ptr, mut other: i16) -> i16 { + return (((this.with(|__s| __s.value) as i32) + (other as i32)) as i16); + } } #[derive( Copy, @@ -124,6 +190,9 @@ impl Boxed_int_ { pub fn twice(mut v: i32) -> i32 { return (v + v); } + pub fn plus(this: Ptr, mut other: i32) -> i32 { + return (this.with(|__s| __s.value) + other); + } } #[derive( Copy, @@ -146,6 +215,9 @@ impl Boxed_long_ { pub fn twice(mut v: i64) -> i64 { return (v + v); } + pub fn plus(this: Ptr, mut other: i64) -> i64 { + return (this.with(|__s| __s.value) + other); + } } #[derive( Copy, @@ -166,6 +238,11 @@ pub struct Outer_int__Inner_int_ { #[offset(4)] pub u: i32, } +impl Outer_int__Inner_int_ { + pub fn sum(this: Ptr) -> i32 { + return ((this.with(|__s| __s.t) as i32) + (this.with(|__s| __s.u) as i32)); + } +} #[derive( Copy, Clone, @@ -183,6 +260,14 @@ pub struct Outer_int_ { #[offset(0)] pub v: i32, } +impl Outer_int_ { + pub fn with(this: Ptr, mut n: i32) -> Outer_int__Inner_int_ { + return Outer_int__Inner_int_ { + t: this.with(|__s| __s.v), + u: n, + }; + } +} #[derive( Copy, Clone, @@ -202,6 +287,11 @@ pub struct Outer_long__Inner_int_ { #[offset(8)] pub u: i32, } +impl Outer_long__Inner_int_ { + pub fn sum(this: Ptr) -> i32 { + return ((this.with(|__s| __s.t) as i32) + (this.with(|__s| __s.u) as i32)); + } +} #[derive( Copy, Clone, @@ -221,6 +311,11 @@ pub struct Outer_long__Inner_char_ { #[offset(8)] pub u: i8, } +impl Outer_long__Inner_char_ { + pub fn sum(this: Ptr) -> i32 { + return ((this.with(|__s| __s.t) as i32) + (this.with(|__s| __s.u) as i32)); + } +} #[derive( Copy, Clone, @@ -238,6 +333,14 @@ pub struct Outer_long_ { #[offset(0)] pub v: i64, } +impl Outer_long_ { + pub fn with(this: Ptr, mut n: i32) -> Outer_long__Inner_int_ { + return Outer_long__Inner_int_ { + t: this.with(|__s| __s.v), + u: n, + }; + } +} #[derive( Copy, Clone, @@ -270,11 +373,8 @@ fn main_0() -> i32 { let oi: Value = Rc::new(RefCell::new(Outer_int_ { v: 3 })); assert!( (({ - Outer_int__Inner_int_Impl::sum( - &Rc::new(RefCell::new( - ({ Outer_int_Impl::with(&oi.as_pointer(), 4) }), - )) - .as_pointer(), + Outer_int__Inner_int_::sum( + Rc::new(RefCell::new(({ Outer_int_::with(oi.as_pointer(), 4) }))).as_pointer(), ) }) == 7) ); @@ -285,224 +385,55 @@ fn main_0() -> i32 { })); assert!( (({ - Outer_long__Inner_int_Impl::sum( - &Rc::new(RefCell::new( - ({ Outer_long_Impl::with(&ol.as_pointer(), 2) }), - )) - .as_pointer(), + Outer_long__Inner_int_::sum( + Rc::new(RefCell::new(({ Outer_long_::with(ol.as_pointer(), 2) }))).as_pointer(), ) }) == 7) ); - assert!( - (({ Outer_long__Inner_char_Impl::sum(&ic.as_pointer(),) }) == (6 + (('a' as i8) as i32))) - ); + assert!((({ Outer_long__Inner_char_::sum(ic.as_pointer(),) }) == (6 + (('a' as i8) as i32)))); assert!((({ Boxed_int_::twice(3,) }) == 6)); let bi: Value = Rc::new(RefCell::new(Boxed_int_ { value: 4 })); - assert!((({ Boxed_int_Impl::plus(&bi.as_pointer(), 5,) }) == 9)); + assert!((({ Boxed_int_::plus(bi.as_pointer(), 5,) }) == 9)); assert!((({ Boxed_long_::twice(10_i64,) }) == 20_i64)); let bl: Value = Rc::new(RefCell::new(Boxed_long_ { value: 7_i64 })); - assert!((({ Boxed_long_Impl::plus(&bl.as_pointer(), 1_i64,) }) == 8_i64)); + assert!((({ Boxed_long_::plus(bl.as_pointer(), 1_i64,) }) == 8_i64)); object!(imc, MyContainer_int_); - assert!(({ MyContainer_int_Impl::empty(&imc.as_pointer(),) })); + assert!(({ MyContainer_int_::empty(imc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(1)); - MyContainer_int_Impl::push_back(&imc.as_pointer(), _item.as_pointer()) + MyContainer_int_::push_back(imc.as_pointer(), _item.as_pointer()) }); assert!( - (({ MyContainer_int_Impl::size(&imc.as_pointer(),) }) == 1_usize) - && ((({ MyContainer_int_Impl::back_4(&imc.as_pointer(),) }).read()) == 1) + (({ MyContainer_int_::size(imc.as_pointer(),) }) == 1_usize) + && ((({ MyContainer_int_::back_4(imc.as_pointer(),) }).read()) == 1) ); - ({ MyContainer_int_Impl::pop_back(&imc.as_pointer()) }); - assert!(({ MyContainer_int_Impl::empty(&imc.as_pointer(),) })); + ({ MyContainer_int_::pop_back(imc.as_pointer()) }); + assert!(({ MyContainer_int_::empty(imc.as_pointer(),) })); object!(cmc, MyContainer_char_); - assert!(({ MyContainer_char_Impl::empty(&cmc.as_pointer(),) })); + assert!(({ MyContainer_char_::empty(cmc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(('a' as i8))); - MyContainer_char_Impl::push_back(&cmc.as_pointer(), _item.as_pointer()) + MyContainer_char_::push_back(cmc.as_pointer(), _item.as_pointer()) }); assert!( - (({ MyContainer_char_Impl::size(&cmc.as_pointer(),) }) == 1_usize) - && (((({ MyContainer_char_Impl::back_4(&cmc.as_pointer(),) }).read()) as i32) + (({ MyContainer_char_::size(cmc.as_pointer(),) }) == 1_usize) + && (((({ MyContainer_char_::back_4(cmc.as_pointer(),) }).read()) as i32) == (('a' as i8) as i32)) ); - ({ MyContainer_char_Impl::pop_back(&cmc.as_pointer()) }); - assert!(({ MyContainer_char_Impl::empty(&cmc.as_pointer(),) })); + ({ MyContainer_char_::pop_back(cmc.as_pointer()) }); + assert!(({ MyContainer_char_::empty(cmc.as_pointer(),) })); object!(fmc, MyContainer_float_); - assert!(({ MyContainer_float_Impl::empty(&fmc.as_pointer(),) })); + assert!(({ MyContainer_float_::empty(fmc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new((1_f64 as f32))); - MyContainer_float_Impl::push_back(&fmc.as_pointer(), _item.as_pointer()) + MyContainer_float_::push_back(fmc.as_pointer(), _item.as_pointer()) }); assert!( - (({ MyContainer_float_Impl::size(&fmc.as_pointer(),) }) == 1_usize) - && (((({ MyContainer_float_Impl::back_4(&fmc.as_pointer(),) }).read()) as f64) - == 1_f64) + (({ MyContainer_float_::size(fmc.as_pointer(),) }) == 1_usize) + && (((({ MyContainer_float_::back_4(fmc.as_pointer(),) }).read()) as f64) == 1_f64) ); - ({ MyContainer_float_Impl::pop_back(&fmc.as_pointer()) }); - assert!(({ MyContainer_float_Impl::empty(&fmc.as_pointer(),) })); + ({ MyContainer_float_::pop_back(fmc.as_pointer()) }); + assert!(({ MyContainer_float_::empty(fmc.as_pointer(),) })); return 0; } -pub trait Boxed_int_Impl { - fn plus(&self, other: i32) -> i32; -} -impl Boxed_int_Impl for Ptr { - fn plus(&self, mut other: i32) -> i32 { - return ((*self).with(|__s| __s.value) + other); - } -} -pub trait Boxed_long_Impl { - fn plus(&self, other: i64) -> i64; -} -impl Boxed_long_Impl for Ptr { - fn plus(&self, mut other: i64) -> i64 { - return ((*self).with(|__s| __s.value) + other); - } -} -pub trait Boxed_short_Impl { - fn plus(&self, other: i16) -> i16; -} -impl Boxed_short_Impl for Ptr { - fn plus(&self, mut other: i16) -> i16 { - return ((((*self).with(|__s| __s.value) as i32) + (other as i32)) as i16); - } -} -pub trait MyContainer_char_Impl { - fn empty(&self) -> bool; - fn size(&self) -> usize; - fn back_3(&self) -> Ptr { - unimplemented!() - } - fn back_4(&self) -> Ptr; - fn pop_back(&self); - fn push_back(&self, item: Ptr); -} -impl MyContainer_char_Impl for Ptr { - fn empty(&self) -> bool { - return (*(*self).upgrade().deref()).vec_.is_empty(); - } - fn size(&self) -> usize { - return (*(*self).upgrade().deref()).vec_.len(); - } - fn back_4(&self) -> Ptr { - return { - let __n = (*(*self).upgrade().deref()).vec_.len() - 1; - field_ref!((*self), vec_).decay().offset((__n) as isize) - }; - } - fn pop_back(&self) { - field!((*self), vec_).with_mut(|__v: &mut Vec| __v.pop()); - return; - } - fn push_back(&self, item: Ptr) { - CopyConstructible::push_copied(&field_ref!((*self), vec_).as_pointer(), (item).clone()); - } -} -pub trait MyContainer_float_Impl { - fn empty(&self) -> bool; - fn size(&self) -> usize; - fn back_3(&self) -> Ptr { - unimplemented!() - } - fn back_4(&self) -> Ptr; - fn pop_back(&self); - fn push_back(&self, item: Ptr); -} -impl MyContainer_float_Impl for Ptr { - fn empty(&self) -> bool { - return (*(*self).upgrade().deref()).vec_.is_empty(); - } - fn size(&self) -> usize { - return (*(*self).upgrade().deref()).vec_.len(); - } - fn back_4(&self) -> Ptr { - return { - let __n = (*(*self).upgrade().deref()).vec_.len() - 1; - field_ref!((*self), vec_).decay().offset((__n) as isize) - }; - } - fn pop_back(&self) { - field!((*self), vec_).with_mut(|__v: &mut Vec| __v.pop()); - return; - } - fn push_back(&self, item: Ptr) { - CopyConstructible::push_copied(&field_ref!((*self), vec_).as_pointer(), (item).clone()); - } -} -pub trait MyContainer_int_Impl { - fn empty(&self) -> bool; - fn size(&self) -> usize; - fn back_3(&self) -> Ptr { - unimplemented!() - } - fn back_4(&self) -> Ptr; - fn pop_back(&self); - fn push_back(&self, item: Ptr); -} -impl MyContainer_int_Impl for Ptr { - fn empty(&self) -> bool { - return (*(*self).upgrade().deref()).vec_.is_empty(); - } - fn size(&self) -> usize { - return (*(*self).upgrade().deref()).vec_.len(); - } - fn back_4(&self) -> Ptr { - return { - let __n = (*(*self).upgrade().deref()).vec_.len() - 1; - field_ref!((*self), vec_).decay().offset((__n) as isize) - }; - } - fn pop_back(&self) { - field!((*self), vec_).with_mut(|__v: &mut Vec| __v.pop()); - return; - } - fn push_back(&self, item: Ptr) { - CopyConstructible::push_copied(&field_ref!((*self), vec_).as_pointer(), (item).clone()); - } -} -pub trait Outer_int_Impl { - fn with(&self, n: i32) -> Outer_int__Inner_int_; -} -impl Outer_int_Impl for Ptr { - fn with(&self, mut n: i32) -> Outer_int__Inner_int_ { - return Outer_int__Inner_int_ { - t: (*self).with(|__s| __s.v), - u: n, - }; - } -} -pub trait Outer_int__Inner_int_Impl { - fn sum(&self) -> i32; -} -impl Outer_int__Inner_int_Impl for Ptr { - fn sum(&self) -> i32 { - return (((*self).with(|__s| __s.t) as i32) + ((*self).with(|__s| __s.u) as i32)); - } -} -pub trait Outer_long_Impl { - fn with(&self, n: i32) -> Outer_long__Inner_int_; -} -impl Outer_long_Impl for Ptr { - fn with(&self, mut n: i32) -> Outer_long__Inner_int_ { - return Outer_long__Inner_int_ { - t: (*self).with(|__s| __s.v), - u: n, - }; - } -} -pub trait Outer_long__Inner_char_Impl { - fn sum(&self) -> i32; -} -impl Outer_long__Inner_char_Impl for Ptr { - fn sum(&self) -> i32 { - return (((*self).with(|__s| __s.t) as i32) + ((*self).with(|__s| __s.u) as i32)); - } -} -pub trait Outer_long__Inner_int_Impl { - fn sum(&self) -> i32; -} -impl Outer_long__Inner_int_Impl for Ptr { - fn sum(&self) -> i32 { - return (((*self).with(|__s| __s.t) as i32) + ((*self).with(|__s| __s.u) as i32)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/complex_function.rs b/tests/unit/out/refcount/complex_function.rs index c6fbbd220c..0ffe5dbb4a 100644 --- a/tests/unit/out/refcount/complex_function.rs +++ b/tests/unit/out/refcount/complex_function.rs @@ -49,6 +49,11 @@ pub struct X2 { #[byte_size(8)] pub v: Ptr, } +impl X2 { + pub fn get(this: Ptr) -> Ptr { + return (this.with(|__s| __s.v.clone())).clone(); + } +} #[derive( Clone, Record, @@ -66,6 +71,11 @@ pub struct X3 { #[byte_size(8)] pub v: Ptr, } +impl X3 { + pub fn get(this: Ptr) -> Ptr { + return this.with(|__s| __s.v.clone()); + } +} #[derive( Clone, Record, @@ -83,6 +93,11 @@ pub struct X4 { #[byte_size(8)] pub v: X3, } +impl X4 { + pub fn get(this: Ptr) -> Ptr { + return field_ptr!(this, v); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -123,32 +138,31 @@ fn main_0() -> i32 { let d: Value = Rc::new(RefCell::new(X4 { v: (c).clone() })); field!({ (*d.borrow()).v.v.clone() }.with(|__s| __s.v.clone()), v).write(0); field!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v ) .write(0); (*d.borrow_mut()).v.v = (b.as_pointer()); let r4: Ptr = field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v ); - let r5: Ptr = ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer()) })) })) }); - let mut p: Ptr = ({ X3Impl::get(&({ X4Impl::get(&d.as_pointer()) })) }); - let r6: Ptr = ({ X4Impl::get(&d.as_pointer()) }); + let r5: Ptr = ({ X2::get(({ X3::get(({ X4::get(d.as_pointer()) })) })) }); + let mut p: Ptr = ({ X3::get(({ X4::get(d.as_pointer()) })) }); + let r6: Ptr = ({ X4::get(d.as_pointer()) }); let r7: Ptr = field_ptr!(d.as_pointer(), v); let r8: Ptr = field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&field_ptr!(d.as_pointer(), v),) }),) }), + ({ X2::get(({ X3::get(field_ptr!(d.as_pointer(), v),) }),) }), v ); - let mut x5: i32 = ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer()) })) })) }) - .with(|__s| __s.v); + let mut x5: i32 = ({ X2::get(({ X3::get(({ X4::get(d.as_pointer()) })) })) }).with(|__s| __s.v); { ({ bar_2(x1.as_pointer()) }).with_mut(|__v| *__v = *__v + 10) }; ({ bar_2(x1.as_pointer()) }).with_mut(|__v| __v.postfix_inc()); let mut bar_out: i32 = (({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) @@ -159,7 +173,7 @@ fn main_0() -> i32 { { ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) @@ -167,21 +181,21 @@ fn main_0() -> i32 { }; ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) .with_mut(|__v| __v.postfix_inc()); let mut bar_inc2: i32 = ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) .with_mut(|__v| __v.prefix_inc().clone()); bar_inc2 = ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) @@ -195,7 +209,7 @@ fn main_0() -> i32 { ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -207,7 +221,7 @@ fn main_0() -> i32 { ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -218,7 +232,7 @@ fn main_0() -> i32 { ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -228,7 +242,7 @@ fn main_0() -> i32 { let mut ptr1: i32 = ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -237,7 +251,7 @@ fn main_0() -> i32 { let ptr2: Ptr = ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -245,7 +259,7 @@ fn main_0() -> i32 { let mut ptr3: Ptr = ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -253,7 +267,7 @@ fn main_0() -> i32 { let mut vptr: i32 = (({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -261,13 +275,13 @@ fn main_0() -> i32 { .read()); let mut pref: Ptr = ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }); ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) @@ -276,7 +290,7 @@ fn main_0() -> i32 { ((((({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -284,43 +298,16 @@ fn main_0() -> i32 { .read()) + (({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) .read())) + ({ - foo_0( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer()) })) })) }) - .with(|__s| __s.v), - ) + foo_0(({ X2::get(({ X3::get(({ X4::get(d.as_pointer()) })) })) }).with(|__s| __s.v)) })) == 54) ); return 0; } -pub trait X2Impl { - fn get(&self) -> Ptr; -} -impl X2Impl for Ptr { - fn get(&self) -> Ptr { - return ((*self).with(|__s| __s.v.clone())).clone(); - } -} -pub trait X3Impl { - fn get(&self) -> Ptr; -} -impl X3Impl for Ptr { - fn get(&self) -> Ptr { - return (*self).with(|__s| __s.v.clone()); - } -} -pub trait X4Impl { - fn get(&self) -> Ptr; -} -impl X4Impl for Ptr { - fn get(&self) -> Ptr { - return field_ptr!((*self), v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/concepts.rs b/tests/unit/out/refcount/concepts.rs index 6d8bb7c121..97e6a487cc 100644 --- a/tests/unit/out/refcount/concepts.rs +++ b/tests/unit/out/refcount/concepts.rs @@ -25,6 +25,11 @@ const _: () = assert!( )] #[byte_size(1)] pub struct Sized {} +impl Sized { + pub fn size(this: Ptr) -> i32 { + return 4; + } +} pub fn is_small_0() -> bool { return true; } @@ -68,12 +73,4 @@ fn main_0() -> i32 { assert!((({ pick_6(1_f32,) }) == 2)); return 0; } -pub trait SizedImpl { - fn size(&self) -> i32; -} -impl SizedImpl for Ptr { - fn size(&self) -> i32 { - return 4; - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/constexpr_function.rs b/tests/unit/out/refcount/constexpr_function.rs index 7d52dfa2b2..b93cdd6ebe 100644 --- a/tests/unit/out/refcount/constexpr_function.rs +++ b/tests/unit/out/refcount/constexpr_function.rs @@ -38,9 +38,14 @@ pub struct Flag { #[offset(0)] pub v: i32, } +impl Flag { + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.v) != 0); + } +} pub fn use_4(f: Flag) -> i32 { let f: Value = Rc::new(RefCell::new(f)); - assert!(({ FlagImpl::to_bool(&f.as_pointer(),) })); + assert!(({ Flag::to_bool(f.as_pointer(),) })); return { (*f.borrow()).v }; } pub fn checked_5(mut x: i32) -> i32 { @@ -72,6 +77,11 @@ pub struct P { #[offset(0)] pub v: i32, } +impl P { + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.v); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -94,7 +104,7 @@ fn main_0() -> i32 { let mut ptr: Ptr = arr.decay(); assert!(!(ptr).is_null()); let p: Value

= Rc::new(RefCell::new(P { v: 9 })); - assert!((({ PImpl::get(&p.as_pointer(),) }) == 9)); + assert!((({ P::get(p.as_pointer(),) }) == 9)); let mut k: i32 = ({ scaled_2(4) }); assert!((k == 4)); let mut ce: bool = true; @@ -111,20 +121,4 @@ fn main_0() -> i32 { thread_local!( static s_8: Value = Rc::new(RefCell::new(true)); ); -pub trait FlagImpl { - fn to_bool(&self) -> bool; -} -impl FlagImpl for Ptr { - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.v) != 0); - } -} -pub trait PImpl { - fn get(&self) -> i32; -} -impl PImpl for Ptr

{ - fn get(&self) -> i32 { - return (*self).with(|__s| __s.v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/constructor.rs b/tests/unit/out/refcount/constructor.rs index 8cd6db1f97..6307c112b3 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -29,10 +29,26 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn const_method(this: Ptr) -> i32 { + return (this.with(|__s| __s.v) * 2); + } + pub fn mut_method(this: Ptr) { + { + field!(this, v).with_mut(|__v| *__v = *__v + 1) + }; + } + pub fn construct(this: Ptr, mut init: i32) { + field!(this, v).write(init); + ({ S::mut_method(this.clone()) }); + let __rhs = ({ S::const_method(this.clone()) }); + total_0.with(|rc| *rc.borrow_mut() += __rhs); + } +} impl Destructible for S { - fn destroy(this: &Ptr) { - ({ SImpl::mut_method(this) }); - let __rhs = ({ SImpl::const_method(this) }); + fn destroy(this: Ptr) { + ({ S::mut_method(this.clone()) }); + let __rhs = ({ S::const_method(this.clone()) }); total_0.with(|rc| *rc.borrow_mut() += __rhs); } } @@ -47,11 +63,23 @@ pub struct Point { #[offset(4)] pub y: i32, } +impl Point { + pub fn construct_2(this: Ptr, mut x: i32, mut y: i32) { + field!(this, x).write(x); + field!(this, y).write(y); + } + pub fn construct_1(this: Ptr, mut v: i32) { + Point::construct_2(this.clone(), v, (v + 1)); + { + field!(this, y).with_mut(|__v| *__v = *__v * 10) + }; + } +} impl DefaultConstructible for Point { - fn default_constructor(this: &Ptr) { - PointImpl::construct_1(this, 4); + fn default_constructor(this: Ptr) { + Point::construct_1(this.clone(), 4); { - field!((*this), x).with_mut(|__v| *__v = *__v + 100) + field!(this, x).with_mut(|__v| *__v = *__v + 100) }; } } @@ -60,7 +88,7 @@ impl Default for Point { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -85,43 +113,6 @@ fn main_0() -> i32 { assert!(({ (*q.borrow()).y } == 80)); return 0; } -pub trait PointImpl { - fn construct_2(&self, x: i32, y: i32); - fn construct_1(&self, v: i32); -} -impl PointImpl for Ptr { - fn construct_2(&self, mut x: i32, mut y: i32) { - field!((*self), x).write(x); - field!((*self), y).write(y); - } - fn construct_1(&self, mut v: i32) { - PointImpl::construct_2(self, v, (v + 1)); - { - field!((*self), y).with_mut(|__v| *__v = *__v * 10) - }; - } -} -pub trait SImpl { - fn const_method(&self) -> i32; - fn mut_method(&self); - fn construct(&self, init: i32); -} -impl SImpl for Ptr { - fn const_method(&self) -> i32 { - return ((*self).with(|__s| __s.v) * 2); - } - fn mut_method(&self) { - { - field!((*self), v).with_mut(|__v| *__v = *__v + 1) - }; - } - fn construct(&self, mut init: i32) { - field!((*self), v).write(init); - ({ SImpl::mut_method(self) }); - let __rhs = ({ SImpl::const_method(self) }); - total_0.with(|rc| *rc.borrow_mut() += __rhs); - } -} pub fn __cpp2rust_init_globals() { let _ = total_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/container_field_addr.rs b/tests/unit/out/refcount/container_field_addr.rs index 683a2c6a03..7ebb9e6509 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -29,9 +29,9 @@ pub struct S { pub v: Vec, } impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { - field!((*this), tag).write(0_i32); - field!((*this), v).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, tag).write(0_i32); + field!(this, v).write(Vec::new()); } } pub fn add_0(mut v: Ptr>, k: i32) { @@ -63,7 +63,7 @@ fn main_0() -> i32 { ({ run_1((local.as_pointer())) }); let mut heap: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + DefaultConstructible::default_constructor(__p.clone()); __p }; field!(heap, tag).write(7); diff --git a/tests/unit/out/refcount/conversion_operator_same_translation.rs b/tests/unit/out/refcount/conversion_operator_same_translation.rs index 45c44fe60d..c6f562fa0d 100644 --- a/tests/unit/out/refcount/conversion_operator_same_translation.rs +++ b/tests/unit/out/refcount/conversion_operator_same_translation.rs @@ -26,6 +26,14 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn to_i8(this: Ptr) -> i8 { + return (this.with(|__s| __s.v) as i8); + } + pub fn to_u8(this: Ptr) -> u8 { + return ((this.with(|__s| __s.v) + 1) as u8); + } +} #[derive( Copy, Clone, @@ -45,50 +53,33 @@ pub struct T { #[offset(0)] pub v: i32, } +impl T { + pub fn to_i64_1(this: Ptr) -> i64 { + return (this.with(|__s| __s.v) as i64); + } + pub fn to_i64_2(this: Ptr) -> i64 { + return ((this.with(|__s| __s.v) + 1) as i64); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 65 })); - let mut a: i8 = ({ SImpl::to_i8(&s.as_pointer()) }); - let mut b: u8 = ({ SImpl::to_u8(&s.as_pointer()) }); + let mut a: i8 = ({ S::to_i8(s.as_pointer()) }); + let mut b: u8 = ({ S::to_u8(s.as_pointer()) }); assert!(((a as i32) == (('A' as i8) as i32))); assert!(((b as i32) == ((66 as u8) as i32))); assert!( - (((({ SImpl::to_i8(&s.as_pointer(),) }) as i32) - + (({ SImpl::to_u8(&s.as_pointer(),) }) as i32)) + (((({ S::to_i8(s.as_pointer(),) }) as i32) + (({ S::to_u8(s.as_pointer(),) }) as i32)) == 131) ); let t: Value = Rc::new(RefCell::new(T { v: 3 })); - let mut c: i64 = ({ TImpl::to_i64_1(&t.as_pointer()) }); - let mut d: i64 = ({ TImpl::to_i64_2(&t.as_pointer()) }); + let mut c: i64 = ({ T::to_i64_1(t.as_pointer()) }); + let mut d: i64 = ({ T::to_i64_2(t.as_pointer()) }); assert!((c == 3_i64)); assert!((d == 4_i64)); return 0; } -pub trait SImpl { - fn to_i8(&self) -> i8; - fn to_u8(&self) -> u8; -} -impl SImpl for Ptr { - fn to_i8(&self) -> i8 { - return ((*self).with(|__s| __s.v) as i8); - } - fn to_u8(&self) -> u8 { - return (((*self).with(|__s| __s.v) + 1) as u8); - } -} -pub trait TImpl { - fn to_i64_1(&self) -> i64; - fn to_i64_2(&self) -> i64; -} -impl TImpl for Ptr { - fn to_i64_1(&self) -> i64 { - return ((*self).with(|__s| __s.v) as i64); - } - fn to_i64_2(&self) -> i64 { - return (((*self).with(|__s| __s.v) + 1) as i64); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index 6a8e8f860a..a117175a55 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -27,20 +27,26 @@ pub struct Partial { #[offset(4)] pub keep: i32, } +impl Partial { + pub fn construct(this: Ptr, mut v: i32, mut keep: i32) { + field!(this, v).write(v); + field!(this, keep).write(keep); + } +} impl CopyConstructible for Partial { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), keep).write(o.with(|__s| __s.keep)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, keep).write(o.with(|__s| __s.keep)); } } impl CopyAssignable for Partial { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { - if ((*this) == (o)) { - return (*this).clone(); + fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + if (this == (o)) { + return (this).clone(); } - field!((*this), v).write(o.with(|__s| __s.v)); + field!(this, v).write(o.with(|__s| __s.v)); (*assigns_0.with(Value::clone).borrow_mut()).prefix_inc(); - return (*this).clone(); + return (this).clone(); } } #[derive( @@ -51,9 +57,19 @@ pub struct NonConstAssign { #[offset(0)] pub mark: i32, } +impl NonConstAssign { + pub fn operator_assign_2(this: Ptr, o: Ptr) -> Ptr { + field!(this, mark).write((o.with(|__s| __s.mark) + 1)); + return (this).clone(); + } + pub fn operator_assign_3(this: Ptr, o: Ptr) -> Ptr { + field!(this, mark).write((o.with(|__s| __s.mark) + 10)); + return (this).clone(); + } +} impl DefaultConstructible for NonConstAssign { - fn default_constructor(this: &Ptr) { - field!((*this), mark).write(0); + fn default_constructor(this: Ptr) { + field!(this, mark).write(0); } } impl Default for NonConstAssign { @@ -62,7 +78,7 @@ impl Default for NonConstAssign { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -86,14 +102,14 @@ pub struct RefQualified { pub mark: i32, } impl DefaultConstructible for RefQualified { - fn default_constructor(this: &Ptr) { - field!((*this), mark).write(0); + fn default_constructor(this: Ptr) { + field!(this, mark).write(0); } } impl CopyAssignable for RefQualified { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { - field!((*this), mark).write((o.with(|__s| __s.mark) + 1)); - return (*this).clone(); + fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, mark).write((o.with(|__s| __s.mark) + 1)); + return (this).clone(); } } impl Default for RefQualified { @@ -101,7 +117,7 @@ impl Default for RefQualified { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -156,9 +172,14 @@ pub struct CopyCounted { #[offset(0)] pub v: i32, } +impl CopyCounted { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl CopyConstructible for CopyCounted { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -207,18 +228,18 @@ pub struct ExplicitOperatorCall { pub w: Vec, } impl CopyAssignable for ExplicitOperatorCall { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: Ptr) -> Ptr { match (field_ref!(o, w).as_pointer(),) { - (__tmp_0,) => field!((*this), w).with_mut(|__b0| { + (__tmp_0,) => field!(this, w).with_mut(|__b0| { (*__b0) = copy_constructed(__tmp_0); }), }; - return (*this).clone(); + return (this).clone(); } } impl DefaultConstructible for ExplicitOperatorCall { - fn default_constructor(this: &Ptr) { - field!((*this), w).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, w).write(Vec::new()); } } thread_local!( @@ -241,24 +262,35 @@ pub struct Swapped { #[offset(0)] pub v: i32, } +impl Swapped { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } + pub fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + let mut t: i32 = this.with(|__s| __s.v); + field!(this, v).write(o.with(|__s| __s.v)); + field!(o, v).write(t); + return (this).clone(); + } +} impl CopyConstructible for Swapped { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn copy_constructor(this: Ptr, o: Ptr) { + 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 { + fn copy_assign(this: Ptr, src: Ptr) -> Ptr { object!(__o, Swapped, src); - SwappedImpl::copy_assign(this, Ptr::clone(&__o.as_pointer())); - Ptr::clone(this) + 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 { + fn move_assign(this: Ptr, src: Ptr) -> Ptr { object!(__o, Swapped, Moved(src)); - SwappedImpl::copy_assign(this, Ptr::clone(&__o.as_pointer())); - Ptr::clone(this) + Swapped::copy_assign(this.clone(), Ptr::clone(&__o.as_pointer())); + Ptr::clone(&this.clone()) } } #[derive( @@ -296,21 +328,26 @@ pub struct VoidAssign { #[offset(0)] pub x: i32, } +impl VoidAssign { + pub fn copy_assign(this: Ptr, o: Ptr) { + field!(this, x).write((o.with(|__s| __s.x) + 5)); + } +} impl DefaultConstructible for VoidAssign { - fn default_constructor(this: &Ptr) { - field!((*this), x).write(0); + fn default_constructor(this: Ptr) { + field!(this, x).write(0); } } impl CopyAssignable for VoidAssign { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { - VoidAssignImpl::copy_assign(this, src); - Ptr::clone(this) + fn copy_assign(this: Ptr, src: Ptr) -> Ptr { + VoidAssign::copy_assign(this.clone(), src); + Ptr::clone(&this.clone()) } } impl MoveAssignable for VoidAssign { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr { - VoidAssignImpl::copy_assign(this, src); - Ptr::clone(this) + fn move_assign(this: Ptr, src: Ptr) -> Ptr { + VoidAssign::copy_assign(this.clone(), src); + Ptr::clone(&this.clone()) } } impl Default for VoidAssign { @@ -318,7 +355,7 @@ impl Default for VoidAssign { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -346,8 +383,8 @@ pub struct HoldsVoidAssign { pub v: VoidAssign, } impl DefaultConstructible for HoldsVoidAssign { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, v)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, v)); } } pub fn main() { @@ -368,7 +405,7 @@ fn main_0() -> i32 { assert!((assigns_0.with(|rc| *rc.borrow()) == 3)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); - PartialImpl::construct(&_o.as_pointer(), 9, 900); + Partial::construct(_o.as_pointer(), 9, 900); assign!(a = _o) }); assert!(({ (*a.borrow()).v } == 9) && ({ (*a.borrow()).keep } == 100)); @@ -383,18 +420,18 @@ fn main_0() -> i32 { let h: Value = Rc::new(RefCell::new(Holder { p: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PartialImpl::construct(&__v.as_pointer(), 4, 40); + Partial::construct(__v.as_pointer(), 4, 40); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PartialImpl::construct(&__v.as_pointer(), 5, 50); + Partial::construct(__v.as_pointer(), 5, 50); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PartialImpl::construct(&__v.as_pointer(), 6, 60); + Partial::construct(__v.as_pointer(), 6, 60); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -411,8 +448,8 @@ fn main_0() -> i32 { object!(n1, NonConstAssign); object!(n2, NonConstAssign); object!(cn, NonConstAssign); - NonConstAssignImpl::operator_assign_2(&n1.as_pointer(), n.as_pointer()); - NonConstAssignImpl::operator_assign_3(&n2.as_pointer(), cn.as_pointer()); + NonConstAssign::operator_assign_2(n1.as_pointer(), n.as_pointer()); + NonConstAssign::operator_assign_3(n2.as_pointer(), cn.as_pointer()); assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); object!(r, RefQualified); @@ -422,18 +459,18 @@ fn main_0() -> i32 { let h2: Value = Rc::new(RefCell::new(Holder { p: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PartialImpl::construct(&__v.as_pointer(), 7, 70); + Partial::construct(__v.as_pointer(), 7, 70); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PartialImpl::construct(&__v.as_pointer(), 8, 80); + Partial::construct(__v.as_pointer(), 8, 80); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PartialImpl::construct(&__v.as_pointer(), 9, 90); + Partial::construct(__v.as_pointer(), 9, 90); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -452,18 +489,18 @@ fn main_0() -> i32 { let hc1: Value = Rc::new(RefCell::new(HasCopyCounted { c: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCountedImpl::construct(&__v.as_pointer(), 1); + CopyCounted::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCountedImpl::construct(&__v.as_pointer(), 2); + CopyCounted::construct(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCountedImpl::construct(&__v.as_pointer(), 3); + CopyCounted::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -471,18 +508,18 @@ fn main_0() -> i32 { let hc2: Value = Rc::new(RefCell::new(HasCopyCounted { c: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCountedImpl::construct(&__v.as_pointer(), 4); + CopyCounted::construct(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCountedImpl::construct(&__v.as_pointer(), 5); + CopyCounted::construct(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCountedImpl::construct(&__v.as_pointer(), 6); + CopyCounted::construct(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -515,21 +552,21 @@ 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()); - SwappedImpl::copy_assign(&sw1.as_pointer(), _o.as_pointer()) + ConstructFrom::construct_from(_o.as_pointer(), 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)); let hs1: Value = Rc::new(RefCell::new(HoldsSwapped { s: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - SwappedImpl::construct(&__v.as_pointer(), 3); + Swapped::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); let hs2: Value = Rc::new(RefCell::new(HoldsSwapped { s: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - SwappedImpl::construct(&__v.as_pointer(), 4); + Swapped::construct(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); @@ -541,60 +578,6 @@ fn main_0() -> i32 { assert!(({ (*hv1.borrow()).v.x } == 5)); return 0; } -pub trait CopyCountedImpl { - fn construct(&self, v: i32); -} -impl CopyCountedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} -pub trait NonConstAssignImpl { - fn operator_assign_2(&self, o: Ptr) -> Ptr; - fn operator_assign_3(&self, o: Ptr) -> Ptr; -} -impl NonConstAssignImpl for Ptr { - fn operator_assign_2(&self, o: Ptr) -> Ptr { - field!((*self), mark).write((o.with(|__s| __s.mark) + 1)); - return (*self).clone(); - } - fn operator_assign_3(&self, o: Ptr) -> Ptr { - field!((*self), mark).write((o.with(|__s| __s.mark) + 10)); - return (*self).clone(); - } -} -pub trait PartialImpl { - fn construct(&self, v: i32, keep: i32); -} -impl PartialImpl for Ptr { - fn construct(&self, mut v: i32, mut keep: i32) { - field!((*self), v).write(v); - field!((*self), keep).write(keep); - } -} -pub trait SwappedImpl { - fn construct(&self, v: i32); - fn copy_assign(&self, o: Ptr) -> Ptr; -} -impl SwappedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } - fn copy_assign(&self, o: Ptr) -> Ptr { - let mut t: i32 = (*self).with(|__s| __s.v); - field!((*self), v).write(o.with(|__s| __s.v)); - field!(o, v).write(t); - return (*self).clone(); - } -} -pub trait VoidAssignImpl { - fn copy_assign(&self, o: Ptr); -} -impl VoidAssignImpl for Ptr { - fn copy_assign(&self, o: Ptr) { - field!((*self), x).write((o.with(|__s| __s.x) + 5)); - } -} pub fn __cpp2rust_init_globals() { let _ = assigns_0.with(|_| ()); let _ = copies_1.with(|_| ()); diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index af76c67ab8..1c838005ce 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -29,9 +29,14 @@ pub struct Counted { #[offset(0)] pub v: i32, } +impl Counted { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -44,9 +49,17 @@ pub struct NonConst { #[offset(0)] pub mark: i32, } +impl NonConst { + pub fn construct_1(this: Ptr, o: Ptr) { + field!(this, mark).write((o.with(|__s| __s.mark) + 1)); + } + pub fn construct_2(this: Ptr, o: Ptr) { + field!(this, mark).write((o.with(|__s| __s.mark) + 10)); + } +} impl DefaultConstructible for NonConst { - fn default_constructor(this: &Ptr) { - field!((*this), mark).write(0); + fn default_constructor(this: Ptr) { + field!(this, mark).write(0); } } impl Default for NonConst { @@ -54,7 +67,7 @@ impl Default for NonConst { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -80,9 +93,14 @@ pub struct Ignored { #[offset(0)] pub v: i32, } +impl Ignored { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl CopyConstructible for Ignored { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), v).write(-1_i32); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, v).write(-1_i32); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -129,9 +147,14 @@ pub struct Box_int_ { #[offset(0)] pub val: i32, } +impl Box_int_ { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, val).write(v); + } +} impl CopyConstructible for Box_int_ { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), val).write(o.with(|__s| __s.val)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, val).write(o.with(|__s| __s.val)); } } #[derive( @@ -164,9 +187,14 @@ pub struct OutOfLine { #[offset(0)] pub v: i32, } +impl OutOfLine { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl CopyConstructible for OutOfLine { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write((o.with(|__s| __s.v) + 100)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write((o.with(|__s| __s.v) + 100)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -186,24 +214,24 @@ pub struct Tracked { pub copied_from: i32, } impl DefaultConstructible for Tracked { - fn default_constructor(this: &Ptr) { - field!((*this), copied_from).write(0); + fn default_constructor(this: Ptr) { + field!(this, copied_from).write(0); } } impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), copied_from).write(0); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, copied_from).write(0); field!(o, copied_from).with_mut(|__v| { __v.prefix_inc(); }); } } impl CopyAssignable for Tracked { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: Ptr) -> Ptr { field!(o, copied_from).with_mut(|__v| { __v.prefix_inc(); }); - return (*this).clone(); + return (this).clone(); } } impl Default for Tracked { @@ -219,9 +247,9 @@ pub fn touch_1(mut t: Ptr) { pub fn by_value_2(c: Ptr) -> i32 { return c.with(|__s| __s.v); } -pub fn make_3(this: Ptr, mut v: i32) { +pub fn make_3(__return: Ptr, mut v: i32) { object!(c, Counted(v)); - ConstructFrom::construct_from(&this, c.as_pointer()); + ConstructFrom::construct_from(__return.clone(), c.as_pointer()); return; } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] @@ -232,18 +260,18 @@ pub struct SelfPtr { pub self_: Ptr, } impl DefaultConstructible for SelfPtr { - fn default_constructor(this: &Ptr) { - field!((*this), self_).write((*this).clone()); + fn default_constructor(this: Ptr) { + field!(this, self_).write((this).clone()); } } impl CopyConstructible for SelfPtr { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), self_).write((*this).clone()); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, self_).write((this).clone()); } } impl MoveConstructible for SelfPtr { - fn move_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), self_).write((*this).clone()); + fn move_constructor(this: Ptr, _a0: Ptr) { + field!(this, self_).write((this).clone()); } } impl Default for SelfPtr { @@ -251,7 +279,7 @@ impl Default for SelfPtr { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -280,8 +308,8 @@ pub struct Derived { pub c: Counted, } impl DefaultConstructible for Derived { - fn default_constructor(this: &Ptr) { - CountedImpl::construct(&field_ptr!(this, c), 20); + fn default_constructor(this: Ptr) { + Counted::construct(field_ptr!(this, c), 20); } } impl Default for Derived { @@ -289,7 +317,7 @@ impl Default for Derived { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -311,12 +339,12 @@ fn main_0() -> i32 { assert!( (({ let _c: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_c.as_pointer(), a.as_pointer()); + ConstructFrom::construct_from(_c.as_pointer(), a.as_pointer()); by_value_2(_c.as_pointer()) }) == 1) ); assert!((copies_0.with(|rc| *rc.borrow()) == 4)); - object!(e, Counted, |e| ({ make_3(Ptr::clone(e), 5,) })); + object!(e, Counted, |e| ({ make_3(Ptr::clone(&e.clone()), 5,) })); assert!(({ (*e.borrow()).v } == 5)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); object!(f, Counted(6)); @@ -329,18 +357,18 @@ fn main_0() -> i32 { let hold: Value = Rc::new(RefCell::new(Holder { c: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::construct(&__v.as_pointer(), 8); + Counted::construct(__v.as_pointer(), 8); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::construct(&__v.as_pointer(), 9); + Counted::construct(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::construct(&__v.as_pointer(), 10); + Counted::construct(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -363,7 +391,7 @@ fn main_0() -> i32 { let o: Value = Rc::new(RefCell::new(Owner { box_: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - Box_int_Impl::construct(&__v.as_pointer(), 3); + Box_int_::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); @@ -413,7 +441,7 @@ fn main_0() -> i32 { { let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); match ({ - DefaultConstructible::default_constructor(&__tmp_3.as_pointer()); + DefaultConstructible::default_constructor(__tmp_3.as_pointer()); __tmp_3.as_pointer() },) { @@ -438,7 +466,7 @@ fn main_0() -> i32 { { let __tmp_5: Value = Rc::new(RefCell::new(::zero_init())); match ({ - CountedImpl::construct(&__tmp_5.as_pointer(), 30); + Counted::construct(__tmp_5.as_pointer(), 30); __tmp_5.as_pointer() },) { @@ -451,50 +479,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait Box_int_Impl { - fn construct(&self, v: i32); -} -impl Box_int_Impl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), val).write(v); - } -} -pub trait CountedImpl { - fn construct(&self, v: i32); -} -impl CountedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} -pub trait IgnoredImpl { - fn construct(&self, v: i32); -} -impl IgnoredImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} -pub trait NonConstImpl { - fn construct_1(&self, o: Ptr); - fn construct_2(&self, o: Ptr); -} -impl NonConstImpl for Ptr { - fn construct_1(&self, o: Ptr) { - field!((*self), mark).write((o.with(|__s| __s.mark) + 1)); - } - fn construct_2(&self, o: Ptr) { - field!((*self), mark).write((o.with(|__s| __s.mark) + 10)); - } -} -pub trait OutOfLineImpl { - fn construct(&self, v: i32); -} -impl OutOfLineImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index e63513d4b4..136f8b34ce 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -51,8 +51,15 @@ pub struct Explicit { #[array_len(2)] pub arr: Box<[i32]>, } +impl Explicit { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, inner).write(Inner { x: (v * 10) }); + field!(this, arr).write(Box::new([v, (v + 1)])); + } +} impl Destructible for Explicit { - fn destroy(this: &Ptr) {} + fn destroy(this: Ptr) {} } #[derive( Clone, @@ -109,17 +116,22 @@ pub struct DefaultCopyUserMove { #[offset(0)] pub v: i32, } +impl DefaultCopyUserMove { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl MoveConstructible for DefaultCopyUserMove { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for DefaultCopyUserMove { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); - return (*this).clone(); + return (this).clone(); } } #[derive( @@ -140,15 +152,20 @@ pub struct UserCopyDefaultMove { #[offset(0)] pub v: i32, } +impl UserCopyDefaultMove { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl CopyConstructible for UserCopyDefaultMove { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write((o.with(|__s| __s.v) + 100)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write((o.with(|__s| __s.v) + 100)); } } impl CopyAssignable for UserCopyDefaultMove { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { - field!((*this), v).write((o.with(|__s| __s.v) + 100)); - return (*this).clone(); + fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write((o.with(|__s| __s.v) + 100)); + return (this).clone(); } } #[derive( @@ -178,6 +195,23 @@ pub struct Buffer { #[array_len(2)] pub arr: Box<[i32]>, } +impl Buffer { + pub fn construct(this: Ptr, n: i32) { + let n: Value = Rc::new(RefCell::new(n)); + field!(this, data).write( + (0..({ ((*n.borrow()) as usize) })) + .map(|_| copy_constructed(n.as_pointer().clone())) + .collect(), + ); + field!(this, rows).write(Vec::new()); + field!(this, n).write((*n.borrow())); + field!(this, arr).write(Box::new([(*n.borrow()), ((*n.borrow()) + 1)])); + CopyConstructible::push_copied( + &field_ref!(this, rows).as_pointer(), + field_ref!(this, data).as_pointer(), + ); + } +} impl Default for Buffer { fn default() -> Self { { ::zero_init() } @@ -201,11 +235,11 @@ pub struct Owner { pub p: Option>, } impl DefaultConstructible for Owner { - fn default_constructor(this: &Ptr) { - field!((*this), data).write(Vec::new()); - field!((*this), n).write(0_i32); - field!((*this), arr).write((0..2).map(|_| 0_i32).collect::>()); - field!((*this), p).write(None); + fn default_constructor(this: Ptr) { + field!(this, data).write(Vec::new()); + field!(this, n).write(0_i32); + field!(this, arr).write((0..2).map(|_| 0_i32).collect::>()); + field!(this, p).write(None); } } impl Default for Owner { @@ -241,8 +275,8 @@ pub struct Copyable { pub data: Vec, } impl DefaultConstructible for Copyable { - fn default_constructor(this: &Ptr) { - field!((*this), data).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, data).write(Vec::new()); } } #[derive( @@ -270,6 +304,13 @@ pub struct Holder { #[byte_size(8)] pub p: Option>, } +impl Holder { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, inner).write(Inner { x: v }); + Explicit::construct(field_ptr!(this, e), v); + field!(this, p).write(None); + } +} pub fn same_0(a: Ptr, b: Ptr) -> bool { return ((({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }) && ({ a.with(|__s| __s.inner.x) } == { b.with(|__s| __s.inner.x) })) @@ -284,20 +325,20 @@ pub struct SeesThis { pub self_: Ptr, } impl CopyAssignable for SeesThis { - fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { - field!((*this), self_).write((*this).clone()); - return (*this).clone(); + fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + field!(this, self_).write((this).clone()); + return (this).clone(); } } impl MoveAssignable for SeesThis { - fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { - field!((*this), self_).write((*this).clone()); - return (*this).clone(); + fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { + field!(this, self_).write((this).clone()); + return (this).clone(); } } impl DefaultConstructible for SeesThis { - fn default_constructor(this: &Ptr) { - field!((*this), self_).write(Ptr::::null()); + fn default_constructor(this: Ptr) { + field!(this, self_).write(Ptr::::null()); } } impl Default for SeesThis { @@ -321,9 +362,9 @@ pub struct HasSeesThis { pub v: Vec, } impl DefaultConstructible for HasSeesThis { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, s)); - field!((*this), v).write(Vec::new()); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, s)); + field!(this, v).write(Vec::new()); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] @@ -335,22 +376,22 @@ pub struct Counted_int_ { pub moves: i32, } impl DefaultConstructible for Counted_int_ { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(0_i32); - field!((*this), moves).write(0); + fn default_constructor(this: Ptr) { + field!(this, v).write(0_i32); + field!(this, moves).write(0); } } impl MoveConstructible for Counted_int_ { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + 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 { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); - return (*this).clone(); + fn move_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); + return (this).clone(); } } impl Default for Counted_int_ { @@ -372,9 +413,9 @@ pub struct HasCounted { pub w: Vec, } impl DefaultConstructible for HasCounted { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, c)); - field!((*this), w).write(Vec::new()); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, c)); + field!(this, w).write(Vec::new()); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable)] @@ -387,32 +428,38 @@ pub struct CtorSeesThis { #[offset(8)] pub id: i32, } +impl CtorSeesThis { + pub fn construct_1(this: Ptr, mut id: i32) { + DefaultConstructible::default_constructor(this.clone()); + field!(this, id).write(id); + } +} impl DefaultConstructible for CtorSeesThis { - fn default_constructor(this: &Ptr) { - field!((*this), self_).write((*this).clone()); - field!((*this), id).write(0); + fn default_constructor(this: Ptr) { + field!(this, self_).write((this).clone()); + field!(this, id).write(0); } } impl CopyConstructible for CtorSeesThis { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), self_).write((*this).clone()); - field!((*this), id).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, self_).write((this).clone()); + field!(this, id).write(0); } } impl MoveConstructible for CtorSeesThis { - fn move_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), self_).write((*this).clone()); - field!((*this), id).write(0); + fn move_constructor(this: Ptr, _a0: Ptr) { + field!(this, self_).write((this).clone()); + field!(this, id).write(0); } } impl CopyAssignable for CtorSeesThis { - fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { - return (*this).clone(); + fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + return (this).clone(); } } impl MoveAssignable for CtorSeesThis { - fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { - return (*this).clone(); + fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { + return (this).clone(); } } impl Default for CtorSeesThis { @@ -420,7 +467,7 @@ impl Default for CtorSeesThis { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -440,9 +487,9 @@ pub struct HasCtorSeesThis { pub v: Vec, } impl DefaultConstructible for HasCtorSeesThis { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, x)); - field!((*this), v).write(Vec::new()); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, x)); + field!(this, v).write(Vec::new()); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] @@ -457,9 +504,9 @@ pub struct InitsCtorSeesThis { pub y: CtorSeesThis, } impl DefaultConstructible for InitsCtorSeesThis { - fn default_constructor(this: &Ptr) { - CtorSeesThisImpl::construct_1(&field_ptr!(this, x), 1); - CtorSeesThisImpl::construct_1(&field_ptr!(this, y), 2); + fn default_constructor(this: Ptr) { + CtorSeesThis::construct_1(field_ptr!(this, x), 1); + CtorSeesThis::construct_1(field_ptr!(this, y), 2); } } impl Default for InitsCtorSeesThis { @@ -468,7 +515,7 @@ impl Default for InitsCtorSeesThis { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -494,16 +541,22 @@ pub struct OutOfLineDefaulted { #[offset(16)] pub v: i32, } +impl OutOfLineDefaulted { + pub fn construct(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, x)); + field!(this, v).write(1); + } +} impl CopyConstructible for OutOfLineDefaulted { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - ConstructFrom::construct_from(&field_ptr!(this, x), field_ptr!(_a0, x)); - field!((*this), v).write(_a0.with(|__s| __s.v)); + fn copy_constructor(this: Ptr, _a0: Ptr) { + ConstructFrom::construct_from(field_ptr!(this, x), field_ptr!(_a0, x)); + field!(this, v).write(_a0.with(|__s| __s.v)); } } impl DefaultConstructible for OutOfLineDefaulted { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { { - OutOfLineDefaultedImpl::construct(this); + OutOfLineDefaulted::construct(this.clone()); } } } @@ -513,7 +566,7 @@ impl Default for OutOfLineDefaulted { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - OutOfLineDefaultedImpl::construct(&__v.as_pointer()); + OutOfLineDefaulted::construct(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -533,10 +586,10 @@ pub struct OutOfLineAssign { pub w: Vec, } impl DefaultConstructible for OutOfLineAssign { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, s)); - field!((*this), v).write(1); - field!((*this), w).write(Vec::new()); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, s)); + field!(this, v).write(1); + field!(this, w).write(Vec::new()); } } impl Default for OutOfLineAssign { @@ -551,25 +604,25 @@ impl Default for OutOfLineAssign { } } impl CopyAssignable for OutOfLineAssign { - fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { - assign!(*field_ptr!((*this), s) = *field_ptr!(_a0, s)); - field!((*this), v).write(_a0.with(|__s| __s.v)); + fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + 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(),) { - (__tmp_0,) => field!((*this), w).with_mut(|__b0| { + (__tmp_0,) => field!(this, w).with_mut(|__b0| { (*__b0) = copy_constructed(__tmp_0); }), }; - return (*this).clone(); + return (this).clone(); } } impl MoveAssignable for OutOfLineAssign { - fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { - assign!(*field_ptr!((*this), s) = Moved(*field_ptr!(_a0, s))); - field!((*this), v).write({ (*_a0.upgrade().deref()).v }); - field!((*this), w).with_mut(|__b0| { + fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { + assign!(*field_ptr!(this, s) = Moved(*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); }); - return (*this).clone(); + return (this).clone(); } } pub fn main() { @@ -580,13 +633,13 @@ fn main_0() -> i32 { object!(a, Explicit(1)); let b: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_b = - std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); let c: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_c = - std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); let d: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_d = - std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!( (({ same_0(b.as_pointer(), a.as_pointer(),) }) && ({ same_0(c.as_pointer(), a.as_pointer(),) })) @@ -626,7 +679,7 @@ fn main_0() -> i32 { CopyConstructible::push_copied(&vec_.as_pointer(), b.as_pointer()); match (Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ExplicitImpl::construct(&__v.as_pointer(), 9); + Explicit::construct(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() })) .as_pointer(),) @@ -697,7 +750,7 @@ fn main_0() -> i32 { { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( - &__v.as_pointer(), + __v.as_pointer(), Moved(bufs.decay().offset(0_usize)), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -833,7 +886,7 @@ fn main_0() -> i32 { ); let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - CtorSeesThisImpl::construct_1(&__p, 4); + CtorSeesThis::construct_1(__p.clone(), 4); __p }; assert!( @@ -884,78 +937,4 @@ fn main_0() -> i32 { } return 0; } -pub trait BufferImpl { - fn construct(&self, n: i32); -} -impl BufferImpl for Ptr { - fn construct(&self, n: i32) { - let n: Value = Rc::new(RefCell::new(n)); - field!((*self), data).write( - (0..({ ((*n.borrow()) as usize) })) - .map(|_| copy_constructed(n.as_pointer().clone())) - .collect(), - ); - field!((*self), rows).write(Vec::new()); - field!((*self), n).write((*n.borrow())); - field!((*self), arr).write(Box::new([(*n.borrow()), ((*n.borrow()) + 1)])); - CopyConstructible::push_copied( - &field_ref!((*self), rows).as_pointer(), - field_ref!((*self), data).as_pointer(), - ); - } -} -pub trait CtorSeesThisImpl { - fn construct_1(&self, id: i32); -} -impl CtorSeesThisImpl for Ptr { - fn construct_1(&self, mut id: i32) { - DefaultConstructible::default_constructor(self); - field!((*self), id).write(id); - } -} -pub trait DefaultCopyUserMoveImpl { - fn construct(&self, v: i32); -} -impl DefaultCopyUserMoveImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} -pub trait ExplicitImpl { - fn construct(&self, v: i32); -} -impl ExplicitImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), inner).write(Inner { x: (v * 10) }); - field!((*self), arr).write(Box::new([v, (v + 1)])); - } -} -pub trait HolderImpl { - fn construct(&self, v: i32); -} -impl HolderImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), inner).write(Inner { x: v }); - ExplicitImpl::construct(&field_ptr!(self, e), v); - field!((*self), p).write(None); - } -} -pub trait OutOfLineDefaultedImpl { - fn construct(&self); -} -impl OutOfLineDefaultedImpl for Ptr { - fn construct(&self) { - DefaultConstructible::default_constructor(&field_ptr!(self, x)); - field!((*self), v).write(1); - } -} -pub trait UserCopyDefaultMoveImpl { - fn construct(&self, v: i32); -} -impl UserCopyDefaultMoveImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index fc18a0899a..65c9b482e9 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -22,17 +22,22 @@ pub struct NoCopy { #[offset(0)] pub v: i32, } +impl NoCopy { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl MoveConstructible for NoCopy { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for NoCopy { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); - return (*this).clone(); + return (this).clone(); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] @@ -42,21 +47,21 @@ pub struct PrivateCopy { pub v: i32, } impl DefaultConstructible for PrivateCopy { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(0); + fn default_constructor(this: Ptr) { + field!(this, v).write(0); } } impl MoveConstructible for PrivateCopy { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for PrivateCopy { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); - return (*this).clone(); + return (this).clone(); } } impl Default for PrivateCopy { @@ -64,7 +69,7 @@ impl Default for PrivateCopy { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -77,8 +82,8 @@ pub struct Immovable { pub v: i32, } impl DefaultConstructible for Immovable { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(0); + fn default_constructor(this: Ptr) { + field!(this, v).write(0); } } impl Default for Immovable { @@ -86,7 +91,7 @@ impl Default for Immovable { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -122,8 +127,8 @@ pub struct VecHolder { pub items: Vec, } impl DefaultConstructible for VecHolder { - fn default_constructor(this: &Ptr) { - field!((*this), items).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, items).write(Vec::new()); } } pub fn bump_0(mut p: Ptr) { @@ -158,7 +163,7 @@ fn main_0() -> i32 { let c: Value = Rc::new(RefCell::new(Container { inner: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoCopyImpl::construct(&__v.as_pointer(), 6); + NoCopy::construct(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, tag: 7, @@ -174,21 +179,13 @@ fn main_0() -> i32 { return 0; } impl CopyAssignable for PrivateCopy { - fn copy_assign(this: &Ptr, _: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _: Ptr) -> Ptr { unreachable!("PrivateCopy::copy_assign is never defined") } } impl CopyConstructible for PrivateCopy { - fn copy_constructor(this: &Ptr, _: Ptr) { + fn copy_constructor(this: Ptr, _: Ptr) { unreachable!("PrivateCopy::copy_constructor is never defined") } } -pub trait NoCopyImpl { - fn construct(&self, v: i32); -} -impl NoCopyImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/default_function_arguments.rs b/tests/unit/out/refcount/default_function_arguments.rs index 07ffcd91a5..4ea07b2fa9 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -21,10 +21,15 @@ pub struct Bar { #[offset(0)] pub v: i32, } +impl Bar { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl DefaultConstructible for Bar { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { { - BarImpl::construct(this, 1); + Bar::construct(this.clone(), 1); } } } @@ -33,7 +38,7 @@ impl Default for Bar { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&__v.as_pointer(), 1); + Bar::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -54,7 +59,7 @@ pub fn by_ref_5(b: Ptr) -> i32 { thread_local!( pub static global_bar_6: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&__v.as_pointer(), 9); + Bar::construct(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -84,6 +89,11 @@ pub struct Holder_int_ { #[offset(0)] pub v: i32, } +impl Holder_int_ { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -100,7 +110,7 @@ fn main_0() -> i32 { let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); assert!( ({ - BarImpl::construct(&__tmp_0.as_pointer(), 2); + Bar::construct(__tmp_0.as_pointer(), 2); __tmp_0.as_pointer() } .with(|__s| __s.v) @@ -110,17 +120,17 @@ fn main_0() -> i32 { let mut arr: [Bar; 3] = [ { let __v: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&__v.as_pointer(), 1); + Bar::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&__v.as_pointer(), 1); + Bar::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&__v.as_pointer(), 1); + Bar::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]; @@ -133,14 +143,14 @@ fn main_0() -> i32 { assert!( (({ let _b: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&_b.as_pointer(), 7); + Bar::construct(_b.as_pointer(), 7); by_ref_5(_b.as_pointer()) }) == 7) ); assert!( (({ let _b: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&_b.as_pointer(), 3); + Bar::construct(_b.as_pointer(), 3); by_ref_5(_b.as_pointer()) }) == 3) ); @@ -148,7 +158,7 @@ fn main_0() -> i32 { assert!( (({ let _b: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&_b.as_pointer(), 4); + Bar::construct(_b.as_pointer(), 4); by_global_ref_7(_b.as_pointer()) }) == 4) ); @@ -164,22 +174,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait BarImpl { - fn construct(&self, v: i32); -} -impl BarImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} -pub trait Holder_int_Impl { - fn construct(&self, v: i32); -} -impl Holder_int_Impl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} pub fn __cpp2rust_init_globals() { let _ = counter_2.with(|_| ()); let _ = global_bar_6.with(|_| ()); diff --git a/tests/unit/out/refcount/delete_array_order.rs b/tests/unit/out/refcount/delete_array_order.rs index 93eaae9e94..423d58b630 100644 --- a/tests/unit/out/refcount/delete_array_order.rs +++ b/tests/unit/out/refcount/delete_array_order.rs @@ -27,11 +27,11 @@ pub struct Element { pub value: i64, } impl Destructible for Element { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { printf!( b"%ld:%ld ", - (*this).with(|__s| __s.id), - (*this).with(|__s| __s.value) + this.with(|__s| __s.id), + this.with(|__s| __s.value) ); } } @@ -57,7 +57,7 @@ fn main_0() -> i32 { { let __p = a; for __i in (0..__p.len()).rev() { - Destructible::destroy(&__p.offset(__i as isize)); + Destructible::destroy(__p.offset(__i as isize)); } __p.delete(); }; diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index 5ed1b53838..76fed90ce0 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -25,7 +25,7 @@ thread_local!( #[byte_size(1)] pub struct S {} impl Destructible for S { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*global_0.with(Value::clone).borrow_mut()).postfix_inc(); } } @@ -137,8 +137,8 @@ pub struct EmptyBody { pub s: S, } impl Destructible for EmptyBody { - fn destroy(this: &Ptr) { - Destructible::destroy(&field_ptr!(this, s)); + fn destroy(this: Ptr) { + Destructible::destroy(field_ptr!(this, s)); } } #[derive( @@ -160,7 +160,7 @@ pub struct Templated_char_ { pub v: i8, } impl Destructible for Templated_char_ { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { global_0.with(|rc| { *rc.borrow_mut() = { ((global_0.with(|rc| *rc.borrow()) as usize) @@ -188,7 +188,7 @@ pub struct Templated_int_ { pub v: i32, } impl Destructible for Templated_int_ { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { global_0.with(|rc| { *rc.borrow_mut() = { ((global_0.with(|rc| *rc.borrow()) as usize) @@ -216,7 +216,7 @@ pub struct Copied { pub v: i32, } impl Destructible for Copied { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*global_0.with(Value::clone).borrow_mut()).postfix_inc(); } } @@ -246,10 +246,10 @@ pub struct Tagged { pub tag: i32, } impl Destructible for Tagged { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*order_1.with(Value::clone).borrow_mut()) [((*order_count_2.with(Value::clone).borrow_mut()).postfix_inc()) as usize] = - (*this).with(|__s| __s.tag); + this.with(|__s| __s.tag); } } #[derive( @@ -294,57 +294,57 @@ fn main_0() -> i32 { { let s: Value = Rc::new(RefCell::new(::default_constructed())); let _dtor_s = - std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 1)); { let s: Value = Rc::new(RefCell::new(::default_constructed())); let _dtor_s = - std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 2)); { let d: Value = Rc::new(RefCell::new(::default_constructed())); let _dtor_d = - std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 3)); { let o: Value = Rc::new(RefCell::new(::default_constructed())); let _dtor_o = - std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 4)); { let am: Value = Rc::new(RefCell::new(::default_constructed())); let _dtor_am = - std::mem::DropGuard::new(am.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(am.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 7)); { let e: Value = Rc::new(RefCell::new(::default_constructed())); let _dtor_e = - std::mem::DropGuard::new(e.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(e.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 8)); { let tc: Value = Rc::new(RefCell::new(::default_constructed())); let _dtor_tc = - std::mem::DropGuard::new(tc.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(tc.clone(), |__p| Destructible::destroy(__p.as_pointer())); let ti: Value = Rc::new(RefCell::new(::default_constructed())); let _dtor_ti = - std::mem::DropGuard::new(ti.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(ti.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 13)); { let a: Value = Rc::new(RefCell::new(Copied { v: 5 })); let _dtor_a = - std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(__p.as_pointer())); let b: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_b = - std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ (*b.borrow()).v } == 5)); } assert!((global_0.with(|rc| *rc.borrow()) == 15)); @@ -357,7 +357,7 @@ fn main_0() -> i32 { third: Tagged { tag: 3 }, })); let _dtor_o = - std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((order_count_2.with(|rc| *rc.borrow()) == 3)); assert!( @@ -382,7 +382,7 @@ fn main_0() -> i32 { { let cs: Value = Rc::new(RefCell::new(::default_constructed())); let _dtor_cs = - std::mem::DropGuard::new(cs.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(cs.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == (before + 1))); return 0; diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index 2576cc6c2d..519779ad0d 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -31,9 +31,9 @@ pub struct S { pub v: i32, } impl Destructible for S { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*destroyed_0.with(Value::clone).borrow_mut()).postfix_inc(); - last_1.with(|rc| *rc.borrow_mut() = (*this).with(|__s| __s.v)); + last_1.with(|rc| *rc.borrow_mut() = this.with(|__s| __s.v)); } } pub fn by_value_2(s: Ptr) -> i32 { @@ -60,6 +60,14 @@ pub struct Holder { #[offset(0)] pub v: i32, } +impl Holder { + pub fn construct(this: Ptr, s: Ptr) { + field!(this, v).write(s.with(|__s| __s.v)); + } + pub fn add(this: Ptr, s: Ptr) -> i32 { + return (this.with(|__s| __s.v) + s.with(|__s| __s.v)); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -68,7 +76,7 @@ fn main_0() -> i32 { { let s: Value = Rc::new(RefCell::new(S { v: 1 })); let _dtor_s = - std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!( ({ (({ @@ -102,7 +110,7 @@ fn main_0() -> i32 { { object!(h, Holder, |h| { let __tmp_0: Value = Rc::new(RefCell::new(S { v: 3 })); - HolderImpl::construct(h, __tmp_0.as_pointer()) + Holder::construct(h.clone(), __tmp_0.as_pointer()) }); assert!( (destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 3) @@ -110,7 +118,7 @@ fn main_0() -> i32 { assert!( (({ let _s: Value = Rc::new(RefCell::new(S { v: 4 })); - HolderImpl::add(&h.as_pointer(), _s.as_pointer()) + Holder::add(h.as_pointer(), _s.as_pointer()) }) == 7) ); assert!( @@ -120,18 +128,6 @@ fn main_0() -> i32 { assert!((destroyed_0.with(|rc| *rc.borrow()) == 2)); return 0; } -pub trait HolderImpl { - fn construct(&self, s: Ptr); - fn add(&self, s: Ptr) -> i32; -} -impl HolderImpl for Ptr { - fn construct(&self, s: Ptr) { - field!((*self), v).write(s.with(|__s| __s.v)); - } - fn add(&self, s: Ptr) -> i32 { - return ((*self).with(|__s| __s.v) + s.with(|__s| __s.v)); - } -} pub fn __cpp2rust_init_globals() { let _ = destroyed_0.with(|_| ()); let _ = last_1.with(|_| ()); diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index 26a155533c..2c30e3fc3c 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -30,10 +30,15 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.v); + } +} impl Destructible for S { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*destroyed_0.with(Value::clone).borrow_mut()).postfix_inc(); - last_1.with(|rc| *rc.borrow_mut() = (*this).with(|__s| __s.v)); + last_1.with(|rc| *rc.borrow_mut() = this.with(|__s| __s.v)); } } #[derive( @@ -60,12 +65,12 @@ pub struct Outer { #[offset(4)] pub w: i32, } -pub fn make_2(this: Ptr, mut v: i32) { - this.write(S { v: v }); +pub fn make_2(__return: Ptr, mut v: i32) { + __return.write(S { v: v }); return; } -pub fn make_outer_3(this: Ptr) { - this.write(Outer { +pub fn make_outer_3(__return: Ptr) { + __return.write(Outer { inner: S { v: 7 }, w: 8, }); @@ -111,7 +116,7 @@ fn main_0() -> i32 { { let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); x = ({ - SImpl::get(&{ + S::get({ ({ make_2(Ptr::clone(&__tmp_1.as_pointer()), 4) }); __tmp_1.as_pointer() }) @@ -185,7 +190,7 @@ fn main_0() -> i32 { { let s: Value = Rc::new(RefCell::new(S { v: 12 })); let _dtor_s = - std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); ({ let _arg0: Value = Rc::new(RefCell::new(::zero_init())); ({ make_2(Ptr::clone(&_arg0.as_pointer()), 13) }); @@ -199,14 +204,6 @@ fn main_0() -> i32 { assert!((destroyed_0.with(|rc| *rc.borrow()) == 2) && (last_1.with(|rc| *rc.borrow()) == 13)); return 0; } -pub trait SImpl { - fn get(&self) -> i32; -} -impl SImpl for Ptr { - fn get(&self) -> i32 { - return (*self).with(|__s| __s.v); - } -} pub fn __cpp2rust_init_globals() { let _ = destroyed_0.with(|_| ()); let _ = last_1.with(|_| ()); diff --git a/tests/unit/out/refcount/doubly_linked_list.rs b/tests/unit/out/refcount/doubly_linked_list.rs index 4e2e30115b..b11c88a210 100644 --- a/tests/unit/out/refcount/doubly_linked_list.rs +++ b/tests/unit/out/refcount/doubly_linked_list.rs @@ -28,6 +28,14 @@ pub struct Node { #[byte_size(8)] pub prev: Ptr, } +impl Node { + pub fn SetNext(this: Ptr, mut n: Ptr) { + field!(this, next).write((n).clone()); + } + pub fn SetPrev(this: Ptr, mut p: Ptr) { + field!(this, prev).write((p).clone()); + } +} pub fn Find_0(mut head: Ptr, mut idx: i32) -> Ptr { let mut curr: Ptr = (head).clone(); { @@ -59,8 +67,8 @@ pub fn Append_2(head: Ptr, new_node: Ptr) { 'loop_: while !((curr.with(|__s| __s.next.clone())).is_null()) { curr = curr.with(|__s| __s.next.clone()); } - ({ NodeImpl::SetNext(&curr, (new_node).clone()) }); - ({ NodeImpl::SetPrev(&new_node, (curr).clone()) }); + ({ Node::SetNext((curr).clone(), (new_node).clone()) }); + ({ Node::SetPrev((new_node).clone(), (curr).clone()) }); } pub fn Delete_3(mut head: Ptr, mut val: i32) -> Ptr { let mut curr: Ptr = (head).clone(); @@ -226,16 +234,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait NodeImpl { - fn SetNext(&self, n: Ptr); - fn SetPrev(&self, p: Ptr); -} -impl NodeImpl for Ptr { - fn SetNext(&self, mut n: Ptr) { - field!((*self), next).write((n).clone()); - } - fn SetPrev(&self, mut p: Ptr) { - field!((*self), prev).write((p).clone()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs index c59595b090..8eb3283d6f 100644 --- a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs @@ -27,7 +27,9 @@ fn main_0() -> i32 { let mut __tmp_2 = { v.decay().begin() }; let mut __tmp_3 = { v.decay().end() }; let mut __it = (__tmp_2).clone(); - while __it != __tmp_3 && !CppEq::equal(&__it.iter_deref(), &__tmp_4.as_pointer()) { + while __it != __tmp_3 + && !CppEq::equal(__it.iter_deref(), __tmp_4.as_pointer().clone()) + { __it.iter_inc(); } __it @@ -43,7 +45,7 @@ fn main_0() -> i32 { for __i in (1..__n).rev() { let __j = (std::hash::BuildHasher::hash_one(&__random, __i) % (__i + 1) as u64) as isize; - Swappable::swap(&__tmp_5.iter_at(__i), __tmp_5.iter_at(__j)); + Swappable::swap(__tmp_5.iter_at(__i), __tmp_5.iter_at(__j)); } }; { diff --git a/tests/unit/out/refcount/enum_underlying_type.rs b/tests/unit/out/refcount/enum_underlying_type.rs index 916f8cc14f..fa3c78775e 100644 --- a/tests/unit/out/refcount/enum_underlying_type.rs +++ b/tests/unit/out/refcount/enum_underlying_type.rs @@ -32,8 +32,8 @@ pub struct HoldsEmpty { pub e: Empty, } impl DefaultConstructible for HoldsEmpty { - fn default_constructor(this: &Ptr) { - field!((*this), e).write(::default()); + fn default_constructor(this: Ptr) { + field!(this, e).write(::default()); } } impl Default for HoldsEmpty { diff --git a/tests/unit/out/refcount/exprs.rs b/tests/unit/out/refcount/exprs.rs index af35f930f7..7d400a4dd7 100644 --- a/tests/unit/out/refcount/exprs.rs +++ b/tests/unit/out/refcount/exprs.rs @@ -43,6 +43,14 @@ pub struct Y { #[byte_size(8)] pub p: Ptr, } +impl Y { + pub fn foo(this: Ptr) -> Ptr { + return field_ptr!(this, x); + } + pub fn ptr(this: Ptr) -> Ptr { + return (field_ptr!(this, x)); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -74,25 +82,13 @@ fn main_0() -> i32 { p: (x.as_pointer()), })); (*y.borrow_mut()).x.x = 5; - field!(({ YImpl::foo(&y.as_pointer(),) }), x).write(1); + field!(({ Y::foo(y.as_pointer(),) }), x).write(1); field!({ (*y.borrow()).p.clone() }, x).write(10); let mut p3: Ptr = (y.as_pointer()); field!(p3.with(|__s| __s.p.clone()), x).write(100); - field!(({ YImpl::ptr(&y.as_pointer(),) }), x).write(1); - field!(({ YImpl::ptr(&y.as_pointer(),) }), x).write(50); + field!(({ Y::ptr(y.as_pointer(),) }), x).write(1); + field!(({ Y::ptr(y.as_pointer(),) }), x).write(50); assert!(({ (*x.borrow()).x } == 100)); return 0; } -pub trait YImpl { - fn foo(&self) -> Ptr; - fn ptr(&self) -> Ptr; -} -impl YImpl for Ptr { - fn foo(&self) -> Ptr { - return field_ptr!((*self), x); - } - fn ptr(&self) -> Ptr { - return (field_ptr!((*self), x)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/field_method_receiver.rs b/tests/unit/out/refcount/field_method_receiver.rs index 976a9a5f6b..b2b7935a1e 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -23,6 +23,26 @@ pub struct Counter { #[offset(0)] pub n: i32, } +impl Counter { + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.n); + } + pub fn add(this: Ptr, mut k: i32) { + { + field!(this, n).with_mut(|__v| *__v = *__v + k) + }; + } + pub fn self_(this: Ptr) -> Ptr { + return (this).clone(); + } + pub fn take(this: Ptr, mut other: Ptr) { + { + let __rhs = other.with(|__s| __s.n); + field!(this, n).with_mut(|__v| *__v = *__v + __rhs) + }; + field!(other, n).write(0); + } +} #[derive( Clone, Record, @@ -51,16 +71,21 @@ pub struct S { #[byte_size(24)] pub v: Vec, } +impl S { + pub fn bump(this: Ptr) { + ({ Counter::add(field_ptr!(this, c), this.with(|__s| __s.tag)) }); + } +} impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { - field!((*this), tag).write(0_i32); - field!((*this), c).write(::default()); - field!((*this), arr).write( + fn default_constructor(this: Ptr) { + field!(this, tag).write(0_i32); + field!(this, c).write(::default()); + field!(this, arr).write( (0..2) .map(|_| ::default()) .collect::>(), ); - field!((*this), v).write(Vec::new()); + field!(this, v).write(Vec::new()); } } impl Default for S { @@ -78,28 +103,28 @@ impl Default for S { } } pub fn run_0(mut o: Ptr) { - ({ CounterImpl::add(&field_ptr!(o, c), 2) }); - assert!((({ CounterImpl::get(&field_ptr!(o, c),) }) == 2)); - ({ CounterImpl::add(&array_field_ptr!(o, arr).offset((1) as isize), 5) }); - assert!((({ CounterImpl::get(&array_field_ptr!(o, arr).offset((1) as isize),) }) == 5)); - ({ CounterImpl::add(&({ CounterImpl::self_(&field_ptr!(o, c)) }), 1) }); - assert!((({ CounterImpl::get(&field_ptr!(o, c),) }) == 3)); - assert!(({ ({ CounterImpl::self_(&field_ptr!(o, c),) }) } == { (field_ptr!(o, c)) })); + ({ Counter::add(field_ptr!(o, c), 2) }); + assert!((({ Counter::get(field_ptr!(o, c),) }) == 2)); + ({ Counter::add(array_field_ptr!(o, arr).offset((1) as isize), 5) }); + assert!((({ Counter::get(array_field_ptr!(o, arr).offset((1) as isize),) }) == 5)); + ({ Counter::add(({ Counter::self_(field_ptr!(o, c)) }), 1) }); + assert!((({ Counter::get(field_ptr!(o, c),) }) == 3)); + assert!(({ ({ Counter::self_(field_ptr!(o, c),) }) } == { (field_ptr!(o, c)) })); ({ - CounterImpl::take( - &array_field_ptr!(o, arr).offset((0) as isize), + Counter::take( + array_field_ptr!(o, arr).offset((0) as isize), (array_field_ptr!(o, arr).offset((1) as isize)), ) }); assert!( - (({ CounterImpl::get(&array_field_ptr!(o, arr).offset((0) as isize),) }) == 5) - && (({ CounterImpl::get(&array_field_ptr!(o, arr).offset((1) as isize),) }) == 0) + (({ Counter::get(array_field_ptr!(o, arr).offset((0) as isize),) }) == 5) + && (({ Counter::get(array_field_ptr!(o, arr).offset((1) as isize),) }) == 0) ); - ({ CounterImpl::take(&field_ptr!(o, c), (field_ptr!(o, c))) }); - assert!((({ CounterImpl::get(&field_ptr!(o, c),) }) == 0)); - ({ SImpl::bump(&o) }); - assert!((({ CounterImpl::get(&field_ptr!(o, c),) }) == 1)); - match (Rc::new(RefCell::new(({ CounterImpl::get(&field_ptr!(o, c)) }))).as_pointer(),) { + ({ Counter::take(field_ptr!(o, c), (field_ptr!(o, c))) }); + assert!((({ Counter::get(field_ptr!(o, c),) }) == 0)); + ({ S::bump((o).clone()) }); + assert!((({ Counter::get(field_ptr!(o, c),) }) == 1)); + match (Rc::new(RefCell::new(({ Counter::get(field_ptr!(o, c)) }))).as_pointer(),) { (__tmp_0,) => { MoveConstructible::push_moved(&field_ref!(o, v).as_pointer(), (__tmp_0).clone()) } @@ -125,38 +150,4 @@ fn main_0() -> i32 { heap.delete(); return 0; } -pub trait CounterImpl { - fn get(&self) -> i32; - fn add(&self, k: i32); - fn self_(&self) -> Ptr; - fn take(&self, other: Ptr); -} -impl CounterImpl for Ptr { - fn get(&self) -> i32 { - return (*self).with(|__s| __s.n); - } - fn add(&self, mut k: i32) { - { - field!((*self), n).with_mut(|__v| *__v = *__v + k) - }; - } - fn self_(&self) -> Ptr { - return (*self).clone(); - } - fn take(&self, mut other: Ptr) { - { - let __rhs = other.with(|__s| __s.n); - field!((*self), n).with_mut(|__v| *__v = *__v + __rhs) - }; - field!(other, n).write(0); - } -} -pub trait SImpl { - fn bump(&self); -} -impl SImpl for Ptr { - fn bump(&self) { - ({ CounterImpl::add(&field_ptr!((*self), c), (*self).with(|__s| __s.tag)) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index 2941553e5a..3ec270e01d 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -89,14 +89,28 @@ pub struct Outer { #[array_len(4)] pub buf: Box<[i32]>, } +impl Outer { + pub fn next(this: Ptr) -> i32 { + return (array_elem!(this, buf, field!(this, x).with_mut(|__v| __v.postfix_inc())).read()); + } + pub fn sum(this: Ptr) -> i32 { + return (this.with(|__s| __s.x) + this.with(|__s| __s.inner.a)); + } + pub fn push(this: Ptr, mut k: i32) { + ({ + let __tmp_0: Value = Rc::new(RefCell::new((k + this.with(|__s| __s.x)))); + MoveConstructible::push_moved(&field_ref!(this, v).as_pointer(), __tmp_0.as_pointer()) + }); + } +} impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { - field!((*this), x).write(0_i32); - field!((*this), inner).write(::default()); - field!((*this), items).write((0..3).map(|_| ::default()).collect::>()); - field!((*this), v).write(Vec::new()); - field!((*this), cursor).write(Ptr::::null()); - field!((*this), buf).write((0..4).map(|_| 0_i32).collect::>()); + fn default_constructor(this: Ptr) { + field!(this, x).write(0_i32); + field!(this, inner).write(::default()); + field!(this, items).write((0..3).map(|_| ::default()).collect::>()); + field!(this, v).write(Vec::new()); + field!(this, cursor).write(Ptr::::null()); + field!(this, buf).write((0..4).map(|_| 0_i32).collect::>()); } } impl Default for Outer { @@ -180,19 +194,19 @@ fn main_0() -> i32 { }) ); (*o.borrow_mut()).x = 0; - let mut first: i32 = ({ OuterImpl::next(&o.as_pointer()) }); + let mut first: i32 = ({ Outer::next(o.as_pointer()) }); assert!((first == 0) && ({ (*o.borrow()).x } == 1)); let __rhs = ({ (*o.borrow()).inner.a } + ({ bump_1((o.as_pointer())) })); (*o.borrow_mut()).x = __rhs; assert!(({ (*o.borrow()).x } == 4)); - ({ OuterImpl::push(&o.as_pointer(), { (*o.borrow()).inner.a }) }); + ({ Outer::push(o.as_pointer(), { (*o.borrow()).inner.a }) }); assert!( ({ ((*o.borrow()).v.len() == 1_usize) && ((vec_elem!(o.as_pointer(), v, 0_usize).read()) == 7) }) ); - assert!((({ OuterImpl::sum(&o.as_pointer(),) }) == 7)); + assert!((({ Outer::sum(o.as_pointer(),) }) == 7)); let y: Value = Rc::new(RefCell::new(0)); { let mut __tmp_1 = { @@ -250,31 +264,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait OuterImpl { - fn next(&self) -> i32; - fn sum(&self) -> i32; - fn push(&self, k: i32); -} -impl OuterImpl for Ptr { - fn next(&self) -> i32 { - return (array_elem!( - (*self), - buf, - field!((*self), x).with_mut(|__v| __v.postfix_inc()) - ) - .read()); - } - fn sum(&self) -> i32 { - return ((*self).with(|__s| __s.x) + (*self).with(|__s| __s.inner.a)); - } - fn push(&self, mut k: i32) { - ({ - let __tmp_0: Value = Rc::new(RefCell::new((k + (*self).with(|__s| __s.x)))); - MoveConstructible::push_moved( - &field_ref!((*self), v).as_pointer(), - __tmp_0.as_pointer(), - ) - }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index 83307b68c6..504af54ae4 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -23,9 +23,14 @@ pub struct P { #[offset(0)] pub x: i32, } +impl P { + pub fn operator_eq(this: Ptr, o: Ptr

) -> bool { + return ({ this.with(|__s| __s.x) } == { o.with(|__s| __s.x) }); + } +} impl CppEq for P { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - PImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + P::operator_eq(__lhs.clone(), __rhs.clone()) } } pub fn main() { @@ -54,7 +59,9 @@ fn main_0() -> i32 { { let mut __tmp_3 = { (*v_end.borrow()).clone() }; let mut __it = ({ (*v_begin.borrow()).clone() }); - while __it != __tmp_3 && !CppEq::equal(&__it.iter_deref(), &__tmp_4.as_pointer()) { + while __it != __tmp_3 + && !CppEq::equal(__it.iter_deref(), __tmp_4.as_pointer().clone()) + { __it.iter_inc(); } __it @@ -99,7 +106,7 @@ fn main_0() -> i32 { let mut __tmp_9 = { v.decay().begin() }; let mut __it = (__tmp_8).clone(); while __it != __tmp_9 - && !CppEq::equal(&__it.iter_deref(), &__tmp_10.as_pointer()) + && !CppEq::equal(__it.iter_deref(), __tmp_10.as_pointer().clone()) { __it.iter_inc(); } @@ -115,7 +122,8 @@ fn main_0() -> i32 { let mut __tmp_11 = { w.decay().begin().iter_add(2_isize) }; let mut __tmp_12 = { w.decay().end() }; let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 && !CppEq::equal(&__it.iter_deref(), &__tmp_13.as_pointer()) + while __it != __tmp_12 + && !CppEq::equal(__it.iter_deref(), __tmp_13.as_pointer().clone()) { __it.iter_inc(); } @@ -130,7 +138,8 @@ fn main_0() -> i32 { let mut __tmp_14 = { w.decay().begin().iter_add(2_isize) }; let mut __tmp_15 = { w.decay().end() }; let mut __it = (__tmp_14).clone(); - while __it != __tmp_15 && !CppEq::equal(&__it.iter_deref(), &__tmp_16.as_pointer()) + while __it != __tmp_15 + && !CppEq::equal(__it.iter_deref(), __tmp_16.as_pointer().clone()) { __it.iter_inc(); } @@ -145,7 +154,8 @@ fn main_0() -> i32 { let mut __tmp_17 = { w.decay().begin().iter_add(2_isize) }; let mut __tmp_18 = { w.decay().begin().iter_add(4_isize) }; let mut __it = (__tmp_17).clone(); - while __it != __tmp_18 && !CppEq::equal(&__it.iter_deref(), &__tmp_19.as_pointer()) + while __it != __tmp_18 + && !CppEq::equal(__it.iter_deref(), __tmp_19.as_pointer().clone()) { __it.iter_inc(); } @@ -166,7 +176,7 @@ fn main_0() -> i32 { let mut __tmp_21 = { p.decay().end() }; let mut __it = (__tmp_20).clone(); while __it != __tmp_21 - && !CppEq::equal(&__it.iter_deref(), &(__tmp_22.as_pointer())) + && !CppEq::equal(__it.iter_deref(), (__tmp_22.as_pointer()).clone()) { __it.iter_inc(); } @@ -176,12 +186,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait PImpl { - fn operator_eq(&self, o: Ptr

) -> bool; -} -impl PImpl for Ptr

{ - fn operator_eq(&self, o: Ptr

) -> bool { - return ({ (*self).with(|__s| __s.x) } == { o.with(|__s| __s.x) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/fn_ptr.rs b/tests/unit/out/refcount/fn_ptr.rs index 38db1f7d81..8a188a60a8 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -47,6 +47,11 @@ pub struct HashHolder_unsigned_long__ptr__bool__ { #[byte_size(8)] pub h: FnPtr u64>, } +impl HashHolder_unsigned_long__ptr__bool__ { + pub fn construct(this: Ptr, h: Ptr u64>>) { + field!(this, h).write((h.read())); + } +} thread_local!( pub static total_7: Value = Rc::new(RefCell::new(0)); ); @@ -95,7 +100,7 @@ fn main_0() -> i32 { let __tmp_0: Value u64>> = Rc::new(RefCell::new( (FnPtr:: usize>::new(identity_hash_6)).cast:: u64>(), )); - HashHolder_unsigned_long__ptr__bool__Impl::construct(hh, __tmp_0.as_pointer()) + HashHolder_unsigned_long__ptr__bool__::construct(hh.clone(), __tmp_0.as_pointer()) }); assert!((({ { (*hh.borrow()).h.clone() }.call(true,) }) == 1_u64)); let mut handler: FnPtr = FnPtr::::new(add_to_total_8); @@ -129,14 +134,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait HashHolder_unsigned_long__ptr__bool__Impl { - fn construct(&self, h: Ptr u64>>); -} -impl HashHolder_unsigned_long__ptr__bool__Impl for Ptr { - fn construct(&self, h: Ptr u64>>) { - field!((*self), h).write((h.read())); - } -} pub fn __cpp2rust_init_globals() { let _ = total_7.with(|_| ()); } diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index a2dfea5e77..38d211ae47 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -65,18 +65,26 @@ pub struct MoveOnly { #[offset(0)] pub data_: i32, } +impl MoveOnly { + pub fn construct(this: Ptr, mut data: i32) { + field!(this, data_).write(data); + } + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.data_); + } +} impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, x: Ptr) { - field!((*this), data_).write(x.with(|__s| __s.data_)); + fn move_constructor(this: Ptr, x: Ptr) { + field!(this, data_).write(x.with(|__s| __s.data_)); field!(x, data_).write(0); } } -pub fn make_move_only_2(this: Ptr) { - MoveOnlyImpl::construct(&this, 4); +pub fn make_move_only_2(__return: Ptr) { + MoveOnly::construct(__return.clone(), 4); return; } -pub fn scale_move_only_3(this: Ptr, x: Ptr) { - MoveOnlyImpl::construct(&this, (({ MoveOnlyImpl::get(&x) }) * 10)); +pub fn scale_move_only_3(__return: Ptr, x: Ptr) { + MoveOnly::construct(__return.clone(), (({ MoveOnly::get((x).clone()) }) * 10)); return; } pub fn main() { @@ -109,29 +117,17 @@ fn main_0() -> i32 { assert!((({ h1.cb.call(3,) }) == -3_i32)); assert!(({ (h1.cb).clone() } == { (h2.cb).clone() })); let mut mk: FnPtr)> = FnPtr::)>::new(make_move_only_2); - object!(m, MoveOnly, |m| ({ mk.call(Ptr::clone(m),) })); - assert!((({ MoveOnlyImpl::get(&m.as_pointer(),) }) == 4)); + object!(m, MoveOnly, |m| ({ mk.call(Ptr::clone(&m.clone()),) })); + assert!((({ MoveOnly::get(m.as_pointer(),) }) == 4)); let mut sc: FnPtr, Ptr)> = FnPtr::, Ptr)>::new(scale_move_only_3); object!(n, MoveOnly, |n| ({ let _arg0: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_arg0.as_pointer(), Moved(m.as_pointer())); - sc.call(Ptr::clone(n), _arg0.as_pointer()) + ConstructFrom::construct_from(_arg0.as_pointer(), Moved(m.as_pointer())); + sc.call(Ptr::clone(&n.clone()), _arg0.as_pointer()) })); - assert!((({ MoveOnlyImpl::get(&n.as_pointer(),) }) == 40)); - assert!((({ MoveOnlyImpl::get(&m.as_pointer(),) }) == 0)); + assert!((({ MoveOnly::get(n.as_pointer(),) }) == 40)); + assert!((({ MoveOnly::get(m.as_pointer(),) }) == 0)); return 0; } -pub trait MoveOnlyImpl { - fn construct(&self, data: i32); - fn get(&self) -> i32; -} -impl MoveOnlyImpl for Ptr { - fn construct(&self, mut data: i32) { - field!((*self), data_).write(data); - } - fn get(&self) -> i32 { - return (*self).with(|__s| __s.data_); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/fn_ref.rs b/tests/unit/out/refcount/fn_ref.rs index ed88a34c1b..5abd8b284b 100644 --- a/tests/unit/out/refcount/fn_ref.rs +++ b/tests/unit/out/refcount/fn_ref.rs @@ -38,6 +38,11 @@ pub struct Holder { #[byte_size(8)] pub f: FnPtr i32>, } +impl Holder { + pub fn run(this: Ptr, mut x: i32) -> i32 { + return ({ this.with(|__s| __s.f.clone()).call(x) }); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -53,15 +58,7 @@ fn main_0() -> i32 { let h: Value = Rc::new(RefCell::new(Holder { f: FnPtr:: i32>::new(twice_1), })); - assert!((({ HolderImpl::run(&h.as_pointer(), 8,) }) == 16)); + assert!((({ Holder::run(h.as_pointer(), 8,) }) == 16)); return 0; } -pub trait HolderImpl { - fn run(&self, x: i32) -> i32; -} -impl HolderImpl for Ptr { - fn run(&self, mut x: i32) -> i32 { - return ({ (*self).with(|__s| __s.f.clone()).call(x) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/for_body_destructor.rs b/tests/unit/out/refcount/for_body_destructor.rs index 282cb65648..10ab5ac542 100644 --- a/tests/unit/out/refcount/for_body_destructor.rs +++ b/tests/unit/out/refcount/for_body_destructor.rs @@ -24,9 +24,14 @@ pub struct Guard { #[offset(0)] pub digit: i32, } +impl Guard { + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.digit) != 0); + } +} impl Destructible for Guard { - fn destroy(this: &Ptr) { - printf!(b"%d ", (*this).with(|__s| __s.digit)); + fn destroy(this: Ptr) { + printf!(b"%d ", this.with(|__s| __s.digit)); } } pub fn step_0(i: Ptr) { @@ -47,11 +52,11 @@ fn main_0() -> i32 { 'for_body: { let first: Value = Rc::new(RefCell::new(Guard { digit: 1 })); let _dtor_first = std::mem::DropGuard::new(first.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); let second: Value = Rc::new(RefCell::new(Guard { digit: 2 })); let _dtor_second = std::mem::DropGuard::new(second.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if ((*i.borrow()) == 0) { break 'for_body; @@ -67,7 +72,7 @@ fn main_0() -> i32 { 'for_body: { let g: Value = Rc::new(RefCell::new(Guard { digit: 3 })); let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); break 'loop_; } @@ -81,7 +86,7 @@ fn main_0() -> i32 { 'for_body: { let outer: Value = Rc::new(RefCell::new(Guard { digit: 4 })); let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); { let j: Value = Rc::new(RefCell::new(0)); @@ -89,7 +94,7 @@ fn main_0() -> i32 { 'for_body: { let inner: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if ((*j.borrow()) == 0) { break 'for_body; @@ -111,13 +116,13 @@ fn main_0() -> i32 { 'for_body: { let outer: Value = Rc::new(RefCell::new(Guard { digit: 4 })); let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); let mut j: i32 = 0; 'loop_: while ((*j.prefix_inc()) < 3) { let inner: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if (j == 1) { continue 'loop_; @@ -129,7 +134,7 @@ fn main_0() -> i32 { __do_while = false; let inner: Value = Rc::new(RefCell::new(Guard { digit: 6 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); continue 'loop_; } @@ -140,7 +145,7 @@ fn main_0() -> i32 { let mut value: i32 = (value.read()); let inner: Value = Rc::new(RefCell::new(Guard { digit: value })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if (value == 1) { continue 'loop_; @@ -158,15 +163,15 @@ fn main_0() -> i32 { 'loop_: loop { let condition: Value = Rc::new(RefCell::new(Guard { digit: i })); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); - if !({ GuardImpl::to_bool(&condition.as_pointer()) }) { + if !({ Guard::to_bool(condition.as_pointer()) }) { break; } 'for_body: { let body: Value = Rc::new(RefCell::new(Guard { digit: 4 })); let _dtor_body = std::mem::DropGuard::new(body.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if (i == 2) { break 'for_body; @@ -183,12 +188,12 @@ fn main_0() -> i32 { { let init: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_init = - std::mem::DropGuard::new(init.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(init.clone(), |__p| Destructible::destroy(__p.as_pointer())); 'loop_: while ((*i.borrow()) < 2) { 'for_body: { let body: Value = Rc::new(RefCell::new(Guard { digit: 6 })); let _dtor_body = std::mem::DropGuard::new(body.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); } ({ step_0(i.as_pointer()) }); @@ -202,19 +207,11 @@ fn main_0() -> i32 { digit: (*j.prefix_inc()), })); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); continue 'loop_; } } printf!(b"\n"); return 0; } -pub trait GuardImpl { - fn to_bool(&self) -> bool; -} -impl GuardImpl for Ptr { - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.digit) != 0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index 51e5a772ea..e955dbad8d 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -29,9 +29,9 @@ pub struct S { pub a: i32, } impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(Vec::new()); - field!((*this), a).write(0_i32); + fn default_constructor(this: Ptr) { + field!(this, v).write(Vec::new()); + field!(this, a).write(0_i32); } } pub fn main() { diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index ddc09a1228..2830c24e3f 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -22,18 +22,25 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl Tracked { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } @@ -43,6 +50,16 @@ pub fn chosen_overload_0(_a0: Ptr) -> Overload { pub fn chosen_overload_1(_a0: Ptr) -> Overload { return Overload_kRvalueOverload; } +impl Holder { + pub fn construct_1(this: Ptr, x: Ptr) { + ConstructFrom::construct_from(field_ptr!(this, t), (x).clone()); + } +} +impl Holder { + pub fn construct_2(this: Ptr, x: Ptr) { + ConstructFrom::construct_from(field_ptr!(this, t), Moved((x).clone())); + } +} #[derive( Record, ByteRepr, @@ -74,12 +91,12 @@ pub fn forward_twice_4(x: Ptr) -> Overload { pub fn forward_twice_5(x: Ptr) -> Overload { return ({ forward_once_3((x).clone()) }); } -pub fn forward_into_ctor_6(this: Ptr, x: Ptr) { - HolderImpl::construct_1(&this, (x).clone()); +pub fn forward_into_ctor_6(__return: Ptr, x: Ptr) { + Holder::construct_1(__return.clone(), (x).clone()); return; } -pub fn forward_into_ctor_7(this: Ptr, x: Ptr) { - HolderImpl::construct_2(&this, (x).clone()); +pub fn forward_into_ctor_7(__return: Ptr, x: Ptr) { + Holder::construct_2(__return.clone(), (x).clone()); return; } pub fn main() { @@ -95,7 +112,7 @@ fn main_0() -> i32 { assert!( ((({ let _x: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_x.as_pointer(), 8); + Tracked::construct(_x.as_pointer(), 8); forward_once_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -109,14 +126,14 @@ fn main_0() -> i32 { assert!( ((({ let _x: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_x.as_pointer(), 10); + Tracked::construct(_x.as_pointer(), 10); forward_twice_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); object!(kept, Tracked(11)); object!(from_lvalue, Holder, |from_lvalue| ({ - forward_into_ctor_6(Ptr::clone(from_lvalue), kept.as_pointer()) + forward_into_ctor_6(Ptr::clone(&from_lvalue.clone()), kept.as_pointer()) })); assert!(({ (*from_lvalue.borrow()).t.v } == 11)); assert!(({ (*from_lvalue.borrow()).t.copies } == 1)); @@ -124,34 +141,12 @@ fn main_0() -> i32 { assert!(({ (*kept.borrow()).v } == 11)); object!(from_rvalue, Holder, |from_rvalue| ({ let _x: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_x.as_pointer(), 12); - forward_into_ctor_7(Ptr::clone(from_rvalue), _x.as_pointer()) + Tracked::construct(_x.as_pointer(), 12); + forward_into_ctor_7(Ptr::clone(&from_rvalue.clone()), _x.as_pointer()) })); assert!(({ (*from_rvalue.borrow()).t.v } == 12)); assert!(({ (*from_rvalue.borrow()).t.copies } == 0)); assert!(({ (*from_rvalue.borrow()).t.moves } == 1)); return 0; } -pub trait HolderImpl { - fn construct_1(&self, x: Ptr); - fn construct_2(&self, x: Ptr); -} -impl HolderImpl for Ptr { - fn construct_1(&self, x: Ptr) { - ConstructFrom::construct_from(&field_ptr!(self, t), (x).clone()); - } - fn construct_2(&self, x: Ptr) { - ConstructFrom::construct_from(&field_ptr!(self, t), Moved((x).clone())); - } -} -pub trait TrackedImpl { - fn construct(&self, v: i32); -} -impl TrackedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index b3f6eec60d..9b665040ef 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -22,18 +22,25 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl Tracked { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } @@ -74,7 +81,7 @@ fn main_0() -> i32 { assert!( ((({ let _x: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_x.as_pointer(), 4); + Tracked::construct(_x.as_pointer(), 4); forward_by_decltype_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -88,7 +95,7 @@ fn main_0() -> i32 { assert!( ((({ let _x: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_x.as_pointer(), 6); + Tracked::construct(_x.as_pointer(), 6); forward_abbreviated_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -97,21 +104,11 @@ fn main_0() -> i32 { assert!( (({ let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_args_1.as_pointer(), 8); + Tracked::construct(_args_1.as_pointer(), 8); forward_abbreviated_pack_6(c.as_pointer(), _args_1.as_pointer()) }) == ((Overload_kLvalueOverload as i32) + (Overload_kRvalueOverload as i32))) ); assert!(({ (*c.borrow()).v } == 7)); return 0; } -pub trait TrackedImpl { - fn construct(&self, v: i32); -} -impl TrackedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index dfcbcd792a..8c178d0bd4 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -24,18 +24,25 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl Tracked { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } @@ -51,8 +58,8 @@ pub fn chosen_overload_2(_a0: Ptr) -> Overload { pub fn chosen_overload_3(_a0: Ptr) -> Overload { return Overload_kIntRvalueOverload; } -pub fn copy_or_move_into_param_4(this: Ptr, t: Ptr) { - ConstructFrom::construct_from(&this, Moved((t).clone())); +pub fn copy_or_move_into_param_4(__return: Ptr, t: Ptr) { + ConstructFrom::construct_from(__return.clone(), Moved((t).clone())); return; } pub fn main() { @@ -72,8 +79,8 @@ 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())); - copy_or_move_into_param_4(Ptr::clone(moved), _t.as_pointer()) + ConstructFrom::construct_from(_t.as_pointer(), Moved(b.as_pointer())); + copy_or_move_into_param_4(Ptr::clone(&moved.clone()), _t.as_pointer()) })); assert!(({ (*moved.borrow()).v } == 6)); assert!(({ (*moved.borrow()).copies } == 0)); @@ -82,8 +89,8 @@ 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()); - copy_or_move_into_param_4(Ptr::clone(copied), _t.as_pointer()) + ConstructFrom::construct_from(_t.as_pointer(), c.as_pointer()); + copy_or_move_into_param_4(Ptr::clone(&copied.clone()), _t.as_pointer()) })); assert!(({ (*copied.borrow()).v } == 7)); assert!(({ (*copied.borrow()).copies } == 1)); @@ -102,14 +109,4 @@ fn main_0() -> i32 { assert!(({ ((*i.borrow()) == 8) })); return 0; } -pub trait TrackedImpl { - fn construct(&self, v: i32); -} -impl TrackedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index d89c63fc27..69e43be7ae 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -24,18 +24,25 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl Tracked { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } @@ -87,6 +94,12 @@ pub fn forward_pack_7( }; return digits; } +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())); + } +} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] @@ -100,8 +113,8 @@ pub struct Pair { #[byte_size(12)] pub b: Tracked, } -pub fn forward_pack_into_ctor_8(this: Ptr, args_0: Ptr, args_1: Ptr) { - PairImpl::construct(&this, (args_0).clone(), (args_1).clone()); +pub fn forward_pack_into_ctor_8(__return: Ptr, args_0: Ptr, args_1: Ptr) { + Pair::construct(__return.clone(), (args_0).clone(), (args_1).clone()); return; } pub fn main() { @@ -116,7 +129,7 @@ fn main_0() -> i32 { assert!( (({ let _args: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_args.as_pointer(), 2); + Tracked::construct(_args.as_pointer(), 2); forward_pack_6(_args.as_pointer()) }) == (Overload_kRvalueOverload as i32)) ); @@ -124,7 +137,7 @@ fn main_0() -> i32 { assert!( (({ let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_args_1.as_pointer(), 4); + Tracked::construct(_args_1.as_pointer(), 4); let _args_3: Value = Rc::new(RefCell::new(5)); forward_pack_7( a.as_pointer(), @@ -139,8 +152,12 @@ fn main_0() -> i32 { object!(lhs, Tracked(6)); object!(p, Pair, |p| ({ let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_args_1.as_pointer(), 7); - forward_pack_into_ctor_8(Ptr::clone(p), lhs.as_pointer(), _args_1.as_pointer()) + Tracked::construct(_args_1.as_pointer(), 7); + forward_pack_into_ctor_8( + Ptr::clone(&p.clone()), + lhs.as_pointer(), + _args_1.as_pointer(), + ) })); assert!(({ (*p.borrow()).a.v } == 6)); assert!(({ (*p.borrow()).a.copies } == 1)); @@ -150,23 +167,4 @@ fn main_0() -> i32 { assert!(({ (*lhs.borrow()).v } == 6)); return 0; } -pub trait PairImpl { - fn construct(&self, x: Ptr, y: Ptr); -} -impl PairImpl for Ptr { - fn construct(&self, x: Ptr, y: Ptr) { - ConstructFrom::construct_from(&field_ptr!(self, a), (x).clone()); - ConstructFrom::construct_from(&field_ptr!(self, b), Moved((y).clone())); - } -} -pub trait TrackedImpl { - fn construct(&self, v: i32); -} -impl TrackedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index be8d73196f..c9e3cff5e4 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -36,7 +36,7 @@ pub struct V { pub x: i32, } impl CppEq for V { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_1(__lhs.clone(), __rhs.clone()) } } diff --git a/tests/unit/out/refcount/function_overloading.rs b/tests/unit/out/refcount/function_overloading.rs index 36a73a6ce5..34902af520 100644 --- a/tests/unit/out/refcount/function_overloading.rs +++ b/tests/unit/out/refcount/function_overloading.rs @@ -35,6 +35,14 @@ pub fn bar_4(x: Ptr) -> i32 { )] #[byte_size(1)] pub struct Foo {} +impl Foo { + pub fn foo_1(this: Ptr) {} + pub fn foo_2(this: Ptr) {} + pub fn method_3(this: Ptr, mut x: i32) {} + pub fn method_4(this: Ptr, mut x: i32) {} + pub fn method2_5(this: Ptr, mut x: i32, mut y: i32) {} + pub fn method2_6(this: Ptr, mut x: f64, mut y: f64) {} +} pub fn func_5(mut x: i32) -> i32 { return 1; } @@ -57,27 +65,11 @@ fn main_0() -> i32 { out += ((bar + ({ foo_0(0) })) + ({ foo_1((x.as_pointer())) })); let foo1: Value = Rc::new(RefCell::new(::default())); let foo2: Value = Rc::new(RefCell::new(::default())); - ({ FooImpl::foo_2(&foo1.as_pointer()) }); - ({ FooImpl::method_3(&foo1.as_pointer(), 1) }); - ({ FooImpl::foo_1(&foo2.as_pointer()) }); - ({ FooImpl::method_4(&foo2.as_pointer(), 2) }); + ({ Foo::foo_2(foo1.as_pointer()) }); + ({ Foo::method_3(foo1.as_pointer(), 1) }); + ({ Foo::foo_1(foo2.as_pointer()) }); + ({ Foo::method_4(foo2.as_pointer(), 2) }); assert!((out == 13)); return 0; } -pub trait FooImpl { - fn foo_1(&self); - fn foo_2(&self); - fn method_3(&self, x: i32); - fn method_4(&self, x: i32); - fn method2_5(&self, x: i32, y: i32); - fn method2_6(&self, x: f64, y: f64); -} -impl FooImpl for Ptr { - fn foo_1(&self) {} - fn foo_2(&self) {} - fn method_3(&self, mut x: i32) {} - fn method_4(&self, mut x: i32) {} - fn method2_5(&self, mut x: i32, mut y: i32) {} - fn method2_6(&self, mut x: f64, mut y: f64) {} -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/global_call_temporaries.rs b/tests/unit/out/refcount/global_call_temporaries.rs index 730dd447c5..3ffa8ce93b 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -18,7 +18,7 @@ thread_local!( ({ __tmp_0 = Rc::new(RefCell::new(0)); __tmp_1 = Rc::new(RefCell::new(0)); - if CppLess::less(&__tmp_0.as_pointer(), &__tmp_1.as_pointer()) { + if CppLess::less(__tmp_0.as_pointer().clone(), __tmp_1.as_pointer().clone()) { __tmp_0.as_pointer() } else { __tmp_1.as_pointer() @@ -43,7 +43,7 @@ thread_local!( let __rhs = { __tmp_2 = Rc::new(RefCell::new(6)); __tmp_3 = Rc::new(RefCell::new(5)); - (if CppLess::less(&__tmp_2.as_pointer(), &__tmp_3.as_pointer()) { + (if CppLess::less(__tmp_2.as_pointer().clone(), __tmp_3.as_pointer().clone()) { __tmp_2.as_pointer() } else { __tmp_3.as_pointer() @@ -65,7 +65,7 @@ thread_local!( let __rhs = { __tmp_4 = Rc::new(RefCell::new(1)); __tmp_5 = Rc::new(RefCell::new(2)); - (if CppLess::less(&__tmp_4.as_pointer(), &__tmp_5.as_pointer()) { + (if CppLess::less(__tmp_4.as_pointer().clone(), __tmp_5.as_pointer().clone()) { __tmp_5.as_pointer() } else { __tmp_4.as_pointer() @@ -129,7 +129,7 @@ thread_local!( __tmp_7 = Rc::new(RefCell::new(Box::new([{ __tmp_8 = Rc::new(RefCell::new(4)); __tmp_9 = Rc::new(RefCell::new(3)); - (if CppLess::less(&__tmp_8.as_pointer(), &__tmp_9.as_pointer()) { + (if CppLess::less(__tmp_8.as_pointer().clone(), __tmp_9.as_pointer().clone()) { __tmp_8.as_pointer() } else { __tmp_9.as_pointer() @@ -142,7 +142,8 @@ thread_local!( value: { __tmp_11 = Rc::new(RefCell::new(5)); __tmp_12 = Rc::new(RefCell::new(6)); - (if CppLess::less(&__tmp_11.as_pointer(), &__tmp_12.as_pointer()) { + (if CppLess::less(__tmp_11.as_pointer().clone(), __tmp_12.as_pointer().clone()) + { __tmp_12.as_pointer() } else { __tmp_11.as_pointer() @@ -166,7 +167,10 @@ thread_local!( Rc::new(RefCell::new( (({ __tmp_13 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); - (if CppLess::less(&__tmp_13.as_pointer(), &left_10.with(|v| v.as_pointer())) { + (if CppLess::less( + __tmp_13.as_pointer().clone(), + left_10.with(|v| v.as_pointer()).clone(), + ) { __tmp_13.as_pointer() } else { left_10.with(|v| v.as_pointer()) @@ -185,7 +189,10 @@ thread_local!( Rc::new(RefCell::new( (({ __tmp_14 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); - (if CppLess::less(&left_10.with(|v| v.as_pointer()), &__tmp_14.as_pointer()) { + (if CppLess::less( + left_10.with(|v| v.as_pointer()).clone(), + __tmp_14.as_pointer().clone(), + ) { __tmp_14.as_pointer() } else { left_10.with(|v| v.as_pointer()) @@ -222,7 +229,7 @@ thread_local!( __tmp_15 = Rc::new(RefCell::new(Box::new([{ __tmp_16 = Rc::new(RefCell::new(7)); __tmp_17 = Rc::new(RefCell::new(8)); - (if CppLess::less(&__tmp_16.as_pointer(), &__tmp_17.as_pointer()) { + (if CppLess::less(__tmp_16.as_pointer().clone(), __tmp_17.as_pointer().clone()) { __tmp_17.as_pointer() } else { __tmp_16.as_pointer() @@ -235,7 +242,8 @@ thread_local!( value: { __tmp_19 = Rc::new(RefCell::new(10)); __tmp_20 = Rc::new(RefCell::new(9)); - (if CppLess::less(&__tmp_19.as_pointer(), &__tmp_20.as_pointer()) { + (if CppLess::less(__tmp_19.as_pointer().clone(), __tmp_20.as_pointer().clone()) + { __tmp_19.as_pointer() } else { __tmp_20.as_pointer() diff --git a/tests/unit/out/refcount/global_init_side_effect.rs b/tests/unit/out/refcount/global_init_side_effect.rs index 43e141a5d8..45fe592233 100644 --- a/tests/unit/out/refcount/global_init_side_effect.rs +++ b/tests/unit/out/refcount/global_init_side_effect.rs @@ -25,17 +25,22 @@ thread_local!( #[cpp_from(i32, construct, value)] #[byte_size(1)] pub struct S {} +impl S { + pub fn construct(this: Ptr, mut x: i32) { + total_0.with(|rc| *rc.borrow_mut() += x); + } +} thread_local!( pub static a_1: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - SImpl::construct(&__v.as_pointer(), 1); + S::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); thread_local!( pub static b_2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - SImpl::construct(&__v.as_pointer(), 10); + S::construct(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -47,14 +52,6 @@ fn main_0() -> i32 { assert!((total_0.with(|rc| *rc.borrow()) == 11)); return 0; } -pub trait SImpl { - fn construct(&self, x: i32); -} -impl SImpl for Ptr { - fn construct(&self, mut x: i32) { - total_0.with(|rc| *rc.borrow_mut() += x); - } -} pub fn __cpp2rust_init_globals() { let _ = total_0.with(|_| ()); let _ = a_1.with(|_| ()); diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index af064c9639..46ffacf574 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -38,9 +38,14 @@ pub struct Ctor { #[offset(0)] pub v: i32, } +impl Ctor { + pub fn construct_1(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } +} impl DefaultConstructible for Ctor { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(({ next_0() })); + fn default_constructor(this: Ptr) { + field!(this, v).write(({ next_0() })); } } impl Default for Ctor { @@ -48,7 +53,7 @@ impl Default for Ctor { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -57,14 +62,14 @@ impl Default for Ctor { thread_local!( pub static default_ctor_7: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); thread_local!( pub static arg_ctor_8: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorImpl::construct_1(&__v.as_pointer(), 7); + Ctor::construct_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -78,7 +83,7 @@ thread_local!( thread_local!( pub static inline_member_11: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorImpl::construct_1(&__v.as_pointer(), 5); + Ctor::construct_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -108,7 +113,7 @@ thread_local!( thread_local!( static local_ctor_14: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorImpl::construct_1(&__v.as_pointer(), 3); + Ctor::construct_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -124,8 +129,8 @@ impl Singleton { } } impl DefaultConstructible for Singleton { - fn default_constructor(this: &Ptr) { - field!((*this), hits).write(0); + fn default_constructor(this: Ptr) { + field!(this, hits).write(0); } } impl Default for Singleton { @@ -133,7 +138,7 @@ impl Default for Singleton { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -142,7 +147,7 @@ impl Default for Singleton { thread_local!( static s_15: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -189,14 +194,6 @@ fn main_0() -> i32 { assert!((({ Singleton::instance() }) == ({ Singleton::instance() }))); return 0; } -pub trait CtorImpl { - fn construct_1(&self, x: i32); -} -impl CtorImpl for Ptr { - fn construct_1(&self, mut x: i32) { - field!((*self), v).write(x); - } -} pub fn __cpp2rust_init_globals() { let _ = signature_3.with(|_| ()); let _ = single_4.with(|_| ()); diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index 48c9782dee..197ee125ce 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -30,6 +30,12 @@ pub struct MinHeapNode { #[byte_size(8)] pub right: Ptr, } +impl MinHeapNode { + pub fn IsLeaf(this: Ptr) -> bool { + return ((this.with(|__s| __s.left.clone())).is_null()) + && ((this.with(|__s| __s.right.clone())).is_null()); + } +} pub fn Swap_0(a: Ptr, b: Ptr) { let mut t: MinHeapNode = MinHeapNode { data: a.with(|__s| __s.data), @@ -69,13 +75,173 @@ pub struct MinHeap { #[byte_size(8)] pub alloc: Option>>, } +impl MinHeap { + pub fn Alloc(this: Ptr, mut data: i8, mut freq: i32) -> Ptr { + this.with(|__s| __s.alloc.clone()) + .decay() + .offset((this.with(|__s| __s.next) as usize)) + .write(MinHeapNode { + data: data, + freq: freq, + left: Ptr::::null(), + right: Ptr::::null(), + }); + return (this + .with(|__s| __s.alloc.clone()) + .decay() + .offset((field!(this, next).with_mut(|__v| __v.postfix_inc()) as usize))); + } + pub fn Heapify(this: Ptr, mut idx: i32) { + let mut smallest: i32 = idx; + let mut left: i32 = ((2 * idx) + 1); + let mut right: i32 = ((2 * idx) + 2); + if (left < this.with(|__s| __s.size)) + && ((this + .with(|__s| __s.arr.clone()) + .decay() + .offset((left as usize)) + .read()) + .with(|__s| __s.freq) + < (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((smallest as usize)) + .read()) + .with(|__s| __s.freq)) + { + smallest = left; + } + if (right < this.with(|__s| __s.size)) + && ((this + .with(|__s| __s.arr.clone()) + .decay() + .offset((right as usize)) + .read()) + .with(|__s| __s.freq) + < (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((smallest as usize)) + .read()) + .with(|__s| __s.freq)) + { + smallest = right; + } + if (smallest != idx) { + ({ + Swap_0( + (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((smallest as usize)) + .read()), + (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((idx as usize)) + .read()), + ) + }); + ({ MinHeap::Heapify(this.clone(), smallest) }); + } + } + pub fn ExtractMin(this: Ptr) -> Ptr { + let mut out: Ptr = (this + .with(|__s| __s.arr.clone()) + .decay() + .offset(0_usize) + .read()); + field!(this, size).with_mut(|__v| { + __v.prefix_dec(); + }); + this.with(|__s| __s.arr.clone()) + .decay() + .offset(0_usize) + .write( + (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((this.with(|__s| __s.size) as usize)) + .read()), + ); + ({ MinHeap::Heapify(this.clone(), 0) }); + return out; + } + pub fn Insert(this: Ptr, mut node: Ptr) { + field!(this, size).with_mut(|__v| { + __v.prefix_inc(); + }); + let mut i: i32 = (this.with(|__s| __s.size) - 1); + 'loop_: while (i != 0) + && ({ node.with(|__s| __s.freq) } < { + (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((((i - 1) / 2) as usize)) + .read()) + .with(|__s| __s.freq) + }) + { + this.with(|__s| __s.arr.clone()) + .decay() + .offset((i as usize)) + .write( + (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((((i - 1) / 2) as usize)) + .read()), + ); + i = ((i - 1) / 2); + } + this.with(|__s| __s.arr.clone()) + .decay() + .offset((i as usize)) + .write((node).clone()); + } + pub fn Build( + this: Ptr, + data: Ptr>>>, + freq: Ptr>>>, + mut n: i32, + ) { + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + 'for_body: { + let __rhs = ({ + MinHeap::Alloc( + this.clone(), + (({ (*data.upgrade().deref()).decay().offset((i as usize)) }).read()), + (({ (*freq.upgrade().deref()).decay().offset((i as usize)) }).read()), + ) + }); + this.with(|__s| __s.arr.clone()) + .decay() + .offset((field!(this, size).with_mut(|__v| __v.postfix_inc()) as usize)) + .write(__rhs); + } + i.prefix_inc(); + } + } + { + let mut i: i32 = ((this.with(|__s| __s.size) - 2) / 2); + 'loop_: while (i >= 0) { + 'for_body: { + ({ MinHeap::Heapify(this.clone(), i) }); + } + i.prefix_dec(); + } + } + } +} impl DefaultConstructible for MinHeap { - fn default_constructor(this: &Ptr) { - field!((*this), size).write(0_i32); - field!((*this), capacity).write(0_i32); - field!((*this), arr).write(None); - field!((*this), next).write(0_i32); - field!((*this), alloc).write(None); + fn default_constructor(this: Ptr) { + field!(this, size).write(0_i32); + field!(this, capacity).write(0_i32); + field!(this, arr).write(None); + field!(this, next).write(0_i32); + field!(this, alloc).write(None); } } pub fn AllocMinHeap_1(mut capacity: i32) -> Option> { @@ -102,27 +268,20 @@ pub fn Huffman_2( mut size: i32, ) -> Option> { let mut minHeap: Option> = ({ AllocMinHeap_1(size) }); - ({ - MinHeapImpl::Build( - &(minHeap.as_pointer()), - (data).clone(), - (freq).clone(), - size, - ) - }); + ({ MinHeap::Build((minHeap.as_pointer()), (data).clone(), (freq).clone(), size) }); 'loop_: while (minHeap.as_pointer().with(|__s| (__s).size) != 1) { - let mut left: Ptr = ({ MinHeapImpl::ExtractMin(&(minHeap.as_pointer())) }); - let mut right: Ptr = ({ MinHeapImpl::ExtractMin(&(minHeap.as_pointer())) }); + let mut left: Ptr = ({ MinHeap::ExtractMin((minHeap.as_pointer())) }); + let mut right: Ptr = ({ MinHeap::ExtractMin((minHeap.as_pointer())) }); let mut top: Ptr = ({ - MinHeapImpl::Alloc( - &(minHeap.as_pointer()), + MinHeap::Alloc( + (minHeap.as_pointer()), ('$' as i8), ({ left.with(|__s| __s.freq) } + { right.with(|__s| __s.freq) }), ) }); field!(top, left).write((left).clone()); field!(top, right).write((right).clone()); - ({ MinHeapImpl::Insert(&(minHeap.as_pointer()), (top).clone()) }); + ({ MinHeap::Insert((minHeap.as_pointer()), (top).clone()) }); } return minHeap.take(); } @@ -210,7 +369,7 @@ pub fn CollectCodes_4( ) }); } - if ({ MinHeapNodeImpl::IsLeaf(&root) }) { + if ({ MinHeapNode::IsLeaf((root).clone()) }) { ({ CollectCode_3((arr).clone(), top, (out).clone(), (next).clone()) }); } } @@ -220,7 +379,7 @@ pub fn HuffmanCodes_5( mut size: i32, ) -> Option>> { let mut minHeap: Option> = ({ Huffman_2((data).clone(), (freq).clone(), size) }); - let mut root: Ptr = ({ MinHeapImpl::ExtractMin(&(minHeap.as_pointer())) }); + let mut root: Ptr = ({ MinHeap::ExtractMin((minHeap.as_pointer())) }); let arr: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( (0..100_usize).map(|_| 0_i32).collect::>(), ))))); @@ -283,190 +442,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait MinHeapImpl { - fn Alloc(&self, data: i8, freq: i32) -> Ptr; - fn Heapify(&self, idx: i32); - fn ExtractMin(&self) -> Ptr; - fn Insert(&self, node: Ptr); - fn Build( - &self, - data: Ptr>>>, - freq: Ptr>>>, - n: i32, - ); -} -impl MinHeapImpl for Ptr { - fn Alloc(&self, mut data: i8, mut freq: i32) -> Ptr { - (*self) - .with(|__s| __s.alloc.clone()) - .decay() - .offset(((*self).with(|__s| __s.next) as usize)) - .write(MinHeapNode { - data: data, - freq: freq, - left: Ptr::::null(), - right: Ptr::::null(), - }); - return ((*self) - .with(|__s| __s.alloc.clone()) - .decay() - .offset((field!((*self), next).with_mut(|__v| __v.postfix_inc()) as usize))); - } - fn Heapify(&self, mut idx: i32) { - let mut smallest: i32 = idx; - let mut left: i32 = ((2 * idx) + 1); - let mut right: i32 = ((2 * idx) + 2); - if (left < (*self).with(|__s| __s.size)) - && (((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((left as usize)) - .read()) - .with(|__s| __s.freq) - < ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((smallest as usize)) - .read()) - .with(|__s| __s.freq)) - { - smallest = left; - } - if (right < (*self).with(|__s| __s.size)) - && (((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((right as usize)) - .read()) - .with(|__s| __s.freq) - < ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((smallest as usize)) - .read()) - .with(|__s| __s.freq)) - { - smallest = right; - } - if (smallest != idx) { - ({ - Swap_0( - ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((smallest as usize)) - .read()), - ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((idx as usize)) - .read()), - ) - }); - ({ MinHeapImpl::Heapify(self, smallest) }); - } - } - fn ExtractMin(&self) -> Ptr { - let mut out: Ptr = ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset(0_usize) - .read()); - field!((*self), size).with_mut(|__v| { - __v.prefix_dec(); - }); - (*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset(0_usize) - .write( - ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset(((*self).with(|__s| __s.size) as usize)) - .read()), - ); - ({ MinHeapImpl::Heapify(self, 0) }); - return out; - } - fn Insert(&self, mut node: Ptr) { - field!((*self), size).with_mut(|__v| { - __v.prefix_inc(); - }); - let mut i: i32 = ((*self).with(|__s| __s.size) - 1); - 'loop_: while (i != 0) - && ({ node.with(|__s| __s.freq) } < { - ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((((i - 1) / 2) as usize)) - .read()) - .with(|__s| __s.freq) - }) - { - (*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((i as usize)) - .write( - ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((((i - 1) / 2) as usize)) - .read()), - ); - i = ((i - 1) / 2); - } - (*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((i as usize)) - .write((node).clone()); - } - fn Build( - &self, - data: Ptr>>>, - freq: Ptr>>>, - mut n: i32, - ) { - { - let mut i: i32 = 0; - 'loop_: while (i < n) { - 'for_body: { - let __rhs = ({ - MinHeapImpl::Alloc( - self, - (({ (*data.upgrade().deref()).decay().offset((i as usize)) }).read()), - (({ (*freq.upgrade().deref()).decay().offset((i as usize)) }).read()), - ) - }); - (*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((field!((*self), size).with_mut(|__v| __v.postfix_inc()) as usize)) - .write(__rhs); - } - i.prefix_inc(); - } - } - { - let mut i: i32 = (((*self).with(|__s| __s.size) - 2) / 2); - 'loop_: while (i >= 0) { - 'for_body: { - ({ MinHeapImpl::Heapify(self, i) }); - } - i.prefix_dec(); - } - } - } -} -pub trait MinHeapNodeImpl { - fn IsLeaf(&self) -> bool; -} -impl MinHeapNodeImpl for Ptr { - fn IsLeaf(&self) -> bool { - return (((*self).with(|__s| __s.left.clone())).is_null()) - && (((*self).with(|__s| __s.right.clone())).is_null()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/immutable-deref-on-func-call.rs b/tests/unit/out/refcount/immutable-deref-on-func-call.rs index 32f82f427e..973cb5d533 100644 --- a/tests/unit/out/refcount/immutable-deref-on-func-call.rs +++ b/tests/unit/out/refcount/immutable-deref-on-func-call.rs @@ -23,6 +23,11 @@ pub struct Item { #[offset(0)] pub value: i32, } +impl Item { + pub fn foo(this: Ptr, mut other: Ptr) { + field!(other, value).write(10); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -35,19 +40,11 @@ fn main_0() -> i32 { ); field!(elem!(arr, 0), value).write(1); field!(elem!(arr, 1), value).write(2); - ({ ItemImpl::foo(&arr.offset((0) as isize), (arr.offset((1) as isize))) }); + ({ Item::foo(arr.offset((0) as isize), (arr.offset((1) as isize))) }); let mut result: i32 = (elem!(arr, 0).with(|__s| __s.value) + elem!(arr, 1).with(|__s| __s.value)); arr.delete(); assert!((result == 11)); return 0; } -pub trait ItemImpl { - fn foo(&self, other: Ptr); -} -impl ItemImpl for Ptr { - fn foo(&self, mut other: Ptr) { - field!(other, value).write(10); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index a16f158f64..20f3787eb8 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -27,8 +27,8 @@ pub struct Holder { pub v: Vec, } impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, v).write(Vec::new()); } } pub fn write_through_0(mut p: Ptr) { diff --git a/tests/unit/out/refcount/in_class_field_initializer.rs b/tests/unit/out/refcount/in_class_field_initializer.rs index 017aa4a510..e4c30a6732 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.rs @@ -15,9 +15,9 @@ pub struct Inner { pub y: i32, } impl DefaultConstructible for Inner { - fn default_constructor(this: &Ptr) { - field!((*this), x).write(3); - field!((*this), y).write(4); + fn default_constructor(this: Ptr) { + field!(this, x).write(3); + field!(this, y).write(4); } } impl Default for Inner { @@ -40,11 +40,11 @@ pub struct S { pub d: Inner, } impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { - field!((*this), a).write(1); - field!((*this), b).write(2_i8); - field!((*this), c).write(::default()); - DefaultConstructible::default_constructor(&field_ptr!(this, d)); + fn default_constructor(this: Ptr) { + field!(this, a).write(1); + field!(this, b).write(2_i8); + field!(this, c).write(::default()); + DefaultConstructible::default_constructor(field_ptr!(this, d)); } } impl Default for S { @@ -77,6 +77,12 @@ pub struct Boxed_int_ { #[offset(4)] pub tag: i32, } +impl Boxed_int_ { + pub fn construct(this: Ptr, mut x: i32, mut t: i32) { + field!(this, v).write(x); + field!(this, tag).write(t); + } +} impl Default for Boxed_int_ { fn default() -> Self { { ::zero_init() } @@ -99,13 +105,4 @@ fn main_0() -> i32 { assert!(({ (*boxed.borrow()).tag } == 9)); return 0; } -pub trait Boxed_int_Impl { - fn construct(&self, x: i32, t: i32); -} -impl Boxed_int_Impl for Ptr { - fn construct(&self, mut x: i32, mut t: i32) { - field!((*self), v).write(x); - field!((*self), tag).write(t); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/init_list.rs b/tests/unit/out/refcount/init_list.rs index a4e5bc0ee3..a1bf443709 100644 --- a/tests/unit/out/refcount/init_list.rs +++ b/tests/unit/out/refcount/init_list.rs @@ -35,9 +35,15 @@ pub struct Holder { #[byte_size(8)] pub p: Pair, } +impl Holder { + pub fn operator_assign_1(this: Ptr, o: Ptr) -> Ptr { + field!(this, p).write({ (*o.upgrade().deref()) }); + return (this).clone(); + } +} impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { - field!((*this), p).write(Pair { a: 0, b: 0 }); + fn default_constructor(this: Ptr) { + field!(this, p).write(Pair { a: 0, b: 0 }); } } impl Default for Holder { @@ -59,8 +65,8 @@ pub struct Seven { pub v: i32, } impl DefaultConstructible for Seven { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(7); + fn default_constructor(this: Ptr) { + field!(this, v).write(7); } } impl Default for Seven { @@ -82,7 +88,7 @@ fn main_0() -> i32 { ({ f_0(Vec::from([1, 2, 3, 4])) }); let p: Value = Rc::new(RefCell::new(Pair { a: 1, b: 2 })); object!(h, Holder); - HolderImpl::operator_assign_1(&h.as_pointer(), p.as_pointer()); + Holder::operator_assign_1(h.as_pointer(), p.as_pointer()); assert!(({ (*h.borrow()).p.a } == 1) && ({ (*h.borrow()).p.b } == 2)); assert!((({ sum_1(p.as_pointer(),) }) == 3)); let mut sevens: [Seven; 4] = [::default(); 4]; @@ -97,13 +103,4 @@ fn main_0() -> i32 { } return 0; } -pub trait HolderImpl { - fn operator_assign_1(&self, o: Ptr) -> Ptr; -} -impl HolderImpl for Ptr { - fn operator_assign_1(&self, o: Ptr) -> Ptr { - field!((*self), p).write({ (*o.upgrade().deref()) }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 84cd94f751..dffd012142 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -32,10 +32,10 @@ pub struct Elem { pub coeffs: Vec, } impl DefaultConstructible for Elem { - fn default_constructor(this: &Ptr) { - field!((*this), id).write(0_i32); - field!((*this), hist).write((0..4).map(|_| 0_i32).collect::>()); - field!((*this), coeffs).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, id).write(0_i32); + field!(this, hist).write((0..4).map(|_| 0_i32).collect::>()); + field!(this, coeffs).write(Vec::new()); } } impl Default for Elem { @@ -82,18 +82,18 @@ pub struct State { pub rows: Vec>, } impl DefaultConstructible for State { - fn default_constructor(this: &Ptr) { - field!((*this), count).write(0_i32); - field!((*this), grid).write( + fn default_constructor(this: Ptr) { + field!(this, count).write(0_i32); + field!(this, grid).write( (0..2) .map(|_| (0..3).map(|_| 0_i32).collect::>()) .collect::]>>(), ); - field!((*this), arr).write(Box::<[i32]>::from(std::array::from_fn::<_, 3, _>(|_| { + field!(this, arr).write(Box::<[i32]>::from(std::array::from_fn::<_, 3, _>(|_| { 0_i32 }))); - field!((*this), elems).write(Vec::new()); - field!((*this), rows).write(Vec::new()); + field!(this, elems).write(Vec::new()); + field!(this, rows).write(Vec::new()); } } impl Default for State { @@ -189,36 +189,36 @@ pub struct Counted { pub v: i32, } impl DefaultConstructible for Counted { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(0); + fn default_constructor(this: Ptr) { + field!(this, v).write(0); } } impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Counted { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyAssignable for Counted { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { - field!((*this), v).write(o.with(|__s| __s.v)); + fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write(o.with(|__s| __s.v)); (*copy_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); - return (*this).clone(); + return (this).clone(); } } impl MoveAssignable for Counted { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*move_assigns_5.with(Value::clone).borrow_mut()).prefix_inc(); - return (*this).clone(); + return (this).clone(); } } impl Default for Counted { diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index c7bed88aaa..fb0bb5334d 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -125,11 +125,114 @@ pub struct DisjointSet { #[offset(16)] pub n: i32, } +impl DisjointSet { + pub fn makeSet(this: Ptr) { + { + let mut i: i32 = 0; + 'loop_: while (i < this.with(|__s| __s.n)) { + 'for_body: { + this.with(|__s| __s.parent.clone()) + .decay() + .offset((i as usize)) + .write(i); + this.with(|__s| __s.rank.clone()) + .decay() + .offset((i as usize)) + .write(1); + } + i.postfix_inc(); + } + } + } + pub fn find(this: Ptr, mut x: i32) -> i32 { + if ((this + .with(|__s| __s.parent.clone()) + .decay() + .offset((x as usize)) + .read()) + != x) + { + let __rhs = ({ + DisjointSet::find( + this.clone(), + (this + .with(|__s| __s.parent.clone()) + .decay() + .offset((x as usize)) + .read()), + ) + }); + this.with(|__s| __s.parent.clone()) + .decay() + .offset((x as usize)) + .write(__rhs); + } + return (this + .with(|__s| __s.parent.clone()) + .decay() + .offset((x as usize)) + .read()); + } + pub fn merge(this: Ptr, mut x: i32, mut y: i32) { + let mut xset: i32 = ({ DisjointSet::find(this.clone(), x) }); + let mut yset: i32 = ({ DisjointSet::find(this.clone(), y) }); + if (xset == yset) { + return; + } + if ((this + .with(|__s| __s.rank.clone()) + .decay() + .offset((xset as usize)) + .read()) + < (this + .with(|__s| __s.rank.clone()) + .decay() + .offset((yset as usize)) + .read())) + { + this.with(|__s| __s.parent.clone()) + .decay() + .offset((xset as usize)) + .write(yset); + } else if ((this + .with(|__s| __s.rank.clone()) + .decay() + .offset((xset as usize)) + .read()) + > (this + .with(|__s| __s.rank.clone()) + .decay() + .offset((yset as usize)) + .read())) + { + this.with(|__s| __s.parent.clone()) + .decay() + .offset((yset as usize)) + .write(xset); + } else { + this.with(|__s| __s.parent.clone()) + .decay() + .offset((yset as usize)) + .write(xset); + this.with(|__s| __s.rank.clone()) + .decay() + .offset((xset as usize)) + .write( + ((this + .with(|__s| __s.rank.clone()) + .decay() + .offset((xset as usize)) + .read()) + + 1), + ); + } + } +} impl DefaultConstructible for DisjointSet { - fn default_constructor(this: &Ptr) { - field!((*this), rank).write(None); - field!((*this), parent).write(None); - field!((*this), n).write(0_i32); + fn default_constructor(this: Ptr) { + field!(this, rank).write(None); + field!(this, parent).write(None); + field!(this, n).write(0_i32); } } #[derive( @@ -147,10 +250,10 @@ pub struct Graph { pub E: i32, } impl DefaultConstructible for Graph { - fn default_constructor(this: &Ptr) { - field!((*this), edges).write(None); - field!((*this), V).write(0_i32); - field!((*this), E).write(0_i32); + fn default_constructor(this: Ptr) { + field!(this, edges).write(None); + field!(this, V).write(0_i32); + field!(this, E).write(0_i32); } } pub fn MSTKruskal_2(graph: Ptr) -> f64 { @@ -168,7 +271,7 @@ pub fn MSTKruskal_2(graph: Ptr) -> f64 { ))), n: graph.with(|__s| __s.V), })); - ({ DisjointSetImpl::makeSet(&set.as_pointer()) }); + ({ DisjointSet::makeSet(set.as_pointer()) }); let mut total_weight: f64 = 0_f64; { let mut i: i32 = 0; @@ -189,10 +292,10 @@ pub fn MSTKruskal_2(graph: Ptr) -> f64 { .decay() .offset((i as usize)) .with(|__s| __s.weight); - if (({ DisjointSetImpl::find(&set.as_pointer(), x) }) - != ({ DisjointSetImpl::find(&set.as_pointer(), y) })) + if (({ DisjointSet::find(set.as_pointer(), x) }) + != ({ DisjointSet::find(set.as_pointer(), y) })) { - ({ DisjointSetImpl::merge(&set.as_pointer(), x, y) }); + ({ DisjointSet::merge(set.as_pointer(), x, y) }); total_weight += w; } } @@ -261,119 +364,4 @@ fn main_0() -> i32 { assert!((total_weight == 19_f64)); return 0; } -pub trait DisjointSetImpl { - fn makeSet(&self); - fn find(&self, x: i32) -> i32; - fn merge(&self, x: i32, y: i32); -} -impl DisjointSetImpl for Ptr { - fn makeSet(&self) { - { - let mut i: i32 = 0; - 'loop_: while (i < (*self).with(|__s| __s.n)) { - 'for_body: { - (*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((i as usize)) - .write(i); - (*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((i as usize)) - .write(1); - } - i.postfix_inc(); - } - } - } - fn find(&self, mut x: i32) -> i32 { - if (((*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((x as usize)) - .read()) - != x) - { - let __rhs = ({ - DisjointSetImpl::find( - self, - ((*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((x as usize)) - .read()), - ) - }); - (*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((x as usize)) - .write(__rhs); - } - return ((*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((x as usize)) - .read()); - } - fn merge(&self, mut x: i32, mut y: i32) { - let mut xset: i32 = ({ DisjointSetImpl::find(self, x) }); - let mut yset: i32 = ({ DisjointSetImpl::find(self, y) }); - if (xset == yset) { - return; - } - if (((*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((xset as usize)) - .read()) - < ((*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((yset as usize)) - .read())) - { - (*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((xset as usize)) - .write(yset); - } else if (((*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((xset as usize)) - .read()) - > ((*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((yset as usize)) - .read())) - { - (*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((yset as usize)) - .write(xset); - } else { - (*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((yset as usize)) - .write(xset); - (*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((xset as usize)) - .write( - (((*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((xset as usize)) - .read()) - + 1), - ); - } - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index b7a28c83e7..faf000ed8c 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -26,8 +26,8 @@ pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { pub f: FnPtr, } impl Destructible for Guard__lambda_at_lambda_as_field_cpp_34_13__ { - fn destroy(this: &Ptr) { - ({ (*(*this).upgrade().deref()).f.call() }); + fn destroy(this: Ptr) { + ({ (*this.upgrade().deref()).f.call() }); } } #[derive( @@ -40,8 +40,8 @@ pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { pub f: FnPtr, } impl Destructible for Guard__lambda_at_lambda_as_field_cpp_45_13__ { - fn destroy(this: &Ptr) { - ({ (*(*this).upgrade().deref()).f.call() }); + fn destroy(this: Ptr) { + ({ (*this.upgrade().deref()).f.call() }); } } #[derive( @@ -62,6 +62,12 @@ pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { #[offset(4)] pub calls: i32, } +impl Holder__lambda_at_lambda_as_field_cpp_39_12__ { + pub fn call(this: Ptr, mut x: i32) -> i32 { + field!(this, calls).with_mut(|__v| __v.postfix_inc()); + return ({ (*this.upgrade().deref()).f.call(x) }); + } +} impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { fn default() -> Self { { @@ -95,6 +101,12 @@ pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { #[offset(4)] pub calls: i32, } +impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { + pub fn call(this: Ptr, mut x: i32) -> i32 { + field!(this, calls).with_mut(|__v| __v.postfix_inc()); + return ({ (*this.upgrade().deref()).f.call(x) }); + } +} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable)] #[cpp_from(FnPtr i32 > , construct, value)] #[byte_size(8)] @@ -105,10 +117,17 @@ pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { #[offset(4)] pub moves: i32, } +impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { + pub fn construct(this: Ptr, f: FnPtr i32>) { + let f: Value i32>> = Rc::new(RefCell::new(f)); + field!(this, f).write((*f.borrow()).copy_from()); + field!(this, moves).write(0); + } +} impl MoveConstructible for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), f).write((*o.upgrade().deref()).f.move_from()); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, f).write((*o.upgrade().deref()).f.move_from()); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); } } impl Default for Moving__lambda_at_lambda_as_field_cpp_64_12__ { @@ -156,7 +175,7 @@ fn main_0() -> i32 { }), })); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!((count_2.with(|rc| *rc.borrow()) == 0)); } assert!((count_2.with(|rc| *rc.borrow()) == 1)); @@ -170,9 +189,7 @@ fn main_0() -> i32 { calls: 0, }, )); - assert!( - (({ Holder__lambda_at_lambda_as_field_cpp_39_12__Impl::call(&n.as_pointer(), 2,) }) == 3) - ); + assert!((({ Holder__lambda_at_lambda_as_field_cpp_39_12__::call(n.as_pointer(), 2,) }) == 3)); assert!(({ (*n.borrow()).calls } == 1)); let cleaned: Value = Rc::new(RefCell::new(0)); { @@ -188,7 +205,7 @@ fn main_0() -> i32 { ), })); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ ((*cleaned.borrow()) == 0) })); } assert!(({ ((*cleaned.borrow()) == 1) })); @@ -207,12 +224,8 @@ fn main_0() -> i32 { }, )); (*factor.borrow_mut()) = 100; - assert!( - (({ Holder__lambda_at_lambda_as_field_cpp_51_12__Impl::call(&h.as_pointer(), 2,) }) == 6) - ); - assert!( - (({ Holder__lambda_at_lambda_as_field_cpp_51_12__Impl::call(&h.as_pointer(), 5,) }) == 15) - ); + assert!((({ Holder__lambda_at_lambda_as_field_cpp_51_12__::call(h.as_pointer(), 2,) }) == 6)); + assert!((({ Holder__lambda_at_lambda_as_field_cpp_51_12__::call(h.as_pointer(), 5,) }) == 15)); assert!(({ (*h.borrow()).calls } == 2)); let w: Value i32>> = Rc::new(RefCell::new( ({ @@ -252,40 +265,6 @@ fn main_0() -> i32 { assert!(({ (*m2.borrow()).moves } == 1)); return 0; } -pub trait Holder__lambda_at_lambda_as_field_cpp_39_12__Impl { - fn call(&self, x: i32) -> i32; -} -impl Holder__lambda_at_lambda_as_field_cpp_39_12__Impl - for Ptr -{ - fn call(&self, mut x: i32) -> i32 { - field!((*self), calls).with_mut(|__v| __v.postfix_inc()); - return ({ (*(*self).upgrade().deref()).f.call(x) }); - } -} -pub trait Holder__lambda_at_lambda_as_field_cpp_51_12__Impl { - fn call(&self, x: i32) -> i32; -} -impl Holder__lambda_at_lambda_as_field_cpp_51_12__Impl - for Ptr -{ - fn call(&self, mut x: i32) -> i32 { - field!((*self), calls).with_mut(|__v| __v.postfix_inc()); - return ({ (*(*self).upgrade().deref()).f.call(x) }); - } -} -pub trait Moving__lambda_at_lambda_as_field_cpp_64_12__Impl { - fn construct(&self, f: FnPtr i32>); -} -impl Moving__lambda_at_lambda_as_field_cpp_64_12__Impl - for Ptr -{ - fn construct(&self, f: FnPtr i32>) { - let f: Value i32>> = Rc::new(RefCell::new(f)); - field!((*self), f).write((*f.borrow()).copy_from()); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() { let _ = count_2.with(|_| ()); } diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 2010a3a63b..225a2866f9 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -15,21 +15,21 @@ pub struct Counted { pub moves: i32, } impl DefaultConstructible for Counted { - fn default_constructor(this: &Ptr) { - field!((*this), copies).write(0); - field!((*this), moves).write(0); + fn default_constructor(this: Ptr) { + field!(this, copies).write(0); + field!(this, moves).write(0); } } impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Counted { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); } } impl Default for Counted { @@ -37,7 +37,7 @@ impl Default for Counted { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -50,16 +50,16 @@ thread_local!( #[byte_size(1)] pub struct Dropped {} impl DefaultConstructible for Dropped { - fn default_constructor(this: &Ptr) {} + fn default_constructor(this: Ptr) {} } impl CopyConstructible for Dropped { - fn copy_constructor(this: &Ptr, _a0: Ptr) {} + fn copy_constructor(this: Ptr, _a0: Ptr) {} } impl MoveConstructible for Dropped { - fn move_constructor(this: &Ptr, _a0: Ptr) {} + fn move_constructor(this: Ptr, _a0: Ptr) {} } impl Destructible for Dropped { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*drops_0.with(Value::clone).borrow_mut()).postfix_inc(); } } @@ -73,7 +73,7 @@ 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()); + ConstructFrom::construct_from(__v.as_pointer(), c.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -95,12 +95,12 @@ 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()); + ConstructFrom::construct_from(__v.as_pointer(), c.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, - |this: Ptr| { - ConstructFrom::construct_from(&this, c.as_pointer()); + |__return: Ptr| { + ConstructFrom::construct_from(__return.clone(), c.as_pointer()); return; } ) @@ -114,7 +114,7 @@ fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 2, _>(|_| { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); @@ -123,7 +123,7 @@ 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)); + ConstructFrom::construct_from(__v.as_pointer(), arr.decay().offset(__i)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); @@ -144,17 +144,17 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || {} ))); let _dtor_m = - std::mem::DropGuard::new(m.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(m.clone(), |__p| Destructible::destroy(__p.as_pointer())); let m2: Value> = Rc::new(RefCell::new((*m.borrow()).move_from())); let _dtor_m2 = - std::mem::DropGuard::new(m2.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(m2.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((drops_0.with(|rc| *rc.borrow()) == 2)); { @@ -162,17 +162,17 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || {} ))); let _dtor_k = - std::mem::DropGuard::new(k.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(k.clone(), |__p| Destructible::destroy(__p.as_pointer())); let k2: Value> = Rc::new(RefCell::new((*k.borrow()).copy_from())); let _dtor_k2 = - std::mem::DropGuard::new(k2.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(k2.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((drops_0.with(|rc| *rc.borrow()) == 4)); { @@ -180,15 +180,14 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || {} ))); - let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) - }); + let _dtor_inner = + std::mem::DropGuard::new(inner.clone(), |__p| Destructible::destroy(__p.as_pointer())); let outer: Value> = Rc::new(RefCell::new(lambda!( { let inner: Value> = @@ -196,9 +195,8 @@ fn main_0() -> i32 { }, || {} ))); - let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) - }); + let _dtor_outer = + std::mem::DropGuard::new(outer.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((drops_0.with(|rc| *rc.borrow()) == 6)); return 0; diff --git a/tests/unit/out/refcount/lambda_capture_star_this.rs b/tests/unit/out/refcount/lambda_capture_star_this.rs index 35f4e7de35..638e8b333f 100644 --- a/tests/unit/out/refcount/lambda_capture_star_this.rs +++ b/tests/unit/out/refcount/lambda_capture_star_this.rs @@ -23,34 +23,14 @@ pub struct S { #[offset(0)] pub n: i32, } -pub fn main() { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0()); -} -fn main_0() -> i32 { - let s: Value = Rc::new(RefCell::new(S { n: 1 })); - assert!((({ SImpl::modify_copy(&s.as_pointer(),) }) == 1101)); - assert!(({ (*s.borrow()).n } == 1)); - assert!((({ SImpl::snapshot(&s.as_pointer(),) }) == 2)); - assert!(({ (*s.borrow()).n } == 99)); - assert!((({ SImpl::mixed(&s.as_pointer(), 1,) }) == 100)); - assert!(({ (*s.borrow()).n } == 0)); - return 0; -} -pub trait SImpl { - fn twice(&self) -> i32; - fn modify_copy(&self) -> i32; - fn snapshot(&self) -> i32; - fn mixed(&self, k: i32) -> i32; -} -impl SImpl for Ptr { - fn twice(&self) -> i32 { - return ((*self).with(|__s| __s.n) * 2); +impl S { + pub fn twice(this: Ptr) -> i32 { + return (this.with(|__s| __s.n) * 2); } - fn modify_copy(&self) -> i32 { + pub fn modify_copy(this: Ptr) -> i32 { let f: Value i32>> = Rc::new(RefCell::new(lambda!( { - let this_: Value = Rc::new(RefCell::new((*(*self).upgrade().deref()))); + let this_: Value = Rc::new(RefCell::new((*this.upgrade().deref()))); }, || -> i32 { { @@ -60,33 +40,47 @@ impl SImpl for Ptr { } ))); let mut r: i32 = ({ (*f.borrow()).call() }).clone(); - return ((r * 100) + (*self).with(|__s| __s.n)); + return ((r * 100) + this.with(|__s| __s.n)); } - fn snapshot(&self) -> i32 { + pub fn snapshot(this: Ptr) -> i32 { let f: Value i32>> = Rc::new(RefCell::new(lambda!( { - let this_: Value = Rc::new(RefCell::new((*(*self).upgrade().deref()))); + let this_: Value = Rc::new(RefCell::new((*this.upgrade().deref()))); }, || -> i32 { - return ({ SImpl::twice(&this_.as_pointer()) }); + return ({ S::twice(this_.as_pointer()) }); } ))); - field!((*self), n).write(99); + field!(this, n).write(99); return ({ (*f.borrow()).call() }).clone(); } - fn mixed(&self, k: i32) -> i32 { + pub fn mixed(this: Ptr, k: i32) -> i32 { let k: Value = Rc::new(RefCell::new(k)); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { - let this_: Value = Rc::new(RefCell::new((*(*self).upgrade().deref()))); + let this_: Value = Rc::new(RefCell::new((*this.upgrade().deref()))); let k: Value = Rc::new(RefCell::new((*k.borrow()))); }, || -> i32 { return (this_.as_pointer().with(|__s| __s.n) + (*k.borrow())); } ))); - field!((*self), n).write(0); + field!(this, n).write(0); return ({ (*f.borrow()).call() }).clone(); } } +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + let s: Value = Rc::new(RefCell::new(S { n: 1 })); + assert!((({ S::modify_copy(s.as_pointer(),) }) == 1101)); + assert!(({ (*s.borrow()).n } == 1)); + assert!((({ S::snapshot(s.as_pointer(),) }) == 2)); + assert!(({ (*s.borrow()).n } == 99)); + assert!((({ S::mixed(s.as_pointer(), 1,) }) == 100)); + assert!(({ (*s.borrow()).n } == 0)); + return 0; +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/lambda_capture_this.rs b/tests/unit/out/refcount/lambda_capture_this.rs index 48cac3a0f0..cb10482d9f 100644 --- a/tests/unit/out/refcount/lambda_capture_this.rs +++ b/tests/unit/out/refcount/lambda_capture_this.rs @@ -25,39 +25,19 @@ pub struct S { #[offset(4)] pub step: i32, } -pub fn main() { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0()); -} -fn main_0() -> i32 { - let s: Value = Rc::new(RefCell::new(S { n: 0, step: 2 })); - ({ SImpl::bump(&s.as_pointer(), 3) }); - assert!(({ (*s.borrow()).n } == 6)); - ({ SImpl::bump_via_method(&s.as_pointer(), 4) }); - assert!(({ (*s.borrow()).n } == 10)); - assert!((({ SImpl::read_scaled(&s.as_pointer(),) }) == 20)); - return 0; -} -pub trait SImpl { - fn add(&self, k: i32); - fn scaled(&self) -> i32; - fn bump(&self, by: i32); - fn bump_via_method(&self, by: i32); - fn read_scaled(&self) -> i32; -} -impl SImpl for Ptr { - fn add(&self, mut k: i32) { +impl S { + pub fn add(this: Ptr, mut k: i32) { { - field!((*self), n).with_mut(|__v| *__v = *__v + k) + field!(this, n).with_mut(|__v| *__v = *__v + k) }; } - fn scaled(&self) -> i32 { - return ((*self).with(|__s| __s.n) * (*self).with(|__s| __s.step)); + pub fn scaled(this: Ptr) -> i32 { + return (this.with(|__s| __s.n) * this.with(|__s| __s.step)); } - fn bump(&self, mut by: i32) { + pub fn bump(this: Ptr, mut by: i32) { let inc: Value> = Rc::new(RefCell::new(lambda!( { - let this_: Value> = Rc::new(RefCell::new((*self).clone())); + let this_: Value> = Rc::new(RefCell::new((this).clone())); }, |mut k: i32| { { @@ -68,27 +48,40 @@ impl SImpl for Ptr { ({ (*inc.borrow()).call(by) }); ({ (*inc.borrow()).call(by) }); } - fn bump_via_method(&self, mut by: i32) { + pub fn bump_via_method(this: Ptr, mut by: i32) { let inc: Value> = Rc::new(RefCell::new(lambda!( { - let this_: Value> = Rc::new(RefCell::new((*self).clone())); + let this_: Value> = Rc::new(RefCell::new((this).clone())); }, |mut k: i32| { - ({ SImpl::add(&(*this_.borrow()), k) }); + ({ S::add({ (*this_.borrow()).clone() }, k) }); } ))); ({ (*inc.borrow()).call(by) }); } - fn read_scaled(&self) -> i32 { + pub fn read_scaled(this: Ptr) -> i32 { let get: Value i32>> = Rc::new(RefCell::new(lambda!( { - let this_: Value> = Rc::new(RefCell::new((*self).clone())); + let this_: Value> = Rc::new(RefCell::new((this).clone())); }, || -> i32 { - return ({ SImpl::scaled(&(*this_.borrow())) }); + return ({ S::scaled({ (*this_.borrow()).clone() }) }); } ))); return ({ (*get.borrow()).call() }).clone(); } } +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + let s: Value = Rc::new(RefCell::new(S { n: 0, step: 2 })); + ({ S::bump(s.as_pointer(), 3) }); + assert!(({ (*s.borrow()).n } == 6)); + ({ S::bump_via_method(s.as_pointer(), 4) }); + assert!(({ (*s.borrow()).n } == 10)); + assert!((({ S::read_scaled(s.as_pointer(),) }) == 20)); + return 0; +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/lambda_decltype_type.rs b/tests/unit/out/refcount/lambda_decltype_type.rs index 1add8e940a..9a02d69619 100644 --- a/tests/unit/out/refcount/lambda_decltype_type.rs +++ b/tests/unit/out/refcount/lambda_decltype_type.rs @@ -19,11 +19,28 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[byte_size(1)] pub cmp: FnPtr bool>, } +impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { + pub fn insert(this: Ptr, mut v: i32) { + let mut i: i32 = this.with(|__s| __s.size); + 'loop_: while (i > 0) + && ({ + (*this.upgrade().deref()) + .cmp + .call(v, (array_elem!(this, items, (i - 1)).read())) + }) + { + array_elem!(this, items, i).write((array_elem!(this, items, (i - 1)).read())); + i.postfix_dec(); + } + array_elem!(this, items, i).write(v); + field!(this, size).with_mut(|__v| __v.postfix_inc()); + } +} impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { - fn default_constructor(this: &Ptr) { - field!((*this), items).write((0..4).map(|_| 0_i32).collect::>()); - field!((*this), size).write(0); - field!((*this), cmp).write(FnPtr:: bool>::new( + fn default_constructor(this: Ptr) { + field!(this, items).write((0..4).map(|_| 0_i32).collect::>()); + field!(this, size).write(0); + field!(this, cmp).write(FnPtr:: bool>::new( |mut a: i32, mut b: i32| -> bool { { return (a > b); @@ -60,11 +77,28 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { #[byte_size(1)] pub cmp: FnPtr bool>, } +impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { + pub fn insert(this: Ptr, mut v: i32) { + let mut i: i32 = this.with(|__s| __s.size); + 'loop_: while (i > 0) + && ({ + (*this.upgrade().deref()) + .cmp + .call(v, (array_elem!(this, items, (i - 1)).read())) + }) + { + array_elem!(this, items, i).write((array_elem!(this, items, (i - 1)).read())); + i.postfix_dec(); + } + array_elem!(this, items, i).write(v); + field!(this, size).with_mut(|__v| __v.postfix_inc()); + } +} impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { - fn default_constructor(this: &Ptr) { - field!((*this), items).write((0..4).map(|_| 0_i32).collect::>()); - field!((*this), size).write(0); - field!((*this), cmp).write(FnPtr:: bool>::new( + fn default_constructor(this: Ptr) { + field!(this, items).write((0..4).map(|_| 0_i32).collect::>()); + field!(this, size).write(0); + field!(this, cmp).write(FnPtr:: bool>::new( |mut a: i32, mut b: i32| -> bool { { return (a < b); @@ -102,16 +136,16 @@ fn main_0() -> i32 { }, ))); object!(desc, Sorted__lambda_at_lambda_decltype_type_cpp_22_18__); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl::insert(&desc.as_pointer(), 2) }); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl::insert(&desc.as_pointer(), 7) }); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl::insert(&desc.as_pointer(), 4) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 2) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 7) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 4) }); assert!(((array_elem!(desc.as_pointer(), items, 0).read()) == 7)); assert!(((array_elem!(desc.as_pointer(), items, 1).read()) == 4)); assert!(((array_elem!(desc.as_pointer(), items, 2).read()) == 2)); object!(asc, Sorted__lambda_at_lambda_decltype_type_cpp_19_23__); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl::insert(&asc.as_pointer(), 2) }); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl::insert(&asc.as_pointer(), 7) }); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl::insert(&asc.as_pointer(), 4) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 2) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 7) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 4) }); assert!(((array_elem!(asc.as_pointer(), items, 0).read()) == 2)); assert!(((array_elem!(asc.as_pointer(), items, 1).read()) == 4)); assert!(((array_elem!(asc.as_pointer(), items, 2).read()) == 7)); @@ -146,48 +180,4 @@ fn main_0() -> i32 { assert!(({ (({ (*less.borrow()).call(1, 3,) }) as bool) })); return 0; } -pub trait Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl { - fn insert(&self, v: i32); -} -impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl - for Ptr -{ - fn insert(&self, mut v: i32) { - let mut i: i32 = (*self).with(|__s| __s.size); - 'loop_: while (i > 0) - && ({ - (*(*self).upgrade().deref()) - .cmp - .call(v, (array_elem!((*self), items, (i - 1)).read())) - }) - { - array_elem!((*self), items, i).write((array_elem!((*self), items, (i - 1)).read())); - i.postfix_dec(); - } - array_elem!((*self), items, i).write(v); - field!((*self), size).with_mut(|__v| __v.postfix_inc()); - } -} -pub trait Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl { - fn insert(&self, v: i32); -} -impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl - for Ptr -{ - fn insert(&self, mut v: i32) { - let mut i: i32 = (*self).with(|__s| __s.size); - 'loop_: while (i > 0) - && ({ - (*(*self).upgrade().deref()) - .cmp - .call(v, (array_elem!((*self), items, (i - 1)).read())) - }) - { - array_elem!((*self), items, i).write((array_elem!((*self), items, (i - 1)).read())); - i.postfix_dec(); - } - array_elem!((*self), items, i).write(v); - field!((*self), size).with_mut(|__v| __v.postfix_inc()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/lambda_immediate_init.rs b/tests/unit/out/refcount/lambda_immediate_init.rs index d5fe2f87bd..2ced1e422c 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -18,9 +18,9 @@ pub struct S { pub k: i32, } impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { - field!((*this), j).write(10); - field!((*this), k).write( + fn default_constructor(this: Ptr) { + field!(this, j).write(10); + field!(this, k).write( (({ FnPtr:: i32>::new(|| -> i32 { { diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index ebdd72b00f..12c53fdf5d 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -14,15 +14,34 @@ pub struct Owner { #[byte_size(8)] pub p: Ptr, } +impl Owner { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, p).write(Ptr::alloc(v)); + } + pub fn take(this: Ptr) -> FnPtr i32> { + return lambda!( + { + let self_: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ConstructFrom::construct_from(__v.as_pointer(), Moved((this).clone())); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + }, + || -> i32 { + return ({ (*self_.borrow()).p.clone() }.read()); + } + ); + } +} impl MoveConstructible for Owner { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), p).write(o.with(|__s| __s.p.clone())); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, p).write(o.with(|__s| __s.p.clone())); field!(o, p).write(Ptr::::null()); } } impl Destructible for Owner { - fn destroy(this: &Ptr) { - (*this).with(|__s| __s.p.clone()).delete(); + fn destroy(this: Ptr) { + this.with(|__s| __s.p.clone()).delete(); } } pub fn main() { @@ -35,7 +54,7 @@ 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())); + ConstructFrom::construct_from(__v.as_pointer(), Moved(o.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -44,19 +63,19 @@ fn main_0() -> i32 { } ))); let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ (*o.borrow()).p.clone() }).is_null()); assert!(({ (({ (*f.borrow()).call() }) == 5) })); let g: Value i32>> = Rc::new(RefCell::new((*f.borrow()).move_from())); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ (({ (*g.borrow()).call() }) == 5) })); let total: Value = Rc::new(RefCell::new(0)); let consume: Value> = Rc::new(RefCell::new(lambda!( { let h: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - OwnerImpl::construct(&__v.as_pointer(), 7); + Owner::construct(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let total: Ptr = total.as_pointer(); @@ -70,41 +89,17 @@ fn main_0() -> i32 { } ))); let _dtor_consume = std::mem::DropGuard::new(consume.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); ({ (*consume.borrow()).call() }); ({ (*consume.borrow()).call() }); assert!(({ ((*total.borrow()) == 7) })); object!(o2, Owner(9)); - let t: Value i32>> = - Rc::new(RefCell::new(({ OwnerImpl::take(&o2.as_pointer()) }))); + let t: Value i32>> = Rc::new(RefCell::new(({ Owner::take(o2.as_pointer()) }))); let _dtor_t = - std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ (*o2.borrow()).p.clone() }).is_null()); assert!(({ (({ (*t.borrow()).call() }) == 9) })); return 0; } -pub trait OwnerImpl { - fn construct(&self, v: i32); - fn take(&self) -> FnPtr i32>; -} -impl OwnerImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), p).write(Ptr::alloc(v)); - } - fn take(&self) -> FnPtr i32> { - return lambda!( - { - let self_: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), Moved((*self).clone())); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); - }, - || -> i32 { - return ({ (*self_.borrow()).p.clone() }.read()); - } - ); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/lambda_nested.rs b/tests/unit/out/refcount/lambda_nested.rs index 19cb26cbdb..2a9fadde0a 100644 --- a/tests/unit/out/refcount/lambda_nested.rs +++ b/tests/unit/out/refcount/lambda_nested.rs @@ -23,6 +23,29 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn nested_this(this: Ptr) -> i32 { + let outer: Value i32>> = Rc::new(RefCell::new(lambda!( + { + let this_: Value> = Rc::new(RefCell::new((this).clone())); + }, + |y: i32| -> i32 { + let y: Value = Rc::new(RefCell::new(y)); + let inner: Value i32>> = Rc::new(RefCell::new(lambda!( + { + let this_: Value> = Rc::new(RefCell::new((*this_.borrow()).clone())); + let y: Value = Rc::new(RefCell::new((*y.borrow()))); + }, + |mut z: i32| -> i32 { + return (((*this_.borrow()).with(|__s| __s.v) + (*y.borrow())) + z); + } + ))); + return ({ (*inner.borrow()).call(1) }); + } + ))); + return ({ (*outer.borrow()).call(20) }); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -51,33 +74,7 @@ fn main_0() -> i32 { (*x.borrow_mut()) = 100; assert!(({ (({ (*outer.borrow()).call(20,) }) == 121) })); let s: Value = Rc::new(RefCell::new(S { v: 5 })); - assert!((({ SImpl::nested_this(&s.as_pointer(),) }) == 26)); + assert!((({ S::nested_this(s.as_pointer(),) }) == 26)); return 0; } -pub trait SImpl { - fn nested_this(&self) -> i32; -} -impl SImpl for Ptr { - fn nested_this(&self) -> i32 { - let outer: Value i32>> = Rc::new(RefCell::new(lambda!( - { - let this_: Value> = Rc::new(RefCell::new((*self).clone())); - }, - |y: i32| -> i32 { - let y: Value = Rc::new(RefCell::new(y)); - let inner: Value i32>> = Rc::new(RefCell::new(lambda!( - { - let this_: Value> = Rc::new(RefCell::new((*this_.borrow()).clone())); - let y: Value = Rc::new(RefCell::new((*y.borrow()))); - }, - |mut z: i32| -> i32 { - return (((*this_.borrow()).with(|__s| __s.v) + (*y.borrow())) + z); - } - ))); - return ({ (*inner.borrow()).call(1) }); - } - ))); - return ({ (*outer.borrow()).call(20) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index d3c2ddbd59..ef88225324 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -30,11 +30,11 @@ pub struct UserDefined { pub v: Vec, } impl DefaultConstructible for UserDefined { - fn default_constructor(this: &Ptr) { - field!((*this), a).write(Box::<[i32]>::from(std::array::from_fn::<_, 1, _>(|_| { + fn default_constructor(this: Ptr) { + field!(this, a).write(Box::<[i32]>::from(std::array::from_fn::<_, 1, _>(|_| { 0_i32 }))); - field!((*this), v).write(Vec::new()); + field!(this, v).write(Vec::new()); } } impl Default for UserDefined { diff --git a/tests/unit/out/refcount/linked_list.rs b/tests/unit/out/refcount/linked_list.rs index eb9c1d7488..dc1e47b3a3 100644 --- a/tests/unit/out/refcount/linked_list.rs +++ b/tests/unit/out/refcount/linked_list.rs @@ -25,6 +25,11 @@ pub struct Node { #[byte_size(8)] pub next: Ptr, } +impl Node { + pub fn SetNext(this: Ptr, mut next: Ptr) { + field!(this, next).write((next).clone()); + } +} pub fn Find_0(mut head: Ptr, mut idx: i32) -> Ptr { let mut curr: Ptr = (head).clone(); { @@ -43,7 +48,7 @@ pub fn Append_1(head: Ptr, new_node: Ptr) { 'loop_: while !((curr.with(|__s| __s.next.clone())).is_null()) { curr = curr.with(|__s| __s.next.clone()); } - ({ NodeImpl::SetNext(&curr, (new_node).clone()) }); + ({ Node::SetNext((curr).clone(), (new_node).clone()) }); } pub fn Delete_2(mut head: Ptr, mut val: i32) -> Ptr { let mut curr: Ptr = (head).clone(); @@ -120,12 +125,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait NodeImpl { - fn SetNext(&self, next: Ptr); -} -impl NodeImpl for Ptr { - fn SetNext(&self, mut next: Ptr) { - field!((*self), next).write((next).clone()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index b13f4eaff4..2ee95d677a 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -23,10 +23,16 @@ pub struct Point { #[offset(4)] pub y: i32, } +impl Point { + pub fn construct_1(this: Ptr, mut x: i32, mut y: i32) { + field!(this, x).write(x); + field!(this, y).write(y); + } +} impl DefaultConstructible for Point { - fn default_constructor(this: &Ptr) { - field!((*this), x).write(0); - field!((*this), y).write(0); + fn default_constructor(this: Ptr) { + field!(this, x).write(0); + field!(this, y).write(0); } } impl Default for Point { @@ -34,7 +40,7 @@ impl Default for Point { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -739,7 +745,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key1.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct_1(&__v.as_pointer(), 3, 4); + Point::construct_1(__v.as_pointer(), 3, 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -786,7 +792,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(({ (*key8.borrow()) }))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct_1(&__v.as_pointer(), 5, 6); + Point::construct_1(__v.as_pointer(), 5, 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -972,7 +978,7 @@ fn main_0() -> i32 { }) }); Swappable::swap( - &match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { + match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { (__tmp_68,) => { ({ (*t.borrow_mut()).subscript_move(__tmp_68, |__k| cpp_move!(__k), || 0_i32) }) } @@ -1040,13 +1046,4 @@ fn main_0() -> i32 { } return 0; } -pub trait PointImpl { - fn construct_1(&self, x: i32, y: i32); -} -impl PointImpl for Ptr { - fn construct_1(&self, mut x: i32, mut y: i32) { - field!((*self), x).write(x); - field!((*self), y).write(y); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 58b0144d5b..23a1742f03 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -24,32 +24,40 @@ pub struct Key { #[offset(0)] pub k: i32, } +impl Key { + pub fn construct(this: Ptr, mut k: i32) { + field!(this, k).write(k); + } + pub fn operator_lt(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.k) } < { o.with(|__s| __s.k) }); + } +} impl CopyConstructible for Key { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), k).write(o.with(|__s| __s.k)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, k).write(o.with(|__s| __s.k)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Key { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), k).write(o.with(|__s| __s.k)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, k).write(o.with(|__s| __s.k)); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CppLess for Key { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - KeyImpl::operator_lt(__lhs, __rhs.clone()) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Key::operator_lt(__lhs.clone(), __rhs.clone()) } } impl CppEq for Key { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - !(KeyImpl::operator_lt(__lhs, __rhs.clone())) - && !(KeyImpl::operator_lt(__rhs, __lhs.clone())) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + !(Key::operator_lt(__lhs.clone(), __rhs.clone())) + && !(Key::operator_lt(__rhs.clone(), __lhs.clone())) } } -pub fn make_key_3(this: Ptr, mut k: i32) { +pub fn make_key_3(__return: Ptr, mut k: i32) { (*made_2.with(Value::clone).borrow_mut()).prefix_inc(); - KeyImpl::construct(&this, k); + Key::construct(__return.clone(), k); return; } pub fn main() { @@ -203,7 +211,7 @@ fn main_0() -> i32 { { let __tmp_12: Value = Rc::new(RefCell::new(::zero_init())); match ({ - KeyImpl::construct(&__tmp_12.as_pointer(), 0); + Key::construct(__tmp_12.as_pointer(), 0); __tmp_12.as_pointer() },) { @@ -309,18 +317,6 @@ fn main_0() -> i32 { ); return if ok { 0 } else { 1 }; } -pub trait KeyImpl { - fn construct(&self, k: i32); - fn operator_lt(&self, o: Ptr) -> bool; -} -impl KeyImpl for Ptr { - fn construct(&self, mut k: i32) { - field!((*self), k).write(k); - } - fn operator_lt(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.k) } < { o.with(|__s| __s.k) }); - } -} pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); let _ = moves_1.with(|_| ()); diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index eb19207a9c..6576af11ae 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -29,12 +29,12 @@ pub struct Key { pub identity: i32, } impl CppLess for Key { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_1(__lhs.clone(), __rhs.clone()) } } impl CppEq for Key { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_2(__lhs.clone(), __rhs.clone()) } } @@ -51,8 +51,8 @@ pub struct Mapped { pub value: i32, } impl DefaultConstructible for Mapped { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(0); + fn default_constructor(this: Ptr) { + field!(this, value).write(0); (*default_constructions_0.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -61,7 +61,7 @@ impl Default for Mapped { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 1cc1ffa71d..bd21add8dd 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -25,20 +25,26 @@ pub struct Item { #[offset(0)] pub value: i32, } +impl Item { + pub fn construct_1(this: Ptr, mut value: i32) { + field!(this, value).write(value); + (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl DefaultConstructible for Item { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(0); + fn default_constructor(this: Ptr) { + field!(this, value).write(0); } } impl CopyConstructible for Item { - fn copy_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn copy_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Item { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); field!(other, value).write(-1_i32); } @@ -48,7 +54,7 @@ impl Default for Item { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -64,9 +70,20 @@ pub struct RefItem { #[offset(0)] pub value: i32, } +impl RefItem { + pub fn construct_1(this: Ptr, counter: Ptr, mut amount: i32) { + field!(this, value).write({ + { + counter.with_mut(|__v| *__v = *__v + amount) + }; + (counter.read()) + }); + (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl DefaultConstructible for RefItem { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(0); + fn default_constructor(this: Ptr) { + field!(this, value).write(0); } } impl Default for RefItem { @@ -74,7 +91,7 @@ impl Default for RefItem { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -346,7 +363,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), 10); + Item::construct_1(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -380,7 +397,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), (__tmp_6).clone()); + ConstructFrom::construct_from(__v.as_pointer(), (__tmp_6).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -420,7 +437,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( - &__v.as_pointer(), + __v.as_pointer(), Moved((__tmp_7).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -460,7 +477,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), (__tmp_8).clone()); + ConstructFrom::construct_from(__v.as_pointer(), (__tmp_8).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -501,7 +518,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( - &__v.as_pointer(), + __v.as_pointer(), Moved((__tmp_9).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -540,7 +557,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItemImpl::construct_1(&__v.as_pointer(), counter.as_pointer(), 5); + RefItem::construct_1(__v.as_pointer(), counter.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -562,7 +579,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItemImpl::construct_1(&__v.as_pointer(), (__tmp_10).clone(), 2); + RefItem::construct_1(__v.as_pointer(), (__tmp_10).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -593,7 +610,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItemImpl::construct_1(&__v.as_pointer(), (__tmp_11).clone(), 2); + RefItem::construct_1(__v.as_pointer(), (__tmp_11).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -640,7 +657,7 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new({ let __tmp_13: Value = Rc::new(RefCell::new(::zero_init())); match ({ - ItemImpl::construct_1(&__tmp_13.as_pointer(), 30); + Item::construct_1(__tmp_13.as_pointer(), 30); __tmp_13.as_pointer() },) { @@ -652,7 +669,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( - &__v.as_pointer(), + __v.as_pointer(), Moved((__tmp_12).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -683,7 +700,7 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new({ let __tmp_15: Value = Rc::new(RefCell::new(::zero_init())); match ({ - ItemImpl::construct_1(&__tmp_15.as_pointer(), 40); + Item::construct_1(__tmp_15.as_pointer(), 40); __tmp_15.as_pointer() },) { @@ -695,7 +712,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( - &__v.as_pointer(), + __v.as_pointer(), Moved((__tmp_14).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -734,29 +751,6 @@ fn main_0() -> i32 { ); return if ok { 0 } else { 1 }; } -pub trait ItemImpl { - fn construct_1(&self, value: i32); -} -impl ItemImpl for Ptr { - fn construct_1(&self, mut value: i32) { - field!((*self), value).write(value); - (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait RefItemImpl { - fn construct_1(&self, counter: Ptr, amount: i32); -} -impl RefItemImpl for Ptr { - fn construct_1(&self, counter: Ptr, mut amount: i32) { - field!((*self), value).write({ - { - counter.with_mut(|__v| *__v = *__v + amount) - }; - (counter.read()) - }); - (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = calls_0.with(|_| ()); let _ = made_1.with(|_| ()); diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index b12eb41467..0b80f5ae8b 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -18,9 +18,20 @@ pub struct Item { #[offset(0)] pub value: i32, } +impl Item { + pub fn construct_1(this: Ptr, counter: Ptr, mut amount: i32) { + field!(this, value).write({ + { + counter.with_mut(|__v| *__v = *__v + amount) + }; + (counter.read()) + }); + (*made_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl DefaultConstructible for Item { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(0); + fn default_constructor(this: Ptr) { + field!(this, value).write(0); } } impl Default for Item { @@ -28,7 +39,7 @@ impl Default for Item { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -58,9 +69,9 @@ pub struct Temporary { pub data: Box<[i32]>, } impl DefaultConstructible for Temporary { - fn default_constructor(this: &Ptr) { - field!((*this), n).write(5); - field!((*this), data).write(Box::new([6, 7])); + fn default_constructor(this: Ptr) { + field!(this, n).write(5); + field!(this, data).write(Box::new([6, 7])); (*temporary_calls_4.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -69,7 +80,7 @@ impl Default for Temporary { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -85,21 +96,21 @@ pub struct Nested { pub inner: Temporary, } impl DefaultConstructible for Nested { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, inner)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, inner)); } } pub fn make_temporary_5() -> Temporary { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn make_nested_6() -> Nested { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -111,11 +122,16 @@ pub struct Owner { #[byte_size(8)] pub ptr: Option>, } +impl Owner { + pub fn value(this: Ptr) -> Ptr { + return field_ptr!(this.with(|__s| __s.ptr.clone()).as_pointer(), n); + } +} impl DefaultConstructible for Owner { - fn default_constructor(this: &Ptr) { - field!((*this), ptr).write(Some(Rc::new(RefCell::new({ + fn default_constructor(this: Ptr) { + field!(this, ptr).write(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })))); } @@ -125,7 +141,7 @@ impl Default for Owner { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -138,8 +154,8 @@ pub struct Noncopy { pub n: i32, } impl DefaultConstructible for Noncopy { - fn default_constructor(this: &Ptr) { - field!((*this), n).write(5); + fn default_constructor(this: Ptr) { + field!(this, n).write(5); } } impl Default for Noncopy { @@ -157,9 +173,17 @@ pub struct Held { #[byte_size(8)] pub ptr: Ptr, } +impl Held { + pub fn construct_1(this: Ptr, n: Ptr) { + field!(this, ptr).write((n).clone()); + } + pub fn construct_2(this: Ptr, n: Ptr, mut _a1: i32) { + field!(this, ptr).write((n).clone()); + } +} impl DefaultConstructible for Held { - fn default_constructor(this: &Ptr) { - field!((*this), ptr).write(Ptr::::null()); + fn default_constructor(this: Ptr) { + field!(this, ptr).write(Ptr::::null()); } } impl Default for Held { @@ -167,7 +191,7 @@ impl Default for Held { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -283,7 +307,7 @@ thread_local!( (*{ __tmp_7 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_7 @@ -378,7 +402,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), counter.as_pointer(), 3); + Item::construct_1(__v.as_pointer(), counter.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -406,7 +430,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_9).clone(), 2); + Item::construct_1(__v.as_pointer(), (__tmp_9).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -444,7 +468,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_11).clone(), 2); + Item::construct_1(__v.as_pointer(), (__tmp_11).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -479,7 +503,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_13).clone(), 2); + Item::construct_1(__v.as_pointer(), (__tmp_13).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -515,7 +539,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_16).clone(), 2); + Item::construct_1(__v.as_pointer(), (__tmp_16).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -560,7 +584,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_19).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_19).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -591,7 +615,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_21).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_21).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -622,7 +646,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_24).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_24).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -661,7 +685,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_27).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_27).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -702,7 +726,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_30).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_30).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -729,7 +753,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_33).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_33).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -1246,8 +1270,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - ItemImpl::construct_1( - &__v.as_pointer(), + Item::construct_1( + __v.as_pointer(), (__tmp_61).clone(), 2, ); @@ -1299,8 +1323,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - ItemImpl::construct_1( - &__v.as_pointer(), + Item::construct_1( + __v.as_pointer(), (__tmp_64).clone(), 2, ); @@ -1352,8 +1376,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - ItemImpl::construct_1( - &__v.as_pointer(), + Item::construct_1( + __v.as_pointer(), (__tmp_69).clone(), 2, ); @@ -1616,8 +1640,8 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - HeldImpl::construct_1( - &__v.as_pointer(), + Held::construct_1( + __v.as_pointer(), ordinary.as_pointer(), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -1669,8 +1693,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - HeldImpl::construct_1( - &__v.as_pointer(), + Held::construct_1( + __v.as_pointer(), (__tmp_83).clone(), ); Rc::try_unwrap(__v) @@ -1724,8 +1748,8 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - HeldImpl::construct_2( - &__v.as_pointer(), + Held::construct_2( + __v.as_pointer(), ordinary_array.decay(), 0, ); @@ -1777,8 +1801,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - HeldImpl::construct_2( - &__v.as_pointer(), + Held::construct_2( + __v.as_pointer(), (__tmp_88).clone(), 0, ); @@ -1846,7 +1870,7 @@ fn main_0() -> i32 { __tmp_94 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_94 @@ -1883,7 +1907,7 @@ fn main_0() -> i32 { __tmp_96 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_96 @@ -1921,7 +1945,7 @@ fn main_0() -> i32 { __tmp_98 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_98 @@ -1958,7 +1982,7 @@ fn main_0() -> i32 { __tmp_100 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_100 @@ -1994,7 +2018,7 @@ fn main_0() -> i32 { __tmp_102 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_102 @@ -2030,7 +2054,7 @@ fn main_0() -> i32 { __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })))))); &mut __tmp_104 @@ -2106,8 +2130,8 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - HeldImpl::construct_1( - &__v.as_pointer(), + Held::construct_1( + __v.as_pointer(), ordinary.as_pointer(), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -2136,7 +2160,7 @@ fn main_0() -> i32 { RefCell::new(::zero_init()), ); DefaultConstructible::default_constructor( - &__v.as_pointer(), + __v.as_pointer(), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); @@ -2153,7 +2177,7 @@ fn main_0() -> i32 { RefCell::new(::zero_init()), ); DefaultConstructible::default_constructor( - &__v.as_pointer(), + __v.as_pointer(), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); @@ -2178,8 +2202,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - HeldImpl::construct_1( - &__v.as_pointer(), + Held::construct_1( + __v.as_pointer(), (__tmp_105).clone(), ); Rc::try_unwrap(__v) @@ -2223,9 +2247,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(::zero_init())); { match (({ - OwnerImpl::value(&{ + Owner::value({ DefaultConstructible::default_constructor( - &__tmp_109.as_pointer(), + __tmp_109.as_pointer(), ); __tmp_109.as_pointer() }) @@ -2244,8 +2268,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - HeldImpl::construct_1( - &__v.as_pointer(), + Held::construct_1( + __v.as_pointer(), (__tmp_108).clone(), ); Rc::try_unwrap(__v) @@ -2301,7 +2325,7 @@ fn main_0() -> i32 { match ({ __tmp_111 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); __tmp_111.as_pointer() @@ -2341,7 +2365,7 @@ fn main_0() -> i32 { match ({ __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); __tmp_113.as_pointer() @@ -2495,40 +2519,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait HeldImpl { - fn construct_1(&self, n: Ptr); - fn construct_2(&self, n: Ptr, _a1: i32); -} -impl HeldImpl for Ptr { - fn construct_1(&self, n: Ptr) { - field!((*self), ptr).write((n).clone()); - } - fn construct_2(&self, n: Ptr, mut _a1: i32) { - field!((*self), ptr).write((n).clone()); - } -} -pub trait ItemImpl { - fn construct_1(&self, counter: Ptr, amount: i32); -} -impl ItemImpl for Ptr { - fn construct_1(&self, counter: Ptr, mut amount: i32) { - field!((*self), value).write({ - { - counter.with_mut(|__v| *__v = *__v + amount) - }; - (counter.read()) - }); - (*made_0.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait OwnerImpl { - fn value(&self) -> Ptr; -} -impl OwnerImpl for Ptr { - fn value(&self) -> Ptr { - return field_ptr!((*self).with(|__s| __s.ptr.clone()).as_pointer(), n); - } -} pub fn __cpp2rust_init_globals() { let _ = made_0.with(|_| ()); let _ = visits_1.with(|_| ()); diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index fcf972442b..fdd9e50724 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -40,19 +40,24 @@ pub struct Bag { #[offset(0)] pub n: i32, } +impl Bag { + pub fn construct(this: Ptr, mut n: i32) { + field!(this, n).write(n); + } +} impl CopyConstructible for Bag { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), n).write(o.with(|__s| __s.n)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, n).write(o.with(|__s| __s.n)); (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CppLess for Bag { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_4(__lhs.clone(), __rhs.clone()) } } impl CppEq for Bag { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { !(operator_lt_4(__lhs.clone(), __rhs.clone())) && !(operator_lt_4(__rhs.clone(), __lhs.clone())) } @@ -60,8 +65,8 @@ impl CppEq for Bag { pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.n) } < { b.with(|__s| __s.n) }); } -pub fn make_5(this: Ptr, mut n: i32) { - BagImpl::construct(&this, n); +pub fn make_5(__return: Ptr, mut n: i32) { + Bag::construct(__return.clone(), n); return; } pub fn main() { @@ -75,25 +80,25 @@ fn main_0() -> i32 { let x4: Value = Rc::new(RefCell::new(20)); let mut p1: Ptr = (x1.as_pointer()); let mut p2: Ptr = (x2.as_pointer()); - let mut r1: i32 = (if CppLess::less(&x1.as_pointer(), &x2.as_pointer()) { + let mut r1: i32 = (if CppLess::less(x1.as_pointer().clone(), x2.as_pointer().clone()) { x2.as_pointer() } else { x1.as_pointer() } .read()); - let mut r2: i32 = (if CppLess::less(&x4.as_pointer(), &x3.as_pointer()) { + let mut r2: i32 = (if CppLess::less(x4.as_pointer().clone(), x3.as_pointer().clone()) { x4.as_pointer() } else { x3.as_pointer() } .read()); - let mut r3: i32 = (if CppLess::less(&(p1).clone(), &x2.as_pointer()) { + let mut r3: i32 = (if CppLess::less((p1).clone().clone(), x2.as_pointer().clone()) { x2.as_pointer() } else { (p1).clone() } .read()); - let mut r4: i32 = (if CppLess::less(&x3.as_pointer(), &(p2).clone()) { + let mut r4: i32 = (if CppLess::less(x3.as_pointer().clone(), (p2).clone().clone()) { x3.as_pointer() } else { (p2).clone() @@ -102,7 +107,7 @@ fn main_0() -> i32 { let mut r5: i32 = { let __tmp_0: Value = Rc::new(RefCell::new(30)); let __tmp_1: Value = Rc::new(RefCell::new(40)); - (if CppLess::less(&__tmp_0.as_pointer(), &__tmp_1.as_pointer()) { + (if CppLess::less(__tmp_0.as_pointer().clone(), __tmp_1.as_pointer().clone()) { __tmp_1.as_pointer() } else { __tmp_0.as_pointer() @@ -119,7 +124,7 @@ fn main_0() -> i32 { let mut __it = (__tmp_2).clone(); __it.iter_inc(); while __it != __tmp_3 { - if CppLess::less(&__best.iter_deref(), &__it.iter_deref()) { + if CppLess::less(__best.iter_deref(), __it.iter_deref()) { __best = __it.clone(); } __it.iter_inc(); @@ -131,7 +136,7 @@ fn main_0() -> i32 { assert!( ((match (({ pick_3(0,) }), ({ pick_3(1,) }),) { (__tmp_4, __tmp_5) => { - if CppLess::less(&(__tmp_4).clone(), &(__tmp_5).clone()) { + if CppLess::less((__tmp_4).clone().clone(), (__tmp_5).clone().clone()) { (__tmp_5).clone() } else { (__tmp_4).clone() @@ -145,7 +150,7 @@ fn main_0() -> i32 { assert!( ((match (({ pick_3(1,) }), ({ pick_3(0,) }),) { (__tmp_6, __tmp_7) => { - if CppLess::less(&(__tmp_7).clone(), &(__tmp_6).clone()) { + if CppLess::less((__tmp_7).clone().clone(), (__tmp_6).clone().clone()) { (__tmp_7).clone() } else { (__tmp_6).clone() @@ -172,7 +177,7 @@ fn main_0() -> i32 { }, ) { (__tmp_8, __tmp_10) => { - if CppLess::less(&(__tmp_8).clone(), &(__tmp_10).clone()) { + if CppLess::less((__tmp_8).clone().clone(), (__tmp_10).clone().clone()) { (__tmp_10).clone() } else { (__tmp_8).clone() @@ -195,7 +200,7 @@ fn main_0() -> i32 { }, ) { (__tmp_12, __tmp_14) => { - if CppLess::less(&(__tmp_14).clone(), &(__tmp_12).clone()) { + if CppLess::less((__tmp_14).clone().clone(), (__tmp_12).clone().clone()) { (__tmp_14).clone() } else { (__tmp_12).clone() @@ -216,7 +221,10 @@ fn main_0() -> i32 { let __tmp_17: Value = Rc::new(RefCell::new((largest as u64))); (match (Rc::new(RefCell::new((({ size_of_2(i) }) as u64))).as_pointer(),) { (__tmp_16,) => { - if CppLess::less(&__tmp_17.as_pointer(), &(__tmp_16).clone()) { + if CppLess::less( + __tmp_17.as_pointer().clone(), + (__tmp_16).clone().clone(), + ) { (__tmp_16).clone() } else { __tmp_17.as_pointer() @@ -232,14 +240,6 @@ fn main_0() -> i32 { assert!((largest == 6_usize) && (calls_0.with(|rc| *rc.borrow()) == 3)); return 0; } -pub trait BagImpl { - fn construct(&self, n: i32); -} -impl BagImpl for Ptr { - fn construct(&self, mut n: i32) { - field!((*self), n).write(n); - } -} pub fn __cpp2rust_init_globals() { let _ = calls_0.with(|_| ()); let _ = xs_1.with(|_| ()); diff --git a/tests/unit/out/refcount/min_max_ptr2ptr.rs b/tests/unit/out/refcount/min_max_ptr2ptr.rs index 2250c063af..6c2a8acd49 100644 --- a/tests/unit/out/refcount/min_max_ptr2ptr.rs +++ b/tests/unit/out/refcount/min_max_ptr2ptr.rs @@ -17,13 +17,13 @@ fn main_0() -> i32 { let pb: Value> = Rc::new(RefCell::new((b.as_pointer()))); let mut ppa: Ptr> = (pa.as_pointer()); let mut ppb: Ptr> = (pb.as_pointer()); - let mut r1: i32 = (if CppLess::less(&(ppa.read()), &(ppb.read())) { + let mut r1: i32 = (if CppLess::less((ppa.read()).clone(), (ppb.read()).clone()) { (ppb.read()) } else { (ppa.read()) } .read()); - let mut r2: i32 = (if CppLess::less(&(ppb.read()), &(ppa.read())) { + let mut r2: i32 = (if CppLess::less((ppb.read()).clone(), (ppa.read()).clone()) { (ppb.read()) } else { (ppa.read()) @@ -36,7 +36,7 @@ fn main_0() -> i32 { assert!( ({ ({ - (if CppLess::less(&high.as_pointer(), &low.as_pointer()) { + (if CppLess::less(high.as_pointer().clone(), low.as_pointer().clone()) { high.as_pointer() } else { low.as_pointer() @@ -48,7 +48,7 @@ fn main_0() -> i32 { assert!( ({ ({ - (if CppLess::less(&low.as_pointer(), &high.as_pointer()) { + (if CppLess::less(low.as_pointer().clone(), high.as_pointer().clone()) { low.as_pointer() } else { high.as_pointer() @@ -60,7 +60,7 @@ fn main_0() -> i32 { assert!( ({ ({ - (if CppLess::less(&low.as_pointer(), &high.as_pointer()) { + (if CppLess::less(low.as_pointer().clone(), high.as_pointer().clone()) { high.as_pointer() } else { low.as_pointer() @@ -72,7 +72,7 @@ fn main_0() -> i32 { assert!( ({ ({ - (if CppLess::less(&high.as_pointer(), &low.as_pointer()) { + (if CppLess::less(high.as_pointer().clone(), low.as_pointer().clone()) { low.as_pointer() } else { high.as_pointer() diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 949339cca3..5664557646 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -22,20 +22,25 @@ pub struct MoveOnly { #[offset(0)] pub v: i32, } +impl MoveOnly { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for MoveOnly { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { - if ((*this) == (o)) { - return (*this).clone(); + fn move_assign(this: Ptr, o: Ptr) -> Ptr { + if (this == (o)) { + return (this).clone(); } - field!((*this), v).write(o.with(|__s| __s.v)); + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); - return (*this).clone(); + return (this).clone(); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] @@ -44,9 +49,19 @@ pub struct ConstMoveAssign { #[offset(0)] pub mark: i32, } +impl ConstMoveAssign { + pub fn operator_assign_2(this: Ptr, o: Ptr) -> Ptr { + field!(this, mark).write((o.with(|__s| __s.mark) + 1)); + return (this).clone(); + } + pub fn operator_assign_3(this: Ptr, o: Ptr) -> Ptr { + field!(this, mark).write((o.with(|__s| __s.mark) + 10)); + return (this).clone(); + } +} impl DefaultConstructible for ConstMoveAssign { - fn default_constructor(this: &Ptr) { - field!((*this), mark).write(0); + fn default_constructor(this: Ptr) { + field!(this, mark).write(0); } } impl Default for ConstMoveAssign { @@ -55,15 +70,15 @@ impl Default for ConstMoveAssign { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } -pub fn make_0(this: Ptr, mut v: i32) { +pub fn make_0(__return: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(&this, Moved(m.as_pointer())); + ConstructFrom::construct_from(__return.clone(), Moved(m.as_pointer())); return; } pub fn main() { @@ -79,7 +94,7 @@ fn main_0() -> i32 { assert!(({ (*b.borrow()).v } == 0)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::construct(&_o.as_pointer(), 3); + MoveOnly::construct(_o.as_pointer(), 3); assign!(b = Moved(_o)) }); assign!(c = Moved(*assign!(a = Moved(b)))); @@ -88,7 +103,7 @@ fn main_0() -> i32 { ); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::construct(&_o.as_pointer(), 5); + MoveOnly::construct(_o.as_pointer(), 5); assign!(a = Moved(_o)) }); assert!(({ (*a.borrow()).v } == 5)); @@ -104,7 +119,7 @@ fn main_0() -> i32 { { let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); match ({ - MoveOnlyImpl::construct(&__tmp_1.as_pointer(), 7); + MoveOnly::construct(__tmp_1.as_pointer(), 7); __tmp_1.as_pointer() },) { @@ -119,32 +134,10 @@ fn main_0() -> i32 { object!(m1, ConstMoveAssign); object!(m2, ConstMoveAssign); object!(cm, ConstMoveAssign); - ConstMoveAssignImpl::operator_assign_2(&m1.as_pointer(), m.as_pointer()); - ConstMoveAssignImpl::operator_assign_3(&m2.as_pointer(), cm.as_pointer()); + ConstMoveAssign::operator_assign_2(m1.as_pointer(), m.as_pointer()); + ConstMoveAssign::operator_assign_3(m2.as_pointer(), cm.as_pointer()); assert!(({ (*m1.borrow()).mark } == 1)); assert!(({ (*m2.borrow()).mark } == 10)); return 0; } -pub trait ConstMoveAssignImpl { - fn operator_assign_2(&self, o: Ptr) -> Ptr; - fn operator_assign_3(&self, o: Ptr) -> Ptr; -} -impl ConstMoveAssignImpl for Ptr { - fn operator_assign_2(&self, o: Ptr) -> Ptr { - field!((*self), mark).write((o.with(|__s| __s.mark) + 1)); - return (*self).clone(); - } - fn operator_assign_3(&self, o: Ptr) -> Ptr { - field!((*self), mark).write((o.with(|__s| __s.mark) + 10)); - return (*self).clone(); - } -} -pub trait MoveOnlyImpl { - fn construct(&self, v: i32); -} -impl MoveOnlyImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index a08b6ac284..97c764b6c1 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -15,9 +15,14 @@ pub struct MoveOnly { #[offset(0)] pub v: i32, } +impl MoveOnly { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } @@ -27,9 +32,17 @@ pub struct ConstMove { #[offset(0)] pub mark: i32, } +impl ConstMove { + pub fn construct_1(this: Ptr, o: Ptr) { + field!(this, mark).write((o.with(|__s| __s.mark) + 1)); + } + pub fn construct_2(this: Ptr, o: Ptr) { + field!(this, mark).write((o.with(|__s| __s.mark) + 10)); + } +} impl DefaultConstructible for ConstMove { - fn default_constructor(this: &Ptr) { - field!((*this), mark).write(0); + fn default_constructor(this: Ptr) { + field!(this, mark).write(0); } } impl Default for ConstMove { @@ -37,7 +50,7 @@ impl Default for ConstMove { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -56,18 +69,25 @@ pub struct ThrowingMove { #[offset(8)] pub moves: i32, } +impl ThrowingMove { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for ThrowingMove { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for ThrowingMove { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } @@ -84,27 +104,34 @@ pub struct NoexceptMove { #[offset(8)] pub moves: i32, } +impl NoexceptMove { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for NoexceptMove { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for NoexceptMove { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } pub fn by_value_0(m: Ptr) -> i32 { return m.with(|__s| __s.v); } -pub fn make_1(this: Ptr, mut v: i32) { +pub fn make_1(__return: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(&this, Moved(m.as_pointer())); + ConstructFrom::construct_from(__return.clone(), Moved(m.as_pointer())); return; } pub fn main() { @@ -122,19 +149,19 @@ fn main_0() -> i32 { object!(d, MoveOnly, Moved(c.as_pointer())); assert!(({ (*d.borrow()).v } == 1)); assert!(({ (*c.borrow()).v } == 0)); - object!(e, MoveOnly, |e| ({ make_1(Ptr::clone(e), 5,) })); + object!(e, MoveOnly, |e| ({ make_1(Ptr::clone(&e.clone()), 5,) })); assert!(({ (*e.borrow()).v } == 5)); assert!( (({ let _m: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::construct(&_m.as_pointer(), 6); + MoveOnly::construct(_m.as_pointer(), 6); by_value_0(_m.as_pointer()) }) == 6) ); assert!( (({ let _m: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_m.as_pointer(), Moved(e.as_pointer())); + ConstructFrom::construct_from(_m.as_pointer(), Moved(e.as_pointer())); by_value_0(_m.as_pointer()) }) == 5) ); @@ -143,7 +170,7 @@ fn main_0() -> i32 { { let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); match ({ - MoveOnlyImpl::construct(&__tmp_1.as_pointer(), 7); + MoveOnly::construct(__tmp_1.as_pointer(), 7); __tmp_1.as_pointer() },) { @@ -180,7 +207,7 @@ fn main_0() -> i32 { { let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); match ({ - NoexceptMoveImpl::construct(&__tmp_3.as_pointer(), 4); + NoexceptMove::construct(__tmp_3.as_pointer(), 4); __tmp_3.as_pointer() },) { @@ -193,44 +220,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait ConstMoveImpl { - fn construct_1(&self, o: Ptr); - fn construct_2(&self, o: Ptr); -} -impl ConstMoveImpl for Ptr { - fn construct_1(&self, o: Ptr) { - field!((*self), mark).write((o.with(|__s| __s.mark) + 1)); - } - fn construct_2(&self, o: Ptr) { - field!((*self), mark).write((o.with(|__s| __s.mark) + 10)); - } -} -pub trait MoveOnlyImpl { - fn construct(&self, v: i32); -} -impl MoveOnlyImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} -pub trait NoexceptMoveImpl { - fn construct(&self, v: i32); -} -impl NoexceptMoveImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} -pub trait ThrowingMoveImpl { - fn construct(&self, v: i32); -} -impl ThrowingMoveImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index 81c681c21d..de74dd8d5d 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -15,14 +15,42 @@ pub struct Chain { #[offset(0)] pub v: i32, } +impl Chain { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } + pub fn add_4(this: Ptr, mut n: i32) -> Ptr { + { + field!(this, v).with_mut(|__v| *__v = *__v + n) + }; + return (this).clone(); + } + pub fn add_5(this: Ptr, mut n: i32) -> Ptr { + { + field!(this, v).with_mut(|__v| *__v = *__v + n) + }; + return (this).clone(); + } + pub fn take(this: Ptr, __return: Ptr) { + ConstructFrom::construct_from(__return.clone(), Moved((this).clone())); + return; + } + pub fn copy(this: Ptr, __return: Ptr) { + ConstructFrom::construct_from(__return.clone(), (this).clone()); + return; + } + pub fn self_(this: Ptr) -> Ptr { + return (this).clone(); + } +} impl CopyConstructible for Chain { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write((o.with(|__s| __s.v) + 100)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write((o.with(|__s| __s.v) + 100)); } } impl MoveConstructible for Chain { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write((o.with(|__s| __s.v) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write((o.with(|__s| __s.v) + 1)); field!(o, v).write(0); } } @@ -35,30 +63,30 @@ pub fn main() { } fn main_0() -> i32 { object!(a, Chain(1)); - ({ ChainImpl::add_4(&({ ChainImpl::add_4(&a.as_pointer(), 1) }), 1) }); + ({ Chain::add_4(({ Chain::add_4(a.as_pointer(), 1) }), 1) }); assert!(({ (*a.borrow()).v } == 3)); object!(b0, Chain(5)); object!( b, Chain, - Moved(({ ChainImpl::add_5(&({ ChainImpl::add_5(&b0.as_pointer(), 1,) }), 1,) })) + Moved(({ Chain::add_5(({ Chain::add_5(b0.as_pointer(), 1,) }), 1,) })) ); assert!(({ (*b.borrow()).v } == 8) && ({ (*b0.borrow()).v } == 0)); object!(c, Chain, |c| { let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); ({ - ChainImpl::take( - &{ - ChainImpl::construct(&__tmp_0.as_pointer(), 10); + Chain::take( + { + Chain::construct(__tmp_0.as_pointer(), 10); __tmp_0.as_pointer() }, - Ptr::clone(c), + Ptr::clone(&c.clone()), ) }) }); assert!(({ (*c.borrow()).v } == 11)); object!(d, Chain, |d| ({ - ChainImpl::copy(&c.as_pointer(), Ptr::clone(d)) + Chain::copy(c.as_pointer(), Ptr::clone(&d.clone())) })); assert!(({ (*d.borrow()).v } == 111) && ({ (*c.borrow()).v } == 11)); object!(g, Chain(20)); @@ -66,53 +94,17 @@ fn main_0() -> i32 { (({ let _c: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( - &_c.as_pointer(), - Moved(({ ChainImpl::self_(&g.as_pointer()) })), + _c.as_pointer(), + Moved(({ Chain::self_(g.as_pointer()) })), ); consume_0(_c.as_pointer()) }) == 21) ); object!(e, Chain(30)); object!(f, Chain, |f| ({ - ChainImpl::take(&e.as_pointer(), Ptr::clone(f)) + Chain::take(e.as_pointer(), Ptr::clone(&f.clone())) })); assert!(({ (*f.borrow()).v } == 31) && ({ (*e.borrow()).v } == 0)); return 0; } -pub trait ChainImpl { - fn construct(&self, v: i32); - fn add_4(&self, n: i32) -> Ptr; - fn add_5(&self, n: i32) -> Ptr; - fn take(&self, this: Ptr); - fn copy(&self, this: Ptr); - fn self_(&self) -> Ptr; -} -impl ChainImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } - fn add_4(&self, mut n: i32) -> Ptr { - { - field!((*self), v).with_mut(|__v| *__v = *__v + n) - }; - return (*self).clone(); - } - fn add_5(&self, mut n: i32) -> Ptr { - { - field!((*self), v).with_mut(|__v| *__v = *__v + n) - }; - return (*self).clone(); - } - fn take(&self, this: Ptr) { - ConstructFrom::construct_from(&this, Moved((*self).clone())); - return; - } - fn copy(&self, this: Ptr) { - ConstructFrom::construct_from(&this, (*self).clone()); - return; - } - fn self_(&self) -> Ptr { - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/nttp_distinct_specializations.rs b/tests/unit/out/refcount/nttp_distinct_specializations.rs index 50684d62f7..048c716494 100644 --- a/tests/unit/out/refcount/nttp_distinct_specializations.rs +++ b/tests/unit/out/refcount/nttp_distinct_specializations.rs @@ -25,6 +25,11 @@ pub struct S_2_ { #[offset(4)] pub w: i32, } +impl S_2_ { + pub fn get(this: Ptr) -> i32 { + return (this.with(|__s| __s.v) - this.with(|__s| __s.w)); + } +} #[derive( Copy, Clone, @@ -42,6 +47,11 @@ pub struct S_1_ { #[offset(0)] pub v: i32, } +impl S_1_ { + pub fn get(this: Ptr) -> i32 { + return (this.with(|__s| __s.v) * 1); + } +} #[derive( Copy, Clone, @@ -59,6 +69,11 @@ pub struct S_3_ { #[offset(0)] pub v: i32, } +impl S_3_ { + pub fn get(this: Ptr) -> i32 { + return (this.with(|__s| __s.v) * 3); + } +} pub fn scale_0(mut x: i32) -> i32 { return (x * 1); } @@ -94,9 +109,9 @@ fn main_0() -> i32 { let s1: Value = Rc::new(RefCell::new(S_1_ { v: 5 })); let s2: Value = Rc::new(RefCell::new(S_2_ { v: 5, w: 1 })); let s3: Value = Rc::new(RefCell::new(S_3_ { v: 5 })); - assert!((({ S_1_Impl::get(&s1.as_pointer(),) }) == 5)); - assert!((({ S_2_Impl::get(&s2.as_pointer(),) }) == 4)); - assert!((({ S_3_Impl::get(&s3.as_pointer(),) }) == 15)); + assert!((({ S_1_::get(s1.as_pointer(),) }) == 5)); + assert!((({ S_2_::get(s2.as_pointer(),) }) == 4)); + assert!((({ S_3_::get(s3.as_pointer(),) }) == 15)); assert!((({ scale_0(7,) }) == 7)); assert!((({ scale_2(7,) }) == 5)); assert!((({ scale_1(7,) }) == 21)); @@ -114,28 +129,4 @@ fn main_0() -> i32 { assert!((ld_inf < 0_f64)); return 0; } -pub trait S_1_Impl { - fn get(&self) -> i32; -} -impl S_1_Impl for Ptr { - fn get(&self) -> i32 { - return ((*self).with(|__s| __s.v) * 1); - } -} -pub trait S_2_Impl { - fn get(&self) -> i32; -} -impl S_2_Impl for Ptr { - fn get(&self) -> i32 { - return ((*self).with(|__s| __s.v) - (*self).with(|__s| __s.w)); - } -} -pub trait S_3_Impl { - fn get(&self) -> i32; -} -impl S_3_Impl for Ptr { - fn get(&self) -> i32 { - return ((*self).with(|__s| __s.v) * 3); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/opaque_record_copy.rs b/tests/unit/out/refcount/opaque_record_copy.rs index 868fa37299..05c563cafd 100644 --- a/tests/unit/out/refcount/opaque_record_copy.rs +++ b/tests/unit/out/refcount/opaque_record_copy.rs @@ -51,10 +51,4 @@ fn main_0() -> i32 { assert!((b.tag == 3)); return 0; } -pub trait ProbeImpl { - fn operator_inc(&self) -> Ptr { - unimplemented!() - } -} -impl ProbeImpl for Ptr {} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_arithmetic_member.rs b/tests/unit/out/refcount/operator_arithmetic_member.rs index 14fb214da2..37a0b9d95d 100644 --- a/tests/unit/out/refcount/operator_arithmetic_member.rs +++ b/tests/unit/out/refcount/operator_arithmetic_member.rs @@ -23,119 +23,105 @@ pub struct S { #[offset(0)] pub v: i32, } -pub fn main() { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0()); -} -fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(S { v: 7 })); - let b: Value = Rc::new(RefCell::new(S { v: 2 })); - assert!(({ ({ SImpl::operator_add_1(&a.as_pointer(), b.as_pointer(),) }).v } == 9)); - assert!(({ ({ SImpl::operator_sub_2(&a.as_pointer(), b.as_pointer(),) }).v } == 5)); - assert!(({ ({ SImpl::operator_mul(&a.as_pointer(), b.as_pointer(),) }).v } == 14)); - assert!(({ ({ SImpl::operator_div(&a.as_pointer(), b.as_pointer(),) }).v } == 3)); - assert!(({ ({ SImpl::operator_rem(&a.as_pointer(), b.as_pointer(),) }).v } == 1)); - assert!(({ ({ SImpl::operator_pos_6(&a.as_pointer(),) }).v } == 7)); - assert!(({ ({ SImpl::operator_neg_7(&a.as_pointer(),) }).v } == -7_i32)); - assert!((({ SImpl::operator_inc_8(&a.as_pointer(),) }).with(|__s| (__s).v) == 8)); - assert!(({ ({ SImpl::operator_post_inc_9(&a.as_pointer(), 0,) }).v } == 8)); - assert!(({ (*a.borrow()).v } == 9)); - assert!((({ SImpl::operator_dec_10(&a.as_pointer(),) }).with(|__s| (__s).v) == 8)); - assert!(({ ({ SImpl::operator_post_dec_11(&a.as_pointer(), 0,) }).v } == 8)); - assert!(({ (*a.borrow()).v } == 7)); - assert!( - (({ SImpl::operator_inc_8(&({ SImpl::operator_inc_8(&a.as_pointer(),) }),) }) - .with(|__s| (__s).v) - == 9) - ); - assert!( - ({ - ({ - let _o: Value = Rc::new(RefCell::new(S { v: 4 })); - SImpl::operator_add_1( - &Rc::new(RefCell::new(S { v: 3 })).as_pointer(), - _o.as_pointer(), - ) - }) - .v - } == 7) - ); - return 0; -} -pub trait SImpl { - fn operator_add_1(&self, o: Ptr) -> S; - fn operator_sub_2(&self, o: Ptr) -> S; - fn operator_mul(&self, o: Ptr) -> S; - fn operator_div(&self, o: Ptr) -> S; - fn operator_rem(&self, o: Ptr) -> S; - fn operator_pos_6(&self) -> S; - fn operator_neg_7(&self) -> S; - fn operator_inc_8(&self) -> Ptr; - fn operator_post_inc_9(&self, _a0: i32) -> S; - fn operator_dec_10(&self) -> Ptr; - fn operator_post_dec_11(&self, _a0: i32) -> S; -} -impl SImpl for Ptr { - fn operator_add_1(&self, o: Ptr) -> S { +impl S { + pub fn operator_add_1(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } + { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } + { o.with(|__s| __s.v) }), }; } - fn operator_sub_2(&self, o: Ptr) -> S { + pub fn operator_sub_2(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } - { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } - { o.with(|__s| __s.v) }), }; } - fn operator_mul(&self, o: Ptr) -> S { + pub fn operator_mul(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } * { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } * { o.with(|__s| __s.v) }), }; } - fn operator_div(&self, o: Ptr) -> S { + pub fn operator_div(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } / { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } / { o.with(|__s| __s.v) }), }; } - fn operator_rem(&self, o: Ptr) -> S { + pub fn operator_rem(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } % { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } % { o.with(|__s| __s.v) }), }; } - fn operator_pos_6(&self) -> S { + pub fn operator_pos_6(this: Ptr) -> S { return S { - v: (*self).with(|__s| __s.v), + v: this.with(|__s| __s.v), }; } - fn operator_neg_7(&self) -> S { + pub fn operator_neg_7(this: Ptr) -> S { return S { - v: -(*self).with(|__s| __s.v), + v: -this.with(|__s| __s.v), }; } - fn operator_inc_8(&self) -> Ptr { - field!((*self), v).with_mut(|__v| { + pub fn operator_inc_8(this: Ptr) -> Ptr { + field!(this, v).with_mut(|__v| { __v.prefix_inc(); }); - return (*self).clone(); + return (this).clone(); } - fn operator_post_inc_9(&self, mut _a0: i32) -> S { - let mut old: S = (*(*self).upgrade().deref()); - field!((*self), v).with_mut(|__v| { + pub fn operator_post_inc_9(this: Ptr, mut _a0: i32) -> S { + let mut old: S = (*this.upgrade().deref()); + field!(this, v).with_mut(|__v| { __v.prefix_inc(); }); return old; } - fn operator_dec_10(&self) -> Ptr { - field!((*self), v).with_mut(|__v| { + pub fn operator_dec_10(this: Ptr) -> Ptr { + field!(this, v).with_mut(|__v| { __v.prefix_dec(); }); - return (*self).clone(); + return (this).clone(); } - fn operator_post_dec_11(&self, mut _a0: i32) -> S { - let mut old: S = (*(*self).upgrade().deref()); - field!((*self), v).with_mut(|__v| { + pub fn operator_post_dec_11(this: Ptr, mut _a0: i32) -> S { + let mut old: S = (*this.upgrade().deref()); + field!(this, v).with_mut(|__v| { __v.prefix_dec(); }); return old; } } +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + let a: Value = Rc::new(RefCell::new(S { v: 7 })); + let b: Value = Rc::new(RefCell::new(S { v: 2 })); + assert!(({ ({ S::operator_add_1(a.as_pointer(), b.as_pointer(),) }).v } == 9)); + assert!(({ ({ S::operator_sub_2(a.as_pointer(), b.as_pointer(),) }).v } == 5)); + assert!(({ ({ S::operator_mul(a.as_pointer(), b.as_pointer(),) }).v } == 14)); + assert!(({ ({ S::operator_div(a.as_pointer(), b.as_pointer(),) }).v } == 3)); + assert!(({ ({ S::operator_rem(a.as_pointer(), b.as_pointer(),) }).v } == 1)); + assert!(({ ({ S::operator_pos_6(a.as_pointer(),) }).v } == 7)); + assert!(({ ({ S::operator_neg_7(a.as_pointer(),) }).v } == -7_i32)); + assert!((({ S::operator_inc_8(a.as_pointer(),) }).with(|__s| (__s).v) == 8)); + assert!(({ ({ S::operator_post_inc_9(a.as_pointer(), 0,) }).v } == 8)); + assert!(({ (*a.borrow()).v } == 9)); + assert!((({ S::operator_dec_10(a.as_pointer(),) }).with(|__s| (__s).v) == 8)); + assert!(({ ({ S::operator_post_dec_11(a.as_pointer(), 0,) }).v } == 8)); + assert!(({ (*a.borrow()).v } == 7)); + assert!( + (({ S::operator_inc_8(({ S::operator_inc_8(a.as_pointer(),) }),) }).with(|__s| (__s).v) + == 9) + ); + assert!( + ({ + ({ + let _o: Value = Rc::new(RefCell::new(S { v: 4 })); + S::operator_add_1( + Rc::new(RefCell::new(S { v: 3 })).as_pointer(), + _o.as_pointer(), + ) + }) + .v + } == 7) + ); + return 0; +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_bitwise_member.rs b/tests/unit/out/refcount/operator_bitwise_member.rs index aedd780f74..0599c2fb9c 100644 --- a/tests/unit/out/refcount/operator_bitwise_member.rs +++ b/tests/unit/out/refcount/operator_bitwise_member.rs @@ -23,59 +23,51 @@ pub struct S { #[offset(0)] pub v: u32, } -pub fn main() { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0()); -} -fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(S { v: 12_u32 })); - let b: Value = Rc::new(RefCell::new(S { v: 10_u32 })); - assert!(({ ({ SImpl::operator_bitnot(&a.as_pointer(),) }).v } == !12_u32)); - assert!(({ ({ SImpl::operator_bitand(&a.as_pointer(), b.as_pointer(),) }).v } == 8_u32)); - assert!(({ ({ SImpl::operator_bitor(&a.as_pointer(), b.as_pointer(),) }).v } == 14_u32)); - assert!(({ ({ SImpl::operator_bitxor(&a.as_pointer(), b.as_pointer(),) }).v } == 6_u32)); - assert!(({ ({ SImpl::operator_shl(&a.as_pointer(), 2,) }).v } == 48_u32)); - assert!(({ ({ SImpl::operator_shr(&a.as_pointer(), 2,) }).v } == 3_u32)); - return 0; -} -pub trait SImpl { - fn operator_bitnot(&self) -> S; - fn operator_bitand(&self, o: Ptr) -> S; - fn operator_bitor(&self, o: Ptr) -> S; - fn operator_bitxor(&self, o: Ptr) -> S; - fn operator_shl(&self, n: i32) -> S; - fn operator_shr(&self, n: i32) -> S; -} -impl SImpl for Ptr { - fn operator_bitnot(&self) -> S { +impl S { + pub fn operator_bitnot(this: Ptr) -> S { return S { - v: !(*self).with(|__s| __s.v), + v: !this.with(|__s| __s.v), }; } - fn operator_bitand(&self, o: Ptr) -> S { + pub fn operator_bitand(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } & { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } & { o.with(|__s| __s.v) }), }; } - fn operator_bitor(&self, o: Ptr) -> S { + pub fn operator_bitor(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } | { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } | { o.with(|__s| __s.v) }), }; } - fn operator_bitxor(&self, o: Ptr) -> S { + pub fn operator_bitxor(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } ^ { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } ^ { o.with(|__s| __s.v) }), }; } - fn operator_shl(&self, mut n: i32) -> S { + pub fn operator_shl(this: Ptr, mut n: i32) -> S { return S { - v: ((*self).with(|__s| __s.v) << n), + v: (this.with(|__s| __s.v) << n), }; } - fn operator_shr(&self, mut n: i32) -> S { + pub fn operator_shr(this: Ptr, mut n: i32) -> S { return S { - v: ((*self).with(|__s| __s.v) >> n), + v: (this.with(|__s| __s.v) >> n), }; } } +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + let a: Value = Rc::new(RefCell::new(S { v: 12_u32 })); + let b: Value = Rc::new(RefCell::new(S { v: 10_u32 })); + assert!(({ ({ S::operator_bitnot(a.as_pointer(),) }).v } == !12_u32)); + assert!(({ ({ S::operator_bitand(a.as_pointer(), b.as_pointer(),) }).v } == 8_u32)); + assert!(({ ({ S::operator_bitor(a.as_pointer(), b.as_pointer(),) }).v } == 14_u32)); + assert!(({ ({ S::operator_bitxor(a.as_pointer(), b.as_pointer(),) }).v } == 6_u32)); + assert!(({ ({ S::operator_shl(a.as_pointer(), 2,) }).v } == 48_u32)); + assert!(({ ({ S::operator_shr(a.as_pointer(), 2,) }).v } == 3_u32)); + return 0; +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index 1e95674b36..35144fd896 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -25,9 +25,15 @@ pub struct Eq { #[offset(4)] pub b: i32, } +impl Eq { + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) + && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); + } +} impl CppEq for Eq { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - EqImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Eq::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -49,14 +55,41 @@ pub struct Cmp { #[offset(4)] pub b: i32, } +impl Cmp { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.a)), + &(_a0.with(|__s| __s.a)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.b)), + &(_a0.with(|__s| __s.b)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) + && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); + } +} impl CppLess for Cmp { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - CmpImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for Cmp { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - CmpImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal } } #[derive( @@ -76,14 +109,31 @@ pub struct Both { #[offset(0)] pub a: i32, } +impl Both { + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.a)), + &(_a0.with(|__s| __s.a)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } +} impl CppLess for Both { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - BothImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Both::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for Both { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - BothImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Both::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -103,14 +153,28 @@ pub struct OrdOnly { #[offset(0)] pub a: i32, } +impl OrdOnly { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.a)), + &(_a0.with(|__s| __s.a)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } +} impl CppLess for OrdOnly { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - OrdOnlyImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + OrdOnly::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for OrdOnly { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - OrdOnlyImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + OrdOnly::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal } } #[derive( @@ -130,14 +194,31 @@ pub struct Inner { #[offset(0)] pub x: i32, } +impl Inner { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.x)), + &(_a0.with(|__s| __s.x)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.x) } == { _a0.with(|__s| __s.x) }); + } +} impl CppLess for Inner { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - InnerImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Inner::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for Inner { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - InnerImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Inner::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal } } #[derive( @@ -160,14 +241,40 @@ pub struct Outer { #[offset(4)] pub y: i32, } +impl Outer { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new( + ({ Inner::operator_cmp(field_ptr!(this, i), field_ptr!(_a0, i)) }), + )); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.y)), + &(_a0.with(|__s| __s.y)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ Inner::operator_eq(field_ptr!(this, i), field_ptr!(_a0, i)) }) + && ({ this.with(|__s| __s.y) } == { _a0.with(|__s| __s.y) }); + } +} impl CppLess for Outer { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - OuterImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Outer::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for Outer { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - OuterImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Outer::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal } } #[derive( @@ -187,14 +294,42 @@ pub struct Secondary { #[offset(0)] pub a: i32, } +impl Secondary { + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } + pub fn operator_ne(this: Ptr, _a0: Ptr) -> bool { + return !({ Secondary::operator_eq((this).clone(), (_a0).clone()) }); + } + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.a)), + &(_a0.with(|__s| __s.a)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_lt(this: Ptr, _a0: Ptr) -> bool { + return ({ Secondary::operator_cmp((this).clone(), (_a0).clone()) }) + == std::cmp::Ordering::Less; + } + pub fn operator_ge(this: Ptr, _a0: Ptr) -> bool { + return ({ Secondary::operator_cmp((this).clone(), (_a0).clone()) }) + != std::cmp::Ordering::Less; + } +} impl CppLess for Secondary { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SecondaryImpl::operator_lt(__lhs, __rhs.clone()) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Secondary::operator_lt(__lhs.clone(), __rhs.clone()) } } impl CppEq for Secondary { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SecondaryImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Secondary::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -214,14 +349,31 @@ pub struct PtrMember { #[byte_size(8)] pub p: Ptr, } +impl PtrMember { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.p.clone())), + &(_a0.with(|__s| __s.p.clone())), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.p.clone()) } == { _a0.with(|__s| __s.p.clone()) }); + } +} impl CppLess for PtrMember { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - PtrMemberImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + PtrMember::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for PtrMember { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - PtrMemberImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + PtrMember::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal } } pub fn main() { @@ -232,39 +384,34 @@ fn main_0() -> i32 { let e1: Value = Rc::new(RefCell::new(Eq { a: 1, b: 2 })); let e2: Value = Rc::new(RefCell::new(Eq { a: 1, b: 2 })); let e3: Value = Rc::new(RefCell::new(Eq { a: 1, b: 3 })); - assert!(({ EqImpl::operator_eq(&e1.as_pointer(), e2.as_pointer(),) })); - assert!(!({ EqImpl::operator_eq(&e1.as_pointer(), e3.as_pointer(),) })); + assert!(({ Eq::operator_eq(e1.as_pointer(), e2.as_pointer(),) })); + assert!(!({ Eq::operator_eq(e1.as_pointer(), e3.as_pointer(),) })); let c1: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 2 })); let c2: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 3 })); let c3: Value = Rc::new(RefCell::new(Cmp { a: 2, b: 0 })); let c4: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 9 })); + assert!(({ Cmp::operator_cmp(c1.as_pointer(), c2.as_pointer(),) }) == std::cmp::Ordering::Less); assert!( - ({ CmpImpl::operator_cmp(&c1.as_pointer(), c2.as_pointer(),) }) == std::cmp::Ordering::Less + ({ Cmp::operator_cmp(c3.as_pointer(), c4.as_pointer(),) }) == std::cmp::Ordering::Greater ); + assert!(({ Cmp::operator_eq(c1.as_pointer(), c1.as_pointer(),) })); assert!( - ({ CmpImpl::operator_cmp(&c3.as_pointer(), c4.as_pointer(),) }) - == std::cmp::Ordering::Greater - ); - assert!(({ CmpImpl::operator_eq(&c1.as_pointer(), c1.as_pointer(),) })); - assert!( - ({ CmpImpl::operator_cmp(&c1.as_pointer(), c2.as_pointer(),) }) + ({ Cmp::operator_cmp(c1.as_pointer(), c2.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) ); let b1: Value = Rc::new(RefCell::new(Both { a: 1 })); let b2: Value = Rc::new(RefCell::new(Both { a: 2 })); assert!( - ({ BothImpl::operator_cmp(&b1.as_pointer(), b2.as_pointer(),) }) - == std::cmp::Ordering::Less + ({ Both::operator_cmp(b1.as_pointer(), b2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ BothImpl::operator_eq(&b2.as_pointer(), b2.as_pointer(),) })); + assert!(({ Both::operator_eq(b2.as_pointer(), b2.as_pointer(),) })); let o1: Value = Rc::new(RefCell::new(OrdOnly { a: 1 })); let o2: Value = Rc::new(RefCell::new(OrdOnly { a: 2 })); assert!( - ({ OrdOnlyImpl::operator_cmp(&o1.as_pointer(), o2.as_pointer(),) }) - == std::cmp::Ordering::Less + ({ OrdOnly::operator_cmp(o1.as_pointer(), o2.as_pointer(),) }) == std::cmp::Ordering::Less ); assert!( - ({ OrdOnlyImpl::operator_cmp(&o2.as_pointer(), o1.as_pointer(),) }) + ({ OrdOnly::operator_cmp(o2.as_pointer(), o1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) ); let x1: Value = Rc::new(RefCell::new(Outer { @@ -280,20 +427,19 @@ fn main_0() -> i32 { y: 9, })); assert!( - ({ OuterImpl::operator_cmp(&x1.as_pointer(), x2.as_pointer(),) }) - == std::cmp::Ordering::Less + ({ Outer::operator_cmp(x1.as_pointer(), x2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ OuterImpl::operator_eq(&x1.as_pointer(), x3.as_pointer(),) })); + assert!(({ Outer::operator_eq(x1.as_pointer(), x3.as_pointer(),) })); assert!( - ({ OuterImpl::operator_cmp(&x2.as_pointer(), x1.as_pointer(),) }) + ({ Outer::operator_cmp(x2.as_pointer(), x1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) ); let s1: Value = Rc::new(RefCell::new(Secondary { a: 1 })); let s2: Value = Rc::new(RefCell::new(Secondary { a: 2 })); - assert!(({ SecondaryImpl::operator_ne(&s1.as_pointer(), s2.as_pointer(),) })); - assert!(({ SecondaryImpl::operator_lt(&s1.as_pointer(), s2.as_pointer(),) })); - assert!(({ SecondaryImpl::operator_ge(&s2.as_pointer(), s1.as_pointer(),) })); - assert!(!({ SecondaryImpl::operator_lt(&s2.as_pointer(), s1.as_pointer(),) })); + assert!(({ Secondary::operator_ne(s1.as_pointer(), s2.as_pointer(),) })); + assert!(({ Secondary::operator_lt(s1.as_pointer(), s2.as_pointer(),) })); + assert!(({ Secondary::operator_ge(s2.as_pointer(), s1.as_pointer(),) })); + assert!(!({ Secondary::operator_lt(s2.as_pointer(), s1.as_pointer(),) })); let arr: Value> = Rc::new(RefCell::new(Box::new([0, 0]))); let p1: Value = Rc::new(RefCell::new(PtrMember { p: arr.decay() })); let p2: Value = Rc::new(RefCell::new(PtrMember { @@ -301,199 +447,14 @@ fn main_0() -> i32 { })); let p3: Value = Rc::new(RefCell::new(PtrMember { p: arr.decay() })); assert!( - ({ PtrMemberImpl::operator_cmp(&p1.as_pointer(), p2.as_pointer(),) }) + ({ PtrMember::operator_cmp(p1.as_pointer(), p2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ PtrMemberImpl::operator_eq(&p1.as_pointer(), p3.as_pointer(),) })); + assert!(({ PtrMember::operator_eq(p1.as_pointer(), p3.as_pointer(),) })); assert!( - ({ PtrMemberImpl::operator_cmp(&p2.as_pointer(), p1.as_pointer(),) }) + ({ PtrMember::operator_cmp(p2.as_pointer(), p1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) ); return 0; } -pub trait BothImpl { - fn operator_eq(&self, _a0: Ptr) -> bool; - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; -} -impl BothImpl for Ptr { - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.a)), - &(_a0.with(|__s| __s.a)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } -} -pub trait CmpImpl { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, _a0: Ptr) -> bool; -} -impl CmpImpl for Ptr { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.a)), - &(_a0.with(|__s| __s.a)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.b)), - &(_a0.with(|__s| __s.b)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) - && ({ (*self).with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); - } -} -pub trait EqImpl { - fn operator_eq(&self, _a0: Ptr) -> bool; -} -impl EqImpl for Ptr { - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) - && ({ (*self).with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); - } -} -pub trait InnerImpl { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, _a0: Ptr) -> bool; -} -impl InnerImpl for Ptr { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.x)), - &(_a0.with(|__s| __s.x)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.x) } == { _a0.with(|__s| __s.x) }); - } -} -pub trait OrdOnlyImpl { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; -} -impl OrdOnlyImpl for Ptr { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.a)), - &(_a0.with(|__s| __s.a)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } -} -pub trait OuterImpl { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, _a0: Ptr) -> bool; -} -impl OuterImpl for Ptr { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new( - ({ InnerImpl::operator_cmp(&field_ptr!((*self), i), field_ptr!(_a0, i)) }), - )); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.y)), - &(_a0.with(|__s| __s.y)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ InnerImpl::operator_eq(&field_ptr!((*self), i), field_ptr!(_a0, i)) }) - && ({ (*self).with(|__s| __s.y) } == { _a0.with(|__s| __s.y) }); - } -} -pub trait PtrMemberImpl { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, _a0: Ptr) -> bool; -} -impl PtrMemberImpl for Ptr { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.p.clone())), - &(_a0.with(|__s| __s.p.clone())), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.p.clone()) } == { _a0.with(|__s| __s.p.clone()) }); - } -} -pub trait SecondaryImpl { - fn operator_eq(&self, _a0: Ptr) -> bool; - fn operator_ne(&self, _a0: Ptr) -> bool; - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; - fn operator_lt(&self, _a0: Ptr) -> bool; - fn operator_ge(&self, _a0: Ptr) -> bool; -} -impl SecondaryImpl for Ptr { - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } - fn operator_ne(&self, _a0: Ptr) -> bool { - return !({ SecondaryImpl::operator_eq(&(*self), (_a0).clone()) }); - } - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.a)), - &(_a0.with(|__s| __s.a)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_lt(&self, _a0: Ptr) -> bool { - return ({ SecondaryImpl::operator_cmp(&(*self), (_a0).clone()) }) - == std::cmp::Ordering::Less; - } - fn operator_ge(&self, _a0: Ptr) -> bool { - return ({ SecondaryImpl::operator_cmp(&(*self), (_a0).clone()) }) - != std::cmp::Ordering::Less; - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index 1884dc7183..a3cce0c780 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -24,12 +24,12 @@ pub struct S { pub v: i32, } impl CppLess for S { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_0(__lhs.clone(), __rhs.clone()) } } impl CppEq for S { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_1(__lhs.clone(), __rhs.clone()) } } @@ -75,12 +75,12 @@ pub struct V { pub v: i32, } impl CppLess for V { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_8(__lhs.read(), __rhs.read()) } } impl CppEq for V { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_9(__lhs.read(), __rhs.read()) } } diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index ee3014ac10..a0088dd538 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -23,14 +23,37 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_eq(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } + pub fn operator_ne(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } != { o.with(|__s| __s.v) }); + } + pub fn operator_lt_3(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }); + } + pub fn operator_gt(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } > { o.with(|__s| __s.v) }); + } + pub fn operator_le(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } <= { o.with(|__s| __s.v) }); + } + pub fn operator_ge(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } >= { o.with(|__s| __s.v) }); + } + pub fn operator_lt_7(this: Ptr, mut o: i32) -> bool { + return (this.with(|__s| __s.v) < o); + } +} impl CppLess for S { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SImpl::operator_lt_3(__lhs, __rhs.clone()) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + S::operator_lt_3(__lhs.clone(), __rhs.clone()) } } impl CppEq for S { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + S::operator_eq(__lhs.clone(), __rhs.clone()) } } pub fn main() { @@ -41,46 +64,14 @@ fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); let c: Value = Rc::new(RefCell::new(S { v: 1 })); - assert!(({ SImpl::operator_eq(&a.as_pointer(), c.as_pointer(),) })); - assert!(({ SImpl::operator_ne(&a.as_pointer(), b.as_pointer(),) })); - assert!(({ SImpl::operator_lt_3(&a.as_pointer(), b.as_pointer(),) })); - assert!(({ SImpl::operator_gt(&b.as_pointer(), a.as_pointer(),) })); - assert!(({ SImpl::operator_le(&a.as_pointer(), c.as_pointer(),) })); - assert!(({ SImpl::operator_ge(&a.as_pointer(), c.as_pointer(),) })); - assert!(!({ SImpl::operator_lt_3(&b.as_pointer(), a.as_pointer(),) })); - assert!(({ SImpl::operator_lt_7(&a.as_pointer(), 5,) })); + assert!(({ S::operator_eq(a.as_pointer(), c.as_pointer(),) })); + assert!(({ S::operator_ne(a.as_pointer(), b.as_pointer(),) })); + assert!(({ S::operator_lt_3(a.as_pointer(), b.as_pointer(),) })); + assert!(({ S::operator_gt(b.as_pointer(), a.as_pointer(),) })); + assert!(({ S::operator_le(a.as_pointer(), c.as_pointer(),) })); + assert!(({ S::operator_ge(a.as_pointer(), c.as_pointer(),) })); + assert!(!({ S::operator_lt_3(b.as_pointer(), a.as_pointer(),) })); + assert!(({ S::operator_lt_7(a.as_pointer(), 5,) })); return 0; } -pub trait SImpl { - fn operator_eq(&self, o: Ptr) -> bool; - fn operator_ne(&self, o: Ptr) -> bool; - fn operator_lt_3(&self, o: Ptr) -> bool; - fn operator_gt(&self, o: Ptr) -> bool; - fn operator_le(&self, o: Ptr) -> bool; - fn operator_ge(&self, o: Ptr) -> bool; - fn operator_lt_7(&self, o: i32) -> bool; -} -impl SImpl for Ptr { - fn operator_eq(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } - fn operator_ne(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } != { o.with(|__s| __s.v) }); - } - fn operator_lt_3(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } < { o.with(|__s| __s.v) }); - } - fn operator_gt(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } > { o.with(|__s| __s.v) }); - } - fn operator_le(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } <= { o.with(|__s| __s.v) }); - } - fn operator_ge(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } >= { o.with(|__s| __s.v) }); - } - fn operator_lt_7(&self, mut o: i32) -> bool { - return ((*self).with(|__s| __s.v) < o); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_mixed.rs b/tests/unit/out/refcount/operator_comparison_mixed.rs index d1cd37776b..999d5b316a 100644 --- a/tests/unit/out/refcount/operator_comparison_mixed.rs +++ b/tests/unit/out/refcount/operator_comparison_mixed.rs @@ -23,6 +23,26 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_eq(this: Ptr, mut o: i32) -> bool { + return (this.with(|__s| __s.v) == o); + } + pub fn operator_ne(this: Ptr, mut o: i32) -> bool { + return (this.with(|__s| __s.v) != o); + } + pub fn operator_lt(this: Ptr, mut o: i32) -> bool { + return (this.with(|__s| __s.v) < o); + } + pub fn operator_gt(this: Ptr, mut o: f64) -> bool { + return ((this.with(|__s| __s.v) as f64) > o); + } + pub fn operator_le(this: Ptr, mut o: i64) -> bool { + return ((this.with(|__s| __s.v) as i64) <= o); + } + pub fn operator_ge(this: Ptr, mut o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } >= { (((o.read()) as i32) - (('0' as i8) as i32)) }); + } +} pub fn operator_eq_0(mut a: i32, b: Ptr) -> bool { return ({ a } == { b.with(|__s| __s.v) }); } @@ -51,12 +71,12 @@ pub fn main() { fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 5 })); let cs: Ptr = s.as_pointer(); - assert!(({ SImpl::operator_eq(&cs, 5,) })); - assert!(({ SImpl::operator_ne(&cs, 4,) })); - assert!(({ SImpl::operator_lt(&cs, 6,) })); - assert!(({ SImpl::operator_gt(&cs, 4.5_f64,) })); - assert!(({ SImpl::operator_le(&cs, 5_i64,) })); - assert!(({ SImpl::operator_ge(&cs, Ptr::::from_string_literal(b"3"),) })); + assert!(({ S::operator_eq((cs).clone(), 5,) })); + assert!(({ S::operator_ne((cs).clone(), 4,) })); + assert!(({ S::operator_lt((cs).clone(), 6,) })); + assert!(({ S::operator_gt((cs).clone(), 4.5_f64,) })); + assert!(({ S::operator_le((cs).clone(), 5_i64,) })); + assert!(({ S::operator_ge((cs).clone(), Ptr::::from_string_literal(b"3"),) })); assert!(({ operator_eq_0(5, s.as_pointer(),) })); assert!(({ operator_ne_1(4, s.as_pointer(),) })); assert!(({ operator_lt_2(4, s.as_pointer(),) })); @@ -67,32 +87,4 @@ fn main_0() -> i32 { assert!(!({ operator_lt_6(s.as_pointer(), 6,) })); return 0; } -pub trait SImpl { - fn operator_eq(&self, o: i32) -> bool; - fn operator_ne(&self, o: i32) -> bool; - fn operator_lt(&self, o: i32) -> bool; - fn operator_gt(&self, o: f64) -> bool; - fn operator_le(&self, o: i64) -> bool; - fn operator_ge(&self, o: Ptr) -> bool; -} -impl SImpl for Ptr { - fn operator_eq(&self, mut o: i32) -> bool { - return ((*self).with(|__s| __s.v) == o); - } - fn operator_ne(&self, mut o: i32) -> bool { - return ((*self).with(|__s| __s.v) != o); - } - fn operator_lt(&self, mut o: i32) -> bool { - return ((*self).with(|__s| __s.v) < o); - } - fn operator_gt(&self, mut o: f64) -> bool { - return (((*self).with(|__s| __s.v) as f64) > o); - } - fn operator_le(&self, mut o: i64) -> bool { - return (((*self).with(|__s| __s.v) as i64) <= o); - } - fn operator_ge(&self, mut o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } >= { (((o.read()) as i32) - (('0' as i8) as i32)) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 95c9dae3de..1229dd8525 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -24,12 +24,12 @@ pub struct X { pub v: i32, } impl CppLess for X { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { ((operator_lt_0(__lhs.read(), __rhs.read())) != 0) } } impl CppEq for X { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { ((operator_eq_1(__lhs.read(), __rhs.read())) != 0) } } @@ -85,6 +85,13 @@ pub struct Custom { #[offset(0)] pub v: i32, } +impl Custom { + pub fn operator_cmp(this: Ptr, o: Ptr) -> Result { + return Result { + r: ({ this.with(|__s| __s.v) } - { o.with(|__s| __s.v) }), + }; + } +} #[derive( Copy, Clone, @@ -102,14 +109,35 @@ pub struct Mixed { #[offset(0)] pub v: i32, } +impl Mixed { + pub fn operator_cmp(this: Ptr, o: Ptr) -> Result { + return Result { + r: ({ this.with(|__s| __s.v) } - { o.with(|__s| __s.v) }), + }; + } + pub fn operator_lt(this: Ptr, o: Ptr) -> i32 { + return if ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }) { + 8 + } else { + 0 + }; + } + pub fn operator_eq(this: Ptr, o: Ptr) -> i32 { + return if ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }) { + 9 + } else { + 0 + }; + } +} impl CppLess for Mixed { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - ((MixedImpl::operator_lt(__lhs, __rhs.clone())) != 0) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + ((Mixed::operator_lt(__lhs.clone(), __rhs.clone())) != 0) } } impl CppEq for Mixed { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - ((MixedImpl::operator_eq(__lhs, __rhs.clone())) != 0) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + ((Mixed::operator_eq(__lhs.clone(), __rhs.clone())) != 0) } } #[derive( @@ -131,6 +159,14 @@ pub struct MyBool { #[offset(0)] pub value: bool, } +impl MyBool { + pub fn construct(this: Ptr, mut v: bool) { + field!(this, value).write(v); + } + pub fn to_bool(this: Ptr) -> bool { + return this.with(|__s| __s.value); + } +} #[derive( Copy, Clone, @@ -149,32 +185,32 @@ pub struct Boolish { pub v: i32, } impl CppLess for Boolish { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { { let __cmp = operator_lt_6(__lhs.read(), __rhs.read()); - MyBoolImpl::to_bool(&Rc::new(RefCell::new(__cmp)).as_pointer()) + MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) } } } impl CppEq for Boolish { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { { let __cmp = operator_eq_7(__lhs.read(), __rhs.read()); - MyBoolImpl::to_bool(&Rc::new(RefCell::new(__cmp)).as_pointer()) + MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) } } } pub fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MyBoolImpl::construct(&__v.as_pointer(), (a.v == b.v)); + MyBool::construct(__v.as_pointer(), (a.v == b.v)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MyBoolImpl::construct(&__v.as_pointer(), (a.v < b.v)); + MyBool::construct(__v.as_pointer(), (a.v < b.v)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -196,10 +232,18 @@ pub struct RefBool { #[offset(0)] pub value: bool, } +impl RefBool { + pub fn construct(this: Ptr, mut v: bool) { + field!(this, value).write(v); + } + pub fn to_bool(this: Ptr) -> bool { + return this.with(|__s| __s.value); + } +} thread_local!( pub static ref_true_8: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefBoolImpl::construct(&__v.as_pointer(), true); + RefBool::construct(__v.as_pointer(), true); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -220,11 +264,16 @@ pub struct RefInt { #[offset(0)] pub v: i32, } +impl RefInt { + pub fn operator_eq(this: Ptr, _a0: Ptr) -> Ptr { + return ref_true_8.with(|v| v.as_pointer()); + } +} impl CppEq for RefInt { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { { - let __cmp = RefIntImpl::operator_eq(__lhs, __rhs.clone()); - RefBoolImpl::to_bool(&__cmp) + let __cmp = RefInt::operator_eq(__lhs.clone(), __rhs.clone()); + RefBool::to_bool(__cmp.clone()) } } } @@ -257,12 +306,12 @@ fn main_0() -> i32 { ); let p: Value = Rc::new(RefCell::new(Custom { v: 5 })); let q: Value = Rc::new(RefCell::new(Custom { v: 2 })); - let mut r: Result = ({ CustomImpl::operator_cmp(&p.as_pointer(), q.as_pointer()) }); + let mut r: Result = ({ Custom::operator_cmp(p.as_pointer(), q.as_pointer()) }); assert!((r.r == 3)); let m: Value = Rc::new(RefCell::new(Mixed { v: 4 })); let n: Value = Rc::new(RefCell::new(Mixed { v: 4 })); - assert!((({ MixedImpl::operator_eq(&m.as_pointer(), n.as_pointer(),) }) == 9)); - assert!(({ ({ MixedImpl::operator_cmp(&m.as_pointer(), n.as_pointer(),) }).r } == 0)); + assert!((({ Mixed::operator_eq(m.as_pointer(), n.as_pointer(),) }) == 9)); + assert!(({ ({ Mixed::operator_cmp(m.as_pointer(), n.as_pointer(),) }).r } == 0)); let ms: Value> = Rc::new(RefCell::new(Box::new([ Mixed { v: 6 }, Mixed { v: 4 }, @@ -279,20 +328,18 @@ fn main_0() -> i32 { (({ (*ms.borrow())[(0) as usize].v } == 4) && ({ (*ms.borrow())[(1) as usize].v } == 5)) && ({ (*ms.borrow())[(2) as usize].v } == 6) ); - assert!((({ MixedImpl::operator_lt(&ms.decay().offset(0), ms.decay().offset(1),) }) == 8)); + assert!((({ Mixed::operator_lt(ms.decay().offset(0), ms.decay().offset(1),) }) == 8)); let mut b1: Boolish = Boolish { v: 1 }; let mut b2: Boolish = Boolish { v: 2 }; assert!( ({ - MyBoolImpl::to_bool( - &Rc::new(RefCell::new(({ operator_eq_7(b1, Boolish { v: 1 }) }))).as_pointer(), + MyBool::to_bool( + Rc::new(RefCell::new(({ operator_eq_7(b1, Boolish { v: 1 }) }))).as_pointer(), ) }) ); assert!( - !({ - MyBoolImpl::to_bool(&Rc::new(RefCell::new(({ operator_lt_6(b2, b1) }))).as_pointer()) - }) + !({ MyBool::to_bool(Rc::new(RefCell::new(({ operator_lt_6(b2, b1,) }))).as_pointer(),) }) ); let mut lt: MyBool = ({ operator_lt_6(b1, b2) }); assert!(lt.value); @@ -315,11 +362,7 @@ fn main_0() -> i32 { let ri1: Value = Rc::new(RefCell::new(RefInt { v: 1 })); let ri2: Value = Rc::new(RefCell::new(RefInt { v: 2 })); assert!( - ({ - RefBoolImpl::to_bool( - &({ RefIntImpl::operator_eq(&ri1.as_pointer(), ri2.as_pointer()) }), - ) - }) + ({ RefBool::to_bool(({ RefInt::operator_eq(ri1.as_pointer(), ri2.as_pointer(),) }),) }) ); let ris: Value> = Rc::new(RefCell::new(Box::new([RefInt { v: 1 }, RefInt { v: 2 }]))); @@ -327,7 +370,7 @@ fn main_0() -> i32 { ({ let mut __tmp_3 = { ris.decay().offset((2) as isize) }; let mut __it = ris.decay(); - while __it != __tmp_3 && !CppEq::equal(&__it.iter_deref(), &ri2.as_pointer()) { + while __it != __tmp_3 && !CppEq::equal(__it.iter_deref(), ri2.as_pointer().clone()) { __it.iter_inc(); } __it @@ -335,74 +378,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait CustomImpl { - fn operator_cmp(&self, o: Ptr) -> Result; -} -impl CustomImpl for Ptr { - fn operator_cmp(&self, o: Ptr) -> Result { - return Result { - r: ({ (*self).with(|__s| __s.v) } - { o.with(|__s| __s.v) }), - }; - } -} -pub trait MixedImpl { - fn operator_cmp(&self, o: Ptr) -> Result; - fn operator_lt(&self, o: Ptr) -> i32; - fn operator_eq(&self, o: Ptr) -> i32; -} -impl MixedImpl for Ptr { - fn operator_cmp(&self, o: Ptr) -> Result { - return Result { - r: ({ (*self).with(|__s| __s.v) } - { o.with(|__s| __s.v) }), - }; - } - fn operator_lt(&self, o: Ptr) -> i32 { - return if ({ (*self).with(|__s| __s.v) } < { o.with(|__s| __s.v) }) { - 8 - } else { - 0 - }; - } - fn operator_eq(&self, o: Ptr) -> i32 { - return if ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }) { - 9 - } else { - 0 - }; - } -} -pub trait MyBoolImpl { - fn construct(&self, v: bool); - fn to_bool(&self) -> bool; -} -impl MyBoolImpl for Ptr { - fn construct(&self, mut v: bool) { - field!((*self), value).write(v); - } - fn to_bool(&self) -> bool { - return (*self).with(|__s| __s.value); - } -} -pub trait RefBoolImpl { - fn construct(&self, v: bool); - fn to_bool(&self) -> bool; -} -impl RefBoolImpl for Ptr { - fn construct(&self, mut v: bool) { - field!((*self), value).write(v); - } - fn to_bool(&self) -> bool { - return (*self).with(|__s| __s.value); - } -} -pub trait RefIntImpl { - fn operator_eq(&self, _a0: Ptr) -> Ptr; -} -impl RefIntImpl for Ptr { - fn operator_eq(&self, _a0: Ptr) -> Ptr { - return ref_true_8.with(|v| v.as_pointer()); - } -} pub fn __cpp2rust_init_globals() { let _ = ref_true_8.with(|_| ()); } diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index 5592587956..7edce8d200 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -29,13 +29,18 @@ pub struct S { #[offset(0)] data_: i32, } +impl S { + pub fn construct(this: Ptr, mut data: i32) { + field!(this, data_).write(data); + } +} impl CppLess for S { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_1(__lhs.clone(), __rhs.clone()) } } impl CppEq for S { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_0(__lhs.clone(), __rhs.clone()) } } @@ -52,12 +57,4 @@ fn main_0() -> i32 { assert!(!({ operator_lt_1(b.as_pointer(), a.as_pointer(),) })); return 0; } -pub trait SImpl { - fn construct(&self, data: i32); -} -impl SImpl for Ptr { - fn construct(&self, mut data: i32) { - field!((*self), data_).write(data); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_compound_assignment_member.rs b/tests/unit/out/refcount/operator_compound_assignment_member.rs index faf75dcb59..74ff0168e0 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_member.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_member.rs @@ -23,6 +23,65 @@ pub struct S { #[offset(0)] pub v: u32, } +impl S { + pub fn operator_assign_1(this: Ptr, mut n: u32) -> Ptr { + field!(this, v).write(n); + return (this).clone(); + } + pub fn operator_add_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write({ (this.with(|__s| __s.v)).wrapping_add(o.with(|__s| __s.v)) }); + return (this).clone(); + } + pub fn operator_sub_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write({ (this.with(|__s| __s.v)).wrapping_sub(o.with(|__s| __s.v)) }); + return (this).clone(); + } + pub fn operator_mul_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write({ (this.with(|__s| __s.v)).wrapping_mul(o.with(|__s| __s.v)) }); + return (this).clone(); + } + pub fn operator_div_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write({ (this.with(|__s| __s.v)).wrapping_div(o.with(|__s| __s.v)) }); + return (this).clone(); + } + pub fn operator_rem_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write({ (this.with(|__s| __s.v)).wrapping_rem(o.with(|__s| __s.v)) }); + return (this).clone(); + } + pub fn operator_bitand_assign(this: Ptr, o: Ptr) -> Ptr { + { + let __rhs = o.with(|__s| __s.v); + field!(this, v).with_mut(|__v| *__v = *__v & __rhs) + }; + return (this).clone(); + } + pub fn operator_bitor_assign(this: Ptr, o: Ptr) -> Ptr { + { + let __rhs = o.with(|__s| __s.v); + field!(this, v).with_mut(|__v| *__v = *__v | __rhs) + }; + return (this).clone(); + } + pub fn operator_bitxor_assign(this: Ptr, o: Ptr) -> Ptr { + { + let __rhs = o.with(|__s| __s.v); + field!(this, v).with_mut(|__v| *__v = *__v ^ __rhs) + }; + return (this).clone(); + } + pub fn operator_shl_assign(this: Ptr, mut n: i32) -> Ptr { + { + field!(this, v).with_mut(|__v| *__v = *__v << n) + }; + return (this).clone(); + } + pub fn operator_shr_assign(this: Ptr, mut n: i32) -> Ptr { + { + field!(this, v).with_mut(|__v| *__v = *__v >> n) + }; + return (this).clone(); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -30,111 +89,39 @@ pub fn main() { fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(S { v: 6_u32 })); let b: Value = Rc::new(RefCell::new(S { v: 4_u32 })); - SImpl::operator_add_assign(&a.as_pointer(), b.as_pointer()); + S::operator_add_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 10_u32)); - SImpl::operator_sub_assign(&a.as_pointer(), b.as_pointer()); + S::operator_sub_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 6_u32)); - SImpl::operator_mul_assign(&a.as_pointer(), b.as_pointer()); + S::operator_mul_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 24_u32)); - SImpl::operator_div_assign(&a.as_pointer(), b.as_pointer()); + S::operator_div_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 6_u32)); - SImpl::operator_rem_assign(&a.as_pointer(), b.as_pointer()); + S::operator_rem_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 2_u32)); - SImpl::operator_bitor_assign(&a.as_pointer(), b.as_pointer()); + S::operator_bitor_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 6_u32)); - SImpl::operator_bitand_assign(&a.as_pointer(), b.as_pointer()); + S::operator_bitand_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 4_u32)); - SImpl::operator_bitxor_assign(&a.as_pointer(), b.as_pointer()); + S::operator_bitxor_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 0_u32)); - SImpl::operator_assign_1(&a.as_pointer(), 3_u32); + S::operator_assign_1(a.as_pointer(), 3_u32); assert!(({ (*a.borrow()).v } == 3_u32)); - SImpl::operator_shl_assign(&a.as_pointer(), 2); + S::operator_shl_assign(a.as_pointer(), 2); assert!(({ (*a.borrow()).v } == 12_u32)); - SImpl::operator_shr_assign(&a.as_pointer(), 1); + S::operator_shr_assign(a.as_pointer(), 1); assert!(({ (*a.borrow()).v } == 6_u32)); - SImpl::operator_add_assign( - &({ SImpl::operator_add_assign(&a.as_pointer(), b.as_pointer()) }), + S::operator_add_assign( + ({ S::operator_add_assign(a.as_pointer(), b.as_pointer()) }), b.as_pointer(), ); assert!(({ (*a.borrow()).v } == 14_u32)); let mut c: S = S { v: 0_u32 }; - c = (*({ SImpl::operator_assign_1(&a.as_pointer(), 1_u32) }) + c = (*({ S::operator_assign_1(a.as_pointer(), 1_u32) }) .upgrade() .deref()); assert!(({ (*a.borrow()).v } == 1_u32)); assert!((c.v == 1_u32)); return 0; } -pub trait SImpl { - fn operator_assign_1(&self, n: u32) -> Ptr; - fn operator_add_assign(&self, o: Ptr) -> Ptr; - fn operator_sub_assign(&self, o: Ptr) -> Ptr; - fn operator_mul_assign(&self, o: Ptr) -> Ptr; - fn operator_div_assign(&self, o: Ptr) -> Ptr; - fn operator_rem_assign(&self, o: Ptr) -> Ptr; - fn operator_bitand_assign(&self, o: Ptr) -> Ptr; - fn operator_bitor_assign(&self, o: Ptr) -> Ptr; - fn operator_bitxor_assign(&self, o: Ptr) -> Ptr; - fn operator_shl_assign(&self, n: i32) -> Ptr; - fn operator_shr_assign(&self, n: i32) -> Ptr; -} -impl SImpl for Ptr { - fn operator_assign_1(&self, mut n: u32) -> Ptr { - field!((*self), v).write(n); - return (*self).clone(); - } - fn operator_add_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_add(o.with(|__s| __s.v)) }); - return (*self).clone(); - } - fn operator_sub_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_sub(o.with(|__s| __s.v)) }); - return (*self).clone(); - } - fn operator_mul_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_mul(o.with(|__s| __s.v)) }); - return (*self).clone(); - } - fn operator_div_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_div(o.with(|__s| __s.v)) }); - return (*self).clone(); - } - fn operator_rem_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_rem(o.with(|__s| __s.v)) }); - return (*self).clone(); - } - fn operator_bitand_assign(&self, o: Ptr) -> Ptr { - { - let __rhs = o.with(|__s| __s.v); - field!((*self), v).with_mut(|__v| *__v = *__v & __rhs) - }; - return (*self).clone(); - } - fn operator_bitor_assign(&self, o: Ptr) -> Ptr { - { - let __rhs = o.with(|__s| __s.v); - field!((*self), v).with_mut(|__v| *__v = *__v | __rhs) - }; - return (*self).clone(); - } - fn operator_bitxor_assign(&self, o: Ptr) -> Ptr { - { - let __rhs = o.with(|__s| __s.v); - field!((*self), v).with_mut(|__v| *__v = *__v ^ __rhs) - }; - return (*self).clone(); - } - fn operator_shl_assign(&self, mut n: i32) -> Ptr { - { - field!((*self), v).with_mut(|__v| *__v = *__v << n) - }; - return (*self).clone(); - } - fn operator_shr_assign(&self, mut n: i32) -> Ptr { - { - field!((*self), v).with_mut(|__v| *__v = *__v >> n) - }; - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index 7fe14b5f97..7355fb70d4 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -30,7 +30,7 @@ pub struct Defaulted { pub b: i32, } impl CppEq for Defaulted { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_0(__lhs.clone(), __rhs.clone()) } } @@ -67,12 +67,12 @@ pub struct DefaultedOrd { pub a: i32, } impl CppLess for DefaultedOrd { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_cmp_1(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for DefaultedOrd { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_2(__lhs.clone(), __rhs.clone()) } } @@ -105,12 +105,12 @@ pub struct Inline { pub a: i32, } impl CppLess for Inline { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_4(__lhs.clone(), __rhs.clone()) } } impl CppEq for Inline { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_3(__lhs.clone(), __rhs.clone()) } } @@ -132,7 +132,7 @@ pub struct OutOfLine { pub a: i32, } impl CppEq for OutOfLine { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_6(__lhs.clone(), __rhs.clone()) } } @@ -169,12 +169,12 @@ pub struct Tmpl_int_ { pub v: i32, } impl CppLess for Tmpl_int_ { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_9(__lhs.clone(), __rhs.clone()) } } impl CppEq for Tmpl_int_ { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_8(__lhs.clone(), __rhs.clone()) } } @@ -216,7 +216,7 @@ pub struct TmplDefaulted_int_ { pub v: i32, } impl CppEq for TmplDefaulted_int_ { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_11(__lhs.clone(), __rhs.clone()) } } diff --git a/tests/unit/out/refcount/operator_less_than.rs b/tests/unit/out/refcount/operator_less_than.rs index 3450be62fc..e62ec942fc 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -25,15 +25,22 @@ pub struct Pair { #[offset(4)] pub y: i32, } +impl Pair { + pub fn operator_lt(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.x) } < { other.with(|__s| __s.x) }) + || (({ this.with(|__s| __s.x) } == { other.with(|__s| __s.x) }) + && ({ this.with(|__s| __s.y) } < { other.with(|__s| __s.y) })); + } +} impl CppLess for Pair { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - PairImpl::operator_lt(__lhs, __rhs.clone()) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Pair::operator_lt(__lhs.clone(), __rhs.clone()) } } impl CppEq for Pair { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - !(PairImpl::operator_lt(__lhs, __rhs.clone())) - && !(PairImpl::operator_lt(__rhs, __lhs.clone())) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + !(Pair::operator_lt(__lhs.clone(), __rhs.clone())) + && !(Pair::operator_lt(__rhs.clone(), __lhs.clone())) } } pub fn main() { @@ -43,17 +50,7 @@ pub fn main() { fn main_0() -> i32 { let pair1: Value = Rc::new(RefCell::new(Pair { x: 1, y: 2 })); let pair2: Value = Rc::new(RefCell::new(Pair { x: 1, y: 3 })); - assert!(({ PairImpl::operator_lt(&pair1.as_pointer(), pair2.as_pointer(),) })); + assert!(({ Pair::operator_lt(pair1.as_pointer(), pair2.as_pointer(),) })); return 0; } -pub trait PairImpl { - fn operator_lt(&self, other: Ptr) -> bool; -} -impl PairImpl for Ptr { - fn operator_lt(&self, other: Ptr) -> bool { - return ({ (*self).with(|__s| __s.x) } < { other.with(|__s| __s.x) }) - || (({ (*self).with(|__s| __s.x) } == { other.with(|__s| __s.x) }) - && ({ (*self).with(|__s| __s.y) } < { other.with(|__s| __s.y) })); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_logical_member.rs b/tests/unit/out/refcount/operator_logical_member.rs index f633eada1d..f00dcd2c1a 100644 --- a/tests/unit/out/refcount/operator_logical_member.rs +++ b/tests/unit/out/refcount/operator_logical_member.rs @@ -23,6 +23,17 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_not(this: Ptr) -> bool { + return (this.with(|__s| __s.v) == 0); + } + pub fn operator_and(this: Ptr, o: Ptr) -> bool { + return (this.with(|__s| __s.v) != 0) && (o.with(|__s| __s.v) != 0); + } + pub fn operator_or(this: Ptr, o: Ptr) -> bool { + return (this.with(|__s| __s.v) != 0) || (o.with(|__s| __s.v) != 0); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -30,28 +41,12 @@ pub fn main() { fn main_0() -> i32 { let t: Value = Rc::new(RefCell::new(S { v: 1 })); let f: Value = Rc::new(RefCell::new(S { v: 0 })); - assert!(({ SImpl::operator_not(&f.as_pointer(),) })); - assert!(!({ SImpl::operator_not(&t.as_pointer(),) })); - assert!(({ SImpl::operator_and(&t.as_pointer(), t.as_pointer(),) })); - assert!(!({ SImpl::operator_and(&t.as_pointer(), f.as_pointer(),) })); - assert!(({ SImpl::operator_or(&t.as_pointer(), f.as_pointer(),) })); - assert!(!({ SImpl::operator_or(&f.as_pointer(), f.as_pointer(),) })); + assert!(({ S::operator_not(f.as_pointer(),) })); + assert!(!({ S::operator_not(t.as_pointer(),) })); + assert!(({ S::operator_and(t.as_pointer(), t.as_pointer(),) })); + assert!(!({ S::operator_and(t.as_pointer(), f.as_pointer(),) })); + assert!(({ S::operator_or(t.as_pointer(), f.as_pointer(),) })); + assert!(!({ S::operator_or(f.as_pointer(), f.as_pointer(),) })); return 0; } -pub trait SImpl { - fn operator_not(&self) -> bool; - fn operator_and(&self, o: Ptr) -> bool; - fn operator_or(&self, o: Ptr) -> bool; -} -impl SImpl for Ptr { - fn operator_not(&self) -> bool { - return ((*self).with(|__s| __s.v) == 0); - } - fn operator_and(&self, o: Ptr) -> bool { - return ((*self).with(|__s| __s.v) != 0) && (o.with(|__s| __s.v) != 0); - } - fn operator_or(&self, o: Ptr) -> bool { - return ((*self).with(|__s| __s.v) != 0) || (o.with(|__s| __s.v) != 0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_member_pointer_member.rs b/tests/unit/out/refcount/operator_member_pointer_member.rs index 19aad4c322..47534cf43d 100644 --- a/tests/unit/out/refcount/operator_member_pointer_member.rs +++ b/tests/unit/out/refcount/operator_member_pointer_member.rs @@ -65,6 +65,23 @@ pub struct S { #[byte_size(4)] pub inner: Inner, } +impl S { + pub fn operator_index_1(this: Ptr, mut i: i32) -> Ptr { + return array_field_ptr!(this, data).offset((i) as isize); + } + pub fn operator_index_2(this: Ptr, mut i: i32) -> Ptr { + return array_field_ptr!(this, data).offset((i) as isize); + } + pub fn operator_deref(this: Ptr) -> Ptr { + return field_ptr!(this, inner); + } + pub fn operator_arrow(this: Ptr) -> Ptr { + return (field_ptr!(this, inner)); + } + pub fn operator_addr(this: Ptr) -> Ptr { + return (array_field_ptr!(this, data).offset((0) as isize)); + } +} impl Default for S { fn default() -> Self { { @@ -84,17 +101,17 @@ fn main_0() -> i32 { data: Box::new([1, 2, 3]), inner: Inner { x: 9 }, })); - assert!(((({ SImpl::operator_index_1(&s.as_pointer(), 1,) }).read()) == 2)); - ({ SImpl::operator_index_1(&s.as_pointer(), 1) }).write(20); - assert!(((({ SImpl::operator_index_1(&s.as_pointer(), 1,) }).read()) == 20)); + assert!(((({ S::operator_index_1(s.as_pointer(), 1,) }).read()) == 2)); + ({ S::operator_index_1(s.as_pointer(), 1) }).write(20); + assert!(((({ S::operator_index_1(s.as_pointer(), 1,) }).read()) == 20)); let cs: Ptr = s.as_pointer(); - assert!(((({ SImpl::operator_index_2(&cs, 2,) }).read()) == 3)); - assert!((({ SImpl::operator_deref(&s.as_pointer(),) }).with(|__s| (__s).x) == 9)); - field!(({ SImpl::operator_deref(&s.as_pointer(),) }), x).write(10); - assert!((({ SImpl::operator_arrow(&s.as_pointer(),) }).with(|__s| __s.x) == 10)); - field!(({ SImpl::operator_arrow(&s.as_pointer(),) }), x).write(11); + assert!(((({ S::operator_index_2((cs).clone(), 2,) }).read()) == 3)); + assert!((({ S::operator_deref(s.as_pointer(),) }).with(|__s| (__s).x) == 9)); + field!(({ S::operator_deref(s.as_pointer(),) }), x).write(10); + assert!((({ S::operator_arrow(s.as_pointer(),) }).with(|__s| __s.x) == 10)); + field!(({ S::operator_arrow(s.as_pointer(),) }), x).write(11); assert!(({ (*s.borrow()).inner.x } == 11)); - let mut p: Ptr = ({ SImpl::operator_addr(&s.as_pointer()) }); + let mut p: Ptr = ({ S::operator_addr(s.as_pointer()) }); assert!(((p.read()) == 1)); p.write(5); assert!(((array_elem!(s.as_pointer(), data, 0).read()) == 5)); @@ -109,30 +126,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait SImpl { - fn operator_index_1(&self, i: i32) -> Ptr; - fn operator_index_2(&self, i: i32) -> Ptr; - fn operator_deref(&self) -> Ptr; - fn operator_arrow(&self) -> Ptr; - fn operator_addr(&self) -> Ptr; -} -impl SImpl for Ptr { - fn operator_index_1(&self, mut i: i32) -> Ptr { - return array_field_ptr!((*self), data).offset((i) as isize); - } - fn operator_index_2(&self, mut i: i32) -> Ptr { - return array_field_ptr!((*self), data).offset((i) as isize); - } - fn operator_deref(&self) -> Ptr { - return field_ptr!((*self), inner); - } - fn operator_arrow(&self) -> Ptr { - return (field_ptr!((*self), inner)); - } - fn operator_addr(&self) -> Ptr { - return (array_field_ptr!((*self), data).offset((0) as isize)); - } -} pub fn __cpp2rust_init_globals() { let _ = table_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/operator_other_member.rs b/tests/unit/out/refcount/operator_other_member.rs index 14e4b3ba85..462a8f50d7 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_member.rs @@ -44,6 +44,28 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_call_1(this: Ptr) -> i32 { + return this.with(|__s| __s.v); + } + pub fn operator_call_2(this: Ptr, mut a: i32) -> i32 { + return (this.with(|__s| __s.v) + a); + } + pub fn operator_call_3(this: Ptr, mut a: i32, mut b: i32) -> i32 { + return ((this.with(|__s| __s.v) + a) + b); + } + pub fn operator_comma(this: Ptr, o: Ptr) -> S { + return S { + v: ({ (this.with(|__s| __s.v) * 10) } + { o.with(|__s| __s.v) }), + }; + } + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.v); + } + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.v) != 0); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -51,58 +73,26 @@ pub fn main() { fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 3 })); let t: Value = Rc::new(RefCell::new(S { v: 4 })); - assert!((({ SImpl::operator_call_1(&s.as_pointer(),) }) == 3)); - assert!((({ SImpl::operator_call_2(&s.as_pointer(), 1,) }) == 4)); - assert!((({ SImpl::operator_call_3(&s.as_pointer(), 1, 2,) }) == 6)); - assert!(({ ({ SImpl::operator_comma(&s.as_pointer(), t.as_pointer(),) }).v } == 34)); - let mut i: i32 = ({ SImpl::to_i32(&s.as_pointer()) }); + assert!((({ S::operator_call_1(s.as_pointer(),) }) == 3)); + assert!((({ S::operator_call_2(s.as_pointer(), 1,) }) == 4)); + assert!((({ S::operator_call_3(s.as_pointer(), 1, 2,) }) == 6)); + assert!(({ ({ S::operator_comma(s.as_pointer(), t.as_pointer(),) }).v } == 34)); + let mut i: i32 = ({ S::to_i32(s.as_pointer()) }); assert!((i == 3)); - assert!(((({ SImpl::to_i32(&s.as_pointer(),) }) + 1) == 4)); - if ({ SImpl::to_bool(&s.as_pointer()) }) { - assert!(({ SImpl::to_bool(&s.as_pointer(),) })); + assert!(((({ S::to_i32(s.as_pointer(),) }) + 1) == 4)); + if ({ S::to_bool(s.as_pointer()) }) { + assert!(({ S::to_bool(s.as_pointer(),) })); } else { assert!(false); } let z: Value = Rc::new(RefCell::new(S { v: 0 })); - assert!(({ SImpl::to_bool(&s.as_pointer(),) })); - assert!(!({ SImpl::to_bool(&z.as_pointer(),) })); - assert!(({ SImpl::to_bool(&s.as_pointer(),) }) && (!({ SImpl::to_bool(&z.as_pointer(),) }))); + assert!(({ S::to_bool(s.as_pointer(),) })); + assert!(!({ S::to_bool(z.as_pointer(),) })); + assert!(({ S::to_bool(s.as_pointer(),) }) && (!({ S::to_bool(z.as_pointer(),) }))); let st: Value = Rc::new(RefCell::new(::default())); assert!((({ Static::operator_call(6, 7,) }) == 42)); - assert!((({ SImpl::operator_call_1(&Rc::new(RefCell::new(S { v: 5 })).as_pointer(),) }) == 5)); - assert!( - (({ SImpl::operator_call_3(&Rc::new(RefCell::new(S { v: 5 })).as_pointer(), 1, 1,) }) == 7) - ); + assert!((({ S::operator_call_1(Rc::new(RefCell::new(S { v: 5 })).as_pointer(),) }) == 5)); + assert!((({ S::operator_call_3(Rc::new(RefCell::new(S { v: 5 })).as_pointer(), 1, 1,) }) == 7)); return 0; } -pub trait SImpl { - fn operator_call_1(&self) -> i32; - fn operator_call_2(&self, a: i32) -> i32; - fn operator_call_3(&self, a: i32, b: i32) -> i32; - fn operator_comma(&self, o: Ptr) -> S; - fn to_i32(&self) -> i32; - fn to_bool(&self) -> bool; -} -impl SImpl for Ptr { - fn operator_call_1(&self) -> i32 { - return (*self).with(|__s| __s.v); - } - fn operator_call_2(&self, mut a: i32) -> i32 { - return ((*self).with(|__s| __s.v) + a); - } - fn operator_call_3(&self, mut a: i32, mut b: i32) -> i32 { - return (((*self).with(|__s| __s.v) + a) + b); - } - fn operator_comma(&self, o: Ptr) -> S { - return S { - v: ({ ((*self).with(|__s| __s.v) * 10) } + { o.with(|__s| __s.v) }), - }; - } - fn to_i32(&self) -> i32 { - return (*self).with(|__s| __s.v); - } - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.v) != 0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_overloads.rs b/tests/unit/out/refcount/operator_overloads.rs index 0dace84931..9c04822e52 100644 --- a/tests/unit/out/refcount/operator_overloads.rs +++ b/tests/unit/out/refcount/operator_overloads.rs @@ -23,6 +23,37 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_eq_1(this: Ptr, mut o: i32) -> i32 { + return if (this.with(|__s| __s.v) == o) { 1 } else { 0 }; + } + pub fn operator_eq_2(this: Ptr, mut o: i64) -> i32 { + return if ((this.with(|__s| __s.v) as i64) == o) { + 2 + } else { + 0 + }; + } + pub fn operator_eq_3(this: Ptr, mut o: f64) -> i32 { + return if ((this.with(|__s| __s.v) as f64) == o) { + 3 + } else { + 0 + }; + } + pub fn operator_add(this: Ptr, o: Ptr) -> i32 { + return ({ this.with(|__s| __s.v) } + { o.with(|__s| __s.v) }); + } + pub fn operator_sub(this: Ptr, mut o: S) -> i32 { + return (this.with(|__s| __s.v) - o.v); + } + pub fn operator_mul_6(this: Ptr, o: Ptr) -> i32 { + return ({ this.with(|__s| __s.v) } * { o.with(|__s| __s.v) }); + } + pub fn operator_mul_7(this: Ptr, mut o: i32) -> i32 { + return ((this.with(|__s| __s.v) * o) + 1); + } +} pub fn operator_div_0(a: Ptr, b: Ptr) -> i32 { return ({ a.with(|__s| __s.v) } / { b.with(|__s| __s.v) }); } @@ -52,14 +83,14 @@ pub fn main() { fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 6 })); let t: Value = Rc::new(RefCell::new(S { v: 4 })); - assert!((({ SImpl::operator_eq_1(&s.as_pointer(), 6,) }) == 1)); - assert!((({ SImpl::operator_eq_2(&s.as_pointer(), 6_i64,) }) == 2)); - assert!((({ SImpl::operator_eq_3(&s.as_pointer(), 6_f64,) }) == 3)); - assert!((({ SImpl::operator_eq_1(&s.as_pointer(), 7,) }) == 0)); - assert!((({ SImpl::operator_add(&s.as_pointer(), t.as_pointer(),) }) == 10)); - assert!((({ SImpl::operator_sub(&s.as_pointer(), { (*t.borrow()) },) }) == 2)); - assert!((({ SImpl::operator_mul_6(&s.as_pointer(), t.as_pointer(),) }) == 24)); - assert!((({ SImpl::operator_mul_7(&s.as_pointer(), 2,) }) == 13)); + assert!((({ S::operator_eq_1(s.as_pointer(), 6,) }) == 1)); + assert!((({ S::operator_eq_2(s.as_pointer(), 6_i64,) }) == 2)); + assert!((({ S::operator_eq_3(s.as_pointer(), 6_f64,) }) == 3)); + assert!((({ S::operator_eq_1(s.as_pointer(), 7,) }) == 0)); + assert!((({ S::operator_add(s.as_pointer(), t.as_pointer(),) }) == 10)); + assert!((({ S::operator_sub(s.as_pointer(), { (*t.borrow()) },) }) == 2)); + assert!((({ S::operator_mul_6(s.as_pointer(), t.as_pointer(),) }) == 24)); + assert!((({ S::operator_mul_7(s.as_pointer(), 2,) }) == 13)); assert!((({ operator_div_0(s.as_pointer(), t.as_pointer(),) }) == 1)); assert!((({ operator_div_1({ (*s.borrow()) }, 4,) }) == 2)); assert!((({ operator_rem_2({ (*s.borrow()) }, { (*t.borrow()) },) }) == 2)); @@ -68,48 +99,4 @@ fn main_0() -> i32 { assert!((({ operator_eq_5(6_i64, s.as_pointer(),) }) == 5)); return 0; } -pub trait SImpl { - fn operator_eq_1(&self, o: i32) -> i32; - fn operator_eq_2(&self, o: i64) -> i32; - fn operator_eq_3(&self, o: f64) -> i32; - fn operator_add(&self, o: Ptr) -> i32; - fn operator_sub(&self, o: S) -> i32; - fn operator_mul_6(&self, o: Ptr) -> i32; - fn operator_mul_7(&self, o: i32) -> i32; -} -impl SImpl for Ptr { - fn operator_eq_1(&self, mut o: i32) -> i32 { - return if ((*self).with(|__s| __s.v) == o) { - 1 - } else { - 0 - }; - } - fn operator_eq_2(&self, mut o: i64) -> i32 { - return if (((*self).with(|__s| __s.v) as i64) == o) { - 2 - } else { - 0 - }; - } - fn operator_eq_3(&self, mut o: f64) -> i32 { - return if (((*self).with(|__s| __s.v) as f64) == o) { - 3 - } else { - 0 - }; - } - fn operator_add(&self, o: Ptr) -> i32 { - return ({ (*self).with(|__s| __s.v) } + { o.with(|__s| __s.v) }); - } - fn operator_sub(&self, mut o: S) -> i32 { - return ((*self).with(|__s| __s.v) - o.v); - } - fn operator_mul_6(&self, o: Ptr) -> i32 { - return ({ (*self).with(|__s| __s.v) } * { o.with(|__s| __s.v) }); - } - fn operator_mul_7(&self, mut o: i32) -> i32 { - return (((*self).with(|__s| __s.v) * o) + 1); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_qualifiers.rs b/tests/unit/out/refcount/operator_qualifiers.rs index 7536bb88cb..40680854c3 100644 --- a/tests/unit/out/refcount/operator_qualifiers.rs +++ b/tests/unit/out/refcount/operator_qualifiers.rs @@ -23,68 +23,53 @@ pub struct S { #[offset(0)] pub v: i32, } -pub fn main() { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0()); -} -fn main_0() -> i32 { - let s: Value = Rc::new(RefCell::new(S { v: 10 })); - let cs: Value = Rc::new(RefCell::new(S { v: 10 })); - let vs: Value = Rc::new(RefCell::new(S { v: 10 })); - assert!((({ SImpl::operator_add_1(&s.as_pointer(), 1,) }) == 11)); - assert!((({ SImpl::operator_add_2(&cs.as_pointer(), 1,) }) == 12)); - assert!((({ SImpl::operator_add_3(&vs.as_pointer(), 1,) }) == 13)); - assert!((({ SImpl::operator_sub_4(&s.as_pointer(), 1,) }) == 9)); - assert!( - (({ SImpl::operator_sub_5(&Rc::new(RefCell::new(S { v: 10 })).as_pointer(), 1,) }) == 8) - ); - assert!((({ SImpl::operator_mul_6(&s.as_pointer(), 3,) }) == 30)); - assert!((({ SImpl::operator_mul_6(&cs.as_pointer(), 3,) }) == 30)); - assert!( - (({ SImpl::operator_mul_7(&Rc::new(RefCell::new(S { v: 10 })).as_pointer(), 3,) }) == 60) - ); - assert!((({ SImpl::operator_index_8(&s.as_pointer(), 2,) }) == 12)); - assert!((({ SImpl::operator_index_9(&cs.as_pointer(), 2,) }) == 112)); - return 0; -} -pub trait SImpl { - fn operator_add_1(&self, a: i32) -> i32; - fn operator_add_2(&self, a: i32) -> i32; - fn operator_add_3(&self, a: i32) -> i32; - fn operator_sub_4(&self, a: i32) -> i32; - fn operator_sub_5(&self, a: i32) -> i32; - fn operator_mul_6(&self, a: i32) -> i32; - fn operator_mul_7(&self, a: i32) -> i32; - fn operator_index_8(&self, i: i32) -> i32; - fn operator_index_9(&self, i: i32) -> i32; -} -impl SImpl for Ptr { - fn operator_add_1(&self, mut a: i32) -> i32 { - return ((*self).with(|__s| __s.v) + a); +impl S { + pub fn operator_add_1(this: Ptr, mut a: i32) -> i32 { + return (this.with(|__s| __s.v) + a); } - fn operator_add_2(&self, mut a: i32) -> i32 { - return (((*self).with(|__s| __s.v) + a) + 1); + pub fn operator_add_2(this: Ptr, mut a: i32) -> i32 { + return ((this.with(|__s| __s.v) + a) + 1); } - fn operator_add_3(&self, mut a: i32) -> i32 { - return (((*self).with(|__s| __s.v) + a) + 2); + pub fn operator_add_3(this: Ptr, mut a: i32) -> i32 { + return ((this.with(|__s| __s.v) + a) + 2); } - fn operator_sub_4(&self, mut a: i32) -> i32 { - return ((*self).with(|__s| __s.v) - a); + pub fn operator_sub_4(this: Ptr, mut a: i32) -> i32 { + return (this.with(|__s| __s.v) - a); } - fn operator_sub_5(&self, mut a: i32) -> i32 { - return (((*self).with(|__s| __s.v) - a) - 1); + pub fn operator_sub_5(this: Ptr, mut a: i32) -> i32 { + return ((this.with(|__s| __s.v) - a) - 1); } - fn operator_mul_6(&self, mut a: i32) -> i32 { - return ((*self).with(|__s| __s.v) * a); + pub fn operator_mul_6(this: Ptr, mut a: i32) -> i32 { + return (this.with(|__s| __s.v) * a); } - fn operator_mul_7(&self, mut a: i32) -> i32 { - return (((*self).with(|__s| __s.v) * a) * 2); + pub fn operator_mul_7(this: Ptr, mut a: i32) -> i32 { + return ((this.with(|__s| __s.v) * a) * 2); } - fn operator_index_8(&self, mut i: i32) -> i32 { - return ((*self).with(|__s| __s.v) + i); + pub fn operator_index_8(this: Ptr, mut i: i32) -> i32 { + return (this.with(|__s| __s.v) + i); } - fn operator_index_9(&self, mut i: i32) -> i32 { - return (((*self).with(|__s| __s.v) + i) + 100); + pub fn operator_index_9(this: Ptr, mut i: i32) -> i32 { + return ((this.with(|__s| __s.v) + i) + 100); } } +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + let s: Value = Rc::new(RefCell::new(S { v: 10 })); + let cs: Value = Rc::new(RefCell::new(S { v: 10 })); + let vs: Value = Rc::new(RefCell::new(S { v: 10 })); + assert!((({ S::operator_add_1(s.as_pointer(), 1,) }) == 11)); + assert!((({ S::operator_add_2(cs.as_pointer(), 1,) }) == 12)); + assert!((({ S::operator_add_3(vs.as_pointer(), 1,) }) == 13)); + assert!((({ S::operator_sub_4(s.as_pointer(), 1,) }) == 9)); + assert!((({ S::operator_sub_5(Rc::new(RefCell::new(S { v: 10 })).as_pointer(), 1,) }) == 8)); + assert!((({ S::operator_mul_6(s.as_pointer(), 3,) }) == 30)); + assert!((({ S::operator_mul_6(cs.as_pointer(), 3,) }) == 30)); + assert!((({ S::operator_mul_7(Rc::new(RefCell::new(S { v: 10 })).as_pointer(), 3,) }) == 60)); + assert!((({ S::operator_index_8(s.as_pointer(), 2,) }) == 12)); + assert!((({ S::operator_index_9(cs.as_pointer(), 2,) }) == 112)); + return 0; +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 1989c8fa75..993d253862 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -23,14 +23,28 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_cmp(this: Ptr, o: Ptr) -> std::cmp::Ordering { + if ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }) { + return (*libcc2rs::strong_ordering_less().upgrade().deref()); + } + if ({ this.with(|__s| __s.v) } > { o.with(|__s| __s.v) }) { + return (*libcc2rs::strong_ordering_greater().upgrade().deref()); + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_eq(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} impl CppLess for S { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + S::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for S { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + S::operator_eq(__lhs.clone(), __rhs.clone()) } } pub fn main() { @@ -40,41 +54,15 @@ pub fn main() { fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); + assert!(({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) == std::cmp::Ordering::Less); + assert!(({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) == std::cmp::Ordering::Greater); + assert!(({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) != std::cmp::Ordering::Greater); + assert!(({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) != std::cmp::Ordering::Less); + assert!(!({ S::operator_eq(a.as_pointer(), b.as_pointer(),) })); assert!( - ({ SImpl::operator_cmp(&a.as_pointer(), b.as_pointer(),) }) == std::cmp::Ordering::Less - ); - assert!( - ({ SImpl::operator_cmp(&b.as_pointer(), a.as_pointer(),) }) == std::cmp::Ordering::Greater - ); - assert!( - ({ SImpl::operator_cmp(&a.as_pointer(), b.as_pointer(),) }) != std::cmp::Ordering::Greater - ); - assert!( - ({ SImpl::operator_cmp(&b.as_pointer(), a.as_pointer(),) }) != std::cmp::Ordering::Less - ); - assert!(!({ SImpl::operator_eq(&a.as_pointer(), b.as_pointer(),) })); - assert!( - ({ SImpl::operator_cmp(&a.as_pointer(), b.as_pointer(),) }) + ({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) ); return 0; } -pub trait SImpl { - fn operator_cmp(&self, o: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, o: Ptr) -> bool; -} -impl SImpl for Ptr { - fn operator_cmp(&self, o: Ptr) -> std::cmp::Ordering { - if ({ (*self).with(|__s| __s.v) } < { o.with(|__s| __s.v) }) { - return (*libcc2rs::strong_ordering_less().upgrade().deref()); - } - if ({ (*self).with(|__s| __s.v) } > { o.with(|__s| __s.v) }) { - return (*libcc2rs::strong_ordering_greater().upgrade().deref()); - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_eq(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index cf9740e798..8aa303c76d 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -23,14 +23,20 @@ pub struct Lt { #[offset(0)] pub v: i32, } +impl Lt { + pub fn operator_lt(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }); + } +} impl CppLess for Lt { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - LtImpl::operator_lt(__lhs, __rhs.clone()) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Lt::operator_lt(__lhs.clone(), __rhs.clone()) } } impl CppEq for Lt { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - !(LtImpl::operator_lt(__lhs, __rhs.clone())) && !(LtImpl::operator_lt(__rhs, __lhs.clone())) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + !(Lt::operator_lt(__lhs.clone(), __rhs.clone())) + && !(Lt::operator_lt(__rhs.clone(), __lhs.clone())) } } #[derive( @@ -50,9 +56,14 @@ pub struct Eq { #[offset(0)] pub v: i32, } +impl Eq { + pub fn operator_eq(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} impl CppEq for Eq { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - EqImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Eq::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -72,14 +83,22 @@ pub struct Cmp { #[offset(0)] pub v: i32, } +impl Cmp { + pub fn operator_cmp(this: Ptr, o: Ptr) -> std::cmp::Ordering { + return std::cmp::Ord::cmp(&(this.with(|__s| __s.v)), &(o.with(|__s| __s.v))); + } + pub fn operator_eq(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} impl CppLess for Cmp { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - CmpImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for Cmp { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - CmpImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Cmp::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -100,12 +119,12 @@ pub struct Free { pub v: i32, } impl CppLess for Free { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_0(__lhs.clone(), __rhs.clone()) } } impl CppEq for Free { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_1(__lhs.clone(), __rhs.clone()) } } @@ -167,7 +186,7 @@ fn main_0() -> i32 { let mut __tmp_1 = { eqs.decay().begin() }; let mut __tmp_2 = { eqs.decay().end() }; let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 && !CppEq::equal(&__it.iter_deref(), &two.as_pointer()) { + while __it != __tmp_2 && !CppEq::equal(__it.iter_deref(), two.as_pointer().clone()) { __it.iter_inc(); } __it @@ -181,7 +200,7 @@ fn main_0() -> i32 { let mut __tmp_3 = { eqs.decay().begin() }; let mut __tmp_4 = { eqs.decay().end() }; let mut __it = (__tmp_3).clone(); - while __it != __tmp_4 && !CppEq::equal(&__it.iter_deref(), &nine.as_pointer()) { + while __it != __tmp_4 && !CppEq::equal(__it.iter_deref(), nine.as_pointer().clone()) { __it.iter_inc(); } __it @@ -208,7 +227,7 @@ fn main_0() -> i32 { let mut __tmp_6 = { cmps.decay().begin() }; let mut __tmp_7 = { cmps.decay().end() }; let mut __it = (__tmp_6).clone(); - while __it != __tmp_7 && !CppEq::equal(&__it.iter_deref(), &three.as_pointer()) { + while __it != __tmp_7 && !CppEq::equal(__it.iter_deref(), three.as_pointer().clone()) { __it.iter_inc(); } __it @@ -232,7 +251,7 @@ fn main_0() -> i32 { let mut __tmp_9 = { frees.decay().begin() }; let mut __tmp_10 = { frees.decay().end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && !CppEq::equal(&__it.iter_deref(), &ftwo.as_pointer()) { + while __it != __tmp_10 && !CppEq::equal(__it.iter_deref(), ftwo.as_pointer().clone()) { __it.iter_inc(); } __it @@ -276,32 +295,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait CmpImpl { - fn operator_cmp(&self, o: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, o: Ptr) -> bool; -} -impl CmpImpl for Ptr { - fn operator_cmp(&self, o: Ptr) -> std::cmp::Ordering { - return std::cmp::Ord::cmp(&((*self).with(|__s| __s.v)), &(o.with(|__s| __s.v))); - } - fn operator_eq(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} -pub trait EqImpl { - fn operator_eq(&self, o: Ptr) -> bool; -} -impl EqImpl for Ptr { - fn operator_eq(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} -pub trait LtImpl { - fn operator_lt(&self, o: Ptr) -> bool; -} -impl LtImpl for Ptr { - fn operator_lt(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } < { o.with(|__s| __s.v) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/overload_mangling.rs b/tests/unit/out/refcount/overload_mangling.rs index 4518022b92..7de23c49e2 100644 --- a/tests/unit/out/refcount/overload_mangling.rs +++ b/tests/unit/out/refcount/overload_mangling.rs @@ -33,6 +33,20 @@ pub fn twice_2(mut n: i32) -> i32 { )] #[byte_size(1)] pub struct Access_S_ {} +impl Access_S_ { + pub fn get_1(this: Ptr, mut p: Ptr) -> i32 { + return p.with(|__s| __s.base); + } + pub fn get_2(this: Ptr, mut p: Ptr) -> i32 { + return (p.with(|__s| __s.base) + 1); + } + pub fn ref_3(this: Ptr, r: Ptr) -> i32 { + return (r.with(|__s| __s.base) + 2); + } + pub fn ref_4(this: Ptr, r: Ptr) -> i32 { + return (r.with(|__s| __s.base) + 3); + } +} #[derive( Copy, Clone, @@ -50,6 +64,83 @@ pub struct S { #[offset(0)] pub base: i32, } +impl S { + pub fn plain_4(this: Ptr, mut x: i32) -> i32 { + return (this.with(|__s| __s.base) + x); + } + pub fn plain_5(this: Ptr, mut x: i64) -> i32 { + return ((this.with(|__s| __s.base) + (x as i32)) + 1); + } + pub fn take_6(this: Ptr, x: Ptr) -> i32 { + return (({ this.with(|__s| __s.base) } + { (x.read()) }) + 1); + } + pub fn take_7(this: Ptr, x: Ptr) -> i32 { + return (({ this.with(|__s| __s.base) } + { (x.read()) }) + 2); + } + pub fn pick_8(this: Ptr, p: (Value, Value)) -> i32 { + let p: Value<(Value, Value)> = Rc::new(RefCell::new(p)); + return (this.with(|__s| __s.base) + (*(*p.borrow()).0.borrow())); + } + pub fn pick_9(this: Ptr, p: (Value, Value)) -> i32 { + let p: Value<(Value, Value)> = Rc::new(RefCell::new(p)); + return (this.with(|__s| __s.base) + ((*(*p.borrow()).1.borrow()) as i32)); + } + pub fn apply_10(this: Ptr, mut f: FnPtr)>, x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + ({ f.call((x.as_pointer())) }); + return (this.with(|__s| __s.base) + (*x.borrow())); + } + pub fn apply_11(this: Ptr, mut f: FnPtr, i32)>, x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + ({ f.call((x.as_pointer()), 10) }); + return (this.with(|__s| __s.base) + (*x.borrow())); + } + pub fn apply_12(this: Ptr, mut f: FnPtr i32>, mut x: i32) -> i32 { + return ({ this.with(|__s| __s.base) } + { ({ f.call(x) }) }); + } + pub fn combine_13( + this: Ptr, + p: Ptr<(Value, Value)>, + mut f: FnPtr i32>, + mut q: Ptr, + mut n: u64, + ) -> i32 { + return ({ + ({ + ({ this.with(|__s| __s.base) } + { ((*(*p.upgrade().deref()).1.borrow()) as i32) }) + } + { ({ f.call((q.read())) }) }) + } + { (n as i32) }); + } + pub fn combine_14( + this: Ptr, + p: Ptr<(Value, Value)>, + mut f: FnPtr, i32)>, + mut q: Ptr, + mut n: u64, + ) -> i32 { + ({ f.call((q).clone(), (n as i32)) }); + return ({ ({ this.with(|__s| __s.base) } + { (*(*p.upgrade().deref()).0.borrow()) }) } + + { (q.read()) }); + } + pub fn width_1_char(this: Ptr, mut x: i32) -> i32 { + return (this.with(|__s| __s.base) + (x * (::std::mem::size_of::() as i32))); + } + pub fn width_1_int(this: Ptr, mut x: i32) -> i32 { + return (this.with(|__s| __s.base) + (x * (::std::mem::size_of::() as i32))); + } + pub fn scale_2_2(this: Ptr, mut x: i32) -> i32 { + return (this.with(|__s| __s.base) + (x * 2)); + } + pub fn scale_2_3(this: Ptr, mut x: i32) -> i32 { + return (this.with(|__s| __s.base) + (x * 3)); + } + pub fn count_3(this: Ptr, mut x: i32) -> i32 { + return ((this.with(|__s| __s.base) + x) + (0 as i32)); + } + pub fn count_3_int_long(this: Ptr, mut x: i32) -> i32 { + return ((this.with(|__s| __s.base) + x) + (2 as i32)); + } +} #[derive( Copy, Clone, @@ -73,45 +164,41 @@ pub fn main() { } fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { base: 100 })); - assert!((({ SImpl::width_1_char(&s.as_pointer(), 3,) }) == 103)); - assert!((({ SImpl::width_1_int(&s.as_pointer(), 3,) }) == 112)); - assert!((({ SImpl::scale_2_2(&s.as_pointer(), 5,) }) == 110)); - assert!((({ SImpl::scale_2_3(&s.as_pointer(), 5,) }) == 115)); - assert!((({ SImpl::count_3(&s.as_pointer(), 1,) }) == 101)); - assert!((({ SImpl::count_3_int_long(&s.as_pointer(), 1,) }) == 103)); - assert!((({ SImpl::plain_4(&s.as_pointer(), 1,) }) == 101)); - assert!((({ SImpl::plain_5(&s.as_pointer(), 1_i64,) }) == 102)); + assert!((({ S::width_1_char(s.as_pointer(), 3,) }) == 103)); + assert!((({ S::width_1_int(s.as_pointer(), 3,) }) == 112)); + assert!((({ S::scale_2_2(s.as_pointer(), 5,) }) == 110)); + assert!((({ S::scale_2_3(s.as_pointer(), 5,) }) == 115)); + assert!((({ S::count_3(s.as_pointer(), 1,) }) == 101)); + assert!((({ S::count_3_int_long(s.as_pointer(), 1,) }) == 103)); + assert!((({ S::plain_4(s.as_pointer(), 1,) }) == 101)); + assert!((({ S::plain_5(s.as_pointer(), 1_i64,) }) == 102)); let y: Value = Rc::new(RefCell::new(1)); - assert!((({ SImpl::take_6(&s.as_pointer(), y.as_pointer(),) }) == 102)); + assert!((({ S::take_6(s.as_pointer(), y.as_pointer(),) }) == 102)); assert!( (({ let _x: Value = Rc::new(RefCell::new(5)); - SImpl::take_7(&s.as_pointer(), _x.as_pointer()) + S::take_7(s.as_pointer(), _x.as_pointer()) }) == 107) ); assert!( (({ - SImpl::pick_8( - &s.as_pointer(), + S::pick_8( + s.as_pointer(), (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2))), ) }) == 101) ); assert!( (({ - SImpl::pick_9( - &s.as_pointer(), + S::pick_9( + s.as_pointer(), (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2_i64))), ) }) == 102) ); - assert!((({ SImpl::apply_10(&s.as_pointer(), FnPtr::)>::new(inc_0), 1,) }) == 102)); - assert!( - (({ SImpl::apply_11(&s.as_pointer(), FnPtr::, i32)>::new(add_1), 1,) }) == 111) - ); - assert!( - (({ SImpl::apply_12(&s.as_pointer(), FnPtr:: i32>::new(twice_2), 3,) }) == 106) - ); + assert!((({ S::apply_10(s.as_pointer(), FnPtr::)>::new(inc_0), 1,) }) == 102)); + assert!((({ S::apply_11(s.as_pointer(), FnPtr::, i32)>::new(add_1), 1,) }) == 111)); + assert!((({ S::apply_12(s.as_pointer(), FnPtr:: i32>::new(twice_2), 3,) }) == 106)); let c: Value = Rc::new(RefCell::new(3)); assert!( (({ @@ -119,8 +206,8 @@ fn main_0() -> i32 { Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2_i64)), ))); - SImpl::combine_13( - &s.as_pointer(), + S::combine_13( + s.as_pointer(), _p.as_pointer(), FnPtr:: i32>::new(twice_2), (c.as_pointer()), @@ -135,8 +222,8 @@ fn main_0() -> i32 { Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2)), ))); - SImpl::combine_14( - &s.as_pointer(), + S::combine_14( + s.as_pointer(), _p.as_pointer(), FnPtr::, i32)>::new(add_1), (z.as_pointer()), @@ -148,142 +235,12 @@ fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(::default())); let mut cs: Ptr = (s.as_pointer()); let cr: Ptr = s.as_pointer(); - assert!((({ Access_S_Impl::get_1(&a.as_pointer(), (s.as_pointer()),) }) == 100)); - assert!((({ Access_S_Impl::get_2(&a.as_pointer(), (cs).clone(),) }) == 101)); - assert!((({ Access_S_Impl::ref_3(&a.as_pointer(), s.as_pointer(),) }) == 102)); - assert!((({ Access_S_Impl::ref_4(&a.as_pointer(), (cr).clone(),) }) == 103)); + assert!((({ Access_S_::get_1(a.as_pointer(), (s.as_pointer()),) }) == 100)); + assert!((({ Access_S_::get_2(a.as_pointer(), (cs).clone(),) }) == 101)); + assert!((({ Access_S_::ref_3(a.as_pointer(), s.as_pointer(),) }) == 102)); + assert!((({ Access_S_::ref_4(a.as_pointer(), (cr).clone(),) }) == 103)); let mut b: Box_ = Box_ { v: 4 }; assert!((b.v == 4)); return 0; } -pub trait Access_S_Impl { - fn get_1(&self, p: Ptr) -> i32; - fn get_2(&self, p: Ptr) -> i32; - fn ref_3(&self, r: Ptr) -> i32; - fn ref_4(&self, r: Ptr) -> i32; -} -impl Access_S_Impl for Ptr { - fn get_1(&self, mut p: Ptr) -> i32 { - return p.with(|__s| __s.base); - } - fn get_2(&self, mut p: Ptr) -> i32 { - return (p.with(|__s| __s.base) + 1); - } - fn ref_3(&self, r: Ptr) -> i32 { - return (r.with(|__s| __s.base) + 2); - } - fn ref_4(&self, r: Ptr) -> i32 { - return (r.with(|__s| __s.base) + 3); - } -} -pub trait SImpl { - fn plain_4(&self, x: i32) -> i32; - fn plain_5(&self, x: i64) -> i32; - fn take_6(&self, x: Ptr) -> i32; - fn take_7(&self, x: Ptr) -> i32; - fn pick_8(&self, p: (Value, Value)) -> i32; - fn pick_9(&self, p: (Value, Value)) -> i32; - fn apply_10(&self, f: FnPtr)>, x: i32) -> i32; - fn apply_11(&self, f: FnPtr, i32)>, x: i32) -> i32; - fn apply_12(&self, f: FnPtr i32>, x: i32) -> i32; - fn combine_13( - &self, - p: Ptr<(Value, Value)>, - f: FnPtr i32>, - q: Ptr, - n: u64, - ) -> i32; - fn combine_14( - &self, - p: Ptr<(Value, Value)>, - f: FnPtr, i32)>, - q: Ptr, - n: u64, - ) -> i32; - fn width_1_char(&self, x: i32) -> i32; - fn width_1_int(&self, x: i32) -> i32; - fn scale_2_2(&self, x: i32) -> i32; - fn scale_2_3(&self, x: i32) -> i32; - fn count_3(&self, x: i32) -> i32; - fn count_3_int_long(&self, x: i32) -> i32; -} -impl SImpl for Ptr { - fn plain_4(&self, mut x: i32) -> i32 { - return ((*self).with(|__s| __s.base) + x); - } - fn plain_5(&self, mut x: i64) -> i32 { - return (((*self).with(|__s| __s.base) + (x as i32)) + 1); - } - fn take_6(&self, x: Ptr) -> i32 { - return (({ (*self).with(|__s| __s.base) } + { (x.read()) }) + 1); - } - fn take_7(&self, x: Ptr) -> i32 { - return (({ (*self).with(|__s| __s.base) } + { (x.read()) }) + 2); - } - fn pick_8(&self, p: (Value, Value)) -> i32 { - let p: Value<(Value, Value)> = Rc::new(RefCell::new(p)); - return ((*self).with(|__s| __s.base) + (*(*p.borrow()).0.borrow())); - } - fn pick_9(&self, p: (Value, Value)) -> i32 { - let p: Value<(Value, Value)> = Rc::new(RefCell::new(p)); - return ((*self).with(|__s| __s.base) + ((*(*p.borrow()).1.borrow()) as i32)); - } - fn apply_10(&self, mut f: FnPtr)>, x: i32) -> i32 { - let x: Value = Rc::new(RefCell::new(x)); - ({ f.call((x.as_pointer())) }); - return ((*self).with(|__s| __s.base) + (*x.borrow())); - } - fn apply_11(&self, mut f: FnPtr, i32)>, x: i32) -> i32 { - let x: Value = Rc::new(RefCell::new(x)); - ({ f.call((x.as_pointer()), 10) }); - return ((*self).with(|__s| __s.base) + (*x.borrow())); - } - fn apply_12(&self, mut f: FnPtr i32>, mut x: i32) -> i32 { - return ({ (*self).with(|__s| __s.base) } + { ({ f.call(x) }) }); - } - fn combine_13( - &self, - p: Ptr<(Value, Value)>, - mut f: FnPtr i32>, - mut q: Ptr, - mut n: u64, - ) -> i32 { - return ({ - ({ - ({ (*self).with(|__s| __s.base) } + { - ((*(*p.upgrade().deref()).1.borrow()) as i32) - }) - } + { ({ f.call((q.read())) }) }) - } + { (n as i32) }); - } - fn combine_14( - &self, - p: Ptr<(Value, Value)>, - mut f: FnPtr, i32)>, - mut q: Ptr, - mut n: u64, - ) -> i32 { - ({ f.call((q).clone(), (n as i32)) }); - return ({ ({ (*self).with(|__s| __s.base) } + { (*(*p.upgrade().deref()).0.borrow()) }) } - + { (q.read()) }); - } - fn width_1_char(&self, mut x: i32) -> i32 { - return ((*self).with(|__s| __s.base) + (x * (::std::mem::size_of::() as i32))); - } - fn width_1_int(&self, mut x: i32) -> i32 { - return ((*self).with(|__s| __s.base) + (x * (::std::mem::size_of::() as i32))); - } - fn scale_2_2(&self, mut x: i32) -> i32 { - return ((*self).with(|__s| __s.base) + (x * 2)); - } - fn scale_2_3(&self, mut x: i32) -> i32 { - return ((*self).with(|__s| __s.base) + (x * 3)); - } - fn count_3(&self, mut x: i32) -> i32 { - return (((*self).with(|__s| __s.base) + x) + (0 as i32)); - } - fn count_3_int_long(&self, mut x: i32) -> i32 { - return (((*self).with(|__s| __s.base) + x) + (2 as i32)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index ba1b6498b7..437a960d52 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -25,6 +25,11 @@ pub struct Celsius { #[offset(0)] pub degrees: i32, } +impl Celsius { + pub fn construct(this: Ptr, mut d: i32) { + field!(this, degrees).write(d); + } +} #[derive( Copy, Clone, @@ -44,6 +49,11 @@ pub struct Meters { #[offset(0)] pub value: i32, } +impl Meters { + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.value); + } +} #[derive( Copy, Clone, @@ -63,6 +73,11 @@ pub struct Label { #[offset(0)] pub id: i32, } +impl Label { + pub fn construct(this: Ptr, c: Ptr) { + field!(this, id).write(c.with(|__s| __s.degrees)); + } +} #[derive( Copy, Clone, @@ -85,6 +100,16 @@ pub struct Owner { #[offset(4)] pub copied: i32, } +impl Owner { + pub fn construct_1(this: Ptr, c: Ptr) { + field!(this, taken).write(0); + field!(this, copied).write(c.with(|__s| __s.degrees)); + } + pub fn construct_2(this: Ptr, c: Ptr) { + field!(this, taken).write(c.with(|__s| __s.degrees)); + field!(this, copied).write(0); + } +} #[derive( Copy, Clone, @@ -104,6 +129,11 @@ pub struct Holder { #[offset(0)] pub value: i32, } +impl Holder { + pub fn construct(this: Ptr, mut c: Celsius) { + field!(this, value).write(c.degrees); + } +} #[derive( Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, TriviallyCopyable, )] @@ -113,10 +143,15 @@ pub struct Fallback { #[offset(0)] pub value: i32, } +impl Fallback { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, value).write(v); + } +} impl DefaultConstructible for Fallback { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { { - FallbackImpl::construct(this, -1_i32); + Fallback::construct(this.clone(), -1_i32); } } } @@ -125,7 +160,7 @@ impl Default for Fallback { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - FallbackImpl::construct(&__v.as_pointer(), -1_i32); + Fallback::construct(__v.as_pointer(), -1_i32); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -167,6 +202,17 @@ pub struct Observer { #[offset(0)] pub seen: i32, } +impl Observer { + pub fn construct(this: Ptr, c: Ptr) { + field!(this, seen).write(c.with(|__s| __s.hits)); + field!(c, hits).with_mut(|__v| __v.postfix_inc()); + } +} +impl Tag { + pub fn construct(this: Ptr, u: Ptr) { + field!(this, code).write((u.with(|__s| __s.degrees) + 100)); + } +} #[derive( Copy, Clone, @@ -205,6 +251,16 @@ pub struct Name { #[offset(0)] pub len: i32, } +impl Name { + pub fn construct(this: Ptr, mut s: Ptr) { + field!(this, len).write(0); + 'loop_: while ((elem!(s, this.with(|__s| __s.len)).read()) != 0) { + field!(this, len).with_mut(|__v| { + __v.prefix_inc(); + }); + } + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -219,12 +275,12 @@ fn main_0() -> i32 { let from_ints: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 1); + Celsius::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 2); + Celsius::construct(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ))); @@ -232,10 +288,8 @@ fn main_0() -> i32 { assert!(({ (*(*from_ints.borrow()).1.borrow()).degrees } == 2)); let m: Value = Rc::new(RefCell::new(Meters { value: 7 })); let from_operators: Value<(Value, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new(({ MetersImpl::to_i32(&m.as_pointer()) }))), - Rc::new(RefCell::new( - (({ MetersImpl::to_i32(&m.as_pointer()) }) as i64), - )), + Rc::new(RefCell::new(({ Meters::to_i32(m.as_pointer()) }))), + Rc::new(RefCell::new((({ Meters::to_i32(m.as_pointer()) }) as i64))), ))); assert!(({ ((*(*from_operators.borrow()).0.borrow()) == 7) })); assert!(({ ((*(*from_operators.borrow()).1.borrow()) == 7_i64) })); @@ -289,12 +343,12 @@ fn main_0() -> i32 { let celsius: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 10); + Celsius::construct(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 11); + Celsius::construct(__v.as_pointer(), 11); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ))); @@ -313,12 +367,12 @@ fn main_0() -> i32 { match (Rc::new(RefCell::new(( Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 12); + Celsius::construct(__v.as_pointer(), 12); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 13); + Celsius::construct(__v.as_pointer(), 13); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ))) @@ -351,12 +405,12 @@ fn main_0() -> i32 { match (Rc::new(RefCell::new(( Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 14); + Celsius::construct(__v.as_pointer(), 14); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 15); + Celsius::construct(__v.as_pointer(), 15); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ))) @@ -390,7 +444,7 @@ fn main_0() -> i32 { let forwarded_mutable_ref: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ObserverImpl::construct(&__v.as_pointer(), counter.as_pointer()); + Observer::construct(__v.as_pointer(), counter.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new(0)), @@ -412,12 +466,12 @@ fn main_0() -> i32 { let forwarded_records: Value<(Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -38,8 +43,8 @@ pub struct B { pub v: i32, } impl DefaultConstructible for B { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(2); + fn default_constructor(this: Ptr) { + field!(this, v).write(2); } } impl Default for B { @@ -47,7 +52,7 @@ impl Default for B { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -72,6 +77,11 @@ pub struct NoDefault { #[offset(0)] pub v: i32, } +impl NoDefault { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} pub fn used_0(mut x: A) -> i32 { return x.v; } @@ -103,6 +113,14 @@ pub struct S_NoDefault_ { #[offset(0)] pub v: i32, } +impl S_NoDefault_ { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } + pub fn get(this: Ptr, mut t: NoDefault) -> i32 { + return (this.with(|__s| __s.v) + t.v); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -112,7 +130,7 @@ fn main_0() -> i32 { (({ used_0({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 1) @@ -121,7 +139,7 @@ fn main_0() -> i32 { (({ used_0({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - AImpl::construct_1(&__v.as_pointer(), 5); + A::construct_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 5) @@ -130,7 +148,7 @@ fn main_0() -> i32 { (({ used_1({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 2) @@ -140,7 +158,7 @@ fn main_0() -> i32 { scaled_2( { let __v: Value = Rc::new(RefCell::new(::zero_init())); - AImpl::construct_1(&__v.as_pointer(), 3); + A::construct_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, (4usize as i32), @@ -152,7 +170,7 @@ fn main_0() -> i32 { scaled_2( { let __v: Value = Rc::new(RefCell::new(::zero_init())); - AImpl::construct_1(&__v.as_pointer(), 3); + A::construct_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, 2, @@ -163,7 +181,7 @@ fn main_0() -> i32 { (({ always_given_3({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoDefaultImpl::construct(&__v.as_pointer(), 3); + NoDefault::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 3) @@ -171,41 +189,13 @@ fn main_0() -> i32 { object!(s, S_NoDefault_(1)); assert!( (({ - S_NoDefault_Impl::get(&s.as_pointer(), { + S_NoDefault_::get(s.as_pointer(), { let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoDefaultImpl::construct(&__v.as_pointer(), 4); + NoDefault::construct(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 5) ); return 0; } -pub trait AImpl { - fn construct_1(&self, v: i32); -} -impl AImpl for Ptr { - fn construct_1(&self, mut v: i32) { - field!((*self), v).write(v); - } -} -pub trait NoDefaultImpl { - fn construct(&self, v: i32); -} -impl NoDefaultImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} -pub trait S_NoDefault_Impl { - fn construct(&self, v: i32); - fn get(&self, t: NoDefault) -> i32; -} -impl S_NoDefault_Impl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } - fn get(&self, mut t: NoDefault) -> i32 { - return ((*self).with(|__s| __s.v) + t.v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index d246ec5fa3..fff18c3bc5 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -27,8 +27,8 @@ pub struct Inner { pub values: Vec, } impl DefaultConstructible for Inner { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); } } #[derive( @@ -58,10 +58,10 @@ pub struct Outer { pub name: Box<[i8]>, } impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); - DefaultConstructible::default_constructor(&field_ptr!(this, inner)); - field!((*this), name).write((0..8).map(|_| 0_i8).collect::>()); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); + DefaultConstructible::default_constructor(field_ptr!(this, inner)); + field!(this, name).write((0..8).map(|_| 0_i8).collect::>()); } } impl Default for Outer { @@ -75,11 +75,11 @@ impl Default for Outer { } } } -pub fn make_0(this: Ptr, calls: Ptr) { +pub fn make_0(__return: Ptr, calls: Ptr) { calls.with_mut(|__v| { __v.prefix_inc(); }); - this.write(Outer { + __return.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index 2e8b87b90f..13657670a7 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -27,12 +27,12 @@ pub struct Outer { pub values: Vec, } impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); } } -pub fn make_0(this: Ptr) { - this.write(Outer { +pub fn make_0(__return: Ptr) { + __return.write(Outer { values: Vec::from([1, 2, 3, 4]), }); return; @@ -56,6 +56,11 @@ pub struct H { #[offset(0)] pub last: i32, } +impl H { + pub fn construct(this: Ptr, values: Ptr>) { + field!(this, last).write((index!(values, 3_usize).read())); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -63,8 +68,8 @@ pub fn main() { fn main_0() -> i32 { object!(h, H, |h| { let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); - HImpl::construct( - h, + H::construct( + h.clone(), (match { ({ make_0(Ptr::clone(&__tmp_1.as_pointer())) }); __tmp_1.as_pointer() @@ -76,12 +81,4 @@ fn main_0() -> i32 { printf!(b"%d\n", { (*h.borrow()).last }); return 0; } -pub trait HImpl { - fn construct(&self, values: Ptr>); -} -impl HImpl for Ptr { - fn construct(&self, values: Ptr>) { - field!((*self), last).write((index!(values, 3_usize).read())); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index 324e8a8a43..5dfcce5ada 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -27,8 +27,8 @@ pub struct Inner { pub values: Vec, } impl DefaultConstructible for Inner { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); } } #[derive( @@ -55,13 +55,13 @@ pub struct Outer { pub inner: Inner, } impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); - DefaultConstructible::default_constructor(&field_ptr!(this, inner)); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); + DefaultConstructible::default_constructor(field_ptr!(this, inner)); } } -pub fn make_0(this: Ptr) { - this.write(Outer { +pub fn make_0(__return: Ptr) { + __return.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), diff --git a/tests/unit/out/refcount/this.rs b/tests/unit/out/refcount/this.rs index 831fafe88f..6967f7c14c 100644 --- a/tests/unit/out/refcount/this.rs +++ b/tests/unit/out/refcount/this.rs @@ -27,6 +27,86 @@ pub struct S { #[byte_size(8)] pub self__: Ptr, } +impl S { + pub fn construct_1(this: Ptr, mut a: i32) { + field!(this, a_).write(a); + field!(this, self__).write(Ptr::::null()); + } + pub fn construct_2(this: Ptr, mut a: i32, mut other: Ptr) { + field!(this, a_).write(a); + field!(this, self__).write(Ptr::::null()); + if (this == other) { + field!(this, self__).write(Ptr::::null()); + } else { + field!(this, self__).write((other).clone()); + } + } + pub fn construct_3(this: Ptr, mut a: i32, mut other: Ptr) { + field!(this, a_).write(a); + field!(this, self__).write(Ptr::::null()); + if (this == other) { + field!(this, self__).write(Ptr::::null()); + } + } + pub fn returns_this_reference(this: Ptr) -> Ptr { + return (this).clone(); + } + pub fn returns_this_pointer(this: Ptr) -> Ptr { + return (this).clone(); + } + pub fn inc(this: Ptr) -> Ptr { + field!(this, a_).with_mut(|__v| __v.postfix_inc()); + return (this).clone(); + } + pub fn set_from_this(this: Ptr) { + field!(this, a_).write((this.with(|__s| __s.a_) + 1)); + } + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.a_); + } + pub fn twice(this: Ptr) -> i32 { + return (({ S::get(this.clone()) }) * 2); + } + pub fn link(this: Ptr) { + field!(this, self__).write((this).clone()); + } + pub fn bump_me(this: Ptr) { + ({ bump_0((this).clone()) }); + } + pub fn cref(this: Ptr) -> Ptr { + return (this).clone(); + } + pub fn is(this: Ptr, mut o: Ptr) -> bool { + return (o == this); + } + pub fn destroy(this: Ptr) { + this.delete(); + } + pub fn reset(this: Ptr) { + let __rhs = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::construct_1(__v.as_pointer(), 0); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + this.write(__rhs); + } + pub fn copy_if_different_const(this: Ptr, mut other: Ptr) -> bool { + if (this == other) { + return false; + } + field!(this, a_).write(other.with(|__s| __s.a_)); + field!(this, self__).write(other.with(|__s| __s.self__.clone())); + return true; + } + pub fn copy_if_different(this: Ptr, mut other: Ptr) -> bool { + if (this == other) { + return false; + } + field!(this, a_).write(other.with(|__s| __s.a_)); + field!(this, self__).write(other.with(|__s| __s.self__.clone())); + return true; + } +} pub fn bump_0(mut p: Ptr) { field!(p, a_).with_mut(|__v| __v.postfix_inc()); } @@ -49,65 +129,72 @@ pub struct D { #[offset(0)] pub a_: i32, } +impl D { + pub fn construct(this: Ptr, mut a: i32) { + field!(this, a_).write(a); + { + field!(this, a_).with_mut(|__v| *__v = *__v * 2) + }; + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { object!(s, S::construct_1(1)); - let ref_: Ptr = ({ SImpl::returns_this_reference(&s.as_pointer()) }); + let ref_: Ptr = ({ S::returns_this_reference(s.as_pointer()) }); field!(ref_, a_).with_mut(|__v| __v.postfix_inc()); assert!(({ (*s.borrow()).a_ } == 2)); - let mut ptr: Ptr = ({ SImpl::returns_this_pointer(&s.as_pointer()) }); + let mut ptr: Ptr = ({ S::returns_this_pointer(s.as_pointer()) }); field!(ptr, a_).with_mut(|__v| __v.postfix_inc()); assert!(({ (*s.borrow()).a_ } == 3)); - ({ SImpl::inc(&({ SImpl::inc(&({ SImpl::inc(&s.as_pointer()) })) })) }); + ({ S::inc(({ S::inc(({ S::inc(s.as_pointer()) })) })) }); assert!(({ (*s.borrow()).a_ } == 6)); - ({ SImpl::set_from_this(&s.as_pointer()) }); + ({ S::set_from_this(s.as_pointer()) }); assert!(({ (*s.borrow()).a_ } == 7)); - assert!((({ SImpl::twice(&s.as_pointer(),) }) == 14)); - ({ SImpl::link(&s.as_pointer()) }); + assert!((({ S::twice(s.as_pointer(),) }) == 14)); + ({ S::link(s.as_pointer()) }); assert!(({ { (*s.borrow()).self__.clone() } } == { (s.as_pointer()) })); field!({ (*s.borrow()).self__.clone() }, a_).with_mut(|__v| __v.postfix_inc()); assert!(({ (*s.borrow()).a_ } == 8)); - ({ SImpl::bump_me(&s.as_pointer()) }); + ({ S::bump_me(s.as_pointer()) }); assert!(({ (*s.borrow()).a_ } == 9)); object!(d, D(3)); assert!(({ (*d.borrow()).a_ } == 6)); - let cr: Ptr = ({ SImpl::cref(&s.as_pointer()) }); + let cr: Ptr = ({ S::cref(s.as_pointer()) }); assert!((cr.with(|__s| __s.a_) == 9)); object!(t, S::construct_1(0)); - assert!(({ SImpl::is(&s.as_pointer(), (s.as_pointer()),) })); - assert!(!({ SImpl::is(&s.as_pointer(), (t.as_pointer()),) })); + assert!(({ S::is(s.as_pointer(), (s.as_pointer()),) })); + assert!(!({ S::is(s.as_pointer(), (t.as_pointer()),) })); let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - SImpl::construct_1(&__p, 1); + S::construct_1(__p.clone(), 1); __p }; - let mut q: Ptr = ({ SImpl::returns_this_pointer(&p) }); + let mut q: Ptr = ({ S::returns_this_pointer((p).clone()) }); field!(q, a_).with_mut(|__v| __v.postfix_inc()); assert!((p.with(|__s| __s.a_) == 2)); p.delete(); let mut h: Ptr = { let __p = Ptr::alloc(::zero_init()); - SImpl::construct_1(&__p, 5); + S::construct_1(__p.clone(), 5); __p }; - ({ SImpl::destroy(&h) }); - ({ SImpl::reset(&s.as_pointer()) }); + ({ S::destroy((h).clone()) }); + ({ S::reset(s.as_pointer()) }); assert!(({ (*s.borrow()).a_ } == 0)); assert!(({ (*s.borrow()).self__.clone() }).is_null()); assert!( - ((({ SImpl::copy_if_different(&s.as_pointer(), (s.as_pointer()),) }) as i32) - == (false as i32)) + ((({ S::copy_if_different(s.as_pointer(), (s.as_pointer()),) }) as i32) == (false as i32)) ); assert!( - ((({ SImpl::copy_if_different_const(&s.as_pointer(), (s.as_pointer()),) }) as i32) + ((({ S::copy_if_different_const(s.as_pointer(), (s.as_pointer()),) }) as i32) == (false as i32)) ); object!(other, S::construct_1(22)); assert!( - ((({ SImpl::copy_if_different(&s.as_pointer(), (other.as_pointer()),) }) as i32) + ((({ S::copy_if_different(s.as_pointer(), (other.as_pointer()),) }) as i32) == (true as i32)) ); assert!(({ (*s.borrow()).a_ } == { (*other.borrow()).a_ })); @@ -116,121 +203,11 @@ fn main_0() -> i32 { assert!(({ { (*u.borrow()).self__.clone() } } == { (s.as_pointer()) })); let s_const: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - SImpl::construct_1(&__v.as_pointer(), 100); + S::construct_1(__v.as_pointer(), 100); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); object!(u1, S::construct_3(1, (s_const.as_pointer()))); assert!(({ (*u1.borrow()).self__.clone() }).is_null()); return 0; } -pub trait DImpl { - fn construct(&self, a: i32); -} -impl DImpl for Ptr { - fn construct(&self, mut a: i32) { - field!((*self), a_).write(a); - { - field!((*self), a_).with_mut(|__v| *__v = *__v * 2) - }; - } -} -pub trait SImpl { - fn construct_1(&self, a: i32); - fn construct_2(&self, a: i32, other: Ptr); - fn construct_3(&self, a: i32, other: Ptr); - fn returns_this_reference(&self) -> Ptr; - fn returns_this_pointer(&self) -> Ptr; - fn inc(&self) -> Ptr; - fn set_from_this(&self); - fn get(&self) -> i32; - fn twice(&self) -> i32; - fn link(&self); - fn bump_me(&self); - fn cref(&self) -> Ptr; - fn is(&self, o: Ptr) -> bool; - fn destroy(&self); - fn reset(&self); - fn copy_if_different_const(&self, other: Ptr) -> bool; - fn copy_if_different(&self, other: Ptr) -> bool; -} -impl SImpl for Ptr { - fn construct_1(&self, mut a: i32) { - field!((*self), a_).write(a); - field!((*self), self__).write(Ptr::::null()); - } - fn construct_2(&self, mut a: i32, mut other: Ptr) { - field!((*self), a_).write(a); - field!((*self), self__).write(Ptr::::null()); - if ((*self) == other) { - field!((*self), self__).write(Ptr::::null()); - } else { - field!((*self), self__).write((other).clone()); - } - } - fn construct_3(&self, mut a: i32, mut other: Ptr) { - field!((*self), a_).write(a); - field!((*self), self__).write(Ptr::::null()); - if ((*self) == other) { - field!((*self), self__).write(Ptr::::null()); - } - } - fn returns_this_reference(&self) -> Ptr { - return (*self).clone(); - } - fn returns_this_pointer(&self) -> Ptr { - return (*self).clone(); - } - fn inc(&self) -> Ptr { - field!((*self), a_).with_mut(|__v| __v.postfix_inc()); - return (*self).clone(); - } - fn set_from_this(&self) { - field!((*self), a_).write(((*self).with(|__s| __s.a_) + 1)); - } - fn get(&self) -> i32 { - return (*self).with(|__s| __s.a_); - } - fn twice(&self) -> i32 { - return (({ SImpl::get(self) }) * 2); - } - fn link(&self) { - field!((*self), self__).write((*self).clone()); - } - fn bump_me(&self) { - ({ bump_0((*self).clone()) }); - } - fn cref(&self) -> Ptr { - return (*self).clone(); - } - fn is(&self, mut o: Ptr) -> bool { - return (o == (*self)); - } - fn destroy(&self) { - (*self).delete(); - } - fn reset(&self) { - let __rhs = { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - SImpl::construct_1(&__v.as_pointer(), 0); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; - (*self).write(__rhs); - } - fn copy_if_different_const(&self, mut other: Ptr) -> bool { - if ((*self) == other) { - return false; - } - field!((*self), a_).write(other.with(|__s| __s.a_)); - field!((*self), self__).write(other.with(|__s| __s.self__.clone())); - return true; - } - fn copy_if_different(&self, mut other: Ptr) -> bool { - if ((*self) == other) { - return false; - } - field!((*self), a_).write(other.with(|__s| __s.a_)); - field!((*self), self__).write(other.with(|__s| __s.self__.clone())); - return true; - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index d99fbe7bd9..a4735ddfbe 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -46,8 +46,8 @@ pub struct Outer { pub runs: Vec, } impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { - field!((*this), runs).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, runs).write(Vec::new()); } } pub fn main() { diff --git a/tests/unit/out/refcount/unboxed_conditional_iterator.rs b/tests/unit/out/refcount/unboxed_conditional_iterator.rs index 15b18cc32e..2f66920724 100644 --- a/tests/unit/out/refcount/unboxed_conditional_iterator.rs +++ b/tests/unit/out/refcount/unboxed_conditional_iterator.rs @@ -59,7 +59,7 @@ pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { let mut __tmp_1 = { items.decay().end() }; let mut __it = (__tmp_0).clone(); while __it != __tmp_1 - && !CppEq::equal(&__it.iter_deref(), &sigma.offset((i) as isize)) + && !CppEq::equal(__it.iter_deref(), sigma.offset((i) as isize).clone()) { __it.iter_inc(); } diff --git a/tests/unit/out/refcount/unboxed_locals.rs b/tests/unit/out/refcount/unboxed_locals.rs index 1d74367807..be10bc8eed 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -172,7 +172,7 @@ fn main_0() -> i32 { let high: Value = Rc::new(RefCell::new(3)); let mut low: i32 = { let __tmp_0: Value = Rc::new(RefCell::new(2)); - (if CppLess::less(&__tmp_0.as_pointer(), &high.as_pointer()) { + (if CppLess::less(__tmp_0.as_pointer().clone(), high.as_pointer().clone()) { __tmp_0.as_pointer() } else { high.as_pointer() diff --git a/tests/unit/out/refcount/unboxed_records.rs b/tests/unit/out/refcount/unboxed_records.rs index 9466e8a26b..aed059e058 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.rs @@ -72,9 +72,16 @@ pub struct Counter { #[offset(0)] pub n: i32, } +impl Counter { + pub fn inc(this: Ptr) { + field!(this, n).with_mut(|__v| { + __v.prefix_inc(); + }); + } +} impl DefaultConstructible for Counter { - fn default_constructor(this: &Ptr) { - field!((*this), n).write(0); + fn default_constructor(this: Ptr) { + field!(this, n).write(0); } } impl Default for Counter { @@ -142,18 +149,8 @@ fn main_0() -> i32 { ({ set_0((field_ptr!(field_addr.as_pointer(), b)), 7) }); assert!(({ (*field_addr.borrow()).b } == 7)); object!(counter, Counter); - ({ CounterImpl::inc(&counter.as_pointer()) }); + ({ Counter::inc(counter.as_pointer()) }); assert!(({ (*counter.borrow()).n } == 1)); return 0; } -pub trait CounterImpl { - fn inc(&self); -} -impl CounterImpl for Ptr { - fn inc(&self) { - field!((*self), n).with_mut(|__v| { - __v.prefix_inc(); - }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index 68bef48b82..bd740b79fa 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -16,9 +16,18 @@ pub struct SafePointer { #[byte_size(8)] pub ptr: Option>, } +impl SafePointer { + pub fn inc(this: Ptr) { + this.with(|__s| __s.ptr.clone()) + .as_pointer() + .with_mut(|__v| { + __v.prefix_inc(); + }); + } +} impl DefaultConstructible for SafePointer { - fn default_constructor(this: &Ptr) { - field!((*this), ptr).write(None); + fn default_constructor(this: Ptr) { + field!(this, ptr).write(None); } } #[derive( @@ -40,6 +49,16 @@ pub struct Pair { #[offset(4)] pub y: i32, } +impl Pair { + pub fn inc(this: Ptr, mut k: i32) { + { + field!(this, x).with_mut(|__v| *__v = *__v + k) + }; + { + field!(this, y).with_mut(|__v| *__v = *__v + k) + }; + } +} pub fn DoStuffWithSafePointer_0(safe_ptr: Ptr>>) { let mut x1: Option> = Some(Rc::new(RefCell::new(0))); let mut x2: Option> = Some(Rc::new(RefCell::new(0))); @@ -60,8 +79,8 @@ pub fn DoStuffWithSafePointer_0(safe_ptr: Ptr>>) { (*__b0) = x1.take(); }), }; - ({ SafePointerImpl::inc(&({ (*safe_ptr.upgrade().deref()).as_pointer() })) }); - ({ SafePointerImpl::inc(&({ (*safe_ptr.upgrade().deref()).as_pointer() })) }); + ({ SafePointer::inc(({ (*safe_ptr.upgrade().deref()).as_pointer() })) }); + ({ SafePointer::inc(({ (*safe_ptr.upgrade().deref()).as_pointer() })) }); let mut x3: Option> = Some(Rc::new(RefCell::new(10))); let mut x4: Option> = Some(Rc::new(RefCell::new(20))); x3.as_pointer() @@ -77,7 +96,7 @@ pub fn DoStuffWithSafePointer_0(safe_ptr: Ptr>>) { x: (raw_ptr2.read()), y: 5, }))); - ({ PairImpl::inc(&(pair.as_pointer()), 10) }); + ({ Pair::inc((pair.as_pointer()), 10) }); ({ (*safe_ptr.upgrade().deref()).as_pointer() }) .with(|__s| (__s).ptr.clone()) .as_pointer() @@ -159,7 +178,7 @@ pub fn RndStuff_2() { 'for_body: { assert!((elem!(p3_0, i).with(|__s| __s.x) == 1)); assert!((elem!(p3_0, i).with(|__s| __s.y) == 2)); - ({ PairImpl::inc(&({ (*x3.borrow()).decay().offset((i as usize)) }), 10) }); + ({ Pair::inc(({ (*x3.borrow()).decay().offset((i as usize)) }), 10) }); assert!((elem!(p3_0, i).with(|__s| __s.x) == 11)); assert!((elem!(p3_0, i).with(|__s| __s.y) == 12)); } @@ -194,7 +213,7 @@ pub fn RndStuff_2() { 'for_body: { assert!((elem!(p3_1, i).with(|__s| __s.x) == -1_i32)); assert!((elem!(p3_1, i).with(|__s| __s.y) == -2_i32)); - ({ PairImpl::inc(&({ (*x3.borrow()).decay().offset((i as usize)) }), -10_i32) }); + ({ Pair::inc(({ (*x3.borrow()).decay().offset((i as usize)) }), -10_i32) }); assert!((elem!(p3_1, i).with(|__s| __s.x) == -11_i32)); assert!((elem!(p3_1, i).with(|__s| __s.y) == -12_i32)); } @@ -232,30 +251,4 @@ fn main_0() -> i32 { ({ unique_ptr_that_wraps_container_3() }); return 0; } -pub trait PairImpl { - fn inc(&self, k: i32); -} -impl PairImpl for Ptr { - fn inc(&self, mut k: i32) { - { - field!((*self), x).with_mut(|__v| *__v = *__v + k) - }; - { - field!((*self), y).with_mut(|__v| *__v = *__v + k) - }; - } -} -pub trait SafePointerImpl { - fn inc(&self); -} -impl SafePointerImpl for Ptr { - fn inc(&self) { - (*self) - .with(|__s| __s.ptr.clone()) - .as_pointer() - .with_mut(|__v| { - __v.prefix_inc(); - }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/unique_ptr_const_deref.rs b/tests/unit/out/refcount/unique_ptr_const_deref.rs index 454aaf6fff..5bdcba70e9 100644 --- a/tests/unit/out/refcount/unique_ptr_const_deref.rs +++ b/tests/unit/out/refcount/unique_ptr_const_deref.rs @@ -17,8 +17,8 @@ pub struct Holder { pub val: Option>, } impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { - field!((*this), val).write(None); + fn default_constructor(this: Ptr) { + field!(this, val).write(None); } } pub fn read_val_0(mut h: Ptr) -> i32 { diff --git a/tests/unit/out/refcount/unique_ptr_field_reset.rs b/tests/unit/out/refcount/unique_ptr_field_reset.rs index 4f6de52840..78a2bb0ea3 100644 --- a/tests/unit/out/refcount/unique_ptr_field_reset.rs +++ b/tests/unit/out/refcount/unique_ptr_field_reset.rs @@ -35,10 +35,18 @@ pub struct Holder { #[offset(8)] pub n: i32, } +impl Holder { + pub fn set(this: Ptr, mut p: Ptr) { + { + let _p: Ptr<_> = (p).clone(); + field_ptr!(this, data).write(_p.to_owned_opt()) + }; + } +} impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { - field!((*this), data).write(None); - field!((*this), n).write(0_i32); + fn default_constructor(this: Ptr) { + field!(this, data).write(None); + field!(this, n).write(0_i32); } } pub fn main() { @@ -59,7 +67,7 @@ fn main_0() -> i32 { .with(|__s| __s.v) == 3) ); - ({ HolderImpl::set(&h.as_pointer(), Ptr::alloc(Data { v: 4 })) }); + ({ Holder::set(h.as_pointer(), Ptr::alloc(Data { v: 4 })) }); assert!( (hp.with(|__s| __s.data.clone()) .as_pointer() @@ -78,15 +86,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait HolderImpl { - fn set(&self, p: Ptr); -} -impl HolderImpl for Ptr { - fn set(&self, mut p: Ptr) { - { - let _p: Ptr<_> = (p).clone(); - field_ptr!((*self), data).write(_p.to_owned_opt()) - }; - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/unique_ptr_nested.rs b/tests/unit/out/refcount/unique_ptr_nested.rs index 83088c96fd..4bd124f7ec 100644 --- a/tests/unit/out/refcount/unique_ptr_nested.rs +++ b/tests/unit/out/refcount/unique_ptr_nested.rs @@ -36,8 +36,8 @@ pub struct Outer { pub inner: Option>, } impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { - field!((*this), inner).write(None); + fn default_constructor(this: Ptr) { + field!(this, inner).write(None); } } pub fn main() { diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index 7f5725c809..b1d257ca32 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -44,9 +44,15 @@ pub struct Guard_1 { #[offset(8)] pub active: bool, } +impl Guard_1 { + pub fn construct(this: Ptr, val: Ptr>) { + field!(this, ap).write((val).clone()); + field!(this, active).write(true); + } +} impl Destructible for Guard_1 { - fn destroy(this: &Ptr) { - if (*this).with(|__s| __s.active) {} + fn destroy(this: Ptr) { + if this.with(|__s| __s.active) {} } } pub fn sum_ptr_2(n: i32, __args: Box<[VaArg]>) -> i32 { @@ -95,13 +101,4 @@ fn main_0() -> i32 { assert!((({ sum_ptr_2(2, Box::new([(4).into(), (5).into(),])) }) == 9)); return 0; } -pub trait Guard_1Impl { - fn construct(&self, val: Ptr>); -} -impl Guard_1Impl for Ptr { - fn construct(&self, val: Ptr>) { - field!((*self), ap).write((val).clone()); - field!((*self), active).write(true); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 50a02a2158..47f5e85479 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -48,9 +48,9 @@ pub struct Foo { pub b: Vec, } impl DefaultConstructible for Foo { - fn default_constructor(this: &Ptr) { - field!((*this), a).write(Vec::new()); - field!((*this), b).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, a).write(Vec::new()); + field!(this, b).write(Vec::new()); } } #[derive( @@ -72,6 +72,11 @@ pub struct Wrapped { #[offset(0)] pub v: i32, } +impl Wrapped { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} pub fn exchange_1(x: Ptr>, y: Ptr>) { x.swap_with(&(y).clone(), |__v| __v.with_mut(std::mem::take)); } @@ -795,12 +800,4 @@ fn main_0() -> i32 { } return 0; } -pub trait WrappedImpl { - fn construct(&self, v: i32); -} -impl WrappedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index cc1b881f20..688722f1c7 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -25,6 +25,11 @@ pub struct Degrees { #[offset(0)] pub value: i32, } +impl Degrees { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, value).write(v); + } +} #[derive( Copy, Clone, @@ -44,6 +49,11 @@ pub struct Reading { #[offset(0)] pub raw_: i32, } +impl Reading { + pub fn to_i64(this: Ptr) -> i64 { + return ((this.with(|__s| __s.raw_) as i64) * 10_i64); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -237,20 +247,4 @@ fn main_0() -> i32 { assert!((v8[0_usize] == 40_i64) && (v8[1_usize] == 50_i64)); return 0; } -pub trait DegreesImpl { - fn construct(&self, v: i32); -} -impl DegreesImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), value).write(v); - } -} -pub trait ReadingImpl { - fn to_i64(&self) -> i64; -} -impl ReadingImpl for Ptr { - fn to_i64(&self) -> i64 { - return (((*self).with(|__s| __s.raw_) as i64) * 10_i64); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index cecfe4bdc3..7eca784f53 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -25,6 +25,11 @@ pub struct Point { #[offset(4)] pub y: i32, } +impl Point { + pub fn sum(this: Ptr) -> i32 { + return (this.with(|__s| __s.x) + this.with(|__s| __s.y)); + } +} #[derive( Clone, Record, @@ -49,9 +54,9 @@ pub struct Holder { pub points: Vec, } impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); - field!((*this), points).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); + field!(this, points).write(Vec::new()); } } pub fn push_and_index_0(v: Ptr>) -> i32 { @@ -122,9 +127,7 @@ fn main_0() -> i32 { }); field!(vec_elem!(h.as_pointer(), points, 0_usize), y).write(5); assert!(((vec_elem!(h.as_pointer(), values, 1_usize).read()) == 6)); - assert!( - (({ PointImpl::sum(&field_ref!(h.as_pointer(), points).decay().offset(0_usize),) }) == 6) - ); + assert!((({ Point::sum(field_ref!(h.as_pointer(), points).decay().offset(0_usize),) }) == 6)); let mut hp: Ptr = (h.as_pointer()); vec_elem!(hp, values, 0_usize).write(((vec_elem!(hp, values, 1_usize).read()) + 1)); field!(vec_elem!(hp, points, 0_usize), x).write((vec_elem!(hp, values, 0_usize).read())); @@ -174,12 +177,4 @@ fn main_0() -> i32 { assert!(({ (*a.borrow())[1_usize] } == 10)); return 0; } -pub trait PointImpl { - fn sum(&self) -> i32; -} -impl PointImpl for Ptr { - fn sum(&self) -> i32 { - return ((*self).with(|__s| __s.x) + (*self).with(|__s| __s.y)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index 2683886115..140a20b210 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -20,6 +20,14 @@ use std::rc::{Rc, Weak}; )] #[byte_size(1)] pub struct TestAllocator_int_ {} +impl TestAllocator_int_ { + pub fn allocate(this: Ptr, mut n: usize) -> Ptr { + return Ptr::alloc_array((0..n).map(|_| 0_i32).collect::>()); + } + pub fn deallocate(this: Ptr, mut p: Ptr, mut _a1: usize) { + p.delete(); + } +} #[derive( Copy, Clone, @@ -34,6 +42,14 @@ pub struct TestAllocator_int_ {} )] #[byte_size(1)] pub struct TestAllocator_double_ {} +impl TestAllocator_double_ { + pub fn allocate(this: Ptr, mut n: usize) -> Ptr { + return Ptr::alloc_array((0..n).map(|_| 0_f64).collect::>()); + } + pub fn deallocate(this: Ptr, mut p: Ptr, mut _a1: usize) { + p.delete(); + } +} pub fn copy_0(mut copy_vector: Vec) {} pub fn fn_1(v: Ptr>, v3: Vec) { let v3: Value> = Rc::new(RefCell::new(v3)); @@ -461,28 +477,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait TestAllocator_double_Impl { - fn allocate(&self, n: usize) -> Ptr; - fn deallocate(&self, p: Ptr, _a1: usize); -} -impl TestAllocator_double_Impl for Ptr { - fn allocate(&self, mut n: usize) -> Ptr { - return Ptr::alloc_array((0..n).map(|_| 0_f64).collect::>()); - } - fn deallocate(&self, mut p: Ptr, mut _a1: usize) { - p.delete(); - } -} -pub trait TestAllocator_int_Impl { - fn allocate(&self, n: usize) -> Ptr; - fn deallocate(&self, p: Ptr, _a1: usize); -} -impl TestAllocator_int_Impl for Ptr { - fn allocate(&self, mut n: usize) -> Ptr { - return Ptr::alloc_array((0..n).map(|_| 0_i32).collect::>()); - } - fn deallocate(&self, mut p: Ptr, mut _a1: usize) { - p.delete(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 043974a1c8..7af3f1a185 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -28,8 +28,8 @@ pub struct NonTrivial { pub data: Vec, } impl DefaultConstructible for NonTrivial { - fn default_constructor(this: &Ptr) { - field!((*this), data).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, data).write(Vec::new()); } } pub fn unused_ref_param_1(x: Ptr) {} @@ -69,8 +69,8 @@ pub struct NonCopyable { pub value: Option>, } impl DefaultConstructible for NonCopyable { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(None); + fn default_constructor(this: Ptr) { + field!(this, value).write(None); } } pub fn unused_noncopyable_param_5(x: Ptr) {} diff --git a/tests/unit/out/unsafe/05_new.rs b/tests/unit/out/unsafe/05_new.rs index e759fb132e..a1efffa008 100644 --- a/tests/unit/out/unsafe/05_new.rs +++ b/tests/unit/out/unsafe/05_new.rs @@ -31,7 +31,7 @@ pub struct A {} )] pub struct D {} impl D { - pub unsafe fn operator_call(&self, mut ptr: *const A) { + pub unsafe fn operator_call(this: *const Self, mut ptr: *const A) { { let __p = ptr; if !__p.is_null() { diff --git a/tests/unit/out/unsafe/10_struct.rs b/tests/unit/out/unsafe/10_struct.rs index ec9f7117a2..62398003c9 100644 --- a/tests/unit/out/unsafe/10_struct.rs +++ b/tests/unit/out/unsafe/10_struct.rs @@ -37,14 +37,14 @@ pub struct Graph { pub adj: *mut *mut GraphNode, } impl Graph { - pub unsafe fn push(&self, mut src: u32, mut dst: u32) { - (*self.adj.offset((src) as isize)) = (Box::leak(Box::new(GraphNode { + pub unsafe fn push(this: *const Self, mut src: u32, mut dst: u32) { + (*(*this).adj.offset((src) as isize)) = (Box::leak(Box::new(GraphNode { dst: dst, - next: (*self.adj.offset((src) as isize)), + next: (*(*this).adj.offset((src) as isize)), })) as *mut GraphNode); - (*self.adj.offset((dst) as isize)) = (Box::leak(Box::new(GraphNode { + (*(*this).adj.offset((dst) as isize)) = (Box::leak(Box::new(GraphNode { dst: src, - next: (*self.adj.offset((dst) as isize)), + next: (*(*this).adj.offset((dst) as isize)), })) as *mut GraphNode); } } @@ -54,13 +54,13 @@ pub struct Partial { pub p: *mut i32, } impl Partial { - pub unsafe fn construct_1(&mut self, mut q: *mut i32) { - (&raw mut self.p).write(q); + pub unsafe fn construct_1(this: *mut Self, mut q: *mut i32) { + (&raw mut (*this).p).write(q); } } impl DefaultConstructibleUnsafe for Partial { - unsafe fn default_constructor(&mut self) { - (&raw mut self.p).write(std::ptr::null_mut()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).p).write(std::ptr::null_mut()); } } impl Default for Partial { diff --git a/tests/unit/out/unsafe/any.rs b/tests/unit/out/unsafe/any.rs index 79f9527793..676e6ad93b 100644 --- a/tests/unit/out/unsafe/any.rs +++ b/tests/unit/out/unsafe/any.rs @@ -22,9 +22,9 @@ pub struct Point { pub y: i32, } impl Point { - pub unsafe fn construct(&mut self, mut x: i32, mut y: i32) { - (&raw mut self.x).write(x); - (&raw mut self.y).write(y); + pub unsafe fn construct(this: *mut Self, mut x: i32, mut y: i32) { + (&raw mut (*this).x).write(x); + (&raw mut (*this).y).write(y); } } pub fn main() { @@ -36,7 +36,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: Option> = Some(Box::new({ let mut __v: Point = ::zero_init(); - Point::construct(&mut __v, 3, 4); + Point::construct(&raw mut __v, 3, 4); __v })); assert!(a.is_some()); @@ -65,7 +65,7 @@ unsafe fn main_0() -> i32 { let q: *mut Point = { a = Some(Box::new({ let mut __v: Point = ::zero_init(); - Point::construct(&mut __v, 5, 6); + Point::construct(&raw mut __v, 5, 6); __v })); a.as_mut().unwrap().downcast_mut::().unwrap() diff --git a/tests/unit/out/unsafe/array_of_noncopy_struct.rs b/tests/unit/out/unsafe/array_of_noncopy_struct.rs index 1a149bffad..26b8dd2b99 100644 --- a/tests/unit/out/unsafe/array_of_noncopy_struct.rs +++ b/tests/unit/out/unsafe/array_of_noncopy_struct.rs @@ -23,9 +23,9 @@ pub struct NonCopy { pub tag: i32, } impl DefaultConstructibleUnsafe for NonCopy { - unsafe fn default_constructor(&mut self) { - (&raw mut self.data).write(Vec::new()); - (&raw mut self.tag).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).data).write(Vec::new()); + (&raw mut (*this).tag).write(0); } } impl Default for NonCopy { @@ -47,7 +47,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut arr: [NonCopy; 3] = std::array::from_fn::<_, 3, _>(|_| { let mut __v: NonCopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }); arr[(0) as usize].tag = 7; diff --git a/tests/unit/out/unsafe/as_const.rs b/tests/unit/out/unsafe/as_const.rs index cfe9e4b522..90835907eb 100644 --- a/tests/unit/out/unsafe/as_const.rs +++ b/tests/unit/out/unsafe/as_const.rs @@ -24,17 +24,17 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn f_1(&mut self) -> Overload { + pub unsafe fn f_1(this: *mut Self) -> Overload { return Overload_kMutableOverload; } - pub unsafe fn f_2(&self) -> Overload { + pub unsafe fn f_2(this: *const Self) -> Overload { return Overload_kConstOverload; } - pub unsafe fn value_ref_3(&mut self) -> *mut i32 { - return &mut self.v; + pub unsafe fn value_ref_3(this: *mut Self) -> *mut i32 { + return &mut (*this).v; } - pub unsafe fn value_ref_4(&self) -> *const i32 { - return &self.v; + pub unsafe fn value_ref_4(this: *const Self) -> *const i32 { + return &(*this).v; } } pub unsafe fn g_0(_a0: *mut S) -> Overload { @@ -51,20 +51,20 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut s: S = S { v: 7 }; - assert!((((unsafe { S::f_1(&mut s,) }) as i32) == (Overload_kMutableOverload as i32))); - assert!((((unsafe { S::f_2(&s,) }) as i32) == (Overload_kConstOverload as i32))); + assert!((((unsafe { S::f_1(&raw mut s,) }) as i32) == (Overload_kMutableOverload as i32))); + assert!((((unsafe { S::f_2(&raw const s,) }) as i32) == (Overload_kConstOverload as i32))); assert!((((unsafe { g_0(&mut s,) }) as i32) == (Overload_kMutableOverload as i32))); assert!((((unsafe { g_1(&s,) }) as i32) == (Overload_kConstOverload as i32))); - (*(unsafe { S::value_ref_3(&mut s) })) = 9; + (*(unsafe { S::value_ref_3(&raw mut s) })) = 9; assert!(((s.v) == (9))); - assert!(((*(unsafe { S::value_ref_4(&s,) })) == (9))); + assert!(((*(unsafe { S::value_ref_4(&raw const s,) })) == (9))); let cs: *const S = &s; - assert!((((unsafe { S::f_2(&(*cs),) }) as i32) == (Overload_kConstOverload as i32))); + assert!((((unsafe { S::f_2(&raw const (*cs),) }) as i32) == (Overload_kConstOverload as i32))); assert!((((*cs).v) == (9))); let mut p: *mut S = (&mut s as *mut S); (*p).v = 11; assert!(((s.v) == (11))); - assert!((((unsafe { S::f_1(&mut (*p),) }) as i32) == (Overload_kMutableOverload as i32))); + assert!((((unsafe { S::f_1(&raw mut (*p),) }) as i32) == (Overload_kMutableOverload as i32))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 99b439ee17..a6d55f72e3 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -1461,7 +1461,7 @@ pub static mut selected_values_34: std::cell::LazyCell<[u32; 3]> = )] pub struct IndexedBinding {} impl IndexedBinding { - pub unsafe fn get_1_0(&mut self) -> *mut u32 { + pub unsafe fn get_1_0(this: *mut Self) -> *mut u32 { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_34)) [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_34))[(0) as usize]) as usize]; @@ -1470,10 +1470,10 @@ impl IndexedBinding { pub unsafe fn test_binding_35() { let mut owner: IndexedBinding = ::default(); let __decomp_36: *mut IndexedBinding = &mut owner; - let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_36)) }); + let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&raw mut (*__decomp_36)) }); let mut result: u32 = (match ( { 1_u32 }, - &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_36)) })), + &mut (*(unsafe { IndexedBinding::get_1_0(&raw mut (*__decomp_36)) })), ) { (__tmp_97, __tmp_98) => { (*__tmp_98) = (*__tmp_98).wrapping_add(__tmp_97); @@ -2134,8 +2134,8 @@ pub struct Counts_59 { pub counts: Vec, } impl DefaultConstructibleUnsafe for Counts_59 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.counts).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).counts).write(Vec::new()); } } #[repr(C)] diff --git a/tests/unit/out/unsafe/cast.rs b/tests/unit/out/unsafe/cast.rs index 836987073e..64c45ff4cc 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -73,9 +73,9 @@ pub struct Bag { pub items: Vec, } impl DefaultConstructibleUnsafe for Bag { - unsafe fn default_constructor(&mut self) { - (&raw mut self.n).write(0_i32); - (&raw mut self.items).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).n).write(0_i32); + (&raw mut (*this).items).write(Vec::new()); } } pub unsafe fn adjacent_arrays_0() { diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index dbd48a62a6..8bb913f0e5 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -22,31 +22,31 @@ pub struct Pair { pub second: i32, } impl Pair { - pub unsafe fn NOP(&mut self) {} - pub unsafe fn GetFirst(&self) -> i32 { - return self.first; + pub unsafe fn NOP(this: *mut Self) {} + pub unsafe fn GetFirst(this: *const Self) -> i32 { + return (*this).first; } - pub unsafe fn GetSecond(&self) -> i32 { - return self.second; + pub unsafe fn GetSecond(this: *const Self) -> i32 { + return (*this).second; } - pub unsafe fn Set(&mut self, field: *mut i32, mut new_val: i32) -> i32 { - (unsafe { Pair::NOP(self) }); + pub unsafe fn Set(this: *mut Self, field: *mut i32, mut new_val: i32) -> i32 { + (unsafe { Pair::NOP(this) }); let mut old_val: i32 = (*field); (*field) = new_val; return old_val; } - pub unsafe fn SetFirst(&mut self, mut new_first: i32) -> i32 { - return ((unsafe { Pair::GetFirst(self) }) + pub unsafe fn SetFirst(this: *mut Self, mut new_first: i32) -> i32 { + return ((unsafe { Pair::GetFirst((this).cast_const()) }) + (unsafe { - let _field: *mut i32 = &mut self.first; - Pair::Set(self, _field, new_first) + let _field: *mut i32 = &mut (*this).first; + Pair::Set(this, _field, new_first) })); } - pub unsafe fn SetSecond(&mut self, mut new_second: i32) -> i32 { - return ((unsafe { Pair::GetSecond(self) }) + pub unsafe fn SetSecond(this: *mut Self, mut new_second: i32) -> i32 { + return ((unsafe { Pair::GetSecond((this).cast_const()) }) + (unsafe { - let _field: *mut i32 = &mut self.second; - Pair::Set(self, _field, new_second) + let _field: *mut i32 = &mut (*this).second; + Pair::Set(this, _field, new_second) })); } } @@ -66,9 +66,9 @@ pub struct Route { pub cost: f64, } impl Route { - pub unsafe fn SetCost(&mut self, mut new_cost: f64) -> f64 { - let mut old_cost: f64 = self.cost; - self.cost = new_cost; + pub unsafe fn SetCost(this: *mut Self, mut new_cost: f64) -> f64 { + let mut old_cost: f64 = (*this).cost; + (*this).cost = new_cost; return old_cost; } } @@ -88,13 +88,13 @@ pub struct Counter { pub calls: i32, } impl Counter { - pub unsafe fn Get(&self) -> i32 { - (*(&raw const self.calls).cast_mut()).prefix_inc(); - return self.v; + pub unsafe fn Get(this: *const Self) -> i32 { + (*(&raw const (*this).calls).cast_mut()).prefix_inc(); + return (*this).v; } - pub unsafe fn operator_eq(&self, o: *const Counter) -> bool { - (*(&raw const self.calls).cast_mut()).prefix_inc(); - return ((self.v) == ((*o).v)); + pub unsafe fn operator_eq(this: *const Self, o: *const Counter) -> bool { + (*(&raw const (*this).calls).cast_mut()).prefix_inc(); + return (((*this).v) == ((*o).v)); } } impl std::cmp::PartialEq for Counter { @@ -118,25 +118,25 @@ pub struct Tally { pub calls: i32, } impl Tally { - pub unsafe fn SameNameBetweenConstAndNonConst_1(&mut self) -> i32 { - self.calls += 1; + pub unsafe fn SameNameBetweenConstAndNonConst_1(this: *mut Self) -> i32 { + (*this).calls += 1; return 1; } - pub unsafe fn SameNameBetweenConstAndNonConst_2(&self) -> i32 { - (*(&raw const self.calls).cast_mut()) += 10; + pub unsafe fn SameNameBetweenConstAndNonConst_2(this: *const Self) -> i32 { + (*(&raw const (*this).calls).cast_mut()) += 10; return 2; } } pub unsafe fn RandomRoute_0(route: *mut Route) -> i32 { if ((((*route).path.first) % (2)) != 0) { return (unsafe { - let _new_first: i32 = (unsafe { Pair::SetSecond(&mut (*route).path, 10) }); - Pair::SetFirst(&mut (*route).path, _new_first) + let _new_first: i32 = (unsafe { Pair::SetSecond(&raw mut (*route).path, 10) }); + Pair::SetFirst(&raw mut (*route).path, _new_first) }); } else { return (unsafe { - let _new_second: i32 = (unsafe { Pair::SetFirst(&mut (*route).path, -10_i32) }); - Pair::SetSecond(&mut (*route).path, _new_second) + let _new_second: i32 = (unsafe { Pair::SetFirst(&raw mut (*route).path, -10_i32) }); + Pair::SetSecond(&raw mut (*route).path, _new_second) }); } panic!("ub: non-void function does not return a value") @@ -164,8 +164,8 @@ unsafe fn main_0() -> i32 { }; let mut old_cost: f64 = (unsafe { Route::SetCost( - &mut route1, - (unsafe { Route::SetCost(&mut route2, 15_f64) }), + &raw mut route1, + (unsafe { Route::SetCost(&raw mut route2, 15_f64) }), ) }); assert!( @@ -177,19 +177,19 @@ unsafe fn main_0() -> i32 { let mut c1: Counter = Counter { v: 3, calls: 0 }; let c2: Counter = Counter { v: 3, calls: 0 }; let mut pc: *const Counter = (&mut c1 as *mut Counter).cast_const(); - assert!(((unsafe { Counter::Get(&c1,) }) == (3))); - assert!(((unsafe { Counter::Get(&c2,) }) == (3))); - assert!(((unsafe { Counter::Get(&(*pc),) }) == (3))); - assert!((unsafe { Counter::operator_eq(&c1, &c2,) })); - assert!((unsafe { Counter::operator_eq(&c2, &c1,) })); + assert!(((unsafe { Counter::Get(&raw const c1,) }) == (3))); + assert!(((unsafe { Counter::Get(&raw const c2,) }) == (3))); + assert!(((unsafe { Counter::Get(&raw const (*pc),) }) == (3))); + assert!((unsafe { Counter::operator_eq(&raw const c1, &c2,) })); + assert!((unsafe { Counter::operator_eq(&raw const c2, &c1,) })); assert!(((c1.calls) == (3))); assert!(((c2.calls) == (2))); let mut t: Tally = Tally { calls: 0 }; let ct: Tally = Tally { calls: 0 }; let rt: *const Tally = &t; - assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_1(&mut t,) }) == (1))); - assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_2(&ct,) }) == (2))); - assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_2(&(*rt),) }) == (2))); + assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_1(&raw mut t,) }) == (1))); + assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_2(&raw const ct,) }) == (2))); + assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_2(&raw const (*rt),) }) == (2))); assert!(((t.calls) == (11))); assert!(((ct.calls) == (10))); return 0; diff --git a/tests/unit/out/unsafe/class_template_lazy_member.rs b/tests/unit/out/unsafe/class_template_lazy_member.rs index acb08b983b..dbb14b2a0e 100644 --- a/tests/unit/out/unsafe/class_template_lazy_member.rs +++ b/tests/unit/out/unsafe/class_template_lazy_member.rs @@ -35,8 +35,8 @@ pub struct Box_int_ { pub val: i32, } impl Box_int_ { - pub unsafe fn twice(&mut self) -> i32 { - return ((self.val) + (self.val)); + pub unsafe fn twice(this: *mut Self) -> i32 { + return (((*this).val) + ((*this).val)); } } #[repr(C)] @@ -54,8 +54,8 @@ pub struct Box_Point_ { pub val: Point, } impl Box_Point_ { - pub unsafe fn get(&mut self) -> Point { - return self.val; + pub unsafe fn get(this: *mut Self) -> Point { + return (*this).val; } } #[repr(C)] @@ -73,8 +73,8 @@ pub struct Deduced_int_ { pub val: i32, } impl Deduced_int_ { - pub unsafe fn twice(&mut self) -> i32 { - return ((self.val) + (self.val)); + pub unsafe fn twice(this: *mut Self) -> i32 { + return (((*this).val) + ((*this).val)); } } #[repr(C)] @@ -92,8 +92,8 @@ pub struct Deduced_Point_ { pub val: Point, } impl Deduced_Point_ { - pub unsafe fn get(&mut self) -> Point { - return self.val; + pub unsafe fn get(this: *mut Self) -> Point { + return (*this).val; } } pub fn main() { @@ -104,17 +104,17 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut i: Box_int_ = Box_int_ { val: 3 }; - assert!(((unsafe { Box_int_::twice(&mut i,) }) == (6))); + assert!(((unsafe { Box_int_::twice(&raw mut i,) }) == (6))); let mut p: Box_Point_ = Box_Point_ { val: Point { x: 4 }, }; - assert!((((unsafe { Box_Point_::get(&mut p,) }).x) == (4))); + assert!((((unsafe { Box_Point_::get(&raw mut p,) }).x) == (4))); let mut d: Deduced_int_ = Deduced_int_ { val: 5 }; - assert!(((unsafe { Deduced_int_::twice(&mut d,) }) == (10))); + assert!(((unsafe { Deduced_int_::twice(&raw mut d,) }) == (10))); let mut dp: Deduced_Point_ = Deduced_Point_ { val: Point { x: 6 }, }; - assert!((((unsafe { Deduced_Point_::get(&mut dp,) }).x) == (6))); + assert!((((unsafe { Deduced_Point_::get(&raw mut dp,) }).x) == (6))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/class_templates.rs b/tests/unit/out/unsafe/class_templates.rs index 999d8bac36..91c1cf5f86 100644 --- a/tests/unit/out/unsafe/class_templates.rs +++ b/tests/unit/out/unsafe/class_templates.rs @@ -23,29 +23,29 @@ pub struct MyContainer_int_ { vec_: Vec, } impl MyContainer_int_ { - pub unsafe fn empty(&self) -> bool { - return self.vec_.is_empty(); + pub unsafe fn empty(this: *const Self) -> bool { + return (*this).vec_.is_empty(); } - pub unsafe fn size(&self) -> usize { - return self.vec_.len(); + pub unsafe fn size(this: *const Self) -> usize { + return (*this).vec_.len(); } - pub unsafe fn back_4(&mut self) -> *mut i32 { + pub unsafe fn back_4(this: *mut Self) -> *mut i32 { return { - let __n = self.vec_.len() - 1; - &raw mut self.vec_[__n] + let __n = (*this).vec_.len() - 1; + &raw mut (&mut (*this)).vec_[__n] }; } - pub unsafe fn pop_back(&mut self) { - self.vec_.pop(); + pub unsafe fn pop_back(this: *mut Self) { + (*this).vec_.pop(); return; } - pub unsafe fn push_back(&mut self, item: *const i32) { - self.vec_.push_copied(item); + pub unsafe fn push_back(this: *mut Self, item: *const i32) { + (*this).vec_.push_copied(item); } } impl DefaultConstructibleUnsafe for MyContainer_int_ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.vec_).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).vec_).write(Vec::new()); } } #[repr(C)] @@ -65,29 +65,29 @@ pub struct MyContainer_char_ { vec_: Vec, } impl MyContainer_char_ { - pub unsafe fn empty(&self) -> bool { - return self.vec_.is_empty(); + pub unsafe fn empty(this: *const Self) -> bool { + return (*this).vec_.is_empty(); } - pub unsafe fn size(&self) -> usize { - return self.vec_.len(); + pub unsafe fn size(this: *const Self) -> usize { + return (*this).vec_.len(); } - pub unsafe fn back_4(&mut self) -> *mut libc::c_char { + pub unsafe fn back_4(this: *mut Self) -> *mut libc::c_char { return { - let __n = self.vec_.len() - 1; - &raw mut self.vec_[__n] + let __n = (*this).vec_.len() - 1; + &raw mut (&mut (*this)).vec_[__n] }; } - pub unsafe fn pop_back(&mut self) { - self.vec_.pop(); + pub unsafe fn pop_back(this: *mut Self) { + (*this).vec_.pop(); return; } - pub unsafe fn push_back(&mut self, item: *const libc::c_char) { - self.vec_.push_copied(item); + pub unsafe fn push_back(this: *mut Self, item: *const libc::c_char) { + (*this).vec_.push_copied(item); } } impl DefaultConstructibleUnsafe for MyContainer_char_ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.vec_).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).vec_).write(Vec::new()); } } #[repr(C)] @@ -107,29 +107,29 @@ pub struct MyContainer_float_ { vec_: Vec, } impl MyContainer_float_ { - pub unsafe fn empty(&self) -> bool { - return self.vec_.is_empty(); + pub unsafe fn empty(this: *const Self) -> bool { + return (*this).vec_.is_empty(); } - pub unsafe fn size(&self) -> usize { - return self.vec_.len(); + pub unsafe fn size(this: *const Self) -> usize { + return (*this).vec_.len(); } - pub unsafe fn back_4(&mut self) -> *mut f32 { + pub unsafe fn back_4(this: *mut Self) -> *mut f32 { return { - let __n = self.vec_.len() - 1; - &raw mut self.vec_[__n] + let __n = (*this).vec_.len() - 1; + &raw mut (&mut (*this)).vec_[__n] }; } - pub unsafe fn pop_back(&mut self) { - self.vec_.pop(); + pub unsafe fn pop_back(this: *mut Self) { + (*this).vec_.pop(); return; } - pub unsafe fn push_back(&mut self, item: *const f32) { - self.vec_.push_copied(item); + pub unsafe fn push_back(this: *mut Self, item: *const f32) { + (*this).vec_.push_copied(item); } } impl DefaultConstructibleUnsafe for MyContainer_float_ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.vec_).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).vec_).write(Vec::new()); } } #[repr(C)] @@ -150,8 +150,8 @@ impl Boxed_short_ { pub unsafe fn twice(mut v: i16) -> i16 { return (((v as i32) + (v as i32)) as i16); } - pub unsafe fn plus(&self, mut other: i16) -> i16 { - return (((self.value as i32) + (other as i32)) as i16); + pub unsafe fn plus(this: *const Self, mut other: i16) -> i16 { + return ((((*this).value as i32) + (other as i32)) as i16); } } #[repr(C)] @@ -172,8 +172,8 @@ impl Boxed_int_ { pub unsafe fn twice(mut v: i32) -> i32 { return ((v) + (v)); } - pub unsafe fn plus(&self, mut other: i32) -> i32 { - return ((self.value) + (other)); + pub unsafe fn plus(this: *const Self, mut other: i32) -> i32 { + return (((*this).value) + (other)); } } #[repr(C)] @@ -194,8 +194,8 @@ impl Boxed_long_ { pub unsafe fn twice(mut v: i64) -> i64 { return ((v) + (v)); } - pub unsafe fn plus(&self, mut other: i64) -> i64 { - return ((self.value) + (other)); + pub unsafe fn plus(this: *const Self, mut other: i64) -> i64 { + return (((*this).value) + (other)); } } #[repr(C)] @@ -214,8 +214,8 @@ pub struct Outer_int__Inner_int_ { pub u: i32, } impl Outer_int__Inner_int_ { - pub unsafe fn sum(&self) -> i32 { - return ((self.t as i32) + (self.u as i32)); + pub unsafe fn sum(this: *const Self) -> i32 { + return (((*this).t as i32) + ((*this).u as i32)); } } #[repr(C)] @@ -233,8 +233,8 @@ pub struct Outer_int_ { pub v: i32, } impl Outer_int_ { - pub unsafe fn with(&self, mut n: i32) -> Outer_int__Inner_int_ { - return Outer_int__Inner_int_ { t: self.v, u: n }; + pub unsafe fn with(this: *const Self, mut n: i32) -> Outer_int__Inner_int_ { + return Outer_int__Inner_int_ { t: (*this).v, u: n }; } } #[repr(C)] @@ -253,8 +253,8 @@ pub struct Outer_long__Inner_int_ { pub u: i32, } impl Outer_long__Inner_int_ { - pub unsafe fn sum(&self) -> i32 { - return ((self.t as i32) + (self.u as i32)); + pub unsafe fn sum(this: *const Self) -> i32 { + return (((*this).t as i32) + ((*this).u as i32)); } } #[repr(C)] @@ -273,8 +273,8 @@ pub struct Outer_long__Inner_char_ { pub u: libc::c_char, } impl Outer_long__Inner_char_ { - pub unsafe fn sum(&self) -> i32 { - return ((self.t as i32) + (self.u as i32)); + pub unsafe fn sum(this: *const Self) -> i32 { + return (((*this).t as i32) + ((*this).u as i32)); } } #[repr(C)] @@ -292,8 +292,8 @@ pub struct Outer_long_ { pub v: i64, } impl Outer_long_ { - pub unsafe fn with(&self, mut n: i32) -> Outer_long__Inner_int_ { - return Outer_long__Inner_int_ { t: self.v, u: n }; + pub unsafe fn with(this: *const Self, mut n: i32) -> Outer_long__Inner_int_ { + return Outer_long__Inner_int_ { t: (*this).v, u: n }; } } #[repr(C)] @@ -326,7 +326,9 @@ unsafe fn main_0() -> i32 { assert!((((unsafe { Boxed_short_::twice(2_i16,) }) as i32) == (4))); let mut oi: Outer_int_ = Outer_int_ { v: 3 }; assert!( - ((unsafe { Outer_int__Inner_int_::sum(&(unsafe { Outer_int_::with(&oi, 4,) }),) }) == (7)) + ((unsafe { + Outer_int__Inner_int_::sum(&(unsafe { Outer_int_::with(&raw const oi, 4) })) + }) == (7)) ); let mut ol: Outer_long_ = Outer_long_ { v: 5_i64 }; let mut ic: Outer_long__Inner_char_ = Outer_long__Inner_char_ { @@ -334,55 +336,57 @@ unsafe fn main_0() -> i32 { u: ('a' as libc::c_char), }; assert!( - ((unsafe { Outer_long__Inner_int_::sum(&(unsafe { Outer_long_::with(&ol, 2,) }),) }) - == (7)) + ((unsafe { + Outer_long__Inner_int_::sum(&(unsafe { Outer_long_::with(&raw const ol, 2) })) + }) == (7)) ); assert!( - ((unsafe { Outer_long__Inner_char_::sum(&ic,) }) == ((6) + (('a' as libc::c_char) as i32))) + ((unsafe { Outer_long__Inner_char_::sum(&raw const ic,) }) + == ((6) + (('a' as libc::c_char) as i32))) ); assert!(((unsafe { Boxed_int_::twice(3,) }) == (6))); let mut bi: Boxed_int_ = Boxed_int_ { value: 4 }; - assert!(((unsafe { Boxed_int_::plus(&bi, 5,) }) == (9))); + assert!(((unsafe { Boxed_int_::plus(&raw const bi, 5,) }) == (9))); assert!(((unsafe { Boxed_long_::twice(10_i64,) }) == (20_i64))); let mut bl: Boxed_long_ = Boxed_long_ { value: 7_i64 }; - assert!(((unsafe { Boxed_long_::plus(&bl, 1_i64,) }) == (8_i64))); + assert!(((unsafe { Boxed_long_::plus(&raw const bl, 1_i64,) }) == (8_i64))); object_unsafe!(imc, MyContainer_int_); - assert!((unsafe { MyContainer_int_::empty(&imc,) })); + assert!((unsafe { MyContainer_int_::empty(&raw const imc,) })); (unsafe { let mut _item: i32 = 1; - MyContainer_int_::push_back(&mut imc, &mut _item) + MyContainer_int_::push_back(&raw mut imc, &mut _item) }); assert!( - ((unsafe { MyContainer_int_::size(&imc,) }) == (1_usize)) - && ((*(unsafe { MyContainer_int_::back_4(&mut imc,) })) == (1)) + ((unsafe { MyContainer_int_::size(&raw const imc,) }) == (1_usize)) + && ((*(unsafe { MyContainer_int_::back_4(&raw mut imc,) })) == (1)) ); - (unsafe { MyContainer_int_::pop_back(&mut imc) }); - assert!((unsafe { MyContainer_int_::empty(&imc,) })); + (unsafe { MyContainer_int_::pop_back(&raw mut imc) }); + assert!((unsafe { MyContainer_int_::empty(&raw const imc,) })); object_unsafe!(cmc, MyContainer_char_); - assert!((unsafe { MyContainer_char_::empty(&cmc,) })); + assert!((unsafe { MyContainer_char_::empty(&raw const cmc,) })); (unsafe { let mut _item: libc::c_char = ('a' as libc::c_char); - MyContainer_char_::push_back(&mut cmc, &mut _item) + MyContainer_char_::push_back(&raw mut cmc, &mut _item) }); assert!( - ((unsafe { MyContainer_char_::size(&cmc,) }) == (1_usize)) - && (((*(unsafe { MyContainer_char_::back_4(&mut cmc,) })) as i32) + ((unsafe { MyContainer_char_::size(&raw const cmc,) }) == (1_usize)) + && (((*(unsafe { MyContainer_char_::back_4(&raw mut cmc,) })) as i32) == (('a' as libc::c_char) as i32)) ); - (unsafe { MyContainer_char_::pop_back(&mut cmc) }); - assert!((unsafe { MyContainer_char_::empty(&cmc,) })); + (unsafe { MyContainer_char_::pop_back(&raw mut cmc) }); + assert!((unsafe { MyContainer_char_::empty(&raw const cmc,) })); object_unsafe!(fmc, MyContainer_float_); - assert!((unsafe { MyContainer_float_::empty(&fmc,) })); + assert!((unsafe { MyContainer_float_::empty(&raw const fmc,) })); (unsafe { let mut _item: f32 = (1_f64 as f32); - MyContainer_float_::push_back(&mut fmc, &mut _item) + MyContainer_float_::push_back(&raw mut fmc, &mut _item) }); assert!( - ((unsafe { MyContainer_float_::size(&fmc,) }) == (1_usize)) - && (((*(unsafe { MyContainer_float_::back_4(&mut fmc,) })) as f64) == (1_f64)) + ((unsafe { MyContainer_float_::size(&raw const fmc,) }) == (1_usize)) + && (((*(unsafe { MyContainer_float_::back_4(&raw mut fmc,) })) as f64) == (1_f64)) ); - (unsafe { MyContainer_float_::pop_back(&mut fmc) }); - assert!((unsafe { MyContainer_float_::empty(&fmc,) })); + (unsafe { MyContainer_float_::pop_back(&raw mut fmc) }); + assert!((unsafe { MyContainer_float_::empty(&raw const fmc,) })); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index ed66325643..11379eabf7 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(); { - v4.assign_from(&mut v2); + AssignFromUnsafe::assign_from(&raw mut v4, &mut v2); }; { let mut i: i32 = 0; diff --git a/tests/unit/out/unsafe/complex_function.rs b/tests/unit/out/unsafe/complex_function.rs index 6d0fe914cd..99d90add18 100644 --- a/tests/unit/out/unsafe/complex_function.rs +++ b/tests/unit/out/unsafe/complex_function.rs @@ -44,8 +44,8 @@ pub struct X2 { pub v: *mut X1, } impl X2 { - pub unsafe fn get(&mut self) -> *mut X1 { - return self.v; + pub unsafe fn get(this: *mut Self) -> *mut X1 { + return (*this).v; } } #[repr(C)] @@ -63,8 +63,8 @@ pub struct X3 { pub v: *mut X2, } impl X3 { - pub unsafe fn get(&mut self) -> *mut X2 { - return self.v; + pub unsafe fn get(this: *mut Self) -> *mut X2 { + return (*this).v; } } #[repr(C)] @@ -82,8 +82,8 @@ pub struct X4 { pub v: X3, } impl X4 { - pub unsafe fn get(&mut self) -> *mut X3 { - return &mut self.v; + pub unsafe fn get(this: *mut Self) -> *mut X3 { + return &mut (*this).v; } } pub fn main() { @@ -117,28 +117,35 @@ unsafe fn main_0() -> i32 { }; let mut d: X4 = X4 { v: c }; (*(*d.v.v).v).v = 0; - (*(unsafe { X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) })).v = - 0; + (*(unsafe { + X2::get(&raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) }))) + })) + .v = 0; d.v.v = (&mut b as *mut X2); let r4: *const i32 = &(*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get(&raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) }))) })) .v; - let r5: *mut X1 = - (unsafe { X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) }); - let mut p: *mut X2 = (unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }); - let r6: *mut X3 = (unsafe { X4::get(&mut d) }); + let r5: *mut X1 = (unsafe { + X2::get(&raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) }))) + }); + let mut p: *mut X2 = (unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) }); + let r6: *mut X3 = (unsafe { X4::get(&raw mut d) }); let r7: *mut X3 = &mut d.v; - let r8: *mut i32 = &mut (*(unsafe { X2::get(&mut (*(unsafe { X3::get(&mut d.v) }))) })).v; - let mut x5: i32 = - (*(unsafe { X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) })) - .v; + let r8: *mut i32 = + &mut (*(unsafe { X2::get(&raw mut (*(unsafe { X3::get(&raw mut d.v) }))) })).v; + let mut x5: i32 = (*(unsafe { + X2::get(&raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) }))) + })) + .v; (*(unsafe { bar_2(&mut x1) })) += 10; (*(unsafe { bar_2(&mut x1) })).postfix_inc(); let mut bar_out: i32 = (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -149,7 +156,9 @@ unsafe fn main_0() -> i32 { (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -157,7 +166,9 @@ unsafe fn main_0() -> i32 { (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -166,7 +177,9 @@ unsafe fn main_0() -> i32 { let mut bar_inc2: i32 = (*(*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -175,7 +188,9 @@ unsafe fn main_0() -> i32 { bar_inc2 = (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -186,7 +201,9 @@ unsafe fn main_0() -> i32 { (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -195,7 +212,9 @@ unsafe fn main_0() -> i32 { (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -203,7 +222,9 @@ unsafe fn main_0() -> i32 { (*(&mut (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -211,7 +232,9 @@ unsafe fn main_0() -> i32 { let mut ptr1: i32 = (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -220,7 +243,9 @@ unsafe fn main_0() -> i32 { let ptr2: *mut i32 = &mut (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -228,7 +253,9 @@ unsafe fn main_0() -> i32 { let mut ptr3: *mut i32 = (&mut (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -236,7 +263,9 @@ unsafe fn main_0() -> i32 { let mut vptr: i32 = (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -244,7 +273,9 @@ unsafe fn main_0() -> i32 { let mut pref: *mut i32 = (unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -252,7 +283,9 @@ unsafe fn main_0() -> i32 { (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -262,21 +295,33 @@ unsafe fn main_0() -> i32 { ((((*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { + X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) + })), + ) })) .v as *mut i32), ) })) + (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { + X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) + })), + ) })) .v, ) }))) + (unsafe { foo_0( (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { + X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) + })), + ) })) .v, ) diff --git a/tests/unit/out/unsafe/concepts.rs b/tests/unit/out/unsafe/concepts.rs index 23116f6ce1..2423f931ca 100644 --- a/tests/unit/out/unsafe/concepts.rs +++ b/tests/unit/out/unsafe/concepts.rs @@ -24,7 +24,7 @@ const _: () = assert!( )] pub struct Sized {} impl Sized { - pub unsafe fn size(&mut self) -> i32 { + pub unsafe fn size(this: *mut Self) -> i32 { return 4; } } diff --git a/tests/unit/out/unsafe/constexpr_function.rs b/tests/unit/out/unsafe/constexpr_function.rs index 270760aadd..3e63c0340c 100644 --- a/tests/unit/out/unsafe/constexpr_function.rs +++ b/tests/unit/out/unsafe/constexpr_function.rs @@ -36,12 +36,12 @@ pub struct Flag { pub v: i32, } impl Flag { - pub unsafe fn to_bool(&self) -> bool { - return ((self.v) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).v) != (0)); } } pub unsafe fn use_4(mut f: Flag) -> i32 { - assert!((unsafe { Flag::to_bool(&f,) })); + assert!((unsafe { Flag::to_bool(&raw const f,) })); return f.v; } pub unsafe fn checked_5(mut x: i32) -> i32 { @@ -71,8 +71,8 @@ pub struct P { pub v: i32, } impl P { - pub unsafe fn get(&self) -> i32 { - return self.v; + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).v; } } pub fn main() { @@ -99,7 +99,7 @@ unsafe fn main_0() -> i32 { let mut ptr: *mut i32 = arr.as_mut_ptr(); assert!(!(ptr).is_null()); let mut p: P = P { v: 9 }; - assert!(((unsafe { P::get(&p,) }) == (9))); + assert!(((unsafe { P::get(&raw const p,) }) == (9))); let k: i32 = (unsafe { scaled_2(4) }); assert!(((k) == (4))); let ce: bool = true; diff --git a/tests/unit/out/unsafe/constructor.rs b/tests/unit/out/unsafe/constructor.rs index 060a95a2e0..c90dd9a043 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -25,24 +25,24 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn const_method(&self) -> i32 { - return ((self.v) * (2)); + pub unsafe fn const_method(this: *const Self) -> i32 { + return (((*this).v) * (2)); } - pub unsafe fn mut_method(&mut self) { - self.v += 1; + pub unsafe fn mut_method(this: *mut Self) { + (*this).v += 1; } - pub unsafe fn construct(&mut self, mut init: i32) { - (&raw mut self.v).write(init); - (unsafe { S::mut_method(self) }); + pub unsafe fn construct(this: *mut Self, mut init: i32) { + (&raw mut (*this).v).write(init); + (unsafe { S::mut_method(this) }); (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += - (unsafe { S::const_method(self) }); + (unsafe { S::const_method((this).cast_const()) }); } } impl DestructibleUnsafe for S { - unsafe fn destroy(&mut self) { - (unsafe { S::mut_method(self) }); + unsafe fn destroy(this: *mut Self) { + (unsafe { S::mut_method(this) }); (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += - (unsafe { S::const_method(self) }); + (unsafe { S::const_method((this).cast_const()) }); } } #[repr(C)] @@ -55,19 +55,19 @@ pub struct Point { pub y: i32, } impl Point { - pub unsafe fn construct_2(&mut self, mut x: i32, mut y: i32) { - (&raw mut self.x).write(x); - (&raw mut self.y).write(y); + pub unsafe fn construct_2(this: *mut Self, mut x: i32, mut y: i32) { + (&raw mut (*this).x).write(x); + (&raw mut (*this).y).write(y); } - pub unsafe fn construct_1(&mut self, mut v: i32) { - Point::construct_2(&mut *self, v, ((v) + (1))); - self.y *= 10; + pub unsafe fn construct_1(this: *mut Self, mut v: i32) { + Point::construct_2(this, v, ((v) + (1))); + (*this).y *= 10; } } impl DefaultConstructibleUnsafe for Point { - unsafe fn default_constructor(&mut self) { - Point::construct_1(&mut *self, 4); - self.x += 100; + unsafe fn default_constructor(this: *mut Self) { + Point::construct_1(this, 4); + (*this).x += 100; } } impl Default for Point { @@ -75,7 +75,7 @@ impl Default for Point { unsafe { { let mut __v: Point = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } diff --git a/tests/unit/out/unsafe/container_field_addr.rs b/tests/unit/out/unsafe/container_field_addr.rs index e72489b20c..261c0dc092 100644 --- a/tests/unit/out/unsafe/container_field_addr.rs +++ b/tests/unit/out/unsafe/container_field_addr.rs @@ -24,9 +24,9 @@ pub struct S { pub v: Vec, } impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(&mut self) { - (&raw mut self.tag).write(0_i32); - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).tag).write(0_i32); + (&raw mut (*this).v).write(Vec::new()); } } pub unsafe fn add_0(mut v: *mut Vec, mut k: i32) { @@ -60,7 +60,7 @@ unsafe fn main_0() -> i32 { (unsafe { run_1((&mut local as *mut S)) }); let mut heap: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + DefaultConstructibleUnsafe::default_constructor(__p); __p }; (*heap).tag = 7; diff --git a/tests/unit/out/unsafe/conversion_operator_same_translation.rs b/tests/unit/out/unsafe/conversion_operator_same_translation.rs index 292c0bd955..f6ff700658 100644 --- a/tests/unit/out/unsafe/conversion_operator_same_translation.rs +++ b/tests/unit/out/unsafe/conversion_operator_same_translation.rs @@ -24,11 +24,11 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn to_libcc_char(&self) -> libc::c_char { - return (self.v as libc::c_char); + pub unsafe fn to_libcc_char(this: *const Self) -> libc::c_char { + return ((*this).v as libc::c_char); } - pub unsafe fn to_u8(&self) -> u8 { - return (((self.v) + (1)) as u8); + pub unsafe fn to_u8(this: *const Self) -> u8 { + return ((((*this).v) + (1)) as u8); } } #[repr(C)] @@ -48,11 +48,11 @@ pub struct T { pub v: i32, } impl T { - pub unsafe fn to_i64_1(&self) -> i64 { - return (self.v as i64); + pub unsafe fn to_i64_1(this: *const Self) -> i64 { + return ((*this).v as i64); } - pub unsafe fn to_i64_2(&self) -> i64 { - return (((self.v) + (1)) as i64); + pub unsafe fn to_i64_2(this: *const Self) -> i64 { + return ((((*this).v) + (1)) as i64); } } pub fn main() { @@ -63,17 +63,18 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut s: S = S { v: 65 }; - let mut a: libc::c_char = (unsafe { S::to_libcc_char(&s) }); - let mut b: u8 = (unsafe { S::to_u8(&s) }); + let mut a: libc::c_char = (unsafe { S::to_libcc_char(&raw const s) }); + let mut b: u8 = (unsafe { S::to_u8(&raw const s) }); assert!(((a as i32) == (('A' as libc::c_char) as i32))); assert!(((b as i32) == ((66 as u8) as i32))); assert!( - ((((unsafe { S::to_libcc_char(&s,) }) as i32) + ((unsafe { S::to_u8(&s,) }) as i32)) + ((((unsafe { S::to_libcc_char(&raw const s,) }) as i32) + + ((unsafe { S::to_u8(&raw const s,) }) as i32)) == (131)) ); let mut t: T = T { v: 3 }; - let mut c: i64 = (unsafe { T::to_i64_1(&t) }); - let mut d: i64 = (unsafe { T::to_i64_2(&t) }); + let mut c: i64 = (unsafe { T::to_i64_1(&raw const t) }); + let mut d: i64 = (unsafe { T::to_i64_2(&raw const t) }); assert!(((c) == (3_i64))); assert!(((d) == (4_i64))); return 0; diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 307254d0b7..f4702998d3 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -22,25 +22,25 @@ pub struct Partial { pub keep: i32, } impl Partial { - pub unsafe fn construct(&mut self, mut v: i32, mut keep: i32) { - (&raw mut self.v).write(v); - (&raw mut self.keep).write(keep); + pub unsafe fn construct(this: *mut Self, mut v: i32, mut keep: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).keep).write(keep); } } impl CopyConstructibleUnsafe for Partial { - unsafe fn copy_constructor(&mut self, o: *const Partial) { - (&raw mut self.v).write((*o).v); - (&raw mut self.keep).write((*o).keep); + unsafe fn copy_constructor(this: *mut Self, o: *const Partial) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).keep).write((*o).keep); } } impl CopyAssignableUnsafe for Partial { - unsafe fn copy_assign(&mut self, o: *const Partial) -> *mut Partial { - if (((self as *mut Partial).cast_const()) == (o)) { - return &mut (*(self as *mut Partial)); + unsafe fn copy_assign(this: *mut Self, o: *const Partial) -> *mut Partial { + if (((this).cast_const()) == (o)) { + return &mut (*this); } - self.v = (*o).v; + (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)).prefix_inc(); - return &mut (*(self as *mut Partial)); + return &mut (*this); } } #[repr(C)] @@ -51,18 +51,24 @@ pub struct NonConstAssign { pub mark: i32, } impl NonConstAssign { - pub unsafe fn operator_assign_2(&mut self, o: *mut NonConstAssign) -> *mut NonConstAssign { - self.mark = (((*o).mark) + (1)); - return &mut (*(self as *mut NonConstAssign)); + pub unsafe fn operator_assign_2( + this: *mut Self, + o: *mut NonConstAssign, + ) -> *mut NonConstAssign { + (*this).mark = (((*o).mark) + (1)); + return &mut (*this); } - pub unsafe fn operator_assign_3(&mut self, o: *const NonConstAssign) -> *mut NonConstAssign { - self.mark = (((*o).mark) + (10)); - return &mut (*(self as *mut NonConstAssign)); + pub unsafe fn operator_assign_3( + this: *mut Self, + o: *const NonConstAssign, + ) -> *mut NonConstAssign { + (*this).mark = (((*o).mark) + (10)); + return &mut (*this); } } impl DefaultConstructibleUnsafe for NonConstAssign { - unsafe fn default_constructor(&mut self) { - (&raw mut self.mark).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).mark).write(0); } } impl Default for NonConstAssign { @@ -70,7 +76,7 @@ impl Default for NonConstAssign { unsafe { { let mut __v: NonConstAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -91,14 +97,14 @@ pub struct RefQualified { pub mark: i32, } impl DefaultConstructibleUnsafe for RefQualified { - unsafe fn default_constructor(&mut self) { - (&raw mut self.mark).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).mark).write(0); } } impl CopyAssignableUnsafe for RefQualified { - unsafe fn copy_assign(&mut self, o: *const RefQualified) -> *mut RefQualified { - self.mark = (((*o).mark) + (1)); - return &mut (*(self as *mut RefQualified)); + unsafe fn copy_assign(this: *mut Self, o: *const RefQualified) -> *mut RefQualified { + (*this).mark = (((*o).mark) + (1)); + return &mut (*this); } } impl Default for RefQualified { @@ -106,7 +112,7 @@ impl Default for RefQualified { unsafe { { let mut __v: RefQualified = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -145,13 +151,13 @@ pub struct CopyCounted { pub v: i32, } impl CopyCounted { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl CopyConstructibleUnsafe for CopyCounted { - unsafe fn copy_constructor(&mut self, o: *const CopyCounted) { - (&raw mut self.v).write((*o).v); + unsafe fn copy_constructor(this: *mut Self, o: *const CopyCounted) { + (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); } } @@ -184,16 +190,19 @@ pub struct ExplicitOperatorCall { pub w: Vec, } impl CopyAssignableUnsafe for ExplicitOperatorCall { - unsafe fn copy_assign(&mut self, o: *const ExplicitOperatorCall) -> *mut ExplicitOperatorCall { + unsafe fn copy_assign( + this: *mut Self, + o: *const ExplicitOperatorCall, + ) -> *mut ExplicitOperatorCall { { - self.w.assign_from(&(*o).w); + AssignFromUnsafe::assign_from(&raw mut (*this).w, &(*o).w); }; - return &mut (*(self as *mut ExplicitOperatorCall)); + return &mut (*this); } } impl DefaultConstructibleUnsafe for ExplicitOperatorCall { - unsafe fn default_constructor(&mut self) { - (&raw mut self.w).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).w).write(Vec::new()); } } pub static mut swap_copies_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); @@ -212,34 +221,34 @@ pub struct Swapped { pub v: i32, } impl Swapped { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } - pub unsafe fn copy_assign(&mut self, o: *mut Swapped) -> *mut Swapped { - let mut t: i32 = self.v; - self.v = (*o).v; + pub unsafe fn copy_assign(this: *mut Self, o: *mut Swapped) -> *mut Swapped { + let mut t: i32 = (*this).v; + (*this).v = (*o).v; (*o).v = t; - return &mut (*(self as *mut Swapped)); + return &mut (*this); } } impl CopyConstructibleUnsafe for Swapped { - unsafe fn copy_constructor(&mut self, o: *const Swapped) { - (&raw mut self.v).write((*o).v); + unsafe fn copy_constructor(this: *mut Self, o: *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(&mut self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { object_unsafe!(__o, Swapped, src); - Swapped::copy_assign(&mut *self, &mut __o); - &mut *self + Swapped::copy_assign(this, &raw mut __o); + this } } impl MoveAssignableUnsafe for Swapped { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { object_unsafe!(__o, Swapped, Moved(src)); - Swapped::copy_assign(&mut *self, &mut __o); - &mut *self + Swapped::copy_assign(this, &raw mut __o); + this } } #[repr(C)] @@ -271,25 +280,25 @@ pub struct VoidAssign { pub x: i32, } impl VoidAssign { - pub unsafe fn copy_assign(&mut self, o: *const VoidAssign) { - self.x = (((*o).x) + (5)); + pub unsafe fn copy_assign(this: *mut Self, o: *const VoidAssign) { + (*this).x = (((*o).x) + (5)); } } impl DefaultConstructibleUnsafe for VoidAssign { - unsafe fn default_constructor(&mut self) { - (&raw mut self.x).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).x).write(0); } } impl CopyAssignableUnsafe for VoidAssign { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - VoidAssign::copy_assign(&mut *self, src); - &mut *self + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + VoidAssign::copy_assign(this, src); + this } } impl MoveAssignableUnsafe for VoidAssign { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - VoidAssign::copy_assign(&mut *self, src); - &mut *self + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + VoidAssign::copy_assign(this, src); + this } } impl Default for VoidAssign { @@ -297,7 +306,7 @@ impl Default for VoidAssign { unsafe { { let mut __v: VoidAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -321,8 +330,8 @@ pub struct HoldsVoidAssign { pub v: VoidAssign, } impl DefaultConstructibleUnsafe for HoldsVoidAssign { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.v); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).v); } } pub fn main() { @@ -348,7 +357,7 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3))); (unsafe { let mut _o: Partial = ::zero_init(); - Partial::construct(&mut _o, 9, 900); + Partial::construct(&raw mut _o, 9, 900); assign_unsafe!(a = _o) }); assert!(((a.v) == (9)) && ((a.keep) == (100))); @@ -363,18 +372,18 @@ unsafe fn main_0() -> i32 { let mut h: Holder = Holder { p: { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 4, 40); + Partial::construct(&raw mut __v, 4, 40); __v }, arr: [ { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 5, 50); + Partial::construct(&raw mut __v, 5, 50); __v }, { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 6, 60); + Partial::construct(&raw mut __v, 6, 60); __v }, ], @@ -388,8 +397,8 @@ unsafe fn main_0() -> i32 { object_unsafe!(n1, NonConstAssign); object_unsafe!(n2, NonConstAssign); object_unsafe!(cn, NonConstAssign); - (unsafe { NonConstAssign::operator_assign_2(&mut n1, &mut n) }); - (unsafe { NonConstAssign::operator_assign_3(&mut n2, &cn) }); + (unsafe { NonConstAssign::operator_assign_2(&raw mut n1, &mut n) }); + (unsafe { NonConstAssign::operator_assign_3(&raw mut n2, &cn) }); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); object_unsafe!(r, RefQualified); @@ -399,18 +408,18 @@ unsafe fn main_0() -> i32 { let mut h2: Holder = Holder { p: { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 7, 70); + Partial::construct(&raw mut __v, 7, 70); __v }, arr: [ { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 8, 80); + Partial::construct(&raw mut __v, 8, 80); __v }, { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 9, 90); + Partial::construct(&raw mut __v, 9, 90); __v }, ], @@ -426,18 +435,18 @@ unsafe fn main_0() -> i32 { let mut hc1: HasCopyCounted = HasCopyCounted { c: { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 1); + CopyCounted::construct(&raw mut __v, 1); __v }, arr: [ { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 2); + CopyCounted::construct(&raw mut __v, 2); __v }, { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 3); + CopyCounted::construct(&raw mut __v, 3); __v }, ], @@ -445,18 +454,18 @@ unsafe fn main_0() -> i32 { let mut hc2: HasCopyCounted = HasCopyCounted { c: { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 4); + CopyCounted::construct(&raw mut __v, 4); __v }, arr: [ { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 5); + CopyCounted::construct(&raw mut __v, 5); __v }, { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 6); + CopyCounted::construct(&raw mut __v, 6); __v }, ], @@ -481,8 +490,8 @@ unsafe fn main_0() -> i32 { object_unsafe!(sw2, Swapped(2)); (unsafe { let mut _o: Swapped = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _o, &sw2); - Swapped::copy_assign(&mut sw1, &mut _o) + ConstructFromUnsafe::construct_from(&raw mut _o, &sw2); + Swapped::copy_assign(&raw mut sw1, &mut _o) }); assert!( ((sw1.v) == (2)) @@ -491,14 +500,14 @@ unsafe fn main_0() -> i32 { let mut hs1: HoldsSwapped = HoldsSwapped { s: { let mut __v: Swapped = ::zero_init(); - Swapped::construct(&mut __v, 3); + Swapped::construct(&raw mut __v, 3); __v }, }; let mut hs2: HoldsSwapped = HoldsSwapped { s: { let mut __v: Swapped = ::zero_init(); - Swapped::construct(&mut __v, 4); + Swapped::construct(&raw mut __v, 4); __v }, }; diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 9b07550355..0c83840e9f 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -25,13 +25,13 @@ pub struct Counted { pub v: i32, } impl Counted { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(&mut self, o: *const Counted) { - (&raw mut self.v).write((*o).v); + unsafe fn copy_constructor(this: *mut Self, o: *const Counted) { + (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } @@ -44,16 +44,16 @@ pub struct NonConst { pub mark: i32, } impl NonConst { - pub unsafe fn construct_1(&mut self, o: *mut NonConst) { - (&raw mut self.mark).write((((*o).mark) + (1))); + pub unsafe fn construct_1(this: *mut Self, o: *mut NonConst) { + (&raw mut (*this).mark).write((((*o).mark) + (1))); } - pub unsafe fn construct_2(&mut self, o: *const NonConst) { - (&raw mut self.mark).write((((*o).mark) + (10))); + pub unsafe fn construct_2(this: *mut Self, o: *const NonConst) { + (&raw mut (*this).mark).write((((*o).mark) + (10))); } } impl DefaultConstructibleUnsafe for NonConst { - unsafe fn default_constructor(&mut self) { - (&raw mut self.mark).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).mark).write(0); } } impl Default for NonConst { @@ -61,7 +61,7 @@ impl Default for NonConst { unsafe { { let mut __v: NonConst = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -85,13 +85,13 @@ pub struct Ignored { pub v: i32, } impl Ignored { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl CopyConstructibleUnsafe for Ignored { - unsafe fn copy_constructor(&mut self, _a0: *const Ignored) { - (&raw mut self.v).write(-1_i32); + unsafe fn copy_constructor(this: *mut Self, _a0: *const Ignored) { + (&raw mut (*this).v).write(-1_i32); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } @@ -124,13 +124,13 @@ pub struct Box_int_ { pub val: i32, } impl Box_int_ { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.val).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).val).write(v); } } impl CopyConstructibleUnsafe for Box_int_ { - unsafe fn copy_constructor(&mut self, o: *const Box_int_) { - (&raw mut self.val).write((*o).val); + unsafe fn copy_constructor(this: *mut Self, o: *const Box_int_) { + (&raw mut (*this).val).write((*o).val); } } #[repr(C)] @@ -159,13 +159,13 @@ pub struct OutOfLine { pub v: i32, } impl OutOfLine { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl CopyConstructibleUnsafe for OutOfLine { - unsafe fn copy_constructor(&mut self, o: *const OutOfLine) { - (&raw mut self.v).write((((*o).v) + (100))); + unsafe fn copy_constructor(this: *mut Self, o: *const OutOfLine) { + (&raw mut (*this).v).write((((*o).v) + (100))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } @@ -182,20 +182,20 @@ pub struct Tracked { pub copied_from: i32, } impl DefaultConstructibleUnsafe for Tracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.copied_from).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).copied_from).write(0); } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { - (&raw mut self.copied_from).write(0); + unsafe fn copy_constructor(this: *mut Self, o: *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(&mut self, o: *const Tracked) -> *mut Tracked { + unsafe fn copy_assign(this: *mut Self, o: *const Tracked) -> *mut Tracked { (*(&raw const (*o).copied_from).cast_mut()).prefix_inc(); - return &mut (*(self as *mut Tracked)); + return &mut (*this); } } impl Default for Tracked { @@ -209,9 +209,9 @@ pub unsafe fn touch_1(mut t: *const Tracked) { pub unsafe fn by_value_2(c: *mut Counted) -> i32 { return (*c).v; } -pub unsafe fn make_3(this: *mut Counted, mut v: i32) { +pub unsafe fn make_3(__return: *mut Counted, mut v: i32) { object_unsafe!(c, Counted(v)); - ConstructFromUnsafe::construct_from(&mut *this, &c); + ConstructFromUnsafe::construct_from(__return, &c); return; } #[repr(C)] @@ -220,18 +220,18 @@ pub struct SelfPtr { pub self_: *mut SelfPtr, } impl DefaultConstructibleUnsafe for SelfPtr { - unsafe fn default_constructor(&mut self) { - (&raw mut self.self_).write((self as *mut SelfPtr)); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).self_).write(this); } } impl CopyConstructibleUnsafe for SelfPtr { - unsafe fn copy_constructor(&mut self, _a0: *const SelfPtr) { - (&raw mut self.self_).write((self as *mut SelfPtr)); + unsafe fn copy_constructor(this: *mut Self, _a0: *const SelfPtr) { + (&raw mut (*this).self_).write(this); } } impl MoveConstructibleUnsafe for SelfPtr { - unsafe fn move_constructor(&mut self, _a0: *mut SelfPtr) { - (&raw mut self.self_).write((self as *mut SelfPtr)); + unsafe fn move_constructor(this: *mut Self, _a0: *mut SelfPtr) { + (&raw mut (*this).self_).write(this); } } impl Default for SelfPtr { @@ -239,7 +239,7 @@ impl Default for SelfPtr { unsafe { { let mut __v: SelfPtr = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -266,8 +266,8 @@ pub struct Derived { pub c: Counted, } impl DefaultConstructibleUnsafe for Derived { - unsafe fn default_constructor(&mut self) { - Counted::construct(&mut self.c, 20); + unsafe fn default_constructor(this: *mut Self) { + Counted::construct(&raw mut (*this).c, 20); } } impl Default for Derived { @@ -275,7 +275,7 @@ impl Default for Derived { unsafe { { let mut __v: Derived = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -297,7 +297,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _c: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _c, &a); + ConstructFromUnsafe::construct_from(&raw mut _c, &a); by_value_2(&mut _c) }) == (1)) ); @@ -315,18 +315,18 @@ unsafe fn main_0() -> i32 { let mut hold: Holder = Holder { c: { let mut __v: Counted = ::zero_init(); - Counted::construct(&mut __v, 8); + Counted::construct(&raw mut __v, 8); __v }, arr: [ { let mut __v: Counted = ::zero_init(); - Counted::construct(&mut __v, 9); + Counted::construct(&raw mut __v, 9); __v }, { let mut __v: Counted = ::zero_init(); - Counted::construct(&mut __v, 10); + Counted::construct(&raw mut __v, 10); __v }, ], @@ -348,7 +348,7 @@ unsafe fn main_0() -> i32 { let mut o: Owner = Owner { box_: { let mut __v: Box_int_ = ::zero_init(); - Box_int_::construct(&mut __v, 3); + Box_int_::construct(&raw mut __v, 3); __v }, }; @@ -404,7 +404,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_3: SelfPtr = ::zero_init(); match (({ - DefaultConstructibleUnsafe::default_constructor(&mut __tmp_3); + DefaultConstructibleUnsafe::default_constructor(&raw mut __tmp_3); &mut __tmp_3 } as *mut SelfPtr),) { @@ -425,7 +425,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_5: Counted = ::zero_init(); match (({ - Counted::construct(&mut __tmp_5, 30); + Counted::construct(&raw mut __tmp_5, 30); &mut __tmp_5 } as *mut Counted),) { diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 9c2e761bf4..234e910395 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -41,14 +41,14 @@ pub struct Explicit { pub arr: [i32; 2], } impl Explicit { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.inner).write(Inner { x: ((v) * (10)) }); - (&raw mut self.arr).write([v, ((v) + (1))]); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).inner).write(Inner { x: ((v) * (10)) }); + (&raw mut (*this).arr).write([v, ((v) + (1))]); } } impl DestructibleUnsafe for Explicit { - unsafe fn destroy(&mut self) {} + unsafe fn destroy(this: *mut Self) {} } #[repr(C)] #[derive( @@ -86,21 +86,24 @@ pub struct DefaultCopyUserMove { pub v: i32, } impl DefaultCopyUserMove { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl MoveConstructibleUnsafe for DefaultCopyUserMove { - unsafe fn move_constructor(&mut self, o: *mut DefaultCopyUserMove) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *mut DefaultCopyUserMove) { + (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for DefaultCopyUserMove { - unsafe fn move_assign(&mut self, o: *mut DefaultCopyUserMove) -> *mut DefaultCopyUserMove { - self.v = (*o).v; + unsafe fn move_assign( + this: *mut Self, + o: *mut DefaultCopyUserMove, + ) -> *mut DefaultCopyUserMove { + (*this).v = (*o).v; (*o).v = 0; - return &mut (*(self as *mut DefaultCopyUserMove)); + return &mut (*this); } } #[repr(C)] @@ -119,19 +122,22 @@ pub struct UserCopyDefaultMove { pub v: i32, } impl UserCopyDefaultMove { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl CopyConstructibleUnsafe for UserCopyDefaultMove { - unsafe fn copy_constructor(&mut self, o: *const UserCopyDefaultMove) { - (&raw mut self.v).write((((*o).v) + (100))); + unsafe fn copy_constructor(this: *mut Self, o: *const UserCopyDefaultMove) { + (&raw mut (*this).v).write((((*o).v) + (100))); } } impl CopyAssignableUnsafe for UserCopyDefaultMove { - unsafe fn copy_assign(&mut self, o: *const UserCopyDefaultMove) -> *mut UserCopyDefaultMove { - self.v = (((*o).v) + (100)); - return &mut (*(self as *mut UserCopyDefaultMove)); + unsafe fn copy_assign( + this: *mut Self, + o: *const UserCopyDefaultMove, + ) -> *mut UserCopyDefaultMove { + (*this).v = (((*o).v) + (100)); + return &mut (*this); } } #[repr(C)] @@ -153,14 +159,14 @@ pub struct Buffer { pub arr: [i32; 2], } impl Buffer { - pub unsafe fn construct(&mut self, mut n: i32) { - (&raw mut self.data).write(Vec::from_fn((n as usize), |_| { + pub unsafe fn construct(this: *mut Self, mut n: i32) { + (&raw mut (*this).data).write(Vec::from_fn((n as usize), |_| { copy_constructed_unsafe(&mut n) })); - (&raw mut self.rows).write(Vec::new()); - (&raw mut self.n).write(n); - (&raw mut self.arr).write([n, ((n) + (1))]); - self.rows.push_copied(&mut self.data); + (&raw mut (*this).rows).write(Vec::new()); + (&raw mut (*this).n).write(n); + (&raw mut (*this).arr).write([n, ((n) + (1))]); + (*this).rows.push_copied(&mut (*this).data); } } #[repr(C)] @@ -180,11 +186,11 @@ pub struct Owner { pub p: Option>, } impl DefaultConstructibleUnsafe for Owner { - unsafe fn default_constructor(&mut self) { - (&raw mut self.data).write(Vec::new()); - (&raw mut self.n).write(0_i32); - (&raw mut self.arr).write([0_i32; 2]); - (&raw mut self.p).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).data).write(Vec::new()); + (&raw mut (*this).n).write(0_i32); + (&raw mut (*this).arr).write([0_i32; 2]); + (&raw mut (*this).p).write(None); } } #[repr(C)] @@ -204,8 +210,8 @@ pub struct Copyable { pub data: Vec, } impl DefaultConstructibleUnsafe for Copyable { - unsafe fn default_constructor(&mut self) { - (&raw mut self.data).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).data).write(Vec::new()); } } #[repr(C)] @@ -226,10 +232,10 @@ pub struct Holder { pub p: Option>, } impl Holder { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.inner).write(Inner { x: v }); - Explicit::construct(&mut self.e, v); - (&raw mut self.p).write(None); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).inner).write(Inner { x: v }); + Explicit::construct(&raw mut (*this).e, v); + (&raw mut (*this).p).write(None); } } pub unsafe fn same_0(a: *const Explicit, b: *const Explicit) -> bool { @@ -243,20 +249,20 @@ pub struct SeesThis { pub self_: *mut SeesThis, } impl CopyAssignableUnsafe for SeesThis { - unsafe fn copy_assign(&mut self, _a0: *const SeesThis) -> *mut SeesThis { - self.self_ = (self as *mut SeesThis); - return &mut (*(self as *mut SeesThis)); + unsafe fn copy_assign(this: *mut Self, _a0: *const SeesThis) -> *mut SeesThis { + (*this).self_ = this; + return &mut (*this); } } impl MoveAssignableUnsafe for SeesThis { - unsafe fn move_assign(&mut self, _a0: *mut SeesThis) -> *mut SeesThis { - self.self_ = (self as *mut SeesThis); - return &mut (*(self as *mut SeesThis)); + unsafe fn move_assign(this: *mut Self, _a0: *mut SeesThis) -> *mut SeesThis { + (*this).self_ = this; + return &mut (*this); } } impl DefaultConstructibleUnsafe for SeesThis { - unsafe fn default_constructor(&mut self) { - (&raw mut self.self_).write(std::ptr::null_mut()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).self_).write(std::ptr::null_mut()); } } impl Default for SeesThis { @@ -276,9 +282,9 @@ pub struct HasSeesThis { pub v: Vec, } impl DefaultConstructibleUnsafe for HasSeesThis { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.s); - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).s); + (&raw mut (*this).v).write(Vec::new()); } } #[repr(C)] @@ -288,22 +294,22 @@ pub struct Counted_int_ { pub moves: i32, } impl DefaultConstructibleUnsafe for Counted_int_ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(0_i32); - (&raw mut self.moves).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(0_i32); + (&raw mut (*this).moves).write(0); } } impl MoveConstructibleUnsafe for Counted_int_ { - unsafe fn move_constructor(&mut self, o: *mut Counted_int_) { - (&raw mut self.v).write((*o).v); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *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(&mut self, o: *mut Counted_int_) -> *mut Counted_int_ { - self.v = (*o).v; - self.moves = (((*o).moves) + (1)); - return &mut (*(self as *mut Counted_int_)); + unsafe fn move_assign(this: *mut Self, o: *mut Counted_int_) -> *mut Counted_int_ { + (*this).v = (*o).v; + (*this).moves = (((*o).moves) + (1)); + return &mut (*this); } } impl Default for Counted_int_ { @@ -326,9 +332,9 @@ pub struct HasCounted { pub w: Vec, } impl DefaultConstructibleUnsafe for HasCounted { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.c); - (&raw mut self.w).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).c); + (&raw mut (*this).w).write(Vec::new()); } } #[repr(C)] @@ -341,37 +347,37 @@ pub struct CtorSeesThis { pub id: i32, } impl CtorSeesThis { - pub unsafe fn construct_1(&mut self, mut id: i32) { - DefaultConstructibleUnsafe::default_constructor(&mut *self); - self.id = id; + pub unsafe fn construct_1(this: *mut Self, mut id: i32) { + DefaultConstructibleUnsafe::default_constructor(this); + (*this).id = id; } } impl DefaultConstructibleUnsafe for CtorSeesThis { - unsafe fn default_constructor(&mut self) { - (&raw mut self.self_).write((self as *mut CtorSeesThis)); - (&raw mut self.id).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).self_).write(this); + (&raw mut (*this).id).write(0); } } impl CopyConstructibleUnsafe for CtorSeesThis { - unsafe fn copy_constructor(&mut self, _a0: *const CtorSeesThis) { - (&raw mut self.self_).write((self as *mut CtorSeesThis)); - (&raw mut self.id).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const CtorSeesThis) { + (&raw mut (*this).self_).write(this); + (&raw mut (*this).id).write(0); } } impl MoveConstructibleUnsafe for CtorSeesThis { - unsafe fn move_constructor(&mut self, _a0: *mut CtorSeesThis) { - (&raw mut self.self_).write((self as *mut CtorSeesThis)); - (&raw mut self.id).write(0); + unsafe fn move_constructor(this: *mut Self, _a0: *mut CtorSeesThis) { + (&raw mut (*this).self_).write(this); + (&raw mut (*this).id).write(0); } } impl CopyAssignableUnsafe for CtorSeesThis { - unsafe fn copy_assign(&mut self, _a0: *const CtorSeesThis) -> *mut CtorSeesThis { - return &mut (*(self as *mut CtorSeesThis)); + unsafe fn copy_assign(this: *mut Self, _a0: *const CtorSeesThis) -> *mut CtorSeesThis { + return &mut (*this); } } impl MoveAssignableUnsafe for CtorSeesThis { - unsafe fn move_assign(&mut self, _a0: *mut CtorSeesThis) -> *mut CtorSeesThis { - return &mut (*(self as *mut CtorSeesThis)); + unsafe fn move_assign(this: *mut Self, _a0: *mut CtorSeesThis) -> *mut CtorSeesThis { + return &mut (*this); } } impl Default for CtorSeesThis { @@ -379,7 +385,7 @@ impl Default for CtorSeesThis { unsafe { { let mut __v: CtorSeesThis = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -400,9 +406,9 @@ pub struct HasCtorSeesThis { pub v: Vec, } impl DefaultConstructibleUnsafe for HasCtorSeesThis { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.x); - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + (&raw mut (*this).v).write(Vec::new()); } } #[repr(C)] @@ -415,9 +421,9 @@ pub struct InitsCtorSeesThis { pub y: CtorSeesThis, } impl DefaultConstructibleUnsafe for InitsCtorSeesThis { - unsafe fn default_constructor(&mut self) { - CtorSeesThis::construct_1(&mut self.x, 1); - CtorSeesThis::construct_1(&mut self.y, 2); + unsafe fn default_constructor(this: *mut Self) { + CtorSeesThis::construct_1(&raw mut (*this).x, 1); + CtorSeesThis::construct_1(&raw mut (*this).y, 2); } } impl Default for InitsCtorSeesThis { @@ -425,7 +431,7 @@ impl Default for InitsCtorSeesThis { unsafe { { let mut __v: InitsCtorSeesThis = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -447,21 +453,21 @@ pub struct OutOfLineDefaulted { pub v: i32, } impl OutOfLineDefaulted { - pub unsafe fn construct(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.x); - (&raw mut self.v).write(1); + pub unsafe fn construct(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + (&raw mut (*this).v).write(1); } } impl CopyConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn copy_constructor(&mut self, _a0: *const OutOfLineDefaulted) { - ConstructFromUnsafe::construct_from(&mut self.x, &(*_a0).x); - (&raw mut self.v).write((*_a0).v); + unsafe fn copy_constructor(this: *mut Self, _a0: *const OutOfLineDefaulted) { + ConstructFromUnsafe::construct_from(&raw mut (*this).x, &(*_a0).x); + (&raw mut (*this).v).write((*_a0).v); } } impl DefaultConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { unsafe { - OutOfLineDefaulted::construct(&mut *self); + OutOfLineDefaulted::construct(this); } } } @@ -470,7 +476,7 @@ impl Default for OutOfLineDefaulted { unsafe { { let mut __v: OutOfLineDefaulted = ::zero_init(); - OutOfLineDefaulted::construct(&mut __v); + OutOfLineDefaulted::construct(&raw mut __v); __v } } @@ -485,10 +491,10 @@ pub struct OutOfLineAssign { pub w: Vec, } impl DefaultConstructibleUnsafe for OutOfLineAssign { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.s); - (&raw mut self.v).write(1); - (&raw mut self.w).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).s); + (&raw mut (*this).v).write(1); + (&raw mut (*this).w).write(Vec::new()); } } impl Default for OutOfLineAssign { @@ -503,29 +509,29 @@ impl Default for OutOfLineAssign { } } impl CopyAssignableUnsafe for OutOfLineAssign { - unsafe fn copy_assign(&mut self, _a0: *const OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn copy_assign(this: *mut Self, _a0: *const OutOfLineAssign) -> *mut OutOfLineAssign { (unsafe { let _arg0: *const SeesThis = &(*_a0).s; - assign_unsafe!(self.s = *_arg0) + assign_unsafe!((*this).s = *_arg0) }); - self.v = (*_a0).v; + (*this).v = (*_a0).v; { - self.w.assign_from(&(*_a0).w); + AssignFromUnsafe::assign_from(&raw mut (*this).w, &(*_a0).w); }; - return &mut (*(self as *mut OutOfLineAssign)); + return &mut (*this); } } impl MoveAssignableUnsafe for OutOfLineAssign { - unsafe fn move_assign(&mut self, _a0: *mut OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn move_assign(this: *mut Self, _a0: *mut OutOfLineAssign) -> *mut OutOfLineAssign { (unsafe { let _arg0: *mut SeesThis = &mut (*_a0).s; - assign_unsafe!(self.s = Moved(*_arg0)) + assign_unsafe!((*this).s = Moved(*_arg0)) }); - self.v = (*_a0).v; + (*this).v = (*_a0).v; { - self.w = std::mem::take(&mut (*_a0).w); + (*this).w = std::mem::take(&mut (*_a0).w); }; - return &mut (*(self as *mut OutOfLineAssign)); + return &mut (*this); } } pub fn main() { @@ -538,15 +544,15 @@ unsafe fn main_0() -> i32 { object_unsafe!(a, Explicit(1)); let mut b: Explicit = a.clone(); let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut c: Explicit = a.clone(); let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut d: Explicit = a.clone(); let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!( ((unsafe { same_0(&b, &a,) }) && (unsafe { same_0(&c, &a,) })) @@ -580,7 +586,7 @@ unsafe fn main_0() -> i32 { vec_.push_copied(&mut b); match ((&mut { let mut __v: Explicit = ::zero_init(); - Explicit::construct(&mut __v, 9); + Explicit::construct(&raw mut __v, 9); __v } as *mut Explicit),) { @@ -627,7 +633,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { { let mut __v: Buffer = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut bufs[(0_usize)])); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut bufs[(0_usize)])); __v } }; @@ -771,7 +777,7 @@ unsafe fn main_0() -> i32 { assert!(((i.y.self_) == (&mut i.y as *mut CtorSeesThis)) && ((i.y.id) == (2))); let mut p: *mut CtorSeesThis = { let __p: *mut CtorSeesThis = Box::leak(Box::new(::zero_init())); - CtorSeesThis::construct_1(&mut *__p, 4); + CtorSeesThis::construct_1(__p, 4); __p }; assert!((((*p).self_) == (p)) && (((*p).id) == (4))); diff --git a/tests/unit/out/unsafe/copy_move_deleted.rs b/tests/unit/out/unsafe/copy_move_deleted.rs index 08f7648ccb..d2aebc4c55 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.rs @@ -20,21 +20,21 @@ pub struct NoCopy { pub v: i32, } impl NoCopy { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl MoveConstructibleUnsafe for NoCopy { - unsafe fn move_constructor(&mut self, o: *mut NoCopy) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *mut NoCopy) { + (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for NoCopy { - unsafe fn move_assign(&mut self, o: *mut NoCopy) -> *mut NoCopy { - self.v = (*o).v; + unsafe fn move_assign(this: *mut Self, o: *mut NoCopy) -> *mut NoCopy { + (*this).v = (*o).v; (*o).v = 0; - return &mut (*(self as *mut NoCopy)); + return &mut (*this); } } #[repr(C)] @@ -43,21 +43,21 @@ pub struct PrivateCopy { pub v: i32, } impl DefaultConstructibleUnsafe for PrivateCopy { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(0); } } impl MoveConstructibleUnsafe for PrivateCopy { - unsafe fn move_constructor(&mut self, o: *mut PrivateCopy) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *mut PrivateCopy) { + (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for PrivateCopy { - unsafe fn move_assign(&mut self, o: *mut PrivateCopy) -> *mut PrivateCopy { - self.v = (*o).v; + unsafe fn move_assign(this: *mut Self, o: *mut PrivateCopy) -> *mut PrivateCopy { + (*this).v = (*o).v; (*o).v = 0; - return &mut (*(self as *mut PrivateCopy)); + return &mut (*this); } } impl Default for PrivateCopy { @@ -65,7 +65,7 @@ impl Default for PrivateCopy { unsafe { { let mut __v: PrivateCopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -77,8 +77,8 @@ pub struct Immovable { pub v: i32, } impl DefaultConstructibleUnsafe for Immovable { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(0); } } impl Default for Immovable { @@ -86,7 +86,7 @@ impl Default for Immovable { unsafe { { let mut __v: Immovable = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -120,8 +120,8 @@ pub struct VecHolder { pub items: Vec, } impl DefaultConstructibleUnsafe for VecHolder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.items).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).items).write(Vec::new()); } } pub unsafe fn bump_0(mut p: *mut NoCopy) { @@ -158,7 +158,7 @@ unsafe fn main_0() -> i32 { let mut c: Container = Container { inner: { let mut __v: NoCopy = ::zero_init(); - NoCopy::construct(&mut __v, 6); + NoCopy::construct(&raw mut __v, 6); __v }, tag: 7, @@ -171,12 +171,12 @@ unsafe fn main_0() -> i32 { return 0; } impl CopyAssignableUnsafe for PrivateCopy { - unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, _: *const Self) -> *mut Self { unreachable!("PrivateCopy::copy_assign is never defined") } } impl CopyConstructibleUnsafe for PrivateCopy { - unsafe fn copy_constructor(&mut self, _: *const Self) { + unsafe fn copy_constructor(this: *mut Self, _: *const Self) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/unsafe/default_function_arguments.rs b/tests/unit/out/unsafe/default_function_arguments.rs index 33af2f9951..90b63a8497 100644 --- a/tests/unit/out/unsafe/default_function_arguments.rs +++ b/tests/unit/out/unsafe/default_function_arguments.rs @@ -21,14 +21,14 @@ pub struct Bar { pub v: i32, } impl Bar { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl DefaultConstructibleUnsafe for Bar { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { unsafe { - Bar::construct(&mut *self, 1); + Bar::construct(this, 1); } } } @@ -37,7 +37,7 @@ impl Default for Bar { unsafe { { let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, 1); + Bar::construct(&raw mut __v, 1); __v } } @@ -56,7 +56,7 @@ pub unsafe fn by_ref_5(b: *const Bar) -> i32 { pub static mut global_bar_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, 9); + Bar::construct(&raw mut __v, 9); __v } }); @@ -84,8 +84,8 @@ pub struct Holder_int_ { pub v: i32, } impl Holder_int_ { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } pub fn main() { @@ -116,7 +116,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_0: Bar = ::zero_init(); assert!( (((*{ - Bar::construct(&mut __tmp_0, 2); + Bar::construct(&raw mut __tmp_0, 2); &mut __tmp_0 }) .v) == (2)) @@ -125,17 +125,17 @@ unsafe fn main_0() -> i32 { let mut arr: [Bar; 3] = [ { let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, 1); + Bar::construct(&raw mut __v, 1); __v }, { let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, 1); + Bar::construct(&raw mut __v, 1); __v }, { let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, 1); + Bar::construct(&raw mut __v, 1); __v }, ]; @@ -148,14 +148,14 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _b: Bar = ::zero_init(); - Bar::construct(&mut _b, 7); + Bar::construct(&raw mut _b, 7); by_ref_5(&mut _b) }) == (7)) ); assert!( ((unsafe { let mut _b: Bar = ::zero_init(); - Bar::construct(&mut _b, 3); + Bar::construct(&raw mut _b, 3); by_ref_5(&mut _b) }) == (3)) ); @@ -167,7 +167,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _b: Bar = ::zero_init(); - Bar::construct(&mut _b, 4); + Bar::construct(&raw mut _b, 4); by_global_ref_7(&mut _b) }) == (4)) ); diff --git a/tests/unit/out/unsafe/delete_array_order.rs b/tests/unit/out/unsafe/delete_array_order.rs index d93c32b7e8..37887d77ab 100644 --- a/tests/unit/out/unsafe/delete_array_order.rs +++ b/tests/unit/out/unsafe/delete_array_order.rs @@ -23,12 +23,12 @@ pub struct Element { pub value: i64, } impl DestructibleUnsafe for Element { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (unsafe { libc::printf( c"%ld:%ld ".as_ptr() as *const libc::c_char, - (self.id), - (self.value), + ((*this).id), + ((*this).value), ) }); } @@ -62,7 +62,7 @@ unsafe fn main_0() -> i32 { / ::std::mem::size_of::()) .rev() { - DestructibleUnsafe::destroy(&mut *__p.add(__i)); + DestructibleUnsafe::destroy(__p.add(__i)); } ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( __p, diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index 22b6c1b551..3addd21275 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -21,7 +21,7 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| #[memberwise(copy_assign)] pub struct S {} impl DestructibleUnsafe for S { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).postfix_inc(); } } @@ -112,8 +112,8 @@ pub struct EmptyBody { pub s: S, } impl DestructibleUnsafe for EmptyBody { - unsafe fn destroy(&mut self) { - DestructibleUnsafe::destroy(&mut self.s); + unsafe fn destroy(this: *mut Self) { + DestructibleUnsafe::destroy(&raw mut (*this).s); } } #[repr(C)] @@ -132,7 +132,7 @@ pub struct Templated_char_ { pub v: libc::c_char, } impl DestructibleUnsafe for Templated_char_ { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) .wrapping_add((::std::mem::size_of::() as usize))) as i32; @@ -154,7 +154,7 @@ pub struct Templated_int_ { pub v: i32, } impl DestructibleUnsafe for Templated_int_ { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) .wrapping_add((::std::mem::size_of::() as usize))) as i32; @@ -176,7 +176,7 @@ pub struct Copied { pub v: i32, } impl DestructibleUnsafe for Copied { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).postfix_inc(); } } @@ -199,10 +199,10 @@ pub struct Tagged { pub tag: i32, } impl DestructibleUnsafe for Tagged { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut order_1)) [((*std::cell::LazyCell::force_mut(&mut *&raw mut order_count_2)).postfix_inc()) - as usize] = self.tag; + as usize] = (*this).tag; } } #[repr(C)] @@ -239,64 +239,64 @@ unsafe fn main_0() -> i32 { { let mut s: S = ::default_constructed(); let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (1))); { let mut s: S = ::default_constructed(); let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (2))); { let mut d: Defaulted = ::default_constructed(); let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (3))); { let mut o: Outer = ::default_constructed(); let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (4))); { let mut am: ArrayMember = ::default_constructed(); let _dtor_am = std::mem::DropGuard::new(&raw mut am, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (7))); { let mut e: EmptyBody = ::default_constructed(); let _dtor_e = std::mem::DropGuard::new(&raw mut e, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (8))); { let mut tc: Templated_char_ = ::default_constructed(); let _dtor_tc = std::mem::DropGuard::new(&raw mut tc, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut ti: Templated_int_ = ::default_constructed(); let _dtor_ti = std::mem::DropGuard::new(&raw mut ti, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (13))); { let mut a: Copied = Copied { v: 5 }; let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut b: Copied = a.clone(); let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!(((b.v) == (5))); } @@ -310,7 +310,7 @@ unsafe fn main_0() -> i32 { third: Tagged { tag: 3 }, }; let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut order_count_2)) == (3))); @@ -321,7 +321,7 @@ unsafe fn main_0() -> i32 { { let mut cs: S = ::default_constructed(); let _dtor_cs = std::mem::DropGuard::new(&raw mut cs, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == ((before) + (1)))); diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index 55b96ce8cf..985751c001 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -24,9 +24,9 @@ pub struct S { pub v: i32, } impl DestructibleUnsafe for S { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)).postfix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = self.v; + (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = (*this).v; } } pub unsafe fn by_value_2(s: *mut S) -> i32 { @@ -51,11 +51,11 @@ pub struct Holder { pub v: i32, } impl Holder { - pub unsafe fn construct(&mut self, s: *mut S) { - (&raw mut self.v).write((*s).v); + pub unsafe fn construct(this: *mut Self, s: *mut S) { + (&raw mut (*this).v).write((*s).v); } - pub unsafe fn add(&self, s: *mut S) -> i32 { - return ((self.v) + ((*s).v)); + pub unsafe fn add(this: *const Self, s: *mut S) -> i32 { + return (((*this).v) + ((*s).v)); } } pub fn main() { @@ -68,7 +68,7 @@ unsafe fn main_0() -> i32 { { let mut s: S = S { v: 1 }; let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!( ((unsafe { @@ -117,7 +117,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _s: S = S { v: 4 }; - Holder::add(&h, &mut _s) + Holder::add(&raw const h, &mut _s) }) == (7)) ); assert!( diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index b07f4a8914..b1f69ed8dc 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -24,14 +24,14 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn get(&self) -> i32 { - return self.v; + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).v; } } impl DestructibleUnsafe for S { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)).postfix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = self.v; + (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = (*this).v; } } #[repr(C)] @@ -53,12 +53,12 @@ pub struct Outer { pub inner: S, pub w: i32, } -pub unsafe fn make_2(this: *mut S, mut v: i32) { - this.write(S { v: v }); +pub unsafe fn make_2(__return: *mut S, mut v: i32) { + __return.write(S { v: v }); return; } -pub unsafe fn make_outer_3(this: *mut Outer) { - this.write(Outer { +pub unsafe fn make_outer_3(__return: *mut Outer) { + __return.write(Outer { inner: S { v: 7 }, w: 8, }); @@ -80,7 +80,7 @@ pub fn main() { unsafe fn main_0() -> i32 { { let mut __v: S = ::zero_init(); - (unsafe { make_2(&mut __v, 1) }); + (unsafe { make_2(&raw mut __v, 1) }); }; assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) @@ -89,7 +89,7 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; &({ let mut __v: S = ::zero_init(); - (unsafe { make_2(&mut __v, 2) }); + (unsafe { make_2(&raw mut __v, 2) }); }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) @@ -99,7 +99,7 @@ unsafe fn main_0() -> i32 { let mut x: i32 = { let mut __tmp_0: S = ::zero_init(); (*{ - (unsafe { make_2(&mut __tmp_0, 3) }); + (unsafe { make_2(&raw mut __tmp_0, 3) }); &mut __tmp_0 }) .v @@ -114,7 +114,7 @@ unsafe fn main_0() -> i32 { x = (unsafe { S::get( &(*{ - (unsafe { make_2(&mut __tmp_1, 4) }); + (unsafe { make_2(&raw mut __tmp_1, 4) }); &mut __tmp_1 }), ) @@ -128,7 +128,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_2: Outer = ::zero_init(); x = (*{ - (unsafe { make_outer_3(&mut __tmp_2) }); + (unsafe { make_outer_3(&raw mut __tmp_2) }); &mut __tmp_2 }) .inner @@ -144,7 +144,7 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; x = (unsafe { let mut _s: S = ::zero_init(); - (unsafe { make_2(&mut _s, 6) }); + (unsafe { make_2(&raw mut _s, 6) }); use_4(&mut _s) }); assert!( @@ -164,7 +164,7 @@ unsafe fn main_0() -> i32 { x = (if ((x) == (3)) { { let mut __v: S = ::zero_init(); - (unsafe { make_2(&mut __v, 9) }); + (unsafe { make_2(&raw mut __v, 9) }); __v } } else { @@ -178,7 +178,7 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { let mut __tmp_3: S = ::zero_init(); - (unsafe { make_2(&mut __tmp_3, 11) }); + (unsafe { make_2(&raw mut __tmp_3, 11) }); let r: *const S = &mut __tmp_3; assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (0)) @@ -193,11 +193,11 @@ unsafe fn main_0() -> i32 { { let mut s: S = S { v: 12 }; let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); (unsafe { let mut _arg0: S = ::zero_init(); - (unsafe { make_2(&mut _arg0, 13) }); + (unsafe { make_2(&raw mut _arg0, 13) }); assign_unsafe!(s = _arg0) }); assert!( diff --git a/tests/unit/out/unsafe/doubly_linked_list.rs b/tests/unit/out/unsafe/doubly_linked_list.rs index dc47af772b..3a382f5f2d 100644 --- a/tests/unit/out/unsafe/doubly_linked_list.rs +++ b/tests/unit/out/unsafe/doubly_linked_list.rs @@ -23,11 +23,11 @@ pub struct Node { pub prev: *mut Node, } impl Node { - pub unsafe fn SetNext(&mut self, mut n: *mut Node) { - self.next = n; + pub unsafe fn SetNext(this: *mut Self, mut n: *mut Node) { + (*this).next = n; } - pub unsafe fn SetPrev(&mut self, mut p: *mut Node) { - self.prev = p; + pub unsafe fn SetPrev(this: *mut Self, mut p: *mut Node) { + (*this).prev = p; } } pub unsafe fn Find_0(mut head: *mut Node, mut idx: i32) -> *mut Node { @@ -61,8 +61,8 @@ pub unsafe fn Append_2(head: *mut Node, new_node: *mut Node) { 'loop_: while !(((*curr).next).is_null()) { curr = (*curr).next; } - (unsafe { Node::SetNext(&mut (*curr), (new_node)) }); - (unsafe { Node::SetPrev(&mut (*new_node), curr) }); + (unsafe { Node::SetNext(&raw mut (*curr), (new_node)) }); + (unsafe { Node::SetPrev(&raw mut (*new_node), curr) }); } pub unsafe fn Delete_3(mut head: *mut Node, mut val: i32) -> *mut Node { let mut curr: *mut Node = head; diff --git a/tests/unit/out/unsafe/enum_underlying_type.rs b/tests/unit/out/unsafe/enum_underlying_type.rs index 55f7fe3ba5..1b958a6d17 100644 --- a/tests/unit/out/unsafe/enum_underlying_type.rs +++ b/tests/unit/out/unsafe/enum_underlying_type.rs @@ -31,8 +31,8 @@ pub struct HoldsEmpty { pub e: Empty, } impl DefaultConstructibleUnsafe for HoldsEmpty { - unsafe fn default_constructor(&mut self) { - (&raw mut self.e).write(false); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).e).write(false); } } impl Default for HoldsEmpty { diff --git a/tests/unit/out/unsafe/exprs.rs b/tests/unit/out/unsafe/exprs.rs index 496aac9ce2..4608f32b8e 100644 --- a/tests/unit/out/unsafe/exprs.rs +++ b/tests/unit/out/unsafe/exprs.rs @@ -36,11 +36,11 @@ pub struct Y { pub p: *mut X, } impl Y { - pub unsafe fn foo(&mut self) -> *mut X { - return &mut self.x; + pub unsafe fn foo(this: *mut Self) -> *mut X { + return &mut (*this).x; } - pub unsafe fn ptr(&mut self) -> *mut X { - return (&mut self.x as *mut X); + pub unsafe fn ptr(this: *mut Self) -> *mut X { + return (&mut (*this).x as *mut X); } } pub fn main() { @@ -76,12 +76,12 @@ unsafe fn main_0() -> i32 { p: (&mut x as *mut X), }; y.x.x = 5; - (*(unsafe { Y::foo(&mut y) })).x = 1; + (*(unsafe { Y::foo(&raw mut y) })).x = 1; (*y.p).x = 10; let mut p3: *mut Y = (&mut y as *mut Y); (*(*p3).p).x = 100; - (*(unsafe { Y::ptr(&mut y) })).x = 1; - (*(unsafe { Y::ptr(&mut y) })).x = 50; + (*(unsafe { Y::ptr(&raw mut y) })).x = 1; + (*(unsafe { Y::ptr(&raw mut y) })).x = 50; assert!(((x.x) == (100))); return 0; } diff --git a/tests/unit/out/unsafe/field_method_receiver.rs b/tests/unit/out/unsafe/field_method_receiver.rs index aa79f7d35d..d5c643bb92 100644 --- a/tests/unit/out/unsafe/field_method_receiver.rs +++ b/tests/unit/out/unsafe/field_method_receiver.rs @@ -21,17 +21,17 @@ pub struct Counter { pub n: i32, } impl Counter { - pub unsafe fn get(&self) -> i32 { - return self.n; + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).n; } - pub unsafe fn add(&mut self, mut k: i32) { - self.n += k; + pub unsafe fn add(this: *mut Self, mut k: i32) { + (*this).n += k; } - pub unsafe fn self_(&mut self) -> *mut Counter { - return (self as *mut Counter); + pub unsafe fn self_(this: *mut Self) -> *mut Counter { + return this; } - pub unsafe fn take(&mut self, mut other: *mut Counter) { - self.n += (*other).n; + pub unsafe fn take(this: *mut Self, mut other: *mut Counter) { + (*this).n += (*other).n; (*other).n = 0; } } @@ -55,45 +55,45 @@ pub struct S { pub v: Vec, } impl S { - pub unsafe fn bump(&mut self) { + pub unsafe fn bump(this: *mut Self) { (unsafe { - let _k: i32 = self.tag; - Counter::add(&mut self.c, _k) + let _k: i32 = (*this).tag; + Counter::add(&raw mut (*this).c, _k) }); } } impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(&mut self) { - (&raw mut self.tag).write(0_i32); - (&raw mut self.c).write(::default()); - (&raw mut self.arr).write([::default(); 2]); - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).tag).write(0_i32); + (&raw mut (*this).c).write(::default()); + (&raw mut (*this).arr).write([::default(); 2]); + (&raw mut (*this).v).write(Vec::new()); } } pub unsafe fn run_0(mut o: *mut S) { - (unsafe { Counter::add(&mut (*o).c, 2) }); - assert!(((unsafe { Counter::get(&(*o).c,) }) == (2))); - (unsafe { Counter::add(&mut (*o).arr[(1) as usize], 5) }); - assert!(((unsafe { Counter::get(&(*o).arr[(1) as usize],) }) == (5))); - (unsafe { Counter::add(&mut (*(unsafe { Counter::self_(&mut (*o).c) })), 1) }); - assert!(((unsafe { Counter::get(&(*o).c,) }) == (3))); - assert!(((unsafe { Counter::self_(&mut (*o).c,) }) == (&mut (*o).c as *mut Counter))); + (unsafe { Counter::add(&raw mut (*o).c, 2) }); + assert!(((unsafe { Counter::get(&raw const (*o).c,) }) == (2))); + (unsafe { Counter::add(&raw mut (*o).arr[(1) as usize], 5) }); + assert!(((unsafe { Counter::get(&raw const (*o).arr[(1) as usize],) }) == (5))); + (unsafe { Counter::add(&raw mut (*(unsafe { Counter::self_(&raw mut (*o).c) })), 1) }); + assert!(((unsafe { Counter::get(&raw const (*o).c,) }) == (3))); + assert!(((unsafe { Counter::self_(&raw mut (*o).c,) }) == (&mut (*o).c as *mut Counter))); (unsafe { let _other: *mut Counter = (&mut (*o).arr[(1) as usize] as *mut Counter); - Counter::take(&mut (*o).arr[(0) as usize], _other) + Counter::take(&raw mut (*o).arr[(0) as usize], _other) }); assert!( - ((unsafe { Counter::get(&(*o).arr[(0) as usize],) }) == (5)) - && ((unsafe { Counter::get(&(*o).arr[(1) as usize],) }) == (0)) + ((unsafe { Counter::get(&raw const (*o).arr[(0) as usize],) }) == (5)) + && ((unsafe { Counter::get(&raw const (*o).arr[(1) as usize],) }) == (0)) ); (unsafe { let _other: *mut Counter = (&mut (*o).c as *mut Counter); - Counter::take(&mut (*o).c, _other) + Counter::take(&raw mut (*o).c, _other) }); - assert!(((unsafe { Counter::get(&(*o).c,) }) == (0))); - (unsafe { S::bump(&mut (*o)) }); - assert!(((unsafe { Counter::get(&(*o).c,) }) == (1))); - match ((&mut (unsafe { Counter::get(&(*o).c) }) as *mut i32),) { + assert!(((unsafe { Counter::get(&raw const (*o).c,) }) == (0))); + (unsafe { S::bump(&raw mut (*o)) }); + assert!(((unsafe { Counter::get(&raw const (*o).c,) }) == (1))); + match ((&mut (unsafe { Counter::get(&raw const (*o).c) }) as *mut i32),) { (__tmp_0,) => (*o).v.push_moved(__tmp_0), }; assert!((((*o).v.len()) == (1_usize)) && (((&mut (*o)).v[(0_usize)]) == (1))); diff --git a/tests/unit/out/unsafe/field_pointers.rs b/tests/unit/out/unsafe/field_pointers.rs index c2188bddb9..c913579ed6 100644 --- a/tests/unit/out/unsafe/field_pointers.rs +++ b/tests/unit/out/unsafe/field_pointers.rs @@ -58,27 +58,27 @@ pub struct Outer { pub buf: [i32; 4], } impl Outer { - pub unsafe fn next(&mut self) -> i32 { - return self.buf[(self.x.postfix_inc()) as usize]; + pub unsafe fn next(this: *mut Self) -> i32 { + return (*this).buf[((*this).x.postfix_inc()) as usize]; } - pub unsafe fn sum(&self) -> i32 { - return ((self.x) + (self.inner.a)); + pub unsafe fn sum(this: *const Self) -> i32 { + return (((*this).x) + ((*this).inner.a)); } - pub unsafe fn push(&mut self, mut k: i32) { + pub unsafe fn push(this: *mut Self, mut k: i32) { { - let mut __tmp_0: i32 = ((k) + (self.x)); - self.v.push_moved(&mut __tmp_0) + let mut __tmp_0: i32 = ((k) + ((*this).x)); + (*this).v.push_moved(&mut __tmp_0) }; } } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.x).write(0_i32); - (&raw mut self.inner).write(::default()); - (&raw mut self.items).write([::default(); 3]); - (&raw mut self.v).write(Vec::new()); - (&raw mut self.cursor).write(std::ptr::null_mut()); - (&raw mut self.buf).write([0_i32; 4]); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).x).write(0_i32); + (&raw mut (*this).inner).write(::default()); + (&raw mut (*this).items).write([::default(); 3]); + (&raw mut (*this).v).write(Vec::new()); + (&raw mut (*this).cursor).write(std::ptr::null_mut()); + (&raw mut (*this).buf).write([0_i32; 4]); } } pub unsafe fn set_0(mut p: *mut i32, mut value: i32) { @@ -129,16 +129,16 @@ unsafe fn main_0() -> i32 { ((o.buf[(1) as usize]) == (6)) && ((o.cursor) == (&mut o.buf[(2) as usize] as *mut i32)) ); o.x = 0; - let mut first: i32 = (unsafe { Outer::next(&mut o) }); + let mut first: i32 = (unsafe { Outer::next(&raw mut o) }); assert!(((first) == (0)) && ((o.x) == (1))); o.x = ((o.inner.a) + (unsafe { bump_1((&mut o as *mut Outer)) })); assert!(((o.x) == (4))); (unsafe { let _k: i32 = o.inner.a; - Outer::push(&mut o, _k) + Outer::push(&raw mut o, _k) }); assert!(((o.v.len()) == (1_usize)) && ((o.v[(0_usize)]) == (7))); - assert!(((unsafe { Outer::sum(&o,) }) == (7))); + assert!(((unsafe { Outer::sum(&raw const o,) }) == (7))); let mut y: i32 = 0; { let mut __tmp_1 = { ((&mut o.items[(2) as usize].a as *mut i32) as *mut ::libc::c_void) }; diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index 35b7cf60a8..62eb6c3e8c 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -21,8 +21,8 @@ pub struct P { pub x: i32, } impl P { - pub unsafe fn operator_eq(&self, o: *const P) -> bool { - return ((self.x) == ((*o).x)); + pub unsafe fn operator_eq(this: *const Self, o: *const P) -> bool { + return (((*this).x) == ((*o).x)); } } impl std::cmp::PartialEq for P { diff --git a/tests/unit/out/unsafe/fn_ptr.rs b/tests/unit/out/unsafe/fn_ptr.rs index f0bcf58aae..33631eaf0e 100644 --- a/tests/unit/out/unsafe/fn_ptr.rs +++ b/tests/unit/out/unsafe/fn_ptr.rs @@ -48,8 +48,8 @@ pub struct HashHolder_unsigned_long__ptr__bool__ { pub h: Option u64>, } impl HashHolder_unsigned_long__ptr__bool__ { - pub unsafe fn construct(&mut self, h: *const Option u64>) { - (&raw mut self.h).write((*h)); + pub unsafe fn construct(this: *mut Self, h: *const Option u64>) { + (&raw mut (*this).h).write((*h)); } } pub static mut total_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index 129df4dff2..02770b369d 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -59,25 +59,28 @@ pub struct MoveOnly { pub data_: i32, } impl MoveOnly { - pub unsafe fn construct(&mut self, mut data: i32) { - (&raw mut self.data_).write(data); + pub unsafe fn construct(this: *mut Self, mut data: i32) { + (&raw mut (*this).data_).write(data); } - pub unsafe fn get(&self) -> i32 { - return self.data_; + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).data_; } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(&mut self, x: *mut MoveOnly) { - (&raw mut self.data_).write((*x).data_); + unsafe fn move_constructor(this: *mut Self, x: *mut MoveOnly) { + (&raw mut (*this).data_).write((*x).data_); (*x).data_ = 0; } } -pub unsafe fn make_move_only_2(this: *mut MoveOnly) { - MoveOnly::construct(&mut *this, 4); +pub unsafe fn make_move_only_2(__return: *mut MoveOnly) { + MoveOnly::construct(__return, 4); return; } -pub unsafe fn scale_move_only_3(this: *mut MoveOnly, x: *mut MoveOnly) { - MoveOnly::construct(&mut *this, ((unsafe { MoveOnly::get(&(*x)) }) * (10))); +pub unsafe fn scale_move_only_3(__return: *mut MoveOnly, x: *mut MoveOnly) { + MoveOnly::construct( + __return, + ((unsafe { MoveOnly::get(&raw const (*x)) }) * (10)), + ); return; } pub fn main() { @@ -113,15 +116,15 @@ unsafe fn main_0() -> i32 { assert!(((h1.cb) == (h2.cb))); let mut mk: Option = Some(make_move_only_2); object_unsafe!(m, MoveOnly, |m| (unsafe { (mk).unwrap()(m,) })); - assert!(((unsafe { MoveOnly::get(&m,) }) == (4))); + assert!(((unsafe { MoveOnly::get(&raw const m,) }) == (4))); let mut sc: Option = Some(scale_move_only_3); object_unsafe!(n, MoveOnly, |n| (unsafe { let mut _arg0: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _arg0, Moved(&mut m)); + ConstructFromUnsafe::construct_from(&raw mut _arg0, Moved(&mut m)); (sc).unwrap()(n, &mut _arg0) })); - assert!(((unsafe { MoveOnly::get(&n,) }) == (40))); - assert!(((unsafe { MoveOnly::get(&m,) }) == (0))); + assert!(((unsafe { MoveOnly::get(&raw const n,) }) == (40))); + assert!(((unsafe { MoveOnly::get(&raw const m,) }) == (0))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/fn_ref.rs b/tests/unit/out/unsafe/fn_ref.rs index 85484ae166..0ecb990a2e 100644 --- a/tests/unit/out/unsafe/fn_ref.rs +++ b/tests/unit/out/unsafe/fn_ref.rs @@ -36,8 +36,8 @@ pub struct Holder { pub f: Option i32>, } impl Holder { - pub unsafe fn run(&self, mut x: i32) -> i32 { - return (unsafe { (self.f).unwrap()(x) }); + pub unsafe fn run(this: *const Self, mut x: i32) -> i32 { + return (unsafe { ((*this).f).unwrap()(x) }); } } pub fn main() { @@ -55,7 +55,7 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { call_deduced_3(Some(twice_1), 7,) }) == (14))); assert!(((unsafe { call_forwarded_4(Some(square_0), 6,) }) == (36))); let mut h: Holder = Holder { f: Some(twice_1) }; - assert!(((unsafe { Holder::run(&h, 8,) }) == (16))); + assert!(((unsafe { Holder::run(&raw const h, 8,) }) == (16))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/for_body_destructor.rs b/tests/unit/out/unsafe/for_body_destructor.rs index 9f321e61b1..f1fb22888d 100644 --- a/tests/unit/out/unsafe/for_body_destructor.rs +++ b/tests/unit/out/unsafe/for_body_destructor.rs @@ -22,13 +22,13 @@ pub struct Guard { pub digit: i32, } impl Guard { - pub unsafe fn to_bool(&self) -> bool { - return ((self.digit) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).digit) != (0)); } } impl DestructibleUnsafe for Guard { - unsafe fn destroy(&mut self) { - (unsafe { libc::printf(c"%d ".as_ptr() as *const libc::c_char, (self.digit)) }); + unsafe fn destroy(this: *mut Self) { + (unsafe { libc::printf(c"%d ".as_ptr() as *const libc::c_char, ((*this).digit)) }); } } pub unsafe fn step_0(i: *mut i32) { @@ -49,11 +49,11 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut first: Guard = Guard { digit: 1 }; let _dtor_first = std::mem::DropGuard::new(&raw mut first, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut second: Guard = Guard { digit: 2 }; let _dtor_second = std::mem::DropGuard::new(&raw mut second, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); if ((i) == (0)) { break 'for_body; @@ -69,7 +69,7 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut g: Guard = Guard { digit: 3 }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); break 'loop_; } @@ -83,7 +83,7 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut outer: Guard = Guard { digit: 4 }; let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); { let mut j: i32 = 0; @@ -92,7 +92,7 @@ unsafe fn main_0() -> i32 { let mut inner: Guard = Guard { digit: 5 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); if ((j) == (0)) { break 'for_body; @@ -114,13 +114,13 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut outer: Guard = Guard { digit: 4 }; let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut j: i32 = 0; 'loop_: while ((*j.prefix_inc()) < (3)) { let mut inner: Guard = Guard { digit: 5 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); if ((j) == (1)) { continue 'loop_; @@ -132,7 +132,7 @@ unsafe fn main_0() -> i32 { __do_while = false; let mut inner: Guard = Guard { digit: 6 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); continue 'loop_; } @@ -144,7 +144,7 @@ unsafe fn main_0() -> i32 { let mut value: i32 = (*value); let mut inner: Guard = Guard { digit: value }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); if ((value) == (1)) { continue 'loop_; @@ -162,15 +162,15 @@ unsafe fn main_0() -> i32 { 'loop_: loop { let mut condition: Guard = Guard { digit: i }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); - if !(unsafe { Guard::to_bool(&condition) }) { + if !(unsafe { Guard::to_bool(&raw const condition) }) { break; } 'for_body: { let mut body: Guard = Guard { digit: 4 }; let _dtor_body = std::mem::DropGuard::new(&raw mut body, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); if ((i) == (2)) { break 'for_body; @@ -189,13 +189,13 @@ unsafe fn main_0() -> i32 { { let mut init: Guard = Guard { digit: 5 }; let _dtor_init = std::mem::DropGuard::new(&raw mut init, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); 'loop_: while ((i) < (2)) { 'for_body: { let mut body: Guard = Guard { digit: 6 }; let _dtor_body = std::mem::DropGuard::new(&raw mut body, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } (unsafe { step_0(&mut i) }); @@ -209,7 +209,7 @@ unsafe fn main_0() -> i32 { digit: (*j.prefix_inc()), }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); continue 'loop_; } diff --git a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs index b082ddc614..4cee7d467c 100644 --- a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs @@ -24,9 +24,9 @@ pub struct S { pub a: i32, } impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(Vec::new()); - (&raw mut self.a).write(0_i32); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(Vec::new()); + (&raw mut (*this).a).write(0_i32); } } pub fn main() { diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 28acaf70ac..36855b01cc 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -20,24 +20,24 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *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(&mut self, o: *mut Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } @@ -48,13 +48,13 @@ pub unsafe fn chosen_overload_1(_a0: *mut Tracked) -> Overload { return Overload_kRvalueOverload; } impl Holder { - pub unsafe fn construct_1(&mut self, x: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut self.t, x); + pub unsafe fn construct_1(this: *mut Self, x: *mut Tracked) { + ConstructFromUnsafe::construct_from(&raw mut (*this).t, x); } } impl Holder { - pub unsafe fn construct_2(&mut self, x: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut self.t, Moved(x)); + pub unsafe fn construct_2(this: *mut Self, x: *mut Tracked) { + ConstructFromUnsafe::construct_from(&raw mut (*this).t, Moved(x)); } } #[repr(C)] @@ -84,12 +84,12 @@ pub unsafe fn forward_twice_4(x: *mut Tracked) -> Overload { pub unsafe fn forward_twice_5(x: *mut Tracked) -> Overload { return (unsafe { forward_once_3(x) }); } -pub unsafe fn forward_into_ctor_6(this: *mut Holder, x: *mut Tracked) { - Holder::construct_1(&mut *this, x); +pub unsafe fn forward_into_ctor_6(__return: *mut Holder, x: *mut Tracked) { + Holder::construct_1(__return, x); return; } -pub unsafe fn forward_into_ctor_7(this: *mut Holder, x: *mut Tracked) { - Holder::construct_2(&mut *this, x); +pub unsafe fn forward_into_ctor_7(__return: *mut Holder, x: *mut Tracked) { + Holder::construct_2(__return, x); return; } pub fn main() { @@ -107,7 +107,7 @@ unsafe fn main_0() -> i32 { assert!( (((unsafe { let mut _x: Tracked = ::zero_init(); - Tracked::construct(&mut _x, 8); + Tracked::construct(&raw mut _x, 8); forward_once_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -120,7 +120,7 @@ unsafe fn main_0() -> i32 { assert!( (((unsafe { let mut _x: Tracked = ::zero_init(); - Tracked::construct(&mut _x, 10); + Tracked::construct(&raw mut _x, 10); forward_twice_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -135,7 +135,7 @@ unsafe fn main_0() -> i32 { assert!(((kept.v) == (11))); object_unsafe!(from_rvalue, Holder, |from_rvalue| (unsafe { let mut _x: Tracked = ::zero_init(); - Tracked::construct(&mut _x, 12); + Tracked::construct(&raw mut _x, 12); forward_into_ctor_7(from_rvalue, &mut _x) })); assert!(((from_rvalue.t.v) == (12))); diff --git a/tests/unit/out/unsafe/forward_decltype.rs b/tests/unit/out/unsafe/forward_decltype.rs index da2ffa87cd..719d60dd5d 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -20,24 +20,24 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *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(&mut self, o: *mut Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } @@ -78,7 +78,7 @@ unsafe fn main_0() -> i32 { assert!( (((unsafe { let mut _x: Tracked = ::zero_init(); - Tracked::construct(&mut _x, 4); + Tracked::construct(&raw mut _x, 4); forward_by_decltype_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -91,7 +91,7 @@ unsafe fn main_0() -> i32 { assert!( (((unsafe { let mut _x: Tracked = ::zero_init(); - Tracked::construct(&mut _x, 6); + Tracked::construct(&raw mut _x, 6); forward_abbreviated_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -100,7 +100,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&mut _args_1, 8); + Tracked::construct(&raw mut _args_1, 8); forward_abbreviated_pack_6(&mut c, &mut _args_1) }) == ((Overload_kLvalueOverload as i32) + (Overload_kRvalueOverload as i32))) ); diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index bc6566496a..d787f5307c 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -22,24 +22,24 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *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(&mut self, o: *mut Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } @@ -55,8 +55,8 @@ pub unsafe fn chosen_overload_2(_a0: *const i32) -> Overload { pub unsafe fn chosen_overload_3(_a0: *mut i32) -> Overload { return Overload_kIntRvalueOverload; } -pub unsafe fn copy_or_move_into_param_4(this: *mut Tracked, t: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut *this, Moved(t)); +pub unsafe fn copy_or_move_into_param_4(__return: *mut Tracked, t: *mut Tracked) { + ConstructFromUnsafe::construct_from(__return, Moved(t)); return; } pub fn main() { @@ -76,7 +76,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(&mut _t, Moved(&mut b)); + ConstructFromUnsafe::construct_from(&raw mut _t, Moved(&mut b)); copy_or_move_into_param_4(moved, &mut _t) })); assert!(((moved.v) == (6))); @@ -86,7 +86,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(&mut _t, &c); + ConstructFromUnsafe::construct_from(&raw mut _t, &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 85010a2f44..f848da77e0 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -22,24 +22,24 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *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(&mut self, o: *mut Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } @@ -90,9 +90,9 @@ pub unsafe fn forward_pack_7( return digits; } impl Pair { - pub unsafe fn construct(&mut self, x: *mut Tracked, y: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut self.a, x); - ConstructFromUnsafe::construct_from(&mut self.b, Moved(y)); + 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)); } } #[repr(C)] @@ -105,11 +105,11 @@ pub struct Pair { pub b: Tracked, } pub unsafe fn forward_pack_into_ctor_8( - this: *mut Pair, + __return: *mut Pair, args_0: *mut Tracked, args_1: *mut Tracked, ) { - Pair::construct(&mut *this, args_0, args_1); + Pair::construct(__return, args_0, args_1); return; } pub fn main() { @@ -126,7 +126,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _args: Tracked = ::zero_init(); - Tracked::construct(&mut _args, 2); + Tracked::construct(&raw mut _args, 2); forward_pack_6(&mut _args) }) == (Overload_kRvalueOverload as i32)) ); @@ -134,7 +134,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&mut _args_1, 4); + Tracked::construct(&raw mut _args_1, 4); let mut _args_3: i32 = 5; forward_pack_7(&mut a, &mut _args_1, &mut i, &mut _args_3) }) == (1234)) @@ -144,7 +144,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(lhs, Tracked(6)); object_unsafe!(p, Pair, |p| (unsafe { let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&mut _args_1, 7); + Tracked::construct(&raw mut _args_1, 7); forward_pack_into_ctor_8(p, &mut lhs, &mut _args_1) })); assert!(((p.a.v) == (6))); diff --git a/tests/unit/out/unsafe/function_overloading.rs b/tests/unit/out/unsafe/function_overloading.rs index d35fad6066..907ea78ec0 100644 --- a/tests/unit/out/unsafe/function_overloading.rs +++ b/tests/unit/out/unsafe/function_overloading.rs @@ -34,12 +34,12 @@ pub unsafe fn bar_4(x: *mut i32) -> i32 { )] pub struct Foo {} impl Foo { - pub unsafe fn foo_1(&self) {} - pub unsafe fn foo_2(&mut self) {} - pub unsafe fn method_3(&mut self, mut x: i32) {} - pub unsafe fn method_4(&self, mut x: i32) {} - pub unsafe fn method2_5(&self, mut x: i32, mut y: i32) {} - pub unsafe fn method2_6(&self, mut x: f64, mut y: f64) {} + pub unsafe fn foo_1(this: *const Self) {} + pub unsafe fn foo_2(this: *mut Self) {} + pub unsafe fn method_3(this: *mut Self, mut x: i32) {} + pub unsafe fn method_4(this: *const Self, mut x: i32) {} + pub unsafe fn method2_5(this: *const Self, mut x: i32, mut y: i32) {} + pub unsafe fn method2_6(this: *const Self, mut x: f64, mut y: f64) {} } pub unsafe fn func_5(mut x: i32) -> i32 { return 1; @@ -74,10 +74,10 @@ unsafe fn main_0() -> i32 { out += (((bar) + (unsafe { foo_0(0) })) + (unsafe { foo_1((&mut x as *mut i32)) })); let mut foo1: Foo = ::default(); let foo2: Foo = ::default(); - (unsafe { Foo::foo_2(&mut foo1) }); - (unsafe { Foo::method_3(&mut foo1, 1) }); - (unsafe { Foo::foo_1(&foo2) }); - (unsafe { Foo::method_4(&foo2, 2) }); + (unsafe { Foo::foo_2(&raw mut foo1) }); + (unsafe { Foo::method_3(&raw mut foo1, 1) }); + (unsafe { Foo::foo_1(&raw const foo2) }); + (unsafe { Foo::method_4(&raw const foo2, 2) }); assert!(((out) == (13))); return 0; } diff --git a/tests/unit/out/unsafe/global_init_side_effect.rs b/tests/unit/out/unsafe/global_init_side_effect.rs index 8bf88c678d..53c5e4a197 100644 --- a/tests/unit/out/unsafe/global_init_side_effect.rs +++ b/tests/unit/out/unsafe/global_init_side_effect.rs @@ -22,21 +22,21 @@ pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u #[cpp_from(i32, construct, value)] pub struct S {} impl S { - pub unsafe fn construct(&mut self, mut x: i32) { + pub unsafe fn construct(this: *mut Self, mut x: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += x; } } pub static mut a_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: S = ::zero_init(); - S::construct(&mut __v, 1); + S::construct(&raw mut __v, 1); __v } }); pub static mut b_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: S = ::zero_init(); - S::construct(&mut __v, 10); + S::construct(&raw mut __v, 10); __v } }); diff --git a/tests/unit/out/unsafe/global_non_const_init.rs b/tests/unit/out/unsafe/global_non_const_init.rs index 110bdf2dde..667aebda32 100644 --- a/tests/unit/out/unsafe/global_non_const_init.rs +++ b/tests/unit/out/unsafe/global_non_const_init.rs @@ -33,13 +33,13 @@ pub struct Ctor { pub v: i32, } impl Ctor { - pub unsafe fn construct_1(&mut self, mut x: i32) { - (&raw mut self.v).write(x); + pub unsafe fn construct_1(this: *mut Self, mut x: i32) { + (&raw mut (*this).v).write(x); } } impl DefaultConstructibleUnsafe for Ctor { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write((unsafe { next_0() })); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write((unsafe { next_0() })); } } impl Default for Ctor { @@ -47,7 +47,7 @@ impl Default for Ctor { unsafe { { let mut __v: Ctor = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -56,14 +56,14 @@ impl Default for Ctor { pub static mut default_ctor_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } }); pub static mut arg_ctor_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - Ctor::construct_1(&mut __v, 7); + Ctor::construct_1(&raw mut __v, 7); __v } }); @@ -78,7 +78,7 @@ pub static mut str_9: std::cell::LazyCell> = pub static mut inline_member_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - Ctor::construct_1(&mut __v, 5); + Ctor::construct_1(&raw mut __v, 5); __v } }); @@ -105,7 +105,7 @@ static mut once_13: std::cell::LazyCell = static mut local_ctor_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - Ctor::construct_1(&mut __v, 3); + Ctor::construct_1(&raw mut __v, 3); __v } }); @@ -120,8 +120,8 @@ impl Singleton { } } impl DefaultConstructibleUnsafe for Singleton { - unsafe fn default_constructor(&mut self) { - (&raw mut self.hits).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).hits).write(0); } } impl Default for Singleton { @@ -129,7 +129,7 @@ impl Default for Singleton { unsafe { { let mut __v: Singleton = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -138,7 +138,7 @@ impl Default for Singleton { static mut s_15: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Singleton = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } }); diff --git a/tests/unit/out/unsafe/huffman.rs b/tests/unit/out/unsafe/huffman.rs index 7bd66bd8f0..b08a31aac0 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -24,8 +24,8 @@ pub struct MinHeapNode { pub right: *mut MinHeapNode, } impl MinHeapNode { - pub unsafe fn IsLeaf(&self) -> bool { - return ((self.left).is_null()) && ((self.right).is_null()); + pub unsafe fn IsLeaf(this: *const Self) -> bool { + return (((*this).left).is_null()) && (((*this).right).is_null()); } } pub unsafe fn Swap_0(a: *mut MinHeapNode, b: *mut MinHeapNode) { @@ -66,29 +66,33 @@ pub struct MinHeap { pub alloc: Option>, } impl MinHeap { - pub unsafe fn Alloc(&mut self, mut data: libc::c_char, mut freq: i32) -> *mut MinHeapNode { - (*self + pub unsafe fn Alloc( + this: *mut Self, + mut data: libc::c_char, + mut freq: i32, + ) -> *mut MinHeapNode { + (*(*this) .alloc .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut MinHeapNode) - .add((self.next as usize))) = MinHeapNode { + .add(((*this).next as usize))) = MinHeapNode { data: data, freq: freq, left: std::ptr::null_mut(), right: std::ptr::null_mut(), }; - return (&mut (*self + return (&mut (*(*this) .alloc .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut MinHeapNode) - .add((self.next.postfix_inc() as usize))) as *mut MinHeapNode); + .add(((*this).next.postfix_inc() as usize))) as *mut MinHeapNode); } - pub unsafe fn Heapify(&mut self, mut idx: i32) { + pub unsafe fn Heapify(this: *mut Self, mut idx: i32) { let mut smallest: i32 = idx; let mut left: i32 = (((2) * (idx)) + (1)); let mut right: i32 = (((2) * (idx)) + (2)); - if ((left) < (self.size)) - && (((*(*self + if ((left) < ((*this).size)) + && (((*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -96,7 +100,7 @@ impl MinHeap { }) .add((left as usize)))) .freq) - < ((*(*self + < ((*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -107,8 +111,8 @@ impl MinHeap { { smallest = left; } - if ((right) < (self.size)) - && (((*(*self + if ((right) < ((*this).size)) + && (((*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -116,7 +120,7 @@ impl MinHeap { }) .add((right as usize)))) .freq) - < ((*(*self + < ((*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -129,14 +133,14 @@ impl MinHeap { } if ((smallest) != (idx)) { (unsafe { - let _a: *mut MinHeapNode = &mut (*(*self + let _a: *mut MinHeapNode = &mut (*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) .add((smallest as usize)))); - let _b: *mut MinHeapNode = &mut (*(*self + let _b: *mut MinHeapNode = &mut (*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -145,40 +149,40 @@ impl MinHeap { .add((idx as usize)))); Swap_0(_a, _b) }); - (unsafe { MinHeap::Heapify(self, smallest) }); + (unsafe { MinHeap::Heapify(this, smallest) }); } } - pub unsafe fn ExtractMin(&mut self) -> *mut MinHeapNode { - let mut out: *mut MinHeapNode = (*self + pub unsafe fn ExtractMin(this: *mut Self) -> *mut MinHeapNode { + let mut out: *mut MinHeapNode = (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) .add(0_usize)); - self.size.prefix_dec(); - (*self + (*this).size.prefix_dec(); + (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) - .add(0_usize)) = (*self + .add(0_usize)) = (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) - .add((self.size as usize))); - (unsafe { MinHeap::Heapify(self, 0) }); + .add(((*this).size as usize))); + (unsafe { MinHeap::Heapify(this, 0) }); return out; } - pub unsafe fn Insert(&mut self, mut node: *mut MinHeapNode) { - self.size.prefix_inc(); - let mut i: i32 = ((self.size) - (1)); + pub unsafe fn Insert(this: *mut Self, mut node: *mut MinHeapNode) { + (*this).size.prefix_inc(); + let mut i: i32 = (((*this).size) - (1)); 'loop_: while ((i) != (0)) && (((*node).freq) - < ((*(*self + < ((*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -187,13 +191,13 @@ impl MinHeap { .add(((((i) - (1)) / (2)) as usize)))) .freq)) { - (*self + (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) - .add((i as usize))) = (*self + .add((i as usize))) = (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -202,7 +206,7 @@ impl MinHeap { .add(((((i) - (1)) / (2)) as usize))); i = (((i) - (1)) / (2)); } - (*self + (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -211,7 +215,7 @@ impl MinHeap { .add((i as usize))) = node; } pub unsafe fn Build( - &mut self, + this: *mut Self, data: *mut Option>, freq: *mut Option>, mut n: i32, @@ -220,13 +224,13 @@ impl MinHeap { let mut i: i32 = 0; 'loop_: while ((i) < (n)) { 'for_body: { - (*self + (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) - .add((self.size.postfix_inc() as usize))) = (unsafe { + .add(((*this).size.postfix_inc() as usize))) = (unsafe { let _data: libc::c_char = (*(*data) .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut libc::c_char) @@ -235,17 +239,17 @@ impl MinHeap { .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((i as usize))); - MinHeap::Alloc(self, _data, _freq) + MinHeap::Alloc(this, _data, _freq) }); } i.prefix_inc(); } } { - let mut i: i32 = (((self.size) - (2)) / (2)); + let mut i: i32 = ((((*this).size) - (2)) / (2)); 'loop_: while ((i) >= (0)) { 'for_body: { - (unsafe { MinHeap::Heapify(self, i) }); + (unsafe { MinHeap::Heapify(this, i) }); } i.prefix_dec(); } @@ -253,12 +257,12 @@ impl MinHeap { } } impl DefaultConstructibleUnsafe for MinHeap { - unsafe fn default_constructor(&mut self) { - (&raw mut self.size).write(0_i32); - (&raw mut self.capacity).write(0_i32); - (&raw mut self.arr).write(None); - (&raw mut self.next).write(0_i32); - (&raw mut self.alloc).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).size).write(0_i32); + (&raw mut (*this).capacity).write(0_i32); + (&raw mut (*this).arr).write(None); + (&raw mut (*this).next).write(0_i32); + (&raw mut (*this).alloc).write(None); } } pub unsafe fn AllocMinHeap_1(mut capacity: i32) -> Option> { @@ -287,7 +291,7 @@ pub unsafe fn Huffman_2( let mut minHeap: Option> = (unsafe { AllocMinHeap_1(size) }); (unsafe { MinHeap::Build( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), data, @@ -303,21 +307,21 @@ pub unsafe fn Huffman_2( { let mut left: *mut MinHeapNode = (unsafe { MinHeap::ExtractMin( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), ) }); let mut right: *mut MinHeapNode = (unsafe { MinHeap::ExtractMin( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), ) }); let mut top: *mut MinHeapNode = (unsafe { MinHeap::Alloc( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), ('$' as libc::c_char), @@ -328,7 +332,7 @@ pub unsafe fn Huffman_2( (*top).right = right; (unsafe { MinHeap::Insert( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), top, @@ -397,7 +401,7 @@ pub unsafe fn CollectCodes_4( .add((top as usize))) = 1; (unsafe { CollectCodes_4((*root).right, arr, ((top) + (1)), out, next) }); } - if (unsafe { MinHeapNode::IsLeaf(&(*(root).cast_const())) }) { + if (unsafe { MinHeapNode::IsLeaf(&raw const (*(root).cast_const())) }) { (unsafe { CollectCode_3(arr, top, out, next) }); } } @@ -409,7 +413,7 @@ pub unsafe fn HuffmanCodes_5( let mut minHeap: Option> = (unsafe { Huffman_2(data, freq, size) }); let mut root: *mut MinHeapNode = (unsafe { MinHeap::ExtractMin( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), ) diff --git a/tests/unit/out/unsafe/immutable-deref-on-func-call.rs b/tests/unit/out/unsafe/immutable-deref-on-func-call.rs index dfb8ab5645..f3768f61ff 100644 --- a/tests/unit/out/unsafe/immutable-deref-on-func-call.rs +++ b/tests/unit/out/unsafe/immutable-deref-on-func-call.rs @@ -21,7 +21,7 @@ pub struct Item { pub value: i32, } impl Item { - pub unsafe fn foo(&mut self, mut other: *mut Item) { + pub unsafe fn foo(this: *mut Self, mut other: *mut Item) { (*other).value = 10; } } @@ -42,7 +42,7 @@ unsafe fn main_0() -> i32 { (*arr.offset((1) as isize)).value = 2; (unsafe { let _other: *mut Item = (&mut (*arr.offset((1) as isize)) as *mut Item); - Item::foo(&mut (*arr.offset((0) as isize)), _other) + Item::foo(&raw mut (*arr.offset((0) as isize)), _other) }); let mut result: i32 = (((*arr.offset((0) as isize)).value) + ((*arr.offset((1) as isize)).value)); diff --git a/tests/unit/out/unsafe/implicit_autoref.rs b/tests/unit/out/unsafe/implicit_autoref.rs index 9008386eb7..8528b4c6d6 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -23,8 +23,8 @@ pub struct Holder { pub v: Vec, } impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(Vec::new()); } } pub unsafe fn write_through_0(mut p: *mut i32) { diff --git a/tests/unit/out/unsafe/in_class_field_initializer.rs b/tests/unit/out/unsafe/in_class_field_initializer.rs index 81acf09748..8dbb959f6a 100644 --- a/tests/unit/out/unsafe/in_class_field_initializer.rs +++ b/tests/unit/out/unsafe/in_class_field_initializer.rs @@ -13,9 +13,9 @@ pub struct Inner { pub y: i32, } impl DefaultConstructibleUnsafe for Inner { - unsafe fn default_constructor(&mut self) { - (&raw mut self.x).write(3); - (&raw mut self.y).write(4); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).x).write(3); + (&raw mut (*this).y).write(4); } } impl Default for Inner { @@ -32,11 +32,11 @@ pub struct S { pub d: Inner, } impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(&mut self) { - (&raw mut self.a).write(1); - (&raw mut self.b).write((2 as libc::c_char)); - (&raw mut self.c).write(::default()); - DefaultConstructibleUnsafe::default_constructor(&mut self.d); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).a).write(1); + (&raw mut (*this).b).write((2 as libc::c_char)); + (&raw mut (*this).c).write(::default()); + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).d); } } impl Default for S { @@ -66,9 +66,9 @@ pub struct Boxed_int_ { pub tag: i32, } impl Boxed_int_ { - pub unsafe fn construct(&mut self, mut x: i32, mut t: i32) { - (&raw mut self.v).write(x); - (&raw mut self.tag).write(t); + pub unsafe fn construct(this: *mut Self, mut x: i32, mut t: i32) { + (&raw mut (*this).v).write(x); + (&raw mut (*this).tag).write(t); } } impl Default for Boxed_int_ { diff --git a/tests/unit/out/unsafe/init_list.rs b/tests/unit/out/unsafe/init_list.rs index 9d3b585001..ac9d1c1658 100644 --- a/tests/unit/out/unsafe/init_list.rs +++ b/tests/unit/out/unsafe/init_list.rs @@ -28,14 +28,14 @@ pub struct Holder { pub p: Pair, } impl Holder { - pub unsafe fn operator_assign_1(&mut self, o: *mut Pair) -> *mut Holder { - self.p = (*o); - return &mut (*(self as *mut Holder)); + pub unsafe fn operator_assign_1(this: *mut Self, o: *mut Pair) -> *mut Holder { + (*this).p = (*o); + return &mut (*this); } } impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.p).write(Pair { a: 0, b: 0 }); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).p).write(Pair { a: 0, b: 0 }); } } impl Default for Holder { @@ -56,8 +56,8 @@ pub struct Seven { pub v: i32, } impl DefaultConstructibleUnsafe for Seven { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(7); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(7); } } impl Default for Seven { @@ -81,7 +81,7 @@ unsafe fn main_0() -> i32 { (unsafe { f_0(Vec::from([1, 2, 3, 4])) }); let mut p: Pair = Pair { a: 1, b: 2 }; object_unsafe!(h, Holder); - (unsafe { Holder::operator_assign_1(&mut h, &mut p) }); + (unsafe { Holder::operator_assign_1(&raw mut h, &mut p) }); assert!(((h.p.a) == (1)) && ((h.p.b) == (2))); assert!(((unsafe { sum_1(&p,) }) == (3))); let mut sevens: [Seven; 4] = [::default(); 4]; diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index 0b21b79238..47a07f2ea9 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -25,10 +25,10 @@ pub struct Elem { pub coeffs: Vec, } impl DefaultConstructibleUnsafe for Elem { - unsafe fn default_constructor(&mut self) { - (&raw mut self.id).write(0_i32); - (&raw mut self.hist).write([0_i32; 4]); - (&raw mut self.coeffs).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).id).write(0_i32); + (&raw mut (*this).hist).write([0_i32; 4]); + (&raw mut (*this).coeffs).write(Vec::new()); } } #[repr(C)] @@ -51,12 +51,12 @@ pub struct State { pub rows: Vec>, } impl DefaultConstructibleUnsafe for State { - unsafe fn default_constructor(&mut self) { - (&raw mut self.count).write(0_i32); - (&raw mut self.grid).write([[0_i32; 3]; 2]); - (&raw mut self.arr).write(std::array::from_fn::<_, 3, _>(|_| 0_i32)); - (&raw mut self.elems).write(Vec::new()); - (&raw mut self.rows).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).count).write(0_i32); + (&raw mut (*this).grid).write([[0_i32; 3]; 2]); + (&raw mut (*this).arr).write(std::array::from_fn::<_, 3, _>(|_| 0_i32)); + (&raw mut (*this).elems).write(Vec::new()); + (&raw mut (*this).rows).write(Vec::new()); } } impl Default for State { @@ -143,36 +143,36 @@ pub struct Counted { pub v: i32, } impl DefaultConstructibleUnsafe for Counted { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(0); } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(&mut self, o: *const Counted) { - (&raw mut self.v).write((*o).v); + unsafe fn copy_constructor(this: *mut Self, o: *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(&mut self, o: *mut Counted) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *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(&mut self, o: *const Counted) -> *mut Counted { - self.v = (*o).v; + unsafe fn copy_assign(this: *mut Self, o: *const Counted) -> *mut Counted { + (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_assigns_4)).prefix_inc(); - return &mut (*(self as *mut Counted)); + return &mut (*this); } } impl MoveAssignableUnsafe for Counted { - unsafe fn move_assign(&mut self, o: *mut Counted) -> *mut Counted { - self.v = (*o).v; + unsafe fn move_assign(this: *mut Self, o: *mut Counted) -> *mut Counted { + (*this).v = (*o).v; (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_5)).prefix_inc(); - return &mut (*(self as *mut Counted)); + return &mut (*this); } } impl Default for Counted { diff --git a/tests/unit/out/unsafe/kruskal.rs b/tests/unit/out/unsafe/kruskal.rs index 897b47150b..2f887245a5 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.rs @@ -188,17 +188,17 @@ pub struct DisjointSet { pub n: i32, } impl DisjointSet { - pub unsafe fn makeSet(&mut self) { + pub unsafe fn makeSet(this: *mut Self) { { let mut i: i32 = 0; - 'loop_: while ((i) < (self.n)) { + 'loop_: while ((i) < ((*this).n)) { 'for_body: { - (*self + (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((i as usize))) = i; - (*self + (*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) @@ -208,82 +208,82 @@ impl DisjointSet { } } } - pub unsafe fn find(&mut self, mut x: i32) -> i32 { - if ((*self + pub unsafe fn find(this: *mut Self, mut x: i32) -> i32 { + if ((*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((x as usize))) != (x)) { - (*self + (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((x as usize))) = (unsafe { - let _x: i32 = (*self + let _x: i32 = (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((x as usize))); - DisjointSet::find(self, _x) + DisjointSet::find(this, _x) }); } - return (*self + return (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((x as usize))); } - pub unsafe fn merge(&mut self, mut x: i32, mut y: i32) { - let mut xset: i32 = (unsafe { DisjointSet::find(self, x) }); - let mut yset: i32 = (unsafe { DisjointSet::find(self, y) }); + pub unsafe fn merge(this: *mut Self, mut x: i32, mut y: i32) { + let mut xset: i32 = (unsafe { DisjointSet::find(this, x) }); + let mut yset: i32 = (unsafe { DisjointSet::find(this, y) }); if ((xset) == (yset)) { return; } - if ((*self + if ((*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((xset as usize))) - < (*self + < (*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((yset as usize)))) { - (*self + (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((xset as usize))) = yset; - } else if ((*self + } else if ((*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((xset as usize))) - > (*self + > (*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((yset as usize)))) { - (*self + (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((yset as usize))) = xset; } else { - (*self + (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((yset as usize))) = xset; - (*self + (*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((xset as usize))) = ((*self + .add((xset as usize))) = ((*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) @@ -293,10 +293,10 @@ impl DisjointSet { } } impl DefaultConstructibleUnsafe for DisjointSet { - unsafe fn default_constructor(&mut self) { - (&raw mut self.rank).write(None); - (&raw mut self.parent).write(None); - (&raw mut self.n).write(0_i32); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).rank).write(None); + (&raw mut (*this).parent).write(None); + (&raw mut (*this).n).write(0_i32); } } #[repr(C)] @@ -315,10 +315,10 @@ pub struct Graph { pub E: i32, } impl DefaultConstructibleUnsafe for Graph { - unsafe fn default_constructor(&mut self) { - (&raw mut self.edges).write(None); - (&raw mut self.V).write(0_i32); - (&raw mut self.E).write(0_i32); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).edges).write(None); + (&raw mut (*this).V).write(0_i32); + (&raw mut (*this).E).write(0_i32); } } pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { @@ -340,7 +340,7 @@ pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { ), n: (*graph).V, }; - (unsafe { DisjointSet::makeSet(&mut set) }); + (unsafe { DisjointSet::makeSet(&raw mut set) }); let mut total_weight: f64 = 0_f64; { let mut i: i32 = 0; @@ -364,10 +364,10 @@ pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Edge) .add((i as usize))) .weight; - if ((unsafe { DisjointSet::find(&mut set, x) }) - != (unsafe { DisjointSet::find(&mut set, y) })) + if ((unsafe { DisjointSet::find(&raw mut set, x) }) + != (unsafe { DisjointSet::find(&raw mut set, y) })) { - (unsafe { DisjointSet::merge(&mut set, x, y) }); + (unsafe { DisjointSet::merge(&raw mut set, x, y) }); total_weight += w; } } diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index 8e632c6980..9427def813 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -22,8 +22,8 @@ pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { pub f: FnPtr, } impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_34_13__ { - unsafe fn destroy(&mut self) { - (unsafe { self.f.call() }); + unsafe fn destroy(this: *mut Self) { + (unsafe { (*this).f.call() }); } } #[repr(C)] @@ -34,8 +34,8 @@ pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { pub f: FnPtr, } impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_45_13__ { - unsafe fn destroy(&mut self) { - (unsafe { self.f.call() }); + unsafe fn destroy(this: *mut Self) { + (unsafe { (*this).f.call() }); } } #[repr(C)] @@ -52,9 +52,9 @@ pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { pub calls: i32, } impl Holder__lambda_at_lambda_as_field_cpp_39_12__ { - pub unsafe fn call(&mut self, mut x: i32) -> i32 { - self.calls.postfix_inc(); - return (unsafe { self.f.call(x) }); + pub unsafe fn call(this: *mut Self, mut x: i32) -> i32 { + (*this).calls.postfix_inc(); + return (unsafe { (*this).f.call(x) }); } } impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { @@ -86,9 +86,9 @@ pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { pub calls: i32, } impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { - pub unsafe fn call(&mut self, mut x: i32) -> i32 { - self.calls.postfix_inc(); - return (unsafe { self.f.call(x) }); + pub unsafe fn call(this: *mut Self, mut x: i32) -> i32 { + (*this).calls.postfix_inc(); + return (unsafe { (*this).f.call(x) }); } } #[repr(C)] @@ -99,15 +99,18 @@ pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { pub moves: i32, } impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { - pub unsafe fn construct(&mut self, mut f: FnPtr i32>) { - (&raw mut self.f).write(f.copy_from()); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut f: FnPtr i32>) { + (&raw mut (*this).f).write(f.copy_from()); + (&raw mut (*this).moves).write(0); } } impl MoveConstructibleUnsafe for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - unsafe fn move_constructor(&mut self, o: *mut Moving__lambda_at_lambda_as_field_cpp_64_12__) { - (&raw mut self.f).write((*o).f.move_from()); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor( + this: *mut Self, + o: *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))); } } impl Default for Moving__lambda_at_lambda_as_field_cpp_64_12__ { @@ -151,7 +154,7 @@ unsafe fn main_0() -> i32 { }), }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_2)) == (0))); } @@ -165,7 +168,9 @@ unsafe fn main_0() -> i32 { }), calls: 0, }; - assert!(((unsafe { Holder__lambda_at_lambda_as_field_cpp_39_12__::call(&mut n, 2,) }) == (3))); + assert!( + ((unsafe { Holder__lambda_at_lambda_as_field_cpp_39_12__::call(&raw mut n, 2,) }) == (3)) + ); assert!(((n.calls) == (1))); let mut cleaned: i32 = 0; { @@ -181,7 +186,7 @@ unsafe fn main_0() -> i32 { ), }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!(((cleaned) == (0))); } @@ -200,8 +205,12 @@ unsafe fn main_0() -> i32 { calls: 0, }; factor = 100; - assert!(((unsafe { Holder__lambda_at_lambda_as_field_cpp_51_12__::call(&mut h, 2,) }) == (6))); - assert!(((unsafe { Holder__lambda_at_lambda_as_field_cpp_51_12__::call(&mut h, 5,) }) == (15))); + assert!( + ((unsafe { Holder__lambda_at_lambda_as_field_cpp_51_12__::call(&raw mut h, 2,) }) == (6)) + ); + assert!( + ((unsafe { Holder__lambda_at_lambda_as_field_cpp_51_12__::call(&raw mut h, 5,) }) == (15)) + ); assert!(((h.calls) == (2))); let mut w: FnPtr i32> = (unsafe { wrap_0(lambda_unsafe!( diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index ae9d514bae..9fdb98268b 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -13,21 +13,21 @@ pub struct Counted { pub moves: i32, } impl DefaultConstructibleUnsafe for Counted { - unsafe fn default_constructor(&mut self) { - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(&mut self, o: *const Counted) { - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *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(&mut self, o: *mut Counted) { - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Counted) { + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); } } impl Default for Counted { @@ -35,7 +35,7 @@ impl Default for Counted { unsafe { { let mut __v: Counted = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -46,16 +46,16 @@ pub static mut drops_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u #[derive(FnPtrArg, ZeroInitializationUnsafe)] pub struct Dropped {} impl DefaultConstructibleUnsafe for Dropped { - unsafe fn default_constructor(&mut self) {} + unsafe fn default_constructor(this: *mut Self) {} } impl CopyConstructibleUnsafe for Dropped { - unsafe fn copy_constructor(&mut self, _a0: *const Dropped) {} + unsafe fn copy_constructor(this: *mut Self, _a0: *const Dropped) {} } impl MoveConstructibleUnsafe for Dropped { - unsafe fn move_constructor(&mut self, _a0: *mut Dropped) {} + unsafe fn move_constructor(this: *mut Self, _a0: *mut Dropped) {} } impl DestructibleUnsafe for Dropped { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)).postfix_inc(); } } @@ -71,7 +71,7 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &c); + ConstructFromUnsafe::construct_from(&raw mut __v, &c); __v }; }, @@ -93,16 +93,16 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &c); + ConstructFromUnsafe::construct_from(&raw mut __v, &c); __v }; }, - |this: *mut Counted| { - ConstructFromUnsafe::construct_from(&mut *this, &c); + |__return: *mut Counted| { + ConstructFromUnsafe::construct_from(__return, &c); return; } ) - .call(&mut __tmp_0) + .call(&raw mut __tmp_0) }); &mut __tmp_0 }) @@ -111,14 +111,14 @@ unsafe fn main_0() -> i32 { assert!(((returned) == (2))); let mut arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|_| { let mut __v: Counted = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }); let mut a: FnPtr i32> = lambda_unsafe!( { let arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|__i: usize| { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &arr[(__i)]); + ConstructFromUnsafe::construct_from(&raw mut __v, &arr[(__i)]); __v }); }, @@ -136,18 +136,18 @@ unsafe fn main_0() -> i32 { { let d: Dropped = { let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; }, || {} ); let _dtor_m = std::mem::DropGuard::new(&raw mut m, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut m2: FnPtr = m.move_from(); let _dtor_m2 = std::mem::DropGuard::new(&raw mut m2, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (2))); @@ -156,18 +156,18 @@ unsafe fn main_0() -> i32 { { let d: Dropped = { let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; }, || {} ); let _dtor_k = std::mem::DropGuard::new(&raw mut k, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut k2: FnPtr = k.copy_from(); let _dtor_k2 = std::mem::DropGuard::new(&raw mut k2, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (4))); @@ -176,14 +176,14 @@ unsafe fn main_0() -> i32 { { let d: Dropped = { let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; }, || {} ); let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut outer: FnPtr = lambda_unsafe!( { @@ -192,7 +192,7 @@ unsafe fn main_0() -> i32 { || {} ); let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (6))); diff --git a/tests/unit/out/unsafe/lambda_capture_star_this.rs b/tests/unit/out/unsafe/lambda_capture_star_this.rs index da181b4648..90c2955b37 100644 --- a/tests/unit/out/unsafe/lambda_capture_star_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_star_this.rs @@ -21,13 +21,13 @@ pub struct S { pub n: i32, } impl S { - pub unsafe fn twice(&self) -> i32 { - return ((self.n) * (2)); + pub unsafe fn twice(this: *const Self) -> i32 { + return (((*this).n) * (2)); } - pub unsafe fn modify_copy(&mut self) -> i32 { + pub unsafe fn modify_copy(this: *mut Self) -> i32 { let mut f: FnPtr i32> = lambda_unsafe!( { - let this_: S = (*(self as *mut S)); + let this_: S = (*this); }, || -> i32 { (*(&raw mut this_)).n += 10; @@ -35,31 +35,31 @@ impl S { } ); let mut r: i32 = (unsafe { f.call() }); - return (((r) * (100)) + (self.n)); + return (((r) * (100)) + ((*this).n)); } - pub unsafe fn snapshot(&mut self) -> i32 { + pub unsafe fn snapshot(this: *mut Self) -> i32 { let mut f: FnPtr i32> = lambda_unsafe!( { - let this_: S = (*(self as *mut S)); + let this_: S = (*this); }, || -> i32 { - return (unsafe { S::twice(&(*(&raw mut this_))) }); + return (unsafe { S::twice(&raw const (*(&raw mut this_))) }); } ); - self.n = 99; + (*this).n = 99; return (unsafe { f.call() }); } - pub unsafe fn mixed(&mut self, mut k: i32) -> i32 { + pub unsafe fn mixed(this: *mut Self, mut k: i32) -> i32 { let mut f: FnPtr i32> = lambda_unsafe!( { - let this_: S = (*(self as *mut S)); + let this_: S = (*this); let k: i32 = k; }, || -> i32 { return (((*(&raw mut this_)).n) + (k)); } ); - self.n = 0; + (*this).n = 0; return (unsafe { f.call() }); } } @@ -71,11 +71,11 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut s: S = S { n: 1 }; - assert!(((unsafe { S::modify_copy(&mut s,) }) == (1101))); + assert!(((unsafe { S::modify_copy(&raw mut s,) }) == (1101))); assert!(((s.n) == (1))); - assert!(((unsafe { S::snapshot(&mut s,) }) == (2))); + assert!(((unsafe { S::snapshot(&raw mut s,) }) == (2))); assert!(((s.n) == (99))); - assert!(((unsafe { S::mixed(&mut s, 1,) }) == (100))); + assert!(((unsafe { S::mixed(&raw mut s, 1,) }) == (100))); assert!(((s.n) == (0))); return 0; } diff --git a/tests/unit/out/unsafe/lambda_capture_this.rs b/tests/unit/out/unsafe/lambda_capture_this.rs index 77bec8611a..f055abe092 100644 --- a/tests/unit/out/unsafe/lambda_capture_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_this.rs @@ -22,16 +22,16 @@ pub struct S { pub step: i32, } impl S { - pub unsafe fn add(&mut self, mut k: i32) { - self.n += k; + pub unsafe fn add(this: *mut Self, mut k: i32) { + (*this).n += k; } - pub unsafe fn scaled(&self) -> i32 { - return ((self.n) * (self.step)); + pub unsafe fn scaled(this: *const Self) -> i32 { + return (((*this).n) * ((*this).step)); } - pub unsafe fn bump(&mut self, mut by: i32) { + pub unsafe fn bump(this: *mut Self, mut by: i32) { let mut inc: FnPtr = lambda_unsafe!( { - let this_: *mut S = (self as *mut S); + let this_: *mut S = this; }, |mut k: i32| { (*this_).n += k; @@ -40,24 +40,24 @@ impl S { (unsafe { inc.call(by) }); (unsafe { inc.call(by) }); } - pub unsafe fn bump_via_method(&mut self, mut by: i32) { + pub unsafe fn bump_via_method(this: *mut Self, mut by: i32) { let mut inc: FnPtr = lambda_unsafe!( { - let this_: *mut S = (self as *mut S); + let this_: *mut S = this; }, |mut k: i32| { - (unsafe { S::add(&mut (*this_), k) }); + (unsafe { S::add(&raw mut (*this_), k) }); } ); (unsafe { inc.call(by) }); } - pub unsafe fn read_scaled(&self) -> i32 { + pub unsafe fn read_scaled(this: *const Self) -> i32 { let mut get: FnPtr i32> = lambda_unsafe!( { - let this_: *const S = (self as *const S); + let this_: *const S = this; }, || -> i32 { - return (unsafe { S::scaled(&(*this_)) }); + return (unsafe { S::scaled(&raw const (*this_)) }); } ); return (unsafe { get.call() }); @@ -71,11 +71,11 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut s: S = S { n: 0, step: 2 }; - (unsafe { S::bump(&mut s, 3) }); + (unsafe { S::bump(&raw mut s, 3) }); assert!(((s.n) == (6))); - (unsafe { S::bump_via_method(&mut s, 4) }); + (unsafe { S::bump_via_method(&raw mut s, 4) }); assert!(((s.n) == (10))); - assert!(((unsafe { S::read_scaled(&s,) }) == (20))); + assert!(((unsafe { S::read_scaled(&raw const s,) }) == (20))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/lambda_decltype_type.rs b/tests/unit/out/unsafe/lambda_decltype_type.rs index 9363c82547..08727a0734 100644 --- a/tests/unit/out/unsafe/lambda_decltype_type.rs +++ b/tests/unit/out/unsafe/lambda_decltype_type.rs @@ -14,26 +14,26 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { pub cmp: FnPtr bool>, } impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { - pub unsafe fn insert(&mut self, mut v: i32) { - let mut i: i32 = self.size; + pub unsafe fn insert(this: *mut Self, mut v: i32) { + let mut i: i32 = (*this).size; 'loop_: while ((i) > (0)) && (unsafe { - let _b: i32 = self.items[((i) - (1)) as usize]; - self.cmp.call(v, _b) + let _b: i32 = (*this).items[((i) - (1)) as usize]; + (*this).cmp.call(v, _b) }) { - self.items[(i) as usize] = self.items[((i) - (1)) as usize]; + (*this).items[(i) as usize] = (*this).items[((i) - (1)) as usize]; i.postfix_dec(); } - self.items[(i) as usize] = v; - self.size.postfix_inc(); + (*this).items[(i) as usize] = v; + (*this).size.postfix_inc(); } } impl DefaultConstructibleUnsafe for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.items).write([0_i32; 4]); - (&raw mut self.size).write(0); - (&raw mut self.cmp).write(FnPtr:: bool>::new( + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).items).write([0_i32; 4]); + (&raw mut (*this).size).write(0); + (&raw mut (*this).cmp).write(FnPtr:: bool>::new( |mut a: i32, mut b: i32| -> bool { unsafe { return ((a) > (b)); @@ -65,26 +65,26 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { pub cmp: FnPtr bool>, } impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { - pub unsafe fn insert(&mut self, mut v: i32) { - let mut i: i32 = self.size; + pub unsafe fn insert(this: *mut Self, mut v: i32) { + let mut i: i32 = (*this).size; 'loop_: while ((i) > (0)) && (unsafe { - let _b: i32 = self.items[((i) - (1)) as usize]; - self.cmp.call(v, _b) + let _b: i32 = (*this).items[((i) - (1)) as usize]; + (*this).cmp.call(v, _b) }) { - self.items[(i) as usize] = self.items[((i) - (1)) as usize]; + (*this).items[(i) as usize] = (*this).items[((i) - (1)) as usize]; i.postfix_dec(); } - self.items[(i) as usize] = v; - self.size.postfix_inc(); + (*this).items[(i) as usize] = v; + (*this).size.postfix_inc(); } } impl DefaultConstructibleUnsafe for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.items).write([0_i32; 4]); - (&raw mut self.size).write(0); - (&raw mut self.cmp).write(FnPtr:: bool>::new( + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).items).write([0_i32; 4]); + (&raw mut (*this).size).write(0); + (&raw mut (*this).cmp).write(FnPtr:: bool>::new( |mut a: i32, mut b: i32| -> bool { unsafe { return ((a) < (b)); @@ -122,16 +122,16 @@ unsafe fn main_0() -> i32 { } }); object_unsafe!(desc, Sorted__lambda_at_lambda_decltype_type_cpp_22_18__); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&mut desc, 2) }); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&mut desc, 7) }); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&mut desc, 4) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 2) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 7) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 4) }); assert!(((desc.items[(0) as usize]) == (7))); assert!(((desc.items[(1) as usize]) == (4))); assert!(((desc.items[(2) as usize]) == (2))); object_unsafe!(asc, Sorted__lambda_at_lambda_decltype_type_cpp_19_23__); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&mut asc, 2) }); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&mut asc, 7) }); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&mut asc, 4) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 2) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 7) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 4) }); assert!(((asc.items[(0) as usize]) == (2))); assert!(((asc.items[(1) as usize]) == (4))); assert!(((asc.items[(2) as usize]) == (7))); diff --git a/tests/unit/out/unsafe/lambda_immediate_init.rs b/tests/unit/out/unsafe/lambda_immediate_init.rs index ed176294c7..cd9d7a8e24 100644 --- a/tests/unit/out/unsafe/lambda_immediate_init.rs +++ b/tests/unit/out/unsafe/lambda_immediate_init.rs @@ -16,9 +16,9 @@ pub struct S { pub k: i32, } impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(&mut self) { - (&raw mut self.j).write(10); - (&raw mut self.k).write( + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).j).write(10); + (&raw mut (*this).k).write( ((unsafe { FnPtr:: i32>::new(|| -> i32 { unsafe { diff --git a/tests/unit/out/unsafe/lambda_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index e722c7be24..1c66791fba 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -13,18 +13,15 @@ pub struct Owner { pub p: *mut i32, } impl Owner { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.p).write((Box::leak(Box::new(v)) as *mut i32)); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).p).write((Box::leak(Box::new(v)) as *mut i32)); } - pub unsafe fn take(&mut self) -> FnPtr i32> { + pub unsafe fn take(this: *mut Self) -> FnPtr i32> { return lambda_unsafe!( { let self_: Owner = { let mut __v: Owner = ::zero_init(); - ConstructFromUnsafe::construct_from( - &mut __v, - Moved(&mut (*(self as *mut Owner))), - ); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut (*this))); __v }; }, @@ -35,15 +32,15 @@ impl Owner { } } impl MoveConstructibleUnsafe for Owner { - unsafe fn move_constructor(&mut self, o: *mut Owner) { - (&raw mut self.p).write((*o).p); + unsafe fn move_constructor(this: *mut Self, o: *mut Owner) { + (&raw mut (*this).p).write((*o).p); (*o).p = std::ptr::null_mut(); } } impl DestructibleUnsafe for Owner { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { { - let __p = self.p; + let __p = (*this).p; if !__p.is_null() { ::std::mem::drop(Box::from_raw(__p)) } @@ -62,7 +59,7 @@ unsafe fn main_0() -> i32 { { let h: Owner = { let mut __v: Owner = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut o)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut o)); __v }; }, @@ -71,13 +68,13 @@ unsafe fn main_0() -> i32 { } ); let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!((o.p).is_null()); assert!(((unsafe { f.call() }) == (5))); let mut g: FnPtr i32> = f.move_from(); let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!(((unsafe { g.call() }) == (5))); let mut total: i32 = 0; @@ -85,7 +82,7 @@ unsafe fn main_0() -> i32 { { let h: Owner = { let mut __v: Owner = ::zero_init(); - Owner::construct(&mut __v, 7); + Owner::construct(&raw mut __v, 7); __v }; let total: *mut i32 = &mut total; @@ -96,15 +93,15 @@ unsafe fn main_0() -> i32 { } ); let _dtor_consume = std::mem::DropGuard::new(&raw mut consume, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); (unsafe { consume.call() }); (unsafe { consume.call() }); assert!(((total) == (7))); object_unsafe!(o2, Owner(9)); - let mut t: FnPtr i32> = (unsafe { Owner::take(&mut o2) }); + let mut t: FnPtr i32> = (unsafe { Owner::take(&raw mut o2) }); let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!((o2.p).is_null()); assert!(((unsafe { t.call() }) == (9))); diff --git a/tests/unit/out/unsafe/lambda_nested.rs b/tests/unit/out/unsafe/lambda_nested.rs index 9617322fc0..57e99f3436 100644 --- a/tests/unit/out/unsafe/lambda_nested.rs +++ b/tests/unit/out/unsafe/lambda_nested.rs @@ -21,10 +21,10 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn nested_this(&mut self) -> i32 { + pub unsafe fn nested_this(this: *mut Self) -> i32 { let mut outer: FnPtr i32> = lambda_unsafe!( { - let this_: *mut S = (self as *mut S); + let this_: *mut S = this; }, |mut y: i32| -> i32 { let mut inner: FnPtr i32> = lambda_unsafe!( @@ -71,7 +71,7 @@ unsafe fn main_0() -> i32 { x = 100; assert!(((unsafe { outer.call(20,) }) == (121))); let mut s: S = S { v: 5 }; - assert!(((unsafe { S::nested_this(&mut s,) }) == (26))); + assert!(((unsafe { S::nested_this(&raw mut s,) }) == (26))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/libc_struct_without_default.rs b/tests/unit/out/unsafe/libc_struct_without_default.rs index 9c72ff7f29..b5d7cfed8e 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -23,9 +23,9 @@ pub struct UserDefined { pub v: Vec, } impl DefaultConstructibleUnsafe for UserDefined { - unsafe fn default_constructor(&mut self) { - (&raw mut self.a).write(std::array::from_fn::<_, 1, _>(|_| 0_i32)); - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).a).write(std::array::from_fn::<_, 1, _>(|_| 0_i32)); + (&raw mut (*this).v).write(Vec::new()); } } impl Default for UserDefined { diff --git a/tests/unit/out/unsafe/linked_list.rs b/tests/unit/out/unsafe/linked_list.rs index 6cf73c6397..3101cc9ed8 100644 --- a/tests/unit/out/unsafe/linked_list.rs +++ b/tests/unit/out/unsafe/linked_list.rs @@ -22,8 +22,8 @@ pub struct Node { pub next: *mut Node, } impl Node { - pub unsafe fn SetNext(&mut self, mut next: *mut Node) { - self.next = next; + pub unsafe fn SetNext(this: *mut Self, mut next: *mut Node) { + (*this).next = next; } } pub unsafe fn Find_0(mut head: *mut Node, mut idx: i32) -> *mut Node { @@ -44,7 +44,7 @@ pub unsafe fn Append_1(head: *mut Node, new_node: *mut Node) { 'loop_: while !(((*curr).next).is_null()) { curr = (*curr).next; } - (unsafe { Node::SetNext(&mut (*curr), (new_node)) }); + (unsafe { Node::SetNext(&raw mut (*curr), (new_node)) }); } pub unsafe fn Delete_2(mut head: *mut Node, mut val: i32) -> *mut Node { let mut curr: *mut Node = head; diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index ef4c06e1b6..b1c75afbca 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -22,15 +22,15 @@ pub struct Point { pub y: i32, } impl Point { - pub unsafe fn construct_1(&mut self, mut x: i32, mut y: i32) { - (&raw mut self.x).write(x); - (&raw mut self.y).write(y); + pub unsafe fn construct_1(this: *mut Self, mut x: i32, mut y: i32) { + (&raw mut (*this).x).write(x); + (&raw mut (*this).y).write(y); } } impl DefaultConstructibleUnsafe for Point { - unsafe fn default_constructor(&mut self) { - (&raw mut self.x).write(0); - (&raw mut self.y).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).x).write(0); + (&raw mut (*this).y).write(0); } } impl Default for Point { @@ -38,7 +38,7 @@ impl Default for Point { unsafe { { let mut __v: Point = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -447,7 +447,7 @@ unsafe fn main_0() -> i32 { let mut point_new: (UnsafeBidirectionalIterator<(i32, Point)>, bool) = points.try_emplace(key1, || { let mut __v: Point = ::zero_init(); - Point::construct_1(&mut __v, 3, 4); + Point::construct_1(&raw mut __v, 3, 4); __v }); assert!(((point_new.1) as bool)); @@ -481,7 +481,7 @@ unsafe fn main_0() -> i32 { }; points.emplace((key8, { let mut __v: Point = ::zero_init(); - Point::construct_1(&mut __v, 5, 6); + Point::construct_1(&raw mut __v, 5, 6); __v })); { diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 51f47533cd..3db77d5c8f 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -18,22 +18,22 @@ pub struct Key { pub k: i32, } impl Key { - pub unsafe fn construct(&mut self, mut k: i32) { - (&raw mut self.k).write(k); + pub unsafe fn construct(this: *mut Self, mut k: i32) { + (&raw mut (*this).k).write(k); } - pub unsafe fn operator_lt(&self, o: *const Key) -> bool { - return ((self.k) < ((*o).k)); + pub unsafe fn operator_lt(this: *const Self, o: *const Key) -> bool { + return (((*this).k) < ((*o).k)); } } impl CopyConstructibleUnsafe for Key { - unsafe fn copy_constructor(&mut self, o: *const Key) { - (&raw mut self.k).write((*o).k); + unsafe fn copy_constructor(this: *mut Self, o: *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(&mut self, o: *mut Key) { - (&raw mut self.k).write((*o).k); + unsafe fn move_constructor(this: *mut Self, o: *mut Key) { + (&raw mut (*this).k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); } } @@ -64,9 +64,9 @@ impl std::cmp::PartialEq for Key { } } impl std::cmp::Eq for Key {} -pub unsafe fn make_key_3(this: *mut Key, mut k: i32) { +pub unsafe fn make_key_3(__return: *mut Key, mut k: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)).prefix_inc(); - Key::construct(&mut *this, k); + Key::construct(__return, k); return; } pub fn main() { @@ -101,7 +101,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_1: Key = ::zero_init(); (*match (({ - (unsafe { make_key_3(&mut __tmp_1, 4) }); + (unsafe { make_key_3(&raw mut __tmp_1, 4) }); &mut __tmp_1 } as *mut Key),) { @@ -111,7 +111,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_3: Key = ::zero_init(); (*match (({ - (unsafe { make_key_3(&mut __tmp_3, 4) }); + (unsafe { make_key_3(&raw mut __tmp_3, 4) }); &mut __tmp_3 } as *mut Key),) { @@ -141,7 +141,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_5: Key = ::zero_init(); (*match (({ - Key::construct(&mut __tmp_5, 0); + Key::construct(&raw mut __tmp_5, 0); &mut __tmp_5 } as *mut Key),) { diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index d7f3b4279f..62f5ce6810 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -59,8 +59,8 @@ pub struct Mapped { pub value: i32, } impl DefaultConstructibleUnsafe for Mapped { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)).prefix_inc(); } } @@ -69,7 +69,7 @@ impl Default for Mapped { unsafe { { let mut __v: Mapped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index aa77d462f1..50b537fdfa 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -17,25 +17,25 @@ pub struct Item { pub value: i32, } impl Item { - pub unsafe fn construct_1(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct_1(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); } } impl DefaultConstructibleUnsafe for Item { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(0); } } impl CopyConstructibleUnsafe for Item { - unsafe fn copy_constructor(&mut self, other: *const Item) { - (&raw mut self.value).write((*other).value); + unsafe fn copy_constructor(this: *mut Self, other: *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(&mut self, other: *mut Item) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *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; } @@ -45,7 +45,7 @@ impl Default for Item { unsafe { { let mut __v: Item = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -61,8 +61,8 @@ pub struct RefItem { pub value: i32, } impl RefItem { - pub unsafe fn construct_1(&mut self, counter: *mut i32, mut amount: i32) { - (&raw mut self.value).write({ + pub unsafe fn construct_1(this: *mut Self, counter: *mut i32, mut amount: i32) { + (&raw mut (*this).value).write({ (*counter) += amount; (*counter) }); @@ -70,8 +70,8 @@ impl RefItem { } } impl DefaultConstructibleUnsafe for RefItem { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(0); } } impl Default for RefItem { @@ -79,7 +79,7 @@ impl Default for RefItem { unsafe { { let mut __v: RefItem = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -251,7 +251,7 @@ unsafe fn main_0() -> i32 { let mut key: i32 = 0; items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, 10); + Item::construct_1(&raw mut __v, 10); __v }); object_unsafe!(source, Item::construct_1(20)); @@ -266,7 +266,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_6,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, __tmp_6); + ConstructFromUnsafe::construct_from(&raw mut __v, __tmp_6); __v }), }; @@ -282,7 +282,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_7,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_7)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_7)); __v }), }; @@ -299,7 +299,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_8,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, __tmp_8); + ConstructFromUnsafe::construct_from(&raw mut __v, __tmp_8); __v }), }; @@ -316,7 +316,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_9,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_9)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_9)); __v }), }; @@ -336,7 +336,7 @@ unsafe fn main_0() -> i32 { let mut counter: i32 = 0; refs.try_emplace(key, || { let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&mut __v, &mut counter, 5); + RefItem::construct_1(&raw mut __v, &mut counter, 5); __v }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = 0; @@ -344,7 +344,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_10,) => refs.try_emplace(key, || { let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&mut __v, __tmp_10, 2); + RefItem::construct_1(&raw mut __v, __tmp_10, 2); __v }), }; @@ -359,7 +359,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_11,) => refs.try_emplace(key, || { let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&mut __v, __tmp_11, 2); + RefItem::construct_1(&raw mut __v, __tmp_11, 2); __v }), }; @@ -384,13 +384,13 @@ unsafe fn main_0() -> i32 { let mut temporary_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { let mut __tmp_13: Item = ::zero_init(); match (({ - Item::construct_1(&mut __tmp_13, 30); + Item::construct_1(&raw mut __tmp_13, 30); &mut __tmp_13 } as *mut Item),) { (__tmp_12,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_12)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_12)); __v }), } @@ -407,13 +407,13 @@ unsafe fn main_0() -> i32 { let mut temporary_new: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { let mut __tmp_15: Item = ::zero_init(); match (({ - Item::construct_1(&mut __tmp_15, 40); + Item::construct_1(&raw mut __tmp_15, 40); &mut __tmp_15 } as *mut Item),) { (__tmp_14,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_14)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_14)); __v }), } diff --git a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs index 1c48fa5c3d..4fb0165186 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -14,8 +14,8 @@ pub struct Item { pub value: i32, } impl Item { - pub unsafe fn construct_1(&mut self, counter: *mut i32, mut amount: i32) { - (&raw mut self.value).write({ + pub unsafe fn construct_1(this: *mut Self, counter: *mut i32, mut amount: i32) { + (&raw mut (*this).value).write({ (*counter) += amount; (*counter) }); @@ -23,8 +23,8 @@ impl Item { } } impl DefaultConstructibleUnsafe for Item { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(0); } } impl Default for Item { @@ -32,7 +32,7 @@ impl Default for Item { unsafe { { let mut __v: Item = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -55,9 +55,9 @@ pub struct Temporary { pub data: [i32; 2], } impl DefaultConstructibleUnsafe for Temporary { - unsafe fn default_constructor(&mut self) { - (&raw mut self.n).write(5); - (&raw mut self.data).write([6, 7]); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).n).write(5); + (&raw mut (*this).data).write([6, 7]); (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)).prefix_inc(); } } @@ -66,7 +66,7 @@ impl Default for Temporary { unsafe { { let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -80,21 +80,21 @@ pub struct Nested { pub inner: Temporary, } impl DefaultConstructibleUnsafe for Nested { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.inner); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).inner); } } pub unsafe fn make_temporary_5() -> Temporary { return { let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; } pub unsafe fn make_nested_6() -> Nested { return { let mut __v: Nested = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; } @@ -107,18 +107,18 @@ pub struct Owner { pub ptr: Option>, } impl Owner { - pub unsafe fn value(&mut self) -> *const i32 { - return &(*self.ptr.as_deref().map_or(::std::ptr::null_mut(), |v| { + pub unsafe fn value(this: *mut Self) -> *const i32 { + return &(*(*this).ptr.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const Temporary as *mut Temporary })) .n; } } impl DefaultConstructibleUnsafe for Owner { - unsafe fn default_constructor(&mut self) { - (&raw mut self.ptr).write(Some(Box::new({ + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).ptr).write(Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }))); } @@ -128,7 +128,7 @@ impl Default for Owner { unsafe { { let mut __v: Owner = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -140,8 +140,8 @@ pub struct Noncopy { pub n: i32, } impl DefaultConstructibleUnsafe for Noncopy { - unsafe fn default_constructor(&mut self) { - (&raw mut self.n).write(5); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).n).write(5); } } impl Default for Noncopy { @@ -158,16 +158,16 @@ pub struct Held { pub ptr: *const i32, } impl Held { - pub unsafe fn construct_1(&mut self, n: *const i32) { - (&raw mut self.ptr).write((n)); + pub unsafe fn construct_1(this: *mut Self, n: *const i32) { + (&raw mut (*this).ptr).write((n)); } - pub unsafe fn construct_2(&mut self, n: *const [i32; 2], mut _a1: i32) { - (&raw mut self.ptr).write((*n).as_ptr()); + pub unsafe fn construct_2(this: *mut Self, n: *const [i32; 2], mut _a1: i32) { + (&raw mut (*this).ptr).write((*n).as_ptr()); } } impl DefaultConstructibleUnsafe for Held { - unsafe fn default_constructor(&mut self) { - (&raw mut self.ptr).write(std::ptr::null()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).ptr).write(std::ptr::null()); } } impl Default for Held { @@ -175,7 +175,7 @@ impl Default for Held { unsafe { { let mut __v: Held = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -246,7 +246,7 @@ pub static mut global_owned_16: std::cell::LazyCell<( match ((&mut (*(*{ __tmp_6 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_6 @@ -300,7 +300,7 @@ unsafe fn main_0() -> i32 { let mut counter: i32 = 0; m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, &mut counter, 3); + Item::construct_1(&raw mut __v, &mut counter, 3); __v }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) = 0; @@ -314,7 +314,7 @@ unsafe fn main_0() -> i32 { ) { (__tmp_7, __tmp_8) => (*__tmp_7).try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_8, 2); + Item::construct_1(&raw mut __v, __tmp_8, 2); __v }), }; @@ -332,7 +332,7 @@ unsafe fn main_0() -> i32 { { (__tmp_10,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_10, 2); + Item::construct_1(&raw mut __v, __tmp_10, 2); __v }), }; @@ -350,7 +350,7 @@ unsafe fn main_0() -> i32 { { (__tmp_12,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_12, 2); + Item::construct_1(&raw mut __v, __tmp_12, 2); __v }), }; @@ -369,7 +369,7 @@ unsafe fn main_0() -> i32 { { (__tmp_15,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_15, 2); + Item::construct_1(&raw mut __v, __tmp_15, 2); __v }), }; @@ -392,7 +392,7 @@ unsafe fn main_0() -> i32 { { (__tmp_18,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_18, 3); + Item::construct_1(&raw mut __v, __tmp_18, 3); __v }), }; @@ -413,7 +413,7 @@ unsafe fn main_0() -> i32 { { (__tmp_20,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_20, 3); + Item::construct_1(&raw mut __v, __tmp_20, 3); __v }), }; @@ -430,7 +430,7 @@ unsafe fn main_0() -> i32 { { (__tmp_23,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_23, 3); + Item::construct_1(&raw mut __v, __tmp_23, 3); __v }), }; @@ -456,7 +456,7 @@ unsafe fn main_0() -> i32 { { (__tmp_26,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_26, 3); + Item::construct_1(&raw mut __v, __tmp_26, 3); __v }), }; @@ -481,7 +481,7 @@ unsafe fn main_0() -> i32 { { (__tmp_29,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_29, 3); + Item::construct_1(&raw mut __v, __tmp_29, 3); __v }), }; @@ -496,7 +496,7 @@ unsafe fn main_0() -> i32 { { (__tmp_32,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_32, 3); + Item::construct_1(&raw mut __v, __tmp_32, 3); __v }), }; @@ -727,7 +727,7 @@ unsafe fn main_0() -> i32 { { (__tmp_60,) => selected.try_emplace(keys[(0) as usize], || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_60, 2); + Item::construct_1(&raw mut __v, __tmp_60, 2); __v }), }; @@ -750,7 +750,7 @@ unsafe fn main_0() -> i32 { { (__tmp_63,) => selected.try_emplace(keys[(1) as usize], || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_63, 2); + Item::construct_1(&raw mut __v, __tmp_63, 2); __v }), }; @@ -773,7 +773,7 @@ unsafe fn main_0() -> i32 { { (__tmp_68,) => selected.try_emplace(keys[(2) as usize], || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_68, 2); + Item::construct_1(&raw mut __v, __tmp_68, 2); __v }), }; @@ -913,7 +913,7 @@ unsafe fn main_0() -> i32 { if (hit != 0) { references.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_1(&mut __v, &ordinary); + Held::construct_1(&raw mut __v, &ordinary); __v }); } @@ -944,7 +944,7 @@ unsafe fn main_0() -> i32 { { (__tmp_79,) => references.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_1(&mut __v, __tmp_79); + Held::construct_1(&raw mut __v, __tmp_79); __v }), }; @@ -971,7 +971,7 @@ unsafe fn main_0() -> i32 { if (hit != 0) { arrays.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_2(&mut __v, &ordinary_array, 0); + Held::construct_2(&raw mut __v, &ordinary_array, 0); __v }); } @@ -1000,7 +1000,7 @@ unsafe fn main_0() -> i32 { { (__tmp_82,) => arrays.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_2(&mut __v, __tmp_82, 0); + Held::construct_2(&raw mut __v, __tmp_82, 0); __v }), }; @@ -1045,7 +1045,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*(*{ __tmp_86 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_86 @@ -1064,7 +1064,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*&mut (*(*{ __tmp_88 = Some(Box::new({ let mut __v: Nested = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_88 @@ -1084,7 +1084,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*(*{ __tmp_90 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_90 @@ -1103,7 +1103,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*(*{ __tmp_92 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_92 @@ -1120,7 +1120,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*((*{ __tmp_94 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_94 @@ -1139,7 +1139,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*((*(*{ __tmp_96 = Some(Box::new(Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })))); &mut __tmp_96 @@ -1192,7 +1192,7 @@ unsafe fn main_0() -> i32 { if (hit != 0) { references.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_1(&mut __v, &ordinary); + Held::construct_1(&raw mut __v, &ordinary); __v }); } @@ -1209,7 +1209,7 @@ unsafe fn main_0() -> i32 { __tmp_98 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); DefaultConstructibleUnsafe::default_constructor( - &mut __v, + &raw mut __v, ); __v })); @@ -1225,7 +1225,7 @@ unsafe fn main_0() -> i32 { __tmp_99 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); DefaultConstructibleUnsafe::default_constructor( - &mut __v, + &raw mut __v, ); __v })); @@ -1242,7 +1242,7 @@ unsafe fn main_0() -> i32 { { (__tmp_97,) => references.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_1(&mut __v, __tmp_97); + Held::construct_1(&raw mut __v, __tmp_97); __v }), }; @@ -1272,7 +1272,7 @@ unsafe fn main_0() -> i32 { Owner::value( &mut (*{ DefaultConstructibleUnsafe::default_constructor( - &mut __tmp_101, + &raw mut __tmp_101, ); &mut __tmp_101 }), @@ -1281,7 +1281,7 @@ unsafe fn main_0() -> i32 { { (__tmp_100,) => owners.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_1(&mut __v, __tmp_100); + Held::construct_1(&raw mut __v, __tmp_100); __v }), }; @@ -1306,7 +1306,7 @@ unsafe fn main_0() -> i32 { match (({ __tmp_103 = Some(Box::new({ let mut __v: Noncopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_103 @@ -1323,7 +1323,7 @@ unsafe fn main_0() -> i32 { match (({ __tmp_105 = Some(Box::new({ let mut __v: Noncopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_105 diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 6d058d9580..2418d926f2 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -34,13 +34,13 @@ pub struct Bag { pub n: i32, } impl Bag { - pub unsafe fn construct(&mut self, mut n: i32) { - (&raw mut self.n).write(n); + pub unsafe fn construct(this: *mut Self, mut n: i32) { + (&raw mut (*this).n).write(n); } } impl CopyConstructibleUnsafe for Bag { - unsafe fn copy_constructor(&mut self, o: *const Bag) { - (&raw mut self.n).write((*o).n); + unsafe fn copy_constructor(this: *mut Self, o: *const Bag) { + (&raw mut (*this).n).write((*o).n); (*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)).prefix_inc(); } } @@ -74,8 +74,8 @@ impl std::cmp::Eq for Bag {} pub unsafe fn operator_lt_4(a: *const Bag, b: *const Bag) -> bool { return (((*a).n) < ((*b).n)); } -pub unsafe fn make_5(this: *mut Bag, mut n: i32) { - Bag::construct(&mut *this, n); +pub unsafe fn make_5(__return: *mut Bag, mut n: i32) { + Bag::construct(__return, n); return; } pub fn main() { @@ -162,11 +162,11 @@ unsafe fn main_0() -> i32 { let mut __tmp_7: Bag = ::zero_init(); (((*match ( ({ - (unsafe { make_5(&mut __tmp_5, 1) }); + (unsafe { make_5(&raw mut __tmp_5, 1) }); &mut __tmp_5 } as *const Bag), ({ - (unsafe { make_5(&mut __tmp_7, 2) }); + (unsafe { make_5(&raw mut __tmp_7, 2) }); &mut __tmp_7 } as *const Bag), ) { @@ -182,11 +182,11 @@ unsafe fn main_0() -> i32 { let mut __tmp_11: Bag = ::zero_init(); (((*match ( ({ - (unsafe { make_5(&mut __tmp_9, 1) }); + (unsafe { make_5(&raw mut __tmp_9, 1) }); &mut __tmp_9 } as *const Bag), ({ - (unsafe { make_5(&mut __tmp_11, 2) }); + (unsafe { make_5(&raw mut __tmp_11, 2) }); &mut __tmp_11 } as *const Bag), ) { diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index ac1f8d6f3c..d8a0ea3fa0 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -20,24 +20,24 @@ pub struct MoveOnly { pub v: i32, } impl MoveOnly { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(&mut self, o: *mut MoveOnly) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *mut MoveOnly) { + (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for MoveOnly { - unsafe fn move_assign(&mut self, o: *mut MoveOnly) -> *mut MoveOnly { - if ((self as *mut MoveOnly) == (o)) { - return &mut (*(self as *mut MoveOnly)); + unsafe fn move_assign(this: *mut Self, o: *mut MoveOnly) -> *mut MoveOnly { + if ((this) == (o)) { + return &mut (*this); } - self.v = (*o).v; + (*this).v = (*o).v; (*o).v = 0; - return &mut (*(self as *mut MoveOnly)); + return &mut (*this); } } #[repr(C)] @@ -46,18 +46,24 @@ pub struct ConstMoveAssign { pub mark: i32, } impl ConstMoveAssign { - pub unsafe fn operator_assign_2(&mut self, o: *mut ConstMoveAssign) -> *mut ConstMoveAssign { - self.mark = (((*o).mark) + (1)); - return &mut (*(self as *mut ConstMoveAssign)); + pub unsafe fn operator_assign_2( + this: *mut Self, + o: *mut ConstMoveAssign, + ) -> *mut ConstMoveAssign { + (*this).mark = (((*o).mark) + (1)); + return &mut (*this); } - pub unsafe fn operator_assign_3(&mut self, o: *const ConstMoveAssign) -> *mut ConstMoveAssign { - self.mark = (((*o).mark) + (10)); - return &mut (*(self as *mut ConstMoveAssign)); + pub unsafe fn operator_assign_3( + this: *mut Self, + o: *const ConstMoveAssign, + ) -> *mut ConstMoveAssign { + (*this).mark = (((*o).mark) + (10)); + return &mut (*this); } } impl DefaultConstructibleUnsafe for ConstMoveAssign { - unsafe fn default_constructor(&mut self) { - (&raw mut self.mark).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).mark).write(0); } } impl Default for ConstMoveAssign { @@ -65,15 +71,15 @@ impl Default for ConstMoveAssign { unsafe { { let mut __v: ConstMoveAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } } } -pub unsafe fn make_0(this: *mut MoveOnly, mut v: i32) { +pub unsafe fn make_0(__return: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut m)); + ConstructFromUnsafe::construct_from(__return, Moved(&mut m)); return; } pub fn main() { @@ -91,20 +97,20 @@ unsafe fn main_0() -> i32 { assert!(((b.v) == (0))); (unsafe { let mut _o: MoveOnly = ::zero_init(); - MoveOnly::construct(&mut _o, 3); + MoveOnly::construct(&raw mut _o, 3); assign_unsafe!(b = Moved(_o)) }); assign_unsafe!(c = Moved((*assign_unsafe!(a = Moved(b))))); assert!((((b.v) == (0)) && ((a.v) == (0))) && ((c.v) == (3))); (unsafe { let mut _o: MoveOnly = ::zero_init(); - MoveOnly::construct(&mut _o, 5); + MoveOnly::construct(&raw mut _o, 5); assign_unsafe!(a = Moved(_o)) }); assert!(((a.v) == (5))); (unsafe { let mut _o: MoveOnly = ::zero_init(); - (unsafe { make_0(&mut _o, 6) }); + (unsafe { make_0(&raw mut _o, 6) }); assign_unsafe!(a = Moved(_o)) }); assert!(((a.v) == (6))); @@ -117,7 +123,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_1: MoveOnly = ::zero_init(); match (({ - MoveOnly::construct(&mut __tmp_1, 7); + MoveOnly::construct(&raw mut __tmp_1, 7); &mut __tmp_1 } as *mut MoveOnly),) { @@ -132,8 +138,8 @@ unsafe fn main_0() -> i32 { object_unsafe!(m1, ConstMoveAssign); object_unsafe!(m2, ConstMoveAssign); object_unsafe!(cm, ConstMoveAssign); - (unsafe { ConstMoveAssign::operator_assign_2(&mut m1, &mut m) }); - (unsafe { ConstMoveAssign::operator_assign_3(&mut m2, &cm) }); + (unsafe { ConstMoveAssign::operator_assign_2(&raw mut m1, &mut m) }); + (unsafe { ConstMoveAssign::operator_assign_3(&raw mut m2, &cm) }); assert!(((m1.mark) == (1))); assert!(((m2.mark) == (10))); return 0; diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index 7df880a284..314099031b 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -15,13 +15,13 @@ pub struct MoveOnly { pub v: i32, } impl MoveOnly { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(&mut self, o: *mut MoveOnly) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *mut MoveOnly) { + (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } @@ -31,16 +31,16 @@ pub struct ConstMove { pub mark: i32, } impl ConstMove { - pub unsafe fn construct_1(&mut self, o: *mut ConstMove) { - (&raw mut self.mark).write((((*o).mark) + (1))); + pub unsafe fn construct_1(this: *mut Self, o: *mut ConstMove) { + (&raw mut (*this).mark).write((((*o).mark) + (1))); } - pub unsafe fn construct_2(&mut self, o: *const ConstMove) { - (&raw mut self.mark).write((((*o).mark) + (10))); + pub unsafe fn construct_2(this: *mut Self, o: *const ConstMove) { + (&raw mut (*this).mark).write((((*o).mark) + (10))); } } impl DefaultConstructibleUnsafe for ConstMove { - unsafe fn default_constructor(&mut self) { - (&raw mut self.mark).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).mark).write(0); } } impl Default for ConstMove { @@ -48,7 +48,7 @@ impl Default for ConstMove { unsafe { { let mut __v: ConstMove = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -65,24 +65,24 @@ pub struct ThrowingMove { pub moves: i32, } impl ThrowingMove { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for ThrowingMove { - unsafe fn copy_constructor(&mut self, o: *const ThrowingMove) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *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(&mut self, o: *mut ThrowingMove) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut ThrowingMove) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } @@ -97,33 +97,33 @@ pub struct NoexceptMove { pub moves: i32, } impl NoexceptMove { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for NoexceptMove { - unsafe fn copy_constructor(&mut self, o: *const NoexceptMove) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *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(&mut self, o: *mut NoexceptMove) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut NoexceptMove) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } pub unsafe fn by_value_0(m: *mut MoveOnly) -> i32 { return (*m).v; } -pub unsafe fn make_1(this: *mut MoveOnly, mut v: i32) { +pub unsafe fn make_1(__return: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut m)); + ConstructFromUnsafe::construct_from(__return, Moved(&mut m)); return; } pub fn main() { @@ -148,14 +148,14 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _m: MoveOnly = ::zero_init(); - MoveOnly::construct(&mut _m, 6); + MoveOnly::construct(&raw mut _m, 6); by_value_0(&mut _m) }) == (6)) ); assert!( ((unsafe { let mut _m: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _m, Moved(&mut e)); + ConstructFromUnsafe::construct_from(&raw mut _m, Moved(&mut e)); by_value_0(&mut _m) }) == (5)) ); @@ -164,7 +164,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_1: MoveOnly = ::zero_init(); match (({ - MoveOnly::construct(&mut __tmp_1, 7); + MoveOnly::construct(&raw mut __tmp_1, 7); &mut __tmp_1 } as *mut MoveOnly),) { @@ -201,7 +201,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_3: NoexceptMove = ::zero_init(); match (({ - NoexceptMove::construct(&mut __tmp_3, 4); + NoexceptMove::construct(&raw mut __tmp_3, 4); &mut __tmp_3 } as *mut NoexceptMove),) { diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index f50a3cf2c6..65caaec186 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -15,37 +15,37 @@ pub struct Chain { pub v: i32, } impl Chain { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } - pub unsafe fn add_4(&mut self, mut n: i32) -> *mut Chain { - self.v += n; - return &mut (*(self as *mut Chain)); + pub unsafe fn add_4(this: *mut Self, mut n: i32) -> *mut Chain { + (*this).v += n; + return &mut (*this); } - pub unsafe fn add_5(&mut self, mut n: i32) -> *mut Chain { - self.v += n; - return &mut (*(self as *mut Chain)); + pub unsafe fn add_5(this: *mut Self, mut n: i32) -> *mut Chain { + (*this).v += n; + return &mut (*this); } - pub unsafe fn take(&mut self, this: *mut Chain) { - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut (*(self as *mut Chain)))); + pub unsafe fn take(this: *mut Self, __return: *mut Chain) { + ConstructFromUnsafe::construct_from(__return, Moved(&mut (*this))); return; } - pub unsafe fn copy(&self, this: *mut Chain) { - ConstructFromUnsafe::construct_from(&mut *this, &(*(self as *const Chain))); + pub unsafe fn copy(this: *const Self, __return: *mut Chain) { + ConstructFromUnsafe::construct_from(__return, &(*this)); return; } - pub unsafe fn self_(&mut self) -> *mut Chain { - return &mut (*(self as *mut Chain)); + pub unsafe fn self_(this: *mut Self) -> *mut Chain { + return &mut (*this); } } impl CopyConstructibleUnsafe for Chain { - unsafe fn copy_constructor(&mut self, o: *const Chain) { - (&raw mut self.v).write((((*o).v) + (100))); + unsafe fn copy_constructor(this: *mut Self, o: *const Chain) { + (&raw mut (*this).v).write((((*o).v) + (100))); } } impl MoveConstructibleUnsafe for Chain { - unsafe fn move_constructor(&mut self, o: *mut Chain) { - (&raw mut self.v).write((((*o).v) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Chain) { + (&raw mut (*this).v).write((((*o).v) + (1))); (*o).v = 0; } } @@ -60,13 +60,13 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(a, Chain(1)); - (unsafe { Chain::add_4(&mut (*(unsafe { Chain::add_4(&mut a, 1) })), 1) }); + (unsafe { Chain::add_4(&raw mut (*(unsafe { Chain::add_4(&raw mut a, 1) })), 1) }); assert!(((a.v) == (3))); object_unsafe!(b0, Chain(5)); object_unsafe!( b, Chain, - Moved((unsafe { Chain::add_5(&mut (*(unsafe { Chain::add_5(&mut b0, 1,) })), 1,) })) + Moved((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| { @@ -74,7 +74,7 @@ unsafe fn main_0() -> i32 { (unsafe { Chain::take( &mut (*{ - Chain::construct(&mut __tmp_0, 10); + Chain::construct(&raw mut __tmp_0, 10); &mut __tmp_0 }), c, @@ -82,18 +82,21 @@ unsafe fn main_0() -> i32 { }) }); assert!(((c.v) == (11))); - object_unsafe!(d, Chain, |d| (unsafe { Chain::copy(&c, d,) })); + object_unsafe!(d, Chain, |d| (unsafe { Chain::copy(&raw const c, d,) })); assert!(((d.v) == (111)) && ((c.v) == (11))); object_unsafe!(g, Chain(20)); assert!( ((unsafe { let mut _c: Chain = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _c, Moved((unsafe { Chain::self_(&mut g) }))); + ConstructFromUnsafe::construct_from( + &raw mut _c, + Moved((unsafe { Chain::self_(&raw mut g) })), + ); consume_0(&mut _c) }) == (21)) ); object_unsafe!(e, Chain(30)); - object_unsafe!(f, Chain, |f| (unsafe { Chain::take(&mut e, f,) })); + object_unsafe!(f, Chain, |f| (unsafe { Chain::take(&raw mut e, f,) })); assert!(((f.v) == (31)) && ((e.v) == (0))); return 0; } diff --git a/tests/unit/out/unsafe/nttp_distinct_specializations.rs b/tests/unit/out/unsafe/nttp_distinct_specializations.rs index f9f374e227..72c4559f6c 100644 --- a/tests/unit/out/unsafe/nttp_distinct_specializations.rs +++ b/tests/unit/out/unsafe/nttp_distinct_specializations.rs @@ -22,8 +22,8 @@ pub struct S_2_ { pub w: i32, } impl S_2_ { - pub unsafe fn get(&self) -> i32 { - return ((self.v) - (self.w)); + pub unsafe fn get(this: *const Self) -> i32 { + return (((*this).v) - ((*this).w)); } } #[repr(C)] @@ -41,8 +41,8 @@ pub struct S_1_ { pub v: i32, } impl S_1_ { - pub unsafe fn get(&self) -> i32 { - return ((self.v) * (1)); + pub unsafe fn get(this: *const Self) -> i32 { + return (((*this).v) * (1)); } } #[repr(C)] @@ -60,8 +60,8 @@ pub struct S_3_ { pub v: i32, } impl S_3_ { - pub unsafe fn get(&self) -> i32 { - return ((self.v) * (3)); + pub unsafe fn get(this: *const Self) -> i32 { + return (((*this).v) * (3)); } } pub unsafe fn scale_0(mut x: i32) -> i32 { @@ -101,9 +101,9 @@ unsafe fn main_0() -> i32 { let mut s1: S_1_ = S_1_ { v: 5 }; let mut s2: S_2_ = S_2_ { v: 5, w: 1 }; let mut s3: S_3_ = S_3_ { v: 5 }; - assert!(((unsafe { S_1_::get(&s1,) }) == (5))); - assert!(((unsafe { S_2_::get(&s2,) }) == (4))); - assert!(((unsafe { S_3_::get(&s3,) }) == (15))); + assert!(((unsafe { S_1_::get(&raw const s1,) }) == (5))); + assert!(((unsafe { S_2_::get(&raw const s2,) }) == (4))); + assert!(((unsafe { S_3_::get(&raw const s3,) }) == (15))); assert!(((unsafe { scale_0(7,) }) == (7))); assert!(((unsafe { scale_2(7,) }) == (5))); assert!(((unsafe { scale_1(7,) }) == (21))); diff --git a/tests/unit/out/unsafe/operator_arithmetic_member.rs b/tests/unit/out/unsafe/operator_arithmetic_member.rs index 5cae6acad9..2c3c8bda4b 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_member.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_member.rs @@ -21,53 +21,53 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_add_1(&self, o: *const S) -> S { + pub unsafe fn operator_add_1(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) + ((*o).v)), + v: (((*this).v) + ((*o).v)), }; } - pub unsafe fn operator_sub_2(&self, o: *const S) -> S { + pub unsafe fn operator_sub_2(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) - ((*o).v)), + v: (((*this).v) - ((*o).v)), }; } - pub unsafe fn operator_mul(&self, o: *const S) -> S { + pub unsafe fn operator_mul(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) * ((*o).v)), + v: (((*this).v) * ((*o).v)), }; } - pub unsafe fn operator_div(&self, o: *const S) -> S { + pub unsafe fn operator_div(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) / ((*o).v)), + v: (((*this).v) / ((*o).v)), }; } - pub unsafe fn operator_rem(&self, o: *const S) -> S { + pub unsafe fn operator_rem(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) % ((*o).v)), + v: (((*this).v) % ((*o).v)), }; } - pub unsafe fn operator_pos_6(&self) -> S { - return S { v: self.v }; + pub unsafe fn operator_pos_6(this: *const Self) -> S { + return S { v: (*this).v }; } - pub unsafe fn operator_neg_7(&self) -> S { - return S { v: -self.v }; + pub unsafe fn operator_neg_7(this: *const Self) -> S { + return S { v: -(*this).v }; } - pub unsafe fn operator_inc_8(&mut self) -> *mut S { - self.v.prefix_inc(); - return &mut (*(self as *mut S)); + pub unsafe fn operator_inc_8(this: *mut Self) -> *mut S { + (*this).v.prefix_inc(); + return &mut (*this); } - pub unsafe fn operator_post_inc_9(&mut self, mut _a0: i32) -> S { - let mut old: S = (*(self as *mut S)); - self.v.prefix_inc(); + pub unsafe fn operator_post_inc_9(this: *mut Self, mut _a0: i32) -> S { + let mut old: S = (*this); + (*this).v.prefix_inc(); return old; } - pub unsafe fn operator_dec_10(&mut self) -> *mut S { - self.v.prefix_dec(); - return &mut (*(self as *mut S)); + pub unsafe fn operator_dec_10(this: *mut Self) -> *mut S { + (*this).v.prefix_dec(); + return &mut (*this); } - pub unsafe fn operator_post_dec_11(&mut self, mut _a0: i32) -> S { - let mut old: S = (*(self as *mut S)); - self.v.prefix_dec(); + pub unsafe fn operator_post_dec_11(this: *mut Self, mut _a0: i32) -> S { + let mut old: S = (*this); + (*this).v.prefix_dec(); return old; } } @@ -80,22 +80,24 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: S = S { v: 7 }; let mut b: S = S { v: 2 }; - assert!((((unsafe { S::operator_add_1(&a, &b,) }).v) == (9))); - assert!((((unsafe { S::operator_sub_2(&a, &b,) }).v) == (5))); - assert!((((unsafe { S::operator_mul(&a, &b,) }).v) == (14))); - assert!((((unsafe { S::operator_div(&a, &b,) }).v) == (3))); - assert!((((unsafe { S::operator_rem(&a, &b,) }).v) == (1))); - assert!((((unsafe { S::operator_pos_6(&a,) }).v) == (7))); - assert!((((unsafe { S::operator_neg_7(&a,) }).v) == (-7_i32))); - assert!((((*(unsafe { S::operator_inc_8(&mut a,) })).v) == (8))); - assert!((((unsafe { S::operator_post_inc_9(&mut a, 0,) }).v) == (8))); + assert!((((unsafe { S::operator_add_1(&raw const a, &b,) }).v) == (9))); + assert!((((unsafe { S::operator_sub_2(&raw const a, &b,) }).v) == (5))); + assert!((((unsafe { S::operator_mul(&raw const a, &b,) }).v) == (14))); + assert!((((unsafe { S::operator_div(&raw const a, &b,) }).v) == (3))); + assert!((((unsafe { S::operator_rem(&raw const a, &b,) }).v) == (1))); + assert!((((unsafe { S::operator_pos_6(&raw const a,) }).v) == (7))); + assert!((((unsafe { S::operator_neg_7(&raw const a,) }).v) == (-7_i32))); + assert!((((*(unsafe { S::operator_inc_8(&raw mut a,) })).v) == (8))); + assert!((((unsafe { S::operator_post_inc_9(&raw mut a, 0,) }).v) == (8))); assert!(((a.v) == (9))); - assert!((((*(unsafe { S::operator_dec_10(&mut a,) })).v) == (8))); - assert!((((unsafe { S::operator_post_dec_11(&mut a, 0,) }).v) == (8))); + assert!((((*(unsafe { S::operator_dec_10(&raw mut a,) })).v) == (8))); + assert!((((unsafe { S::operator_post_dec_11(&raw mut a, 0,) }).v) == (8))); assert!(((a.v) == (7))); assert!( - (((*(unsafe { S::operator_inc_8(&mut (*(unsafe { S::operator_inc_8(&mut a,) })),) })).v) - == (9)) + (((*(unsafe { + S::operator_inc_8(&raw mut (*(unsafe { S::operator_inc_8(&raw mut a) }))) + })) + .v) == (9)) ); assert!( (((unsafe { diff --git a/tests/unit/out/unsafe/operator_bitwise_member.rs b/tests/unit/out/unsafe/operator_bitwise_member.rs index df6d2e2d6c..e3907641d2 100644 --- a/tests/unit/out/unsafe/operator_bitwise_member.rs +++ b/tests/unit/out/unsafe/operator_bitwise_member.rs @@ -21,32 +21,32 @@ pub struct S { pub v: u32, } impl S { - pub unsafe fn operator_bitnot(&self) -> S { - return S { v: !self.v }; + pub unsafe fn operator_bitnot(this: *const Self) -> S { + return S { v: !(*this).v }; } - pub unsafe fn operator_bitand(&self, o: *const S) -> S { + pub unsafe fn operator_bitand(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) & ((*o).v)), + v: (((*this).v) & ((*o).v)), }; } - pub unsafe fn operator_bitor(&self, o: *const S) -> S { + pub unsafe fn operator_bitor(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) | ((*o).v)), + v: (((*this).v) | ((*o).v)), }; } - pub unsafe fn operator_bitxor(&self, o: *const S) -> S { + pub unsafe fn operator_bitxor(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) ^ ((*o).v)), + v: (((*this).v) ^ ((*o).v)), }; } - pub unsafe fn operator_shl(&self, mut n: i32) -> S { + pub unsafe fn operator_shl(this: *const Self, mut n: i32) -> S { return S { - v: ((self.v) << (n)), + v: (((*this).v) << (n)), }; } - pub unsafe fn operator_shr(&self, mut n: i32) -> S { + pub unsafe fn operator_shr(this: *const Self, mut n: i32) -> S { return S { - v: ((self.v) >> (n)), + v: (((*this).v) >> (n)), }; } } @@ -59,12 +59,12 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: S = S { v: 12_u32 }; let mut b: S = S { v: 10_u32 }; - assert!((((unsafe { S::operator_bitnot(&a,) }).v) == (!12_u32))); - assert!((((unsafe { S::operator_bitand(&a, &b,) }).v) == (8_u32))); - assert!((((unsafe { S::operator_bitor(&a, &b,) }).v) == (14_u32))); - assert!((((unsafe { S::operator_bitxor(&a, &b,) }).v) == (6_u32))); - assert!((((unsafe { S::operator_shl(&a, 2,) }).v) == (48_u32))); - assert!((((unsafe { S::operator_shr(&a, 2,) }).v) == (3_u32))); + assert!((((unsafe { S::operator_bitnot(&raw const a,) }).v) == (!12_u32))); + assert!((((unsafe { S::operator_bitand(&raw const a, &b,) }).v) == (8_u32))); + assert!((((unsafe { S::operator_bitor(&raw const a, &b,) }).v) == (14_u32))); + assert!((((unsafe { S::operator_bitxor(&raw const a, &b,) }).v) == (6_u32))); + assert!((((unsafe { S::operator_shl(&raw const a, 2,) }).v) == (48_u32))); + assert!((((unsafe { S::operator_shr(&raw const a, 2,) }).v) == (3_u32))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index f9b1fa5a6b..3ed17b1d67 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -22,9 +22,8 @@ pub struct Eq { pub b: i32, } impl Eq { - pub unsafe fn operator_eq(&self, _a0: *const Eq) -> bool { - return (((*(self as *const Eq)).a) == ((*_a0).a)) - && (((*(self as *const Eq)).b) == ((*_a0).b)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const Eq) -> bool { + return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); } } impl std::cmp::PartialEq for Eq { @@ -49,26 +48,23 @@ pub struct Cmp { pub b: i32, } impl Cmp { - pub unsafe fn operator_cmp(&self, _a0: *const Cmp) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Cmp) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Cmp)).a), &((*_a0).a)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Cmp)).b), &((*_a0).b)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).b), &((*_a0).b)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const Cmp) -> bool { - return (((*(self as *const Cmp)).a) == ((*_a0).a)) - && (((*(self as *const Cmp)).b) == ((*_a0).b)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const Cmp) -> bool { + return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); } } impl std::cmp::Ord for Cmp { @@ -102,13 +98,12 @@ pub struct Both { pub a: i32, } impl Both { - pub unsafe fn operator_eq(&self, _a0: *const Both) -> bool { - return (((*(self as *const Both)).a) == ((*_a0).a)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const Both) -> bool { + return (((*this).a) == ((*_a0).a)); } - pub unsafe fn operator_cmp(&self, _a0: *const Both) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Both) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Both)).a), &((*_a0).a)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } @@ -147,10 +142,9 @@ pub struct OrdOnly { pub a: i32, } impl OrdOnly { - pub unsafe fn operator_cmp(&self, _a0: *const OrdOnly) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const OrdOnly) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const OrdOnly)).a), &((*_a0).a)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } @@ -189,18 +183,17 @@ pub struct Inner { pub x: i32, } impl Inner { - pub unsafe fn operator_cmp(&self, _a0: *const Inner) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Inner) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Inner)).x), &((*_a0).x)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).x), &((*_a0).x)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const Inner) -> bool { - return (((*(self as *const Inner)).x) == ((*_a0).x)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const Inner) -> bool { + return (((*this).x) == ((*_a0).x)); } } impl std::cmp::Ord for Inner { @@ -235,30 +228,29 @@ pub struct Outer { pub y: i32, } impl Outer { - pub unsafe fn operator_cmp(&self, _a0: *const Outer) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Outer) -> std::cmp::Ordering { { let mut cmp: std::cmp::Ordering = (unsafe { let _arg0: *const Inner = &(*_a0).i; - Inner::operator_cmp(&(*(self as *const Outer)).i, _arg0) + Inner::operator_cmp(&raw const (*this).i, _arg0) }); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Outer)).y), &((*_a0).y)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).y), &((*_a0).y)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const Outer) -> bool { + pub unsafe fn operator_eq(this: *const Self, _a0: *const Outer) -> bool { return (unsafe { let _arg0: *const Inner = &(*_a0).i; - Inner::operator_eq(&(*(self as *const Outer)).i, _arg0) - }) && (((*(self as *const Outer)).y) == ((*_a0).y)); + Inner::operator_eq(&raw const (*this).i, _arg0) + }) && (((*this).y) == ((*_a0).y)); } } impl std::cmp::Ord for Outer { @@ -292,28 +284,27 @@ pub struct Secondary { pub a: i32, } impl Secondary { - pub unsafe fn operator_eq(&self, _a0: *const Secondary) -> bool { - return (((*(self as *const Secondary)).a) == ((*_a0).a)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const Secondary) -> bool { + return (((*this).a) == ((*_a0).a)); } - pub unsafe fn operator_ne(&self, _a0: *const Secondary) -> bool { - return !(unsafe { Secondary::operator_eq(&(*(self as *const Secondary)), _a0) }); + pub unsafe fn operator_ne(this: *const Self, _a0: *const Secondary) -> bool { + return !(unsafe { Secondary::operator_eq(&raw const (*this), _a0) }); } - pub unsafe fn operator_cmp(&self, _a0: *const Secondary) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Secondary) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Secondary)).a), &((*_a0).a)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_lt(&self, _a0: *const Secondary) -> bool { - return (unsafe { Secondary::operator_cmp(&(*(self as *const Secondary)), _a0) }) + pub unsafe fn operator_lt(this: *const Self, _a0: *const Secondary) -> bool { + return (unsafe { Secondary::operator_cmp(&raw const (*this), _a0) }) == std::cmp::Ordering::Less; } - pub unsafe fn operator_ge(&self, _a0: *const Secondary) -> bool { - return (unsafe { Secondary::operator_cmp(&(*(self as *const Secondary)), _a0) }) + pub unsafe fn operator_ge(this: *const Self, _a0: *const Secondary) -> bool { + return (unsafe { Secondary::operator_cmp(&raw const (*this), _a0) }) != std::cmp::Ordering::Less; } } @@ -348,18 +339,17 @@ pub struct PtrMember { pub p: *mut i32, } impl PtrMember { - pub unsafe fn operator_cmp(&self, _a0: *const PtrMember) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const PtrMember) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const PtrMember)).p), &((*_a0).p)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).p), &((*_a0).p)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const PtrMember) -> bool { - return (((*(self as *const PtrMember)).p) == ((*_a0).p)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const PtrMember) -> bool { + return (((*this).p) == ((*_a0).p)); } } impl std::cmp::Ord for PtrMember { @@ -390,34 +380,37 @@ unsafe fn main_0() -> i32 { let mut e1: Eq = Eq { a: 1, b: 2 }; let mut e2: Eq = Eq { a: 1, b: 2 }; let mut e3: Eq = Eq { a: 1, b: 3 }; - assert!((unsafe { Eq::operator_eq(&e1, &e2,) })); - assert!(!(unsafe { Eq::operator_eq(&e1, &e3,) })); + assert!((unsafe { Eq::operator_eq(&raw const e1, &e2,) })); + assert!(!(unsafe { Eq::operator_eq(&raw const e1, &e3,) })); let mut c1: Cmp = Cmp { a: 1, b: 2 }; let mut c2: Cmp = Cmp { a: 1, b: 3 }; let mut c3: Cmp = Cmp { a: 2, b: 0 }; let mut c4: Cmp = Cmp { a: 1, b: 9 }; - assert!((unsafe { Cmp::operator_cmp(&c1, &c2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { Cmp::operator_cmp(&c3, &c4,) }) == std::cmp::Ordering::Greater); + assert!((unsafe { Cmp::operator_cmp(&raw const c1, &c2,) }) == std::cmp::Ordering::Less); + assert!((unsafe { Cmp::operator_cmp(&raw const c3, &c4,) }) == std::cmp::Ordering::Greater); assert!( (unsafe { let _arg0: *const Cmp = &c1; - Cmp::operator_eq(&c1, _arg0) + Cmp::operator_eq(&raw const c1, _arg0) }) ); - assert!((unsafe { Cmp::operator_cmp(&c1, &c2,) }) == libcc2rs::STRONG_ORDERING_LESS); + assert!((unsafe { Cmp::operator_cmp(&raw const c1, &c2,) }) == libcc2rs::STRONG_ORDERING_LESS); let mut b1: Both = Both { a: 1 }; let mut b2: Both = Both { a: 2 }; - assert!((unsafe { Both::operator_cmp(&b1, &b2,) }) == std::cmp::Ordering::Less); + assert!((unsafe { Both::operator_cmp(&raw const b1, &b2,) }) == std::cmp::Ordering::Less); assert!( (unsafe { let _arg0: *const Both = &b2; - Both::operator_eq(&b2, _arg0) + Both::operator_eq(&raw const b2, _arg0) }) ); let mut o1: OrdOnly = OrdOnly { a: 1 }; let mut o2: OrdOnly = OrdOnly { a: 2 }; - assert!((unsafe { OrdOnly::operator_cmp(&o1, &o2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { OrdOnly::operator_cmp(&o2, &o1,) }) == libcc2rs::STRONG_ORDERING_GREATER); + assert!((unsafe { OrdOnly::operator_cmp(&raw const o1, &o2,) }) == std::cmp::Ordering::Less); + assert!( + (unsafe { OrdOnly::operator_cmp(&raw const o2, &o1,) }) + == libcc2rs::STRONG_ORDERING_GREATER + ); let mut x1: Outer = Outer { i: Inner { x: 1 }, y: 9, @@ -430,15 +423,17 @@ unsafe fn main_0() -> i32 { i: Inner { x: 1 }, y: 9, }; - assert!((unsafe { Outer::operator_cmp(&x1, &x2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { Outer::operator_eq(&x1, &x3,) })); - assert!((unsafe { Outer::operator_cmp(&x2, &x1,) }) == libcc2rs::STRONG_ORDERING_GREATER); + assert!((unsafe { Outer::operator_cmp(&raw const x1, &x2,) }) == std::cmp::Ordering::Less); + assert!((unsafe { Outer::operator_eq(&raw const x1, &x3,) })); + assert!( + (unsafe { Outer::operator_cmp(&raw const x2, &x1,) }) == libcc2rs::STRONG_ORDERING_GREATER + ); let mut s1: Secondary = Secondary { a: 1 }; let mut s2: Secondary = Secondary { a: 2 }; - assert!((unsafe { Secondary::operator_ne(&s1, &s2,) })); - assert!((unsafe { Secondary::operator_lt(&s1, &s2,) })); - assert!((unsafe { Secondary::operator_ge(&s2, &s1,) })); - assert!(!(unsafe { Secondary::operator_lt(&s2, &s1,) })); + assert!((unsafe { Secondary::operator_ne(&raw const s1, &s2,) })); + assert!((unsafe { Secondary::operator_lt(&raw const s1, &s2,) })); + assert!((unsafe { Secondary::operator_ge(&raw const s2, &s1,) })); + assert!(!(unsafe { Secondary::operator_lt(&raw const s2, &s1,) })); let mut arr: [i32; 2] = [0, 0]; let mut p1: PtrMember = PtrMember { p: arr.as_mut_ptr(), @@ -449,9 +444,12 @@ unsafe fn main_0() -> i32 { let mut p3: PtrMember = PtrMember { p: arr.as_mut_ptr(), }; - assert!((unsafe { PtrMember::operator_cmp(&p1, &p2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { PtrMember::operator_eq(&p1, &p3,) })); - assert!((unsafe { PtrMember::operator_cmp(&p2, &p1,) }) == libcc2rs::STRONG_ORDERING_GREATER); + assert!((unsafe { PtrMember::operator_cmp(&raw const p1, &p2,) }) == std::cmp::Ordering::Less); + assert!((unsafe { PtrMember::operator_eq(&raw const p1, &p3,) })); + assert!( + (unsafe { PtrMember::operator_cmp(&raw const p2, &p1,) }) + == libcc2rs::STRONG_ORDERING_GREATER + ); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_member.rs b/tests/unit/out/unsafe/operator_comparison_member.rs index 8f040647f7..8901e9a173 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -21,26 +21,26 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_eq(&self, o: *const S) -> bool { - return ((self.v) == ((*o).v)); + pub unsafe fn operator_eq(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); } - pub unsafe fn operator_ne(&self, o: *const S) -> bool { - return ((self.v) != ((*o).v)); + pub unsafe fn operator_ne(this: *const Self, o: *const S) -> bool { + return (((*this).v) != ((*o).v)); } - pub unsafe fn operator_lt_3(&self, o: *const S) -> bool { - return ((self.v) < ((*o).v)); + pub unsafe fn operator_lt_3(this: *const Self, o: *const S) -> bool { + return (((*this).v) < ((*o).v)); } - pub unsafe fn operator_gt(&self, o: *const S) -> bool { - return ((self.v) > ((*o).v)); + pub unsafe fn operator_gt(this: *const Self, o: *const S) -> bool { + return (((*this).v) > ((*o).v)); } - pub unsafe fn operator_le(&self, o: *const S) -> bool { - return ((self.v) <= ((*o).v)); + pub unsafe fn operator_le(this: *const Self, o: *const S) -> bool { + return (((*this).v) <= ((*o).v)); } - pub unsafe fn operator_ge(&self, o: *const S) -> bool { - return ((self.v) >= ((*o).v)); + pub unsafe fn operator_ge(this: *const Self, o: *const S) -> bool { + return (((*this).v) >= ((*o).v)); } - pub unsafe fn operator_lt_7(&self, mut o: i32) -> bool { - return ((self.v) < (o)); + pub unsafe fn operator_lt_7(this: *const Self, mut o: i32) -> bool { + return (((*this).v) < (o)); } } impl std::cmp::Ord for S { @@ -77,14 +77,14 @@ unsafe fn main_0() -> i32 { let mut a: S = S { v: 1 }; let mut b: S = S { v: 2 }; let mut c: S = S { v: 1 }; - assert!((unsafe { S::operator_eq(&a, &c,) })); - assert!((unsafe { S::operator_ne(&a, &b,) })); - assert!((unsafe { S::operator_lt_3(&a, &b,) })); - assert!((unsafe { S::operator_gt(&b, &a,) })); - assert!((unsafe { S::operator_le(&a, &c,) })); - assert!((unsafe { S::operator_ge(&a, &c,) })); - assert!(!(unsafe { S::operator_lt_3(&b, &a,) })); - assert!((unsafe { S::operator_lt_7(&a, 5,) })); + assert!((unsafe { S::operator_eq(&raw const a, &c,) })); + assert!((unsafe { S::operator_ne(&raw const a, &b,) })); + assert!((unsafe { S::operator_lt_3(&raw const a, &b,) })); + assert!((unsafe { S::operator_gt(&raw const b, &a,) })); + assert!((unsafe { S::operator_le(&raw const a, &c,) })); + assert!((unsafe { S::operator_ge(&raw const a, &c,) })); + assert!(!(unsafe { S::operator_lt_3(&raw const b, &a,) })); + assert!((unsafe { S::operator_lt_7(&raw const a, 5,) })); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_mixed.rs b/tests/unit/out/unsafe/operator_comparison_mixed.rs index eecee4a3b6..d70ad8a71d 100644 --- a/tests/unit/out/unsafe/operator_comparison_mixed.rs +++ b/tests/unit/out/unsafe/operator_comparison_mixed.rs @@ -21,23 +21,23 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_eq(&self, mut o: i32) -> bool { - return ((self.v) == (o)); + pub unsafe fn operator_eq(this: *const Self, mut o: i32) -> bool { + return (((*this).v) == (o)); } - pub unsafe fn operator_ne(&self, mut o: i32) -> bool { - return ((self.v) != (o)); + pub unsafe fn operator_ne(this: *const Self, mut o: i32) -> bool { + return (((*this).v) != (o)); } - pub unsafe fn operator_lt(&self, mut o: i32) -> bool { - return ((self.v) < (o)); + pub unsafe fn operator_lt(this: *const Self, mut o: i32) -> bool { + return (((*this).v) < (o)); } - pub unsafe fn operator_gt(&self, mut o: f64) -> bool { - return ((self.v as f64) > (o)); + pub unsafe fn operator_gt(this: *const Self, mut o: f64) -> bool { + return (((*this).v as f64) > (o)); } - pub unsafe fn operator_le(&self, mut o: i64) -> bool { - return ((self.v as i64) <= (o)); + pub unsafe fn operator_le(this: *const Self, mut o: i64) -> bool { + return (((*this).v as i64) <= (o)); } - pub unsafe fn operator_ge(&self, mut o: *const libc::c_char) -> bool { - return ((self.v) >= (((*o) as i32) - (('0' as libc::c_char) as i32))); + pub unsafe fn operator_ge(this: *const Self, mut o: *const libc::c_char) -> bool { + return (((*this).v) >= (((*o) as i32) - (('0' as libc::c_char) as i32))); } } pub unsafe fn operator_eq_0(mut a: i32, b: *const S) -> bool { @@ -70,12 +70,12 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut s: S = S { v: 5 }; let cs: *const S = &s; - assert!((unsafe { S::operator_eq(&(*cs), 5,) })); - assert!((unsafe { S::operator_ne(&(*cs), 4,) })); - assert!((unsafe { S::operator_lt(&(*cs), 6,) })); - assert!((unsafe { S::operator_gt(&(*cs), 4.5_f64,) })); - assert!((unsafe { S::operator_le(&(*cs), 5_i64,) })); - assert!((unsafe { S::operator_ge(&(*cs), c"3".as_ptr(),) })); + assert!((unsafe { S::operator_eq(&raw const (*cs), 5,) })); + assert!((unsafe { S::operator_ne(&raw const (*cs), 4,) })); + assert!((unsafe { S::operator_lt(&raw const (*cs), 6,) })); + assert!((unsafe { S::operator_gt(&raw const (*cs), 4.5_f64,) })); + assert!((unsafe { S::operator_le(&raw const (*cs), 5_i64,) })); + assert!((unsafe { S::operator_ge(&raw const (*cs), c"3".as_ptr(),) })); assert!((unsafe { operator_eq_0(5, &s,) })); assert!((unsafe { operator_ne_1(4, &s,) })); assert!((unsafe { operator_lt_2(4, &s,) })); diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index 3c1fd305f9..dec785d640 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -91,9 +91,9 @@ pub struct Custom { pub v: i32, } impl Custom { - pub unsafe fn operator_cmp(&self, o: *const Custom) -> Result { + pub unsafe fn operator_cmp(this: *const Self, o: *const Custom) -> Result { return Result { - r: ((self.v) - ((*o).v)), + r: (((*this).v) - ((*o).v)), }; } } @@ -112,16 +112,16 @@ pub struct Mixed { pub v: i32, } impl Mixed { - pub unsafe fn operator_cmp(&self, o: *const Mixed) -> Result { + pub unsafe fn operator_cmp(this: *const Self, o: *const Mixed) -> Result { return Result { - r: ((self.v) - ((*o).v)), + r: (((*this).v) - ((*o).v)), }; } - pub unsafe fn operator_lt(&self, o: *const Mixed) -> i32 { - return if ((self.v) < ((*o).v)) { 8 } else { 0 }; + pub unsafe fn operator_lt(this: *const Self, o: *const Mixed) -> i32 { + return if (((*this).v) < ((*o).v)) { 8 } else { 0 }; } - pub unsafe fn operator_eq(&self, o: *const Mixed) -> i32 { - return if ((self.v) == ((*o).v)) { 9 } else { 0 }; + pub unsafe fn operator_eq(this: *const Self, o: *const Mixed) -> i32 { + return if (((*this).v) == ((*o).v)) { 9 } else { 0 }; } } impl std::cmp::Ord for Mixed { @@ -165,11 +165,11 @@ pub struct MyBool { pub value: bool, } impl MyBool { - pub unsafe fn construct(&mut self, mut v: bool) { - (&raw mut self.value).write(v); + pub unsafe fn construct(this: *mut Self, mut v: bool) { + (&raw mut (*this).value).write(v); } - pub unsafe fn to_bool(&self) -> bool { - return self.value; + pub unsafe fn to_bool(this: *const Self) -> bool { + return (*this).value; } } #[repr(C)] @@ -224,14 +224,14 @@ impl std::cmp::Eq for Boolish {} pub unsafe fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { let mut __v: MyBool = ::zero_init(); - MyBool::construct(&mut __v, ((a.v) == (b.v))); + MyBool::construct(&raw mut __v, ((a.v) == (b.v))); __v }; } pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { let mut __v: MyBool = ::zero_init(); - MyBool::construct(&mut __v, ((a.v) < (b.v))); + MyBool::construct(&raw mut __v, ((a.v) < (b.v))); __v }; } @@ -251,17 +251,17 @@ pub struct RefBool { pub value: bool, } impl RefBool { - pub unsafe fn construct(&mut self, mut v: bool) { - (&raw mut self.value).write(v); + pub unsafe fn construct(this: *mut Self, mut v: bool) { + (&raw mut (*this).value).write(v); } - pub unsafe fn to_bool(&self) -> bool { - return self.value; + pub unsafe fn to_bool(this: *const Self) -> bool { + return (*this).value; } } pub static mut ref_true_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: RefBool = ::zero_init(); - RefBool::construct(&mut __v, true); + RefBool::construct(&raw mut __v, true); __v } }); @@ -280,7 +280,7 @@ pub struct RefInt { pub v: i32, } impl RefInt { - pub unsafe fn operator_eq(&self, _a0: *const RefInt) -> *mut RefBool { + pub unsafe fn operator_eq(this: *const Self, _a0: *const RefInt) -> *mut RefBool { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut ref_true_8)); } } @@ -367,12 +367,12 @@ unsafe fn main_0() -> i32 { ); let mut p: Custom = Custom { v: 5 }; let mut q: Custom = Custom { v: 2 }; - let mut r: Result = (unsafe { Custom::operator_cmp(&p, &q) }); + let mut r: Result = (unsafe { Custom::operator_cmp(&raw const p, &q) }); assert!(((r.r) == (3))); let mut m: Mixed = Mixed { v: 4 }; let mut n: Mixed = Mixed { v: 4 }; - assert!(((unsafe { Mixed::operator_eq(&m, &n,) }) == (9))); - assert!((((unsafe { Mixed::operator_cmp(&m, &n,) }).r) == (0))); + assert!(((unsafe { Mixed::operator_eq(&raw const m, &n,) }) == (9))); + assert!((((unsafe { Mixed::operator_cmp(&raw const m, &n,) }).r) == (0))); let mut ms: [Mixed; 3] = [Mixed { v: 6 }, Mixed { v: 4 }, Mixed { v: 5 }]; { let mut __tmp_1 = { ms.as_mut_ptr() }; @@ -394,7 +394,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let _o: *const Mixed = &ms[(1) as usize]; - Mixed::operator_lt(&ms[(0) as usize], _o) + Mixed::operator_lt(&raw const ms[(0) as usize], _o) }) == (8)) ); let mut b1: Boolish = Boolish { v: 1 }; @@ -444,7 +444,11 @@ unsafe fn main_0() -> i32 { ); let mut ri1: RefInt = RefInt { v: 1 }; let mut ri2: RefInt = RefInt { v: 2 }; - assert!((unsafe { RefBool::to_bool(&(*(unsafe { RefInt::operator_eq(&ri1, &ri2,) })),) })); + assert!( + (unsafe { + RefBool::to_bool(&raw const (*(unsafe { RefInt::operator_eq(&raw const ri1, &ri2) }))) + }) + ); let mut ris: [RefInt; 2] = [RefInt { v: 1 }, RefInt { v: 2 }]; assert!( (({ diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index 7a34aa7e3a..8da1438508 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -27,8 +27,8 @@ pub struct S { data_: i32, } impl S { - pub unsafe fn construct(&mut self, mut data: i32) { - (&raw mut self.data_).write(data); + pub unsafe fn construct(this: *mut Self, mut data: i32) { + (&raw mut (*this).data_).write(data); } } impl std::cmp::Ord for S { diff --git a/tests/unit/out/unsafe/operator_compound_assignment_member.rs b/tests/unit/out/unsafe/operator_compound_assignment_member.rs index 3989e666b1..6cc08edab3 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_member.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_member.rs @@ -21,49 +21,49 @@ pub struct S { pub v: u32, } impl S { - pub unsafe fn operator_assign_1(&mut self, mut n: u32) -> *mut S { - self.v = n; - return &mut (*(self as *mut S)); + pub unsafe fn operator_assign_1(this: *mut Self, mut n: u32) -> *mut S { + (*this).v = n; + return &mut (*this); } - pub unsafe fn operator_add_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_add((*o).v); - return &mut (*(self as *mut S)); + pub unsafe fn operator_add_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v = ((*this).v).wrapping_add((*o).v); + return &mut (*this); } - pub unsafe fn operator_sub_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_sub((*o).v); - return &mut (*(self as *mut S)); + pub unsafe fn operator_sub_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v = ((*this).v).wrapping_sub((*o).v); + return &mut (*this); } - pub unsafe fn operator_mul_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_mul((*o).v); - return &mut (*(self as *mut S)); + pub unsafe fn operator_mul_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v = ((*this).v).wrapping_mul((*o).v); + return &mut (*this); } - pub unsafe fn operator_div_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_div((*o).v); - return &mut (*(self as *mut S)); + pub unsafe fn operator_div_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v = ((*this).v).wrapping_div((*o).v); + return &mut (*this); } - pub unsafe fn operator_rem_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_rem((*o).v); - return &mut (*(self as *mut S)); + pub unsafe fn operator_rem_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v = ((*this).v).wrapping_rem((*o).v); + return &mut (*this); } - pub unsafe fn operator_bitand_assign(&mut self, o: *const S) -> *mut S { - self.v &= (*o).v; - return &mut (*(self as *mut S)); + pub unsafe fn operator_bitand_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v &= (*o).v; + return &mut (*this); } - pub unsafe fn operator_bitor_assign(&mut self, o: *const S) -> *mut S { - self.v |= (*o).v; - return &mut (*(self as *mut S)); + pub unsafe fn operator_bitor_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v |= (*o).v; + return &mut (*this); } - pub unsafe fn operator_bitxor_assign(&mut self, o: *const S) -> *mut S { - self.v ^= (*o).v; - return &mut (*(self as *mut S)); + pub unsafe fn operator_bitxor_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v ^= (*o).v; + return &mut (*this); } - pub unsafe fn operator_shl_assign(&mut self, mut n: i32) -> *mut S { - self.v <<= n; - return &mut (*(self as *mut S)); + pub unsafe fn operator_shl_assign(this: *mut Self, mut n: i32) -> *mut S { + (*this).v <<= n; + return &mut (*this); } - pub unsafe fn operator_shr_assign(&mut self, mut n: i32) -> *mut S { - self.v >>= n; - return &mut (*(self as *mut S)); + pub unsafe fn operator_shr_assign(this: *mut Self, mut n: i32) -> *mut S { + (*this).v >>= n; + return &mut (*this); } } pub fn main() { @@ -75,35 +75,38 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: S = S { v: 6_u32 }; let mut b: S = S { v: 4_u32 }; - (unsafe { S::operator_add_assign(&mut a, &b) }); + (unsafe { S::operator_add_assign(&raw mut a, &b) }); assert!(((a.v) == (10_u32))); - (unsafe { S::operator_sub_assign(&mut a, &b) }); + (unsafe { S::operator_sub_assign(&raw mut a, &b) }); assert!(((a.v) == (6_u32))); - (unsafe { S::operator_mul_assign(&mut a, &b) }); + (unsafe { S::operator_mul_assign(&raw mut a, &b) }); assert!(((a.v) == (24_u32))); - (unsafe { S::operator_div_assign(&mut a, &b) }); + (unsafe { S::operator_div_assign(&raw mut a, &b) }); assert!(((a.v) == (6_u32))); - (unsafe { S::operator_rem_assign(&mut a, &b) }); + (unsafe { S::operator_rem_assign(&raw mut a, &b) }); assert!(((a.v) == (2_u32))); - (unsafe { S::operator_bitor_assign(&mut a, &b) }); + (unsafe { S::operator_bitor_assign(&raw mut a, &b) }); assert!(((a.v) == (6_u32))); - (unsafe { S::operator_bitand_assign(&mut a, &b) }); + (unsafe { S::operator_bitand_assign(&raw mut a, &b) }); assert!(((a.v) == (4_u32))); - (unsafe { S::operator_bitxor_assign(&mut a, &b) }); + (unsafe { S::operator_bitxor_assign(&raw mut a, &b) }); assert!(((a.v) == (0_u32))); - (unsafe { S::operator_assign_1(&mut a, 3_u32) }); + (unsafe { S::operator_assign_1(&raw mut a, 3_u32) }); assert!(((a.v) == (3_u32))); - (unsafe { S::operator_shl_assign(&mut a, 2) }); + (unsafe { S::operator_shl_assign(&raw mut a, 2) }); assert!(((a.v) == (12_u32))); - (unsafe { S::operator_shr_assign(&mut a, 1) }); + (unsafe { S::operator_shr_assign(&raw mut a, 1) }); assert!(((a.v) == (6_u32))); (unsafe { let _o: *const S = &b; - S::operator_add_assign(&mut (*(unsafe { S::operator_add_assign(&mut a, &b) })), _o) + S::operator_add_assign( + &raw mut (*(unsafe { S::operator_add_assign(&raw mut a, &b) })), + _o, + ) }); assert!(((a.v) == (14_u32))); let mut c: S = S { v: 0_u32 }; - c = (*(unsafe { S::operator_assign_1(&mut a, 1_u32) })); + c = (*(unsafe { S::operator_assign_1(&raw mut a, 1_u32) })); assert!(((a.v) == (1_u32))); assert!(((c.v) == (1_u32))); return 0; diff --git a/tests/unit/out/unsafe/operator_less_than.rs b/tests/unit/out/unsafe/operator_less_than.rs index 6f57bf5217..5bf2faffa5 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.rs @@ -22,17 +22,17 @@ pub struct Pair { pub y: i32, } impl Pair { - pub unsafe fn operator_lt(&mut self, other: *const Pair) -> bool { - return ((self.x) < ((*other).x)) - || (((self.x) == ((*other).x)) && ((self.y) < ((*other).y))); + pub unsafe fn operator_lt(this: *mut Self, other: *const Pair) -> bool { + return (((*this).x) < ((*other).x)) + || ((((*this).x) == ((*other).x)) && (((*this).y) < ((*other).y))); } } impl std::cmp::Ord for Pair { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if Pair::operator_lt(&mut *(&raw const *self).cast_mut(), other as *const Pair) { + if Pair::operator_lt((&raw const *self).cast_mut(), other as *const Pair) { std::cmp::Ordering::Less - } else if Pair::operator_lt(&mut *(&raw const *other).cast_mut(), self as *const Pair) { + } else if Pair::operator_lt((&raw const *other).cast_mut(), self as *const Pair) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -48,8 +48,8 @@ impl std::cmp::PartialOrd for Pair { impl std::cmp::PartialEq for Pair { fn eq(&self, other: &Self) -> bool { unsafe { - !(Pair::operator_lt(&mut *(&raw const *self).cast_mut(), other as *const Pair)) - && !(Pair::operator_lt(&mut *(&raw const *other).cast_mut(), self as *const Pair)) + !(Pair::operator_lt((&raw const *self).cast_mut(), other as *const Pair)) + && !(Pair::operator_lt((&raw const *other).cast_mut(), self as *const Pair)) } } } @@ -63,7 +63,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut pair1: Pair = Pair { x: 1, y: 2 }; let mut pair2: Pair = Pair { x: 1, y: 3 }; - assert!((unsafe { Pair::operator_lt(&mut pair1, &pair2,) })); + assert!((unsafe { Pair::operator_lt(&raw mut pair1, &pair2,) })); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_logical_member.rs b/tests/unit/out/unsafe/operator_logical_member.rs index 562497a560..839cbe90ce 100644 --- a/tests/unit/out/unsafe/operator_logical_member.rs +++ b/tests/unit/out/unsafe/operator_logical_member.rs @@ -21,14 +21,14 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_not(&self) -> bool { - return ((self.v) == (0)); + pub unsafe fn operator_not(this: *const Self) -> bool { + return (((*this).v) == (0)); } - pub unsafe fn operator_and(&self, o: *const S) -> bool { - return ((self.v) != (0)) && (((*o).v) != (0)); + pub unsafe fn operator_and(this: *const Self, o: *const S) -> bool { + return (((*this).v) != (0)) && (((*o).v) != (0)); } - pub unsafe fn operator_or(&self, o: *const S) -> bool { - return ((self.v) != (0)) || (((*o).v) != (0)); + pub unsafe fn operator_or(this: *const Self, o: *const S) -> bool { + return (((*this).v) != (0)) || (((*o).v) != (0)); } } pub fn main() { @@ -40,20 +40,20 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut t: S = S { v: 1 }; let mut f: S = S { v: 0 }; - assert!((unsafe { S::operator_not(&f,) })); - assert!(!(unsafe { S::operator_not(&t,) })); + assert!((unsafe { S::operator_not(&raw const f,) })); + assert!(!(unsafe { S::operator_not(&raw const t,) })); assert!( (unsafe { let _o: *const S = &t; - S::operator_and(&t, _o) + S::operator_and(&raw const t, _o) }) ); - assert!(!(unsafe { S::operator_and(&t, &f,) })); - assert!((unsafe { S::operator_or(&t, &f,) })); + assert!(!(unsafe { S::operator_and(&raw const t, &f,) })); + assert!((unsafe { S::operator_or(&raw const t, &f,) })); assert!( !(unsafe { let _o: *const S = &f; - S::operator_or(&f, _o) + S::operator_or(&raw const f, _o) }) ); return 0; diff --git a/tests/unit/out/unsafe/operator_member_pointer_member.rs b/tests/unit/out/unsafe/operator_member_pointer_member.rs index 1da1aa4c95..acd45f374d 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_member.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_member.rs @@ -55,20 +55,20 @@ pub struct S { pub inner: Inner, } impl S { - pub unsafe fn operator_index_1(&mut self, mut i: i32) -> *mut i32 { - return &mut self.data[(i) as usize]; + pub unsafe fn operator_index_1(this: *mut Self, mut i: i32) -> *mut i32 { + return &mut (*this).data[(i) as usize]; } - pub unsafe fn operator_index_2(&self, mut i: i32) -> *const i32 { - return &self.data[(i) as usize]; + pub unsafe fn operator_index_2(this: *const Self, mut i: i32) -> *const i32 { + return &(*this).data[(i) as usize]; } - pub unsafe fn operator_deref(&mut self) -> *mut Inner { - return &mut self.inner; + pub unsafe fn operator_deref(this: *mut Self) -> *mut Inner { + return &mut (*this).inner; } - pub unsafe fn operator_arrow(&mut self) -> *mut Inner { - return (&mut self.inner as *mut Inner); + pub unsafe fn operator_arrow(this: *mut Self) -> *mut Inner { + return (&mut (*this).inner as *mut Inner); } - pub unsafe fn operator_addr(&mut self) -> *mut i32 { - return (&mut self.data[(0) as usize] as *mut i32); + pub unsafe fn operator_addr(this: *mut Self) -> *mut i32 { + return (&mut (*this).data[(0) as usize] as *mut i32); } } pub fn main() { @@ -82,17 +82,17 @@ unsafe fn main_0() -> i32 { data: [1, 2, 3], inner: Inner { x: 9 }, }; - assert!(((*(unsafe { S::operator_index_1(&mut s, 1,) })) == (2))); - (*(unsafe { S::operator_index_1(&mut s, 1) })) = 20; - assert!(((*(unsafe { S::operator_index_1(&mut s, 1,) })) == (20))); + assert!(((*(unsafe { S::operator_index_1(&raw mut s, 1,) })) == (2))); + (*(unsafe { S::operator_index_1(&raw mut s, 1) })) = 20; + assert!(((*(unsafe { S::operator_index_1(&raw mut s, 1,) })) == (20))); let cs: *const S = &s; - assert!(((*(unsafe { S::operator_index_2(&(*cs), 2,) })) == (3))); - assert!((((*(unsafe { S::operator_deref(&mut s,) })).x) == (9))); - (*(unsafe { S::operator_deref(&mut s) })).x = 10; - assert!((((*(unsafe { S::operator_arrow(&mut s,) })).x) == (10))); - (*(unsafe { S::operator_arrow(&mut s) })).x = 11; + assert!(((*(unsafe { S::operator_index_2(&raw const (*cs), 2,) })) == (3))); + assert!((((*(unsafe { S::operator_deref(&raw mut s,) })).x) == (9))); + (*(unsafe { S::operator_deref(&raw mut s) })).x = 10; + assert!((((*(unsafe { S::operator_arrow(&raw mut s,) })).x) == (10))); + (*(unsafe { S::operator_arrow(&raw mut s) })).x = 11; assert!(((s.inner.x) == (11))); - let mut p: *mut i32 = (unsafe { S::operator_addr(&mut s) }); + let mut p: *mut i32 = (unsafe { S::operator_addr(&raw mut s) }); assert!(((*p) == (1))); (*p) = 5; assert!(((s.data[(0) as usize]) == (5))); diff --git a/tests/unit/out/unsafe/operator_other_member.rs b/tests/unit/out/unsafe/operator_other_member.rs index c20b77e1cd..06b1da4f26 100644 --- a/tests/unit/out/unsafe/operator_other_member.rs +++ b/tests/unit/out/unsafe/operator_other_member.rs @@ -40,25 +40,25 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_call_1(&self) -> i32 { - return self.v; + pub unsafe fn operator_call_1(this: *const Self) -> i32 { + return (*this).v; } - pub unsafe fn operator_call_2(&self, mut a: i32) -> i32 { - return ((self.v) + (a)); + pub unsafe fn operator_call_2(this: *const Self, mut a: i32) -> i32 { + return (((*this).v) + (a)); } - pub unsafe fn operator_call_3(&self, mut a: i32, mut b: i32) -> i32 { - return (((self.v) + (a)) + (b)); + pub unsafe fn operator_call_3(this: *const Self, mut a: i32, mut b: i32) -> i32 { + return ((((*this).v) + (a)) + (b)); } - pub unsafe fn operator_comma(&self, o: *const S) -> S { + pub unsafe fn operator_comma(this: *const Self, o: *const S) -> S { return S { - v: (((self.v) * (10)) + ((*o).v)), + v: ((((*this).v) * (10)) + ((*o).v)), }; } - pub unsafe fn to_i32(&self) -> i32 { - return self.v; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).v; } - pub unsafe fn to_bool(&self) -> bool { - return ((self.v) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).v) != (0)); } } pub fn main() { @@ -70,22 +70,22 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut s: S = S { v: 3 }; let mut t: S = S { v: 4 }; - assert!(((unsafe { S::operator_call_1(&s,) }) == (3))); - assert!(((unsafe { S::operator_call_2(&s, 1,) }) == (4))); - assert!(((unsafe { S::operator_call_3(&s, 1, 2,) }) == (6))); - assert!((((unsafe { S::operator_comma(&s, &t,) }).v) == (34))); - let mut i: i32 = (unsafe { S::to_i32(&s) }); + assert!(((unsafe { S::operator_call_1(&raw const s,) }) == (3))); + assert!(((unsafe { S::operator_call_2(&raw const s, 1,) }) == (4))); + assert!(((unsafe { S::operator_call_3(&raw const s, 1, 2,) }) == (6))); + assert!((((unsafe { S::operator_comma(&raw const s, &t,) }).v) == (34))); + let mut i: i32 = (unsafe { S::to_i32(&raw const s) }); assert!(((i) == (3))); - assert!((((unsafe { S::to_i32(&s,) }) + (1)) == (4))); - if (unsafe { S::to_bool(&s) }) { - assert!((unsafe { S::to_bool(&s,) })); + assert!((((unsafe { S::to_i32(&raw const s,) }) + (1)) == (4))); + if (unsafe { S::to_bool(&raw const s) }) { + assert!((unsafe { S::to_bool(&raw const s,) })); } else { assert!(false); } let mut z: S = S { v: 0 }; - assert!((unsafe { S::to_bool(&s,) })); - assert!(!(unsafe { S::to_bool(&z,) })); - assert!((unsafe { S::to_bool(&s,) }) && (!(unsafe { S::to_bool(&z,) }))); + assert!((unsafe { S::to_bool(&raw const s,) })); + assert!(!(unsafe { S::to_bool(&raw const z,) })); + assert!((unsafe { S::to_bool(&raw const s,) }) && (!(unsafe { S::to_bool(&raw const z,) }))); let mut st: Static = ::default(); assert!(((unsafe { Static::operator_call(6, 7,) }) == (42))); assert!(((unsafe { S::operator_call_1(&S { v: 5 },) }) == (5))); diff --git a/tests/unit/out/unsafe/operator_overloads.rs b/tests/unit/out/unsafe/operator_overloads.rs index fc09de884e..297a4a697c 100644 --- a/tests/unit/out/unsafe/operator_overloads.rs +++ b/tests/unit/out/unsafe/operator_overloads.rs @@ -21,26 +21,26 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_eq_1(&self, mut o: i32) -> i32 { - return if ((self.v) == (o)) { 1 } else { 0 }; + pub unsafe fn operator_eq_1(this: *const Self, mut o: i32) -> i32 { + return if (((*this).v) == (o)) { 1 } else { 0 }; } - pub unsafe fn operator_eq_2(&self, mut o: i64) -> i32 { - return if ((self.v as i64) == (o)) { 2 } else { 0 }; + pub unsafe fn operator_eq_2(this: *const Self, mut o: i64) -> i32 { + return if (((*this).v as i64) == (o)) { 2 } else { 0 }; } - pub unsafe fn operator_eq_3(&self, mut o: f64) -> i32 { - return if ((self.v as f64) == (o)) { 3 } else { 0 }; + pub unsafe fn operator_eq_3(this: *const Self, mut o: f64) -> i32 { + return if (((*this).v as f64) == (o)) { 3 } else { 0 }; } - pub unsafe fn operator_add(&self, o: *const S) -> i32 { - return ((self.v) + ((*o).v)); + pub unsafe fn operator_add(this: *const Self, o: *const S) -> i32 { + return (((*this).v) + ((*o).v)); } - pub unsafe fn operator_sub(&self, mut o: S) -> i32 { - return ((self.v) - (o.v)); + pub unsafe fn operator_sub(this: *const Self, mut o: S) -> i32 { + return (((*this).v) - (o.v)); } - pub unsafe fn operator_mul_6(&self, o: *const S) -> i32 { - return ((self.v) * ((*o).v)); + pub unsafe fn operator_mul_6(this: *const Self, o: *const S) -> i32 { + return (((*this).v) * ((*o).v)); } - pub unsafe fn operator_mul_7(&self, mut o: i32) -> i32 { - return (((self.v) * (o)) + (1)); + pub unsafe fn operator_mul_7(this: *const Self, mut o: i32) -> i32 { + return ((((*this).v) * (o)) + (1)); } } pub unsafe fn operator_div_0(a: *const S, b: *const S) -> i32 { @@ -70,14 +70,14 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut s: S = S { v: 6 }; let mut t: S = S { v: 4 }; - assert!(((unsafe { S::operator_eq_1(&s, 6,) }) == (1))); - assert!(((unsafe { S::operator_eq_2(&s, 6_i64,) }) == (2))); - assert!(((unsafe { S::operator_eq_3(&s, 6_f64,) }) == (3))); - assert!(((unsafe { S::operator_eq_1(&s, 7,) }) == (0))); - assert!(((unsafe { S::operator_add(&s, &t,) }) == (10))); - assert!(((unsafe { S::operator_sub(&s, t,) }) == (2))); - assert!(((unsafe { S::operator_mul_6(&s, &t,) }) == (24))); - assert!(((unsafe { S::operator_mul_7(&s, 2,) }) == (13))); + assert!(((unsafe { S::operator_eq_1(&raw const s, 6,) }) == (1))); + assert!(((unsafe { S::operator_eq_2(&raw const s, 6_i64,) }) == (2))); + assert!(((unsafe { S::operator_eq_3(&raw const s, 6_f64,) }) == (3))); + assert!(((unsafe { S::operator_eq_1(&raw const s, 7,) }) == (0))); + assert!(((unsafe { S::operator_add(&raw const s, &t,) }) == (10))); + assert!(((unsafe { S::operator_sub(&raw const s, t,) }) == (2))); + assert!(((unsafe { S::operator_mul_6(&raw const s, &t,) }) == (24))); + assert!(((unsafe { S::operator_mul_7(&raw const s, 2,) }) == (13))); assert!( ((unsafe { let _a: *const S = &s; diff --git a/tests/unit/out/unsafe/operator_qualifiers.rs b/tests/unit/out/unsafe/operator_qualifiers.rs index af429253b9..41a39f0738 100644 --- a/tests/unit/out/unsafe/operator_qualifiers.rs +++ b/tests/unit/out/unsafe/operator_qualifiers.rs @@ -21,32 +21,32 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_add_1(&mut self, mut a: i32) -> i32 { - return ((self.v) + (a)); + pub unsafe fn operator_add_1(this: *mut Self, mut a: i32) -> i32 { + return (((*this).v) + (a)); } - pub unsafe fn operator_add_2(&self, mut a: i32) -> i32 { - return (((self.v) + (a)) + (1)); + pub unsafe fn operator_add_2(this: *const Self, mut a: i32) -> i32 { + return ((((*this).v) + (a)) + (1)); } - pub unsafe fn operator_add_3(&mut self, mut a: i32) -> i32 { - return (((self.v) + (a)) + (2)); + pub unsafe fn operator_add_3(this: *mut Self, mut a: i32) -> i32 { + return ((((*this).v) + (a)) + (2)); } - pub unsafe fn operator_sub_4(&mut self, mut a: i32) -> i32 { - return ((self.v) - (a)); + pub unsafe fn operator_sub_4(this: *mut Self, mut a: i32) -> i32 { + return (((*this).v) - (a)); } - pub unsafe fn operator_sub_5(&mut self, mut a: i32) -> i32 { - return (((self.v) - (a)) - (1)); + pub unsafe fn operator_sub_5(this: *mut Self, mut a: i32) -> i32 { + return ((((*this).v) - (a)) - (1)); } - pub unsafe fn operator_mul_6(&self, mut a: i32) -> i32 { - return ((self.v) * (a)); + pub unsafe fn operator_mul_6(this: *const Self, mut a: i32) -> i32 { + return (((*this).v) * (a)); } - pub unsafe fn operator_mul_7(&self, mut a: i32) -> i32 { - return (((self.v) * (a)) * (2)); + pub unsafe fn operator_mul_7(this: *const Self, mut a: i32) -> i32 { + return ((((*this).v) * (a)) * (2)); } - pub unsafe fn operator_index_8(&mut self, mut i: i32) -> i32 { - return ((self.v) + (i)); + pub unsafe fn operator_index_8(this: *mut Self, mut i: i32) -> i32 { + return (((*this).v) + (i)); } - pub unsafe fn operator_index_9(&self, mut i: i32) -> i32 { - return (((self.v) + (i)) + (100)); + pub unsafe fn operator_index_9(this: *const Self, mut i: i32) -> i32 { + return ((((*this).v) + (i)) + (100)); } } pub fn main() { @@ -59,16 +59,16 @@ unsafe fn main_0() -> i32 { let mut s: S = S { v: 10 }; let cs: S = S { v: 10 }; let mut vs: S = S { v: 10 }; - assert!(((unsafe { S::operator_add_1(&mut s, 1,) }) == (11))); - assert!(((unsafe { S::operator_add_2(&cs, 1,) }) == (12))); - assert!(((unsafe { S::operator_add_3(&mut vs, 1,) }) == (13))); - assert!(((unsafe { S::operator_sub_4(&mut s, 1,) }) == (9))); + assert!(((unsafe { S::operator_add_1(&raw mut s, 1,) }) == (11))); + assert!(((unsafe { S::operator_add_2(&raw const cs, 1,) }) == (12))); + assert!(((unsafe { S::operator_add_3(&raw mut vs, 1,) }) == (13))); + assert!(((unsafe { S::operator_sub_4(&raw mut s, 1,) }) == (9))); assert!(((unsafe { S::operator_sub_5(&mut S { v: 10 }, 1,) }) == (8))); - assert!(((unsafe { S::operator_mul_6(&s, 3,) }) == (30))); - assert!(((unsafe { S::operator_mul_6(&cs, 3,) }) == (30))); + assert!(((unsafe { S::operator_mul_6(&raw const s, 3,) }) == (30))); + assert!(((unsafe { S::operator_mul_6(&raw const cs, 3,) }) == (30))); assert!(((unsafe { S::operator_mul_7(&S { v: 10 }, 3,) }) == (60))); - assert!(((unsafe { S::operator_index_8(&mut s, 2,) }) == (12))); - assert!(((unsafe { S::operator_index_9(&cs, 2,) }) == (112))); + assert!(((unsafe { S::operator_index_8(&raw mut s, 2,) }) == (12))); + assert!(((unsafe { S::operator_index_9(&raw const cs, 2,) }) == (112))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index eb74b41521..001ceea13f 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -21,17 +21,17 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_cmp(&self, o: *const S) -> std::cmp::Ordering { - if ((self.v) < ((*o).v)) { + pub unsafe fn operator_cmp(this: *const Self, o: *const S) -> std::cmp::Ordering { + if (((*this).v) < ((*o).v)) { return libcc2rs::STRONG_ORDERING_LESS; } - if ((self.v) > ((*o).v)) { + if (((*this).v) > ((*o).v)) { return libcc2rs::STRONG_ORDERING_GREATER; } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, o: *const S) -> bool { - return ((self.v) == ((*o).v)); + pub unsafe fn operator_eq(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); } } impl std::cmp::Ord for S { @@ -59,12 +59,12 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: S = S { v: 1 }; let mut b: S = S { v: 2 }; - assert!((unsafe { S::operator_cmp(&a, &b,) }) == std::cmp::Ordering::Less); - assert!((unsafe { S::operator_cmp(&b, &a,) }) == std::cmp::Ordering::Greater); - assert!((unsafe { S::operator_cmp(&a, &b,) }) != std::cmp::Ordering::Greater); - assert!((unsafe { S::operator_cmp(&b, &a,) }) != std::cmp::Ordering::Less); - assert!(!(unsafe { S::operator_eq(&a, &b,) })); - assert!((unsafe { S::operator_cmp(&a, &b,) }) == libcc2rs::STRONG_ORDERING_LESS); + assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) == std::cmp::Ordering::Less); + assert!((unsafe { S::operator_cmp(&raw const b, &a,) }) == std::cmp::Ordering::Greater); + assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) != std::cmp::Ordering::Greater); + assert!((unsafe { S::operator_cmp(&raw const b, &a,) }) != std::cmp::Ordering::Less); + assert!(!(unsafe { S::operator_eq(&raw const a, &b,) })); + assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) == libcc2rs::STRONG_ORDERING_LESS); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index ff4e03fc64..c5e3127926 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -21,8 +21,8 @@ pub struct Lt { pub v: i32, } impl Lt { - pub unsafe fn operator_lt(&self, o: *const Lt) -> bool { - return ((self.v) < ((*o).v)); + pub unsafe fn operator_lt(this: *const Self, o: *const Lt) -> bool { + return (((*this).v) < ((*o).v)); } } impl std::cmp::Ord for Lt { @@ -67,8 +67,8 @@ pub struct Eq { pub v: i32, } impl Eq { - pub unsafe fn operator_eq(&self, o: *const Eq) -> bool { - return ((self.v) == ((*o).v)); + pub unsafe fn operator_eq(this: *const Self, o: *const Eq) -> bool { + return (((*this).v) == ((*o).v)); } } impl std::cmp::PartialEq for Eq { @@ -92,11 +92,11 @@ pub struct Cmp { pub v: i32, } impl Cmp { - pub unsafe fn operator_cmp(&self, o: *const Cmp) -> std::cmp::Ordering { - return std::cmp::Ord::cmp(&(self.v), &((*o).v)); + pub unsafe fn operator_cmp(this: *const Self, o: *const Cmp) -> std::cmp::Ordering { + return std::cmp::Ord::cmp(&((*this).v), &((*o).v)); } - pub unsafe fn operator_eq(&self, o: *const Cmp) -> bool { - return ((self.v) == ((*o).v)); + pub unsafe fn operator_eq(this: *const Self, o: *const Cmp) -> bool { + return (((*this).v) == ((*o).v)); } } impl std::cmp::Ord for Cmp { diff --git a/tests/unit/out/unsafe/overload_mangling.rs b/tests/unit/out/unsafe/overload_mangling.rs index a508eda753..14ba1ffaaf 100644 --- a/tests/unit/out/unsafe/overload_mangling.rs +++ b/tests/unit/out/unsafe/overload_mangling.rs @@ -28,16 +28,16 @@ pub unsafe fn twice_2(mut n: i32) -> i32 { )] pub struct Access_S_ {} impl Access_S_ { - pub unsafe fn get_1(&mut self, mut p: *mut S) -> i32 { + pub unsafe fn get_1(this: *mut Self, mut p: *mut S) -> i32 { return (*p).base; } - pub unsafe fn get_2(&mut self, mut p: *const S) -> i32 { + pub unsafe fn get_2(this: *mut Self, mut p: *const S) -> i32 { return (((*p).base) + (1)); } - pub unsafe fn ref_3(&mut self, r: *mut S) -> i32 { + pub unsafe fn ref_3(this: *mut Self, r: *mut S) -> i32 { return (((*r).base) + (2)); } - pub unsafe fn ref_4(&mut self, r: *const S) -> i32 { + pub unsafe fn ref_4(this: *mut Self, r: *const S) -> i32 { return (((*r).base) + (3)); } } @@ -56,72 +56,84 @@ pub struct S { pub base: i32, } impl S { - pub unsafe fn plain_4(&self, mut x: i32) -> i32 { - return ((self.base) + (x)); + pub unsafe fn plain_4(this: *const Self, mut x: i32) -> i32 { + return (((*this).base) + (x)); } - pub unsafe fn plain_5(&self, mut x: i64) -> i32 { - return (((self.base) + (x as i32)) + (1)); + pub unsafe fn plain_5(this: *const Self, mut x: i64) -> i32 { + return ((((*this).base) + (x as i32)) + (1)); } - pub unsafe fn take_6(&self, x: *mut i32) -> i32 { - return (((self.base) + (*x)) + (1)); + pub unsafe fn take_6(this: *const Self, x: *mut i32) -> i32 { + return ((((*this).base) + (*x)) + (1)); } - pub unsafe fn take_7(&self, x: *mut i32) -> i32 { - return (((self.base) + (*x)) + (2)); + pub unsafe fn take_7(this: *const Self, x: *mut i32) -> i32 { + return ((((*this).base) + (*x)) + (2)); } - pub unsafe fn pick_8(&self, mut p: (i32, i32)) -> i32 { - return ((self.base) + (p.0)); + pub unsafe fn pick_8(this: *const Self, mut p: (i32, i32)) -> i32 { + return (((*this).base) + (p.0)); } - pub unsafe fn pick_9(&self, mut p: (i32, i64)) -> i32 { - return ((self.base) + ((p.1) as i32)); + pub unsafe fn pick_9(this: *const Self, mut p: (i32, i64)) -> i32 { + return (((*this).base) + ((p.1) as i32)); } - pub unsafe fn apply_10(&self, mut f: Option, mut x: i32) -> i32 { + pub unsafe fn apply_10( + this: *const Self, + mut f: Option, + mut x: i32, + ) -> i32 { (unsafe { (f).unwrap()((&mut x as *mut i32)) }); - return ((self.base) + (x)); + return (((*this).base) + (x)); } - pub unsafe fn apply_11(&self, mut f: Option, mut x: i32) -> i32 { + pub unsafe fn apply_11( + this: *const Self, + mut f: Option, + mut x: i32, + ) -> i32 { (unsafe { (f).unwrap()((&mut x as *mut i32), 10) }); - return ((self.base) + (x)); + return (((*this).base) + (x)); } - pub unsafe fn apply_12(&self, mut f: Option i32>, mut x: i32) -> i32 { - return ((self.base) + (unsafe { (f).unwrap()(x) })); + pub unsafe fn apply_12( + this: *const Self, + mut f: Option i32>, + mut x: i32, + ) -> i32 { + return (((*this).base) + (unsafe { (f).unwrap()(x) })); } pub unsafe fn combine_13( - &self, + this: *const Self, p: *const (i32, i64), mut f: Option i32>, mut q: *const i32, mut n: u64, ) -> i32 { - return ((((self.base) + (((*p).1) as i32)) + (unsafe { (f).unwrap()((*q)) })) + return (((((*this).base) + (((*p).1) as i32)) + (unsafe { (f).unwrap()((*q)) })) + (n as i32)); } pub unsafe fn combine_14( - &self, + this: *const Self, p: *const (i32, i32), mut f: Option, mut q: *mut i32, mut n: u64, ) -> i32 { (unsafe { (f).unwrap()(q, (n as i32)) }); - return (((self.base) + ((*p).0)) + (*q)); + return ((((*this).base) + ((*p).0)) + (*q)); } - pub unsafe fn width_1_char(&self, mut x: i32) -> i32 { - return ((self.base) + ((x) * (::std::mem::size_of::() as i32))); + pub unsafe fn width_1_char(this: *const Self, mut x: i32) -> i32 { + return (((*this).base) + ((x) * (::std::mem::size_of::() as i32))); } - pub unsafe fn width_1_int(&self, mut x: i32) -> i32 { - return ((self.base) + ((x) * (::std::mem::size_of::() as i32))); + pub unsafe fn width_1_int(this: *const Self, mut x: i32) -> i32 { + return (((*this).base) + ((x) * (::std::mem::size_of::() as i32))); } - pub unsafe fn scale_2_2(&self, mut x: i32) -> i32 { - return ((self.base) + ((x) * (2))); + pub unsafe fn scale_2_2(this: *const Self, mut x: i32) -> i32 { + return (((*this).base) + ((x) * (2))); } - pub unsafe fn scale_2_3(&self, mut x: i32) -> i32 { - return ((self.base) + ((x) * (3))); + pub unsafe fn scale_2_3(this: *const Self, mut x: i32) -> i32 { + return (((*this).base) + ((x) * (3))); } - pub unsafe fn count_3(&self, mut x: i32) -> i32 { - return (((self.base) + (x)) + (0 as i32)); + pub unsafe fn count_3(this: *const Self, mut x: i32) -> i32 { + return ((((*this).base) + (x)) + (0 as i32)); } - pub unsafe fn count_3_int_long(&self, mut x: i32) -> i32 { - return (((self.base) + (x)) + (2 as i32)); + pub unsafe fn count_3_int_long(this: *const Self, mut x: i32) -> i32 { + return ((((*this).base) + (x)) + (2 as i32)); } } #[repr(C)] @@ -146,49 +158,61 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut s: S = S { base: 100 }; - assert!(((unsafe { S::width_1_char(&s, 3,) }) == (103))); - assert!(((unsafe { S::width_1_int(&s, 3,) }) == (112))); - assert!(((unsafe { S::scale_2_2(&s, 5,) }) == (110))); - assert!(((unsafe { S::scale_2_3(&s, 5,) }) == (115))); - assert!(((unsafe { S::count_3(&s, 1,) }) == (101))); - assert!(((unsafe { S::count_3_int_long(&s, 1,) }) == (103))); - assert!(((unsafe { S::plain_4(&s, 1,) }) == (101))); - assert!(((unsafe { S::plain_5(&s, 1_i64,) }) == (102))); + assert!(((unsafe { S::width_1_char(&raw const s, 3,) }) == (103))); + assert!(((unsafe { S::width_1_int(&raw const s, 3,) }) == (112))); + assert!(((unsafe { S::scale_2_2(&raw const s, 5,) }) == (110))); + assert!(((unsafe { S::scale_2_3(&raw const s, 5,) }) == (115))); + assert!(((unsafe { S::count_3(&raw const s, 1,) }) == (101))); + assert!(((unsafe { S::count_3_int_long(&raw const s, 1,) }) == (103))); + assert!(((unsafe { S::plain_4(&raw const s, 1,) }) == (101))); + assert!(((unsafe { S::plain_5(&raw const s, 1_i64,) }) == (102))); let mut y: i32 = 1; - assert!(((unsafe { S::take_6(&s, &mut y,) }) == (102))); + assert!(((unsafe { S::take_6(&raw const s, &mut y,) }) == (102))); assert!( ((unsafe { let mut _x: i32 = 5; - S::take_7(&s, &mut _x) + S::take_7(&raw const s, &mut _x) }) == (107)) ); - assert!(((unsafe { S::pick_8(&s, (1, 2),) }) == (101))); - assert!(((unsafe { S::pick_9(&s, (1, 2_i64),) }) == (102))); - assert!(((unsafe { S::apply_10(&s, Some(inc_0), 1,) }) == (102))); - assert!(((unsafe { S::apply_11(&s, Some(add_1), 1,) }) == (111))); - assert!(((unsafe { S::apply_12(&s, Some(twice_2), 3,) }) == (106))); + assert!(((unsafe { S::pick_8(&raw const s, (1, 2),) }) == (101))); + assert!(((unsafe { S::pick_9(&raw const s, (1, 2_i64),) }) == (102))); + assert!(((unsafe { S::apply_10(&raw const s, Some(inc_0), 1,) }) == (102))); + assert!(((unsafe { S::apply_11(&raw const s, Some(add_1), 1,) }) == (111))); + assert!(((unsafe { S::apply_12(&raw const s, Some(twice_2), 3,) }) == (106))); let c: i32 = 3; assert!( ((unsafe { let mut _p: (i32, i64) = (1, 2_i64); - S::combine_13(&s, &mut _p, Some(twice_2), (&c as *const i32), 4_u64) + S::combine_13( + &raw const s, + &mut _p, + Some(twice_2), + (&c as *const i32), + 4_u64, + ) }) == (112)) ); let mut z: i32 = 1; assert!( ((unsafe { let mut _p: (i32, i32) = (1, 2); - S::combine_14(&s, &mut _p, Some(add_1), (&mut z as *mut i32), 5_u64) + S::combine_14( + &raw const s, + &mut _p, + Some(add_1), + (&mut z as *mut i32), + 5_u64, + ) }) == (107)) ); assert!(((z) == (6))); let mut a: Access_S_ = ::default(); let mut cs: *const S = (&mut s as *mut S).cast_const(); let cr: *const S = &s; - assert!(((unsafe { Access_S_::get_1(&mut a, (&mut s as *mut S),) }) == (100))); - assert!(((unsafe { Access_S_::get_2(&mut a, cs,) }) == (101))); - assert!(((unsafe { Access_S_::ref_3(&mut a, &mut s,) }) == (102))); - assert!(((unsafe { Access_S_::ref_4(&mut a, cr,) }) == (103))); + assert!(((unsafe { Access_S_::get_1(&raw mut a, (&mut s as *mut S),) }) == (100))); + assert!(((unsafe { Access_S_::get_2(&raw mut a, cs,) }) == (101))); + assert!(((unsafe { Access_S_::ref_3(&raw mut a, &mut s,) }) == (102))); + assert!(((unsafe { Access_S_::ref_4(&raw mut a, cr,) }) == (103))); let mut b: Box_ = Box_ { v: 4 }; assert!(((b.v) == (4))); return 0; diff --git a/tests/unit/out/unsafe/pair_converting_construction.rs b/tests/unit/out/unsafe/pair_converting_construction.rs index 67b176c8fe..9228e4c5cc 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.rs @@ -23,8 +23,8 @@ pub struct Celsius { pub degrees: i32, } impl Celsius { - pub unsafe fn construct(&mut self, mut d: i32) { - (&raw mut self.degrees).write(d); + pub unsafe fn construct(this: *mut Self, mut d: i32) { + (&raw mut (*this).degrees).write(d); } } #[repr(C)] @@ -44,8 +44,8 @@ pub struct Meters { pub value: i32, } impl Meters { - pub unsafe fn to_i32(&self) -> i32 { - return self.value; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).value; } } #[repr(C)] @@ -65,8 +65,8 @@ pub struct Label { pub id: i32, } impl Label { - pub unsafe fn construct(&mut self, c: *const Celsius) { - (&raw mut self.id).write((*c).degrees); + pub unsafe fn construct(this: *mut Self, c: *const Celsius) { + (&raw mut (*this).id).write((*c).degrees); } } #[repr(C)] @@ -88,13 +88,13 @@ pub struct Owner { pub copied: i32, } impl Owner { - pub unsafe fn construct_1(&mut self, c: *const Celsius) { - (&raw mut self.taken).write(0); - (&raw mut self.copied).write((*c).degrees); + pub unsafe fn construct_1(this: *mut Self, c: *const Celsius) { + (&raw mut (*this).taken).write(0); + (&raw mut (*this).copied).write((*c).degrees); } - pub unsafe fn construct_2(&mut self, c: *mut Celsius) { - (&raw mut self.taken).write((*c).degrees); - (&raw mut self.copied).write(0); + pub unsafe fn construct_2(this: *mut Self, c: *mut Celsius) { + (&raw mut (*this).taken).write((*c).degrees); + (&raw mut (*this).copied).write(0); } } #[repr(C)] @@ -114,8 +114,8 @@ pub struct Holder { pub value: i32, } impl Holder { - pub unsafe fn construct(&mut self, mut c: Celsius) { - (&raw mut self.value).write(c.degrees); + pub unsafe fn construct(this: *mut Self, mut c: Celsius) { + (&raw mut (*this).value).write(c.degrees); } } #[repr(C)] @@ -127,14 +127,14 @@ pub struct Fallback { pub value: i32, } impl Fallback { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.value).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); } } impl DefaultConstructibleUnsafe for Fallback { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { unsafe { - Fallback::construct(&mut *self, -1_i32); + Fallback::construct(this, -1_i32); } } } @@ -143,7 +143,7 @@ impl Default for Fallback { unsafe { { let mut __v: Fallback = ::zero_init(); - Fallback::construct(&mut __v, -1_i32); + Fallback::construct(&raw mut __v, -1_i32); __v } } @@ -180,14 +180,14 @@ pub struct Observer { pub seen: i32, } impl Observer { - pub unsafe fn construct(&mut self, c: *mut Counter) { - (&raw mut self.seen).write((*c).hits); + pub unsafe fn construct(this: *mut Self, c: *mut Counter) { + (&raw mut (*this).seen).write((*c).hits); (*c).hits.postfix_inc(); } } impl Tag { - pub unsafe fn construct(&mut self, u: *const Celsius) { - (&raw mut self.code).write((((*u).degrees) + (100))); + pub unsafe fn construct(this: *mut Self, u: *const Celsius) { + (&raw mut (*this).code).write((((*u).degrees) + (100))); } } #[repr(C)] @@ -223,10 +223,10 @@ pub struct Name { pub len: i32, } impl Name { - pub unsafe fn construct(&mut self, mut s: *const libc::c_char) { - (&raw mut self.len).write(0); - 'loop_: while ((*s.offset((self.len) as isize)) != 0) { - self.len.prefix_inc(); + pub unsafe fn construct(this: *mut Self, mut s: *const libc::c_char) { + (&raw mut (*this).len).write(0); + 'loop_: while ((*s.offset(((*this).len) as isize)) != 0) { + (*this).len.prefix_inc(); } } } @@ -243,12 +243,12 @@ unsafe fn main_0() -> i32 { let mut from_ints: (Celsius, Celsius) = ( { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 1); + Celsius::construct(&raw mut __v, 1); __v }, { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 2); + Celsius::construct(&raw mut __v, 2); __v }, ); @@ -256,8 +256,8 @@ unsafe fn main_0() -> i32 { assert!(((from_ints.1.degrees) == (2))); let mut m: Meters = Meters { value: 7 }; let mut from_operators: (i32, i64) = ( - (unsafe { Meters::to_i32(&m) }), - ((unsafe { Meters::to_i32(&m) }) as i64), + (unsafe { Meters::to_i32(&raw const m) }), + ((unsafe { Meters::to_i32(&raw const m) }) as i64), ); assert!(((from_operators.0) == (7))); assert!(((from_operators.1) == (7_i64))); @@ -283,12 +283,12 @@ unsafe fn main_0() -> i32 { let mut celsius: (Celsius, Celsius) = ( { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 10); + Celsius::construct(&raw mut __v, 10); __v }, { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 11); + Celsius::construct(&raw mut __v, 11); __v }, ); @@ -302,12 +302,12 @@ unsafe fn main_0() -> i32 { let mut from_moved_record_pair: (Label, Owner) = match ((&mut ( { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 12); + Celsius::construct(&raw mut __v, 12); __v }, { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 13); + Celsius::construct(&raw mut __v, 13); __v }, ) as *mut (Celsius, Celsius)),) @@ -329,12 +329,12 @@ unsafe fn main_0() -> i32 { let mut from_moved_by_value_pair: (Holder, Holder) = match ((&mut ( { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 14); + Celsius::construct(&raw mut __v, 14); __v }, { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 15); + Celsius::construct(&raw mut __v, 15); __v }, ) as *mut (Celsius, Celsius)),) @@ -358,7 +358,7 @@ unsafe fn main_0() -> i32 { let mut forwarded_mutable_ref: (Observer, i32) = ( { let mut __v: Observer = ::zero_init(); - Observer::construct(&mut __v, &mut counter); + Observer::construct(&raw mut __v, &mut counter); __v }, 0, @@ -376,12 +376,12 @@ unsafe fn main_0() -> i32 { let mut forwarded_records: (Label, Owner) = ( { let mut __v: Label = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -41,8 +41,8 @@ pub struct B { pub v: i32, } impl DefaultConstructibleUnsafe for B { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(2); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(2); } } impl Default for B { @@ -50,7 +50,7 @@ impl Default for B { unsafe { { let mut __v: B = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -73,8 +73,8 @@ pub struct NoDefault { pub v: i32, } impl NoDefault { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } pub unsafe fn used_0(mut x: A) -> i32 { @@ -106,11 +106,11 @@ pub struct S_NoDefault_ { pub v: i32, } impl S_NoDefault_ { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } - pub unsafe fn get(&self, mut t: NoDefault) -> i32 { - return ((self.v) + (t.v)); + pub unsafe fn get(this: *const Self, mut t: NoDefault) -> i32 { + return (((*this).v) + (t.v)); } } pub fn main() { @@ -124,7 +124,7 @@ unsafe fn main_0() -> i32 { ((unsafe { used_0({ let mut __v: A = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }) }) == (1)) @@ -133,7 +133,7 @@ unsafe fn main_0() -> i32 { ((unsafe { used_0({ let mut __v: A = ::zero_init(); - A::construct_1(&mut __v, 5); + A::construct_1(&raw mut __v, 5); __v }) }) == (5)) @@ -142,7 +142,7 @@ unsafe fn main_0() -> i32 { ((unsafe { used_1({ let mut __v: B = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }) }) == (2)) @@ -152,7 +152,7 @@ unsafe fn main_0() -> i32 { scaled_2( { let mut __v: A = ::zero_init(); - A::construct_1(&mut __v, 3); + A::construct_1(&raw mut __v, 3); __v }, (::std::mem::size_of::() as i32), @@ -164,7 +164,7 @@ unsafe fn main_0() -> i32 { scaled_2( { let mut __v: A = ::zero_init(); - A::construct_1(&mut __v, 3); + A::construct_1(&raw mut __v, 3); __v }, 2, @@ -175,7 +175,7 @@ unsafe fn main_0() -> i32 { ((unsafe { always_given_3({ let mut __v: NoDefault = ::zero_init(); - NoDefault::construct(&mut __v, 3); + NoDefault::construct(&raw mut __v, 3); __v }) }) == (3)) @@ -183,9 +183,9 @@ unsafe fn main_0() -> i32 { object_unsafe!(s, S_NoDefault_(1)); assert!( ((unsafe { - S_NoDefault_::get(&s, { + S_NoDefault_::get(&raw const s, { let mut __v: NoDefault = ::zero_init(); - NoDefault::construct(&mut __v, 4); + NoDefault::construct(&raw mut __v, 4); __v }) }) == (5)) diff --git a/tests/unit/out/unsafe/temporary_field_addr.rs b/tests/unit/out/unsafe/temporary_field_addr.rs index f49b2ebbbc..6213be8029 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -23,8 +23,8 @@ pub struct Inner { pub values: Vec, } impl DefaultConstructibleUnsafe for Inner { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); } } #[repr(C)] @@ -46,15 +46,15 @@ pub struct Outer { pub name: [libc::c_char; 8], } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); - DefaultConstructibleUnsafe::default_constructor(&mut self.inner); - (&raw mut self.name).write([(0 as libc::c_char); 8]); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).inner); + (&raw mut (*this).name).write([(0 as libc::c_char); 8]); } } -pub unsafe fn make_0(this: *mut Outer, calls: *mut i32) { +pub unsafe fn make_0(__return: *mut Outer, calls: *mut i32) { (*calls).prefix_inc(); - this.write(Outer { + __return.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), @@ -84,7 +84,7 @@ unsafe fn main_0() -> i32 { (unsafe { sum_1( &(*{ - (unsafe { make_0(&mut __tmp_0, &mut calls) }); + (unsafe { make_0(&raw mut __tmp_0, &mut calls) }); &mut __tmp_0 }) .values, @@ -96,7 +96,7 @@ unsafe fn main_0() -> i32 { (unsafe { sum_1( &(*{ - (unsafe { make_0(&mut __tmp_1, &mut calls) }); + (unsafe { make_0(&raw mut __tmp_1, &mut calls) }); &mut __tmp_1 }) .inner @@ -107,7 +107,7 @@ unsafe fn main_0() -> i32 { let mut element: i32 = { let mut __tmp_2: Outer = ::zero_init(); (*{ - (unsafe { make_0(&mut __tmp_2, &mut calls) }); + (unsafe { make_0(&raw mut __tmp_2, &mut calls) }); &mut __tmp_2 }) .values[(((calls) - (2)) as usize)] @@ -116,7 +116,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_3: Outer = ::zero_init(); libc::strlen( ((*{ - (unsafe { make_0(&mut __tmp_3, &mut calls) }); + (unsafe { make_0(&raw mut __tmp_3, &mut calls) }); &mut __tmp_3 }) .name diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index e9174afcfd..7ccbb9e43c 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -23,12 +23,12 @@ pub struct Outer { pub values: Vec, } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); } } -pub unsafe fn make_0(this: *mut Outer) { - this.write(Outer { +pub unsafe fn make_0(__return: *mut Outer) { + __return.write(Outer { values: Vec::from([1, 2, 3, 4]), }); return; @@ -50,8 +50,8 @@ pub struct H { pub last: i32, } impl H { - pub unsafe fn construct(&mut self, values: *const Vec) { - (&raw mut self.last).write((&(*values))[(3_usize)]); + pub unsafe fn construct(this: *mut Self, values: *const Vec) { + (&raw mut (*this).last).write((&(*values))[(3_usize)]); } } pub fn main() { @@ -66,7 +66,7 @@ unsafe fn main_0() -> i32 { H::construct( h, &(*{ - (unsafe { make_0(&mut __tmp_0) }); + (unsafe { make_0(&raw mut __tmp_0) }); &mut __tmp_0 }) .values, diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index 35738bb6ba..7a3f5dc295 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -23,8 +23,8 @@ pub struct Inner { pub values: Vec, } impl DefaultConstructibleUnsafe for Inner { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); } } #[repr(C)] @@ -45,13 +45,13 @@ pub struct Outer { pub inner: Inner, } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); - DefaultConstructibleUnsafe::default_constructor(&mut self.inner); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).inner); } } -pub unsafe fn make_0(this: *mut Outer) { - this.write(Outer { +pub unsafe fn make_0(__return: *mut Outer) { + __return.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), @@ -77,12 +77,12 @@ unsafe fn main_0() -> i32 { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _a: *const Vec = &(*{ - (unsafe { make_0(&mut __tmp_0) }); + (unsafe { make_0(&raw mut __tmp_0) }); &mut __tmp_0 }) .values; let _b: *const Vec = &(*{ - (unsafe { make_0(&mut __tmp_1) }); + (unsafe { make_0(&raw mut __tmp_1) }); &mut __tmp_1 }) .inner diff --git a/tests/unit/out/unsafe/this.rs b/tests/unit/out/unsafe/this.rs index 2f023161df..754894f450 100644 --- a/tests/unit/out/unsafe/this.rs +++ b/tests/unit/out/unsafe/this.rs @@ -24,86 +24,86 @@ pub struct S { pub self__: *mut S, } impl S { - pub unsafe fn construct_1(&mut self, mut a: i32) { - (&raw mut self.a_).write(a); - (&raw mut self.self__).write(std::ptr::null_mut()); - } - pub unsafe fn construct_2(&mut self, mut a: i32, mut other: *mut S) { - (&raw mut self.a_).write(a); - (&raw mut self.self__).write(std::ptr::null_mut()); - if ((self as *mut S) == (other)) { - self.self__ = std::ptr::null_mut(); + pub unsafe fn construct_1(this: *mut Self, mut a: i32) { + (&raw mut (*this).a_).write(a); + (&raw mut (*this).self__).write(std::ptr::null_mut()); + } + pub unsafe fn construct_2(this: *mut Self, mut a: i32, mut other: *mut S) { + (&raw mut (*this).a_).write(a); + (&raw mut (*this).self__).write(std::ptr::null_mut()); + if ((this) == (other)) { + (*this).self__ = std::ptr::null_mut(); } else { - self.self__ = other; + (*this).self__ = other; } } - pub unsafe fn construct_3(&mut self, mut a: i32, mut other: *const S) { - (&raw mut self.a_).write(a); - (&raw mut self.self__).write(std::ptr::null_mut()); - if (((self as *mut S).cast_const()) == (other)) { - self.self__ = std::ptr::null_mut(); + pub unsafe fn construct_3(this: *mut Self, mut a: i32, mut other: *const S) { + (&raw mut (*this).a_).write(a); + (&raw mut (*this).self__).write(std::ptr::null_mut()); + if (((this).cast_const()) == (other)) { + (*this).self__ = std::ptr::null_mut(); } } - pub unsafe fn returns_this_reference(&mut self) -> *mut S { - return &mut (*(self as *mut S)); + pub unsafe fn returns_this_reference(this: *mut Self) -> *mut S { + return &mut (*this); } - pub unsafe fn returns_this_pointer(&mut self) -> *mut S { - return (self as *mut S); + pub unsafe fn returns_this_pointer(this: *mut Self) -> *mut S { + return this; } - pub unsafe fn inc(&mut self) -> *mut S { - self.a_.postfix_inc(); - return &mut (*(self as *mut S)); + pub unsafe fn inc(this: *mut Self) -> *mut S { + (*this).a_.postfix_inc(); + return &mut (*this); } - pub unsafe fn set_from_this(&mut self) { - self.a_ = ((self.a_) + (1)); + pub unsafe fn set_from_this(this: *mut Self) { + (*this).a_ = (((*this).a_) + (1)); } - pub unsafe fn get(&mut self) -> i32 { - return self.a_; + pub unsafe fn get(this: *mut Self) -> i32 { + return (*this).a_; } - pub unsafe fn twice(&mut self) -> i32 { - return ((unsafe { S::get(self) }) * (2)); + pub unsafe fn twice(this: *mut Self) -> i32 { + return ((unsafe { S::get(this) }) * (2)); } - pub unsafe fn link(&mut self) { - self.self__ = (self as *mut S); + pub unsafe fn link(this: *mut Self) { + (*this).self__ = this; } - pub unsafe fn bump_me(&mut self) { - (unsafe { bump_0((self as *mut S)) }); + pub unsafe fn bump_me(this: *mut Self) { + (unsafe { bump_0(this) }); } - pub unsafe fn cref(&self) -> *const S { - return &(*(self as *const S)); + pub unsafe fn cref(this: *const Self) -> *const S { + return &(*this); } - pub unsafe fn is(&self, mut o: *const S) -> bool { - return ((o) == (self as *const S)); + pub unsafe fn is(this: *const Self, mut o: *const S) -> bool { + return ((o) == (this)); } - pub unsafe fn destroy(&mut self) { + pub unsafe fn destroy(this: *mut Self) { { - let __p = (self as *mut S); + let __p = this; if !__p.is_null() { ::std::mem::drop(Box::from_raw(__p)) } }; } - pub unsafe fn reset(&mut self) { - (*(self as *mut S)) = { + pub unsafe fn reset(this: *mut Self) { + (*this) = { let mut __v: S = ::zero_init(); - S::construct_1(&mut __v, 0); + S::construct_1(&raw mut __v, 0); __v }; } - pub unsafe fn copy_if_different_const(&mut self, mut other: *const S) -> bool { - if (((self as *mut S).cast_const()) == (other)) { + pub unsafe fn copy_if_different_const(this: *mut Self, mut other: *const S) -> bool { + if (((this).cast_const()) == (other)) { return false; } - self.a_ = (*other).a_; - self.self__ = (*other).self__; + (*this).a_ = (*other).a_; + (*this).self__ = (*other).self__; return true; } - pub unsafe fn copy_if_different(&mut self, mut other: *mut S) -> bool { - if ((self as *mut S) == (other)) { + pub unsafe fn copy_if_different(this: *mut Self, mut other: *mut S) -> bool { + if ((this) == (other)) { return false; } - self.a_ = (*other).a_; - self.self__ = (*other).self__; + (*this).a_ = (*other).a_; + (*this).self__ = (*other).self__; return true; } } @@ -127,9 +127,9 @@ pub struct D { pub a_: i32, } impl D { - pub unsafe fn construct(&mut self, mut a: i32) { - (&raw mut self.a_).write(a); - self.a_ *= 2; + pub unsafe fn construct(this: *mut Self, mut a: i32) { + (&raw mut (*this).a_).write(a); + (*this).a_ *= 2; } } pub fn main() { @@ -140,41 +140,43 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(s, S::construct_1(1)); - let ref_: *mut S = (unsafe { S::returns_this_reference(&mut s) }); + let ref_: *mut S = (unsafe { S::returns_this_reference(&raw mut s) }); (*ref_).a_.postfix_inc(); assert!(((s.a_) == (2))); - let mut ptr: *mut S = (unsafe { S::returns_this_pointer(&mut s) }); + let mut ptr: *mut S = (unsafe { S::returns_this_pointer(&raw mut s) }); (*ptr).a_.postfix_inc(); assert!(((s.a_) == (3))); - (unsafe { S::inc(&mut (*(unsafe { S::inc(&mut (*(unsafe { S::inc(&mut s) }))) }))) }); + (unsafe { + S::inc(&raw mut (*(unsafe { S::inc(&raw mut (*(unsafe { S::inc(&raw mut s) }))) }))) + }); assert!(((s.a_) == (6))); - (unsafe { S::set_from_this(&mut s) }); + (unsafe { S::set_from_this(&raw mut s) }); assert!(((s.a_) == (7))); - assert!(((unsafe { S::twice(&mut s,) }) == (14))); - (unsafe { S::link(&mut s) }); + assert!(((unsafe { S::twice(&raw mut s,) }) == (14))); + (unsafe { S::link(&raw mut s) }); assert!(((s.self__) == (&mut s as *mut S))); (*s.self__).a_.postfix_inc(); assert!(((s.a_) == (8))); - (unsafe { S::bump_me(&mut s) }); + (unsafe { S::bump_me(&raw mut s) }); assert!(((s.a_) == (9))); object_unsafe!(d, D(3)); assert!(((d.a_) == (6))); - let cr: *const S = (unsafe { S::cref(&s) }); + let cr: *const S = (unsafe { S::cref(&raw const s) }); assert!((((*cr).a_) == (9))); object_unsafe!(t, S::construct_1(0)); assert!( (unsafe { let _o: *const S = (&mut s as *mut S).cast_const(); - S::is(&s, _o) + S::is(&raw const s, _o) }) ); - assert!(!(unsafe { S::is(&s, (&mut t as *mut S).cast_const(),) })); + assert!(!(unsafe { S::is(&raw const s, (&mut t as *mut S).cast_const(),) })); let mut p: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - S::construct_1(&mut *__p, 1); + S::construct_1(__p, 1); __p }; - let mut q: *mut S = (unsafe { S::returns_this_pointer(&mut (*p)) }); + let mut q: *mut S = (unsafe { S::returns_this_pointer(&raw mut (*p)) }); (*q).a_.postfix_inc(); assert!((((*p).a_) == (2))); { @@ -185,30 +187,30 @@ unsafe fn main_0() -> i32 { }; let mut h: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - S::construct_1(&mut *__p, 5); + S::construct_1(__p, 5); __p }; - (unsafe { S::destroy(&mut (*h)) }); - (unsafe { S::reset(&mut s) }); + (unsafe { S::destroy(&raw mut (*h)) }); + (unsafe { S::reset(&raw mut s) }); assert!(((s.a_) == (0))); assert!((s.self__).is_null()); assert!( (((unsafe { let _other: *mut S = (&mut s as *mut S); - S::copy_if_different(&mut s, _other) + S::copy_if_different(&raw mut s, _other) }) as i32) == (false as i32)) ); assert!( (((unsafe { let _other: *const S = (&mut s as *mut S).cast_const(); - S::copy_if_different_const(&mut s, _other) + S::copy_if_different_const(&raw mut s, _other) }) as i32) == (false as i32)) ); object_unsafe!(other, S::construct_1(22)); assert!( - (((unsafe { S::copy_if_different(&mut s, (&mut other as *mut S),) }) as i32) + (((unsafe { S::copy_if_different(&raw mut s, (&mut other as *mut S),) }) as i32) == (true as i32)) ); assert!(((s.a_) == (other.a_))); @@ -217,7 +219,7 @@ unsafe fn main_0() -> i32 { assert!(((u.self__) == (&mut s as *mut S))); let s_const: S = { let mut __v: S = ::zero_init(); - S::construct_1(&mut __v, 100); + S::construct_1(&raw mut __v, 100); __v }; object_unsafe!(u1, S::construct_3(1, (&s_const as *const S))); diff --git a/tests/unit/out/unsafe/typedef-anon-struct.rs b/tests/unit/out/unsafe/typedef-anon-struct.rs index efe21ea088..025c03922c 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -38,8 +38,8 @@ pub struct Outer { pub runs: Vec, } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.runs).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).runs).write(Vec::new()); } } pub fn main() { diff --git a/tests/unit/out/unsafe/unboxed_records.rs b/tests/unit/out/unsafe/unboxed_records.rs index 31f9b28835..4bd99e639c 100644 --- a/tests/unit/out/unsafe/unboxed_records.rs +++ b/tests/unit/out/unsafe/unboxed_records.rs @@ -45,13 +45,13 @@ pub struct Counter { pub n: i32, } impl Counter { - pub unsafe fn inc(&mut self) { - self.n.prefix_inc(); + pub unsafe fn inc(this: *mut Self) { + (*this).n.prefix_inc(); } } impl DefaultConstructibleUnsafe for Counter { - unsafe fn default_constructor(&mut self) { - (&raw mut self.n).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).n).write(0); } } impl Default for Counter { @@ -122,7 +122,7 @@ unsafe fn main_0() -> i32 { (unsafe { set_0((&mut field_addr.b as *mut i32), 7) }); assert!(((field_addr.b) == (7))); object_unsafe!(counter, Counter); - (unsafe { Counter::inc(&mut counter) }); + (unsafe { Counter::inc(&raw mut counter) }); assert!(((counter.n) == (1))); return 0; } diff --git a/tests/unit/out/unsafe/unique_ptr.rs b/tests/unit/out/unsafe/unique_ptr.rs index c0dcabc255..6532b67105 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -20,8 +20,8 @@ pub struct SafePointer { pub ptr: Option>, } impl SafePointer { - pub unsafe fn inc(&mut self) { - (*self + pub unsafe fn inc(this: *mut Self) { + (*(*this) .ptr .as_deref() .map_or(::std::ptr::null_mut(), |v| v as *const i32 as *mut i32)) @@ -29,8 +29,8 @@ impl SafePointer { } } impl DefaultConstructibleUnsafe for SafePointer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.ptr).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).ptr).write(None); } } #[repr(C)] @@ -49,9 +49,9 @@ pub struct Pair { pub y: i32, } impl Pair { - pub unsafe fn inc(&mut self, mut k: i32) { - self.x += k; - self.y += k; + pub unsafe fn inc(this: *mut Self, mut k: i32) { + (*this).x += k; + (*this).y += k; } } pub unsafe fn DoStuffWithSafePointer_0(safe_ptr: *mut Option>) { @@ -79,14 +79,14 @@ pub unsafe fn DoStuffWithSafePointer_0(safe_ptr: *mut Option>) }; (unsafe { SafePointer::inc( - &mut (*(*safe_ptr).as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*(*safe_ptr).as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const SafePointer as *mut SafePointer })), ) }); (unsafe { SafePointer::inc( - &mut (*(*safe_ptr).as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*(*safe_ptr).as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const SafePointer as *mut SafePointer })), ) @@ -114,7 +114,7 @@ pub unsafe fn DoStuffWithSafePointer_0(safe_ptr: *mut Option>) })); (unsafe { Pair::inc( - &mut (*pair + &raw mut (*pair .as_deref() .map_or(::std::ptr::null_mut(), |v| v as *const Pair as *mut Pair)), 10, @@ -226,7 +226,7 @@ pub unsafe fn RndStuff_2() { assert!((((*p3_0.offset((i) as isize)).y) == (2))); (unsafe { Pair::inc( - &mut (*x3 + &raw mut (*x3 .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) .add((i as usize))), @@ -270,7 +270,7 @@ pub unsafe fn RndStuff_2() { assert!((((*p3_1.offset((i) as isize)).y) == (-2_i32))); (unsafe { Pair::inc( - &mut (*x3 + &raw mut (*x3 .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) .add((i as usize))), diff --git a/tests/unit/out/unsafe/unique_ptr_const_deref.rs b/tests/unit/out/unsafe/unique_ptr_const_deref.rs index 8b3e2ab11e..6ee90dac3a 100644 --- a/tests/unit/out/unsafe/unique_ptr_const_deref.rs +++ b/tests/unit/out/unsafe/unique_ptr_const_deref.rs @@ -20,8 +20,8 @@ pub struct Holder { pub val: Option>, } impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.val).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).val).write(None); } } pub unsafe fn read_val_0(mut h: *const Holder) -> i32 { diff --git a/tests/unit/out/unsafe/unique_ptr_field_reset.rs b/tests/unit/out/unsafe/unique_ptr_field_reset.rs index 9dcd1abc2e..141884ba74 100644 --- a/tests/unit/out/unsafe/unique_ptr_field_reset.rs +++ b/tests/unit/out/unsafe/unique_ptr_field_reset.rs @@ -35,10 +35,10 @@ pub struct Holder { pub n: i32, } impl Holder { - pub unsafe fn set(&mut self, mut p: *mut Data) { + pub unsafe fn set(this: *mut Self, mut p: *mut Data) { { let _a0: *mut Data = p; - self.data = if _a0.is_null() { + (*this).data = if _a0.is_null() { None } else { Some(Box::from_raw(_a0)) @@ -47,9 +47,9 @@ impl Holder { } } impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.data).write(None); - (&raw mut self.n).write(0_i32); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).data).write(None); + (&raw mut (*this).n).write(0_i32); } } pub fn main() { @@ -77,7 +77,12 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *const Data as *mut Data)) .v) == (3)) ); - (unsafe { Holder::set(&mut h, (Box::leak(Box::new(Data { v: 4 })) as *mut Data)) }); + (unsafe { + Holder::set( + &raw mut h, + (Box::leak(Box::new(Data { v: 4 })) as *mut Data), + ) + }); assert!( (((*(*hp) .data diff --git a/tests/unit/out/unsafe/unique_ptr_nested.rs b/tests/unit/out/unsafe/unique_ptr_nested.rs index 3ff0cfe3eb..1d6e66ec66 100644 --- a/tests/unit/out/unsafe/unique_ptr_nested.rs +++ b/tests/unit/out/unsafe/unique_ptr_nested.rs @@ -35,8 +35,8 @@ pub struct Outer { pub inner: Option>, } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.inner).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).inner).write(None); } } pub fn main() { diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs index 9536d30ea9..3c13297f45 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -38,14 +38,14 @@ pub struct Guard_1 { pub active: bool, } impl Guard_1 { - pub unsafe fn construct(&mut self, val: *mut *const VaArg) { - (&raw mut self.ap).write(val); - (&raw mut self.active).write(true); + pub unsafe fn construct(this: *mut Self, val: *mut *const VaArg) { + (&raw mut (*this).ap).write(val); + (&raw mut (*this).active).write(true); } } impl DestructibleUnsafe for Guard_1 { - unsafe fn destroy(&mut self) { - if self.active {} + unsafe fn destroy(this: *mut Self) { + if (*this).active {} } } pub unsafe fn sum_ptr_2(mut n: i32, __args: Box<[VaArg]>) -> i32 { diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index d24a3c8bed..1e1283e461 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -39,9 +39,9 @@ pub struct Foo { pub b: Vec, } impl DefaultConstructibleUnsafe for Foo { - unsafe fn default_constructor(&mut self) { - (&raw mut self.a).write(Vec::new()); - (&raw mut self.b).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).a).write(Vec::new()); + (&raw mut (*this).b).write(Vec::new()); } } #[repr(C)] @@ -61,8 +61,8 @@ pub struct Wrapped { pub v: i32, } impl Wrapped { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } pub unsafe fn exchange_1(x: *mut Vec, y: *mut Vec) { diff --git a/tests/unit/out/unsafe/vector2.rs b/tests/unit/out/unsafe/vector2.rs index f678ef14b3..69dde434ba 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; { - v2.assign_from(v); + AssignFromUnsafe::assign_from(&raw mut v2, v); }; (&mut (*v4))[(1_usize)] = 13; assert!(((x) == (6))); diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index 950aef3614..02864261d4 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -23,8 +23,8 @@ pub struct Degrees { pub value: i32, } impl Degrees { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.value).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); } } #[repr(C)] @@ -44,8 +44,8 @@ pub struct Reading { pub raw_: i32, } impl Reading { - pub unsafe fn to_i64(&self) -> i64 { - return ((self.raw_ as i64) * (10_i64)); + pub unsafe fn to_i64(this: *const Self) -> i64 { + return (((*this).raw_ as i64) * (10_i64)); } } pub fn main() { diff --git a/tests/unit/out/unsafe/vector_subscript_direct.rs b/tests/unit/out/unsafe/vector_subscript_direct.rs index 9fb3c0edcc..3811ac10a2 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.rs @@ -22,8 +22,8 @@ pub struct Point { pub y: i32, } impl Point { - pub unsafe fn sum(&self) -> i32 { - return ((self.x) + (self.y)); + pub unsafe fn sum(this: *const Self) -> i32 { + return (((*this).x) + ((*this).y)); } } #[repr(C)] @@ -44,9 +44,9 @@ pub struct Holder { pub points: Vec, } impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); - (&raw mut self.points).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); + (&raw mut (*this).points).write(Vec::new()); } } pub unsafe fn push_and_index_0(v: *mut Vec) -> i32 { @@ -118,7 +118,7 @@ unsafe fn main_0() -> i32 { }; h.points[(0_usize)].y = 5; assert!(((h.values[(1_usize)]) == (6))); - assert!(((unsafe { Point::sum(&h.points[(0_usize)],) }) == (6))); + assert!(((unsafe { Point::sum(&raw const h.points[(0_usize)],) }) == (6))); let mut hp: *mut Holder = (&mut h as *mut Holder); (&mut (*hp)).values[(0_usize)] = (((&mut (*hp)).values[(1_usize)]) + (1)); (&mut (*hp)).points[(0_usize)].x = (&mut (*hp)).values[(0_usize)]; diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index 2998d58793..34293aab10 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -19,10 +19,10 @@ use std::rc::Rc; )] pub struct TestAllocator_int_ {} impl TestAllocator_int_ { - pub unsafe fn allocate(&mut self, mut n: usize) -> *mut i32 { + pub unsafe fn allocate(this: *mut Self, mut n: usize) -> *mut i32 { return Box::leak((0..n).map(|_| 0_i32).collect::>()).as_mut_ptr(); } - pub unsafe fn deallocate(&mut self, mut p: *mut i32, mut _a1: usize) { + pub unsafe fn deallocate(this: *mut Self, mut p: *mut i32, mut _a1: usize) { { let __p = p; if !__p.is_null() { @@ -48,10 +48,10 @@ impl TestAllocator_int_ { )] pub struct TestAllocator_double_ {} impl TestAllocator_double_ { - pub unsafe fn allocate(&mut self, mut n: usize) -> *mut f64 { + pub unsafe fn allocate(this: *mut Self, mut n: usize) -> *mut f64 { return Box::leak((0..n).map(|_| 0_f64).collect::>()).as_mut_ptr(); } - pub unsafe fn deallocate(&mut self, mut p: *mut f64, mut _a1: usize) { + pub unsafe fn deallocate(this: *mut Self, mut p: *mut f64, mut _a1: usize) { { let __p = p; if !__p.is_null() { diff --git a/tests/unit/out/unsafe/void_cast.rs b/tests/unit/out/unsafe/void_cast.rs index ce227797ee..a118dad1d3 100644 --- a/tests/unit/out/unsafe/void_cast.rs +++ b/tests/unit/out/unsafe/void_cast.rs @@ -24,8 +24,8 @@ pub struct NonTrivial { pub data: Vec, } impl DefaultConstructibleUnsafe for NonTrivial { - unsafe fn default_constructor(&mut self) { - (&raw mut self.data).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).data).write(Vec::new()); } } pub unsafe fn unused_ref_param_1(x: *const NonTrivial) {} @@ -64,8 +64,8 @@ pub struct NonCopyable { pub value: Option>, } impl DefaultConstructibleUnsafe for NonCopyable { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(None); } } pub unsafe fn unused_noncopyable_param_5(x: *const NonCopyable) {}