diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index a24a19ee77..f520b22d0e 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -334,8 +334,9 @@ Converter::MaterializeTemp(const std::string &binding_name, std::string value; { ScopedPush init_type(curr_init_type_, pointee); - value = retain_bound_temporaries_ ? ConvertFreshRValue(expr, pointee) - : ConvertRValue(expr, pointee); + value = retain_bound_temporaries_ || !param_type->isReferenceType() + ? ConvertFreshRValue(expr, pointee) + : ConvertRValue(expr, pointee); } auto type_str = ToStringBase(pointee); bool is_static = in_const_initializer_ && !declarations; @@ -405,7 +406,7 @@ Converter::ConvertFunctionPointerType(const clang::FunctionProtoType *proto) { result += ','; } for (auto p_ty : proto->param_types()) { - result += ToString(p_ty); + result += ToString(GetPassedParamType(ctx_, p_ty)); result += ','; } if (proto->isVariadic()) { @@ -616,7 +617,7 @@ bool Converter::NeedsMut(const clang::VarDecl *decl, clang::QualType type, } bool Converter::ConvertVarDeclSkipInit(clang::VarDecl *decl) { - auto qual_type = decl->getType(); + auto qual_type = GetConvertedVarType(decl); if (IsVaListType(qual_type) && decl->isLocalVarDecl()) { StrCat(keyword::kLet, keyword_mut_, GetNamedDeclAsString(decl), token::kColon); @@ -2461,7 +2462,9 @@ Converter::CallInfo Converter::CollectCallInfo(clang::CallExpr *expr) { : Kind::Hoisted, }; bool is_materialize = clang::isa(arg); - if (is_materialize && ca.param_type->isReferenceType()) { + if (UsesReturnSlot(ca.param_type)) { + ca.kind = Kind::Materialized; + } else if (is_materialize && ca.param_type->isReferenceType()) { ca.kind = Kind::Materialized; } else if (is_materialize) { ca.kind = Kind::Inline; @@ -4660,7 +4663,12 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) { } { PushBrace brace(*this); - ConvertVarInit(ctor->getParamDecl(i)->getType(), arg); + auto type = ctor->getParamDecl(i)->getType(); + if (UsesReturnSlot(type)) { + StrCat(EmitMaterializedTempBinding(type, arg)); + } else { + ConvertVarInit(type, arg); + } } StrCat(token::kComma); } diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 49599ff6a1..4569abc4c3 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -848,7 +848,7 @@ static bool HasFieldWithMoveAssign(const clang::RecordDecl *decl) { // Whether a defaulted move assignment of decl isn't a copy assignment. static bool NeedsDefaultedMoveAssignment(const clang::CXXRecordDecl *decl) { - return !decl->isTriviallyCopyable() || !HasDefaultedCopyAssignment(decl) || + return !decl->canPassInRegisters() || !HasDefaultedCopyAssignment(decl) || HasFieldWithMoveAssign(decl); } @@ -902,7 +902,7 @@ bool HasMoveAssignOperator(const clang::RecordDecl *decl) { // fields: when the record has a copy constructor, or a field (or element of // an array field) has a copy assignment operator. static bool NeedsDefaultedCopyAssignment(const clang::CXXRecordDecl *decl) { - return !decl->isTriviallyCopyable() || GetUserDefinedCopyConstructor(decl) || + return !decl->canPassInRegisters() || GetUserDefinedCopyConstructor(decl) || llvm::any_of(decl->fields(), [](const clang::FieldDecl *field) { auto *record = field->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl(); @@ -1063,7 +1063,7 @@ static const clang::Expr *IgnorePlacementWrappers(const clang::Expr *init) { bool UsesReturnSlot(clang::QualType type) { auto *record = type->getAsCXXRecordDecl(); return record && record->hasDefinition() && IsUserDefinedDecl(record) && - !record->isLambda() && !record->isTriviallyCopyable(); + !record->isLambda() && !record->canPassInRegisters(); } bool IsReturnSlotCall(const clang::Expr *expr) { @@ -1889,11 +1889,23 @@ const clang::FieldDecl *AsLambdaCaptureThis(const clang::FunctionDecl *fn) { return nullptr; } +clang::QualType GetPassedParamType(const clang::ASTContext &ctx, + clang::QualType type) { + return UsesReturnSlot(type) ? ctx.getLValueReferenceType(type) : type; +} + +clang::QualType GetConvertedVarType(const clang::ValueDecl *decl) { + if (clang::isa(decl)) { + return GetPassedParamType(decl->getASTContext(), decl->getType()); + } + return decl->getType(); +} + clang::QualType GetDeclRefType(const clang::FunctionDecl *fn, const clang::Expr *expr, const clang::ValueDecl *decl) { auto field = AsLambdaCaptureField(fn, expr); - return field ? field->getType() : decl->getType(); + return field ? field->getType() : GetConvertedVarType(decl); } bool IsUserOperatorCall(const clang::CXXOperatorCallExpr *expr) { diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 0632105b69..d78633d3e1 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -383,6 +383,11 @@ clang::Expr *AsLambdaUncapturedConstant(const clang::FunctionDecl *fn, const clang::FieldDecl *AsLambdaCaptureThis(const clang::FunctionDecl *fn); +clang::QualType GetPassedParamType(const clang::ASTContext &ctx, + clang::QualType type); + +clang::QualType GetConvertedVarType(const clang::ValueDecl *decl); + clang::QualType GetDeclRefType(const clang::FunctionDecl *fn, const clang::Expr *expr, const clang::ValueDecl *decl); diff --git a/cpp2rust/converter/models/boxed_vars.cpp b/cpp2rust/converter/models/boxed_vars.cpp index 036e35baee..a0d63e9b61 100644 --- a/cpp2rust/converter/models/boxed_vars.cpp +++ b/cpp2rust/converter/models/boxed_vars.cpp @@ -38,7 +38,7 @@ bool IsFlatVec(clang::QualType type) { // and iterators translated to pointers, unless they have a destructor, which // is called with a pointer to them. bool CanUnbox(clang::ASTContext &ctx, const clang::VarDecl *decl) { - auto type = decl->getType(); + auto type = GetConvertedVarType(decl); if (IsFlatVec(type)) { // Vectors are flat Vecs. } else if (type->isConstantArrayType()) { diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index f5b59f4463..d8b1a58ac0 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -930,7 +930,7 @@ void ConverterRefCount::EmitFunctionPreamble(clang::FunctionDecl *decl) { } for (auto *param : DefinitionParameters(decl)) { // Unboxed parameters are used in place. - if (param->getType()->isReferenceType() || IsUnboxedVar(param)) { + if (GetConvertedVarType(param)->isReferenceType() || IsUnboxedVar(param)) { continue; } auto name = GetNamedDeclAsString(param); diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 1e9576d87b..de01f93293 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -778,13 +778,9 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { VaArg, FnPtrArg, Destructible, - Memberwise, - CopyConstructible, - MoveConstructible, - Swappable, + Copyable, Default, )] -#[memberwise(copy_assign, move_assign)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { #[offset(0)] diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 686c763bae..c665ced852 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -720,13 +720,9 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, - MemberwiseUnsafe, - CopyConstructibleUnsafe, - MoveConstructibleUnsafe, - SwappableUnsafe, + CopyableUnsafe, Default, )] -#[memberwise(copy_assign, move_assign)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 6552133f34..9d8e95dddf 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -290,8 +290,8 @@ pub fn touch_1(mut t: Ptr) { __v.prefix_inc(); }); } -pub fn by_value_2(mut c: Counted) -> i32 { - return c.v; +pub fn by_value_2(c: Ptr) -> i32 { + return c.with(|__s| __s.v); } pub fn make_3(this: Ptr, mut v: i32) { let c: Value = Rc::new(RefCell::new(::zero_init())); @@ -318,11 +318,9 @@ fn main_0() -> i32 { ); assert!( (({ - by_value_2({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(&__v.as_pointer(), { a.as_pointer() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) + let _c: Value = Rc::new(RefCell::new(::zero_init())); + CopyConstructible::copy_constructor(&_c.as_pointer(), { a.as_pointer() }); + by_value_2(_c.as_pointer()) }) == 1) ); assert!((copies_0.with(|rc| *rc.borrow()) == 4)); diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index 7ca26154cd..de1b673a8f 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -37,14 +37,12 @@ impl Destructible for S { last_1.with(|rc| *rc.borrow_mut() = (*this).with(|__s| __s.v)); } } -pub fn by_value_2(s: S) -> i32 { - let s: Value = Rc::new(RefCell::new(s)); +pub fn by_value_2(s: Ptr) -> i32 { assert!((destroyed_0.with(|rc| *rc.borrow()) == 0)); - return { (*s.borrow()).v }; + return s.with(|__s| __s.v); } -pub fn with_default_3(s: S) -> i32 { - let s: Value = Rc::new(RefCell::new(s)); - return { (*s.borrow()).v }; +pub fn with_default_3(s: Ptr) -> i32 { + return s.with(|__s| __s.v); } #[derive( Copy, @@ -72,26 +70,51 @@ 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())); - assert!((({ by_value_2({ (*s.borrow()).clone() },) }) == 1)); + assert!( + ({ + (({ + let _s: Value = Rc::new(RefCell::new((*s.borrow()).clone())); + by_value_2(_s.as_pointer()) + }) == 1) + }) + ); assert!( (destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 1) ); } assert!((destroyed_0.with(|rc| *rc.borrow()) == 2)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); - assert!((({ by_value_2(S { v: 2 },) }) == 2)); + assert!( + (({ + let _s: Value = Rc::new(RefCell::new(S { v: 2 })); + by_value_2(_s.as_pointer()) + }) == 2) + ); assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 2)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); - assert!((({ with_default_3(S { v: 5 },) }) == 5)); + assert!( + (({ + let _s: Value = Rc::new(RefCell::new(S { v: 5 })); + with_default_3(_s.as_pointer()) + }) == 5) + ); assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 5)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); { let h: Value = Rc::new(RefCell::new(::zero_init())); - HolderImpl::construct(&h.as_pointer(), { S { v: 3 } }); + { + let __tmp_0: Value = Rc::new(RefCell::new(S { v: 3 })); + HolderImpl::construct(&h.as_pointer(), { __tmp_0.as_pointer() }) + }; assert!( (destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 3) ); - assert!((({ HolderImpl::add(&h.as_pointer(), S { v: 4 },) }) == 7)); + assert!( + (({ + let _s: Value = Rc::new(RefCell::new(S { v: 4 })); + HolderImpl::add(&h.as_pointer(), _s.as_pointer()) + }) == 7) + ); assert!( (destroyed_0.with(|rc| *rc.borrow()) == 2) && (last_1.with(|rc| *rc.borrow()) == 4) ); @@ -100,17 +123,15 @@ fn main_0() -> i32 { return 0; } pub trait HolderImpl { - fn construct(&self, s: S); - fn add(&self, s: S) -> i32; + fn construct(&self, s: Ptr); + fn add(&self, s: Ptr) -> i32; } impl HolderImpl for Ptr { - fn construct(&self, s: S) { - let s: Value = Rc::new(RefCell::new(s)); - field!((*self), v).write({ (*s.borrow()).v }); + fn construct(&self, s: Ptr) { + field!((*self), v).write(s.with(|__s| __s.v)); } - fn add(&self, s: S) -> i32 { - let s: Value = Rc::new(RefCell::new(s)); - return ((*self).with(|__s| __s.v) + { (*s.borrow()).v }); + fn add(&self, s: Ptr) -> i32 { + return ((*self).with(|__s| __s.v) + s.with(|__s| __s.v)); } } pub fn __cpp2rust_init_globals() { diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index 128d7d2399..3ae848f70f 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -75,9 +75,8 @@ pub fn make_move_only_2(this: Ptr) { MoveOnlyImpl::construct(&this, { 4 }); return; } -pub fn scale_move_only_3(this: Ptr, x: MoveOnly) { - let x: Value = Rc::new(RefCell::new(x)); - MoveOnlyImpl::construct(&this, { (({ MoveOnlyImpl::get(&x.as_pointer()) }) * 10) }); +pub fn scale_move_only_3(this: Ptr, x: Ptr) { + MoveOnlyImpl::construct(&this, { (({ MoveOnlyImpl::get(&x) }) * 10) }); return; } pub fn main() { @@ -113,15 +112,13 @@ fn main_0() -> i32 { let m: Value = Rc::new(RefCell::new(::zero_init())); ({ mk.call(Ptr::clone(&m.as_pointer())) }); assert!((({ MoveOnlyImpl::get(&m.as_pointer(),) }) == 4)); - let mut sc: FnPtr, MoveOnly)> = - FnPtr::, MoveOnly)>::new(scale_move_only_3); + let mut sc: FnPtr, Ptr)> = + FnPtr::, Ptr)>::new(scale_move_only_3); let n: Value = Rc::new(RefCell::new(::zero_init())); ({ - sc.call(Ptr::clone(&n.as_pointer()), { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(&__v.as_pointer(), { m.as_pointer() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) + let _arg0: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&_arg0.as_pointer(), { m.as_pointer() }); + sc.call(Ptr::clone(&n.as_pointer()), _arg0.as_pointer()) }); assert!((({ MoveOnlyImpl::get(&n.as_pointer(),) }) == 40)); assert!((({ MoveOnlyImpl::get(&m.as_pointer(),) }) == 0)); diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index e0edf48c4c..7ff07c899a 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -73,9 +73,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: Tracked) { - let t: Value = Rc::new(RefCell::new(t)); - MoveConstructible::move_constructor(&this, { t.as_pointer() }); +pub fn copy_or_move_into_param_4(this: Ptr, t: Ptr) { + MoveConstructible::move_constructor(&this, { (t).clone() }); return; } pub fn main() { @@ -97,11 +96,9 @@ fn main_0() -> i32 { TrackedImpl::construct(&b.as_pointer(), { 6 }); let moved: Value = Rc::new(RefCell::new(::zero_init())); ({ - copy_or_move_into_param_4(Ptr::clone(&moved.as_pointer()), { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(&__v.as_pointer(), { b.as_pointer() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) + let _t: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&_t.as_pointer(), { b.as_pointer() }); + copy_or_move_into_param_4(Ptr::clone(&moved.as_pointer()), _t.as_pointer()) }); assert!(({ (*moved.borrow()).v } == 6)); assert!(({ (*moved.borrow()).copies } == 0)); @@ -111,11 +108,9 @@ fn main_0() -> i32 { TrackedImpl::construct(&c.as_pointer(), { 7 }); let copied: Value = Rc::new(RefCell::new(::zero_init())); ({ - copy_or_move_into_param_4(Ptr::clone(&copied.as_pointer()), { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(&__v.as_pointer(), { c.as_pointer() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) + let _t: Value = Rc::new(RefCell::new(::zero_init())); + CopyConstructible::copy_constructor(&_t.as_pointer(), { c.as_pointer() }); + copy_or_move_into_param_4(Ptr::clone(&copied.as_pointer()), _t.as_pointer()) }); assert!(({ (*copied.borrow()).v } == 7)); assert!(({ (*copied.borrow()).copies } == 1)); diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index f939859150..4cc361382a 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -143,8 +143,8 @@ impl Clone for NoexceptMove { Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -pub fn by_value_0(mut m: MoveOnly) -> i32 { - return m.v; +pub fn by_value_0(m: Ptr) -> i32 { + return m.with(|__s| __s.v); } pub fn make_1(this: Ptr, mut v: i32) { let m: Value = Rc::new(RefCell::new(::zero_init())); @@ -176,20 +176,16 @@ fn main_0() -> i32 { assert!(({ (*e.borrow()).v } == 5)); assert!( (({ - by_value_0({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::construct(&__v.as_pointer(), { 6 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) + let _m: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnlyImpl::construct(&_m.as_pointer(), { 6 }); + by_value_0(_m.as_pointer()) }) == 6) ); assert!( (({ - by_value_0({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(&__v.as_pointer(), { e.as_pointer() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) + let _m: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&_m.as_pointer(), { e.as_pointer() }); + by_value_0(_m.as_pointer()) }) == 5) ); assert!(({ (*e.borrow()).v } == 0)); diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index c246783611..22b0fb3852 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -44,8 +44,8 @@ impl Clone for Chain { Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -pub fn consume_0(mut c: Chain) -> i32 { - return c.v; +pub fn consume_0(c: Ptr) -> i32 { + return c.with(|__s| __s.v); } pub fn main() { __cpp2rust_init_globals(); @@ -84,13 +84,11 @@ fn main_0() -> i32 { ChainImpl::construct(&g.as_pointer(), { 20 }); assert!( (({ - consume_0({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(&__v.as_pointer(), { - ({ ChainImpl::self_(&g.as_pointer()) }) - }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) + let _c: Value = Rc::new(RefCell::new(::zero_init())); + MoveConstructible::move_constructor(&_c.as_pointer(), { + ({ ChainImpl::self_(&g.as_pointer()) }) + }); + consume_0(_c.as_pointer()) }) == 21) ); let e: Value = Rc::new(RefCell::new(::zero_init())); diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 34df69c218..dbd0e85acc 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -272,8 +272,8 @@ impl Default for Tracked { pub unsafe fn touch_1(mut t: *const Tracked) { (*(&raw const (*t).copied_from).cast_mut()).prefix_inc(); } -pub unsafe fn by_value_2(mut c: Counted) -> i32 { - return c.v; +pub unsafe fn by_value_2(c: *mut Counted) -> i32 { + return (*c).v; } pub unsafe fn make_3(this: *mut Counted, mut v: i32) { let mut c: Counted = ::zero_init(); @@ -300,11 +300,9 @@ unsafe fn main_0() -> i32 { assert!((((b.v) == (1)) && ((c.v) == (1))) && ((d.v) == (1))); assert!( ((unsafe { - by_value_2({ - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, { &a }); - __v - }) + let mut _c: Counted = ::zero_init(); + CopyConstructibleUnsafe::copy_constructor(&mut _c, { &a }); + by_value_2(&mut _c) }) == (1)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (4))); diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index 3295a48960..8e4a961d80 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -30,12 +30,12 @@ impl DestructibleUnsafe for S { (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = self.v; } } -pub unsafe fn by_value_2(mut s: S) -> i32 { +pub unsafe fn by_value_2(s: *mut S) -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (0))); - return s.v; + return (*s).v; } -pub unsafe fn with_default_3(mut s: S) -> i32 { - return s.v; +pub unsafe fn with_default_3(s: *mut S) -> i32 { + return (*s).v; } #[repr(C)] #[derive( @@ -52,11 +52,11 @@ pub struct Holder { pub v: i32, } impl Holder { - pub unsafe fn construct(&mut self, mut s: S) { - (&raw mut self.v).write(s.v); + pub unsafe fn construct(&mut self, s: *mut S) { + (&raw mut self.v).write((*s).v); } - pub unsafe fn add(&self, mut s: S) -> i32 { - return ((self.v) + (s.v)); + pub unsafe fn add(&self, s: *mut S) -> i32 { + return ((self.v) + ((*s).v)); } } pub fn main() { @@ -71,7 +71,12 @@ unsafe fn main_0() -> i32 { let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); - assert!(((unsafe { by_value_2(s.clone(),) }) == (1))); + assert!( + ((unsafe { + let mut _s: S = s.clone(); + by_value_2(&mut _s) + }) == (1)) + ); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (1)) @@ -79,13 +84,23 @@ unsafe fn main_0() -> i32 { } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (2))); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; - assert!(((unsafe { by_value_2(S { v: 2 },) }) == (2))); + assert!( + ((unsafe { + let mut _s: S = S { v: 2 }; + by_value_2(&mut _s) + }) == (2)) + ); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (2)) ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; - assert!(((unsafe { with_default_3(S { v: 5 },) }) == (5))); + assert!( + ((unsafe { + let mut _s: S = S { v: 5 }; + with_default_3(&mut _s) + }) == (5)) + ); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (5)) @@ -93,12 +108,20 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { let mut h: Holder = ::zero_init(); - Holder::construct(&mut h, { S { v: 3 } }); + { + let mut __tmp_0: S = S { v: 3 }; + Holder::construct(&mut h, { &mut __tmp_0 }) + }; assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (3)) ); - assert!(((unsafe { Holder::add(&h, S { v: 4 },) }) == (7))); + assert!( + ((unsafe { + let mut _s: S = S { v: 4 }; + Holder::add(&h, &mut _s) + }) == (7)) + ); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (4)) diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index 2dfe9fcc22..66ed45f1e1 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -76,8 +76,8 @@ pub unsafe fn make_move_only_2(this: *mut MoveOnly) { MoveOnly::construct(&mut *this, { 4 }); return; } -pub unsafe fn scale_move_only_3(this: *mut MoveOnly, mut x: MoveOnly) { - MoveOnly::construct(&mut *this, { ((unsafe { MoveOnly::get(&x) }) * (10)) }); +pub unsafe fn scale_move_only_3(this: *mut MoveOnly, x: *mut MoveOnly) { + MoveOnly::construct(&mut *this, { ((unsafe { MoveOnly::get(&(*x)) }) * (10)) }); return; } pub fn main() { @@ -115,14 +115,12 @@ unsafe fn main_0() -> i32 { let mut m: MoveOnly = ::zero_init(); (unsafe { (mk).unwrap()(&mut m) }); assert!(((unsafe { MoveOnly::get(&m,) }) == (4))); - let mut sc: Option = Some(scale_move_only_3); + let mut sc: Option = Some(scale_move_only_3); let mut n: MoveOnly = ::zero_init(); (unsafe { - (sc).unwrap()(&mut n, { - let mut __v: MoveOnly = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut m }); - __v - }) + let mut _arg0: MoveOnly = ::zero_init(); + MoveConstructibleUnsafe::move_constructor(&mut _arg0, { &mut m }); + (sc).unwrap()(&mut n, &mut _arg0) }); assert!(((unsafe { MoveOnly::get(&n,) }) == (40))); assert!(((unsafe { MoveOnly::get(&m,) }) == (0))); diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index 743926faf8..1806e696f0 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -72,8 +72,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, mut t: Tracked) { - MoveConstructibleUnsafe::move_constructor(&mut *this, { &mut t }); +pub unsafe fn copy_or_move_into_param_4(this: *mut Tracked, t: *mut Tracked) { + MoveConstructibleUnsafe::move_constructor(&mut *this, { t }); return; } pub fn main() { @@ -95,11 +95,9 @@ unsafe fn main_0() -> i32 { Tracked::construct(&mut b, { 6 }); let mut moved: Tracked = ::zero_init(); (unsafe { - copy_or_move_into_param_4(&mut moved, { - let mut __v: Tracked = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut b }); - __v - }) + let mut _t: Tracked = ::zero_init(); + MoveConstructibleUnsafe::move_constructor(&mut _t, { &mut b }); + copy_or_move_into_param_4(&mut moved, &mut _t) }); assert!(((moved.v) == (6))); assert!(((moved.copies) == (0))); @@ -109,11 +107,9 @@ unsafe fn main_0() -> i32 { Tracked::construct(&mut c, { 7 }); let mut copied: Tracked = ::zero_init(); (unsafe { - copy_or_move_into_param_4(&mut copied, { - let mut __v: Tracked = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); - __v - }) + let mut _t: Tracked = ::zero_init(); + CopyConstructibleUnsafe::copy_constructor(&mut _t, { &c }); + copy_or_move_into_param_4(&mut copied, &mut _t) }); assert!(((copied.v) == (7))); assert!(((copied.copies) == (1))); diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index 5e17dae306..7a4d99e982 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -152,8 +152,8 @@ impl Clone for NoexceptMove { } } } -pub unsafe fn by_value_0(mut m: MoveOnly) -> i32 { - return m.v; +pub unsafe fn by_value_0(m: *mut MoveOnly) -> i32 { + return (*m).v; } pub unsafe fn make_1(this: *mut MoveOnly, mut v: i32) { let mut m: MoveOnly = ::zero_init(); @@ -187,20 +187,16 @@ unsafe fn main_0() -> i32 { assert!(((e.v) == (5))); assert!( ((unsafe { - by_value_0({ - let mut __v: MoveOnly = ::zero_init(); - MoveOnly::construct(&mut __v, { 6 }); - __v - }) + let mut _m: MoveOnly = ::zero_init(); + MoveOnly::construct(&mut _m, { 6 }); + by_value_0(&mut _m) }) == (6)) ); assert!( ((unsafe { - by_value_0({ - let mut __v: MoveOnly = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut e }); - __v - }) + let mut _m: MoveOnly = ::zero_init(); + MoveConstructibleUnsafe::move_constructor(&mut _m, { &mut e }); + by_value_0(&mut _m) }) == (5)) ); assert!(((e.v) == (0))); diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index 5106bbda02..72e29f0353 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -66,8 +66,8 @@ impl Clone for Chain { } } } -pub unsafe fn consume_0(mut c: Chain) -> i32 { - return c.v; +pub unsafe fn consume_0(c: *mut Chain) -> i32 { + return (*c).v; } pub fn main() { unsafe { @@ -108,13 +108,11 @@ unsafe fn main_0() -> i32 { Chain::construct(&mut g, { 20 }); assert!( ((unsafe { - consume_0({ - let mut __v: Chain = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, { - (unsafe { Chain::self_(&mut g) }) - }); - __v - }) + let mut _c: Chain = ::zero_init(); + MoveConstructibleUnsafe::move_constructor(&mut _c, { + (unsafe { Chain::self_(&mut g) }) + }); + consume_0(&mut _c) }) == (21)) ); let mut e: Chain = ::zero_init();