From e9c3a39b93fba506f36bfe0fd95918d94b360379 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Tue, 1 Dec 2026 16:09:19 +0000 Subject: [PATCH 01/12] Update rules --- .../utility/out/refcount/forward-helpers.rs | 70 ++++++++--------- .../utility/out/unsafe/forward-helpers.rs | 48 +++++------- tests/unit/out/refcount/copy_ctor.rs | 14 ++-- .../out/refcount/destructor_temporaries.rs | 78 +++++++++++++++---- tests/unit/out/refcount/fn_ptr_struct.rs | 46 +++++------ tests/unit/out/refcount/forward_basic.rs | 38 ++++----- tests/unit/out/refcount/forward_explicit.rs | 31 ++++---- tests/unit/out/refcount/forward_pack.rs | 30 +++---- .../out/refcount/lambda_capture_copy_ctor.rs | 41 +++++----- tests/unit/out/refcount/map_key_copy_ctor.rs | 25 ++++-- tests/unit/out/refcount/max.rs | 37 ++++++--- tests/unit/out/refcount/move_assign.rs | 15 ++-- tests/unit/out/refcount/move_ctor.rs | 12 ++- tests/unit/out/refcount/move_this.rs | 56 +++++++------ tests/unit/out/refcount/rule_of_five.rs | 12 ++- .../refcount/structured_binding_copy_ctor.rs | 15 ++-- .../structured_binding_element_ctor.rs | 13 +++- .../refcount/structured_binding_move_ctor.rs | 16 ++-- .../unit/out/refcount/temporary_field_addr.rs | 48 +++++++++--- .../out/refcount/temporary_field_ctor_arg.rs | 15 +++- .../out/refcount/temporary_field_two_args.rs | 23 ++++-- tests/unit/out/unsafe/copy_ctor.rs | 12 ++- .../unit/out/unsafe/destructor_temporaries.rs | 71 +++++++++++++---- tests/unit/out/unsafe/fn_ptr_struct.rs | 30 ++++--- tests/unit/out/unsafe/forward_basic.rs | 28 +++---- tests/unit/out/unsafe/forward_explicit.rs | 19 +++-- tests/unit/out/unsafe/forward_pack.rs | 18 +++-- .../out/unsafe/lambda_capture_copy_ctor.rs | 39 +++++----- tests/unit/out/unsafe/map_key_copy_ctor.rs | 23 ++++-- tests/unit/out/unsafe/max.rs | 33 +++++--- tests/unit/out/unsafe/move_assign.rs | 15 ++-- tests/unit/out/unsafe/move_ctor.rs | 12 ++- tests/unit/out/unsafe/move_this.rs | 40 +++++----- tests/unit/out/unsafe/rule_of_five.rs | 12 ++- .../unsafe/structured_binding_copy_ctor.rs | 15 ++-- .../unsafe/structured_binding_element_ctor.rs | 13 +++- .../unsafe/structured_binding_move_ctor.rs | 13 +++- tests/unit/out/unsafe/temporary_field_addr.rs | 49 ++++++++++-- .../out/unsafe/temporary_field_ctor_arg.rs | 16 +++- .../out/unsafe/temporary_field_two_args.rs | 22 ++++-- 40 files changed, 690 insertions(+), 473 deletions(-) diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 82816a7f3d..aca3d2f6e6 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -90,30 +90,26 @@ impl Default for p6_forward_like_Holder { } } } -pub fn take_1(self_: Ptr) -> p6_forward_like_Movable { - return { - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(&__v.as_pointer(), { field_ptr!(self_, member) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; +pub fn take_1(this: Ptr, self_: Ptr) { + CopyConstructible::copy_constructor(&this, { field_ptr!(self_, member) }); + return; } -pub fn take_2(self_: Ptr) -> p6_forward_like_Movable { - return { - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(&__v.as_pointer(), { field_ptr!(self_, member) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; +pub fn take_2(this: Ptr, self_: Ptr) { + MoveConstructible::move_constructor(&this, { field_ptr!(self_, member) }); + return; } pub fn test_3() { let holder: Value = Rc::new(RefCell::new(::zero_init())); p6_forward_like_HolderImpl::construct_1(&holder.as_pointer()); - let mut copied: p6_forward_like_Movable = ({ take_1(holder.as_pointer()) }); - assert!((copied.value == 1) && ({ (*holder.borrow()).member.value } == 1)); - let mut moved: p6_forward_like_Movable = ({ take_2(holder.as_pointer()) }); - assert!((moved.value == 1) && ({ (*holder.borrow()).member.value } == 0)); + let copied: Value = + Rc::new(RefCell::new(::zero_init())); + ({ take_1(Ptr::clone(&copied.as_pointer()), holder.as_pointer()) }); + assert!(({ (*copied.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 1)); + let moved: Value = + Rc::new(RefCell::new(::zero_init())); + ({ take_2(Ptr::clone(&moved.as_pointer()), holder.as_pointer()) }); + assert!(({ (*moved.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 0)); } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_from(i32, construct, value)] @@ -222,31 +218,33 @@ impl Default for p10_forward_in_template_A { { ::zero_init() } } } -pub fn make_5(source: Ptr) -> p10_forward_in_template_A { - return { - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(&__v.as_pointer(), { (source).clone() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; +pub fn make_5(this: Ptr, source: Ptr) { + CopyConstructible::copy_constructor(&this, { (source).clone() }); + return; } -pub fn make_6(source: Ptr) -> p10_forward_in_template_A { - return { - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(&__v.as_pointer(), { (source).clone() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; +pub fn make_6(this: Ptr, source: Ptr) { + MoveConstructible::move_constructor(&this, { (source).clone() }); + return; } pub fn test_7() { let a: Value = Rc::new(RefCell::new(::zero_init())); p10_forward_in_template_AImpl::construct(&a.as_pointer(), { 1 }); - let mut copied: p10_forward_in_template_A = ({ make_5(a.as_pointer()) }); - assert!(((copied.value == 1) && (copied.copies == 1)) && (copied.moves == 0)); + let copied: Value = + Rc::new(RefCell::new(::zero_init())); + ({ make_5(Ptr::clone(&copied.as_pointer()), a.as_pointer()) }); + assert!( + (({ (*copied.borrow()).value } == 1) && ({ (*copied.borrow()).copies } == 1)) + && ({ (*copied.borrow()).moves } == 0) + ); assert!(({ (*a.borrow()).value } == 1)); - let mut moved: p10_forward_in_template_A = ({ make_6(a.as_pointer()) }); - assert!(((moved.value == 1) && (moved.copies == 0)) && (moved.moves == 1)); + let moved: Value = + Rc::new(RefCell::new(::zero_init())); + ({ make_6(Ptr::clone(&moved.as_pointer()), a.as_pointer()) }); + assert!( + (({ (*moved.borrow()).value } == 1) && ({ (*moved.borrow()).copies } == 0)) + && ({ (*moved.borrow()).moves } == 1) + ); assert!(({ (*a.borrow()).value } == 0)); } #[derive( diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index 95587da170..02d80b3f2f 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -92,26 +92,22 @@ impl Default for p6_forward_like_Holder { } } } -pub unsafe fn take_1(self_: *mut p6_forward_like_Holder) -> p6_forward_like_Movable { - return { - let mut __v: p6_forward_like_Movable = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, { &(*self_).member }); - __v - }; +pub unsafe fn take_1(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { + CopyConstructibleUnsafe::copy_constructor(&mut *this, { &(*self_).member }); + return; } -pub unsafe fn take_2(self_: *mut p6_forward_like_Holder) -> p6_forward_like_Movable { - return { - let mut __v: p6_forward_like_Movable = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*self_).member }); - __v - }; +pub unsafe fn take_2(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { + MoveConstructibleUnsafe::move_constructor(&mut *this, { &mut (*self_).member }); + return; } pub unsafe fn test_3() { let mut holder: p6_forward_like_Holder = ::zero_init(); p6_forward_like_Holder::construct_1(&mut holder); - let mut copied: p6_forward_like_Movable = (unsafe { take_1(&mut holder) }); + let mut copied: p6_forward_like_Movable = ::zero_init(); + (unsafe { take_1(&mut copied, &mut holder) }); assert!(((copied.value) == (1)) && ((holder.member.value) == (1))); - let mut moved: p6_forward_like_Movable = (unsafe { take_2(&mut holder) }); + let mut moved: p6_forward_like_Movable = ::zero_init(); + (unsafe { take_2(&mut moved, &mut holder) }); assert!(((moved.value) == (1)) && ((holder.member.value) == (0))); } #[repr(C)] @@ -222,27 +218,23 @@ impl Default for p10_forward_in_template_A { unsafe { ::zero_init() } } } -pub unsafe fn make_5(source: *mut p10_forward_in_template_A) -> p10_forward_in_template_A { - return { - let mut __v: p10_forward_in_template_A = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, { source }); - __v - }; +pub unsafe fn make_5(this: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A) { + CopyConstructibleUnsafe::copy_constructor(&mut *this, { source }); + return; } -pub unsafe fn make_6(source: *mut p10_forward_in_template_A) -> p10_forward_in_template_A { - return { - let mut __v: p10_forward_in_template_A = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, { source }); - __v - }; +pub unsafe fn make_6(this: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A) { + MoveConstructibleUnsafe::move_constructor(&mut *this, { source }); + return; } pub unsafe fn test_7() { let mut a: p10_forward_in_template_A = ::zero_init(); p10_forward_in_template_A::construct(&mut a, { 1 }); - let mut copied: p10_forward_in_template_A = (unsafe { make_5(&mut a) }); + let mut copied: p10_forward_in_template_A = ::zero_init(); + (unsafe { make_5(&mut copied, &mut a) }); assert!((((copied.value) == (1)) && ((copied.copies) == (1))) && ((copied.moves) == (0))); assert!(((a.value) == (1))); - let mut moved: p10_forward_in_template_A = (unsafe { make_6(&mut a) }); + let mut moved: p10_forward_in_template_A = ::zero_init(); + (unsafe { make_6(&mut moved, &mut a) }); assert!((((moved.value) == (1)) && ((moved.copies) == (0))) && ((moved.moves) == (1))); assert!(((a.value) == (0))); } diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 2a49235cd4..b233c65a4b 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -274,14 +274,11 @@ pub fn touch_1(mut t: Ptr) { pub fn by_value_2(mut c: Counted) -> i32 { return c.v; } -pub fn make_3(mut v: i32) -> Counted { +pub fn make_3(this: Ptr, mut v: i32) { let c: Value = Rc::new(RefCell::new(::zero_init())); CountedImpl::construct(&c.as_pointer(), { v }); - return { - 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() - }; + CopyConstructible::copy_constructor(&this, { c.as_pointer() }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -310,8 +307,9 @@ fn main_0() -> i32 { }) == 1) ); assert!((copies_0.with(|rc| *rc.borrow()) == 4)); - let mut e: Counted = ({ make_3(5) }); - assert!((e.v == 5)); + let e: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_3(Ptr::clone(&e.as_pointer()), 5) }); + assert!(({ (*e.borrow()).v } == 5)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); let f: Value = Rc::new(RefCell::new(::zero_init())); CountedImpl::construct(&f.as_pointer(), { 6 }); diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index 6d362528fb..9579f8af2f 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -36,14 +36,16 @@ pub struct Outer { #[offset(4)] pub w: i32, } -pub fn make_2(mut v: i32) -> S { - return S { v: v }; +pub fn make_2(this: Ptr, mut v: i32) { + this.write(S { v: v }); + return; } -pub fn make_outer_3() -> Outer { - return Outer { +pub fn make_outer_3(this: Ptr) { + this.write(Outer { inner: S { v: 7 }, w: 8, - }; + }); + return; } pub fn use_4(s: Ptr) -> i32 { assert!((destroyed_0.with(|rc| *rc.borrow()) == 0)); @@ -57,25 +59,57 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ make_2(1) }); + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_2(Ptr::clone(&__v.as_pointer()), 1) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 1)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); - &({ make_2(2) }); + &({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_2(Ptr::clone(&__v.as_pointer()), 2) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 2)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); - let mut x: i32 = { ({ make_2(3) }).v }; + let mut x: i32 = { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_2(Ptr::clone(&__v.as_pointer()), 3) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + .v + }; assert!( ((x == 3) && (destroyed_0.with(|rc| *rc.borrow()) == 1)) && (last_1.with(|rc| *rc.borrow()) == 3) ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); - x = ({ SImpl::get(&Rc::new(RefCell::new(({ make_2(4) }))).as_pointer()) }); + x = ({ + SImpl::get( + &Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_2(Ptr::clone(&__v.as_pointer()), 4) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer(), + ) + }); assert!( ((x == 4) && (destroyed_0.with(|rc| *rc.borrow()) == 1)) && (last_1.with(|rc| *rc.borrow()) == 4) ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); - x = { ({ make_outer_3() }).inner.v }; + x = { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_outer_3(Ptr::clone(&__v.as_pointer())) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + .inner + .v + }; assert!( ((x == 7) && (destroyed_0.with(|rc| *rc.borrow()) == 1)) && (last_1.with(|rc| *rc.borrow()) == 7) @@ -85,7 +119,11 @@ fn main_0() -> i32 { assert!((x == 5) && (destroyed_0.with(|rc| *rc.borrow()) == 1)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); x = ({ - let _s: Value = Rc::new(RefCell::new(({ make_2(6) }))); + let _s: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_2(Ptr::clone(&__v.as_pointer()), 6) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); use_4(_s.as_pointer()) }); assert!( @@ -104,7 +142,11 @@ fn main_0() -> i32 { destroyed_0.with(|rc| *rc.borrow_mut() = 0); x = { (if (x == 3) { - ({ make_2(9) }) + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_2(Ptr::clone(&__v.as_pointer()), 9) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } } else { S { v: 10 } }) @@ -116,7 +158,11 @@ fn main_0() -> i32 { ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); { - let __tmp_0: Value = Rc::new(RefCell::new(({ make_2(11) }))); + let __tmp_0: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_2(Ptr::clone(&__v.as_pointer()), 11) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let r: Ptr = __tmp_0.as_pointer(); assert!((destroyed_0.with(|rc| *rc.borrow()) == 0) && (r.with(|__s| __s.v) == 11)); } @@ -126,7 +172,11 @@ 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())); - let __rhs = ({ make_2(13) }); + let __rhs = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_2(Ptr::clone(&__v.as_pointer()), 13) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; (*s.borrow_mut()) = __rhs; assert!( ((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 13)) diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index 5b5a84f3c8..020d97616e 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -61,22 +61,14 @@ impl MoveConstructible for MoveOnly { field!(x, data_).write(0); } } -pub fn make_move_only_2() -> MoveOnly { - return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::construct(&__v.as_pointer(), { 4 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; +pub fn make_move_only_2(this: Ptr) { + MoveOnlyImpl::construct(&this, { 4 }); + return; } -pub fn scale_move_only_3(x: MoveOnly) -> MoveOnly { +pub fn scale_move_only_3(this: Ptr, x: MoveOnly) { let x: Value = Rc::new(RefCell::new(x)); - return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::construct(&__v.as_pointer(), { - (({ MoveOnlyImpl::get(&x.as_pointer()) }) * 10) - }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + MoveOnlyImpl::construct(&this, { (({ MoveOnlyImpl::get(&x.as_pointer()) }) * 10) }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -107,20 +99,20 @@ fn main_0() -> i32 { h1.cb = FnPtr:: i32>::new(negate_1); assert!((({ h1.cb.call(3,) }) == -3_i32)); assert!(({ (h1.cb).clone() } == { (h2.cb).clone() })); - let mut mk: FnPtr MoveOnly> = FnPtr:: MoveOnly>::new(make_move_only_2); - let m: Value = Rc::new(RefCell::new(({ mk.call() }))); + let mut mk: FnPtr)> = FnPtr::)>::new(make_move_only_2); + 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 n: Value = Rc::new(RefCell::new( - ({ - sc.call({ - 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 mut sc: FnPtr, MoveOnly)> = + FnPtr::, MoveOnly)>::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() + }) + }); assert!((({ MoveOnlyImpl::get(&n.as_pointer(),) }) == 40)); assert!((({ MoveOnlyImpl::get(&m.as_pointer(),) }) == 0)); return 0; diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index 61255eb73b..55574a021e 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -101,19 +101,13 @@ 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(x: Ptr) -> Holder { - return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - HolderImpl::construct_1(&__v.as_pointer(), { (x).clone() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; +pub fn forward_into_ctor_6(this: Ptr, x: Ptr) { + HolderImpl::construct_1(&this, { (x).clone() }); + return; } -pub fn forward_into_ctor_7(x: Ptr) -> Holder { - return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - HolderImpl::construct_2(&__v.as_pointer(), { (x).clone() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; +pub fn forward_into_ctor_7(this: Ptr, x: Ptr) { + HolderImpl::construct_2(&this, { (x).clone() }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -157,22 +151,24 @@ fn main_0() -> i32 { ); let kept: Value = Rc::new(RefCell::new(::zero_init())); TrackedImpl::construct(&kept.as_pointer(), { 11 }); - let mut from_lvalue: Holder = ({ forward_into_ctor_6(kept.as_pointer()) }); - assert!((from_lvalue.t.v == 11)); - assert!((from_lvalue.t.copies == 1)); - assert!((from_lvalue.t.moves == 0)); + let from_lvalue: Value = Rc::new(RefCell::new(::zero_init())); + ({ forward_into_ctor_6(Ptr::clone(&from_lvalue.as_pointer()), kept.as_pointer()) }); + assert!(({ (*from_lvalue.borrow()).t.v } == 11)); + assert!(({ (*from_lvalue.borrow()).t.copies } == 1)); + assert!(({ (*from_lvalue.borrow()).t.moves } == 0)); assert!(({ (*kept.borrow()).v } == 11)); - let mut from_rvalue: Holder = ({ + let from_rvalue: Value = Rc::new(RefCell::new(::zero_init())); + ({ let _x: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); TrackedImpl::construct(&__v.as_pointer(), { 12 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - forward_into_ctor_7(_x.as_pointer()) + forward_into_ctor_7(Ptr::clone(&from_rvalue.as_pointer()), _x.as_pointer()) }); - assert!((from_rvalue.t.v == 12)); - assert!((from_rvalue.t.copies == 0)); - assert!((from_rvalue.t.moves == 1)); + 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 { diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index 222435ff5c..b26735659d 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -73,13 +73,10 @@ 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(t: Tracked) -> Tracked { +pub fn copy_or_move_into_param_4(this: Ptr, t: Tracked) { let t: Value = Rc::new(RefCell::new(t)); - return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(&__v.as_pointer(), { t.as_pointer() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + MoveConstructible::move_constructor(&this, { t.as_pointer() }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -98,29 +95,31 @@ fn main_0() -> i32 { assert!(({ (*a.borrow()).v } == 5)); let b: Value = Rc::new(RefCell::new(::zero_init())); TrackedImpl::construct(&b.as_pointer(), { 6 }); - let mut moved: Tracked = ({ - copy_or_move_into_param_4({ + 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() }) }); - assert!((moved.v == 6)); - assert!((moved.copies == 0)); - assert!((moved.moves == 2)); + assert!(({ (*moved.borrow()).v } == 6)); + assert!(({ (*moved.borrow()).copies } == 0)); + assert!(({ (*moved.borrow()).moves } == 2)); assert!(({ (*b.borrow()).v } == 0)); let c: Value = Rc::new(RefCell::new(::zero_init())); TrackedImpl::construct(&c.as_pointer(), { 7 }); - let mut copied: Tracked = ({ - copy_or_move_into_param_4({ + 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() }) }); - assert!((copied.v == 7)); - assert!((copied.copies == 1)); - assert!((copied.moves == 1)); + assert!(({ (*copied.borrow()).v } == 7)); + assert!(({ (*copied.borrow()).copies } == 1)); + assert!(({ (*copied.borrow()).moves } == 1)); assert!(({ (*c.borrow()).v } == 7)); let i: Value = Rc::new(RefCell::new(8)); assert!( diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index 4d3f7077cc..3186b99a45 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -133,14 +133,9 @@ pub struct Pair { #[byte_size(12)] pub b: Tracked, } -pub fn forward_pack_into_ctor_8(args_0: Ptr, args_1: Ptr) -> Pair { - return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - PairImpl::construct(&__v.as_pointer(), { (args_0).clone() }, { - (args_1).clone() - }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; +pub fn forward_pack_into_ctor_8(this: Ptr, args_0: Ptr, args_1: Ptr) { + PairImpl::construct(&this, { (args_0).clone() }, { (args_1).clone() }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -183,19 +178,24 @@ fn main_0() -> i32 { assert!(({ ((*i.borrow()) == 3) })); let lhs: Value = Rc::new(RefCell::new(::zero_init())); TrackedImpl::construct(&lhs.as_pointer(), { 6 }); - let mut p: Pair = ({ + let p: Value = Rc::new(RefCell::new(::zero_init())); + ({ let _args_1: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); TrackedImpl::construct(&__v.as_pointer(), { 7 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - forward_pack_into_ctor_8(lhs.as_pointer(), _args_1.as_pointer()) + forward_pack_into_ctor_8( + Ptr::clone(&p.as_pointer()), + lhs.as_pointer(), + _args_1.as_pointer(), + ) }); - assert!((p.a.v == 6)); - assert!((p.a.copies == 1)); - assert!((p.b.v == 7)); - assert!((p.b.copies == 0)); - assert!((p.b.moves == 1)); + assert!(({ (*p.borrow()).a.v } == 6)); + assert!(({ (*p.borrow()).a.copies } == 1)); + assert!(({ (*p.borrow()).b.v } == 7)); + assert!(({ (*p.borrow()).b.copies } == 0)); + assert!(({ (*p.borrow()).b.moves } == 1)); assert!(({ (*lhs.borrow()).v } == 6)); return 0; } diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index ca8593aac8..be617e7eb1 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -122,25 +122,28 @@ fn main_0() -> i32 { let h: Value i32>> = Rc::new(RefCell::new((*f.borrow()).move_from())); assert!(({ (({ (*h.borrow()).call() }) == 11) })); let mut returned: i32 = { - ({ - lambda!( - { - let c: Value = Rc::new(RefCell::new({ - 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() - })); - }, - || -> Counted { - return { - 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() - }; - } - ) - .call() - }) + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ + lambda!( + { + let c: Value = Rc::new(RefCell::new({ + 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() + })); + }, + |this: Ptr| { + CopyConstructible::copy_constructor(&this, { c.as_pointer() }); + return; + } + ) + .call(Ptr::clone(&__v.as_pointer())) + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } .copies }; assert!((returned == 2)); diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 6e36157d2b..136ca1bc15 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -65,13 +65,10 @@ impl Clone for Key { Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -pub fn make_key_3(mut k: i32) -> Key { +pub fn make_key_3(this: Ptr, mut k: i32) { (*made_2.with(Value::clone).borrow_mut()).prefix_inc(); - return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - KeyImpl::construct(&__v.as_pointer(), { k }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + KeyImpl::construct(&this, { k }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -129,7 +126,13 @@ fn main_0() -> i32 { != 0 }; ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; - match (Rc::new(RefCell::new(({ make_key_3(4) }))).as_pointer(),) { + match (Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_key_3(Ptr::clone(&__v.as_pointer()), 4) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer(),) + { (__tmp_3,) => { ({ (*m.borrow_mut()).subscript_move((__tmp_3).clone(), |__k| cpp_move!(__k), || 0_i32) @@ -137,7 +140,13 @@ fn main_0() -> i32 { } } .write(40); - match (Rc::new(RefCell::new(({ make_key_3(4) }))).as_pointer(),) { + match (Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_key_3(Ptr::clone(&__v.as_pointer()), 4) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer(),) + { (__tmp_4,) => { ({ (*m.borrow_mut()).subscript_move((__tmp_4).clone(), |__k| cpp_move!(__k), || 0_i32) diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index b219ab77e3..0a91ec8156 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -67,12 +67,9 @@ impl Clone 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(mut n: i32) -> Bag { - return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - BagImpl::construct(&__v.as_pointer(), { n }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; +pub fn make_5(this: Ptr, mut n: i32) { + BagImpl::construct(&this, { n }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -169,8 +166,18 @@ fn main_0() -> i32 { calls_0.with(|rc| *rc.borrow_mut() = 0); assert!( (match ( - Rc::new(RefCell::new(({ make_5(1,) }))).as_pointer(), - Rc::new(RefCell::new(({ make_5(2,) }))).as_pointer(), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_5(Ptr::clone(&__v.as_pointer()), 1) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer(), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_5(Ptr::clone(&__v.as_pointer()), 2) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer(), ) { (__tmp_8, __tmp_9) => { if CppLess::less(&(__tmp_8).clone(), &(__tmp_9).clone()) { @@ -183,8 +190,18 @@ fn main_0() -> i32 { .with(|__s| __s.n) == 2) && (match ( - Rc::new(RefCell::new(({ make_5(1,) }))).as_pointer(), - Rc::new(RefCell::new(({ make_5(2,) }))).as_pointer(), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_5(Ptr::clone(&__v.as_pointer()), 1) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer(), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_5(Ptr::clone(&__v.as_pointer()), 2) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer(), ) { (__tmp_10, __tmp_11) => { if CppLess::less(&(__tmp_11).clone(), &(__tmp_10).clone()) { diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 5c69c25111..5640ffd68f 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -49,14 +49,11 @@ impl Default for ConstMoveAssign { } } } -pub fn make_0(mut v: i32) -> MoveOnly { +pub fn make_0(this: Ptr, mut v: i32) { let m: Value = Rc::new(RefCell::new(::zero_init())); MoveOnlyImpl::construct(&m.as_pointer(), { v }); - return { - 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() - }; + MoveConstructible::move_constructor(&this, { m.as_pointer() }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -99,7 +96,11 @@ fn main_0() -> i32 { }); assert!(({ (*a.borrow()).v } == 5)); ({ - let _o: Value = Rc::new(RefCell::new(({ make_0(6) }))); + let _o: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_0(Ptr::clone(&__v.as_pointer()), 6) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); MoveAssignable::move_assign(&a.as_pointer(), _o.as_pointer()) }); assert!(({ (*a.borrow()).v } == 6)); diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index bf42125a6a..12cd305b33 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -139,14 +139,11 @@ impl Clone for NoexceptMove { pub fn by_value_0(mut m: MoveOnly) -> i32 { return m.v; } -pub fn make_1(mut v: i32) -> MoveOnly { +pub fn make_1(this: Ptr, mut v: i32) { let m: Value = Rc::new(RefCell::new(::zero_init())); MoveOnlyImpl::construct(&m.as_pointer(), { v }); - return { - 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() - }; + MoveConstructible::move_constructor(&this, { m.as_pointer() }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -167,7 +164,8 @@ fn main_0() -> i32 { MoveConstructible::move_constructor(&d.as_pointer(), { c.as_pointer() }); assert!(({ (*d.borrow()).v } == 1)); assert!(({ (*c.borrow()).v } == 0)); - let e: Value = Rc::new(RefCell::new(({ make_1(5) }))); + let e: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_1(Ptr::clone(&e.as_pointer()), 5) }); assert!(({ (*e.borrow()).v } == 5)); assert!( (({ diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index d7ca2c4917..e16e8c51f2 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -63,21 +63,22 @@ fn main_0() -> i32 { ({ ChainImpl::add_5(&({ ChainImpl::add_5(&b0.as_pointer(), 1) }), 1) }) }); assert!(({ (*b.borrow()).v } == 8) && ({ (*b0.borrow()).v } == 0)); - let c: Value = Rc::new(RefCell::new( - ({ - ChainImpl::take( - &Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ChainImpl::construct(&__v.as_pointer(), { 10 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer(), - ) - }), - )); + let c: Value = Rc::new(RefCell::new(::zero_init())); + ({ + ChainImpl::take( + &Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ChainImpl::construct(&__v.as_pointer(), { 10 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer(), + Ptr::clone(&c.as_pointer()), + ) + }); assert!(({ (*c.borrow()).v } == 11)); - let mut d: Chain = ({ ChainImpl::copy(&c.as_pointer()) }); - assert!((d.v == 111) && ({ (*c.borrow()).v } == 11)); + let d: Value = Rc::new(RefCell::new(::zero_init())); + ({ ChainImpl::copy(&c.as_pointer(), Ptr::clone(&d.as_pointer())) }); + assert!(({ (*d.borrow()).v } == 111) && ({ (*c.borrow()).v } == 11)); let g: Value = Rc::new(RefCell::new(::zero_init())); ChainImpl::construct(&g.as_pointer(), { 20 }); assert!( @@ -93,16 +94,17 @@ fn main_0() -> i32 { ); let e: Value = Rc::new(RefCell::new(::zero_init())); ChainImpl::construct(&e.as_pointer(), { 30 }); - let mut f: Chain = ({ ChainImpl::take(&e.as_pointer()) }); - assert!((f.v == 31) && ({ (*e.borrow()).v } == 0)); + let f: Value = Rc::new(RefCell::new(::zero_init())); + ({ ChainImpl::take(&e.as_pointer(), Ptr::clone(&f.as_pointer())) }); + 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) -> Chain; - fn copy(&self) -> Chain; + fn take(&self, this: Ptr); + fn copy(&self, this: Ptr); fn self_(&self) -> Ptr; } impl ChainImpl for Ptr { @@ -121,19 +123,13 @@ impl ChainImpl for Ptr { }; return (*self).clone(); } - fn take(&self) -> Chain { - return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(&__v.as_pointer(), { (*self).clone() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + fn take(&self, this: Ptr) { + MoveConstructible::move_constructor(&this, { (*self).clone() }); + return; } - fn copy(&self) -> Chain { - return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(&__v.as_pointer(), { (*self).clone() }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + fn copy(&self, this: Ptr) { + CopyConstructible::copy_constructor(&this, { (*self).clone() }); + return; } fn self_(&self) -> Ptr { return (*self).clone(); diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index d531563ba2..885150a4b1 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -123,16 +123,13 @@ impl Default for Buffer { { ::zero_init() } } } -pub fn make_3(mut size: i32) -> Buffer { +pub fn make_3(this: Ptr, mut size: i32) { let b: Value = Rc::new(RefCell::new(::zero_init())); BufferImpl::construct(&b.as_pointer(), { size }); let _dtor_b = std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(&__p.as_pointer())); - return { - 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() - }; + MoveConstructible::move_constructor(&this, { b.as_pointer() }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -166,7 +163,8 @@ fn main_0() -> i32 { assert!( ({ (*c.borrow()).size } == 4) && ((array_elem!(c.as_pointer(), data, 3).read()) == 3) ); - let d: Value = Rc::new(RefCell::new(({ make_3(2) }))); + let d: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_3(Ptr::clone(&d.as_pointer()), 2) }); let _dtor_d = std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(&__p.as_pointer())); assert!(({ (*d.borrow()).size } == 2) && (moves_2.with(|rc| *rc.borrow()) == 2)); diff --git a/tests/unit/out/refcount/structured_binding_copy_ctor.rs b/tests/unit/out/refcount/structured_binding_copy_ctor.rs index fbf79e55b6..7e1d1d28ad 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -46,12 +46,9 @@ impl Clone for Counted { Rc::try_unwrap(__v).ok().unwrap().into_inner() } } -pub fn make_counted_1() -> Counted { - return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CountedImpl::construct(&__v.as_pointer(), { 5 }, { 6 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; +pub fn make_counted_1(this: Ptr) { + CountedImpl::construct(&this, { 5 }, { 6 }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -75,7 +72,11 @@ fn main_0() -> i32 { let __decomp_4: Ptr = s.as_pointer(); assert!((copies_0.with(|rc| *rc.borrow()) == 1)); assert!((__decomp_4.with(|__s| __s.x) == 1)); - let __decomp_5: Value = Rc::new(RefCell::new(({ make_counted_1() }))); + let __decomp_5: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_counted_1(Ptr::clone(&__v.as_pointer())) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!((copies_0.with(|rc| *rc.borrow()) == 1)); assert!(({ (*__decomp_5.borrow()).x } == 5)); assert!(({ (*__decomp_5.borrow()).y } == 6)); diff --git a/tests/unit/out/refcount/structured_binding_element_ctor.rs b/tests/unit/out/refcount/structured_binding_element_ctor.rs index 38ce3e5e78..1f1f671a28 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -76,8 +76,8 @@ pub struct Two { #[byte_size(4)] pub b: Elem, } -pub fn make_two_2() -> Two { - return Two { +pub fn make_two_2(this: Ptr) { + this.write(Two { a: { let __v: Value = Rc::new(RefCell::new(::zero_init())); ElemImpl::construct(&__v.as_pointer(), { 1 }); @@ -88,7 +88,8 @@ pub fn make_two_2() -> Two { ElemImpl::construct(&__v.as_pointer(), { 2 }); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, - }; + }); + return; } pub fn main() { __cpp2rust_init_globals(); @@ -134,7 +135,11 @@ fn main_0() -> i32 { assert!(({ (*t.borrow()).a.v } == -1_i32)); let mut before_copies: i32 = copies_0.with(|rc| *rc.borrow()); let mut before_moves: i32 = moves_1.with(|rc| *rc.borrow()); - let __decomp_6: Value = Rc::new(RefCell::new(({ make_two_2() }))); + let __decomp_6: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_two_2(Ptr::clone(&__v.as_pointer())) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!((copies_0.with(|rc| *rc.borrow()) == before_copies)); assert!((moves_1.with(|rc| *rc.borrow()) == before_moves)); assert!(({ (*__decomp_6.borrow()).a.v } == 1)); diff --git a/tests/unit/out/refcount/structured_binding_move_ctor.rs b/tests/unit/out/refcount/structured_binding_move_ctor.rs index 7efb59bd00..202d1e2cb4 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -104,8 +104,11 @@ fn main_0() -> i32 { xs: Vec::from([1, 2, 3]), ys: Vec::from([4, 5]), })); - let __decomp_3: Value = - Rc::new(RefCell::new(({ HolderImpl::extract(&h.as_pointer()) }))); + let __decomp_3: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ HolderImpl::extract(&h.as_pointer(), Ptr::clone(&__v.as_pointer())) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!(({ ((*__decomp_3.borrow()).xs.len() == 3_usize) })); assert!(({ ((*__decomp_3.borrow()).ys.len() == 2_usize) })); assert!(((elem!(field_ref!(__decomp_3.as_pointer(), xs).decay(), 2_usize).read()) == 3)); @@ -115,14 +118,15 @@ fn main_0() -> i32 { return 0; } pub trait HolderImpl { - fn extract(&self) -> Holder; + fn extract(&self, this: Ptr); } impl HolderImpl for Ptr { - fn extract(&self) -> Holder { - return Holder { + fn extract(&self, this: Ptr) { + this.write(Holder { xs: field!((*self), xs).with_mut(std::mem::take), ys: field!((*self), ys).with_mut(std::mem::take), - }; + }); + return; } } pub trait MovableImpl { diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index 2092084f89..a5166a0b93 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -65,17 +65,18 @@ impl Default for Outer { } } } -pub fn make_0(calls: Ptr) -> Outer { +pub fn make_0(this: Ptr, calls: Ptr) { calls.with_mut(|__v| { __v.prefix_inc(); }); - return Outer { + this.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), }, name: i8::array_from_literal(b"abc\0\0\0\0\0"), - }; + }); + return; } pub fn sum_1(values: Ptr>) -> i32 { let mut total: i32 = 0; @@ -93,20 +94,38 @@ fn main_0() -> i32 { let calls: Value = Rc::new(RefCell::new(0)); let mut member: i32 = ({ sum_1( - (match Rc::new(RefCell::new(({ make_0(calls.as_pointer()) }))).as_pointer() { + (match Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_0(Ptr::clone(&__v.as_pointer()), calls.as_pointer()) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer() + { __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), }), ) }); let mut nested: i32 = ({ sum_1( - (match Rc::new(RefCell::new(({ make_0(calls.as_pointer()) }))).as_pointer() { + (match Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_0(Ptr::clone(&__v.as_pointer()), calls.as_pointer()) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer() + { __tmp_1 => field_ref!(field_ptr!(__tmp_1, inner), values).as_pointer(), }), ) }); let mut element: i32 = (match ( - (match Rc::new(RefCell::new(({ make_0(calls.as_pointer()) }))).as_pointer() { + (match Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_0(Ptr::clone(&__v.as_pointer()), calls.as_pointer()) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer() + { __tmp_3 => field_ref!(__tmp_3, values).as_pointer(), }), { (((*calls.borrow()) - 2) as usize) }, @@ -119,12 +138,17 @@ fn main_0() -> i32 { } } .read()); - let mut length: usize = - (match Rc::new(RefCell::new(({ make_0(calls.as_pointer()) }))).as_pointer() { - __tmp_5 => array_field_ptr!(__tmp_5, name), - }) - .to_c_string_iterator() - .count(); + let mut length: usize = (match Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_0(Ptr::clone(&__v.as_pointer()), calls.as_pointer()) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer() + { + __tmp_5 => array_field_ptr!(__tmp_5, name), + }) + .to_c_string_iterator() + .count(); let mut aggregate: i32 = ({ sum_1( (match Rc::new(RefCell::new(Outer { diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index fcc400eb16..1fe785bdd3 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -27,10 +27,11 @@ pub struct Outer { #[byte_size(24)] pub values: Vec, } -pub fn make_0() -> Outer { - return Outer { +pub fn make_0(this: Ptr) { + this.write(Outer { values: Vec::from([1, 2, 3, 4]), - }; + }); + return; } #[derive( Copy, @@ -58,7 +59,13 @@ pub fn main() { fn main_0() -> i32 { let h: Value = Rc::new(RefCell::new(::zero_init())); HImpl::construct(&h.as_pointer(), { - (match Rc::new(RefCell::new(({ make_0() }))).as_pointer() { + (match Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_0(Ptr::clone(&__v.as_pointer())) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer() + { __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), }) }); diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index da7f6e770c..a41ba05542 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -51,13 +51,14 @@ pub struct Outer { #[byte_size(24)] pub inner: Inner, } -pub fn make_0() -> Outer { - return Outer { +pub fn make_0(this: Ptr) { + this.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), }, - }; + }); + return; } pub fn two_1(a: Ptr>, b: Ptr>) -> i32 { return ({ (index!(a, 0_usize).read()) } + { (index!(b, 2_usize).read()) }); @@ -71,10 +72,22 @@ fn main_0() -> i32 { b"%d\n", ({ two_1( - (match Rc::new(RefCell::new(({ make_0() }))).as_pointer() { + (match Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_0(Ptr::clone(&__v.as_pointer())) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer() + { __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), }), - (match Rc::new(RefCell::new(({ make_0() }))).as_pointer() { + (match Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_0(Ptr::clone(&__v.as_pointer())) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer() + { __tmp_1 => field_ref!(field_ptr!(__tmp_1, inner), values).as_pointer(), }), ) diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index c8150e4077..128aa8d931 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -267,14 +267,11 @@ pub unsafe fn touch_1(mut t: *const Tracked) { pub unsafe fn by_value_2(mut c: Counted) -> i32 { return c.v; } -pub unsafe fn make_3(mut v: i32) -> Counted { +pub unsafe fn make_3(this: *mut Counted, mut v: i32) { let mut c: Counted = ::zero_init(); Counted::construct(&mut c, { v }); - return { - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); - __v - }; + CopyConstructibleUnsafe::copy_constructor(&mut *this, { &c }); + return; } pub fn main() { unsafe { @@ -303,7 +300,8 @@ unsafe fn main_0() -> i32 { }) == (1)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (4))); - let mut e: Counted = (unsafe { make_3(5) }); + let mut e: Counted = ::zero_init(); + (unsafe { make_3(&mut e, 5) }); assert!(((e.v) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5))); let mut f: Counted = ::zero_init(); diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index f0a784d4a9..fc72f4ec88 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -33,14 +33,16 @@ pub struct Outer { pub inner: S, pub w: i32, } -pub unsafe fn make_2(mut v: i32) -> S { - return S { v: v }; +pub unsafe fn make_2(this: *mut S, mut v: i32) { + this.write(S { v: v }); + return; } -pub unsafe fn make_outer_3() -> Outer { - return Outer { +pub unsafe fn make_outer_3(this: *mut Outer) { + this.write(Outer { inner: S { v: 7 }, w: 8, - }; + }); + return; } pub unsafe fn use_4(s: *const S) -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (0))); @@ -56,31 +58,56 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { make_2(1) }); + { + let mut __v: S = ::zero_init(); + (unsafe { make_2(&mut __v, 1) }); + __v + }; assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (1)) ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; - &(unsafe { make_2(2) }); + &({ + let mut __v: S = ::zero_init(); + (unsafe { make_2(&mut __v, 2) }); + __v + }); 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; - let mut x: i32 = (unsafe { make_2(3) }).v; + let mut x: i32 = { + let mut __v: S = ::zero_init(); + (unsafe { make_2(&mut __v, 3) }); + __v + } + .v; assert!( (((x) == (3)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (3)) ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; - x = (unsafe { S::get(&(unsafe { make_2(4) })) }); + x = (unsafe { + S::get(&{ + let mut __v: S = ::zero_init(); + (unsafe { make_2(&mut __v, 4) }); + __v + }) + }); assert!( (((x) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (4)) ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; - x = (unsafe { make_outer_3() }).inner.v; + x = { + let mut __v: Outer = ::zero_init(); + (unsafe { make_outer_3(&mut __v) }); + __v + } + .inner + .v; assert!( (((x) == (7)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (7)) @@ -90,7 +117,11 @@ unsafe fn main_0() -> i32 { assert!(((x) == (5)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1))); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; x = (unsafe { - let mut _s: S = (unsafe { make_2(6) }); + let mut _s: S = { + let mut __v: S = ::zero_init(); + (unsafe { make_2(&mut __v, 6) }); + __v + }; use_4(&mut _s) }); assert!( @@ -108,7 +139,11 @@ unsafe fn main_0() -> i32 { assert!(((x) == (3)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (2))); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; x = (if ((x) == (3)) { - (unsafe { make_2(9) }) + { + let mut __v: S = ::zero_init(); + (unsafe { make_2(&mut __v, 9) }); + __v + } } else { S { v: 10 } }) @@ -119,7 +154,11 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { - let mut __tmp_0: S = (unsafe { make_2(11) }); + let mut __tmp_0: S = { + let mut __v: S = ::zero_init(); + (unsafe { make_2(&mut __v, 11) }); + __v + }; let r: *const S = &mut __tmp_0; assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (0)) @@ -136,7 +175,11 @@ unsafe fn main_0() -> i32 { let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); - s = (unsafe { make_2(13) }); + s = { + let mut __v: S = ::zero_init(); + (unsafe { make_2(&mut __v, 13) }); + __v + }; assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (13))) diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index db38c500b5..86c3967747 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -70,19 +70,13 @@ impl MoveConstructibleUnsafe for MoveOnly { (*x).data_ = 0; } } -pub unsafe fn make_move_only_2() -> MoveOnly { - return { - let mut __v: MoveOnly = ::zero_init(); - MoveOnly::construct(&mut __v, { 4 }); - __v - }; +pub unsafe fn make_move_only_2(this: *mut MoveOnly) { + MoveOnly::construct(&mut *this, { 4 }); + return; } -pub unsafe fn scale_move_only_3(mut x: MoveOnly) -> MoveOnly { - return { - let mut __v: MoveOnly = ::zero_init(); - MoveOnly::construct(&mut __v, { ((unsafe { MoveOnly::get(&x) }) * (10)) }); - __v - }; +pub unsafe fn scale_move_only_3(this: *mut MoveOnly, mut x: MoveOnly) { + MoveOnly::construct(&mut *this, { ((unsafe { MoveOnly::get(&x) }) * (10)) }); + return; } pub fn main() { unsafe { @@ -115,12 +109,14 @@ unsafe fn main_0() -> i32 { (h1.cb) = Some(negate_1); assert!(((unsafe { (h1.cb).unwrap()(3,) }) == (-3_i32))); assert!(((h1.cb) == (h2.cb))); - let mut mk: Option MoveOnly> = Some(make_move_only_2); - let mut m: MoveOnly = (unsafe { (mk).unwrap()() }); + let mut mk: Option = Some(make_move_only_2); + let mut m: MoveOnly = ::zero_init(); + (unsafe { (mk).unwrap()(&mut m) }); assert!(((unsafe { MoveOnly::get(&m,) }) == (4))); - let mut sc: Option MoveOnly> = Some(scale_move_only_3); - let mut n: MoveOnly = (unsafe { - (sc).unwrap()({ + 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 diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 5cddaafe53..10eca79285 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -106,19 +106,13 @@ 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(x: *mut Tracked) -> Holder { - return { - let mut __v: Holder = ::zero_init(); - Holder::construct_1(&mut __v, { x }); - __v - }; -} -pub unsafe fn forward_into_ctor_7(x: *mut Tracked) -> Holder { - return { - let mut __v: Holder = ::zero_init(); - Holder::construct_2(&mut __v, { x }); - __v - }; +pub unsafe fn forward_into_ctor_6(this: *mut Holder, x: *mut Tracked) { + Holder::construct_1(&mut *this, { x }); + return; +} +pub unsafe fn forward_into_ctor_7(this: *mut Holder, x: *mut Tracked) { + Holder::construct_2(&mut *this, { x }); + return; } pub fn main() { unsafe { @@ -163,18 +157,20 @@ unsafe fn main_0() -> i32 { ); let mut kept: Tracked = ::zero_init(); Tracked::construct(&mut kept, { 11 }); - let mut from_lvalue: Holder = (unsafe { forward_into_ctor_6(&mut kept) }); + let mut from_lvalue: Holder = ::zero_init(); + (unsafe { forward_into_ctor_6(&mut from_lvalue, &mut kept) }); assert!(((from_lvalue.t.v) == (11))); assert!(((from_lvalue.t.copies) == (1))); assert!(((from_lvalue.t.moves) == (0))); assert!(((kept.v) == (11))); - let mut from_rvalue: Holder = (unsafe { + let mut from_rvalue: Holder = ::zero_init(); + (unsafe { let mut _x: Tracked = { let mut __v: Tracked = ::zero_init(); Tracked::construct(&mut __v, { 12 }); __v }; - forward_into_ctor_7(&mut _x) + forward_into_ctor_7(&mut from_rvalue, &mut _x) }); assert!(((from_rvalue.t.v) == (12))); assert!(((from_rvalue.t.copies) == (0))); diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index 0667b43d09..819ff4cbb9 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -72,12 +72,9 @@ pub unsafe fn chosen_overload_2(_a0: *const i32) -> Overload { pub unsafe fn chosen_overload_3(_a0: *mut i32) -> Overload { return Overload_kIntRvalueOverload; } -pub unsafe fn copy_or_move_into_param_4(mut t: Tracked) -> Tracked { - return { - let mut __v: Tracked = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut t }); - __v - }; +pub unsafe fn copy_or_move_into_param_4(this: *mut Tracked, mut t: Tracked) { + MoveConstructibleUnsafe::move_constructor(&mut *this, { &mut t }); + return; } pub fn main() { unsafe { @@ -96,8 +93,9 @@ unsafe fn main_0() -> i32 { assert!(((a.v) == (5))); let mut b: Tracked = ::zero_init(); Tracked::construct(&mut b, { 6 }); - let mut moved: Tracked = (unsafe { - copy_or_move_into_param_4({ + 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 @@ -109,8 +107,9 @@ unsafe fn main_0() -> i32 { assert!(((b.v) == (0))); let mut c: Tracked = ::zero_init(); Tracked::construct(&mut c, { 7 }); - let mut copied: Tracked = (unsafe { - copy_or_move_into_param_4({ + 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 diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index 8717af807f..4e7bbfe557 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -130,12 +130,13 @@ pub struct Pair { pub a: Tracked, pub b: Tracked, } -pub unsafe fn forward_pack_into_ctor_8(args_0: *mut Tracked, args_1: *mut Tracked) -> Pair { - return { - let mut __v: Pair = ::zero_init(); - Pair::construct(&mut __v, { args_0 }, { args_1 }); - __v - }; +pub unsafe fn forward_pack_into_ctor_8( + this: *mut Pair, + args_0: *mut Tracked, + args_1: *mut Tracked, +) { + Pair::construct(&mut *this, { args_0 }, { args_1 }); + return; } pub fn main() { unsafe { @@ -175,13 +176,14 @@ unsafe fn main_0() -> i32 { assert!(((i) == (3))); let mut lhs: Tracked = ::zero_init(); Tracked::construct(&mut lhs, { 6 }); - let mut p: Pair = (unsafe { + let mut p: Pair = ::zero_init(); + (unsafe { let mut _args_1: Tracked = { let mut __v: Tracked = ::zero_init(); Tracked::construct(&mut __v, { 7 }); __v }; - forward_pack_into_ctor_8(&mut lhs, &mut _args_1) + forward_pack_into_ctor_8(&mut p, &mut lhs, &mut _args_1) }); assert!(((p.a.v) == (6))); assert!(((p.a.copies) == (1))); diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index 3f9f9f4f99..590d509721 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -130,25 +130,26 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { f.call() }) == (10))); let mut h: FnPtr i32> = f.move_from(); assert!(((unsafe { h.call() }) == (11))); - let mut returned: i32 = (unsafe { - lambda_unsafe!( - { - let c: Counted = { - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); - __v - }; - }, - || -> Counted { - return { - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); - __v - }; - } - ) - .call() - }) + let mut returned: i32 = { + let mut __v: Counted = ::zero_init(); + (unsafe { + lambda_unsafe!( + { + let c: Counted = { + let mut __v: Counted = ::zero_init(); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); + __v + }; + }, + |this: *mut Counted| { + CopyConstructibleUnsafe::copy_constructor(&mut *this, { &c }); + return; + } + ) + .call(&mut __v) + }); + __v + } .copies; assert!(((returned) == (2))); let mut arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|_| { diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 95152a9c8f..3623848929 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -81,13 +81,10 @@ impl Clone for Key { } } } -pub unsafe fn make_key_3(mut k: i32) -> Key { +pub unsafe fn make_key_3(this: *mut Key, mut k: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)).prefix_inc(); - return { - let mut __v: Key = ::zero_init(); - Key::construct(&mut __v, { k }); - __v - }; + Key::construct(&mut *this, { k }); + return; } pub fn main() { unsafe { @@ -121,10 +118,20 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) != 0; - (*match ((&mut (unsafe { make_key_3(4) }) as *mut Key),) { + (*match ((&mut { + let mut __v: Key = ::zero_init(); + (unsafe { make_key_3(&mut __v, 4) }); + __v + } as *mut Key),) + { (__tmp_0,) => &mut (*m.subscript_move(__tmp_0, |__k| cpp_move_unsafe!(__k), || 0_i32)), }) = 40; - (*match ((&mut (unsafe { make_key_3(4) }) as *mut Key),) { + (*match ((&mut { + let mut __v: Key = ::zero_init(); + (unsafe { make_key_3(&mut __v, 4) }); + __v + } as *mut Key),) + { (__tmp_1,) => &mut (*m.subscript_move(__tmp_1, |__k| cpp_move_unsafe!(__k), || 0_i32)), }) = 41; ok = ((ok as i32) diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index d4e9cc256f..7dafef37a7 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -82,12 +82,9 @@ impl Clone 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(mut n: i32) -> Bag { - return { - let mut __v: Bag = ::zero_init(); - Bag::construct(&mut __v, { n }); - __v - }; +pub unsafe fn make_5(this: *mut Bag, mut n: i32) { + Bag::construct(&mut *this, { n }); + return; } pub fn main() { unsafe { @@ -169,8 +166,16 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) = 0; assert!( (((*match ( - (&mut (unsafe { make_5(1,) }) as *const Bag), - (&mut (unsafe { make_5(2,) }) as *const Bag), + (&mut { + let mut __v: Bag = ::zero_init(); + (unsafe { make_5(&mut __v, 1) }); + __v + } as *const Bag), + (&mut { + let mut __v: Bag = ::zero_init(); + (unsafe { make_5(&mut __v, 2) }); + __v + } as *const Bag), ) { (__tmp_4, __tmp_5) => { { @@ -182,8 +187,16 @@ unsafe fn main_0() -> i32 { }) .n) == (2)) && (((*match ( - (&mut (unsafe { make_5(1,) }) as *const Bag), - (&mut (unsafe { make_5(2,) }) as *const Bag), + (&mut { + let mut __v: Bag = ::zero_init(); + (unsafe { make_5(&mut __v, 1) }); + __v + } as *const Bag), + (&mut { + let mut __v: Bag = ::zero_init(); + (unsafe { make_5(&mut __v, 2) }); + __v + } as *const Bag), ) { (__tmp_6, __tmp_7) => { { diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index ab5355532b..6fd672cde0 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -64,14 +64,11 @@ impl Default for ConstMoveAssign { } } } -pub unsafe fn make_0(mut v: i32) -> MoveOnly { +pub unsafe fn make_0(this: *mut MoveOnly, mut v: i32) { let mut m: MoveOnly = ::zero_init(); MoveOnly::construct(&mut m, { v }); - return { - let mut __v: MoveOnly = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut m }); - __v - }; + MoveConstructibleUnsafe::move_constructor(&mut *this, { &mut m }); + return; } pub fn main() { unsafe { @@ -114,7 +111,11 @@ unsafe fn main_0() -> i32 { }); assert!(((a.v) == (5))); (unsafe { - let mut _o: MoveOnly = (unsafe { make_0(6) }); + let mut _o: MoveOnly = { + let mut __v: MoveOnly = ::zero_init(); + (unsafe { make_0(&mut __v, 6) }); + __v + }; MoveAssignableUnsafe::move_assign(&mut a, &mut _o) }); assert!(((a.v) == (6))); diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index 81c69eae2d..1b424b4893 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -151,14 +151,11 @@ impl Clone for NoexceptMove { pub unsafe fn by_value_0(mut m: MoveOnly) -> i32 { return m.v; } -pub unsafe fn make_1(mut v: i32) -> MoveOnly { +pub unsafe fn make_1(this: *mut MoveOnly, mut v: i32) { let mut m: MoveOnly = ::zero_init(); MoveOnly::construct(&mut m, { v }); - return { - let mut __v: MoveOnly = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut m }); - __v - }; + MoveConstructibleUnsafe::move_constructor(&mut *this, { &mut m }); + return; } pub fn main() { unsafe { @@ -181,7 +178,8 @@ unsafe fn main_0() -> i32 { MoveConstructibleUnsafe::move_constructor(&mut d, { &mut c }); assert!(((d.v) == (1))); assert!(((c.v) == (0))); - let mut e: MoveOnly = (unsafe { make_1(5) }); + let mut e: MoveOnly = ::zero_init(); + (unsafe { make_1(&mut e, 5) }); assert!(((e.v) == (5))); assert!( ((unsafe { diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index 986fe6e10d..fb59458b77 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -34,19 +34,13 @@ impl Chain { self.v += n; return &mut (*(self as *mut Chain)); } - pub unsafe fn take(&mut self) -> Chain { - return { - let mut __v: Chain = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut (*(self as *mut Chain)) }); - __v - }; + pub unsafe fn take(&mut self, this: *mut Chain) { + MoveConstructibleUnsafe::move_constructor(&mut *this, { &mut (*(self as *mut Chain)) }); + return; } - pub unsafe fn copy(&self) -> Chain { - return { - let mut __v: Chain = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, { &(*(self as *const Chain)) }); - __v - }; + pub unsafe fn copy(&self, this: *mut Chain) { + CopyConstructibleUnsafe::copy_constructor(&mut *this, { &(*(self as *const Chain)) }); + return; } pub unsafe fn self_(&mut self) -> *mut Chain { return &mut (*(self as *mut Chain)); @@ -93,15 +87,20 @@ unsafe fn main_0() -> i32 { (unsafe { Chain::add_5(&mut (*(unsafe { Chain::add_5(&mut b0, 1) })), 1) }) }); assert!(((b.v) == (8)) && ((b0.v) == (0))); - let mut c: Chain = (unsafe { - Chain::take(&mut { - let mut __v: Chain = ::zero_init(); - Chain::construct(&mut __v, { 10 }); - __v - }) + let mut c: Chain = ::zero_init(); + (unsafe { + Chain::take( + &mut { + let mut __v: Chain = ::zero_init(); + Chain::construct(&mut __v, { 10 }); + __v + }, + &mut c, + ) }); assert!(((c.v) == (11))); - let mut d: Chain = (unsafe { Chain::copy(&c) }); + let mut d: Chain = ::zero_init(); + (unsafe { Chain::copy(&c, &mut d) }); assert!(((d.v) == (111)) && ((c.v) == (11))); let mut g: Chain = ::zero_init(); Chain::construct(&mut g, { 20 }); @@ -118,7 +117,8 @@ unsafe fn main_0() -> i32 { ); let mut e: Chain = ::zero_init(); Chain::construct(&mut e, { 30 }); - let mut f: Chain = (unsafe { Chain::take(&mut e) }); + let mut f: Chain = ::zero_init(); + (unsafe { Chain::take(&mut e, &mut f) }); assert!(((f.v) == (31)) && ((e.v) == (0))); return 0; } diff --git a/tests/unit/out/unsafe/rule_of_five.rs b/tests/unit/out/unsafe/rule_of_five.rs index a47218d1de..4642b609a7 100644 --- a/tests/unit/out/unsafe/rule_of_five.rs +++ b/tests/unit/out/unsafe/rule_of_five.rs @@ -122,17 +122,14 @@ impl Clone for Buffer { } } } -pub unsafe fn make_3(mut size: i32) -> Buffer { +pub unsafe fn make_3(this: *mut Buffer, mut size: i32) { let mut b: Buffer = ::zero_init(); Buffer::construct(&mut b, { size }); let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); - return { - let mut __v: Buffer = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, { &mut b }); - __v - }; + MoveConstructibleUnsafe::move_constructor(&mut *this, { &mut b }); + return; } pub fn main() { unsafe { @@ -170,7 +167,8 @@ unsafe fn main_0() -> i32 { ); assert!(((a.size) == (0)) && ((a.data[(0) as usize]) == (-1_i32))); assert!(((c.size) == (4)) && ((c.data[(3) as usize]) == (3))); - let mut d: Buffer = (unsafe { make_3(2) }); + let mut d: Buffer = ::zero_init(); + (unsafe { make_3(&mut d, 2) }); let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); diff --git a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs index 2e47b6d1b0..6cd2a5ad8d 100644 --- a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs @@ -44,12 +44,9 @@ impl Clone for Counted { } } } -pub unsafe fn make_counted_1() -> Counted { - return { - let mut __v: Counted = ::zero_init(); - Counted::construct(&mut __v, { 5 }, { 6 }); - __v - }; +pub unsafe fn make_counted_1(this: *mut Counted) { + Counted::construct(&mut *this, { 5 }, { 6 }); + return; } pub fn main() { unsafe { @@ -75,7 +72,11 @@ unsafe fn main_0() -> i32 { let __decomp_4: *const Counted = &s; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); assert!((((*__decomp_4).x) == (1))); - let mut __decomp_5: Counted = (unsafe { make_counted_1() }); + let mut __decomp_5: Counted = { + let mut __v: Counted = ::zero_init(); + (unsafe { make_counted_1(&mut __v) }); + __v + }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); assert!(((__decomp_5.x) == (5))); assert!(((__decomp_5.y) == (6))); diff --git a/tests/unit/out/unsafe/structured_binding_element_ctor.rs b/tests/unit/out/unsafe/structured_binding_element_ctor.rs index 84b9aba0f9..53168c11e1 100644 --- a/tests/unit/out/unsafe/structured_binding_element_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_element_ctor.rs @@ -69,8 +69,8 @@ pub struct Two { pub a: Elem, pub b: Elem, } -pub unsafe fn make_two_2() -> Two { - return Two { +pub unsafe fn make_two_2(this: *mut Two) { + this.write(Two { a: { let mut __v: Elem = ::zero_init(); Elem::construct(&mut __v, { 1 }); @@ -81,7 +81,8 @@ pub unsafe fn make_two_2() -> Two { Elem::construct(&mut __v, { 2 }); __v }, - }; + }); + return; } pub fn main() { unsafe { @@ -129,7 +130,11 @@ unsafe fn main_0() -> i32 { assert!(((t.a.v) == (-1_i32))); let mut before_copies: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)); let mut before_moves: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)); - let mut __decomp_6: Two = (unsafe { make_two_2() }); + let mut __decomp_6: Two = { + let mut __v: Two = ::zero_init(); + (unsafe { make_two_2(&mut __v) }); + __v + }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (before_copies))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (before_moves))); assert!(((__decomp_6.a.v) == (1))); diff --git a/tests/unit/out/unsafe/structured_binding_move_ctor.rs b/tests/unit/out/unsafe/structured_binding_move_ctor.rs index 89bab3c2ea..6bca08362f 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -73,11 +73,12 @@ pub struct Holder { pub ys: Vec, } impl Holder { - pub unsafe fn extract(&mut self) -> Holder { - return Holder { + pub unsafe fn extract(&mut self, this: *mut Holder) { + this.write(Holder { xs: std::mem::take(&mut self.xs), ys: std::mem::take(&mut self.ys), - }; + }); + return; } } pub fn main() { @@ -104,7 +105,11 @@ unsafe fn main_0() -> i32 { xs: Vec::from([1, 2, 3]), ys: Vec::from([4, 5]), }; - let mut __decomp_3: Holder = (unsafe { Holder::extract(&mut h) }); + let mut __decomp_3: Holder = { + let mut __v: Holder = ::zero_init(); + (unsafe { Holder::extract(&mut h, &mut __v) }); + __v + }; assert!(((__decomp_3.xs.len()) == (3_usize))); assert!(((__decomp_3.ys.len()) == (2_usize))); assert!(((__decomp_3.xs[(2_usize)]) == (3))); diff --git a/tests/unit/out/unsafe/temporary_field_addr.rs b/tests/unit/out/unsafe/temporary_field_addr.rs index f5bd942b51..3a7e880712 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -42,15 +42,16 @@ pub struct Outer { pub inner: Inner, pub name: [libc::c_char; 8], } -pub unsafe fn make_0(calls: *mut i32) -> Outer { +pub unsafe fn make_0(this: *mut Outer, calls: *mut i32) { (*calls).prefix_inc(); - return Outer { + this.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), }, name: std::mem::transmute(*b"abc\0\0\0\0\0"), - }; + }); + return; } pub unsafe fn sum_1(values: *const Vec) -> i32 { let mut total: i32 = 0; @@ -68,11 +69,43 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut calls: i32 = 0; - let mut member: i32 = (unsafe { sum_1(&(unsafe { make_0(&mut calls) }).values) }); - let mut nested: i32 = (unsafe { sum_1(&(unsafe { make_0(&mut calls) }).inner.values) }); - let mut element: i32 = (unsafe { make_0(&mut calls) }).values[(((calls) - (2)) as usize)]; - let mut length: usize = - libc::strlen(((unsafe { make_0(&mut calls) }).name.as_mut_ptr()).cast_const()); + let mut member: i32 = (unsafe { + sum_1( + &{ + let mut __v: Outer = ::zero_init(); + (unsafe { make_0(&mut __v, &mut calls) }); + __v + } + .values, + ) + }); + let mut nested: i32 = (unsafe { + sum_1( + &{ + let mut __v: Outer = ::zero_init(); + (unsafe { make_0(&mut __v, &mut calls) }); + __v + } + .inner + .values, + ) + }); + let mut element: i32 = { + let mut __v: Outer = ::zero_init(); + (unsafe { make_0(&mut __v, &mut calls) }); + __v + } + .values[(((calls) - (2)) as usize)]; + let mut length: usize = libc::strlen( + ({ + let mut __v: Outer = ::zero_init(); + (unsafe { make_0(&mut __v, &mut calls) }); + __v + } + .name + .as_mut_ptr()) + .cast_const(), + ); let mut aggregate: i32 = (unsafe { sum_1( &Outer { diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index 8f1208c5d7..2161b1290d 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -23,10 +23,11 @@ use std::rc::Rc; pub struct Outer { pub values: Vec, } -pub unsafe fn make_0() -> Outer { - return Outer { +pub unsafe fn make_0(this: *mut Outer) { + this.write(Outer { values: Vec::from([1, 2, 3, 4]), - }; + }); + return; } #[repr(C)] #[derive( @@ -57,7 +58,14 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut h: H = ::zero_init(); - H::construct(&mut h, { &(unsafe { make_0() }).values }); + H::construct(&mut h, { + &{ + let mut __v: Outer = ::zero_init(); + (unsafe { make_0(&mut __v) }); + __v + } + .values + }); (unsafe { libc::printf(c"%d\n".as_ptr() as *const libc::c_char, (h.last)) }); return 0; } diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index e90e0c2e63..700c79e869 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -41,13 +41,14 @@ pub struct Outer { pub values: Vec, pub inner: Inner, } -pub unsafe fn make_0() -> Outer { - return Outer { +pub unsafe fn make_0(this: *mut Outer) { + this.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), }, - }; + }); + return; } pub unsafe fn two_1(a: *const Vec, b: *const Vec) -> i32 { return (((&(*a))[(0_usize)]) + ((&(*b))[(2_usize)])); @@ -63,8 +64,19 @@ unsafe fn main_0() -> i32 { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - let _a: *const Vec = &(unsafe { make_0() }).values; - let _b: *const Vec = &(unsafe { make_0() }).inner.values; + let _a: *const Vec = &{ + let mut __v: Outer = ::zero_init(); + (unsafe { make_0(&mut __v) }); + __v + } + .values; + let _b: *const Vec = &{ + let mut __v: Outer = ::zero_init(); + (unsafe { make_0(&mut __v) }); + __v + } + .inner + .values; two_1(_a, _b) }), ) From 47092138598cc4bb34bcbe39ba1073281a471def Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Tue, 1 Dec 2026 17:00:00 +0000 Subject: [PATCH 02/12] Build into the storage of the caller --- cpp2rust/converter/converter.cpp | 81 ++++++++++++++++--- cpp2rust/converter/converter.h | 13 ++- cpp2rust/converter/converter_lib.cpp | 32 +++++++- cpp2rust/converter/converter_lib.h | 6 ++ cpp2rust/converter/models/boxed_vars.cpp | 2 +- .../converter/models/converter_refcount.cpp | 16 +++- .../converter/models/converter_refcount.h | 4 + 7 files changed, 129 insertions(+), 25 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index fded87dcca..72d0e6818e 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -385,6 +385,12 @@ bool Converter::VisitReferenceType(clang::ReferenceType *type) { std::string Converter::ConvertFunctionPointerType(const clang::FunctionProtoType *proto) { std::string result = "fn("; + auto return_type = proto->getReturnType(); + bool return_slot = UsesReturnSlot(return_type); + if (return_slot) { + result += ToString(ctx_.getPointerType(return_type.getUnqualifiedType())); + result += ','; + } for (auto p_ty : proto->param_types()) { result += ToString(p_ty); result += ','; @@ -393,8 +399,8 @@ Converter::ConvertFunctionPointerType(const clang::FunctionProtoType *proto) { result += "Box<[VaArg]>,"; } result += ')'; - if (!proto->getReturnType()->isVoidType()) { - result += std::format(" -> {}", ToString(proto->getReturnType())); + if (!return_type->isVoidType() && !return_slot) { + result += std::format(" -> {}", ToString(return_type)); } return result; } @@ -706,7 +712,7 @@ void Converter::ConvertVarDecl(clang::VarDecl *decl) { if (auto *construct = GetInPlaceVarConstruct(decl)) { auto name = GetNamedDeclAsString(decl); StrCat(CreatePlacementStorage( - GetRecordName(construct->getConstructor()->getParent()), name)); + GetRecordName(construct->getType()->getAsCXXRecordDecl()), name)); ConstructInPlace(decl->getInit(), construct, GetPlacementReceiver(name)); return; } @@ -1424,7 +1430,7 @@ void Converter::EmitConstructorFieldInits(clang::CXXConstructorDecl *decl) { auto *init = ctor_initializer ? ctor_initializer->getInit() : field->getInClassInitializer(); - if (auto *construct = init ? GetInPlaceConstruct(init) : nullptr) { + if (auto *construct = init ? GetPlacementInitializer(init) : nullptr) { ConstructInPlace(init, construct, GetFieldPlacementReceiver(field_name)); continue; } @@ -1593,6 +1599,21 @@ bool Converter::VisitDeclStmt(clang::DeclStmt *stmt) { bool Converter::VisitReturnStmt(clang::ReturnStmt *stmt) { ScopedValue return_value(return_value_, stmt->getRetValue()); auto return_type = curr_function_->getReturnType(); + if (auto *value = stmt->getRetValue(); value && UsesReturnSlot(return_type)) { + if (auto *construct = GetPlacementInitializer(value)) { + ConstructInPlace(value, construct, GetReturnSlotReceiver()); + } else { + HoistMaterializedTempBindings hoist_temps(*this); + StrCat("this.write"); + { + PushParen paren(*this); + ConvertVarInit(return_type, value); + } + StrCat(token::kSemiColon); + } + StrCat(keyword::kReturn, token::kSemiColon); + return false; + } if (!return_type->isVoidType()) { HoistMaterializedTempBindings hoist_temps(*this); StrCat(keyword::kReturn); @@ -2133,6 +2154,18 @@ void Converter::ConvertVAArgCall(clang::CallExpr *expr) { } bool Converter::VisitCallExpr(clang::CallExpr *expr) { + if (IsReturnSlotCall(expr) && in_place_.expr != expr) { + PushBrace block(*this); + StrCat(CreatePlacementStorage( + GetRecordName(expr->getType()->getAsCXXRecordDecl()))); + { + ScopedValue in_place(in_place_, {expr, GetPlacementReceiver()}); + Convert(expr); + } + StrCat(token::kSemiColon, TakePlacementValue()); + MarkFresh(); + return false; + } if (ConvertSpecialCall(expr)) { return false; } @@ -2483,6 +2516,11 @@ void Converter::EmitArgList(const CallInfo &info) { StrCat(std::exchange(ufcs_receiver_, std::string()), token::kComma); } + if (IsReturnSlotCall(info.expr)) { + assert(in_place_.expr == info.expr); + StrCat(GetReturnSlotArg(in_place_.receiver), token::kComma); + } + for (unsigned i = 0; i < info.args.size(); i++) { const auto &ca = info.args[i]; switch (ca.kind) { @@ -4460,14 +4498,15 @@ bool Converter::VisitCXXNewExpr(clang::CXXNewExpr *expr) { if (!curr_init_type_.empty() && curr_init_type_.back()->isPointerType()) { StrCat(".as_mut_ptr()"); } - } else if (auto *construct = expr->getInitializer() - ? GetInPlaceConstruct(expr->getInitializer()) - : nullptr) { + } else if (auto *construct = + expr->getInitializer() + ? GetPlacementInitializer(expr->getInitializer()) + : nullptr) { PushBrace block(*this); StrCat( std::format("let __p: *mut {0} = Box::leak(Box::new(<{0}>::" "zero_init()));", - GetRecordName(construct->getConstructor()->getParent()))); + GetRecordName(construct->getType()->getAsCXXRecordDecl()))); ConstructInPlace(expr->getInitializer(), construct, "&mut *__p"); StrCat("__p"); } else if (pointee) { @@ -4579,21 +4618,20 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) { } void Converter::ConstructInPlace(clang::Expr *init, - const clang::CXXConstructExpr *construct, + const clang::Expr *construct, std::string receiver) { ScopedValue in_place(in_place_, {construct, std::move(receiver)}); ConvertFullExpression([&] { Convert(init); }); StrCat(token::kSemiColon); } -const clang::CXXConstructExpr * -Converter::GetInPlaceVarConstruct(clang::VarDecl *decl) { +const clang::Expr *Converter::GetInPlaceVarConstruct(clang::VarDecl *decl) { if (!decl->isLocalVarDecl() || decl->isStaticLocal() || IsGlobalVar(decl) || !decl->hasInit() || clang::isa(decl) || !CanConstructVarInPlace(decl)) { return nullptr; } - return GetInPlaceConstruct(decl->getInit()); + return GetPlacementInitializer(decl->getInit()); } const char *Converter::GetConstructorSelf() const { return "&mut self"; } @@ -4632,6 +4670,17 @@ bool Converter::CanConstructVarInPlace(const clang::VarDecl *decl) const { const char *Converter::TakePlacementValue() const { return "__v"; } +const char *Converter::GetReturnSlotReceiver() const { return "&mut *this"; } + +std::string Converter::GetReturnSlotArg(std::string_view receiver) const { + return std::string(receiver); +} + +std::string Converter::GetReturnSlotParam(clang::QualType type) { + return std::format("this: {},", + ToString(ctx_.getPointerType(type.getUnqualifiedType()))); +} + bool Converter::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) { if (expr->isElidable()) { Convert(expr->getArg(0)); @@ -4840,6 +4889,9 @@ void Converter::ConvertLambdaCapture(const clang::FieldDecl *field, void Converter::ConvertLambdaClosure(const clang::CXXRecordDecl *decl, clang::CXXMethodDecl *call_operator) { StrCat('|'); + if (UsesReturnSlot(call_operator->getReturnType())) { + StrCat(GetReturnSlotParam(call_operator->getReturnType())); + } ConvertParamList(call_operator->parameters(), call_operator->isVariadic()); StrCat('|'); ConvertFunctionReturnType(call_operator); @@ -5374,6 +5426,9 @@ void Converter::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, } void Converter::ConvertFunctionParameters(clang::FunctionDecl *decl) { + if (UsesReturnSlot(decl->getReturnType())) { + StrCat(GetReturnSlotParam(decl->getReturnType())); + } ConvertParamList(DefinitionParameters(decl), decl->isVariadic()); } @@ -5391,7 +5446,7 @@ void Converter::ConvertParamList(llvm::ArrayRef params, void Converter::ConvertFunctionReturnType(clang::FunctionDecl *decl) { auto return_type = decl->getReturnType(); - if (!return_type->isVoidType()) { + if (!return_type->isVoidType() && !UsesReturnSlot(return_type)) { StrCat(token::kArrow); Convert(return_type); } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 9465b20af4..04deafa4ee 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -278,6 +278,12 @@ class Converter : public clang::RecursiveASTVisitor { virtual const char *TakePlacementValue() const; + virtual const char *GetReturnSlotReceiver() const; + + virtual std::string GetReturnSlotArg(std::string_view receiver) const; + + std::string GetReturnSlotParam(clang::QualType type); + virtual bool VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl); virtual bool VisitFieldDecl(clang::FieldDecl *decl); @@ -1224,7 +1230,7 @@ class Converter : public clang::RecursiveASTVisitor { // A construction that constructs its object in place, in the storage that // receiver gives to the constructor. struct InPlaceConstruct { - const clang::CXXConstructExpr *expr = nullptr; + const clang::Expr *expr = nullptr; std::string receiver; }; InPlaceConstruct in_place_; @@ -1239,13 +1245,12 @@ class Converter : public clang::RecursiveASTVisitor { // Converts init, which constructs an object by construct, to a statement that // constructs the object in the storage that receiver gives. - void ConstructInPlace(clang::Expr *init, - const clang::CXXConstructExpr *construct, + void ConstructInPlace(clang::Expr *init, const clang::Expr *construct, std::string receiver); // The construction of decl by its initializer, if it can be done in the // storage of decl. - const clang::CXXConstructExpr *GetInPlaceVarConstruct(clang::VarDecl *decl); + const clang::Expr *GetInPlaceVarConstruct(clang::VarDecl *decl); bool retain_bound_temporaries_ = false; class HoistMaterializedTempBindings { Converter &c; diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index ae3a76f481..70d41c8b19 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -713,7 +713,7 @@ bool IsConvertibleCopyConstructor(const clang::CXXConstructorDecl *ctor) { static bool HasFieldWithDefaultConstructor(const clang::CXXRecordDecl *decl) { return llvm::any_of(decl->fields(), [](const clang::FieldDecl *field) { if (auto *init = field->getInClassInitializer()) { - return GetInPlaceConstruct(init) != nullptr; + return GetPlacementInitializer(init) != nullptr; } auto *record = field->getType()->getAsCXXRecordDecl(); if (!record || !record->hasDefinition() || !IsUserDefinedDecl(record) || @@ -1038,7 +1038,7 @@ bool IsPassThroughConstructor(const clang::CXXConstructorDecl *ctor) { IsRValueConvertingConstructor(ctor)); } -const clang::CXXConstructExpr *GetInPlaceConstruct(const clang::Expr *init) { +static const clang::Expr *IgnorePlacementWrappers(const clang::Expr *init) { while (true) { init = init->IgnoreParens(); if (auto *cleanups = clang::dyn_cast(init)) { @@ -1050,9 +1050,35 @@ const clang::CXXConstructExpr *GetInPlaceConstruct(const clang::Expr *init) { cast && cast->getCastKind() == clang::CK_ConstructorConversion) { init = cast->getSubExpr(); } else { - break; + return init; } } +} + +bool UsesReturnSlot(clang::QualType type) { + auto *record = type->getAsCXXRecordDecl(); + return record && record->hasDefinition() && IsUserDefinedDecl(record) && + !record->isLambda() && !record->isTriviallyCopyable(); +} + +bool IsReturnSlotCall(const clang::Expr *expr) { + auto *call = clang::dyn_cast(expr); + if (!call || !call->isPRValue() || !UsesReturnSlot(call->getType())) { + return false; + } + auto *callee = call->getDirectCallee(); + return !callee || IsUserDefinedDecl(callee); +} + +const clang::Expr *GetPlacementInitializer(const clang::Expr *init) { + if (auto *call = IgnorePlacementWrappers(init); IsReturnSlotCall(call)) { + return call; + } + return GetInPlaceConstruct(init); +} + +const clang::CXXConstructExpr *GetInPlaceConstruct(const clang::Expr *init) { + init = IgnorePlacementWrappers(init); auto *construct = clang::dyn_cast(init); if (!construct || construct->isElidable() || construct->getType()->isArrayType()) { diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 80ff63fd0e..4015bf1179 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -218,6 +218,12 @@ bool IsRValueConvertingConstructor(const clang::CXXConstructorDecl *ctor); // is translated to a function that receives the storage. const clang::CXXConstructExpr *GetInPlaceConstruct(const clang::Expr *init); +bool UsesReturnSlot(clang::QualType type); + +bool IsReturnSlotCall(const clang::Expr *expr); + +const clang::Expr *GetPlacementInitializer(const clang::Expr *init); + bool IsPassThroughConstructor(const clang::CXXConstructorDecl *ctor); bool MethodNeedsMutableReceiver(const clang::CXXMethodDecl *method); diff --git a/cpp2rust/converter/models/boxed_vars.cpp b/cpp2rust/converter/models/boxed_vars.cpp index 32ceca1f14..036e35baee 100644 --- a/cpp2rust/converter/models/boxed_vars.cpp +++ b/cpp2rust/converter/models/boxed_vars.cpp @@ -164,7 +164,7 @@ class AddressTakenVisitor // constructor as `this`, which constructs it in place. bool VisitVarDecl(clang::VarDecl *decl) { if (decl->isLocalVarDecl() && decl->hasInit() && - GetInPlaceConstruct(decl->getInit())) { + GetPlacementInitializer(decl->getInit())) { AddressTaken(decl); } return true; diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index fb8a121898..2af4570aee 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -2061,13 +2061,14 @@ bool ConverterRefCount::VisitCXXNewExpr(clang::CXXNewExpr *expr) { array_size_as_string, default_alloc_type_as_string, alloc_type_as_string)); } - } else if (auto *construct = expr->getInitializer() - ? GetInPlaceConstruct(expr->getInitializer()) - : nullptr) { + } else if (auto *construct = + expr->getInitializer() + ? GetPlacementInitializer(expr->getInitializer()) + : nullptr) { PushBrace block(*this); StrCat( std::format("let __p = Ptr::alloc(<{}>::zero_init());", - GetRecordName(construct->getConstructor()->getParent()))); + GetRecordName(construct->getType()->getAsCXXRecordDecl()))); ConstructInPlace(expr->getInitializer(), construct, "&__p"); StrCat("__p"); } else { @@ -3838,6 +3839,13 @@ const char *ConverterRefCount::TakePlacementValue() const { return "Rc::try_unwrap(__v).ok().unwrap().into_inner()"; } +const char *ConverterRefCount::GetReturnSlotReceiver() const { return "&this"; } + +std::string +ConverterRefCount::GetReturnSlotArg(std::string_view receiver) const { + return std::format("Ptr::clone({})", receiver); +} + bool ConverterRefCount::VisitCXXThisExpr( [[maybe_unused]] clang::CXXThisExpr *expr) { if (auto field = AsLambdaCaptureThis(curr_function_)) { diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 5554ec479e..0ad31c5959 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -110,6 +110,10 @@ class ConverterRefCount final : public Converter { const char *TakePlacementValue() const override; + const char *GetReturnSlotReceiver() const override; + + std::string GetReturnSlotArg(std::string_view receiver) const override; + void ConvertCXXRecordMethods(clang::CXXRecordDecl *decl) override; void ConvertLateInstantiatedMethods(clang::CXXRecordDecl *decl) override; From c106935283eb5ecc357ea32b5ce1961d2e4fe0dc Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Tue, 1 Dec 2026 17:01:55 +0000 Subject: [PATCH 03/12] Fix binded temporaries --- cpp2rust/converter/converter_lib.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 70d41c8b19..ff836f3013 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -1071,7 +1071,11 @@ bool IsReturnSlotCall(const clang::Expr *expr) { } const clang::Expr *GetPlacementInitializer(const clang::Expr *init) { - if (auto *call = IgnorePlacementWrappers(init); IsReturnSlotCall(call)) { + auto *call = IgnorePlacementWrappers(init); + if (auto *bind = clang::dyn_cast(call)) { + call = bind->getSubExpr(); + } + if (IsReturnSlotCall(call)) { return call; } return GetInPlaceConstruct(init); From 439246552e2e569d27d2ed99a00f60b041e71ba5 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 2 Dec 2026 10:24:20 +0000 Subject: [PATCH 04/12] Update tests --- tests/unit/out/refcount/copy_assign.rs | 7 +- .../refcount/default_function_arguments.rs | 40 +++--- .../out/refcount/destructor_temporaries.rs | 58 ++++---- tests/unit/out/refcount/forward_basic.rs | 21 +-- tests/unit/out/refcount/forward_decltype.rs | 21 +-- tests/unit/out/refcount/forward_pack.rs | 21 +-- .../out/refcount/lambda_capture_copy_ctor.rs | 8 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 101 ++++++++------ tests/unit/out/refcount/map_try_emplace.rs | 16 +-- .../out/refcount/map_try_emplace_lvalues.rs | 10 +- tests/unit/out/refcount/max.rs | 87 ++++++------ tests/unit/out/refcount/move_assign.rs | 21 +-- tests/unit/out/refcount/move_this.rs | 23 ++-- tests/unit/out/refcount/swap_map_no_copy.rs | 35 ++--- .../unit/out/refcount/temporary_field_addr.rs | 110 +++++++-------- .../out/refcount/temporary_field_ctor_arg.rs | 20 +-- .../out/refcount/temporary_field_two_args.rs | 48 ++++--- tests/unit/out/unsafe/copy_assign.rs | 7 +- .../out/unsafe/default_function_arguments.rs | 39 +++--- .../unit/out/unsafe/destructor_temporaries.rs | 62 ++++----- tests/unit/out/unsafe/forward_basic.rs | 21 +-- tests/unit/out/unsafe/forward_decltype.rs | 21 +-- tests/unit/out/unsafe/forward_pack.rs | 21 +-- .../out/unsafe/lambda_capture_copy_ctor.rs | 42 +++--- tests/unit/out/unsafe/map.rs | 30 ++-- tests/unit/out/unsafe/map_key_copy_ctor.rs | 48 ++++--- tests/unit/out/unsafe/map_try_emplace.rs | 16 +-- .../out/unsafe/map_try_emplace_lvalues.rs | 8 +- tests/unit/out/unsafe/max.rs | 73 +++++----- tests/unit/out/unsafe/move_assign.rs | 21 +-- tests/unit/out/unsafe/move_this.rs | 22 +-- tests/unit/out/unsafe/swap_map_no_copy.rs | 130 ++++++++---------- tests/unit/out/unsafe/temporary_field_addr.rs | 80 ++++++----- .../out/unsafe/temporary_field_ctor_arg.rs | 18 +-- .../out/unsafe/temporary_field_two_args.rs | 44 +++--- 35 files changed, 617 insertions(+), 733 deletions(-) diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index 48a0fdb021..b0c7e025f1 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -240,11 +240,8 @@ fn main_0() -> i32 { ({ CopyAssignable::copy_assign(&a.as_pointer(), a.as_pointer()) }); assert!((assigns_0.with(|rc| *rc.borrow()) == 3)); ({ - let _o: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - PartialImpl::construct(&__v.as_pointer(), { 9 }, { 900 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _o: Value = Rc::new(RefCell::new(::zero_init())); + PartialImpl::construct(&_o.as_pointer(), { 9 }, { 900 }); CopyAssignable::copy_assign(&a.as_pointer(), _o.as_pointer()) }); assert!(({ (*a.borrow()).v } == 9) && ({ (*a.borrow()).keep } == 100)); diff --git a/tests/unit/out/refcount/default_function_arguments.rs b/tests/unit/out/refcount/default_function_arguments.rs index 0f7ac66438..01c5c1d526 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -81,16 +81,17 @@ fn main_0() -> i32 { let b: Value = Rc::new(RefCell::new(::zero_init())); BarImpl::construct(&b.as_pointer(), { 1 }); assert!(({ (*b.borrow()).v } == 1)); - assert!( - ({ - { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&__v.as_pointer(), { 2 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() + { + let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + assert!( + ({ + BarImpl::construct(&__tmp_0.as_pointer(), { 2 }); + __tmp_0.as_pointer() } - .v - } == 2) - ); + .with(|__s| __s.v) + == 2) + ) + }; let mut arr: [Bar; 3] = [ { let __v: Value = Rc::new(RefCell::new(::zero_init())); @@ -116,32 +117,23 @@ fn main_0() -> i32 { assert!((counter_2.with(|rc| *rc.borrow()) == 1)); assert!( (({ - let _b: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&__v.as_pointer(), { 7 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _b: Value = Rc::new(RefCell::new(::zero_init())); + BarImpl::construct(&_b.as_pointer(), { 7 }); by_ref_5(_b.as_pointer()) }) == 7) ); assert!( (({ - let _b: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&__v.as_pointer(), { 3 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _b: Value = Rc::new(RefCell::new(::zero_init())); + BarImpl::construct(&_b.as_pointer(), { 3 }); by_ref_5(_b.as_pointer()) }) == 3) ); assert!((({ by_global_ref_7(global_bar_6.with(|v| v.as_pointer()),) }) == 9)); assert!( (({ - let _b: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - BarImpl::construct(&__v.as_pointer(), { 4 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _b: Value = Rc::new(RefCell::new(::zero_init())); + BarImpl::construct(&_b.as_pointer(), { 4 }); by_global_ref_7(_b.as_pointer()) }) == 4) ); diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index 9579f8af2f..9aa4199335 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -62,53 +62,49 @@ fn main_0() -> i32 { { let __v: Value = Rc::new(RefCell::new(::zero_init())); ({ make_2(Ptr::clone(&__v.as_pointer()), 1) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 1)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); &({ let __v: Value = Rc::new(RefCell::new(::zero_init())); ({ make_2(Ptr::clone(&__v.as_pointer()), 2) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() }); assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 2)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); let mut x: i32 = { + let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_2(Ptr::clone(&__v.as_pointer()), 3) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() + ({ make_2(Ptr::clone(&__tmp_0.as_pointer()), 3) }); + __tmp_0.as_pointer() } - .v + .with(|__s| __s.v) }; assert!( ((x == 3) && (destroyed_0.with(|rc| *rc.borrow()) == 1)) && (last_1.with(|rc| *rc.borrow()) == 3) ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); - x = ({ - SImpl::get( - &Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_2(Ptr::clone(&__v.as_pointer()), 4) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer(), - ) - }); + { + let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + x = ({ + SImpl::get(&{ + ({ make_2(Ptr::clone(&__tmp_1.as_pointer()), 4) }); + __tmp_1.as_pointer() + }) + }) + }; assert!( ((x == 4) && (destroyed_0.with(|rc| *rc.borrow()) == 1)) && (last_1.with(|rc| *rc.borrow()) == 4) ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); - x = { - { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_outer_3(Ptr::clone(&__v.as_pointer())) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() + { + let __tmp_2: Value = Rc::new(RefCell::new(::zero_init())); + x = { + ({ make_outer_3(Ptr::clone(&__tmp_2.as_pointer())) }); + __tmp_2.as_pointer() } - .inner - .v + .with(|__s| __s.inner.v) }; assert!( ((x == 7) && (destroyed_0.with(|rc| *rc.borrow()) == 1)) @@ -119,11 +115,8 @@ fn main_0() -> i32 { assert!((x == 5) && (destroyed_0.with(|rc| *rc.borrow()) == 1)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); x = ({ - let _s: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_2(Ptr::clone(&__v.as_pointer()), 6) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _s: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_2(Ptr::clone(&_s.as_pointer()), 6) }); use_4(_s.as_pointer()) }); assert!( @@ -158,12 +151,9 @@ fn main_0() -> i32 { ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); { - let __tmp_0: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_2(Ptr::clone(&__v.as_pointer()), 11) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); - let r: Ptr = __tmp_0.as_pointer(); + let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_2(Ptr::clone(&__tmp_3.as_pointer()), 11) }); + let r: Ptr = __tmp_3.as_pointer(); assert!((destroyed_0.with(|rc| *rc.borrow()) == 0) && (r.with(|__s| __s.v) == 11)); } assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 11)); diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index 55574a021e..05b14668b6 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -122,11 +122,8 @@ fn main_0() -> i32 { assert!(({ (*lvalue.borrow()).v } == 7)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&__v.as_pointer(), { 8 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _x: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct(&_x.as_pointer(), { 8 }); forward_once_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -140,11 +137,8 @@ fn main_0() -> i32 { assert!(({ (*relayed.borrow()).v } == 9)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&__v.as_pointer(), { 10 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _x: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct(&_x.as_pointer(), { 10 }); forward_twice_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -159,11 +153,8 @@ fn main_0() -> i32 { assert!(({ (*kept.borrow()).v } == 11)); let from_rvalue: Value = Rc::new(RefCell::new(::zero_init())); ({ - let _x: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&__v.as_pointer(), { 12 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _x: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct(&_x.as_pointer(), { 12 }); forward_into_ctor_7(Ptr::clone(&from_rvalue.as_pointer()), _x.as_pointer()) }); assert!(({ (*from_rvalue.borrow()).t.v } == 12)); diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index 8dcd8701c7..b59e3838aa 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -96,11 +96,8 @@ fn main_0() -> i32 { assert!(({ (*a.borrow()).v } == 3)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&__v.as_pointer(), { 4 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _x: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct(&_x.as_pointer(), { 4 }); forward_by_decltype_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -114,11 +111,8 @@ fn main_0() -> i32 { assert!(({ (*b.borrow()).v } == 5)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&__v.as_pointer(), { 6 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _x: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct(&_x.as_pointer(), { 6 }); forward_abbreviated_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -127,11 +121,8 @@ fn main_0() -> i32 { TrackedImpl::construct(&c.as_pointer(), { 7 }); assert!( (({ - let _args_1: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&__v.as_pointer(), { 8 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _args_1: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::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))) ); diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index 3186b99a45..78e555afc0 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -149,22 +149,16 @@ fn main_0() -> i32 { assert!(({ (*a.borrow()).v } == 1)); assert!( (({ - let _args: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&__v.as_pointer(), { 2 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _args: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct(&_args.as_pointer(), { 2 }); forward_pack_6(_args.as_pointer()) }) == (Overload_kRvalueOverload as i32)) ); let i: Value = Rc::new(RefCell::new(3)); assert!( (({ - let _args_1: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&__v.as_pointer(), { 4 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _args_1: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct(&_args_1.as_pointer(), { 4 }); let _args_3: Value = Rc::new(RefCell::new(5)); forward_pack_7( a.as_pointer(), @@ -180,11 +174,8 @@ fn main_0() -> i32 { TrackedImpl::construct(&lhs.as_pointer(), { 6 }); let p: Value = Rc::new(RefCell::new(::zero_init())); ({ - let _args_1: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&__v.as_pointer(), { 7 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + 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.as_pointer()), lhs.as_pointer(), diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index be617e7eb1..8dca0a91ce 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -122,8 +122,8 @@ fn main_0() -> i32 { let h: Value i32>> = Rc::new(RefCell::new((*f.borrow()).move_from())); assert!(({ (({ (*h.borrow()).call() }) == 11) })); let mut returned: i32 = { + let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); { - let __v: Value = Rc::new(RefCell::new(::zero_init())); ({ lambda!( { @@ -140,11 +140,11 @@ fn main_0() -> i32 { return; } ) - .call(Ptr::clone(&__v.as_pointer())) + .call(Ptr::clone(&__tmp_0.as_pointer())) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() + __tmp_0.as_pointer() } - .copies + .with(|__s| __s.copies) }; assert!((returned == 2)); let arr: Value> = Rc::new(RefCell::new(Box::new( diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 136ca1bc15..a49155dea2 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -126,34 +126,44 @@ fn main_0() -> i32 { != 0 }; ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; - match (Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_key_3(Ptr::clone(&__v.as_pointer()), 4) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer(),) { - (__tmp_3,) => { - ({ - (*m.borrow_mut()).subscript_move((__tmp_3).clone(), |__k| cpp_move!(__k), || 0_i32) - }) + let __tmp_4: Value = Rc::new(RefCell::new(::zero_init())); + match ({ + ({ make_key_3(Ptr::clone(&__tmp_4.as_pointer()), 4) }); + __tmp_4.as_pointer() + },) + { + (__tmp_3,) => { + ({ + (*m.borrow_mut()).subscript_move( + (__tmp_3).clone(), + |__k| cpp_move!(__k), + || 0_i32, + ) + }) + } } - } - .write(40); - match (Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_key_3(Ptr::clone(&__v.as_pointer()), 4) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer(),) + .write(40) + }; { - (__tmp_4,) => { - ({ - (*m.borrow_mut()).subscript_move((__tmp_4).clone(), |__k| cpp_move!(__k), || 0_i32) - }) + let __tmp_6: Value = Rc::new(RefCell::new(::zero_init())); + match ({ + ({ make_key_3(Ptr::clone(&__tmp_6.as_pointer()), 4) }); + __tmp_6.as_pointer() + },) + { + (__tmp_5,) => { + ({ + (*m.borrow_mut()).subscript_move( + (__tmp_5).clone(), + |__k| cpp_move!(__k), + || 0_i32, + ) + }) + } } - } - .write(41); + .write(41) + }; ok = { ((ok as i32) & ((((made_2.with(|rc| *rc.borrow()) == 2) && (moves_1.with(|rc| *rc.borrow()) == 1)) @@ -161,14 +171,14 @@ fn main_0() -> i32 { != 0 }; match (c.as_pointer(),) { - (__tmp_5,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_5, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_7,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_7, |__k| cpp_move!(__k), || 0_i32) }) } } .write(30); match (c.as_pointer(),) { - (__tmp_6,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_6, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_8,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_8, |__k| cpp_move!(__k), || 0_i32) }) } } .write(31); @@ -189,7 +199,7 @@ fn main_0() -> i32 { .0 .as_pointer(),) { - (__tmp_7,) => ({ (*m.borrow_mut()).subscript(__tmp_7, || 0_i32) }), + (__tmp_9,) => ({ (*m.borrow_mut()).subscript(__tmp_9, || 0_i32) }), } .with_mut(|__v| *__v = *__v + 1) }; @@ -197,7 +207,7 @@ fn main_0() -> i32 { ((ok as i32) & (((copies_0.with(|rc| *rc.borrow()) == 2) && ((match (a.as_pointer(),) { - (__tmp_8,) => ({ (*m.borrow_mut()).subscript(__tmp_8, || 0_i32) }), + (__tmp_10,) => ({ (*m.borrow_mut()).subscript(__tmp_10, || 0_i32) }), } .read()) == 12)) as i32)) @@ -211,20 +221,25 @@ fn main_0() -> i32 { .deref()) .0 .as_pointer()); - match (Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - KeyImpl::construct(&__v.as_pointer(), { 0 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer(),) { - (__tmp_9,) => { - ({ - (*m.borrow_mut()).subscript_move((__tmp_9).clone(), |__k| cpp_move!(__k), || 0_i32) - }) + let __tmp_12: Value = Rc::new(RefCell::new(::zero_init())); + match ({ + KeyImpl::construct(&__tmp_12.as_pointer(), { 0 }); + __tmp_12.as_pointer() + },) + { + (__tmp_11,) => { + ({ + (*m.borrow_mut()).subscript_move( + (__tmp_11).clone(), + |__k| cpp_move!(__k), + || 0_i32, + ) + }) + } } - } - .write(0); + .write(0) + }; ok = { ((ok as i32) & ((moves_1.with(|rc| *rc.borrow()) == 3) as i32)) != 0 }; ok = { ((ok as i32) @@ -245,7 +260,7 @@ fn main_0() -> i32 { ((ok as i32) & ((((*n.borrow()).len() == 5_usize) && ((match (a.as_pointer(),) { - (__tmp_10,) => ({ (*n.borrow_mut()).subscript(__tmp_10, || 0_i32) }), + (__tmp_13,) => ({ (*n.borrow_mut()).subscript(__tmp_13, || 0_i32) }), } .read()) == 12)) as i32)) diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 57cef67ecb..1a85374413 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -656,13 +656,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_13: Value; + let __tmp_13: Value = Rc::new(RefCell::new(::zero_init())); match ({ - __tmp_13 = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), { 30 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + ItemImpl::construct_1(&__tmp_13.as_pointer(), { 30 }); __tmp_13.as_pointer() },) { @@ -702,13 +698,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_15: Value; + let __tmp_15: Value = Rc::new(RefCell::new(::zero_init())); match ({ - __tmp_15 = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), { 40 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + ItemImpl::construct_1(&__tmp_15.as_pointer(), { 40 }); __tmp_15.as_pointer() },) { diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index 5b5b80cc68..26fca55954 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -2177,16 +2177,12 @@ fn main_0() -> i32 { let owners: Value, Value)>> = Rc::new(RefCell::new(Map::new())); { - let __tmp_109: Value; + let __tmp_109: Value = + Rc::new(RefCell::new(::zero_init())); { match (({ OwnerImpl::value(&{ - __tmp_109 = Rc::new(RefCell::new({ - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - OwnerImpl::construct(&__v.as_pointer()); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + OwnerImpl::construct(&__tmp_109.as_pointer()); __tmp_109.as_pointer() }) }),) diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index 0a91ec8156..b811066a87 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -165,54 +165,53 @@ fn main_0() -> i32 { ); calls_0.with(|rc| *rc.borrow_mut() = 0); assert!( - (match ( - Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_5(Ptr::clone(&__v.as_pointer()), 1) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer(), - Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_5(Ptr::clone(&__v.as_pointer()), 2) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer(), - ) { - (__tmp_8, __tmp_9) => { - if CppLess::less(&(__tmp_8).clone(), &(__tmp_9).clone()) { - (__tmp_9).clone() - } else { - (__tmp_8).clone() + ({ + let __tmp_9: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_11: Value = Rc::new(RefCell::new(::zero_init())); + (match ( + { + ({ make_5(Ptr::clone(&__tmp_9.as_pointer()), 1) }); + __tmp_9.as_pointer() + }, + { + ({ make_5(Ptr::clone(&__tmp_11.as_pointer()), 2) }); + __tmp_11.as_pointer() + }, + ) { + (__tmp_8, __tmp_10) => { + if CppLess::less(&(__tmp_8).clone(), &(__tmp_10).clone()) { + (__tmp_10).clone() + } else { + (__tmp_8).clone() + } } } - } - .with(|__s| __s.n) - == 2) - && (match ( - Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_5(Ptr::clone(&__v.as_pointer()), 1) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer(), - Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_5(Ptr::clone(&__v.as_pointer()), 2) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer(), + .with(|__s| __s.n) + == 2) + }) && ({ + let __tmp_13: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_15: Value = Rc::new(RefCell::new(::zero_init())); + (match ( + { + ({ make_5(Ptr::clone(&__tmp_13.as_pointer()), 1) }); + __tmp_13.as_pointer() + }, + { + ({ make_5(Ptr::clone(&__tmp_15.as_pointer()), 2) }); + __tmp_15.as_pointer() + }, ) { - (__tmp_10, __tmp_11) => { - if CppLess::less(&(__tmp_11).clone(), &(__tmp_10).clone()) { - (__tmp_11).clone() + (__tmp_12, __tmp_14) => { + if CppLess::less(&(__tmp_14).clone(), &(__tmp_12).clone()) { + (__tmp_14).clone() } else { - (__tmp_10).clone() + (__tmp_12).clone() } } } .with(|__s| __s.n) == 1) + }) ); assert!((calls_0.with(|rc| *rc.borrow()) == 0)); let mut largest: usize = 0_usize; @@ -221,13 +220,13 @@ fn main_0() -> i32 { 'loop_: while (i < 3) { 'for_body: { largest = (({ - let __tmp_13: Value = Rc::new(RefCell::new((largest as u64))); + 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_12,) => { - if CppLess::less(&__tmp_13.as_pointer(), &(__tmp_12).clone()) { - (__tmp_12).clone() + (__tmp_16,) => { + if CppLess::less(&__tmp_17.as_pointer(), &(__tmp_16).clone()) { + (__tmp_16).clone() } else { - __tmp_13.as_pointer() + __tmp_17.as_pointer() } } } diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 5640ffd68f..7cb0d1c522 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -70,11 +70,8 @@ fn main_0() -> i32 { assert!(({ (*a.borrow()).v } == 2)); assert!(({ (*b.borrow()).v } == 0)); ({ - let _o: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::construct(&__v.as_pointer(), { 3 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _o: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnlyImpl::construct(&_o.as_pointer(), { 3 }); MoveAssignable::move_assign(&b.as_pointer(), _o.as_pointer()) }); ({ @@ -87,20 +84,14 @@ fn main_0() -> i32 { (({ (*b.borrow()).v } == 0) && ({ (*a.borrow()).v } == 0)) && ({ (*c.borrow()).v } == 3) ); ({ - let _o: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::construct(&__v.as_pointer(), { 5 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _o: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnlyImpl::construct(&_o.as_pointer(), { 5 }); MoveAssignable::move_assign(&a.as_pointer(), _o.as_pointer()) }); assert!(({ (*a.borrow()).v } == 5)); ({ - let _o: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_0(Ptr::clone(&__v.as_pointer()), 6) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _o: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_0(Ptr::clone(&_o.as_pointer()), 6) }); MoveAssignable::move_assign(&a.as_pointer(), _o.as_pointer()) }); assert!(({ (*a.borrow()).v } == 6)); diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index e16e8c51f2..b6a984a28a 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -64,17 +64,18 @@ fn main_0() -> i32 { }); assert!(({ (*b.borrow()).v } == 8) && ({ (*b0.borrow()).v } == 0)); let c: Value = Rc::new(RefCell::new(::zero_init())); - ({ - ChainImpl::take( - &Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ChainImpl::construct(&__v.as_pointer(), { 10 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer(), - Ptr::clone(&c.as_pointer()), - ) - }); + { + let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + ({ + ChainImpl::take( + &{ + ChainImpl::construct(&__tmp_0.as_pointer(), { 10 }); + __tmp_0.as_pointer() + }, + Ptr::clone(&c.as_pointer()), + ) + }) + }; assert!(({ (*c.borrow()).v } == 11)); let d: Value = Rc::new(RefCell::new(::zero_init())); ({ ChainImpl::copy(&c.as_pointer(), Ptr::clone(&d.as_pointer())) }); diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index ec70adca23..17c0917f34 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -305,11 +305,8 @@ fn main_0() -> i32 { assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let m1: Value, Value)>> = Rc::new(RefCell::new(Map::new())); ({ - let _o: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct_1(&__v.as_pointer(), { 10 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _o: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct_1(&_o.as_pointer(), { 10 }); MoveAssignable::move_assign( &match (Rc::new(RefCell::new(1)).as_pointer(),) { (__tmp_0,) => { @@ -326,11 +323,8 @@ fn main_0() -> i32 { ) }); ({ - let _o: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct_1(&__v.as_pointer(), { 20 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _o: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct_1(&_o.as_pointer(), { 20 }); MoveAssignable::move_assign( &match (Rc::new(RefCell::new(2)).as_pointer(),) { (__tmp_1,) => { @@ -348,11 +342,8 @@ fn main_0() -> i32 { }); let m2: Value, Value)>> = Rc::new(RefCell::new(Map::new())); ({ - let _o: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct_1(&__v.as_pointer(), { 30 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _o: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct_1(&_o.as_pointer(), { 30 }); MoveAssignable::move_assign( &match (Rc::new(RefCell::new(3)).as_pointer(),) { (__tmp_2,) => { @@ -657,11 +648,8 @@ fn main_0() -> i32 { .collect::, Value)>]>>(), )); ({ - let _o: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct_1(&__v.as_pointer(), { 1 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _o: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct_1(&_o.as_pointer(), { 1 }); MoveAssignable::move_assign( &match (Rc::new(RefCell::new(1)).as_pointer(),) { (__tmp_18,) => { @@ -678,11 +666,8 @@ fn main_0() -> i32 { ) }); ({ - let _o: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct_1(&__v.as_pointer(), { 2 }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); + let _o: Value = Rc::new(RefCell::new(::zero_init())); + TrackedImpl::construct_1(&_o.as_pointer(), { 2 }); MoveAssignable::move_assign( &match (Rc::new(RefCell::new(2)).as_pointer(),) { (__tmp_19,) => { diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index a5166a0b93..cd9d56785e 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -92,63 +92,63 @@ pub fn main() { } fn main_0() -> i32 { let calls: Value = Rc::new(RefCell::new(0)); - let mut member: i32 = ({ - sum_1( - (match Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_0(Ptr::clone(&__v.as_pointer()), calls.as_pointer()) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer() - { - __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), + let mut member: i32 = { + let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + ({ + sum_1( + (match { + ({ make_0(Ptr::clone(&__tmp_1.as_pointer()), calls.as_pointer()) }); + __tmp_1.as_pointer() + } { + __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), + }), + ) + }) + }; + let mut nested: i32 = { + let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + ({ + sum_1( + (match { + ({ make_0(Ptr::clone(&__tmp_3.as_pointer()), calls.as_pointer()) }); + __tmp_3.as_pointer() + } { + __tmp_2 => field_ref!(field_ptr!(__tmp_2, inner), values).as_pointer(), + }), + ) + }) + }; + let mut element: i32 = { + let __tmp_6: Value = Rc::new(RefCell::new(::zero_init())); + (match ( + (match { + ({ make_0(Ptr::clone(&__tmp_6.as_pointer()), calls.as_pointer()) }); + __tmp_6.as_pointer() + } { + __tmp_5 => field_ref!(__tmp_5, values).as_pointer(), }), - ) - }); - let mut nested: i32 = ({ - sum_1( - (match Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_0(Ptr::clone(&__v.as_pointer()), calls.as_pointer()) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer() - { - __tmp_1 => field_ref!(field_ptr!(__tmp_1, inner), values).as_pointer(), - }), - ) - }); - let mut element: i32 = (match ( - (match Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_0(Ptr::clone(&__v.as_pointer()), calls.as_pointer()) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer() - { - __tmp_3 => field_ref!(__tmp_3, values).as_pointer(), - }), - { (((*calls.borrow()) - 2) as usize) }, - ) { - (__tmp_2, mut __tmp_4) => { - if __tmp_4 >= (*__tmp_2.upgrade().deref()).len() { - panic!("out of bounds access") + { (((*calls.borrow()) - 2) as usize) }, + ) { + (__tmp_4, mut __tmp_7) => { + if __tmp_7 >= (*__tmp_4.upgrade().deref()).len() { + panic!("out of bounds access") + } + __tmp_4.decay().offset((__tmp_7) as isize) } - __tmp_2.decay().offset((__tmp_4) as isize) } - } - .read()); - let mut length: usize = (match Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_0(Ptr::clone(&__v.as_pointer()), calls.as_pointer()) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer() - { - __tmp_5 => array_field_ptr!(__tmp_5, name), - }) - .to_c_string_iterator() - .count(); + .read()) + }; + let mut length: usize = { + let __tmp_9: Value = Rc::new(RefCell::new(::zero_init())); + (match { + ({ make_0(Ptr::clone(&__tmp_9.as_pointer()), calls.as_pointer()) }); + __tmp_9.as_pointer() + } { + __tmp_8 => array_field_ptr!(__tmp_8, name), + }) + .to_c_string_iterator() + .count() + }; let mut aggregate: i32 = ({ sum_1( (match Rc::new(RefCell::new(Outer { @@ -160,7 +160,7 @@ fn main_0() -> i32 { })) .as_pointer() { - __tmp_6 => field_ref!(field_ptr!(__tmp_6, inner), values).as_pointer(), + __tmp_10 => field_ref!(field_ptr!(__tmp_10, inner), values).as_pointer(), }), ) }); diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index edf1aebd8d..29ce21332b 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -57,17 +57,17 @@ pub fn main() { } fn main_0() -> i32 { let h: Value = Rc::new(RefCell::new(::zero_init())); - HImpl::construct(&h.as_pointer(), { - (match Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_0(Ptr::clone(&__v.as_pointer())) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer() - { - __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), + { + let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + HImpl::construct(&h.as_pointer(), { + (match { + ({ make_0(Ptr::clone(&__tmp_1.as_pointer())) }); + __tmp_1.as_pointer() + } { + __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), + }) }) - }); + }; printf!(b"%d\n", { (*h.borrow()).last }); return 0; } diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index a41ba05542..1b908ed91d 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -68,31 +68,29 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - printf!( - b"%d\n", - ({ - two_1( - (match Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_0(Ptr::clone(&__v.as_pointer())) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer() - { - __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), - }), - (match Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_0(Ptr::clone(&__v.as_pointer())) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - .as_pointer() - { - __tmp_1 => field_ref!(field_ptr!(__tmp_1, inner), values).as_pointer(), - }), - ) - }) - ); + { + let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + printf!( + b"%d\n", + ({ + two_1( + (match { + ({ make_0(Ptr::clone(&__tmp_1.as_pointer())) }); + __tmp_1.as_pointer() + } { + __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), + }), + (match { + ({ make_0(Ptr::clone(&__tmp_3.as_pointer())) }); + __tmp_3.as_pointer() + } { + __tmp_2 => field_ref!(field_ptr!(__tmp_2, inner), values).as_pointer(), + }), + ) + }) + ) + }; return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 8b5188b98e..092d68e577 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -232,11 +232,8 @@ unsafe fn main_0() -> i32 { }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3))); (unsafe { - let mut _o: Partial = { - let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, { 9 }, { 900 }); - __v - }; + let mut _o: Partial = ::zero_init(); + Partial::construct(&mut _o, { 9 }, { 900 }); CopyAssignableUnsafe::copy_assign(&mut a, &mut _o) }); assert!(((a.v) == (9)) && ((a.keep) == (100))); diff --git a/tests/unit/out/unsafe/default_function_arguments.rs b/tests/unit/out/unsafe/default_function_arguments.rs index a4f692e6c7..78d8544017 100644 --- a/tests/unit/out/unsafe/default_function_arguments.rs +++ b/tests/unit/out/unsafe/default_function_arguments.rs @@ -99,14 +99,16 @@ unsafe fn main_0() -> i32 { let mut b: Bar = ::zero_init(); Bar::construct(&mut b, { 1 }); assert!(((b.v) == (1))); - assert!( - (({ - let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, { 2 }); - __v - } - .v) == (2)) - ); + { + let mut __tmp_0: Bar = ::zero_init(); + assert!( + (((*{ + Bar::construct(&mut __tmp_0, { 2 }); + &mut __tmp_0 + }) + .v) == (2)) + ) + }; let mut arr: [Bar; 3] = [ { let mut __v: Bar = ::zero_init(); @@ -132,21 +134,15 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut counter_2)) == (1))); assert!( ((unsafe { - let mut _b: Bar = { - let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, { 7 }); - __v - }; + let mut _b: Bar = ::zero_init(); + Bar::construct(&mut _b, { 7 }); by_ref_5(&mut _b) }) == (7)) ); assert!( ((unsafe { - let mut _b: Bar = { - let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, { 3 }); - __v - }; + let mut _b: Bar = ::zero_init(); + Bar::construct(&mut _b, { 3 }); by_ref_5(&mut _b) }) == (3)) ); @@ -157,11 +153,8 @@ unsafe fn main_0() -> i32 { ); assert!( ((unsafe { - let mut _b: Bar = { - let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, { 4 }); - __v - }; + let mut _b: Bar = ::zero_init(); + Bar::construct(&mut _b, { 4 }); by_global_ref_7(&mut _b) }) == (4)) ); diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index fc72f4ec88..452e29db99 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -61,7 +61,6 @@ unsafe fn main_0() -> i32 { { let mut __v: S = ::zero_init(); (unsafe { make_2(&mut __v, 1) }); - __v }; assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) @@ -71,7 +70,6 @@ unsafe fn main_0() -> i32 { &({ let mut __v: S = ::zero_init(); (unsafe { make_2(&mut __v, 2) }); - __v }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) @@ -79,35 +77,43 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; let mut x: i32 = { - let mut __v: S = ::zero_init(); - (unsafe { make_2(&mut __v, 3) }); - __v - } - .v; + let mut __tmp_0: S = ::zero_init(); + (*{ + (unsafe { make_2(&mut __tmp_0, 3) }); + &mut __tmp_0 + }) + .v + }; assert!( (((x) == (3)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (3)) ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; - x = (unsafe { - S::get(&{ - let mut __v: S = ::zero_init(); - (unsafe { make_2(&mut __v, 4) }); - __v + { + let mut __tmp_1: S = ::zero_init(); + x = (unsafe { + S::get( + &(*{ + (unsafe { make_2(&mut __tmp_1, 4) }); + &mut __tmp_1 + }), + ) }) - }); + }; assert!( (((x) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (4)) ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; - x = { - let mut __v: Outer = ::zero_init(); - (unsafe { make_outer_3(&mut __v) }); - __v - } - .inner - .v; + { + let mut __tmp_2: Outer = ::zero_init(); + x = (*{ + (unsafe { make_outer_3(&mut __tmp_2) }); + &mut __tmp_2 + }) + .inner + .v + }; assert!( (((x) == (7)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (7)) @@ -117,11 +123,8 @@ unsafe fn main_0() -> i32 { assert!(((x) == (5)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1))); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; x = (unsafe { - let mut _s: S = { - let mut __v: S = ::zero_init(); - (unsafe { make_2(&mut __v, 6) }); - __v - }; + let mut _s: S = ::zero_init(); + (unsafe { make_2(&mut _s, 6) }); use_4(&mut _s) }); assert!( @@ -154,12 +157,9 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { - let mut __tmp_0: S = { - let mut __v: S = ::zero_init(); - (unsafe { make_2(&mut __v, 11) }); - __v - }; - let r: *const S = &mut __tmp_0; + let mut __tmp_3: S = ::zero_init(); + (unsafe { make_2(&mut __tmp_3, 11) }); + let r: *const S = &mut __tmp_3; assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (0)) && (((*r).v) == (11)) diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 10eca79285..3be3338cf7 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -129,11 +129,8 @@ unsafe fn main_0() -> i32 { assert!(((lvalue.v) == (7))); assert!( (((unsafe { - let mut _x: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct(&mut __v, { 8 }); - __v - }; + let mut _x: Tracked = ::zero_init(); + Tracked::construct(&mut _x, { 8 }); forward_once_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -146,11 +143,8 @@ unsafe fn main_0() -> i32 { assert!(((relayed.v) == (9))); assert!( (((unsafe { - let mut _x: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct(&mut __v, { 10 }); - __v - }; + let mut _x: Tracked = ::zero_init(); + Tracked::construct(&mut _x, { 10 }); forward_twice_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -165,11 +159,8 @@ unsafe fn main_0() -> i32 { assert!(((kept.v) == (11))); let mut from_rvalue: Holder = ::zero_init(); (unsafe { - let mut _x: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct(&mut __v, { 12 }); - __v - }; + let mut _x: Tracked = ::zero_init(); + Tracked::construct(&mut _x, { 12 }); forward_into_ctor_7(&mut 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 7d86b616cb..4a72585444 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -95,11 +95,8 @@ unsafe fn main_0() -> i32 { assert!(((a.v) == (3))); assert!( (((unsafe { - let mut _x: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct(&mut __v, { 4 }); - __v - }; + let mut _x: Tracked = ::zero_init(); + Tracked::construct(&mut _x, { 4 }); forward_by_decltype_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -112,11 +109,8 @@ unsafe fn main_0() -> i32 { assert!(((b.v) == (5))); assert!( (((unsafe { - let mut _x: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct(&mut __v, { 6 }); - __v - }; + let mut _x: Tracked = ::zero_init(); + Tracked::construct(&mut _x, { 6 }); forward_abbreviated_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -125,11 +119,8 @@ unsafe fn main_0() -> i32 { Tracked::construct(&mut c, { 7 }); assert!( ((unsafe { - let mut _args_1: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct(&mut __v, { 8 }); - __v - }; + let mut _args_1: Tracked = ::zero_init(); + Tracked::construct(&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_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index 4e7bbfe557..e8bd03f9a9 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -152,22 +152,16 @@ unsafe fn main_0() -> i32 { assert!(((a.v) == (1))); assert!( ((unsafe { - let mut _args: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct(&mut __v, { 2 }); - __v - }; + let mut _args: Tracked = ::zero_init(); + Tracked::construct(&mut _args, { 2 }); forward_pack_6(&mut _args) }) == (Overload_kRvalueOverload as i32)) ); let mut i: i32 = 3; assert!( ((unsafe { - let mut _args_1: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct(&mut __v, { 4 }); - __v - }; + let mut _args_1: Tracked = ::zero_init(); + Tracked::construct(&mut _args_1, { 4 }); let mut _args_3: i32 = 5; forward_pack_7(&mut a, &mut _args_1, &mut i, &mut _args_3) }) == (1234)) @@ -178,11 +172,8 @@ unsafe fn main_0() -> i32 { Tracked::construct(&mut lhs, { 6 }); let mut p: Pair = ::zero_init(); (unsafe { - let mut _args_1: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct(&mut __v, { 7 }); - __v - }; + let mut _args_1: Tracked = ::zero_init(); + Tracked::construct(&mut _args_1, { 7 }); forward_pack_into_ctor_8(&mut p, &mut lhs, &mut _args_1) }); assert!(((p.a.v) == (6))); diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index 590d509721..e12c4a9d84 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -131,26 +131,28 @@ unsafe fn main_0() -> i32 { let mut h: FnPtr i32> = f.move_from(); assert!(((unsafe { h.call() }) == (11))); let mut returned: i32 = { - let mut __v: Counted = ::zero_init(); - (unsafe { - lambda_unsafe!( - { - let c: Counted = { - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); - __v - }; - }, - |this: *mut Counted| { - CopyConstructibleUnsafe::copy_constructor(&mut *this, { &c }); - return; - } - ) - .call(&mut __v) - }); - __v - } - .copies; + let mut __tmp_0: Counted = ::zero_init(); + (*{ + (unsafe { + lambda_unsafe!( + { + let c: Counted = { + let mut __v: Counted = ::zero_init(); + CopyConstructibleUnsafe::copy_constructor(&mut __v, { &c }); + __v + }; + }, + |this: *mut Counted| { + CopyConstructibleUnsafe::copy_constructor(&mut *this, { &c }); + return; + } + ) + .call(&mut __tmp_0) + }); + &mut __tmp_0 + }) + .copies + }; assert!(((returned) == (2))); let mut arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|_| { let mut __v: Counted = ::zero_init(); diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index 2386426f67..5df1205c96 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -656,29 +656,33 @@ unsafe fn main_0() -> i32 { &raw mut (*t.subscript_move(&mut __tmp_43, |__k| cpp_move_unsafe!(__k), || 0_i32)) })) }; - { - let mut __tmp_44: i64; - let mut __tmp_45: i64; - let mut __tmp_46: i64; - assert!( - ((((x) == (10)) - && ((*{ + assert!( + ((((x) == (10)) + && ({ + let mut __tmp_44: i64; + ((*{ __tmp_44 = 1_i64; &raw mut (*t.subscript_move( &mut __tmp_44, |__k| cpp_move_unsafe!(__k), || 0_i32, )) - }) == (4))) - && ((*{ + }) == (4)) + })) + && ({ + let mut __tmp_45: i64; + ((*{ __tmp_45 = 2_i64; &raw mut (*t.subscript_move( &mut __tmp_45, |__k| cpp_move_unsafe!(__k), || 0_i32, )) - }) == (6))) - && ((*{ + }) == (6)) + })) + && ({ + let mut __tmp_46: i64; + ((*{ __tmp_46 = 3_i64; &raw mut (*t.subscript_move( &mut __tmp_46, @@ -686,8 +690,8 @@ unsafe fn main_0() -> i32 { || 0_i32, )) }) == (2)) - ) - }; + }) + ); } return 0; } diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 3623848929..92f323efd5 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -118,22 +118,26 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) != 0; - (*match ((&mut { - let mut __v: Key = ::zero_init(); - (unsafe { make_key_3(&mut __v, 4) }); - __v - } as *mut Key),) { - (__tmp_0,) => &mut (*m.subscript_move(__tmp_0, |__k| cpp_move_unsafe!(__k), || 0_i32)), - }) = 40; - (*match ((&mut { - let mut __v: Key = ::zero_init(); - (unsafe { make_key_3(&mut __v, 4) }); - __v - } as *mut Key),) + let mut __tmp_1: Key = ::zero_init(); + (*match (({ + (unsafe { make_key_3(&mut __tmp_1, 4) }); + &mut __tmp_1 + } as *mut Key),) + { + (__tmp_0,) => &mut (*m.subscript_move(__tmp_0, |__k| cpp_move_unsafe!(__k), || 0_i32)), + }) = 40 + }; { - (__tmp_1,) => &mut (*m.subscript_move(__tmp_1, |__k| cpp_move_unsafe!(__k), || 0_i32)), - }) = 41; + let mut __tmp_3: Key = ::zero_init(); + (*match (({ + (unsafe { make_key_3(&mut __tmp_3, 4) }); + &mut __tmp_3 + } as *mut Key),) + { + (__tmp_2,) => &mut (*m.subscript_move(__tmp_2, |__k| cpp_move_unsafe!(__k), || 0_i32)), + }) = 41 + }; ok = ((ok as i32) & (((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (1))) @@ -154,14 +158,16 @@ unsafe fn main_0() -> i32 { && ((*m.subscript(&a, || 0_i32)) == (12))) as i32)) != 0; let mut first: *const Key = (&(*m.begin().iter_deref()).0 as *const Key); - (*match ((&mut { - let mut __v: Key = ::zero_init(); - Key::construct(&mut __v, { 0 }); - __v - } as *mut Key),) { - (__tmp_2,) => &mut (*m.subscript_move(__tmp_2, |__k| cpp_move_unsafe!(__k), || 0_i32)), - }) = 0; + let mut __tmp_5: Key = ::zero_init(); + (*match (({ + Key::construct(&mut __tmp_5, { 0 }); + &mut __tmp_5 + } as *mut Key),) + { + (__tmp_4,) => &mut (*m.subscript_move(__tmp_4, |__k| cpp_move_unsafe!(__k), || 0_i32)), + }) = 0 + }; ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3)) as i32)) != 0; diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 99592788fa..cab1642c41 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -397,13 +397,9 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) }; let mut temporary_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_13: Item; + let mut __tmp_13: Item = ::zero_init(); match (({ - __tmp_13 = { - let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, { 30 }); - __v - }; + Item::construct_1(&mut __tmp_13, { 30 }); &mut __tmp_13 } as *mut Item),) { @@ -424,13 +420,9 @@ unsafe fn main_0() -> i32 { key.prefix_inc(); key.prefix_inc(); let mut temporary_new: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_15: Item; + let mut __tmp_15: Item = ::zero_init(); match (({ - __tmp_15 = { - let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, { 40 }); - __v - }; + Item::construct_1(&mut __tmp_15, { 40 }); &mut __tmp_15 } as *mut Item),) { diff --git a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs index 7788a2d0f2..1229f2461d 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -1251,16 +1251,12 @@ unsafe fn main_0() -> i32 { ); let mut owners: UnsafeMap = UnsafeMap::new(); { - let mut __tmp_101: Owner; + let mut __tmp_101: Owner = ::zero_init(); { match (((unsafe { Owner::value( &mut (*{ - __tmp_101 = { - let mut __v: Owner = ::zero_init(); - Owner::construct(&mut __v); - __v - }; + Owner::construct(&mut __tmp_101); &mut __tmp_101 }), ) diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 7dafef37a7..3e34a334ab 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -165,48 +165,47 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) = 0; assert!( - (((*match ( - (&mut { - let mut __v: Bag = ::zero_init(); - (unsafe { make_5(&mut __v, 1) }); - __v - } as *const Bag), - (&mut { - let mut __v: Bag = ::zero_init(); - (unsafe { make_5(&mut __v, 2) }); - __v - } as *const Bag), - ) { - (__tmp_4, __tmp_5) => { - { + ({ + let mut __tmp_5: Bag = ::zero_init(); + let mut __tmp_7: Bag = ::zero_init(); + (((*match ( + ({ + (unsafe { make_5(&mut __tmp_5, 1) }); + &mut __tmp_5 + } as *const Bag), + ({ + (unsafe { make_5(&mut __tmp_7, 2) }); + &mut __tmp_7 + } as *const Bag), + ) { + (__tmp_4, __tmp_6) => { let __a: *const _ = __tmp_4; - let __b: *const _ = __tmp_5; + let __b: *const _ = __tmp_6; if *__a < *__b { __b } else { __a } } - } - }) - .n) == (2)) - && (((*match ( - (&mut { - let mut __v: Bag = ::zero_init(); - (unsafe { make_5(&mut __v, 1) }); - __v + }) + .n) == (2)) + }) && ({ + let mut __tmp_9: Bag = ::zero_init(); + let mut __tmp_11: Bag = ::zero_init(); + (((*match ( + ({ + (unsafe { make_5(&mut __tmp_9, 1) }); + &mut __tmp_9 } as *const Bag), - (&mut { - let mut __v: Bag = ::zero_init(); - (unsafe { make_5(&mut __v, 2) }); - __v + ({ + (unsafe { make_5(&mut __tmp_11, 2) }); + &mut __tmp_11 } as *const Bag), ) { - (__tmp_6, __tmp_7) => { - { - let __a: *const _ = __tmp_6; - let __b: *const _ = __tmp_7; - if *__b < *__a { __b } else { __a } - } + (__tmp_8, __tmp_10) => { + let __a: *const _ = __tmp_8; + let __b: *const _ = __tmp_10; + if *__b < *__a { __b } else { __a } } }) .n) == (1)) + }) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (0))); let mut largest: usize = 0_usize; @@ -215,11 +214,11 @@ unsafe fn main_0() -> i32 { 'loop_: while ((i) < (3)) { 'for_body: { largest = (({ - let mut __tmp_9: u64 = (largest as u64); + let mut __tmp_13: u64 = (largest as u64); (*match ((&mut ((unsafe { size_of_2(i) }) as u64) as *const u64),) { - (__tmp_8,) => { - let __a: *const _ = &mut __tmp_9; - let __b: *const _ = __tmp_8; + (__tmp_12,) => { + let __a: *const _ = &mut __tmp_13; + let __b: *const _ = __tmp_12; if *__a < *__b { __b } else { __a } } }) diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index 6fd672cde0..1de05ce949 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -87,11 +87,8 @@ unsafe fn main_0() -> i32 { assert!(((a.v) == (2))); assert!(((b.v) == (0))); (unsafe { - let mut _o: MoveOnly = { - let mut __v: MoveOnly = ::zero_init(); - MoveOnly::construct(&mut __v, { 3 }); - __v - }; + let mut _o: MoveOnly = ::zero_init(); + MoveOnly::construct(&mut _o, { 3 }); MoveAssignableUnsafe::move_assign(&mut b, &mut _o) }); (unsafe { @@ -102,20 +99,14 @@ unsafe fn main_0() -> i32 { }); assert!((((b.v) == (0)) && ((a.v) == (0))) && ((c.v) == (3))); (unsafe { - let mut _o: MoveOnly = { - let mut __v: MoveOnly = ::zero_init(); - MoveOnly::construct(&mut __v, { 5 }); - __v - }; + let mut _o: MoveOnly = ::zero_init(); + MoveOnly::construct(&mut _o, { 5 }); MoveAssignableUnsafe::move_assign(&mut a, &mut _o) }); assert!(((a.v) == (5))); (unsafe { - let mut _o: MoveOnly = { - let mut __v: MoveOnly = ::zero_init(); - (unsafe { make_0(&mut __v, 6) }); - __v - }; + let mut _o: MoveOnly = ::zero_init(); + (unsafe { make_0(&mut _o, 6) }); MoveAssignableUnsafe::move_assign(&mut a, &mut _o) }); assert!(((a.v) == (6))); diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index fb59458b77..4a4d682523 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -88,16 +88,18 @@ unsafe fn main_0() -> i32 { }); assert!(((b.v) == (8)) && ((b0.v) == (0))); let mut c: Chain = ::zero_init(); - (unsafe { - Chain::take( - &mut { - let mut __v: Chain = ::zero_init(); - Chain::construct(&mut __v, { 10 }); - __v - }, - &mut c, - ) - }); + { + let mut __tmp_0: Chain = ::zero_init(); + (unsafe { + Chain::take( + &mut (*{ + Chain::construct(&mut __tmp_0, { 10 }); + &mut __tmp_0 + }), + &mut c, + ) + }) + }; assert!(((c.v) == (11))); let mut d: Chain = ::zero_init(); (unsafe { Chain::copy(&c, &mut d) }); diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index ae94b61441..2fe289e319 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -287,11 +287,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_0: i32; (unsafe { - let mut _o: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&mut __v, { 10 }); - __v - }; + let mut _o: Tracked = ::zero_init(); + Tracked::construct_1(&mut _o, { 10 }); MoveAssignableUnsafe::move_assign( &mut (*{ __tmp_0 = 1; @@ -308,11 +305,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_1: i32; (unsafe { - let mut _o: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&mut __v, { 20 }); - __v - }; + let mut _o: Tracked = ::zero_init(); + Tracked::construct_1(&mut _o, { 20 }); MoveAssignableUnsafe::move_assign( &mut (*{ __tmp_1 = 2; @@ -330,11 +324,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_2: i32; (unsafe { - let mut _o: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&mut __v, { 30 }); - __v - }; + let mut _o: Tracked = ::zero_init(); + Tracked::construct_1(&mut _o, { 30 }); MoveAssignableUnsafe::move_assign( &mut (*{ __tmp_2 = 3; @@ -372,10 +363,9 @@ unsafe fn main_0() -> i32 { SwappableUnsafe::swap(&mut *__a, __b) } }; - { - let mut __tmp_5: i32; - let mut __tmp_6: i32; - assert!( + assert!( + ({ + let mut __tmp_5: i32; (({ __tmp_5 = 1; (*m1.subscript_move( @@ -385,28 +375,30 @@ unsafe fn main_0() -> i32 { )) .v }) == (20)) - && (({ - __tmp_6 = 2; - (*m1.subscript_move( - &mut __tmp_6, - |__k| cpp_move_unsafe!(__k), - || ::default(), - )) - .v - }) == (10)) - ) - }; + }) && ({ + let mut __tmp_6: i32; + (({ + __tmp_6 = 2; + (*m1.subscript_move( + &mut __tmp_6, + |__k| cpp_move_unsafe!(__k), + || ::default(), + )) + .v + }) == (10)) + }) + ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); { let __a: *mut _ = &mut m1; let __b: *mut _ = &mut m2; SwappableUnsafe::swap(&mut *__a, __b) }; - { - let mut __tmp_7: i32; - assert!( - ((m1.len()) == (1_usize)) - && (({ + assert!( + ((m1.len()) == (1_usize)) + && ({ + let mut __tmp_7: i32; + (({ __tmp_7 = 3; (*m1.subscript_move( &mut __tmp_7, @@ -415,14 +407,13 @@ unsafe fn main_0() -> i32 { )) .v }) == (30)) - ) - }; - { - let mut __tmp_8: i32; - let mut __tmp_9: i32; - assert!( - (((m2.len()) == (2_usize)) - && (({ + }) + ); + assert!( + (((m2.len()) == (2_usize)) + && ({ + let mut __tmp_8: i32; + (({ __tmp_8 = 1; (*m2.subscript_move( &mut __tmp_8, @@ -430,8 +421,11 @@ unsafe fn main_0() -> i32 { || ::default(), )) .v - }) == (20))) - && (({ + }) == (20)) + })) + && ({ + let mut __tmp_9: i32; + (({ __tmp_9 = 2; (*m2.subscript_move( &mut __tmp_9, @@ -440,8 +434,8 @@ unsafe fn main_0() -> i32 { )) .v }) == (10)) - ) - }; + }) + ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut arr: [Tracked; 3] = [ { @@ -605,11 +599,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_10: i32; (unsafe { - let mut _o: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&mut __v, { 1 }); - __v - }; + let mut _o: Tracked = ::zero_init(); + Tracked::construct_1(&mut _o, { 1 }); MoveAssignableUnsafe::move_assign( &mut (*{ __tmp_10 = 1; @@ -626,11 +617,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_11: i32; (unsafe { - let mut _o: Tracked = { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&mut __v, { 2 }); - __v - }; + let mut _o: Tracked = ::zero_init(); + Tracked::construct_1(&mut _o, { 2 }); MoveAssignableUnsafe::move_assign( &mut (*{ __tmp_11 = 2; @@ -649,11 +637,11 @@ unsafe fn main_0() -> i32 { let __b: *mut _ = &mut maps[(1) as usize]; SwappableUnsafe::swap(&mut *__a, __b) }; - { - let mut __tmp_12: i32; - assert!( - ((maps[(0) as usize].len()) == (1_usize)) - && (({ + assert!( + ((maps[(0) as usize].len()) == (1_usize)) + && ({ + let mut __tmp_12: i32; + (({ __tmp_12 = 2; (*maps[(0) as usize].subscript_move( &mut __tmp_12, @@ -662,13 +650,13 @@ unsafe fn main_0() -> i32 { )) .v }) == (2)) - ) - }; - { - let mut __tmp_13: i32; - assert!( - ((maps[(1) as usize].len()) == (1_usize)) - && (({ + }) + ); + assert!( + ((maps[(1) as usize].len()) == (1_usize)) + && ({ + let mut __tmp_13: i32; + (({ __tmp_13 = 1; (*maps[(1) as usize].subscript_move( &mut __tmp_13, @@ -677,8 +665,8 @@ unsafe fn main_0() -> i32 { )) .v }) == (1)) - ) - }; + }) + ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut c1: CopyOnly = ::zero_init(); CopyOnly::construct(&mut c1, { 1 }); diff --git a/tests/unit/out/unsafe/temporary_field_addr.rs b/tests/unit/out/unsafe/temporary_field_addr.rs index 3a7e880712..9f30c6f180 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -69,43 +69,51 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut calls: i32 = 0; - let mut member: i32 = (unsafe { - sum_1( - &{ - let mut __v: Outer = ::zero_init(); - (unsafe { make_0(&mut __v, &mut calls) }); - __v - } - .values, - ) - }); - let mut nested: i32 = (unsafe { - sum_1( - &{ - let mut __v: Outer = ::zero_init(); - (unsafe { make_0(&mut __v, &mut calls) }); - __v - } - .inner - .values, - ) - }); + let mut member: i32 = { + let mut __tmp_0: Outer = ::zero_init(); + (unsafe { + sum_1( + &(*{ + (unsafe { make_0(&mut __tmp_0, &mut calls) }); + &mut __tmp_0 + }) + .values, + ) + }) + }; + let mut nested: i32 = { + let mut __tmp_1: Outer = ::zero_init(); + (unsafe { + sum_1( + &(*{ + (unsafe { make_0(&mut __tmp_1, &mut calls) }); + &mut __tmp_1 + }) + .inner + .values, + ) + }) + }; let mut element: i32 = { - let mut __v: Outer = ::zero_init(); - (unsafe { make_0(&mut __v, &mut calls) }); - __v - } - .values[(((calls) - (2)) as usize)]; - let mut length: usize = libc::strlen( - ({ - let mut __v: Outer = ::zero_init(); - (unsafe { make_0(&mut __v, &mut calls) }); - __v - } - .name - .as_mut_ptr()) - .cast_const(), - ); + let mut __tmp_2: Outer = ::zero_init(); + (*{ + (unsafe { make_0(&mut __tmp_2, &mut calls) }); + &mut __tmp_2 + }) + .values[(((calls) - (2)) as usize)] + }; + let mut length: usize = { + let mut __tmp_3: Outer = ::zero_init(); + libc::strlen( + ((*{ + (unsafe { make_0(&mut __tmp_3, &mut calls) }); + &mut __tmp_3 + }) + .name + .as_mut_ptr()) + .cast_const(), + ) + }; let mut aggregate: i32 = (unsafe { sum_1( &Outer { diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index 74040c0d1a..f57417869f 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -57,14 +57,16 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut h: H = ::zero_init(); - H::construct(&mut h, { - &{ - let mut __v: Outer = ::zero_init(); - (unsafe { make_0(&mut __v) }); - __v - } - .values - }); + { + let mut __tmp_0: Outer = ::zero_init(); + H::construct(&mut h, { + &(*{ + (unsafe { make_0(&mut __tmp_0) }); + &mut __tmp_0 + }) + .values + }) + }; (unsafe { libc::printf(c"%d\n".as_ptr() as *const libc::c_char, (h.last)) }); return 0; } diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index 700c79e869..35f4e247d7 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -60,27 +60,29 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { - libc::printf( - c"%d\n".as_ptr() as *const libc::c_char, - (unsafe { - let _a: *const Vec = &{ - let mut __v: Outer = ::zero_init(); - (unsafe { make_0(&mut __v) }); - __v - } - .values; - let _b: *const Vec = &{ - let mut __v: Outer = ::zero_init(); - (unsafe { make_0(&mut __v) }); - __v - } - .inner - .values; - two_1(_a, _b) - }), - ) - }); + { + let mut __tmp_0: Outer = ::zero_init(); + let mut __tmp_1: Outer = ::zero_init(); + (unsafe { + libc::printf( + c"%d\n".as_ptr() as *const libc::c_char, + (unsafe { + let _a: *const Vec = &(*{ + (unsafe { make_0(&mut __tmp_0) }); + &mut __tmp_0 + }) + .values; + let _b: *const Vec = &(*{ + (unsafe { make_0(&mut __tmp_1) }); + &mut __tmp_1 + }) + .inner + .values; + two_1(_a, _b) + }), + ) + }) + }; return 0; } pub unsafe fn __cpp2rust_init_globals() {} From 00b3fcb17a8f9f6dfd1dc93ae8518f39a3589ab8 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 2 Dec 2026 10:26:04 +0000 Subject: [PATCH 05/12] Hoist temporaries before the converterd expression --- cpp2rust/converter/converter.cpp | 58 ++++++++++++++++--- cpp2rust/converter/converter.h | 7 +++ cpp2rust/converter/converter_lib.cpp | 11 ++++ cpp2rust/converter/converter_lib.h | 5 ++ .../converter/models/converter_refcount.cpp | 9 ++- 5 files changed, 79 insertions(+), 11 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 231edda20d..b58617e23c 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -280,7 +280,7 @@ std::string Converter::ConvertPointerReceiver( std::string Converter::ConvertTemporaryPointer( clang::Expr *expr, std::optional implicit_convert_to) { - if (retain_bound_temporaries_ && full_expression_temporaries_) { + if (KeepsTemporaryOwner(expr)) { auto [binding, ref] = MaterializeTemp(NewTempName(), ctx_.getLValueReferenceType( @@ -327,6 +327,11 @@ Converter::MaterializeTemp(const std::string &binding_name, declarations = full_expression_temporaries_; } auto pointee = param_type.getNonReferenceType(); + if (auto *init = GetTemporaryPlacementInitializer(ctx_, expr, pointee); + init && (declarations || !in_const_initializer_)) { + return {ConstructTemporaryInPlace(binding_name, expr, init, declarations), + std::format("& mut {}", binding_name)}; + } std::string value; { ScopedPush init_type(curr_init_type_, pointee); @@ -657,9 +662,7 @@ void Converter::ConvertVarDeclInitializer(clang::VarDecl *decl) { // Rust-only argument conversions can need temporaries even when Clang // supplies no ExprWithCleanups for the initializer. std::string declarations; - ScopedValue scope(full_expression_temporaries_, - in_const_initializer_ ? &declarations - : full_expression_temporaries_); + ScopedValue scope(full_expression_temporaries_, &declarations); auto start = rs_code_->size(); bool registers_destructor = NeedsStaticDestructor(decl); if (registers_destructor) { @@ -1548,7 +1551,13 @@ static bool IsaSemiColonStmt(const clang::Stmt *stmt) { bool Converter::Convert(clang::Stmt *stmt) { PushExprKind push(*this, ExprKind::Void); - auto exited_visit = TraverseStmt(stmt); + bool exited_visit = false; + if (stmt && + (clang::isa(stmt) || clang::isa(stmt))) { + ConvertFullExpression([&] { exited_visit = TraverseStmt(stmt); }); + } else { + exited_visit = TraverseStmt(stmt); + } if (stmt && IsaSemiColonStmt(stmt)) { StrCat(token::kSemiColon); } @@ -1641,7 +1650,7 @@ bool Converter::VisitGotoStmt(clang::GotoStmt *stmt) { void Converter::ConvertCondition(clang::Expr *cond) { PushExprKind push(*this, ExprKind::RValue); - Convert(NormalizeToBool(cond, ctx_)); + ConvertFullExpression([&] { Convert(NormalizeToBool(cond, ctx_)); }); } void Converter::ConvertIfCondition(clang::Expr *cond) { @@ -1897,13 +1906,35 @@ void Converter::ConvertFullExpression(llvm::function_ref convert) { } } +bool Converter::KeepsTemporaryOwner(const clang::Expr *temporary) const { + return full_expression_temporaries_ && + (retain_bound_temporaries_ || + GetTemporaryPlacementInitializer(ctx_, temporary, + temporary->getType())); +} + +std::string Converter::ConstructTemporaryInPlace(const std::string &name, + clang::Expr *temporary, + const clang::Expr *init, + std::string *declarations) { + auto storage = CreatePlacementStorage( + GetRecordName(init->getType()->getAsCXXRecordDecl()), name); + PushExprKind push(*this, ExprKind::Void); + ScopedValue in_place(in_place_, {init, GetPlacementReceiver(name)}); + auto construct = std::format("{};", ToString(temporary->IgnoreImplicit())); + if (!declarations) { + return storage + construct; + } + *declarations += storage; + return construct; +} + bool Converter::VisitMaterializeTemporaryExpr( clang::MaterializeTemporaryExpr *expr) { // A temporary bound to a reference variable lives as long as the variable. bool extended = IsExtendedTemporary(expr); // A consuming conversion moves the temporary into its result instead. - if (isFreshRValue() || (!extended && (!retain_bound_temporaries_ || - !full_expression_temporaries_))) { + if (isFreshRValue() || (!extended && !KeepsTemporaryOwner(expr))) { return true; } // Keep the owner through the full expression, or the scope of the variable @@ -1919,6 +1950,12 @@ bool Converter::VisitMaterializeTemporaryExpr( : materialized_temp_bindings_; } bool pointer = isAddrOf(); + if (!pointer && + GetTemporaryPlacementInitializer(ctx_, expr, expr->getType())) { + StrCat(DerefPtrExpr(ConvertFreshPointer(expr), expr->getType())); + SetValueFreshness(expr->getType()); + return false; + } auto name = NewTempName(); auto type = ctx_.getLValueReferenceType(expr->getType()); auto [binding, ref] = @@ -2171,7 +2208,10 @@ bool Converter::VisitCallExpr(clang::CallExpr *expr) { ScopedValue in_place(in_place_, {expr, GetPlacementReceiver()}); Convert(expr); } - StrCat(token::kSemiColon, TakePlacementValue()); + StrCat(token::kSemiColon); + if (!isVoid()) { + StrCat(TakePlacementValue()); + } MarkFresh(); return false; } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index e28dc6d277..6f76693a61 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -1245,6 +1245,13 @@ class Converter : public clang::RecursiveASTVisitor { // temporaries that live through it, if there are any. void ConvertFullExpression(llvm::function_ref convert); + bool KeepsTemporaryOwner(const clang::Expr *temporary) const; + + std::string ConstructTemporaryInPlace(const std::string &name, + clang::Expr *temporary, + const clang::Expr *init, + std::string *declarations); + // Converts init, which constructs an object by construct, to a statement that // constructs the object in the storage that receiver gives. void ConstructInPlace(clang::Expr *init, const clang::Expr *construct, diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index de34b38324..396f88a2b3 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -1095,6 +1095,17 @@ const clang::Expr *GetPlacementInitializer(const clang::Expr *init) { return GetInPlaceConstruct(init); } +const clang::Expr * +GetTemporaryPlacementInitializer(const clang::ASTContext &ctx, + const clang::Expr *temporary, + clang::QualType type) { + auto *init = GetPlacementInitializer(temporary->IgnoreImplicit()); + if (!init || !ctx.hasSameUnqualifiedType(init->getType(), type)) { + return nullptr; + } + return init; +} + const clang::CXXConstructExpr *GetInPlaceConstruct(const clang::Expr *init) { init = IgnorePlacementWrappers(init); auto *construct = clang::dyn_cast(init); diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index f40a7b9d64..6213a38288 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -228,6 +228,11 @@ bool IsReturnSlotCall(const clang::Expr *expr); const clang::Expr *GetPlacementInitializer(const clang::Expr *init); +const clang::Expr * +GetTemporaryPlacementInitializer(const clang::ASTContext &ctx, + const clang::Expr *temporary, + clang::QualType type); + bool IsPassThroughConstructor(const clang::CXXConstructorDecl *ctor); bool MethodNeedsMutableReceiver(const clang::CXXMethodDecl *method); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 7895d212d9..4e339e06a7 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -482,7 +482,7 @@ std::string ConverterRefCount::ConvertFreshObject(clang::Expr *expr) { std::string ConverterRefCount::ConvertTemporaryPointer( clang::Expr *expr, std::optional implicit_convert_to) { - if (retain_bound_temporaries_ && full_expression_temporaries_) { + if (KeepsTemporaryOwner(expr)) { return Converter::ConvertTemporaryPointer(expr, implicit_convert_to); } return std::format("Rc::new(RefCell::new({})).as_pointer()", @@ -547,6 +547,11 @@ std::pair ConverterRefCount::MaterializeTemp( } auto pointee = param_type.getNonReferenceType(); bool is_static = in_const_initializer_ && !declarations; + if (auto *init = GetTemporaryPlacementInitializer(ctx_, expr, pointee); + init && !is_static) { + return {ConstructTemporaryInPlace(binding_name, expr, init, declarations), + binding_name + ".as_pointer()"}; + } const auto *decl = is_static ? keyword::kStatic : keyword::kLet; std::string type, value; if (pointee->isConstantArrayType()) { @@ -3638,7 +3643,7 @@ void ConverterRefCount::SetUFCSReceiver(clang::Expr *base, bool is_arrow, } if (IsTemporaryObject(ctx_, base) && base->getType()->isRecordType() && !IsReferenceType(base->IgnoreImplicit())) { - if (retain_bound_temporaries_ && full_expression_temporaries_) { + if (KeepsTemporaryOwner(base)) { ufcs_receiver_ = token::kRef + ConvertTemporaryPointer(base, {}); return; } From fb719aeafb0b2c96c3776154c99a3dbe5b3f4e94 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 2 Dec 2026 10:26:20 +0000 Subject: [PATCH 06/12] Update test expectation --- tests/unit/temporary_field_ctor_arg.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/temporary_field_ctor_arg.cpp b/tests/unit/temporary_field_ctor_arg.cpp index 2aae845bd5..832da73d2e 100644 --- a/tests/unit/temporary_field_ctor_arg.cpp +++ b/tests/unit/temporary_field_ctor_arg.cpp @@ -1,4 +1,3 @@ -// panic: refcount // nondet-result: unsafe // Valid C++: the temporary lives until H's constructor returns. Both From 74c828622bddbff6fd289508973adcd94006b4b4 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 2 Dec 2026 10:37:47 +0000 Subject: [PATCH 07/12] Update tests --- .../out/refcount/defaulted_move_cross_tu.rs | 3 +- .../out/unsafe/defaulted_move_cross_tu.rs | 3 +- .../refcount/out_of_line_methods_cross_tu.rs | 14 +- .../unsafe/out_of_line_methods_cross_tu.rs | 12 +- .../out/refcount/p14-class-in-two-files.rs | 14 +- .../out/unsafe/p14-class-in-two-files.rs | 12 +- .../out/refcount/p15-function-template.rs | 14 +- .../out/unsafe/p15-function-template.rs | 12 +- .../out/refcount/p15-inline-function.rs | 14 +- .../out/unsafe/p15-inline-function.rs | 12 +- .../out/refcount/p15-inline-variable.rs | 14 +- .../out/unsafe/p15-inline-variable.rs | 12 +- .../p16-default-argument-lambda-in-class.rs | 14 +- .../p16-default-argument-lambda-in-class.rs | 12 +- .../refcount/p16-lambda-in-inline-function.rs | 14 +- .../unsafe/p16-lambda-in-inline-function.rs | 12 +- .../out/refcount/basic.scope.block.rs | 14 +- .../out/unsafe/basic.scope.block.rs | 12 +- .../out/refcount/basic.start.term-p1-exit.rs | 14 +- .../out/refcount/basic.start.term.rs | 28 +++- .../out/unsafe/basic.start.term-p1-exit.rs | 12 +- .../out/unsafe/basic.start.term.rs | 24 ++- tests/std/basic/out/refcount/basic.def.odr.rs | 45 ++++- tests/std/basic/out/unsafe/basic.def.odr.rs | 35 +++- .../stmt.iter/out/refcount/stmt.while.rs | 26 ++- .../stmt.iter/out/unsafe/stmt.while.rs | 22 ++- .../stmt.select/out/refcount/stmt.switch.rs | 13 +- .../stmt.select/out/unsafe/stmt.switch.rs | 11 +- .../out/refcount/array_of_noncopy_struct.rs | 3 +- .../out/refcount/assignment_single_eval.rs | 3 +- tests/unit/out/refcount/cast.rs | 3 +- tests/unit/out/refcount/class_templates.rs | 9 +- tests/unit/out/refcount/constructor.rs | 13 +- .../unit/out/refcount/container_field_addr.rs | 3 +- tests/unit/out/refcount/copy_assign.rs | 26 ++- tests/unit/out/refcount/copy_ctor.rs | 13 +- .../unit/out/refcount/copy_move_defaulted.rs | 38 +++-- tests/unit/out/refcount/delete_array_order.rs | 14 +- tests/unit/out/refcount/destructor.rs | 154 ++++++++++++++++-- tests/unit/out/refcount/destructor_params.rs | 14 +- .../out/refcount/destructor_temporaries.rs | 39 ++++- .../out/refcount/field_method_receiver.rs | 3 +- tests/unit/out/refcount/field_pointers.rs | 3 +- .../unit/out/refcount/for_body_destructor.rs | 14 +- .../refcount/foreach_disjoint_field_borrow.rs | 3 +- tests/unit/out/refcount/implicit_autoref.rs | 3 +- .../out/refcount/inline_container_fields.rs | 6 +- tests/unit/out/refcount/lambda_as_field.rs | 13 +- .../refcount/libc_struct_without_default.rs | 3 +- tests/unit/out/refcount/push_emplace_back.rs | 6 +- .../unit/out/refcount/rvalue_rule_arg_move.rs | 3 +- tests/unit/out/refcount/sort_no_copy.rs | 3 +- .../refcount/structured_binding_move_ctor.rs | 3 +- tests/unit/out/refcount/swap_map_no_copy.rs | 5 +- .../unit/out/refcount/temporary_field_addr.rs | 6 +- .../out/refcount/temporary_field_ctor_arg.rs | 3 +- .../out/refcount/temporary_field_two_args.rs | 6 +- .../unit/out/refcount/typedef-anon-struct.rs | 3 +- tests/unit/out/refcount/vector.rs | 3 +- .../out/refcount/vector_subscript_direct.rs | 3 +- tests/unit/out/refcount/void_cast.rs | 3 +- .../out/unsafe/array_of_noncopy_struct.rs | 3 +- .../unit/out/unsafe/assignment_single_eval.rs | 3 +- tests/unit/out/unsafe/cast.rs | 3 +- tests/unit/out/unsafe/class_templates.rs | 9 +- tests/unit/out/unsafe/constructor.rs | 11 +- tests/unit/out/unsafe/container_field_addr.rs | 3 +- tests/unit/out/unsafe/copy_assign.rs | 10 +- tests/unit/out/unsafe/copy_ctor.rs | 5 +- tests/unit/out/unsafe/copy_move_defaulted.rs | 34 ++-- tests/unit/out/unsafe/delete_array_order.rs | 12 +- tests/unit/out/unsafe/destructor.rs | 131 +++++++++++++-- tests/unit/out/unsafe/destructor_params.rs | 12 +- .../unit/out/unsafe/destructor_temporaries.rs | 34 +++- .../unit/out/unsafe/field_method_receiver.rs | 3 +- tests/unit/out/unsafe/field_pointers.rs | 3 +- tests/unit/out/unsafe/for_body_destructor.rs | 12 +- .../unsafe/foreach_disjoint_field_borrow.rs | 3 +- tests/unit/out/unsafe/implicit_autoref.rs | 3 +- .../out/unsafe/inline_container_fields.rs | 6 +- tests/unit/out/unsafe/lambda_as_field.rs | 11 +- .../out/unsafe/libc_struct_without_default.rs | 3 +- tests/unit/out/unsafe/push_emplace_back.rs | 6 +- tests/unit/out/unsafe/rvalue_rule_arg_move.rs | 3 +- tests/unit/out/unsafe/sort_no_copy.rs | 3 +- .../unsafe/structured_binding_move_ctor.rs | 3 +- tests/unit/out/unsafe/swap_map_no_copy.rs | 5 +- tests/unit/out/unsafe/temporary_field_addr.rs | 6 +- .../out/unsafe/temporary_field_ctor_arg.rs | 3 +- .../out/unsafe/temporary_field_two_args.rs | 6 +- tests/unit/out/unsafe/typedef-anon-struct.rs | 3 +- tests/unit/out/unsafe/vector.rs | 3 +- .../out/unsafe/vector_subscript_direct.rs | 3 +- tests/unit/out/unsafe/void_cast.rs | 3 +- 94 files changed, 984 insertions(+), 248 deletions(-) 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 8ecca9a2c6..21ff4464c1 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 @@ -36,11 +36,10 @@ impl Default for S { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct T { #[offset(0)] diff --git a/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs index c88ffabaa5..fc9d2f15e6 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 @@ -37,11 +37,10 @@ impl S { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct T { pub v: Vec, } 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 e8fd3c9148..ec2e9aa614 100644 --- a/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs +++ b/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs b/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs index 80012ce45f..1b9a4ef84b 100644 --- a/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs +++ b/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct S { pub v: i32, } diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index 2e7fc99ca2..f1e0b0a9ac 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 @@ -78,7 +78,19 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] 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 d121830008..4acf156250 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 @@ -70,7 +70,17 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct AssertsDtorCountAtExit { pub expected: i32, } 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 217d591c0b..9f01a7d5fd 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 @@ -78,7 +78,19 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] 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 8db26da7bf..6be3fc1d68 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 @@ -70,7 +70,17 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct AssertsDtorCountAtExit { pub expected: i32, } 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 a13379f8dd..21dd819328 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 @@ -78,7 +78,19 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] 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 808d42e458..5b69c600e5 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 @@ -70,7 +70,17 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct AssertsDtorCountAtExit { pub expected: i32, } diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index a4811a9266..2325ffd6e3 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 @@ -78,7 +78,19 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] 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 e0345ac87e..b7906a551a 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 @@ -70,7 +70,17 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct AssertsDtorCountAtExit { pub expected: i32, } diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index bb10609bef..a443bd6e03 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 @@ -78,7 +78,19 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] 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 32284bdcd2..bac67f99e0 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 @@ -70,7 +70,17 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct AssertsDtorCountAtExit { pub expected: i32, } 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 d2b0fb3faa..1f3ed0b777 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 @@ -78,7 +78,19 @@ impl Default for LifetimeTracked { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] 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 bf6a14970a..6e9beddd62 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 @@ -70,7 +70,17 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct AssertsDtorCountAtExit { pub expected: i32, } 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 3038dd053c..5bad7e7bfd 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 @@ -87,7 +87,19 @@ thread_local!( thread_local!( pub static dtorCount_6: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs index 3b0ad1f3ba..eba6486995 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 @@ -75,7 +75,17 @@ pub static mut else_runs_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { pub value: i32, } diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs index 74b41456ee..51361a8071 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct Tracker { #[offset(0)] diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs index 8feb0f56e8..09852599a6 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct Tracker { #[offset(0)] @@ -18,8 +30,20 @@ impl Destructible for Tracker { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Memberwise, + CopyConstructible, + MoveConstructible, + Swappable, + Default, )] +#[memberwise(move_assign, copy_assign)] #[byte_size(4)] pub struct HoldsTracker { #[offset(0)] 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 ed41a6abea..813791e127 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct Tracker { pub tag: i32, } diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs index 6b3236d7bb..b1b60eb5ef 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct Tracker { pub tag: i32, } @@ -27,8 +37,18 @@ impl DestructibleUnsafe for Tracker { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, + Default, )] +#[memberwise(move_assign, copy_assign)] pub struct HoldsTracker { #[destroy] pub member: Tracker, diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index ee18416964..97c581a634 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -458,10 +458,11 @@ pub fn test_19() { FnPtrArg, Destructible, Memberwise, - Movable, + MoveConstructible, + Swappable, Default, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, move_assign, copy_assign)] #[byte_size(8)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[offset(0)] @@ -506,9 +507,18 @@ pub fn test_20() { assert!((useCount_4.with(|rc| *rc.borrow()) == 0)); } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Memberwise, Movable, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Memberwise, + MoveConstructible, + Swappable, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, move_assign, copy_assign)] #[byte_size(8)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(0)] @@ -556,10 +566,11 @@ pub fn test_22() { FnPtrArg, Destructible, Memberwise, - Movable, + MoveConstructible, + Swappable, Default, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, move_assign, copy_assign)] #[byte_size(4)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[offset(0)] @@ -607,7 +618,18 @@ pub fn test_26() { thread_local!( pub static t_ctors_27: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, +)] +#[memberwise(copy_assign)] #[byte_size(1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl Default for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { @@ -639,7 +661,8 @@ pub fn test_28() { thread_local!( pub static ctor_calls_29: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { #[offset(0)] @@ -711,9 +734,13 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { VaArg, FnPtrArg, Destructible, - Copyable, + Memberwise, + CopyConstructible, + MoveConstructible, + Swappable, 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 f787249ad4..8fb80b6a5b 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -419,10 +419,11 @@ pub unsafe fn test_19() { ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, - MovableUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, Default, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, move_assign, copy_assign)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[destroy] pub a: LifetimeTracked, @@ -472,9 +473,10 @@ pub unsafe fn test_20() { ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, - MovableUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, move_assign, copy_assign)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, @@ -534,10 +536,11 @@ pub unsafe fn test_22() { ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, - MovableUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, Default, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, move_assign, copy_assign)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, @@ -591,7 +594,16 @@ pub unsafe fn test_26() { } pub static mut t_ctors_27: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, +)] +#[memberwise(copy_assign)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { pub unsafe fn construct(&mut self) { @@ -624,7 +636,8 @@ pub unsafe fn test_28() { pub static mut ctor_calls_29: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe)] +#[memberwise(copy_assign)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } @@ -694,9 +707,13 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, - CopyableUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, Default, )] +#[memberwise(copy_assign, move_assign)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } 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 f9b7d9ba18..30f24bee61 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs @@ -13,8 +13,19 @@ thread_local!( pub static dtorCount_1: Value = Rc::new(RefCell::new(0)); ); #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Memberwise, + CopyConstructible, + Movable, + Default, )] +#[memberwise(copy_assign)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { @@ -65,8 +76,19 @@ thread_local!( pub static dtorCount_4: Value = Rc::new(RefCell::new(0)); ); #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Memberwise, + CopyConstructible, + Movable, + Default, )] +#[memberwise(copy_assign)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { 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 20aeb1bd40..28f9e59dc9 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs @@ -10,8 +10,17 @@ pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, )] +#[memberwise(copy_assign)] #[cpp_from(i32, construct, value)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { pub value: i32, @@ -63,8 +72,17 @@ pub static mut ctorCount_3: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, )] +#[memberwise(copy_assign)] #[cpp_from(i32, construct, value)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { pub value: i32, 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 62ebf4019a..bd0627b35e 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 @@ -88,8 +88,19 @@ thread_local!( pub static dtorCount_6: Value = Rc::new(RefCell::new(0)); ); #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Memberwise, + CopyConstructible, + Movable, + Default, )] +#[memberwise(copy_assign)] #[cpp_into(i32, to_i32)] #[byte_size(4)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { 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 2b42c2fe50..9e73cb1f6e 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 @@ -76,8 +76,17 @@ pub static mut other_case_runs_5: std::cell::LazyCell = pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, )] +#[memberwise(copy_assign)] #[cpp_into(i32, to_i32)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { pub value: i32, diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index 71791d4f08..317bcf9bd7 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -16,10 +16,9 @@ use std::rc::{Rc, Weak}; Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(32)] pub struct NonCopy { #[offset(0)] diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 48a44912bd..b5289ad4b8 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -2184,11 +2184,10 @@ pub fn test_stable_containers_58() { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct Counts_59 { #[offset(0)] diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index f753b4b78c..ee1fe2634e 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -66,11 +66,10 @@ impl Default for Grid { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(32)] pub struct Bag { #[offset(0)] diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index 1338a5d044..e0e8c740e3 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -16,11 +16,10 @@ use std::rc::{Rc, Weak}; Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct MyContainer_int_ { #[offset(0)] @@ -37,11 +36,10 @@ pub struct MyContainer_int_ { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct MyContainer_char_ { #[offset(0)] @@ -58,11 +56,10 @@ pub struct MyContainer_char_ { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct MyContainer_float_ { #[offset(0)] diff --git a/tests/unit/out/refcount/constructor.rs b/tests/unit/out/refcount/constructor.rs index e50d70586c..8cf4c9c971 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -10,8 +10,19 @@ thread_local!( pub static total_0: Value = Rc::new(RefCell::new(0)); ); #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Memberwise, + CopyConstructible, + Movable, + Default, )] +#[memberwise(copy_assign)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/container_field_addr.rs b/tests/unit/out/refcount/container_field_addr.rs index e96507817e..6c59f17525 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -16,11 +16,10 @@ use std::rc::{Rc, Weak}; Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(32)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index b0c7e025f1..faf50d7ac0 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -99,9 +99,18 @@ impl Default for RefQualified { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Memberwise, Movable, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Memberwise, + MoveConstructible, + Swappable, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct Holder { #[offset(0)] @@ -161,9 +170,18 @@ impl Clone for CopyCounted { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Memberwise, Movable, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Memberwise, + MoveConstructible, + Swappable, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, move_assign, copy_assign)] #[byte_size(12)] pub struct HasCopyCounted { #[offset(0)] diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index b233c65a4b..474c83257c 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -114,9 +114,18 @@ impl Clone for Ignored { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Memberwise, Movable, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Memberwise, + MoveConstructible, + Swappable, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, move_assign, copy_assign)] #[byte_size(12)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index 6c6dc58b73..c009ee5638 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -14,7 +14,20 @@ pub struct Inner { #[offset(0)] pub x: i32, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Copyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + CppFrom, + Memberwise, + CopyConstructible, + MoveConstructible, + Swappable, +)] +#[memberwise(copy_assign, move_assign)] #[cpp_from(i32, construct, value)] #[byte_size(16)] pub struct Explicit { @@ -70,11 +83,12 @@ impl Default for Implicit { FnPtrArg, CppFrom, Destructible, + Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] +#[memberwise(copy_assign)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct DefaultCopyUserMove { @@ -198,11 +212,10 @@ impl Default for Owner { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct Copyable { #[offset(0)] @@ -553,8 +566,8 @@ fn main_0() -> i32 { ExplicitImpl::construct(&f.as_pointer(), { 3 }); let _dtor_f = std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(&__p.as_pointer())); - (*e.borrow_mut()) = (*b.borrow()).clone(); - (*f.borrow_mut()) = (*c.borrow()).clone(); + ({ CopyAssignable::copy_assign(&e.as_pointer(), b.as_pointer()) }); + ({ MoveAssignable::move_assign(&f.as_pointer(), c.as_pointer()) }); assert!( ({ same_0(e.as_pointer(), b.as_pointer(),) }) && ({ same_0(f.as_pointer(), c.as_pointer(),) }) @@ -563,11 +576,12 @@ fn main_0() -> i32 { ExplicitImpl::construct(&g.as_pointer(), { 4 }); let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); - let __rhs = { - (*e.borrow_mut()) = (*f.borrow()).clone(); - (*e.borrow()).clone() - }; - (*g.borrow_mut()) = __rhs; + ({ + CopyAssignable::copy_assign( + &g.as_pointer(), + ({ CopyAssignable::copy_assign(&e.as_pointer(), f.as_pointer()) }), + ) + }); assert!( ({ same_0(g.as_pointer(), f.as_pointer(),) }) && ({ same_0(e.as_pointer(), f.as_pointer(),) }) @@ -614,7 +628,7 @@ fn main_0() -> i32 { DefaultCopyUserMoveImpl::construct(&m3.as_pointer(), { 1 }); let m4: Value = Rc::new(RefCell::new(::zero_init())); DefaultCopyUserMoveImpl::construct(&m4.as_pointer(), { 1 }); - (*m3.borrow_mut()) = (*m1.borrow()); + ({ CopyAssignable::copy_assign(&m3.as_pointer(), m1.as_pointer()) }); ({ MoveAssignable::move_assign(&m4.as_pointer(), m1.as_pointer()) }); assert!( (({ (*m3.borrow()).v } == 7) && ({ (*m4.borrow()).v } == 7)) && ({ (*m1.borrow()).v } == 0) diff --git a/tests/unit/out/refcount/delete_array_order.rs b/tests/unit/out/refcount/delete_array_order.rs index fae54fc406..aad2b0276c 100644 --- a/tests/unit/out/refcount/delete_array_order.rs +++ b/tests/unit/out/refcount/delete_array_order.rs @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(16)] pub struct Element { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index 998b724ff2..67481c16d8 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -9,7 +9,19 @@ use std::rc::{Rc, Weak}; thread_local!( pub static global_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(1)] pub struct S {} impl Destructible for S { @@ -18,8 +30,19 @@ impl Destructible for S { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Memberwise, + CopyConstructible, + Movable, + Default, )] +#[memberwise(copy_assign)] #[byte_size(1)] pub struct Defaulted { #[offset(0)] @@ -28,8 +51,20 @@ pub struct Defaulted { pub s: S, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Memberwise, + CopyConstructible, + MoveConstructible, + Swappable, + Default, )] +#[memberwise(move_assign, copy_assign)] #[byte_size(1)] pub struct Middle { #[offset(0)] @@ -38,8 +73,20 @@ pub struct Middle { pub s: S, } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Memberwise, + CopyConstructible, + MoveConstructible, + Swappable, + Default, )] +#[memberwise(copy_assign, move_assign)] #[byte_size(1)] pub struct Outer { #[offset(0)] @@ -47,7 +94,20 @@ pub struct Outer { #[destroy] pub m: Middle, } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Memberwise, + CopyConstructible, + MoveConstructible, + Swappable, +)] +#[memberwise(move_assign, copy_assign)] #[byte_size(3)] pub struct ArrayMember { #[offset(0)] @@ -65,7 +125,19 @@ impl Default for ArrayMember { } } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(1)] pub struct EmptyBody { #[offset(0)] @@ -77,7 +149,19 @@ impl Destructible for EmptyBody { Destructible::destroy(&field_ptr!(this, s)); } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(1)] pub struct Templated_char_ { #[offset(0)] @@ -93,7 +177,19 @@ impl Destructible for Templated_char_ { }); } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct Templated_int_ { #[offset(0)] @@ -109,7 +205,19 @@ impl Destructible for Templated_int_ { }); } } -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct Copied { #[offset(0)] @@ -127,7 +235,19 @@ thread_local!( thread_local!( pub static order_count_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct Tagged { #[offset(0)] @@ -141,8 +261,20 @@ impl Destructible for Tagged { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Memberwise, + CopyConstructible, + MoveConstructible, + Swappable, + Default, )] +#[memberwise(move_assign, copy_assign)] #[byte_size(20)] pub struct Ordered { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index 50277ed6b3..a6a970b680 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -12,7 +12,19 @@ thread_local!( thread_local!( pub static last_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index 9aa4199335..a6852ad4f4 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -12,7 +12,19 @@ thread_local!( thread_local!( pub static last_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -25,8 +37,20 @@ impl Destructible for S { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Memberwise, + CopyConstructible, + MoveConstructible, + Swappable, + Default, )] +#[memberwise(move_assign, copy_assign)] #[byte_size(8)] pub struct Outer { #[offset(0)] @@ -162,12 +186,11 @@ 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())); - let __rhs = { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ({ make_2(Ptr::clone(&__v.as_pointer()), 13) }); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; - (*s.borrow_mut()) = __rhs; + ({ + let _arg0: Value = Rc::new(RefCell::new(::zero_init())); + ({ make_2(Ptr::clone(&_arg0.as_pointer()), 13) }); + CopyAssignable::copy_assign(&s.as_pointer(), _arg0.as_pointer()) + }); assert!( ((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 13)) && ({ (*s.borrow()).v } == 13) diff --git a/tests/unit/out/refcount/field_method_receiver.rs b/tests/unit/out/refcount/field_method_receiver.rs index 0a731aa1f2..d41c773bed 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -24,10 +24,9 @@ pub struct Counter { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(40)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index e028ee78ca..a92ec2bf84 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -46,10 +46,9 @@ pub struct Header { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(104)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/for_body_destructor.rs b/tests/unit/out/refcount/for_body_destructor.rs index c0b9801e5b..a9fa542be7 100644 --- a/tests/unit/out/refcount/for_body_destructor.rs +++ b/tests/unit/out/refcount/for_body_destructor.rs @@ -6,7 +6,19 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, + Default, +)] +#[memberwise(copy_assign)] #[byte_size(4)] pub struct Guard { #[offset(0)] diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index e818a82d40..f11222b3c3 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -16,11 +16,10 @@ use std::rc::{Rc, Weak}; Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(32)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index bf1bec2052..0ea580ff68 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -16,11 +16,10 @@ use std::rc::{Rc, Weak}; Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 699221ad01..3cd1dc735a 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -16,10 +16,9 @@ use std::rc::{Rc, Weak}; Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(48)] pub struct Elem { #[offset(0)] @@ -53,10 +52,9 @@ impl Default for Elem { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(88)] pub struct State { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index b8e444244c..ca3165a8b4 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -6,7 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Copyable)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Memberwise, + CopyConstructible, + Movable, +)] +#[memberwise(copy_assign)] #[byte_size(1)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { #[offset(0)] diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index 3023a29ddb..a737d339ac 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -16,10 +16,9 @@ use std::rc::{Rc, Weak}; Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(32)] pub struct UserDefined { #[offset(0)] diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index 39dad18550..3492f11f05 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -36,11 +36,10 @@ pub struct Writer { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(48)] pub struct JPEGData { #[offset(0)] @@ -305,10 +304,9 @@ pub fn emplace_ref_self_read_13(values: Ptr>) -> Ptr { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(32)] pub struct Bytes { #[offset(0)] diff --git a/tests/unit/out/refcount/rvalue_rule_arg_move.rs b/tests/unit/out/refcount/rvalue_rule_arg_move.rs index 95ab2ebc6a..266a6f3e7a 100644 --- a/tests/unit/out/refcount/rvalue_rule_arg_move.rs +++ b/tests/unit/out/refcount/rvalue_rule_arg_move.rs @@ -21,11 +21,10 @@ thread_local!( CppFrom, Destructible, Memberwise, - MoveAssignable, Swappable, Default, )] -#[memberwise(copy_assign)] +#[memberwise(copy_assign, move_assign)] #[cpp_from(i32, construct, value)] #[byte_size(4)] pub struct Elem { diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index 4f9064077d..bef796ab38 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -120,11 +120,10 @@ pub fn operator_lt_3(a: Ptr, b: Ptr) -> bool { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct Bag { #[offset(0)] diff --git a/tests/unit/out/refcount/structured_binding_move_ctor.rs b/tests/unit/out/refcount/structured_binding_move_ctor.rs index 202d1e2cb4..67d7d68b52 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -68,11 +68,10 @@ impl Clone for Movable { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(48)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 17c0917f34..a864490df5 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -168,10 +168,11 @@ impl Clone for CopyOnly { FnPtrArg, Destructible, Memberwise, - Movable, + MoveConstructible, + Swappable, Default, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, copy_assign, move_assign)] #[byte_size(8)] pub struct CopyOnlyPair { #[offset(0)] diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index cd9d56785e..9038daf9e3 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -16,11 +16,10 @@ use std::rc::{Rc, Weak}; Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct Inner { #[offset(0)] @@ -37,10 +36,9 @@ pub struct Inner { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(56)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index 29ce21332b..546c4836c2 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -16,11 +16,10 @@ use std::rc::{Rc, Weak}; Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index 1b908ed91d..3d2aaef51a 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -16,11 +16,10 @@ use std::rc::{Rc, Weak}; Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct Inner { #[offset(0)] @@ -37,11 +36,10 @@ pub struct Inner { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(48)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index ecf4510a25..ffcc92c198 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -26,11 +26,10 @@ pub struct Outer_RunInfo { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 2339640e96..b3e7b67336 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -25,11 +25,10 @@ pub fn copy_0(mut copy_vector: Vec) {} Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(48)] pub struct Foo { #[offset(0)] diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index b7ffae56bc..37fa62975d 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -26,11 +26,10 @@ pub struct Point { Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(48)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 6d4cfd5995..26f97d52a8 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -17,11 +17,10 @@ pub fn unused_param_0(mut x: i32) {} Destructible, Memberwise, CopyConstructible, - CopyAssignable, Swappable, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] #[byte_size(24)] pub struct NonTrivial { #[offset(0)] diff --git a/tests/unit/out/unsafe/array_of_noncopy_struct.rs b/tests/unit/out/unsafe/array_of_noncopy_struct.rs index b2d67f6bb6..8639525a23 100644 --- a/tests/unit/out/unsafe/array_of_noncopy_struct.rs +++ b/tests/unit/out/unsafe/array_of_noncopy_struct.rs @@ -15,10 +15,9 @@ use std::rc::Rc; DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct NonCopy { pub data: Vec, pub tag: i32, diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 128874e05c..b8ee840454 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -2006,11 +2006,10 @@ pub unsafe fn test_stable_containers_58() { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Counts_59 { pub counts: Vec, } diff --git a/tests/unit/out/unsafe/cast.rs b/tests/unit/out/unsafe/cast.rs index 3d531690a9..1f50aaa85e 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -43,11 +43,10 @@ pub struct Grid { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Bag { pub n: i32, pub items: Vec, diff --git a/tests/unit/out/unsafe/class_templates.rs b/tests/unit/out/unsafe/class_templates.rs index 22557ec64c..e8129a85c2 100644 --- a/tests/unit/out/unsafe/class_templates.rs +++ b/tests/unit/out/unsafe/class_templates.rs @@ -15,11 +15,10 @@ use std::rc::Rc; DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct MyContainer_int_ { vec_: Vec, } @@ -56,11 +55,10 @@ impl MyContainer_int_ { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct MyContainer_char_ { vec_: Vec, } @@ -97,11 +95,10 @@ impl MyContainer_char_ { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct MyContainer_float_ { vec_: Vec, } diff --git a/tests/unit/out/unsafe/constructor.rs b/tests/unit/out/unsafe/constructor.rs index 61f6b2f371..c26e7350dd 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -9,8 +9,17 @@ use std::rc::Rc; pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, )] +#[memberwise(copy_assign)] #[cpp_from(i32, construct, value)] pub struct S { pub v: i32, diff --git a/tests/unit/out/unsafe/container_field_addr.rs b/tests/unit/out/unsafe/container_field_addr.rs index 30cf3b8a18..366e060d2e 100644 --- a/tests/unit/out/unsafe/container_field_addr.rs +++ b/tests/unit/out/unsafe/container_field_addr.rs @@ -15,11 +15,10 @@ use std::rc::Rc; DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct S { pub tag: i32, pub v: Vec, diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 092d68e577..2b5b3bdd0c 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -119,10 +119,11 @@ impl Default for RefQualified { ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, - MovableUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, Default, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, copy_assign, move_assign)] pub struct Holder { pub p: Partial, pub arr: [Partial; 2], @@ -172,10 +173,11 @@ impl Clone for CopyCounted { ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, - MovableUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, Default, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, move_assign, copy_assign)] pub struct HasCopyCounted { pub c: CopyCounted, pub arr: [CopyCounted; 2], diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 128aa8d931..f5e2d0c867 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -132,10 +132,11 @@ impl Clone for Ignored { ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, - MovableUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, Default, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, move_assign, copy_assign)] pub struct Holder { pub c: Counted, pub arr: [Counted; 2], diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 3c6962454d..3addbd8a8d 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -15,8 +15,18 @@ pub struct Inner { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, + Default, )] +#[memberwise(copy_assign, move_assign)] #[cpp_from(i32, construct, value)] pub struct Explicit { pub v: i32, @@ -51,11 +61,12 @@ pub struct Implicit { ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, + MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] +#[memberwise(copy_assign)] #[cpp_from(i32, construct, value)] pub struct DefaultCopyUserMove { pub v: i32, @@ -174,11 +185,10 @@ pub struct Owner { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Copyable { pub data: Vec, } @@ -522,18 +532,20 @@ unsafe fn main_0() -> i32 { let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); - e = (b).clone(); - f = (c).clone(); + (unsafe { CopyAssignableUnsafe::copy_assign(&mut e, &b) }); + (unsafe { MoveAssignableUnsafe::move_assign(&mut f, &mut c) }); assert!((unsafe { same_0(&e, &b,) }) && (unsafe { same_0(&f, &c,) })); let mut g: Explicit = ::zero_init(); Explicit::construct(&mut g, { 4 }); let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); - g = { - e = (f).clone(); - (e).clone() - }; + (unsafe { + CopyAssignableUnsafe::copy_assign( + &mut g, + &(*(unsafe { CopyAssignableUnsafe::copy_assign(&mut e, &f) })), + ) + }); assert!((unsafe { same_0(&g, &f,) }) && (unsafe { same_0(&e, &f,) })); let mut i: Implicit = Implicit { v: 5, @@ -575,7 +587,7 @@ unsafe fn main_0() -> i32 { DefaultCopyUserMove::construct(&mut m3, { 1 }); let mut m4: DefaultCopyUserMove = ::zero_init(); DefaultCopyUserMove::construct(&mut m4, { 1 }); - m3 = m1; + (unsafe { CopyAssignableUnsafe::copy_assign(&mut m3, &m1) }); (unsafe { MoveAssignableUnsafe::move_assign(&mut m4, &mut m1) }); assert!((((m3.v) == (7)) && ((m4.v) == (7))) && ((m1.v) == (0))); let mut u: UserCopyDefaultMove = ::zero_init(); diff --git a/tests/unit/out/unsafe/delete_array_order.rs b/tests/unit/out/unsafe/delete_array_order.rs index 6b2da5ceed..c2ab8fcfbf 100644 --- a/tests/unit/out/unsafe/delete_array_order.rs +++ b/tests/unit/out/unsafe/delete_array_order.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct Element { pub id: i64, pub value: i64, diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index 1e032cc6fb..15b5d3977c 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -8,7 +8,17 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct S {} impl DestructibleUnsafe for S { unsafe fn destroy(&mut self) { @@ -17,38 +27,87 @@ impl DestructibleUnsafe for S { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, )] +#[memberwise(copy_assign)] pub struct Defaulted { #[destroy] pub s: S, } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, + Default, )] +#[memberwise(move_assign, copy_assign)] pub struct Middle { #[destroy] pub s: S, } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, + Default, )] +#[memberwise(copy_assign, move_assign)] pub struct Outer { #[destroy] pub m: Middle, } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, + Default, )] +#[memberwise(move_assign, copy_assign)] pub struct ArrayMember { #[destroy] pub items: [S; 3], } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct EmptyBody { pub s: S, } @@ -58,7 +117,17 @@ impl DestructibleUnsafe for EmptyBody { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct Templated_char_ { pub v: libc::c_char, } @@ -70,7 +139,17 @@ impl DestructibleUnsafe for Templated_char_ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct Templated_int_ { pub v: i32, } @@ -82,7 +161,17 @@ impl DestructibleUnsafe for Templated_int_ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct Copied { pub v: i32, } @@ -95,7 +184,17 @@ pub static mut order_1: std::cell::LazyCell<[i32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_i32; 3] }); pub static mut order_count_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct Tagged { pub tag: i32, } @@ -108,8 +207,18 @@ impl DestructibleUnsafe for Tagged { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, + Default, )] +#[memberwise(move_assign, copy_assign)] pub struct Ordered { #[destroy] pub first: Tagged, diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index 59984412c7..871d406641 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -9,7 +9,17 @@ use std::rc::Rc; pub static mut destroyed_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct S { pub v: i32, } diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index 452e29db99..e9957badc9 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -9,7 +9,17 @@ use std::rc::Rc; pub static mut destroyed_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct S { pub v: i32, } @@ -26,8 +36,18 @@ impl DestructibleUnsafe for S { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, Default, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, + Default, )] +#[memberwise(move_assign, copy_assign)] pub struct Outer { #[destroy] pub inner: S, @@ -175,11 +195,11 @@ unsafe fn main_0() -> i32 { let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); - s = { - let mut __v: S = ::zero_init(); - (unsafe { make_2(&mut __v, 13) }); - __v - }; + (unsafe { + let mut _arg0: S = ::zero_init(); + (unsafe { make_2(&mut _arg0, 13) }); + CopyAssignableUnsafe::copy_assign(&mut s, &mut _arg0) + }); assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) == (13))) diff --git a/tests/unit/out/unsafe/field_method_receiver.rs b/tests/unit/out/unsafe/field_method_receiver.rs index 16651f982b..b09f1527c6 100644 --- a/tests/unit/out/unsafe/field_method_receiver.rs +++ b/tests/unit/out/unsafe/field_method_receiver.rs @@ -37,11 +37,10 @@ impl Counter { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct S { pub tag: i32, pub c: Counter, diff --git a/tests/unit/out/unsafe/field_pointers.rs b/tests/unit/out/unsafe/field_pointers.rs index 996ddddf87..df6ff0c4d5 100644 --- a/tests/unit/out/unsafe/field_pointers.rs +++ b/tests/unit/out/unsafe/field_pointers.rs @@ -31,11 +31,10 @@ pub struct Header { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Outer { pub x: i32, pub inner: Inner, diff --git a/tests/unit/out/unsafe/for_body_destructor.rs b/tests/unit/out/unsafe/for_body_destructor.rs index 37f709250a..6d98c6f0fb 100644 --- a/tests/unit/out/unsafe/for_body_destructor.rs +++ b/tests/unit/out/unsafe/for_body_destructor.rs @@ -7,7 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe, Default)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, + Default, +)] +#[memberwise(copy_assign)] pub struct Guard { pub digit: i32, } diff --git a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs index fc5e9aba10..eee6559f8c 100644 --- a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs @@ -15,11 +15,10 @@ use std::rc::Rc; DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct S { pub v: Vec, pub a: i32, diff --git a/tests/unit/out/unsafe/implicit_autoref.rs b/tests/unit/out/unsafe/implicit_autoref.rs index 00b439aab8..077bb0b899 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -15,11 +15,10 @@ use std::rc::Rc; DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Holder { pub v: Vec, } diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index 3e649b697d..a574455fe6 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -15,11 +15,10 @@ use std::rc::Rc; DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Elem { pub id: i32, pub hist: [i32; 4], @@ -34,10 +33,9 @@ pub struct Elem { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct State { pub count: i32, pub grid: [[i32; 3]; 2], diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index 8ec874e2eb..a272565864 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -7,7 +7,16 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, CopyableUnsafe)] +#[derive( + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + MemberwiseUnsafe, + CopyConstructibleUnsafe, + MovableUnsafe, +)] +#[memberwise(copy_assign)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { pub f: FnPtr, } diff --git a/tests/unit/out/unsafe/libc_struct_without_default.rs b/tests/unit/out/unsafe/libc_struct_without_default.rs index 739788ab15..aca94964ca 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -15,10 +15,9 @@ use std::rc::Rc; DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct UserDefined { pub a: [i32; 1], pub v: Vec, diff --git a/tests/unit/out/unsafe/push_emplace_back.rs b/tests/unit/out/unsafe/push_emplace_back.rs index b84b317a8e..a641089e2b 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -30,11 +30,10 @@ pub struct Writer { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct JPEGData { pub com_data: Vec>, pub app_data: Vec>, @@ -219,11 +218,10 @@ pub unsafe fn emplace_ref_self_read_13(values: *mut Vec) -> *mut i64 { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Bytes { pub v: Vec>, pub b: [u8; 3], diff --git a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs index 005e072d32..bfb0002d1d 100644 --- a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs +++ b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs @@ -16,11 +16,10 @@ pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u CppFromUnsafe, DestructibleUnsafe, MemberwiseUnsafe, - MoveAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(copy_assign)] +#[memberwise(copy_assign, move_assign)] #[cpp_from(i32, construct, value)] pub struct Elem { pub v: i32, diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index 6070b03e18..23aa4f3ae7 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -159,11 +159,10 @@ pub unsafe fn operator_lt_3(a: *const MoveOnly, b: *const MoveOnly) -> bool { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Bag { pub items: Vec, } diff --git a/tests/unit/out/unsafe/structured_binding_move_ctor.rs b/tests/unit/out/unsafe/structured_binding_move_ctor.rs index 6bca08362f..e771405876 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -63,11 +63,10 @@ impl Clone for Movable { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Holder { pub xs: Vec, pub ys: Vec, diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index 2fe289e319..3e364975ed 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -155,10 +155,11 @@ impl Clone for CopyOnly { ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, - MovableUnsafe, + MoveConstructibleUnsafe, + SwappableUnsafe, Default, )] -#[memberwise(copy_constructor, copy_assign)] +#[memberwise(copy_constructor, copy_assign, move_assign)] pub struct CopyOnlyPair { #[destroy] pub x: CopyOnly, diff --git a/tests/unit/out/unsafe/temporary_field_addr.rs b/tests/unit/out/unsafe/temporary_field_addr.rs index 9f30c6f180..7f21ff56bf 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -15,11 +15,10 @@ use std::rc::Rc; DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Inner { pub values: Vec, } @@ -32,11 +31,10 @@ pub struct Inner { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Outer { pub values: Vec, pub inner: Inner, diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index f57417869f..6f6520eed7 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -15,11 +15,10 @@ use std::rc::Rc; DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Outer { pub values: Vec, } diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index 35f4e247d7..e2abfbf781 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -15,11 +15,10 @@ use std::rc::Rc; DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Inner { pub values: Vec, } @@ -32,11 +31,10 @@ pub struct Inner { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Outer { pub values: Vec, pub inner: Inner, diff --git a/tests/unit/out/unsafe/typedef-anon-struct.rs b/tests/unit/out/unsafe/typedef-anon-struct.rs index 4a65e1aa98..fc3bf233d1 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -23,11 +23,10 @@ pub struct Outer_RunInfo { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Outer { pub runs: Vec, } diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index 79535b6d5f..9a18bc7161 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -23,11 +23,10 @@ pub unsafe fn copy_0(mut copy_vector: Vec) {} DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Foo { pub a: Vec, pub b: Vec, diff --git a/tests/unit/out/unsafe/vector_subscript_direct.rs b/tests/unit/out/unsafe/vector_subscript_direct.rs index 0061870b81..19e48705ef 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.rs @@ -28,11 +28,10 @@ impl Point { DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct Holder { pub values: Vec, pub points: Vec, diff --git a/tests/unit/out/unsafe/void_cast.rs b/tests/unit/out/unsafe/void_cast.rs index b03fefe8a2..4851a690fa 100644 --- a/tests/unit/out/unsafe/void_cast.rs +++ b/tests/unit/out/unsafe/void_cast.rs @@ -16,11 +16,10 @@ pub unsafe fn unused_param_0(mut x: i32) {} DestructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, - CopyAssignableUnsafe, SwappableUnsafe, Default, )] -#[memberwise(move_constructor, move_assign)] +#[memberwise(move_constructor, copy_assign, move_assign)] pub struct NonTrivial { pub data: Vec, } From aa9758e2f8f42b883f576ee51d3885738bd473f1 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 2 Dec 2026 10:38:02 +0000 Subject: [PATCH 08/12] Emit memberwise special members for implicit special members --- cpp2rust/converter/converter_lib.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 396f88a2b3..260006725e 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -858,7 +858,8 @@ 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 !HasDefaultedCopyAssignment(decl) || HasFieldWithMoveAssign(decl); + return !decl->isTriviallyCopyable() || !HasDefaultedCopyAssignment(decl) || + HasFieldWithMoveAssign(decl); } bool IsConvertibleMoveAssignment(const clang::CXXMethodDecl *method) { @@ -911,7 +912,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 GetUserDefinedCopyConstructor(decl) || + return !decl->isTriviallyCopyable() || GetUserDefinedCopyConstructor(decl) || llvm::any_of(decl->fields(), [](const clang::FieldDecl *field) { auto *record = field->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl(); From 176377cb89345541dcbb7083703746c8a685b205 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 2 Dec 2026 10:51:03 +0000 Subject: [PATCH 09/12] Call move by copy instead of move by clone --- cpp2rust/converter/converter.cpp | 6 ++++ libcc2rs-macros/src/constructor.rs | 32 +++++++++++++++---- tests/std/basic/out/refcount/basic.def.odr.rs | 18 ++++++----- tests/std/basic/out/unsafe/basic.def.odr.rs | 16 +++++----- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index b58617e23c..e76aab4077 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5843,6 +5843,12 @@ void Converter::AddCopyAndMoveDerives(const clang::RecordDecl *decl, if (!writes_move) { if (copies) { derive(kMovable, {&kMoveConstructible, &kMoveAssignable, &kSwappable}); + return; + } + for (size_t i = 0; i < std::size(copy); ++i) { + if (implements(copy[i])) { + derive(*move[i], {move[i]}); + } } return; } diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index 4b58297dca..f2d1f9ea95 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -78,13 +78,29 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - } else { format_ident!("{}_constructor", op) }; + let copy_trait = format_ident!( + "Copy{}{}", + if is_assign { + "Assignable" + } else { + "Constructible" + }, + if is_unsafe { "Unsafe" } else { "" } + ); + let copy_method = if is_assign { + format_ident!("copy_assign") + } else { + format_ident!("copy_constructor") + }; if is_unsafe { let src_ty = if is_move { quote!(*mut Self) } else { quote!(*const Self) }; - let body = if is_assign { + let body = if is_move { + quote!(unsafe { ::libcc2rs::#copy_trait::#copy_method(self, src) }) + } else if is_assign { quote! { unsafe { *self = (*src).clone() }; self @@ -110,16 +126,20 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - } else { quote!() }; - let tail = if is_assign { - quote!(this.clone()) + let body = if is_move { + quote!(::libcc2rs::#copy_trait::#copy_method(this, src)) + } else if is_assign { + quote! { + this.write(src.with(Self::clone)); + this.clone() + } } else { - quote!() + quote!(this.write(src.with(Self::clone));) }; quote! { impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause { fn #method(this: &::libcc2rs::Ptr, src: ::libcc2rs::Ptr) #ret { - this.write(src.with(Self::clone)); - #tail + #body } } } diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 97c581a634..ab4ef21e25 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -661,7 +661,16 @@ pub fn test_28() { thread_local!( pub static ctor_calls_29: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + Destructible, + Memberwise, + MoveConstructible, + MoveAssignable, +)] #[memberwise(copy_assign)] #[byte_size(4)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { @@ -909,13 +918,6 @@ impl CopyConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { ) } } -impl MoveConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn move_constructor(_: &Ptr, _: Ptr) { - unreachable!( - "p9_unused_copy_constructor_HasUndefinedCopyCtor::move_constructor is never defined" - ) - } -} impl CopyAssignable for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { fn copy_assign(_: &Ptr, _: Ptr) -> Ptr { unreachable!( diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 8fb80b6a5b..b244e81774 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -636,7 +636,14 @@ pub unsafe fn test_28() { pub static mut ctor_calls_29: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe)] +#[derive( + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + MemberwiseUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, +)] #[memberwise(copy_assign)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, @@ -863,13 +870,6 @@ impl CopyConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor ) } } -impl MoveConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn move_constructor(&mut self, _: *mut Self) { - unreachable!( - "p9_unused_copy_constructor_HasUndefinedCopyCtor::move_constructor is never defined" - ) - } -} impl CopyAssignableUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self { unreachable!( From 05ab20f198c5c96f47b2773900b1d43f86a38105 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 2 Dec 2026 11:20:27 +0000 Subject: [PATCH 10/12] Update tests --- tests/unit/out/refcount/copy_ctor.rs | 12 ++-- tests/unit/out/refcount/destructor_params.rs | 59 +++++++++++++------- tests/unit/out/refcount/fn_ptr_struct.rs | 17 +++--- tests/unit/out/refcount/forward_explicit.rs | 21 +++---- tests/unit/out/refcount/move_ctor.rs | 20 +++---- tests/unit/out/refcount/move_this.rs | 16 +++--- tests/unit/out/unsafe/copy_ctor.rs | 12 ++-- tests/unit/out/unsafe/destructor_params.rs | 49 +++++++++++----- tests/unit/out/unsafe/fn_ptr_struct.rs | 14 ++--- tests/unit/out/unsafe/forward_explicit.rs | 20 +++---- tests/unit/out/unsafe/move_ctor.rs | 20 +++---- tests/unit/out/unsafe/move_this.rs | 16 +++--- 12 files changed, 145 insertions(+), 131 deletions(-) diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 474c83257c..3b3cc54a8b 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -280,8 +280,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())); @@ -308,11 +308,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 a6a970b680..af2d2757a0 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -36,14 +36,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, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Default, @@ -62,26 +60,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) ); @@ -90,17 +113,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 6002dc10e4..e7f43423bb 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -56,9 +56,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() { @@ -94,15 +93,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 b26735659d..99d4965991 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 12cd305b33..d944940381 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -136,8 +136,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())); @@ -169,20 +169,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 b6a984a28a..72ac3a5eb1 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 f5e2d0c867..ad2d60b8a8 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -265,8 +265,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(); @@ -293,11 +293,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 871d406641..99236f9bd5 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -29,12 +29,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( @@ -44,11 +44,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() { @@ -63,7 +63,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)) @@ -71,13 +76,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)) @@ -85,12 +100,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 5caba87dc5..f3fc44b020 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -60,8 +60,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() { @@ -99,14 +99,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 819ff4cbb9..aee0616a48 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 1b424b4893..acf6d9a91d 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -148,8 +148,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(); @@ -183,20 +183,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 4a4d682523..7d23e75676 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(); From f0bd6a23b4632f29294e9b8b16741bdad7254504 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 2 Dec 2026 11:24:39 +0000 Subject: [PATCH 11/12] Build the storage of args in the caller --- cpp2rust/converter/converter.cpp | 20 +++++++++++++------ cpp2rust/converter/converter_lib.cpp | 14 ++++++++++++- cpp2rust/converter/converter_lib.h | 5 +++++ cpp2rust/converter/models/boxed_vars.cpp | 2 +- .../converter/models/converter_refcount.cpp | 2 +- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index e76aab4077..a17a4383e5 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -335,8 +335,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; @@ -406,7 +407,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()) { @@ -617,7 +618,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); @@ -2462,7 +2463,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; @@ -4656,7 +4659,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 260006725e..d08a7a71af 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -1882,11 +1882,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 6213a38288..af56af4e7b 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -353,6 +353,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 4e339e06a7..78c87eeee4 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); From 619b3aeda8161fed1b091cd7484a7ddbc939d997 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 2 Dec 2026 11:26:22 +0000 Subject: [PATCH 12/12] Check canBePassedInReg instead of triviallyCopyable --- cpp2rust/converter/converter_lib.cpp | 6 +++--- tests/std/basic/out/refcount/basic.def.odr.rs | 6 +----- tests/std/basic/out/unsafe/basic.def.odr.rs | 6 +----- .../out/refcount/operator_comparison_nonbool.rs | 13 ++++++++++++- .../unit/out/unsafe/operator_comparison_nonbool.rs | 11 ++++++++++- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index d08a7a71af..9ebbd345a1 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -858,7 +858,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); } @@ -912,7 +912,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(); @@ -1073,7 +1073,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) { diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index ab4ef21e25..77ea8308fb 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -743,13 +743,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 b244e81774..c908c1173a 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -714,13 +714,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/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 0327803602..473c589296 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -132,7 +132,18 @@ pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + CppFrom, + Destructible, + Memberwise, + MoveAssignable, + Default, +)] +#[memberwise(copy_assign)] #[cpp_into(bool, to_bool)] #[byte_size(1)] pub struct RefBool { diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index 2545422fb7..0110c5a232 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -200,7 +200,16 @@ pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { }; } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] +#[derive( + FnPtrArg, + ZeroInitializationUnsafe, + CppFromUnsafe, + DestructibleUnsafe, + MemberwiseUnsafe, + MoveAssignableUnsafe, + Default, +)] +#[memberwise(copy_assign)] #[cpp_into(bool, to_bool)] pub struct RefBool { pub value: bool,