From b3ac62c1ddae4c6fd38b2d4ba4ccffddcc384015 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 17:43:06 +0000 Subject: [PATCH 01/11] Update tests --- .../out/refcount/defaulted_move_cross_tu.rs | 8 +- .../out/unsafe/defaulted_move_cross_tu.rs | 8 +- .../refcount/out_of_line_methods_cross_tu.rs | 10 +- .../unsafe/out_of_line_methods_cross_tu.rs | 10 +- .../out/refcount/p14-class-in-two-files.rs | 3 +- .../out/unsafe/p14-class-in-two-files.rs | 3 +- .../p15-class-template-static-member.rs | 3 +- .../p15-class-template-static-member.rs | 3 +- .../out/refcount/p15-function-template.rs | 3 +- .../out/unsafe/p15-function-template.rs | 3 +- .../out/refcount/p15-inline-function.rs | 3 +- .../out/unsafe/p15-inline-function.rs | 3 +- .../out/refcount/p15-inline-variable.rs | 3 +- .../out/unsafe/p15-inline-variable.rs | 3 +- .../p16-default-argument-lambda-in-class.rs | 3 +- .../p16-default-argument-lambda-in-class.rs | 3 +- .../refcount/p16-lambda-in-inline-function.rs | 3 +- .../unsafe/p16-lambda-in-inline-function.rs | 3 +- .../out/refcount/basic.scope.block.rs | 3 +- .../out/unsafe/basic.scope.block.rs | 3 +- tests/std/basic/out/refcount/basic.def.odr.rs | 13 +- tests/std/basic/out/unsafe/basic.def.odr.rs | 13 +- .../out/refcount/class.copy.ctor.rs | 2 +- .../class.ctor/out/unsafe/class.copy.ctor.rs | 2 +- .../dcl.init.ref-p5-cv-qualification.cpp | 45 ++++++ .../dcl.decl/dcl.init/dcl.init.ref.cpp | 92 ++++++++++++ .../dcl.init.ref-p5-cv-qualification.rs | 52 +++++++ .../dcl.init/out/refcount/dcl.init.ref.rs | 115 ++++++++++++++ .../dcl.init.ref-p5-cv-qualification.rs | 54 +++++++ .../dcl.init/out/unsafe/dcl.init.ref.rs | 110 ++++++++++++++ .../dcl.dcl/dcl.decl/dcl.meaning/dcl.ref.cpp | 92 ++++++++++++ .../dcl.meaning/out/refcount/dcl.ref.rs | 79 ++++++++++ .../dcl.meaning/out/unsafe/dcl.ref.rs | 81 ++++++++++ .../out/refcount/expr.mptr.oper.rs | 8 +- .../out/unsafe/expr.mptr.oper.rs | 8 +- .../stmt.select/out/refcount/stmt.if.rs | 3 +- .../stmt.select/out/refcount/stmt.switch.rs | 3 +- .../stmt.select/out/unsafe/stmt.if.rs | 3 +- .../stmt.select/out/unsafe/stmt.switch.rs | 3 +- .../pairs/out/refcount/pairs.pair.rs | 140 +++++++++++++++++- .../utilities/pairs/out/unsafe/pairs.pair.rs | 92 +++++++++++- tests/std/utilities/pairs/pairs.pair.cpp | 107 +++++++++++++ .../utility/out/refcount/forward-helpers.rs | 45 ++++-- .../utilities/utility/out/refcount/forward.rs | 9 +- .../utility/out/unsafe/forward-helpers.rs | 54 +++++-- .../utilities/utility/out/unsafe/forward.rs | 9 +- tests/unit/out/refcount/copy_assign.rs | 37 +++-- tests/unit/out/refcount/copy_ctor.rs | 26 ++-- .../unit/out/refcount/copy_move_defaulted.rs | 96 +++++++----- tests/unit/out/refcount/copy_move_deleted.rs | 28 ++-- tests/unit/out/refcount/fn_ptr_struct.rs | 5 +- tests/unit/out/refcount/forward_basic.rs | 8 +- tests/unit/out/refcount/forward_decltype.rs | 6 +- tests/unit/out/refcount/forward_explicit.rs | 10 +- tests/unit/out/refcount/forward_pack.rs | 8 +- .../out/refcount/inline_container_fields.rs | 24 +-- tests/unit/out/refcount/lambda_as_field.rs | 8 +- .../out/refcount/lambda_capture_copy_ctor.rs | 14 +- .../out/refcount/lambda_move_only_capture.rs | 10 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 6 +- tests/unit/out/refcount/map_try_emplace.rs | 14 +- tests/unit/out/refcount/max.rs | 3 +- tests/unit/out/refcount/move_assign.rs | 22 +-- tests/unit/out/refcount/move_ctor.rs | 29 ++-- tests/unit/out/refcount/move_this.rs | 12 +- tests/unit/out/refcount/pair.rs | 8 +- tests/unit/out/refcount/rule_of_five.rs | 20 ++- tests/unit/out/refcount/rule_of_three.rs | 6 +- .../unit/out/refcount/rvalue_rule_arg_move.rs | 8 +- tests/unit/out/refcount/size_t_ssize_t.rs | 4 +- tests/unit/out/refcount/sort_no_copy.rs | 12 +- .../refcount/structured_binding_copy_ctor.rs | 3 +- .../structured_binding_element_ctor.rs | 18 ++- .../refcount/structured_binding_move_ctor.rs | 8 +- tests/unit/out/refcount/swap_map_no_copy.rs | 40 +++-- tests/unit/out/unsafe/copy_assign.rs | 37 +++-- tests/unit/out/unsafe/copy_ctor.rs | 26 ++-- tests/unit/out/unsafe/copy_move_defaulted.rs | 105 ++++++++----- tests/unit/out/unsafe/copy_move_deleted.rs | 28 ++-- tests/unit/out/unsafe/fn_ptr_struct.rs | 5 +- tests/unit/out/unsafe/forward_basic.rs | 8 +- tests/unit/out/unsafe/forward_decltype.rs | 6 +- tests/unit/out/unsafe/forward_explicit.rs | 10 +- tests/unit/out/unsafe/forward_pack.rs | 8 +- .../out/unsafe/inline_container_fields.rs | 20 ++- tests/unit/out/unsafe/lambda_as_field.rs | 8 +- .../out/unsafe/lambda_capture_copy_ctor.rs | 14 +- .../out/unsafe/lambda_move_only_capture.rs | 7 +- tests/unit/out/unsafe/map_key_copy_ctor.rs | 6 +- tests/unit/out/unsafe/map_try_emplace.rs | 14 +- tests/unit/out/unsafe/max.rs | 3 +- tests/unit/out/unsafe/move_assign.rs | 22 +-- tests/unit/out/unsafe/move_ctor.rs | 29 ++-- tests/unit/out/unsafe/move_this.rs | 20 ++- tests/unit/out/unsafe/pair.rs | 8 +- tests/unit/out/unsafe/rule_of_five.rs | 20 ++- tests/unit/out/unsafe/rule_of_three.rs | 6 +- tests/unit/out/unsafe/rvalue_rule_arg_move.rs | 6 +- tests/unit/out/unsafe/size_t_ssize_t.rs | 2 +- tests/unit/out/unsafe/sort_no_copy.rs | 12 +- .../unsafe/structured_binding_copy_ctor.rs | 3 +- .../unsafe/structured_binding_element_ctor.rs | 12 +- .../unsafe/structured_binding_move_ctor.rs | 8 +- tests/unit/out/unsafe/swap_map_no_copy.rs | 40 +++-- 104 files changed, 1843 insertions(+), 461 deletions(-) create mode 100644 tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref-p5-cv-qualification.cpp create mode 100644 tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref.cpp create mode 100644 tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref-p5-cv-qualification.rs create mode 100644 tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs create mode 100644 tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref-p5-cv-qualification.rs create mode 100644 tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs create mode 100644 tests/std/dcl.dcl/dcl.decl/dcl.meaning/dcl.ref.cpp create mode 100644 tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.ref.rs create mode 100644 tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.ref.rs diff --git a/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs index d5eb4a1c5f..d294eb6dd2 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 @@ -79,15 +79,15 @@ fn main_0() -> i32 { } pub fn shuffle_1(mut x: i32) -> i32 { object!(a, S(x)); - object!(b, S, Moved(a.as_pointer())); + object!(b, S, RvalueRef::bind(a.as_pointer())); assert!(({ (*a.borrow()).v.is_empty() })); object!(c, S(1)); - assign!(c = Moved(b)); + assign!(c = RvalueRef(b)); assert!(({ (*b.borrow()).v.is_empty() })); let t: Value = Rc::new(RefCell::new(T { v: Vec::from([1]) })); - object!(u, T, Moved(t.as_pointer())); + object!(u, T, RvalueRef::bind(t.as_pointer())); object!(w, T); - assign!(w = Moved(u)); + assign!(w = RvalueRef(u)); assert!( ((({ TImpl::size(&t.as_pointer(),) }) == 0) && (({ TImpl::size(&u.as_pointer(),) }) == 0)) && (({ TImpl::size(&w.as_pointer(),) }) == 1) diff --git a/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs index ec85bb481c..58f7a326b7 100644 --- a/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs +++ b/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs @@ -77,15 +77,15 @@ unsafe fn main_0() -> i32 { } pub unsafe fn shuffle_1(mut x: i32) -> i32 { object_unsafe!(a, S(x)); - object_unsafe!(b, S, Moved(&mut a)); + object_unsafe!(b, S, RvalueRefUnsafe::bind(&mut a)); assert!(a.v.is_empty()); object_unsafe!(c, S(1)); - assign_unsafe!(c = Moved(b)); + assign_unsafe!(c = RvalueRefUnsafe(b)); assert!(b.v.is_empty()); let mut t: T = T { v: Vec::from([1]) }; - object_unsafe!(u, T, Moved(&mut t)); + object_unsafe!(u, T, RvalueRefUnsafe::bind(&mut t)); object_unsafe!(w, T); - assign_unsafe!(w = Moved(u)); + assign_unsafe!(w = RvalueRefUnsafe(u)); assert!( (((unsafe { T::size(&t,) }) == (0)) && ((unsafe { T::size(&u,) }) == (0))) && ((unsafe { T::size(&w,) }) == (1)) diff --git a/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs b/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs index 3648091c45..9655a8a0c3 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 @@ -83,7 +83,7 @@ fn main_0() -> i32 { assert!((({ SImpl::get(&s.as_pointer(),) }) == 4)); assert!((({ SImpl::add(&s.as_pointer(), 2,) }) == 6)); object!(m, M(2)); - object!(n, M, Moved(m.as_pointer())); + object!(n, M, RvalueRef::bind(m.as_pointer())); assert!(({ (*n.borrow()).v } == 2)); object!(c, M, n.as_pointer()); assert!(({ (*c.borrow()).v } == 3)); @@ -100,12 +100,14 @@ fn main_0() -> i32 { return 0; } impl MoveConstructible for M { - fn move_constructor(this: &Ptr, _a0: Ptr) { + fn move_constructor(this: &Ptr, _a0: RvalueRef) { + let _a0 = _a0.as_pointer(); field!((*this), v).write({ (*_a0.upgrade().deref()).v }); } } impl CopyConstructible for M { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write((o.with(|__s| __s.v) + 1)); } } @@ -116,7 +118,7 @@ impl Destructible for S { impl M {} pub fn move_m_1(mut x: i32) -> i32 { object!(m, M(x)); - object!(n, M, Moved(m.as_pointer())); + object!(n, M, RvalueRef::bind(m.as_pointer())); return { (*n.borrow()).v }; } impl Derived {} diff --git a/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs b/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs index 5f7baa55a3..359ab857d3 100644 --- a/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs +++ b/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs @@ -81,7 +81,7 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { S::get(&s,) }) == (4))); assert!(((unsafe { S::add(&mut s, 2,) }) == (6))); object_unsafe!(m, M(2)); - object_unsafe!(n, M, Moved(&mut m)); + object_unsafe!(n, M, RvalueRefUnsafe::bind(&mut m)); assert!(((n.v) == (2))); object_unsafe!(c, M, &n); assert!(((c.v) == (3))); @@ -108,12 +108,14 @@ impl M { } } impl MoveConstructibleUnsafe for M { - unsafe fn move_constructor(&mut self, _a0: *mut M) { + unsafe fn move_constructor(&mut self, _a0: RvalueRefUnsafe) { + let _a0 = (_a0.as_ptr() as *mut M); (&raw mut self.v).write((*_a0).v); } } impl CopyConstructibleUnsafe for M { - unsafe fn copy_constructor(&mut self, o: *const M) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const M); (&raw mut self.v).write((((*o).v) + (1))); } } @@ -140,7 +142,7 @@ impl S { impl M {} pub unsafe fn move_m_1(mut x: i32) -> i32 { object_unsafe!(m, M(x)); - object_unsafe!(n, M, Moved(&mut m)); + object_unsafe!(n, M, RvalueRefUnsafe::bind(&mut m)); return n.v; } impl Derived {} diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index ab50e8b772..8f39664a18 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 @@ -61,7 +61,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index dd845ee0e4..d0ae84b6bf 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index d8b659e11f..240f936fac 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs @@ -61,7 +61,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index 8682ae7d9d..49bb41ee04 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index 074fbc99d8..2d248f9a0b 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 @@ -61,7 +61,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index 240049d3f0..4c6ad661cf 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs index 1ccf381543..e714671e8a 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 @@ -61,7 +61,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs index b89d4469b2..8de81f2055 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index 9985dcd727..08640764f2 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 @@ -61,7 +61,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index 8dc8692001..100cb9920b 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index cb38081e40..d2660015b3 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 @@ -61,7 +61,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs index ca65a2f79b..2d66db0898 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index 51594617c5..4558b47766 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 @@ -61,7 +61,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index 605541690b..9d037055d2 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs index 105c978f15..02d1469f89 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 @@ -61,7 +61,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs index fe6fa8f0ec..6164087fa1 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index c9407dca3a..351d7c57df 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -35,7 +35,8 @@ impl HasConstexprCtor { } } impl CopyConstructible for HasConstexprCtor { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), m).write(o.with(|__s| __s.m)); (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -95,7 +96,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -379,8 +381,9 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember { fn copy_constructor( this: &Ptr, - o: Ptr, + o: LvalueRef>, ) { + let o = o.as_pointer(); field!((*this), value).write(o.with(|__s| __s.value)); field!((*this), scratch).write(o.with(|__s| __s.scratch)); (*copies_18.with(Value::clone).borrow_mut()).prefix_inc(); @@ -827,14 +830,14 @@ impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestruct } } impl CopyConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn copy_constructor(this: &Ptr, _: Ptr) { + fn copy_constructor(this: &Ptr, _: LvalueRef>) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } impl CopyAssignable for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn copy_assign(this: &Ptr, _: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, _: LvalueRef>) -> Ptr { unreachable!( "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" ) diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 1dba12b2f0..9989b758cb 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -33,7 +33,8 @@ impl HasConstexprCtor { } } impl CopyConstructibleUnsafe for HasConstexprCtor { - unsafe fn copy_constructor(&mut self, o: *const HasConstexprCtor) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const HasConstexprCtor); (&raw mut self.m).write((*o).m); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); } @@ -80,7 +81,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)).prefix_inc(); } @@ -342,8 +344,9 @@ impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMember { unsafe fn copy_constructor( &mut self, - o: *const p5_2_mutable_subobject_is_odr_used_HasMutableMember, + o: LvalueRefUnsafe>, ) { + let o = (o.as_ptr() as *const p5_2_mutable_subobject_is_odr_used_HasMutableMember); (&raw mut self.value).write((*o).value); (&raw mut self.scratch).write((*o).scratch); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)).prefix_inc(); @@ -772,14 +775,14 @@ impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDe } } impl CopyConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn copy_constructor(&mut self, _: *const Self) { + unsafe fn copy_constructor(&mut self, _: LvalueRefUnsafe>) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } impl CopyAssignableUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self { + unsafe fn copy_assign(&mut self, _: LvalueRefUnsafe>) -> *mut Self { unreachable!( "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" ) diff --git a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs index ca0bfcf7da..08b9d4ad1e 100644 --- a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs @@ -32,7 +32,7 @@ pub fn pass_0( let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - ConstructFrom::construct_from(&__v.as_pointer(), Moved(object.as_pointer())); + ConstructFrom::construct_from(&__v.as_pointer(), RvalueRef::bind(object.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } diff --git a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs index 46f516516e..015e862a50 100644 --- a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs @@ -31,7 +31,7 @@ pub unsafe fn pass_0( return { let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut object)); + ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut object)); __v }; } diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref-p5-cv-qualification.cpp b/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref-p5-cv-qualification.cpp new file mode 100644 index 0000000000..845a473c26 --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref-p5-cv-qualification.cpp @@ -0,0 +1,45 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [dcl.init.ref]/5.1: a reference binds to an object that is less +// cv-qualified than the type it refers to, for const, volatile and both. +namespace p5_1_more_cv_qualified_reference { +void test() { + int x = 1; + const int &read_only = x; + volatile int &unstable = x; + const volatile int &read_only_unstable = x; + unstable = 2; + assert(read_only == 2); + assert(read_only_unstable == 2); + assert(&read_only == &x); + assert(&unstable == &x); + assert(&read_only_unstable == &x); +} +} // namespace p5_1_more_cv_qualified_reference + +// N4950 [dcl.init.ref]/5.1, [over.ics.rank]/3.2.6: of two references that +// bind, the one to the less cv-qualified type is chosen. +namespace p5_1_overloads_by_cv_qualification { +int which(int &) { return 1; } +int which(const int &) { return 2; } +int which(volatile int &) { return 3; } +int which(const volatile int &) { return 4; } + +void test() { + int plain = 0; + const int read_only = 0; + volatile int unstable = 0; + const volatile int read_only_unstable = 0; + assert(which(plain) == 1); + assert(which(read_only) == 2); + assert(which(unstable) == 3); + assert(which(read_only_unstable) == 4); +} +} // namespace p5_1_overloads_by_cv_qualification + +int main() { + p5_1_more_cv_qualified_reference::test(); + p5_1_overloads_by_cv_qualification::test(); + return 0; +} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref.cpp b/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref.cpp new file mode 100644 index 0000000000..f13961359d --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.ref.cpp @@ -0,0 +1,92 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include +#include + +// N4950 [dcl.init.ref]/5.1: an lvalue reference binds directly to an lvalue +// of a reference-compatible type, including one that is less cv-qualified. +namespace p5_1_lvalue_reference_to_lvalue { +void test() { + int x = 1; + int &plain = x; + const int &read_only = x; + plain = 2; + assert(read_only == 2); + assert(&read_only == &x); +} +} // namespace p5_1_lvalue_reference_to_lvalue + +// N4950 [dcl.init.ref]/5.3: a const lvalue reference and an rvalue reference +// bind to an rvalue, whose temporary lives as long as the reference. +namespace p5_3_reference_to_rvalue { +struct Counter { + int count; +}; + +Counter make(int count) { return Counter{count}; } + +void test() { + const Counter &kept = make(3); + Counter &&owned = make(4); + owned.count += 1; + assert(kept.count == 3); + assert(owned.count == 5); + + const int &number = 7; + int &&temporary = 8; + temporary += 1; + assert(number == 7); + assert(temporary == 9); +} +} // namespace p5_3_reference_to_rvalue + +// N4950 [dcl.init.ref]/5, [over.ics.rank]/3.2.3: an lvalue binds to T& rather +// than to const T&, and an rvalue to T&& rather than to const T&. +namespace p5_overloads_by_value_category { +int which(int &) { return 1; } +int which(const int &) { return 2; } +int which(int &&) { return 3; } + +void test() { + int x = 0; + const int y = 0; + assert(which(x) == 1); + assert(which(y) == 2); + assert(which(5) == 3); + assert(which(std::move(x)) == 3); +} +} // namespace p5_overloads_by_value_category + +// N4950 [dcl.init.ref]/5.4.4: an rvalue reference does not bind to an lvalue, +// so only the const lvalue reference overload takes one. +namespace p5_4_4_rvalue_reference_rejects_lvalue { +int which(const int &) { return 1; } +int which(int &&) { return 2; } + +void test() { + int x = 0; + assert(which(x) == 1); + assert(which(std::move(x)) == 2); + assert(which(3) == 2); +} +} // namespace p5_4_4_rvalue_reference_rejects_lvalue + +// N4950 [dcl.init.ref]/5.3: an xvalue binds to an rvalue reference without a +// copy, so the reference refers to the original object. +namespace p5_3_xvalue_binds_directly { +void test() { + int x = 1; + int &&moved = std::move(x); + moved = 6; + assert(x == 6); + assert(&moved == &x); +} +} // namespace p5_3_xvalue_binds_directly + +int main() { + p5_1_lvalue_reference_to_lvalue::test(); + p5_3_reference_to_rvalue::test(); + p5_overloads_by_value_category::test(); + p5_4_4_rvalue_reference_rejects_lvalue::test(); + p5_3_xvalue_binds_directly::test(); + return 0; +} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref-p5-cv-qualification.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref-p5-cv-qualification.rs new file mode 100644 index 0000000000..26d3030208 --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref-p5-cv-qualification.rs @@ -0,0 +1,52 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn test_0() { + let x: Value = Rc::new(RefCell::new(1)); + let read_only: Ptr = x.as_pointer(); + let unstable: Ptr = x.as_pointer(); + let read_only_unstable: Ptr = x.as_pointer(); + unstable.write(2); + assert!(((read_only.read()) == 2)); + assert!(((read_only_unstable.read()) == 2)); + assert!(({ (read_only).clone() } == { (x.as_pointer()) })); + assert!(({ (unstable).clone() } == { (x.as_pointer()) })); + assert!(({ (read_only_unstable).clone() } == { (x.as_pointer()) })); +} +pub fn which_1(_a0: Ptr) -> i32 { + return 1; +} +pub fn which_2(_a0: Ptr) -> i32 { + return 2; +} +pub fn which_3(_a0: Ptr) -> i32 { + return 3; +} +pub fn which_4(_a0: Ptr) -> i32 { + return 4; +} +pub fn test_5() { + let plain: Value = Rc::new(RefCell::new(0)); + let read_only: Value = Rc::new(RefCell::new(0)); + let unstable: Value = Rc::new(RefCell::new(0)); + let read_only_unstable: Value = Rc::new(RefCell::new(0)); + assert!((({ which_1(plain.as_pointer(),) }) == 1)); + assert!((({ which_2(read_only.as_pointer(),) }) == 2)); + assert!((({ which_3(unstable.as_pointer(),) }) == 3)); + assert!((({ which_4(read_only_unstable.as_pointer(),) }) == 4)); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_5() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs new file mode 100644 index 0000000000..a1876bad6b --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.ref.rs @@ -0,0 +1,115 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn test_0() { + let x: Value = Rc::new(RefCell::new(1)); + let plain: Ptr = x.as_pointer(); + let read_only: Ptr = x.as_pointer(); + plain.write(2); + assert!(((read_only.read()) == 2)); + assert!(({ (read_only).clone() } == { (x.as_pointer()) })); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, +)] +#[byte_size(4)] +pub struct p5_3_reference_to_rvalue_Counter { + #[offset(0)] + pub count: i32, +} +pub fn make_1(mut count: i32) -> p5_3_reference_to_rvalue_Counter { + return p5_3_reference_to_rvalue_Counter { count: count }; +} +pub fn test_2() { + let __tmp_0: Value = Rc::new(RefCell::new(({ make_1(3) }))); + let kept: Ptr = __tmp_0.as_pointer(); + let __tmp_1: Value = Rc::new(RefCell::new(({ make_1(4) }))); + let owned: Ptr = __tmp_1.as_pointer(); + { + field!(owned, count).with_mut(|__v| *__v = *__v + 1) + }; + assert!((kept.with(|__s| __s.count) == 3)); + assert!((owned.with(|__s| __s.count) == 5)); + let __tmp_2: Value = Rc::new(RefCell::new(7)); + let number: Ptr = __tmp_2.as_pointer(); + let __tmp_3: Value = Rc::new(RefCell::new(8)); + let temporary: Ptr = __tmp_3.as_pointer(); + { + temporary.with_mut(|__v| *__v = *__v + 1) + }; + assert!(((number.read()) == 7)); + assert!(((temporary.read()) == 9)); +} +pub fn which_3(_a0: Ptr) -> i32 { + return 1; +} +pub fn which_4(_a0: Ptr) -> i32 { + return 2; +} +pub fn which_5(_a0: Ptr) -> i32 { + return 3; +} +pub fn test_6() { + let x: Value = Rc::new(RefCell::new(0)); + let y: Value = Rc::new(RefCell::new(0)); + assert!((({ which_3(x.as_pointer(),) }) == 1)); + assert!((({ which_4(y.as_pointer(),) }) == 2)); + assert!( + (({ + let _arg0: Value = Rc::new(RefCell::new(5)); + which_5(_arg0.as_pointer()) + }) == 3) + ); + assert!((({ which_5(x.as_pointer(),) }) == 3)); +} +pub fn which_7(_a0: Ptr) -> i32 { + return 1; +} +pub fn which_8(_a0: Ptr) -> i32 { + return 2; +} +pub fn test_9() { + let x: Value = Rc::new(RefCell::new(0)); + assert!((({ which_7(x.as_pointer(),) }) == 1)); + assert!((({ which_8(x.as_pointer(),) }) == 2)); + assert!( + (({ + let _arg0: Value = Rc::new(RefCell::new(3)); + which_8(_arg0.as_pointer()) + }) == 2) + ); +} +pub fn test_10() { + let x: Value = Rc::new(RefCell::new(1)); + let moved: Ptr = x.as_pointer(); + moved.write(6); + assert!(({ ((*x.borrow()) == 6) })); + assert!(({ (moved).clone() } == { (x.as_pointer()) })); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_2() }); + ({ test_6() }); + ({ test_9() }); + ({ test_10() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref-p5-cv-qualification.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref-p5-cv-qualification.rs new file mode 100644 index 0000000000..bad1c17dfb --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref-p5-cv-qualification.rs @@ -0,0 +1,54 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub unsafe fn test_0() { + let mut x: i32 = 1; + let read_only: *const i32 = &x; + let unstable: *mut i32 = &mut x; + let read_only_unstable: *const i32 = &x; + (*unstable) = 2; + assert!(((*read_only) == (2))); + assert!(((*read_only_unstable) == (2))); + assert!(((read_only) == ((&mut x as *mut i32).cast_const()))); + assert!(((unstable) == (&mut x as *mut i32))); + assert!(((read_only_unstable) == ((&mut x as *mut i32).cast_const()))); +} +pub unsafe fn which_1(_a0: *mut i32) -> i32 { + return 1; +} +pub unsafe fn which_2(_a0: *const i32) -> i32 { + return 2; +} +pub unsafe fn which_3(_a0: *mut i32) -> i32 { + return 3; +} +pub unsafe fn which_4(_a0: *const i32) -> i32 { + return 4; +} +pub unsafe fn test_5() { + let mut plain: i32 = 0; + let read_only: i32 = 0; + let mut unstable: i32 = 0; + let read_only_unstable: i32 = 0; + assert!(((unsafe { which_1(&mut plain,) }) == (1))); + assert!(((unsafe { which_2(&read_only,) }) == (2))); + assert!(((unsafe { which_3(&mut unstable,) }) == (3))); + assert!(((unsafe { which_4(&read_only_unstable,) }) == (4))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_0() }); + (unsafe { test_5() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs new file mode 100644 index 0000000000..6ebabc94ac --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.ref.rs @@ -0,0 +1,110 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub unsafe fn test_0() { + let mut x: i32 = 1; + let plain: *mut i32 = &mut x; + let read_only: *const i32 = &x; + (*plain) = 2; + assert!(((*read_only) == (2))); + assert!(((read_only) == ((&mut x as *mut i32).cast_const()))); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, +)] +pub struct p5_3_reference_to_rvalue_Counter { + pub count: i32, +} +pub unsafe fn make_1(mut count: i32) -> p5_3_reference_to_rvalue_Counter { + return p5_3_reference_to_rvalue_Counter { count: count }; +} +pub unsafe fn test_2() { + let mut __tmp_0: p5_3_reference_to_rvalue_Counter = (unsafe { make_1(3) }); + let kept: *const p5_3_reference_to_rvalue_Counter = &mut __tmp_0; + let mut __tmp_1: p5_3_reference_to_rvalue_Counter = (unsafe { make_1(4) }); + let owned: *mut p5_3_reference_to_rvalue_Counter = &mut __tmp_1; + (*owned).count += 1; + assert!((((*kept).count) == (3))); + assert!((((*owned).count) == (5))); + let mut __tmp_2: i32 = 7; + let number: *const i32 = &mut __tmp_2; + let mut __tmp_3: i32 = 8; + let temporary: *mut i32 = &mut __tmp_3; + (*temporary) += 1; + assert!(((*number) == (7))); + assert!(((*temporary) == (9))); +} +pub unsafe fn which_3(_a0: *mut i32) -> i32 { + return 1; +} +pub unsafe fn which_4(_a0: *const i32) -> i32 { + return 2; +} +pub unsafe fn which_5(_a0: *mut i32) -> i32 { + return 3; +} +pub unsafe fn test_6() { + let mut x: i32 = 0; + let y: i32 = 0; + assert!(((unsafe { which_3(&mut x,) }) == (1))); + assert!(((unsafe { which_4(&y,) }) == (2))); + assert!( + ((unsafe { + let mut _arg0: i32 = 5; + which_5(&mut _arg0) + }) == (3)) + ); + assert!(((unsafe { which_5(&mut x,) }) == (3))); +} +pub unsafe fn which_7(_a0: *const i32) -> i32 { + return 1; +} +pub unsafe fn which_8(_a0: *mut i32) -> i32 { + return 2; +} +pub unsafe fn test_9() { + let mut x: i32 = 0; + assert!(((unsafe { which_7(&x,) }) == (1))); + assert!(((unsafe { which_8(&mut x,) }) == (2))); + assert!( + ((unsafe { + let mut _arg0: i32 = 3; + which_8(&mut _arg0) + }) == (2)) + ); +} +pub unsafe fn test_10() { + let mut x: i32 = 1; + let moved: *mut i32 = &mut x; + (*moved) = 6; + assert!(((x) == (6))); + assert!(((moved) == (&mut x as *mut i32))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_0() }); + (unsafe { test_2() }); + (unsafe { test_6() }); + (unsafe { test_9() }); + (unsafe { test_10() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/dcl.ref.cpp b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/dcl.ref.cpp new file mode 100644 index 0000000000..ae1ecbb6d9 --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/dcl.ref.cpp @@ -0,0 +1,92 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include +#include + +// N4950 [dcl.ref]/1: a reference is an alias of the object it is bound to: +// an assignment to it assigns to that object, and its address is the address +// of that object. +namespace p1_reference_is_an_alias { +void test() { + int x = 1; + int y = 2; + int &alias = x; + alias = y; + assert(x == 2); + assert(&alias == &x); + y = 9; + assert(alias == 2); +} +} // namespace p1_reference_is_an_alias + +// N4950 [dcl.ref]/1: a reference to a pointer is an alias of the pointer +// object, not of what it points to. +namespace p1_reference_to_pointer { +void test() { + int x = 1; + int y = 2; + int *pointer = &x; + int *&alias = pointer; + alias = &y; + assert(pointer == &y); + *alias = 7; + assert(y == 7); + assert(x == 1); +} +} // namespace p1_reference_to_pointer + +// N4950 [dcl.ref]/6: an lvalue reference to any reference type, and an rvalue +// reference to an lvalue reference type, is an lvalue reference. +namespace p6_reference_collapsing { +template void assign_through(T &&target, int value) { + target = value; +} + +template int &as_lvalue_reference(T &target) { return target; } + +using IntRef = int &; +using IntRvalueRef = int &&; + +void test() { + int x = 1; + assign_through(x, 5); + assert(x == 5); + + IntRef &lvalue_of_lvalue = x; + IntRef &&rvalue_of_lvalue = x; + IntRvalueRef &lvalue_of_rvalue = x; + lvalue_of_lvalue = 6; + assert(x == 6); + rvalue_of_lvalue = 7; + assert(x == 7); + lvalue_of_rvalue = 8; + assert(x == 8); + assert(&lvalue_of_lvalue == &x); + assert(&rvalue_of_lvalue == &x); + assert(&lvalue_of_rvalue == &x); + + as_lvalue_reference(x) = 9; + assert(x == 9); +} +} // namespace p6_reference_collapsing + +// N4950 [dcl.ref]/6: an rvalue reference to an rvalue reference type is an +// rvalue reference, and binds to an rvalue. +namespace p6_rvalue_of_rvalue_reference { +using IntRvalueRef = int &&; + +int take(IntRvalueRef &&value) { return value; } + +void test() { + int x = 4; + assert(take(std::move(x)) == 4); + assert(take(11) == 11); +} +} // namespace p6_rvalue_of_rvalue_reference + +int main() { + p1_reference_is_an_alias::test(); + p1_reference_to_pointer::test(); + p6_reference_collapsing::test(); + p6_rvalue_of_rvalue_reference::test(); + return 0; +} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.ref.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.ref.rs new file mode 100644 index 0000000000..3cb7dd77ef --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.ref.rs @@ -0,0 +1,79 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn test_0() { + let x: Value = Rc::new(RefCell::new(1)); + let mut y: i32 = 2; + let alias: Ptr = x.as_pointer(); + alias.write(y); + assert!(({ ((*x.borrow()) == 2) })); + assert!(({ (alias).clone() } == { (x.as_pointer()) })); + y = 9; + assert!(((alias.read()) == 2)); +} +pub fn test_1() { + let x: Value = Rc::new(RefCell::new(1)); + let y: Value = Rc::new(RefCell::new(2)); + let pointer: Value> = Rc::new(RefCell::new((x.as_pointer()))); + let alias: Ptr> = pointer.as_pointer(); + alias.write((y.as_pointer())); + assert!(({ ({ (*pointer.borrow()).clone() } == { (y.as_pointer()) }) })); + (alias.read()).write(7); + assert!(({ ((*y.borrow()) == 7) })); + assert!(({ ((*x.borrow()) == 1) })); +} +pub fn assign_through_2(target: Ptr, mut value: i32) { + target.write(value); +} +pub fn as_lvalue_reference_3(target: Ptr) -> Ptr { + return (target).clone(); +} +pub fn test_4() { + let x: Value = Rc::new(RefCell::new(1)); + ({ assign_through_2(x.as_pointer(), 5) }); + assert!(({ ((*x.borrow()) == 5) })); + let lvalue_of_lvalue: Ptr = x.as_pointer(); + let rvalue_of_lvalue: Ptr = x.as_pointer(); + let lvalue_of_rvalue: Ptr = x.as_pointer(); + lvalue_of_lvalue.write(6); + assert!(({ ((*x.borrow()) == 6) })); + rvalue_of_lvalue.write(7); + assert!(({ ((*x.borrow()) == 7) })); + lvalue_of_rvalue.write(8); + assert!(({ ((*x.borrow()) == 8) })); + assert!(({ (lvalue_of_lvalue).clone() } == { (x.as_pointer()) })); + assert!(({ (rvalue_of_lvalue).clone() } == { (x.as_pointer()) })); + assert!(({ (lvalue_of_rvalue).clone() } == { (x.as_pointer()) })); + ({ as_lvalue_reference_3(x.as_pointer()) }).write(9); + assert!(({ ((*x.borrow()) == 9) })); +} +pub fn take_5(value: Ptr) -> i32 { + return (value.read()); +} +pub fn test_6() { + let x: Value = Rc::new(RefCell::new(4)); + assert!((({ take_5(x.as_pointer(),) }) == 4)); + assert!( + (({ + let _value: Value = Rc::new(RefCell::new(11)); + take_5(_value.as_pointer()) + }) == 11) + ); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_1() }); + ({ test_4() }); + ({ test_6() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.ref.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.ref.rs new file mode 100644 index 0000000000..c3ea0d8acb --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.ref.rs @@ -0,0 +1,81 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub unsafe fn test_0() { + let mut x: i32 = 1; + let mut y: i32 = 2; + let alias: *mut i32 = &mut x; + (*alias) = y; + assert!(((x) == (2))); + assert!(((alias) == (&mut x as *mut i32))); + y = 9; + assert!(((*alias) == (2))); +} +pub unsafe fn test_1() { + let mut x: i32 = 1; + let mut y: i32 = 2; + let mut pointer: *mut i32 = (&mut x as *mut i32); + let alias: *mut *mut i32 = &mut pointer; + (*alias) = (&mut y as *mut i32); + assert!(((pointer) == (&mut y as *mut i32))); + (*(*alias)) = 7; + assert!(((y) == (7))); + assert!(((x) == (1))); +} +pub unsafe fn assign_through_2(target: *mut i32, mut value: i32) { + (*target) = value; +} +pub unsafe fn as_lvalue_reference_3(target: *mut i32) -> *mut i32 { + return target; +} +pub unsafe fn test_4() { + let mut x: i32 = 1; + (unsafe { assign_through_2(&mut x, 5) }); + assert!(((x) == (5))); + let lvalue_of_lvalue: *mut i32 = &mut x; + let rvalue_of_lvalue: *mut i32 = &mut x; + let lvalue_of_rvalue: *mut i32 = &mut x; + (*lvalue_of_lvalue) = 6; + assert!(((x) == (6))); + (*rvalue_of_lvalue) = 7; + assert!(((x) == (7))); + (*lvalue_of_rvalue) = 8; + assert!(((x) == (8))); + assert!(((lvalue_of_lvalue) == (&mut x as *mut i32))); + assert!(((rvalue_of_lvalue) == (&mut x as *mut i32))); + assert!(((lvalue_of_rvalue) == (&mut x as *mut i32))); + (*(unsafe { as_lvalue_reference_3(&mut x) })) = 9; + assert!(((x) == (9))); +} +pub unsafe fn take_5(value: *mut i32) -> i32 { + return (*value); +} +pub unsafe fn test_6() { + let mut x: i32 = 4; + assert!(((unsafe { take_5(&mut x,) }) == (4))); + assert!( + ((unsafe { + let mut _value: i32 = 11; + take_5(&mut _value) + }) == (11)) + ); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_0() }); + (unsafe { test_1() }); + (unsafe { test_4() }); + (unsafe { test_6() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs index b79799d018..d6aab29f0b 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs @@ -145,16 +145,18 @@ pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { fn copy_constructor( this: &Ptr, - _a0: Ptr, + _a0: LvalueRef>, ) { + let _a0 = _a0.as_pointer(); (*copyCount_9.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { fn move_constructor( this: &Ptr, - _a0: Ptr, + _a0: RvalueRef, ) { + let _a0 = _a0.as_pointer(); (*moveCount_10.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -191,7 +193,7 @@ pub fn test_11() { object!( from_xvalue, p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - Moved( + RvalueRef::bind( (holder.as_pointer()) .member::(pm) ) diff --git a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs index ec45af9fb2..7d21f723db 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs @@ -132,16 +132,18 @@ pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} impl CopyConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { unsafe fn copy_constructor( &mut self, - _a0: *const p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, + _a0: LvalueRefUnsafe>, ) { + let _a0 = (_a0.as_ptr() as *const p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)).prefix_inc(); } } impl MoveConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { unsafe fn move_constructor( &mut self, - _a0: *mut p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, + _a0: RvalueRefUnsafe, ) { + let _a0 = (_a0.as_ptr() as *mut p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves); (*std::cell::LazyCell::force_mut(&mut *&raw mut moveCount_10)).prefix_inc(); } } @@ -175,7 +177,7 @@ pub unsafe fn test_11() { object_unsafe!( from_xvalue, p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - Moved( + RvalueRefUnsafe::bind( &mut (*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) .wrapping_byte_offset(pm) .cast::()) diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs index 1bd4dc7a47..4f3a4b286f 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs @@ -61,7 +61,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index 83a6535236..33d1a938e8 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 @@ -61,7 +61,8 @@ impl DefaultConstructible for LifetimeTracked { } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs index 0712640fcc..067131a2c9 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs index 1b4268c052..e26693b527 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs @@ -48,7 +48,8 @@ impl DefaultConstructibleUnsafe for LifetimeTracked { } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut self.uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } diff --git a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs index 4dd51e9cb0..0324533ffe 100644 --- a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs @@ -65,14 +65,16 @@ pub fn test_1() { }) ); let referent: Value = Rc::new(RefCell::new(5)); - let bound: Value<(Value>, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new(referent.as_pointer())), + let bound: Value<(Value>>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(referent.as_pointer()))), Rc::new(RefCell::new(('c' as i8))), ))); (*referent.borrow_mut()) = 6; - assert!(({ (((*bound.borrow()).0.borrow().clone().read()) == 6) })); + assert!(({ (((*bound.borrow()).0.borrow().as_pointer().read()) == 6) })); assert!( - ({ ({ ((*bound.borrow()).0.borrow().clone()).clone() } == { (referent.as_pointer()) }) }) + ({ + ({ ((*bound.borrow()).0.borrow().as_pointer()).clone() } == { (referent.as_pointer()) }) + }) ); assert!(({ (((*(*bound.borrow()).1.borrow()) as i32) == (('c' as i8) as i32)) })); } @@ -141,6 +143,130 @@ pub fn test_4() { let mut ordered: bool = ((*a.borrow()) < (*b.borrow())) && ((*b.borrow()) < (*c.borrow())); assert!(ordered); } +pub fn test_5() { + let x: Value = Rc::new(RefCell::new(1)); + let y: Value = Rc::new(RefCell::new(2)); + let to_x: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + let to_y: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(y.as_pointer()))), + Rc::new(RefCell::new(5)), + ))); + { + assign!((*to_x.borrow()).0 = (*to_y.borrow()).0); + assign!((*to_x.borrow()).1 = (*to_y.borrow()).1); + }; + assert!(({ ((*x.borrow()) == 2) })); + assert!(({ ({ ((*to_x.borrow()).0.borrow().as_pointer()).clone() } == { (x.as_pointer()) }) })); + assert!(({ ((*(*to_x.borrow()).1.borrow()) == 5) })); + (*y.borrow_mut()) = 9; + assert!(({ (((*to_x.borrow()).0.borrow().as_pointer().read()) == 2) })); + let u: Value = Rc::new(RefCell::new(1)); + let v: Value = Rc::new(RefCell::new(2)); + let at_u: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new((u.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + let at_v: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new((v.as_pointer()))), + Rc::new(RefCell::new(5)), + ))); + { + assign!((*at_u.borrow()).0 = (*at_v.borrow()).0); + assign!((*at_u.borrow()).1 = (*at_v.borrow()).1); + }; + assert!(({ ((*u.borrow()) == 1) })); + assert!(({ ({ (*(*at_u.borrow()).0.borrow()).clone() } == { (v.as_pointer()) }) })); +} +pub fn test_6() { + let x: Value = Rc::new(RefCell::new(1)); + let y: Value = Rc::new(RefCell::new(2)); + let to_x: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + let to_y: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(y.as_pointer()))), + Rc::new(RefCell::new(5)), + ))); + { + assign!((*to_x.borrow()).0 = RvalueRef((*to_y.borrow()).0)); + assign!((*to_x.borrow()).1 = RvalueRef((*to_y.borrow()).1)); + }; + assert!(({ ((*x.borrow()) == 2) })); + assert!(({ ((*y.borrow()) == 2) })); + assert!(({ ({ ((*to_x.borrow()).0.borrow().as_pointer()).clone() } == { (x.as_pointer()) }) })); +} +pub fn test_7() { + let x: Value = Rc::new(RefCell::new(4)); + let y: Value = Rc::new(RefCell::new(4)); + let to_x: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + let to_y: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(y.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + assert!(({ (*to_x.borrow()) == (*to_y.borrow()) })); + (*y.borrow_mut()) = 5; + assert!((*to_x.borrow()) != (*to_y.borrow())); +} +pub fn test_8() { + let x: Value = Rc::new(RefCell::new(1)); + let to_x: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + ({ (*to_x.borrow()).get_value::<0>().as_pointer() }) + .with(|__r| __r.as_pointer()) + .write(7); + assert!(({ ((*x.borrow()) == 7) })); + ({ (*to_x.borrow()).get_value::<1>().as_pointer() }).write(3); + assert!(({ ((*(*to_x.borrow()).1.borrow()) == 3) })); +} +pub fn test_9() { + let x: Value = Rc::new(RefCell::new(1)); + let read_only: Value<(Value>>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(LvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + (*x.borrow_mut()) = 5; + assert!(({ (((*read_only.borrow()).0.borrow().as_pointer().read()) == 5) })); + assert!( + ({ ({ ((*read_only.borrow()).0.borrow().as_pointer()).clone() } == { (x.as_pointer()) }) }) + ); +} +pub fn test_10() { + let x: Value = Rc::new(RefCell::new(2)); + let owned: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(RvalueRef::bind(x.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + (*owned.borrow()).0.borrow().as_pointer().write(7); + assert!(({ ((*x.borrow()) == 7) })); + assert!( + ({ ({ ((*owned.borrow()).0.borrow().as_pointer()).clone() } == { (x.as_pointer()) }) }) + ); + let a: Value = Rc::new(RefCell::new(1)); + let b: Value = Rc::new(RefCell::new(2)); + let to_a: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(RvalueRef::bind(a.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + let to_b: Value<(Value>, Value)> = Rc::new(RefCell::new(( + Rc::new(RefCell::new(RvalueRef::bind(b.as_pointer()))), + Rc::new(RefCell::new(0)), + ))); + { + assign!((*to_a.borrow()).0 = RvalueRef((*to_b.borrow()).0)); + assign!((*to_a.borrow()).1 = RvalueRef((*to_b.borrow()).1)); + }; + assert!(({ ((*a.borrow()) == 2) })); + assert!(({ ({ ((*to_a.borrow()).0.borrow().as_pointer()).clone() } == { (a.as_pointer()) }) })); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -151,6 +277,12 @@ fn main_0() -> i32 { ({ test_2() }); ({ test_3() }); ({ test_4() }); + ({ test_5() }); + ({ test_6() }); + ({ test_7() }); + ({ test_8() }); + ({ test_9() }); + ({ test_10() }); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs index c78e30a131..9cd7a2d86a 100644 --- a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs @@ -61,10 +61,11 @@ pub unsafe fn test_1() { assert!(((values.len()) == (2_usize))); assert!(((copied.0.len()) == (2_usize)) && ((copied.0[(1_usize)]) == (7))); let mut referent: i32 = 5; - let mut bound: (*const i32, libc::c_char) = (&mut referent, ('c' as libc::c_char)); + let mut bound: (LvalueRefUnsafe>, libc::c_char) = + (LvalueRefUnsafe::bind(&mut referent), ('c' as libc::c_char)); referent = 6; - assert!(((*bound.0) == (6))); - assert!(((bound.0) == ((&mut referent as *mut i32).cast_const()))); + assert!(((*(bound.0.as_ptr() as *const i32)) == (6))); + assert!(((bound.0.as_ptr() as *const i32) == ((&mut referent as *mut i32).cast_const()))); assert!((((bound.1) as i32) == (('c' as libc::c_char) as i32))); } pub unsafe fn test_2() { @@ -153,6 +154,85 @@ pub unsafe fn test_4() { let mut ordered: bool = (a < b) && (b < c); assert!(ordered); } +pub unsafe fn test_5() { + let mut x: i32 = 1; + let mut y: i32 = 2; + let mut to_x: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut x), 0); + let mut to_y: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut y), 5); + { + assign_unsafe!(to_x.0 = (*&mut to_y).0); + assign_unsafe!(to_x.1 = (*&mut to_y).1); + }; + assert!(((x) == (2))); + assert!(((to_x.0.as_ptr() as *mut i32) == (&mut x as *mut i32))); + assert!(((to_x.1) == (5))); + y = 9; + assert!(((*(to_x.0.as_ptr() as *mut i32)) == (2))); + let mut u: i32 = 1; + let mut v: i32 = 2; + let mut at_u: (*mut i32, i32) = ((&mut u as *mut i32), 0); + let mut at_v: (*mut i32, i32) = ((&mut v as *mut i32), 5); + { + assign_unsafe!(at_u.0 = (*&mut at_v).0); + assign_unsafe!(at_u.1 = (*&mut at_v).1); + }; + assert!(((u) == (1))); + assert!(((at_u.0) == (&mut v as *mut i32))); +} +pub unsafe fn test_6() { + let mut x: i32 = 1; + let mut y: i32 = 2; + let mut to_x: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut x), 0); + let mut to_y: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut y), 5); + { + assign_unsafe!(to_x.0 = RvalueRefUnsafe(to_y.0)); + assign_unsafe!(to_x.1 = RvalueRefUnsafe(to_y.1)); + }; + assert!(((x) == (2))); + assert!(((y) == (2))); + assert!(((to_x.0.as_ptr() as *mut i32) == (&mut x as *mut i32))); +} +pub unsafe fn test_7() { + let mut x: i32 = 4; + let mut y: i32 = 4; + let mut to_x: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut x), 0); + let mut to_y: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut y), 0); + assert!(to_x == to_y); + y = 5; + assert!(to_x != to_y); +} +pub unsafe fn test_8() { + let mut x: i32 = 1; + let mut to_x: (LvalueRefUnsafe, i32) = (LvalueRefUnsafe::bind(&mut x), 0); + (*((*to_x.get_mut::<0>()).as_ptr() as *mut i32)) = 7; + assert!(((x) == (7))); + *to_x.get_mut::<1>() = 3; + assert!(((to_x.1) == (3))); +} +pub unsafe fn test_9() { + let mut x: i32 = 1; + let mut read_only: (LvalueRefUnsafe>, i32) = (LvalueRefUnsafe::bind(&mut x), 0); + x = 5; + assert!(((*(read_only.0.as_ptr() as *const i32)) == (5))); + assert!(((read_only.0.as_ptr() as *const i32) == ((&mut x as *mut i32).cast_const()))); +} +pub unsafe fn test_10() { + let mut x: i32 = 2; + let mut owned: (RvalueRefUnsafe, i32) = (RvalueRefUnsafe::bind(&mut x), 0); + (*(owned.0.as_ptr() as *mut i32)) = 7; + assert!(((x) == (7))); + assert!(((owned.0.as_ptr() as *mut i32) == (&mut x as *mut i32))); + let mut a: i32 = 1; + let mut b: i32 = 2; + let mut to_a: (RvalueRefUnsafe, i32) = (RvalueRefUnsafe::bind(&mut a), 0); + let mut to_b: (RvalueRefUnsafe, i32) = (RvalueRefUnsafe::bind(&mut b), 0); + { + assign_unsafe!(to_a.0 = RvalueRefUnsafe(to_b.0)); + assign_unsafe!(to_a.1 = RvalueRefUnsafe(to_b.1)); + }; + assert!(((a) == (2))); + assert!(((to_a.0.as_ptr() as *mut i32) == (&mut a as *mut i32))); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -165,6 +245,12 @@ unsafe fn main_0() -> i32 { (unsafe { test_2() }); (unsafe { test_3() }); (unsafe { test_4() }); + (unsafe { test_5() }); + (unsafe { test_6() }); + (unsafe { test_7() }); + (unsafe { test_8() }); + (unsafe { test_9() }); + (unsafe { test_10() }); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/pairs/pairs.pair.cpp b/tests/std/utilities/pairs/pairs.pair.cpp index 199fc15e9c..145682c5fa 100644 --- a/tests/std/utilities/pairs/pairs.pair.cpp +++ b/tests/std/utilities/pairs/pairs.pair.cpp @@ -109,11 +109,118 @@ void test() { } } // namespace over_match_oper_p3_4_rewritten_candidates +// N4950 [pairs.pair]/22: operator= assigns p.first to first and p.second to +// second. A member of reference type is assigned through, and still refers to +// the same object, while a member of pointer type is given the other pointer. +namespace p22_copy_assignment_of_reference_member { +void test() { + int x = 1; + int y = 2; + std::pair to_x{x, 0}; + std::pair to_y{y, 5}; + to_x = to_y; + assert(x == 2); + assert(&to_x.first == &x); + assert(to_x.second == 5); + y = 9; + assert(to_x.first == 2); + + int u = 1; + int v = 2; + std::pair at_u{&u, 0}; + std::pair at_v{&v, 5}; + at_u = at_v; + assert(u == 1); + assert(at_u.first == &v); +} +} // namespace p22_copy_assignment_of_reference_member + +// N4950 [pairs.pair]/29: the move assignment forwards p.first, which for a +// member of lvalue reference type is an lvalue, so it is assigned through. +namespace p29_move_assignment_of_reference_member { +void test() { + int x = 1; + int y = 2; + std::pair to_x{x, 0}; + std::pair to_y{y, 5}; + to_x = std::move(to_y); + assert(x == 2); + assert(y == 2); + assert(&to_x.first == &x); +} +} // namespace p29_move_assignment_of_reference_member + +// N4950 [pairs.spec]/1: operator== compares the members, and a member of +// reference type is compared by the value of the object it refers to. +namespace spec_p1_equality_of_reference_member { +void test() { + int x = 4; + int y = 4; + std::pair to_x{x, 0}; + std::pair to_y{y, 0}; + assert(to_x == to_y); + y = 5; + assert(to_x != to_y); +} +} // namespace spec_p1_equality_of_reference_member + +// N4950 [pair.astuple]/4: get(p) returns a reference to the member, which +// for a member of reference type is a reference to the object it refers to. +namespace astuple_p4_get_of_reference_member { +void test() { + int x = 1; + std::pair to_x{x, 0}; + std::get<0>(to_x) = 7; + assert(x == 7); + std::get<1>(to_x) = 3; + assert(to_x.second == 3); +} +} // namespace astuple_p4_get_of_reference_member + +// N4950 [pairs.pair]/1, [dcl.ref]/1: a member of type reference to const +// refers to the object it was bound to and reads its current value. +namespace p1_reference_to_const_member { +void test() { + int x = 1; + std::pair read_only{x, 0}; + x = 5; + assert(read_only.first == 5); + assert(&read_only.first == &x); +} +} // namespace p1_reference_to_const_member + +// N4950 [pairs.pair]/29: the move assignment forwards p.first, which for a +// member of rvalue reference type is an rvalue, and assigns to the object the +// member refers to. +namespace p29_move_assignment_of_rvalue_reference_member { +void test() { + int x = 2; + std::pair owned{std::move(x), 0}; + owned.first = 7; + assert(x == 7); + assert(&owned.first == &x); + + int a = 1; + int b = 2; + std::pair to_a{std::move(a), 0}; + std::pair to_b{std::move(b), 0}; + to_a = std::move(to_b); + assert(a == 2); + assert(&to_a.first == &a); +} +} // namespace p29_move_assignment_of_rvalue_reference_member + int main() { p2_move_constructor::test(); p12_forwarding_constructor::test(); p16_converting_move_constructor::test(); p40_converting_move_assignment::test(); over_match_oper_p3_4_rewritten_candidates::test(); + p22_copy_assignment_of_reference_member::test(); + p29_move_assignment_of_reference_member::test(); + spec_p1_equality_of_reference_member::test(); + astuple_p4_get_of_reference_member::test(); + p1_reference_to_const_member::test(); + p29_move_assignment_of_rvalue_reference_member::test(); return 0; } diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 725b0a0dd3..862671435d 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -24,12 +24,14 @@ pub struct p6_forward_like_Movable { pub value: i32, } impl CopyConstructible for p6_forward_like_Movable { - fn copy_constructor(this: &Ptr, other: Ptr) { + fn copy_constructor(this: &Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p6_forward_like_Movable { - fn move_constructor(this: &Ptr, other: Ptr) { + fn move_constructor(this: &Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } @@ -66,7 +68,7 @@ pub fn take_1(this: Ptr, self_: Ptr, self_: Ptr) { - ConstructFrom::construct_from(&this, Moved(field_ptr!(self_, member))); + ConstructFrom::construct_from(&this, RvalueRef::bind(field_ptr!(self_, member))); return; } pub fn test_3() { @@ -90,7 +92,8 @@ pub struct p9_move_Movable { pub value: i32, } impl MoveConstructible for p9_move_Movable { - fn move_constructor(this: &Ptr, other: Ptr) { + fn move_constructor(this: &Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } @@ -107,7 +110,11 @@ pub fn test_4() { && ({ (pointer).clone() } == { (target.as_pointer()) }) ); object!(source, p9_move_Movable(3)); - object!(destination, p9_move_Movable, Moved(source.as_pointer())); + object!( + destination, + p9_move_Movable, + RvalueRef::bind(source.as_pointer()) + ); assert!(({ (*destination.borrow()).value } == 3) && ({ (*source.borrow()).value } == 0)); let strings: Value>> = Rc::new(RefCell::new(Vec::new())); let text: Value> = Rc::new(RefCell::new({ @@ -140,14 +147,16 @@ pub struct p10_forward_in_template_A { pub moves: i32, } impl CopyConstructible for p10_forward_in_template_A { - fn copy_constructor(this: &Ptr, other: Ptr) { + fn copy_constructor(this: &Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!((*this), copies).write((other.with(|__s| __s.copies) + 1)); field!((*this), moves).write(0); } } impl MoveConstructible for p10_forward_in_template_A { - fn move_constructor(this: &Ptr, other: Ptr) { + fn move_constructor(this: &Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!((*this), copies).write(0); field!((*this), moves).write((other.with(|__s| __s.moves) + 1)); @@ -164,7 +173,7 @@ pub fn make_5(this: Ptr, source: Ptr, source: Ptr) { - ConstructFrom::construct_from(&this, Moved((source).clone())); + ConstructFrom::construct_from(&this, RvalueRef::bind((source).clone())); return; } pub fn test_7() { @@ -196,12 +205,17 @@ pub struct p11_move_if_noexcept_NoexceptMove { pub value: i32, } impl CopyConstructible for p11_move_if_noexcept_NoexceptMove { - fn copy_constructor(this: &Ptr, other: Ptr) { + fn copy_constructor( + this: &Ptr, + other: LvalueRef>, + ) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p11_move_if_noexcept_NoexceptMove { - fn move_constructor(this: &Ptr, other: Ptr) { + fn move_constructor(this: &Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } @@ -216,12 +230,17 @@ pub struct p11_move_if_noexcept_ThrowingMove { pub value: i32, } impl CopyConstructible for p11_move_if_noexcept_ThrowingMove { - fn copy_constructor(this: &Ptr, other: Ptr) { + fn copy_constructor( + this: &Ptr, + other: LvalueRef>, + ) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p11_move_if_noexcept_ThrowingMove { - fn move_constructor(this: &Ptr, other: Ptr) { + fn move_constructor(this: &Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } @@ -231,7 +250,7 @@ pub fn test_8() { object!( moved, p11_move_if_noexcept_NoexceptMove, - Moved(moved_from.as_pointer()) + RvalueRef::bind(moved_from.as_pointer()) ); assert!(({ (*moved.borrow()).value } == 1) && ({ (*moved_from.borrow()).value } == 0)); object!(copied_from, p11_move_if_noexcept_ThrowingMove(2)); diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index 9c74c2ab38..ef7d280d26 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -67,14 +67,19 @@ pub struct p10_move_constructor_A { pub value: i32, } impl MoveConstructible for p10_move_constructor_A { - fn move_constructor(this: &Ptr, other: Ptr) { + fn move_constructor(this: &Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } pub fn test_2() { object!(source, p10_move_constructor_A(1)); - object!(target, p10_move_constructor_A, Moved(source.as_pointer())); + object!( + target, + p10_move_constructor_A, + RvalueRef::bind(source.as_pointer()) + ); assert!(({ (*target.borrow()).value } == 1)); assert!(({ (*source.borrow()).value } == 0)); let values: Value> = Rc::new(RefCell::new(Vec::new())); diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index f4d8e19b1d..28e5f3210d 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -28,12 +28,14 @@ impl p6_forward_like_Movable { } } impl CopyConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn copy_constructor(&mut self, other: *const p6_forward_like_Movable) { + unsafe fn copy_constructor(&mut self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const p6_forward_like_Movable); (&raw mut self.value).write((*other).value); } } impl MoveConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn move_constructor(&mut self, other: *mut p6_forward_like_Movable) { + unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut p6_forward_like_Movable); (&raw mut self.value).write((*other).value); (*other).value = 0; } @@ -67,7 +69,7 @@ pub unsafe fn take_1(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_ return; } pub unsafe fn take_2(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut (*self_).member)); + ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(&mut (*self_).member)); return; } pub unsafe fn test_3() { @@ -95,7 +97,8 @@ impl p9_move_Movable { } } impl MoveConstructibleUnsafe for p9_move_Movable { - unsafe fn move_constructor(&mut self, other: *mut p9_move_Movable) { + unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut p9_move_Movable); (&raw mut self.value).write((*other).value); (*other).value = 0; } @@ -111,7 +114,11 @@ pub unsafe fn test_4() { ((moved_pointer) == (&mut target as *mut i32)) && ((pointer) == (&mut target as *mut i32)) ); object_unsafe!(source, p9_move_Movable(3)); - object_unsafe!(destination, p9_move_Movable, Moved(&mut source)); + object_unsafe!( + destination, + p9_move_Movable, + RvalueRefUnsafe::bind(&mut source) + ); assert!(((destination.value) == (3)) && ((source.value) == (0))); let mut strings: Vec> = Vec::new(); let mut text: Vec = std::slice::from_raw_parts( @@ -146,14 +153,19 @@ impl p10_forward_in_template_A { } } impl CopyConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn copy_constructor(&mut self, other: *const p10_forward_in_template_A) { + unsafe fn copy_constructor( + &mut self, + other: LvalueRefUnsafe>, + ) { + let other = (other.as_ptr() as *const p10_forward_in_template_A); (&raw mut self.value).write((*other).value); (&raw mut self.copies).write((((*other).copies) + (1))); (&raw mut self.moves).write(0); } } impl MoveConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn move_constructor(&mut self, other: *mut p10_forward_in_template_A) { + unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut p10_forward_in_template_A); (&raw mut self.value).write((*other).value); (&raw mut self.copies).write(0); (&raw mut self.moves).write((((*other).moves) + (1))); @@ -170,7 +182,7 @@ pub unsafe fn make_5(this: *mut p10_forward_in_template_A, source: *mut p10_forw return; } pub unsafe fn make_6(this: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A) { - ConstructFromUnsafe::construct_from(&mut *this, Moved(source)); + ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(source)); return; } pub unsafe fn test_7() { @@ -200,12 +212,20 @@ impl p11_move_if_noexcept_NoexceptMove { } } impl CopyConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { - unsafe fn copy_constructor(&mut self, other: *const p11_move_if_noexcept_NoexceptMove) { + unsafe fn copy_constructor( + &mut self, + other: LvalueRefUnsafe>, + ) { + let other = (other.as_ptr() as *const p11_move_if_noexcept_NoexceptMove); (&raw mut self.value).write((*other).value); } } impl MoveConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { - unsafe fn move_constructor(&mut self, other: *mut p11_move_if_noexcept_NoexceptMove) { + unsafe fn move_constructor( + &mut self, + other: RvalueRefUnsafe, + ) { + let other = (other.as_ptr() as *mut p11_move_if_noexcept_NoexceptMove); (&raw mut self.value).write((*other).value); (*other).value = 0; } @@ -224,12 +244,20 @@ impl p11_move_if_noexcept_ThrowingMove { } } impl CopyConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { - unsafe fn copy_constructor(&mut self, other: *const p11_move_if_noexcept_ThrowingMove) { + unsafe fn copy_constructor( + &mut self, + other: LvalueRefUnsafe>, + ) { + let other = (other.as_ptr() as *const p11_move_if_noexcept_ThrowingMove); (&raw mut self.value).write((*other).value); } } impl MoveConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { - unsafe fn move_constructor(&mut self, other: *mut p11_move_if_noexcept_ThrowingMove) { + unsafe fn move_constructor( + &mut self, + other: RvalueRefUnsafe, + ) { + let other = (other.as_ptr() as *mut p11_move_if_noexcept_ThrowingMove); (&raw mut self.value).write((*other).value); (*other).value = 0; } @@ -239,7 +267,7 @@ pub unsafe fn test_8() { object_unsafe!( moved, p11_move_if_noexcept_NoexceptMove, - Moved(&mut moved_from) + RvalueRefUnsafe::bind(&mut moved_from) ); assert!(((moved.value) == (1)) && ((moved_from.value) == (0))); object_unsafe!(copied_from, p11_move_if_noexcept_ThrowingMove(2)); diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index 41d519b89c..e777c2b07f 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -61,14 +61,19 @@ impl p10_move_constructor_A { } } impl MoveConstructibleUnsafe for p10_move_constructor_A { - unsafe fn move_constructor(&mut self, other: *mut p10_move_constructor_A) { + unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut p10_move_constructor_A); (&raw mut self.value).write((*other).value); (*other).value = 0; } } pub unsafe fn test_2() { object_unsafe!(source, p10_move_constructor_A(1)); - object_unsafe!(target, p10_move_constructor_A, Moved(&mut source)); + object_unsafe!( + target, + p10_move_constructor_A, + RvalueRefUnsafe::bind(&mut source) + ); assert!(((target.value) == (1))); assert!(((source.value) == (0))); let mut values: Vec = Vec::new(); diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index 6a8e8f860a..7443c7774d 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -28,13 +28,15 @@ pub struct Partial { pub keep: i32, } impl CopyConstructible for Partial { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), keep).write(o.with(|__s| __s.keep)); } } impl CopyAssignable for Partial { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); if ((*this) == (o)) { return (*this).clone(); } @@ -91,7 +93,8 @@ impl DefaultConstructible for RefQualified { } } impl CopyAssignable for RefQualified { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!((*this), mark).write((o.with(|__s| __s.mark) + 1)); return (*this).clone(); } @@ -157,7 +160,8 @@ pub struct CopyCounted { pub v: i32, } impl CopyConstructible for CopyCounted { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -207,7 +211,11 @@ pub struct ExplicitOperatorCall { pub w: Vec, } impl CopyAssignable for ExplicitOperatorCall { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign( + this: &Ptr, + o: LvalueRef>, + ) -> Ptr { + let o = o.as_pointer(); match (field_ref!(o, w).as_pointer(),) { (__tmp_0,) => field!((*this), w).with_mut(|__b0| { (*__b0) = copy_constructed(__tmp_0); @@ -242,21 +250,22 @@ pub struct Swapped { pub v: i32, } impl CopyConstructible for Swapped { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*swap_copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyAssignable for Swapped { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { - object!(__o, Swapped, src); + fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { + object!(__o, Swapped, src.as_pointer()); SwappedImpl::copy_assign(this, Ptr::clone(&__o.as_pointer())); Ptr::clone(this) } } impl MoveAssignable for Swapped { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr { - object!(__o, Swapped, Moved(src)); + fn move_assign(this: &Ptr, src: RvalueRef) -> Ptr { + object!(__o, Swapped, src); SwappedImpl::copy_assign(this, Ptr::clone(&__o.as_pointer())); Ptr::clone(this) } @@ -302,14 +311,14 @@ impl DefaultConstructible for VoidAssign { } } impl CopyAssignable for VoidAssign { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { - VoidAssignImpl::copy_assign(this, src); + fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { + VoidAssignImpl::copy_assign(this, src.as_pointer()); Ptr::clone(this) } } impl MoveAssignable for VoidAssign { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr { - VoidAssignImpl::copy_assign(this, src); + fn move_assign(this: &Ptr, src: RvalueRef) -> Ptr { + VoidAssignImpl::copy_assign(this, src.as_pointer()); Ptr::clone(this) } } diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index af76c67ab8..c2a048960e 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -30,7 +30,8 @@ pub struct Counted { pub v: i32, } impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -81,7 +82,8 @@ pub struct Ignored { pub v: i32, } impl CopyConstructible for Ignored { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), v).write(-1_i32); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -130,7 +132,8 @@ pub struct Box_int_ { pub val: i32, } impl CopyConstructible for Box_int_ { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), val).write(o.with(|__s| __s.val)); } } @@ -165,7 +168,8 @@ pub struct OutOfLine { pub v: i32, } impl CopyConstructible for OutOfLine { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write((o.with(|__s| __s.v) + 100)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -191,7 +195,8 @@ impl DefaultConstructible for Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), copied_from).write(0); field!(o, copied_from).with_mut(|__v| { __v.prefix_inc(); @@ -199,7 +204,8 @@ impl CopyConstructible for Tracked { } } impl CopyAssignable for Tracked { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(o, copied_from).with_mut(|__v| { __v.prefix_inc(); }); @@ -237,12 +243,14 @@ impl DefaultConstructible for SelfPtr { } } impl CopyConstructible for SelfPtr { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), self_).write((*this).clone()); } } impl MoveConstructible for SelfPtr { - fn move_constructor(this: &Ptr, _a0: Ptr) { + fn move_constructor(this: &Ptr, _a0: RvalueRef) { + let _a0 = _a0.as_pointer(); field!((*this), self_).write((*this).clone()); } } @@ -367,7 +375,7 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); - object!(o2, Owner, Moved(o.as_pointer())); + object!(o2, Owner, RvalueRef::bind(o.as_pointer())); assert!(({ (*o2.borrow()).box_.val } == 3)); object!(ol1, OutOfLine(5)); object!(ol2, OutOfLine, ol1.as_pointer()); diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index e63513d4b4..ab3f3f9346 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -110,13 +110,18 @@ pub struct DefaultCopyUserMove { pub v: i32, } impl MoveConstructible for DefaultCopyUserMove { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for DefaultCopyUserMove { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + fn move_assign( + this: &Ptr, + o: RvalueRef, + ) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(0); return (*this).clone(); @@ -141,12 +146,17 @@ pub struct UserCopyDefaultMove { pub v: i32, } impl CopyConstructible for UserCopyDefaultMove { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write((o.with(|__s| __s.v) + 100)); } } impl CopyAssignable for UserCopyDefaultMove { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign( + this: &Ptr, + o: LvalueRef>, + ) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write((o.with(|__s| __s.v) + 100)); return (*this).clone(); } @@ -284,13 +294,15 @@ pub struct SeesThis { pub self_: Ptr, } impl CopyAssignable for SeesThis { - fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, _a0: LvalueRef>) -> Ptr { + let _a0 = _a0.as_pointer(); field!((*this), self_).write((*this).clone()); return (*this).clone(); } } impl MoveAssignable for SeesThis { - fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + fn move_assign(this: &Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); field!((*this), self_).write((*this).clone()); return (*this).clone(); } @@ -341,13 +353,15 @@ impl DefaultConstructible for Counted_int_ { } } impl MoveConstructible for Counted_int_ { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); } } impl MoveAssignable for Counted_int_ { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); return (*this).clone(); @@ -394,24 +408,28 @@ impl DefaultConstructible for CtorSeesThis { } } impl CopyConstructible for CtorSeesThis { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!((*this), self_).write((*this).clone()); field!((*this), id).write(0); } } impl MoveConstructible for CtorSeesThis { - fn move_constructor(this: &Ptr, _a0: Ptr) { + fn move_constructor(this: &Ptr, _a0: RvalueRef) { + let _a0 = _a0.as_pointer(); field!((*this), self_).write((*this).clone()); field!((*this), id).write(0); } } impl CopyAssignable for CtorSeesThis { - fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, _a0: LvalueRef>) -> Ptr { + let _a0 = _a0.as_pointer(); return (*this).clone(); } } impl MoveAssignable for CtorSeesThis { - fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { + fn move_assign(this: &Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); return (*this).clone(); } } @@ -495,7 +513,8 @@ pub struct OutOfLineDefaulted { pub v: i32, } impl CopyConstructible for OutOfLineDefaulted { - fn copy_constructor(this: &Ptr, _a0: Ptr) { + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); ConstructFrom::construct_from(&field_ptr!(this, x), field_ptr!(_a0, x)); field!((*this), v).write(_a0.with(|__s| __s.v)); } @@ -551,7 +570,11 @@ impl Default for OutOfLineAssign { } } impl CopyAssignable for OutOfLineAssign { - fn copy_assign(this: &Ptr, _a0: Ptr) -> Ptr { + fn copy_assign( + this: &Ptr, + _a0: LvalueRef>, + ) -> Ptr { + let _a0 = _a0.as_pointer(); assign!(*field_ptr!((*this), s) = *field_ptr!(_a0, s)); field!((*this), v).write(_a0.with(|__s| __s.v)); match (field_ref!(_a0, w).as_pointer(),) { @@ -563,8 +586,9 @@ impl CopyAssignable for OutOfLineAssign { } } impl MoveAssignable for OutOfLineAssign { - fn move_assign(this: &Ptr, _a0: Ptr) -> Ptr { - assign!(*field_ptr!((*this), s) = Moved(*field_ptr!(_a0, s))); + fn move_assign(this: &Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); + assign!(*field_ptr!((*this), s) = RvalueRef(*field_ptr!(_a0, s))); field!((*this), v).write({ (*_a0.upgrade().deref()).v }); field!((*this), w).with_mut(|__b0| { (*__b0) = field!(_a0, w).with_mut(std::mem::take); @@ -595,7 +619,7 @@ fn main_0() -> i32 { object!(e, Explicit(2)); object!(f, Explicit(3)); assign!(e = b); - assign!(f = Moved(c)); + assign!(f = RvalueRef(c)); assert!( ({ same_0(e.as_pointer(), b.as_pointer(),) }) && ({ same_0(f.as_pointer(), c.as_pointer(),) }) @@ -636,20 +660,20 @@ fn main_0() -> i32 { assert!(({ (*vec_.borrow())[0_usize].v } == 1) && ({ (*vec_.borrow())[1_usize].v } == 9)); object!(m, DefaultCopyUserMove(7)); let m1: Value = Rc::new(RefCell::new((*m.borrow()))); - object!(m2, DefaultCopyUserMove, Moved(m.as_pointer())); + object!(m2, DefaultCopyUserMove, RvalueRef::bind(m.as_pointer())); assert!( (({ (*m1.borrow()).v } == 7) && ({ (*m2.borrow()).v } == 7)) && ({ (*m.borrow()).v } == 0) ); object!(m3, DefaultCopyUserMove(1)); object!(m4, DefaultCopyUserMove(1)); assign!(m3 = m1); - assign!(m4 = Moved(m1)); + assign!(m4 = RvalueRef(m1)); assert!( (({ (*m3.borrow()).v } == 7) && ({ (*m4.borrow()).v } == 7)) && ({ (*m1.borrow()).v } == 0) ); object!(u, UserCopyDefaultMove(8)); object!(u1, UserCopyDefaultMove, u.as_pointer()); - object!(u2, UserCopyDefaultMove, Moved(u.as_pointer())); + object!(u2, UserCopyDefaultMove, RvalueRef::bind(u.as_pointer())); assert!( (({ (*u1.borrow()).v } == 108) && ({ (*u2.borrow()).v } == 8)) && ({ (*u.borrow()).v } == 8) @@ -657,10 +681,10 @@ fn main_0() -> i32 { object!(u3, UserCopyDefaultMove(1)); object!(u4, UserCopyDefaultMove(1)); assign!(u3 = u2); - assign!(u4 = Moved(u2)); + assign!(u4 = RvalueRef(u2)); assert!(({ (*u3.borrow()).v } == 108) && ({ (*u4.borrow()).v } == 8)); object!(p, Buffer(3)); - object!(q, Buffer, Moved(p.as_pointer())); + object!(q, Buffer, RvalueRef::bind(p.as_pointer())); assert!( ({ ((({ (*q.borrow()).n } == 3) && ((*q.borrow()).data.len() == 3_usize)) @@ -669,7 +693,7 @@ fn main_0() -> i32 { }) ); object!(r, Buffer(1)); - assign!(r = Moved(q)); + assign!(r = RvalueRef(q)); assert!( ({ ((({ (*r.borrow()).n } == 3) && ((*r.borrow()).data.len() == 3_usize)) @@ -698,7 +722,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( &__v.as_pointer(), - Moved(bufs.decay().offset(0_usize)), + RvalueRef::bind(bufs.decay().offset(0_usize)), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -727,7 +751,7 @@ fn main_0() -> i32 { let _p: Ptr<_> = Ptr::alloc(7); field_ptr!(o1.as_pointer(), p).write(_p.to_owned_opt()) }; - object!(o2, Owner, Moved(o1.as_pointer())); + object!(o2, Owner, RvalueRef::bind(o1.as_pointer())); assert!( ({ ((({ (*o2.borrow()).n } == 5) && ((*o2.borrow()).data.len() == 1_usize)) @@ -742,7 +766,7 @@ fn main_0() -> i32 { }) ); object!(o3, Owner); - assign!(o3 = Moved(o2)); + assign!(o3 = RvalueRef(o2)); assert!( ((({ (*o3.borrow()).n } == 5) && ((vec_elem!(o3.as_pointer(), data, 0_usize).read()) == 5)) @@ -759,11 +783,11 @@ fn main_0() -> i32 { data: Vec::from([1, 2]), })); let mut c2: Copyable = (*c1.borrow()).clone(); - object!(c3, Copyable, Moved(c1.as_pointer())); + object!(c3, Copyable, RvalueRef::bind(c1.as_pointer())); assert!(({ (c2.data.len() == 2_usize) && ((*c3.borrow()).data.len() == 2_usize) })); assert!(({ (*c1.borrow()).data.is_empty() })); object!(c4, Copyable); - assign!(c4 = Moved(c3)); + assign!(c4 = RvalueRef(c3)); assert!( ({ ((vec_elem!(c4.as_pointer(), data, 1_usize).read()) == 2) @@ -775,14 +799,14 @@ fn main_0() -> i32 { let _p: Ptr<_> = Ptr::alloc(9); field_ptr!(h1.as_pointer(), p).write(_p.to_owned_opt()) }; - object!(h2, Holder, Moved(h1.as_pointer())); + object!(h2, Holder, RvalueRef::bind(h1.as_pointer())); assert!( ((({ (*h2.borrow()).inner.x } == 4) && ({ (*h2.borrow()).e.v } == 4)) && (({ (*h2.borrow()).p.clone() }.as_pointer().read()) == 9)) && (({ (*h1.borrow()).p.clone() }.as_pointer()).is_null()) ); object!(h3, Holder(1)); - assign!(h3 = Moved(h2)); + assign!(h3 = RvalueRef(h2)); assert!( ((({ (*h3.borrow()).inner.x } == 4) && ((array_elem!(field_ptr!(h3.as_pointer(), e), arr, 1).read()) == 5)) @@ -792,15 +816,15 @@ fn main_0() -> i32 { object!(t1, HasSeesThis); object!(t2, HasSeesThis); object!(t3, HasSeesThis); - assign!(t2 = Moved(t1)); + assign!(t2 = RvalueRef(t1)); assert!(({ { (*t2.borrow()).s.self_.clone() } } == { (field_ptr!(t2.as_pointer(), s)) })); assign!(t3 = t2); assert!(({ { (*t3.borrow()).s.self_.clone() } } == { (field_ptr!(t3.as_pointer(), s)) })); object!(k1, HasCounted); - object!(k2, HasCounted, Moved(k1.as_pointer())); + object!(k2, HasCounted, RvalueRef::bind(k1.as_pointer())); assert!(({ (*k2.borrow()).c.moves } == 1)); object!(k3, HasCounted); - assign!(k3 = Moved(k2)); + assign!(k3 = RvalueRef(k2)); assert!(({ (*k3.borrow()).c.moves } == 2)); { object!(d, CtorSeesThis); @@ -816,9 +840,9 @@ fn main_0() -> i32 { assert!(({ { (*h1.borrow()).x.self_.clone() } } == { (field_ptr!(h1.as_pointer(), x)) })); object!(h2, HasCtorSeesThis, h1.as_pointer()); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); - object!(h3, HasCtorSeesThis, Moved(h1.as_pointer())); + object!(h3, HasCtorSeesThis, RvalueRef::bind(h1.as_pointer())); assert!(({ { (*h3.borrow()).x.self_.clone() } } == { (field_ptr!(h3.as_pointer(), x)) })); - assign!(h2 = Moved(h3)); + assign!(h2 = RvalueRef(h3)); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); assign!(h2 = h1); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); @@ -870,7 +894,7 @@ fn main_0() -> i32 { }) ); assert!(({ { (*a2.borrow()).s.self_.clone() } } == { (field_ptr!(a2.as_pointer(), s)) })); - assign!(a3 = Moved(a2)); + assign!(a3 = RvalueRef(a2)); assert!( ({ (({ (*a3.borrow()).v } == 3) && ((*a3.borrow()).w.len() == 1_usize)) diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index fc18a0899a..dd679703a7 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -23,13 +23,15 @@ pub struct NoCopy { pub v: i32, } impl MoveConstructible for NoCopy { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for NoCopy { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(0); return (*this).clone(); @@ -47,13 +49,15 @@ impl DefaultConstructible for PrivateCopy { } } impl MoveConstructible for PrivateCopy { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for PrivateCopy { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(0); return (*this).clone(); @@ -138,17 +142,17 @@ pub fn main() { } fn main_0() -> i32 { object!(a, NoCopy(1)); - object!(b, NoCopy, Moved(a.as_pointer())); + object!(b, NoCopy, RvalueRef::bind(a.as_pointer())); assert!(({ (*b.borrow()).v } == 1) && ({ (*a.borrow()).v } == 0)); - assign!(a = Moved(b)); + assign!(a = RvalueRef(b)); assert!(({ (*a.borrow()).v } == 1) && ({ (*b.borrow()).v } == 0)); ({ bump_0((a.as_pointer())) }); assert!(({ (*a.borrow()).v } == 2)); object!(p, PrivateCopy); (*p.borrow_mut()).v = 3; - object!(q, PrivateCopy, Moved(p.as_pointer())); + object!(q, PrivateCopy, RvalueRef::bind(p.as_pointer())); assert!(({ (*q.borrow()).v } == 3) && ({ (*p.borrow()).v } == 0)); - assign!(p = Moved(q)); + assign!(p = RvalueRef(q)); assert!(({ (*p.borrow()).v } == 3) && ({ (*q.borrow()).v } == 0)); object!(im, Immovable); (*im.borrow_mut()).v = 4; @@ -163,23 +167,23 @@ fn main_0() -> i32 { }, tag: 7, })); - object!(d, Container, Moved(c.as_pointer())); + object!(d, Container, RvalueRef::bind(c.as_pointer())); assert!( (({ (*d.borrow()).inner.v } == 6) && ({ (*d.borrow()).tag } == 7)) && ({ (*c.borrow()).inner.v } == 0) ); object!(h, VecHolder); - object!(h2, VecHolder, Moved(h.as_pointer())); + object!(h2, VecHolder, RvalueRef::bind(h.as_pointer())); assert!(({ ((*h2.borrow()).items.len() == 0_usize) })); return 0; } impl CopyAssignable for PrivateCopy { - fn copy_assign(this: &Ptr, _: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, _: LvalueRef>) -> Ptr { unreachable!("PrivateCopy::copy_assign is never defined") } } impl CopyConstructible for PrivateCopy { - fn copy_constructor(this: &Ptr, _: Ptr) { + fn copy_constructor(this: &Ptr, _: LvalueRef>) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index a2dfea5e77..da8283dd16 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -66,7 +66,8 @@ pub struct MoveOnly { pub data_: i32, } impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, x: Ptr) { + fn move_constructor(this: &Ptr, x: RvalueRef) { + let x = x.as_pointer(); field!((*this), data_).write(x.with(|__s| __s.data_)); field!(x, data_).write(0); } @@ -115,7 +116,7 @@ fn main_0() -> i32 { FnPtr::, Ptr)>::new(scale_move_only_3); object!(n, MoveOnly, |n| ({ let _arg0: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_arg0.as_pointer(), Moved(m.as_pointer())); + ConstructFrom::construct_from(&_arg0.as_pointer(), RvalueRef::bind(m.as_pointer())); sc.call(Ptr::clone(n), _arg0.as_pointer()) })); assert!((({ MoveOnlyImpl::get(&n.as_pointer(),) }) == 40)); diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index ddc09a1228..5f113f8680 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -23,14 +23,16 @@ pub struct Tracked { pub moves: i32, } impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); field!((*this), moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write(o.with(|__s| __s.copies)); field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); @@ -141,7 +143,7 @@ impl HolderImpl for Ptr { ConstructFrom::construct_from(&field_ptr!(self, t), (x).clone()); } fn construct_2(&self, x: Ptr) { - ConstructFrom::construct_from(&field_ptr!(self, t), Moved((x).clone())); + ConstructFrom::construct_from(&field_ptr!(self, t), RvalueRef::bind((x).clone())); } } pub trait TrackedImpl { diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index b3f6eec60d..59247ce5cb 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -23,14 +23,16 @@ pub struct Tracked { pub moves: i32, } impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); field!((*this), moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write(o.with(|__s| __s.copies)); field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index dfcbcd792a..9567f72d68 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -25,14 +25,16 @@ pub struct Tracked { pub moves: i32, } impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); field!((*this), moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write(o.with(|__s| __s.copies)); field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); @@ -52,7 +54,7 @@ pub fn chosen_overload_3(_a0: Ptr) -> Overload { return Overload_kIntRvalueOverload; } pub fn copy_or_move_into_param_4(this: Ptr, t: Ptr) { - ConstructFrom::construct_from(&this, Moved((t).clone())); + ConstructFrom::construct_from(&this, RvalueRef::bind((t).clone())); return; } pub fn main() { @@ -72,7 +74,7 @@ fn main_0() -> i32 { object!(b, Tracked(6)); object!(moved, Tracked, |moved| ({ let _t: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_t.as_pointer(), Moved(b.as_pointer())); + ConstructFrom::construct_from(&_t.as_pointer(), RvalueRef::bind(b.as_pointer())); copy_or_move_into_param_4(Ptr::clone(moved), _t.as_pointer()) })); assert!(({ (*moved.borrow()).v } == 6)); diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index d89c63fc27..f2aa10c943 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -25,14 +25,16 @@ pub struct Tracked { pub moves: i32, } impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); field!((*this), moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write(o.with(|__s| __s.copies)); field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); @@ -156,7 +158,7 @@ pub trait PairImpl { impl PairImpl for Ptr { fn construct(&self, x: Ptr, y: Ptr) { ConstructFrom::construct_from(&field_ptr!(self, a), (x).clone()); - ConstructFrom::construct_from(&field_ptr!(self, b), Moved((y).clone())); + ConstructFrom::construct_from(&field_ptr!(self, b), RvalueRef::bind((y).clone())); } } pub trait TrackedImpl { diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 84cd94f751..3ec91d34ac 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -194,27 +194,31 @@ impl DefaultConstructible for Counted { } } impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Counted { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyAssignable for Counted { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copy_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); return (*this).clone(); } } impl MoveAssignable for Counted { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*move_assigns_5.with(Value::clone).borrow_mut()).prefix_inc(); @@ -344,7 +348,7 @@ fn main_0() -> i32 { ((array_elem!(elems.decay().offset(1_usize), hist, 2).read()) == 5) && ((array_elem!(first, hist, 2).read()) == 0) ); - object!(moved, State, Moved(t.as_pointer())); + object!(moved, State, RvalueRef::bind(t.as_pointer())); assert!( ({ ((*moved.borrow()).grid[(0) as usize][(0) as usize] == 100) @@ -362,7 +366,7 @@ fn main_0() -> i32 { && ((elem!(field_ref!(t.as_pointer(), arr).decay(), 1_usize).read()) == 7) ); let assigned: Value = Rc::new(RefCell::new(::default())); - assign!(assigned = Moved(moved)); + assign!(assigned = RvalueRef(moved)); assert!( ({ ((*assigned.borrow()).grid[(0) as usize][(0) as usize] == 100) @@ -400,7 +404,7 @@ fn main_0() -> i32 { let __p: Ptr = __v.decay(); for __i in 0..3 { __p.offset(__i) - .construct_from(Moved(ca.decay().offset(__i))); + .construct_from(RvalueRef::bind(ca.decay().offset(__i))); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -433,7 +437,7 @@ fn main_0() -> i32 { ); { for __i in 0..3 { - assign!(*ca.as_pointer().decay().offset(__i) = Moved(*cb.decay().offset(__i))); + assign!(*ca.as_pointer().decay().offset(__i) = RvalueRef(*cb.decay().offset(__i))); } ca.as_pointer() }; @@ -459,7 +463,7 @@ fn main_0() -> i32 { let __p: Ptr> = __v.decay(); for __i in 0..2 { __p.offset(__i) - .construct_from(Moved(va.decay().offset(__i))); + .construct_from(RvalueRef::bind(va.decay().offset(__i))); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -474,7 +478,7 @@ fn main_0() -> i32 { ))); { for __i in 0..2 { - assign!(*vc.as_pointer().decay().offset(__i) = Moved(*vb.decay().offset(__i))); + assign!(*vc.as_pointer().decay().offset(__i) = RvalueRef(*vb.decay().offset(__i))); } vc.as_pointer() }; diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index b7a28c83e7..e27f614aa6 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -106,7 +106,11 @@ pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { pub moves: i32, } impl MoveConstructible for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor( + this: &Ptr, + o: RvalueRef, + ) { + let o = o.as_pointer(); field!((*this), f).write((*o.upgrade().deref()).f.move_from()); field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); } @@ -246,7 +250,7 @@ fn main_0() -> i32 { object!( m2, Moving__lambda_at_lambda_as_field_cpp_64_12__, - Moved(m.as_pointer()) + RvalueRef::bind(m.as_pointer()) ); assert!(({ (({ (*m2.borrow()).f.call(3,) }) == 6) })); assert!(({ (*m2.borrow()).moves } == 1)); diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 2010a3a63b..3cebb30512 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -21,13 +21,15 @@ impl DefaultConstructible for Counted { } } impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); field!((*this), moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Counted { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), copies).write(o.with(|__s| __s.copies)); field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); } @@ -53,10 +55,14 @@ impl DefaultConstructible for Dropped { fn default_constructor(this: &Ptr) {} } impl CopyConstructible for Dropped { - fn copy_constructor(this: &Ptr, _a0: Ptr) {} + fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); + } } impl MoveConstructible for Dropped { - fn move_constructor(this: &Ptr, _a0: Ptr) {} + fn move_constructor(this: &Ptr, _a0: RvalueRef) { + let _a0 = _a0.as_pointer(); + } } impl Destructible for Dropped { fn destroy(this: &Ptr) { diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index ebdd72b00f..df1392fe12 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -15,7 +15,8 @@ pub struct Owner { pub p: Ptr, } impl MoveConstructible for Owner { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), p).write(o.with(|__s| __s.p.clone())); field!(o, p).write(Ptr::::null()); } @@ -35,7 +36,7 @@ fn main_0() -> i32 { { let h: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), Moved(o.as_pointer())); + ConstructFrom::construct_from(&__v.as_pointer(), RvalueRef::bind(o.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -97,7 +98,10 @@ impl OwnerImpl for Ptr { { let self_: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), Moved((*self).clone())); + ConstructFrom::construct_from( + &__v.as_pointer(), + RvalueRef::bind((*self).clone()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 58b0144d5b..80f1ee132e 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -25,13 +25,15 @@ pub struct Key { pub k: i32, } impl CopyConstructible for Key { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), k).write(o.with(|__s| __s.k)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Key { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), k).write(o.with(|__s| __s.k)); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 1cc1ffa71d..3e652fd364 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -31,13 +31,15 @@ impl DefaultConstructible for Item { } } impl CopyConstructible for Item { - fn copy_constructor(this: &Ptr, other: Ptr) { + fn copy_constructor(this: &Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Item { - fn move_constructor(this: &Ptr, other: Ptr) { + fn move_constructor(this: &Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); field!(other, value).write(-1_i32); @@ -421,7 +423,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( &__v.as_pointer(), - Moved((__tmp_7).clone()), + RvalueRef::bind((__tmp_7).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -502,7 +504,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( &__v.as_pointer(), - Moved((__tmp_9).clone()), + RvalueRef::bind((__tmp_9).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -653,7 +655,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( &__v.as_pointer(), - Moved((__tmp_12).clone()), + RvalueRef::bind((__tmp_12).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -696,7 +698,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( &__v.as_pointer(), - Moved((__tmp_14).clone()), + RvalueRef::bind((__tmp_14).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index fcf972442b..d5313f931d 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -41,7 +41,8 @@ pub struct Bag { pub n: i32, } impl CopyConstructible for Bag { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), n).write(o.with(|__s| __s.n)); (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 949339cca3..a79729013f 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -23,13 +23,15 @@ pub struct MoveOnly { pub v: i32, } impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for MoveOnly { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); if ((*this) == (o)) { return (*this).clone(); } @@ -63,7 +65,7 @@ impl Default for ConstMoveAssign { } pub fn make_0(this: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(&this, Moved(m.as_pointer())); + ConstructFrom::construct_from(&this, RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -74,31 +76,31 @@ fn main_0() -> i32 { object!(a, MoveOnly(1)); object!(b, MoveOnly(2)); object!(c, MoveOnly(3)); - assign!(a = Moved(b)); + assign!(a = RvalueRef(b)); assert!(({ (*a.borrow()).v } == 2)); assert!(({ (*b.borrow()).v } == 0)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); MoveOnlyImpl::construct(&_o.as_pointer(), 3); - assign!(b = Moved(_o)) + assign!(b = RvalueRef(_o)) }); - assign!(c = Moved(*assign!(a = Moved(b)))); + assign!(c = RvalueRef(*assign!(a = RvalueRef(b)))); assert!( (({ (*b.borrow()).v } == 0) && ({ (*a.borrow()).v } == 0)) && ({ (*c.borrow()).v } == 3) ); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); MoveOnlyImpl::construct(&_o.as_pointer(), 5); - assign!(a = Moved(_o)) + assign!(a = RvalueRef(_o)) }); assert!(({ (*a.borrow()).v } == 5)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); ({ make_0(Ptr::clone(&_o.as_pointer()), 6) }); - assign!(a = Moved(_o)) + assign!(a = RvalueRef(_o)) }); assert!(({ (*a.borrow()).v } == 6)); - assign!(a = Moved(a)); + assign!(a = RvalueRef(a)); assert!(({ (*a.borrow()).v } == 6)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { @@ -112,7 +114,7 @@ fn main_0() -> i32 { } }; object!(d, MoveOnly(8)); - assign!(*vec_.decay().offset(0_usize) = Moved(d)); + assign!(*vec_.decay().offset(0_usize) = RvalueRef(d)); assert!(({ (*vec_.borrow())[0_usize].v } == 8)); assert!(({ (*d.borrow()).v } == 0)); object!(m, ConstMoveAssign); diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index a08b6ac284..05c5b401ea 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -16,7 +16,8 @@ pub struct MoveOnly { pub v: i32, } impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } @@ -57,14 +58,16 @@ pub struct ThrowingMove { pub moves: i32, } impl CopyConstructible for ThrowingMove { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); field!((*this), moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for ThrowingMove { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write(o.with(|__s| __s.copies)); field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); @@ -85,14 +88,16 @@ pub struct NoexceptMove { pub moves: i32, } impl CopyConstructible for NoexceptMove { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); field!((*this), moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for NoexceptMove { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!((*this), copies).write(o.with(|__s| __s.copies)); field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); @@ -104,7 +109,7 @@ pub fn by_value_0(m: Ptr) -> i32 { } pub fn make_1(this: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(&this, Moved(m.as_pointer())); + ConstructFrom::construct_from(&this, RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -113,13 +118,13 @@ pub fn main() { } fn main_0() -> i32 { object!(a, MoveOnly(1)); - object!(b, MoveOnly, Moved(a.as_pointer())); + object!(b, MoveOnly, RvalueRef::bind(a.as_pointer())); assert!(({ (*b.borrow()).v } == 1)); assert!(({ (*a.borrow()).v } == 0)); - object!(c, MoveOnly, Moved(b.as_pointer())); + object!(c, MoveOnly, RvalueRef::bind(b.as_pointer())); assert!(({ (*c.borrow()).v } == 1)); assert!(({ (*b.borrow()).v } == 0)); - object!(d, MoveOnly, Moved(c.as_pointer())); + object!(d, MoveOnly, RvalueRef::bind(c.as_pointer())); assert!(({ (*d.borrow()).v } == 1)); assert!(({ (*c.borrow()).v } == 0)); object!(e, MoveOnly, |e| ({ make_1(Ptr::clone(e), 5,) })); @@ -134,7 +139,7 @@ fn main_0() -> i32 { assert!( (({ let _m: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_m.as_pointer(), Moved(e.as_pointer())); + ConstructFrom::construct_from(&_m.as_pointer(), RvalueRef::bind(e.as_pointer())); by_value_0(_m.as_pointer()) }) == 5) ); @@ -167,13 +172,13 @@ fn main_0() -> i32 { assert!(({ (*t1.borrow()).moves } == 0)); assert!(({ (*t.borrow()).v } == 1)); object!(n, NoexceptMove(2)); - object!(n1, NoexceptMove, Moved(n.as_pointer())); + object!(n1, NoexceptMove, RvalueRef::bind(n.as_pointer())); assert!(({ (*n1.borrow()).v } == 2)); assert!(({ (*n1.borrow()).copies } == 0)); assert!(({ (*n1.borrow()).moves } == 1)); assert!(({ (*n.borrow()).v } == 0)); object!(g, MoveOnly(3)); - object!(g1, MoveOnly, Moved(g.as_pointer())); + object!(g1, MoveOnly, RvalueRef::bind(g.as_pointer())); assert!(({ (*g1.borrow()).v } == 3)); assert!(({ (*g.borrow()).v } == 0)); let nv: Value> = Rc::new(RefCell::new(Vec::new())); diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index 81c681c21d..d8eeca8089 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -16,12 +16,14 @@ pub struct Chain { pub v: i32, } impl CopyConstructible for Chain { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write((o.with(|__s| __s.v) + 100)); } } impl MoveConstructible for Chain { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write((o.with(|__s| __s.v) + 1)); field!(o, v).write(0); } @@ -41,7 +43,7 @@ fn main_0() -> i32 { object!( b, Chain, - Moved(({ ChainImpl::add_5(&({ ChainImpl::add_5(&b0.as_pointer(), 1,) }), 1,) })) + RvalueRef::bind(({ ChainImpl::add_5(&({ ChainImpl::add_5(&b0.as_pointer(), 1,) }), 1,) })) ); assert!(({ (*b.borrow()).v } == 8) && ({ (*b0.borrow()).v } == 0)); object!(c, Chain, |c| { @@ -67,7 +69,7 @@ fn main_0() -> i32 { let _c: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( &_c.as_pointer(), - Moved(({ ChainImpl::self_(&g.as_pointer()) })), + RvalueRef::bind(({ ChainImpl::self_(&g.as_pointer()) })), ); consume_0(_c.as_pointer()) }) == 21) @@ -104,7 +106,7 @@ impl ChainImpl for Ptr { return (*self).clone(); } fn take(&self, this: Ptr) { - ConstructFrom::construct_from(&this, Moved((*self).clone())); + ConstructFrom::construct_from(&this, RvalueRef::bind((*self).clone())); return; } fn copy(&self, this: Ptr) { diff --git a/tests/unit/out/refcount/pair.rs b/tests/unit/out/refcount/pair.rs index 1da712b674..ae6933b441 100644 --- a/tests/unit/out/refcount/pair.rs +++ b/tests/unit/out/refcount/pair.rs @@ -115,8 +115,8 @@ fn main_0() -> i32 { let mut pd: Ptr = ((*d.borrow()).0.as_pointer()); let mut ps: Ptr = ((*s.borrow()).0.as_pointer()); { - assign!((*d.borrow()).0 = Moved((*s.borrow()).0)); - assign!((*d.borrow()).1 = Moved((*s.borrow()).1)); + assign!((*d.borrow()).0 = RvalueRef((*s.borrow()).0)); + assign!((*d.borrow()).1 = RvalueRef((*s.borrow()).1)); }; assert!(((pd.read()) == 3)); ps.write(5); @@ -160,8 +160,8 @@ fn main_0() -> i32 { .borrow_mut()) = 7; assert!(({ ((*(*p.borrow()).1.borrow()) == 7) && ((*(*q.borrow()).1.borrow()) == 4) })); (*(*{ - assign!((*d.borrow()).0 = Moved((*q.borrow()).0)); - assign!((*d.borrow()).1 = Moved((*q.borrow()).1)); + assign!((*d.borrow()).0 = RvalueRef((*q.borrow()).0)); + assign!((*d.borrow()).1 = RvalueRef((*q.borrow()).1)); d.as_pointer() } .upgrade() diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index fef00af72b..7c3d1dec81 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -34,7 +34,8 @@ impl Destructible for Buffer { } } impl CopyConstructible for Buffer { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), data).write((0..4).map(|_| 0_i32).collect::>()); field!((*this), size).write(o.with(|__s| __s.size)); { @@ -51,7 +52,8 @@ impl CopyConstructible for Buffer { } } impl MoveConstructible for Buffer { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), data).write((0..4).map(|_| 0_i32).collect::>()); field!((*this), size).write(o.with(|__s| __s.size)); { @@ -70,7 +72,8 @@ impl MoveConstructible for Buffer { } } impl CopyAssignable for Buffer { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); if ((*this) == (o)) { return (*this).clone(); } @@ -89,7 +92,8 @@ impl CopyAssignable for Buffer { } } impl MoveAssignable for Buffer { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); if ((*this) == (o)) { return (*this).clone(); } @@ -111,7 +115,7 @@ impl MoveAssignable for Buffer { } pub fn make_3(this: Ptr, mut size: i32) { object!(b, Buffer(size)); - ConstructFrom::construct_from(&this, Moved(b.as_pointer())); + ConstructFrom::construct_from(&this, RvalueRef::bind(b.as_pointer())); return; } pub fn main() { @@ -128,7 +132,7 @@ fn main_0() -> i32 { ); array_elem!(b.as_pointer(), data, 0).write(100); assert!(((array_elem!(a.as_pointer(), data, 0).read()) == 0)); - object!(c, Buffer, Moved(a.as_pointer())); + object!(c, Buffer, RvalueRef::bind(a.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 3) && (moves_2.with(|rc| *rc.borrow()) == 1)); assert!( ({ (*a.borrow()).size } == 0) @@ -145,12 +149,12 @@ fn main_0() -> i32 { && ((array_elem!(d.as_pointer(), data, 0).read()) == 100)) && (copies_1.with(|rc| *rc.borrow()) == 2) ); - assign!(d = Moved(c)); + assign!(d = RvalueRef(c)); assert!( (((array_elem!(d.as_pointer(), data, 0).read()) == 0) && ({ (*c.borrow()).size } == 0)) && (moves_2.with(|rc| *rc.borrow()) == 3) ); - assign!(d = Moved(d)); + assign!(d = RvalueRef(d)); assert!(({ (*d.borrow()).size } == 4) && (moves_2.with(|rc| *rc.borrow()) == 3)); } assert!((alive_0.with(|rc| *rc.borrow()) == 0)); diff --git a/tests/unit/out/refcount/rule_of_three.rs b/tests/unit/out/refcount/rule_of_three.rs index 248152dee4..23dd4dc0d2 100644 --- a/tests/unit/out/refcount/rule_of_three.rs +++ b/tests/unit/out/refcount/rule_of_three.rs @@ -39,7 +39,8 @@ impl Destructible for Buffer { } } impl CopyConstructible for Buffer { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), data).write((0..4).map(|_| 0_i32).collect::>()); field!((*this), size).write(o.with(|__s| __s.size)); { @@ -56,7 +57,8 @@ impl CopyConstructible for Buffer { } } impl CopyAssignable for Buffer { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); if ((*this) == (o)) { return (*this).clone(); } diff --git a/tests/unit/out/refcount/rvalue_rule_arg_move.rs b/tests/unit/out/refcount/rvalue_rule_arg_move.rs index 72c6f9c42e..16858720a7 100644 --- a/tests/unit/out/refcount/rvalue_rule_arg_move.rs +++ b/tests/unit/out/refcount/rvalue_rule_arg_move.rs @@ -31,13 +31,15 @@ pub struct Elem { pub v: i32, } impl CopyConstructible for Elem { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Elem { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -60,7 +62,7 @@ fn main_0() -> i32 { let mut __tmp_0 = { >::from(v.decay().end()) }; let __a2 = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), Moved(a.as_pointer())); + ConstructFrom::construct_from(&__v.as_pointer(), RvalueRef::bind(a.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; (*v.borrow_mut()).insert(__tmp_0.index(), __a2); diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 1ab4cac09f..3b6a67899a 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -64,13 +64,13 @@ pub fn size_t_in_rules_3() { let __p: Ptr = __v.decay(); for __i in 0..3 { __p.offset(__i) - .construct_from(Moved(ar2.decay().offset(__i))); + .construct_from(RvalueRef::bind(ar2.decay().offset(__i))); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); { for __i in 0..3 { - assign!(*ar3.as_pointer().decay().offset(__i) = Moved(*ar.decay().offset(__i))); + assign!(*ar3.as_pointer().decay().offset(__i) = RvalueRef(*ar.decay().offset(__i))); } ar3.as_pointer() }; diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index e53d2522ff..3af4e556ac 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -22,25 +22,29 @@ impl DefaultConstructible for Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); } } impl CopyAssignable for Tracked { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); return (*this).clone(); } } impl MoveAssignable for Tracked { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); return (*this).clone(); } diff --git a/tests/unit/out/refcount/structured_binding_copy_ctor.rs b/tests/unit/out/refcount/structured_binding_copy_ctor.rs index a283cf0428..e32d36803e 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -30,7 +30,8 @@ pub struct Counted { pub y: i32, } impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, other: Ptr) { + fn copy_constructor(this: &Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!((*this), x).write((other.with(|__s| __s.x) * 2)); field!((*this), y).write((other.with(|__s| __s.y) * 2)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/unit/out/refcount/structured_binding_element_ctor.rs b/tests/unit/out/refcount/structured_binding_element_ctor.rs index 09f7bb03bd..3d6eeef3bf 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -22,13 +22,15 @@ pub struct Elem { pub v: i32, } impl CopyConstructible for Elem { - fn copy_constructor(this: &Ptr, other: Ptr) { + fn copy_constructor(this: &Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!((*this), v).write((other.with(|__s| __s.v) + 100)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Elem { - fn move_constructor(this: &Ptr, other: Ptr) { + fn move_constructor(this: &Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!((*this), v).write((other.with(|__s| __s.v) + 1000)); field!(other, v).write(-1_i32); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); @@ -97,7 +99,7 @@ fn main_0() -> i32 { assert!(({ (*t.borrow()).a.v } == 50)); let __decomp_5: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), Moved(t.as_pointer())); + ConstructFrom::construct_from(&__v.as_pointer(), RvalueRef::bind(t.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((moves_1.with(|rc| *rc.borrow()) == (base_moves + 2))); @@ -120,7 +122,10 @@ fn main_0() -> i32 { ElemImpl::construct(&__tmp_0.as_pointer(), 7); { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), Moved(__tmp_0.as_pointer())); + ConstructFrom::construct_from( + &__v.as_pointer(), + RvalueRef::bind(__tmp_0.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } })), @@ -129,7 +134,10 @@ fn main_0() -> i32 { ElemImpl::construct(&__tmp_1.as_pointer(), 8); { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), Moved(__tmp_1.as_pointer())); + ConstructFrom::construct_from( + &__v.as_pointer(), + RvalueRef::bind(__tmp_1.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } })), diff --git a/tests/unit/out/refcount/structured_binding_move_ctor.rs b/tests/unit/out/refcount/structured_binding_move_ctor.rs index 8062da38c8..7fcf86294c 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -21,14 +21,16 @@ pub struct Movable { pub y: i32, } impl CopyConstructible for Movable { - fn copy_constructor(this: &Ptr, other: Ptr) { + fn copy_constructor(this: &Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!((*this), x).write(other.with(|__s| __s.x)); field!((*this), y).write(other.with(|__s| __s.y)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Movable { - fn move_constructor(this: &Ptr, other: Ptr) { + fn move_constructor(this: &Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!((*this), x).write(other.with(|__s| __s.x)); field!((*this), y).write(other.with(|__s| __s.y)); field!(other, x).write(0); @@ -73,7 +75,7 @@ fn main_0() -> i32 { object!(m, Movable(3, 4)); let __decomp_2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), Moved(m.as_pointer())); + ConstructFrom::construct_from(&__v.as_pointer(), RvalueRef::bind(m.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((moves_1.with(|rc| *rc.borrow()) == 1)); diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 0a9df41bda..eccc1c42a1 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -22,25 +22,29 @@ impl DefaultConstructible for Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); } } impl CopyAssignable for Tracked { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); return (*this).clone(); } } impl MoveAssignable for Tracked { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); return (*this).clone(); } @@ -140,7 +144,8 @@ pub struct CopyOnly { pub v: i32, } impl CopyConstructible for CopyOnly { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copy_only_copies_1.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -151,7 +156,8 @@ impl Destructible for CopyOnly { } } impl CopyAssignable for CopyOnly { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copy_only_copies_1.with(Value::clone).borrow_mut()).prefix_inc(); return (*this).clone(); @@ -191,27 +197,31 @@ pub struct Moved { pub v: i32, } impl CopyConstructible for Moved { - fn copy_constructor(this: &Ptr, o: Ptr) { + fn copy_constructor(this: &Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Moved { - fn move_constructor(this: &Ptr, o: Ptr) { + fn move_constructor(this: &Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyAssignable for Moved { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); return (*this).clone(); } } impl MoveAssignable for Moved { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { + fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!((*this), v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*move_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -295,7 +305,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); ({ @@ -312,7 +322,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); let m2: Value, Value)>> = Rc::new(RefCell::new(Map::new())); @@ -330,7 +340,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); @@ -635,7 +645,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); ({ @@ -652,7 +662,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); Swappable::swap(&maps.decay().offset(0), maps.decay().offset(1)); diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 307254d0b7..3c2c0fe549 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -28,13 +28,15 @@ impl Partial { } } impl CopyConstructibleUnsafe for Partial { - unsafe fn copy_constructor(&mut self, o: *const Partial) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Partial); (&raw mut self.v).write((*o).v); (&raw mut self.keep).write((*o).keep); } } impl CopyAssignableUnsafe for Partial { - unsafe fn copy_assign(&mut self, o: *const Partial) -> *mut Partial { + unsafe fn copy_assign(&mut self, o: LvalueRefUnsafe>) -> *mut Partial { + let o = (o.as_ptr() as *const Partial); if (((self as *mut Partial).cast_const()) == (o)) { return &mut (*(self as *mut Partial)); } @@ -96,7 +98,8 @@ impl DefaultConstructibleUnsafe for RefQualified { } } impl CopyAssignableUnsafe for RefQualified { - unsafe fn copy_assign(&mut self, o: *const RefQualified) -> *mut RefQualified { + unsafe fn copy_assign(&mut self, o: LvalueRefUnsafe>) -> *mut RefQualified { + let o = (o.as_ptr() as *const RefQualified); self.mark = (((*o).mark) + (1)); return &mut (*(self as *mut RefQualified)); } @@ -150,7 +153,8 @@ impl CopyCounted { } } impl CopyConstructibleUnsafe for CopyCounted { - unsafe fn copy_constructor(&mut self, o: *const CopyCounted) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const CopyCounted); (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); } @@ -184,7 +188,11 @@ pub struct ExplicitOperatorCall { pub w: Vec, } impl CopyAssignableUnsafe for ExplicitOperatorCall { - unsafe fn copy_assign(&mut self, o: *const ExplicitOperatorCall) -> *mut ExplicitOperatorCall { + unsafe fn copy_assign( + &mut self, + o: LvalueRefUnsafe>, + ) -> *mut ExplicitOperatorCall { + let o = (o.as_ptr() as *const ExplicitOperatorCall); { self.w.assign_from(&(*o).w); }; @@ -223,21 +231,22 @@ impl Swapped { } } impl CopyConstructibleUnsafe for Swapped { - unsafe fn copy_constructor(&mut self, o: *const Swapped) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Swapped); (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut swap_copies_2)).prefix_inc(); } } impl CopyAssignableUnsafe for Swapped { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - object_unsafe!(__o, Swapped, src); + unsafe fn copy_assign(&mut self, src: LvalueRefUnsafe>) -> *mut Self { + object_unsafe!(__o, Swapped, (src.as_ptr() as *const Swapped)); Swapped::copy_assign(&mut *self, &mut __o); &mut *self } } impl MoveAssignableUnsafe for Swapped { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - object_unsafe!(__o, Swapped, Moved(src)); + unsafe fn move_assign(&mut self, src: RvalueRefUnsafe) -> *mut Self { + object_unsafe!(__o, Swapped, src); Swapped::copy_assign(&mut *self, &mut __o); &mut *self } @@ -281,14 +290,14 @@ impl DefaultConstructibleUnsafe for VoidAssign { } } impl CopyAssignableUnsafe for VoidAssign { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - VoidAssign::copy_assign(&mut *self, src); + unsafe fn copy_assign(&mut self, src: LvalueRefUnsafe>) -> *mut Self { + VoidAssign::copy_assign(&mut *self, (src.as_ptr() as *const VoidAssign)); &mut *self } } impl MoveAssignableUnsafe for VoidAssign { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - VoidAssign::copy_assign(&mut *self, src); + unsafe fn move_assign(&mut self, src: RvalueRefUnsafe) -> *mut Self { + VoidAssign::copy_assign(&mut *self, (src.as_ptr() as *mut VoidAssign)); &mut *self } } diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 9b07550355..4b7a0e1b9e 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -30,7 +30,8 @@ impl Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(&mut self, o: *const Counted) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Counted); (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } @@ -90,7 +91,8 @@ impl Ignored { } } impl CopyConstructibleUnsafe for Ignored { - unsafe fn copy_constructor(&mut self, _a0: *const Ignored) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const Ignored); (&raw mut self.v).write(-1_i32); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } @@ -129,7 +131,8 @@ impl Box_int_ { } } impl CopyConstructibleUnsafe for Box_int_ { - unsafe fn copy_constructor(&mut self, o: *const Box_int_) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Box_int_); (&raw mut self.val).write((*o).val); } } @@ -164,7 +167,8 @@ impl OutOfLine { } } impl CopyConstructibleUnsafe for OutOfLine { - unsafe fn copy_constructor(&mut self, o: *const OutOfLine) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const OutOfLine); (&raw mut self.v).write((((*o).v) + (100))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } @@ -187,13 +191,15 @@ impl DefaultConstructibleUnsafe for Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut self.copied_from).write(0); (*(&raw const (*o).copied_from).cast_mut()).prefix_inc(); } } impl CopyAssignableUnsafe for Tracked { - unsafe fn copy_assign(&mut self, o: *const Tracked) -> *mut Tracked { + unsafe fn copy_assign(&mut self, o: LvalueRefUnsafe>) -> *mut Tracked { + let o = (o.as_ptr() as *const Tracked); (*(&raw const (*o).copied_from).cast_mut()).prefix_inc(); return &mut (*(self as *mut Tracked)); } @@ -225,12 +231,14 @@ impl DefaultConstructibleUnsafe for SelfPtr { } } impl CopyConstructibleUnsafe for SelfPtr { - unsafe fn copy_constructor(&mut self, _a0: *const SelfPtr) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const SelfPtr); (&raw mut self.self_).write((self as *mut SelfPtr)); } } impl MoveConstructibleUnsafe for SelfPtr { - unsafe fn move_constructor(&mut self, _a0: *mut SelfPtr) { + unsafe fn move_constructor(&mut self, _a0: RvalueRefUnsafe) { + let _a0 = (_a0.as_ptr() as *mut SelfPtr); (&raw mut self.self_).write((self as *mut SelfPtr)); } } @@ -352,7 +360,7 @@ unsafe fn main_0() -> i32 { __v }, }; - object_unsafe!(o2, Owner, Moved(&mut o)); + object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o)); assert!(((o2.box_.val) == (3))); object_unsafe!(ol1, OutOfLine(5)); object_unsafe!(ol2, OutOfLine, &ol1); diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 9c2e761bf4..0260c44400 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -91,13 +91,18 @@ impl DefaultCopyUserMove { } } impl MoveConstructibleUnsafe for DefaultCopyUserMove { - unsafe fn move_constructor(&mut self, o: *mut DefaultCopyUserMove) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut DefaultCopyUserMove); (&raw mut self.v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for DefaultCopyUserMove { - unsafe fn move_assign(&mut self, o: *mut DefaultCopyUserMove) -> *mut DefaultCopyUserMove { + unsafe fn move_assign( + &mut self, + o: RvalueRefUnsafe, + ) -> *mut DefaultCopyUserMove { + let o = (o.as_ptr() as *mut DefaultCopyUserMove); self.v = (*o).v; (*o).v = 0; return &mut (*(self as *mut DefaultCopyUserMove)); @@ -124,12 +129,17 @@ impl UserCopyDefaultMove { } } impl CopyConstructibleUnsafe for UserCopyDefaultMove { - unsafe fn copy_constructor(&mut self, o: *const UserCopyDefaultMove) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const UserCopyDefaultMove); (&raw mut self.v).write((((*o).v) + (100))); } } impl CopyAssignableUnsafe for UserCopyDefaultMove { - unsafe fn copy_assign(&mut self, o: *const UserCopyDefaultMove) -> *mut UserCopyDefaultMove { + unsafe fn copy_assign( + &mut self, + o: LvalueRefUnsafe>, + ) -> *mut UserCopyDefaultMove { + let o = (o.as_ptr() as *const UserCopyDefaultMove); self.v = (((*o).v) + (100)); return &mut (*(self as *mut UserCopyDefaultMove)); } @@ -243,13 +253,15 @@ pub struct SeesThis { pub self_: *mut SeesThis, } impl CopyAssignableUnsafe for SeesThis { - unsafe fn copy_assign(&mut self, _a0: *const SeesThis) -> *mut SeesThis { + unsafe fn copy_assign(&mut self, _a0: LvalueRefUnsafe>) -> *mut SeesThis { + let _a0 = (_a0.as_ptr() as *const SeesThis); self.self_ = (self as *mut SeesThis); return &mut (*(self as *mut SeesThis)); } } impl MoveAssignableUnsafe for SeesThis { - unsafe fn move_assign(&mut self, _a0: *mut SeesThis) -> *mut SeesThis { + unsafe fn move_assign(&mut self, _a0: RvalueRefUnsafe) -> *mut SeesThis { + let _a0 = (_a0.as_ptr() as *mut SeesThis); self.self_ = (self as *mut SeesThis); return &mut (*(self as *mut SeesThis)); } @@ -294,13 +306,15 @@ impl DefaultConstructibleUnsafe for Counted_int_ { } } impl MoveConstructibleUnsafe for Counted_int_ { - unsafe fn move_constructor(&mut self, o: *mut Counted_int_) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Counted_int_); (&raw mut self.v).write((*o).v); (&raw mut self.moves).write((((*o).moves) + (1))); } } impl MoveAssignableUnsafe for Counted_int_ { - unsafe fn move_assign(&mut self, o: *mut Counted_int_) -> *mut Counted_int_ { + unsafe fn move_assign(&mut self, o: RvalueRefUnsafe) -> *mut Counted_int_ { + let o = (o.as_ptr() as *mut Counted_int_); self.v = (*o).v; self.moves = (((*o).moves) + (1)); return &mut (*(self as *mut Counted_int_)); @@ -353,24 +367,31 @@ impl DefaultConstructibleUnsafe for CtorSeesThis { } } impl CopyConstructibleUnsafe for CtorSeesThis { - unsafe fn copy_constructor(&mut self, _a0: *const CtorSeesThis) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const CtorSeesThis); (&raw mut self.self_).write((self as *mut CtorSeesThis)); (&raw mut self.id).write(0); } } impl MoveConstructibleUnsafe for CtorSeesThis { - unsafe fn move_constructor(&mut self, _a0: *mut CtorSeesThis) { + unsafe fn move_constructor(&mut self, _a0: RvalueRefUnsafe) { + let _a0 = (_a0.as_ptr() as *mut CtorSeesThis); (&raw mut self.self_).write((self as *mut CtorSeesThis)); (&raw mut self.id).write(0); } } impl CopyAssignableUnsafe for CtorSeesThis { - unsafe fn copy_assign(&mut self, _a0: *const CtorSeesThis) -> *mut CtorSeesThis { + unsafe fn copy_assign( + &mut self, + _a0: LvalueRefUnsafe>, + ) -> *mut CtorSeesThis { + let _a0 = (_a0.as_ptr() as *const CtorSeesThis); return &mut (*(self as *mut CtorSeesThis)); } } impl MoveAssignableUnsafe for CtorSeesThis { - unsafe fn move_assign(&mut self, _a0: *mut CtorSeesThis) -> *mut CtorSeesThis { + unsafe fn move_assign(&mut self, _a0: RvalueRefUnsafe) -> *mut CtorSeesThis { + let _a0 = (_a0.as_ptr() as *mut CtorSeesThis); return &mut (*(self as *mut CtorSeesThis)); } } @@ -453,7 +474,8 @@ impl OutOfLineDefaulted { } } impl CopyConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn copy_constructor(&mut self, _a0: *const OutOfLineDefaulted) { + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const OutOfLineDefaulted); ConstructFromUnsafe::construct_from(&mut self.x, &(*_a0).x); (&raw mut self.v).write((*_a0).v); } @@ -503,7 +525,11 @@ impl Default for OutOfLineAssign { } } impl CopyAssignableUnsafe for OutOfLineAssign { - unsafe fn copy_assign(&mut self, _a0: *const OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn copy_assign( + &mut self, + _a0: LvalueRefUnsafe>, + ) -> *mut OutOfLineAssign { + let _a0 = (_a0.as_ptr() as *const OutOfLineAssign); (unsafe { let _arg0: *const SeesThis = &(*_a0).s; assign_unsafe!(self.s = *_arg0) @@ -516,10 +542,14 @@ impl CopyAssignableUnsafe for OutOfLineAssign { } } impl MoveAssignableUnsafe for OutOfLineAssign { - unsafe fn move_assign(&mut self, _a0: *mut OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn move_assign( + &mut self, + _a0: RvalueRefUnsafe, + ) -> *mut OutOfLineAssign { + let _a0 = (_a0.as_ptr() as *mut OutOfLineAssign); (unsafe { let _arg0: *mut SeesThis = &mut (*_a0).s; - assign_unsafe!(self.s = Moved(*_arg0)) + assign_unsafe!(self.s = RvalueRefUnsafe(*_arg0)) }); self.v = (*_a0).v; { @@ -555,7 +585,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(e, Explicit(2)); object_unsafe!(f, Explicit(3)); assign_unsafe!(e = b); - assign_unsafe!(f = Moved(c)); + assign_unsafe!(f = RvalueRefUnsafe(c)); assert!((unsafe { same_0(&e, &b,) }) && (unsafe { same_0(&f, &c,) })); object_unsafe!(g, Explicit(4)); assign_unsafe!(g = (*assign_unsafe!(e = f))); @@ -589,30 +619,30 @@ unsafe fn main_0() -> i32 { assert!(((vec_[(0_usize)].v) == (1)) && ((vec_[(1_usize)].v) == (9))); object_unsafe!(m, DefaultCopyUserMove(7)); let mut m1: DefaultCopyUserMove = m; - object_unsafe!(m2, DefaultCopyUserMove, Moved(&mut m)); + object_unsafe!(m2, DefaultCopyUserMove, RvalueRefUnsafe::bind(&mut m)); assert!((((m1.v) == (7)) && ((m2.v) == (7))) && ((m.v) == (0))); object_unsafe!(m3, DefaultCopyUserMove(1)); object_unsafe!(m4, DefaultCopyUserMove(1)); assign_unsafe!(m3 = m1); - assign_unsafe!(m4 = Moved(m1)); + assign_unsafe!(m4 = RvalueRefUnsafe(m1)); assert!((((m3.v) == (7)) && ((m4.v) == (7))) && ((m1.v) == (0))); object_unsafe!(u, UserCopyDefaultMove(8)); object_unsafe!(u1, UserCopyDefaultMove, &u); - object_unsafe!(u2, UserCopyDefaultMove, Moved(&mut u)); + object_unsafe!(u2, UserCopyDefaultMove, RvalueRefUnsafe::bind(&mut u)); assert!((((u1.v) == (108)) && ((u2.v) == (8))) && ((u.v) == (8))); object_unsafe!(u3, UserCopyDefaultMove(1)); object_unsafe!(u4, UserCopyDefaultMove(1)); assign_unsafe!(u3 = u2); - assign_unsafe!(u4 = Moved(u2)); + assign_unsafe!(u4 = RvalueRefUnsafe(u2)); assert!(((u3.v) == (108)) && ((u4.v) == (8))); object_unsafe!(p, Buffer(3)); - object_unsafe!(q, Buffer, Moved(&mut p)); + object_unsafe!(q, Buffer, RvalueRefUnsafe::bind(&mut p)); assert!( ((((q.n) == (3)) && ((q.data.len()) == (3_usize))) && ((q.data[(2_usize)]) == (3))) && (p.data.is_empty()) ); object_unsafe!(r, Buffer(1)); - assign_unsafe!(r = Moved(q)); + assign_unsafe!(r = RvalueRefUnsafe(q)); assert!( ((((r.n) == (3)) && ((r.data.len()) == (3_usize))) && ((r.arr[(1) as usize]) == (4))) && (q.data.is_empty()) @@ -627,7 +657,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { { let mut __v: Buffer = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut bufs[(0_usize)])); + ConstructFromUnsafe::construct_from( + &mut __v, + RvalueRefUnsafe::bind(&mut bufs[(0_usize)]), + ); __v } }; @@ -653,7 +686,7 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(_a0)) } }; - object_unsafe!(o2, Owner, Moved(&mut o1)); + object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o1)); assert!( ((((o2.n) == (5)) && ((o2.data.len()) == (1_usize))) && ((o2.arr[(1) as usize]) == (6))) && ((*o2 @@ -671,7 +704,7 @@ unsafe fn main_0() -> i32 { .is_null()) ); object_unsafe!(o3, Owner); - assign_unsafe!(o3 = Moved(o2)); + assign_unsafe!(o3 = RvalueRefUnsafe(o2)); assert!( ((((o3.n) == (5)) && ((o3.data[(0_usize)]) == (5))) && ((o3.arr[(0) as usize]) == (5))) && ((*o3 @@ -692,11 +725,11 @@ unsafe fn main_0() -> i32 { data: Vec::from([1, 2]), }; let mut c2: Copyable = c1.clone(); - object_unsafe!(c3, Copyable, Moved(&mut c1)); + object_unsafe!(c3, Copyable, RvalueRefUnsafe::bind(&mut c1)); assert!(((c2.data.len()) == (2_usize)) && ((c3.data.len()) == (2_usize))); assert!(c1.data.is_empty()); object_unsafe!(c4, Copyable); - assign_unsafe!(c4 = Moved(c3)); + assign_unsafe!(c4 = RvalueRefUnsafe(c3)); assert!(((c4.data[(1_usize)]) == (2)) && (c3.data.is_empty())); object_unsafe!(h1, Holder(4)); { @@ -707,7 +740,7 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(_a0)) } }; - object_unsafe!(h2, Holder, Moved(&mut h1)); + object_unsafe!(h2, Holder, RvalueRefUnsafe::bind(&mut h1)); assert!( ((((h2.inner.x) == (4)) && ((h2.e.v) == (4))) && ((*h2 @@ -722,7 +755,7 @@ unsafe fn main_0() -> i32 { .is_null()) ); object_unsafe!(h3, Holder(1)); - assign_unsafe!(h3 = Moved(h2)); + assign_unsafe!(h3 = RvalueRefUnsafe(h2)); assert!( ((((h3.inner.x) == (4)) && ((h3.e.arr[(1) as usize]) == (5))) && ((*h3 @@ -739,15 +772,15 @@ unsafe fn main_0() -> i32 { object_unsafe!(t1, HasSeesThis); object_unsafe!(t2, HasSeesThis); object_unsafe!(t3, HasSeesThis); - assign_unsafe!(t2 = Moved(t1)); + assign_unsafe!(t2 = RvalueRefUnsafe(t1)); assert!(((t2.s.self_) == (&mut t2.s as *mut SeesThis))); assign_unsafe!(t3 = t2); assert!(((t3.s.self_) == (&mut t3.s as *mut SeesThis))); object_unsafe!(k1, HasCounted); - object_unsafe!(k2, HasCounted, Moved(&mut k1)); + object_unsafe!(k2, HasCounted, RvalueRefUnsafe::bind(&mut k1)); assert!(((k2.c.moves) == (1))); object_unsafe!(k3, HasCounted); - assign_unsafe!(k3 = Moved(k2)); + assign_unsafe!(k3 = RvalueRefUnsafe(k2)); assert!(((k3.c.moves) == (2))); { object_unsafe!(d, CtorSeesThis); @@ -760,9 +793,9 @@ unsafe fn main_0() -> i32 { assert!(((h1.x.self_) == (&mut h1.x as *mut CtorSeesThis))); object_unsafe!(h2, HasCtorSeesThis, &h1); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); - object_unsafe!(h3, HasCtorSeesThis, Moved(&mut h1)); + object_unsafe!(h3, HasCtorSeesThis, RvalueRefUnsafe::bind(&mut h1)); assert!(((h3.x.self_) == (&mut h3.x as *mut CtorSeesThis))); - assign_unsafe!(h2 = Moved(h3)); + assign_unsafe!(h2 = RvalueRefUnsafe(h3)); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); assign_unsafe!(h2 = h1); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); @@ -797,7 +830,7 @@ unsafe fn main_0() -> i32 { assign_unsafe!(a2 = a1); assert!((((a2.v) == (3)) && ((a2.w.len()) == (1_usize))) && ((a1.w.len()) == (1_usize))); assert!(((a2.s.self_) == (&mut a2.s as *mut SeesThis))); - assign_unsafe!(a3 = Moved(a2)); + assign_unsafe!(a3 = RvalueRefUnsafe(a2)); assert!( (((a3.v) == (3)) && ((a3.w.len()) == (1_usize))) && ((a3.s.self_) == (&mut a3.s as *mut SeesThis)) diff --git a/tests/unit/out/unsafe/copy_move_deleted.rs b/tests/unit/out/unsafe/copy_move_deleted.rs index 08f7648ccb..81d45a877a 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.rs @@ -25,13 +25,15 @@ impl NoCopy { } } impl MoveConstructibleUnsafe for NoCopy { - unsafe fn move_constructor(&mut self, o: *mut NoCopy) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut NoCopy); (&raw mut self.v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for NoCopy { - unsafe fn move_assign(&mut self, o: *mut NoCopy) -> *mut NoCopy { + unsafe fn move_assign(&mut self, o: RvalueRefUnsafe) -> *mut NoCopy { + let o = (o.as_ptr() as *mut NoCopy); self.v = (*o).v; (*o).v = 0; return &mut (*(self as *mut NoCopy)); @@ -48,13 +50,15 @@ impl DefaultConstructibleUnsafe for PrivateCopy { } } impl MoveConstructibleUnsafe for PrivateCopy { - unsafe fn move_constructor(&mut self, o: *mut PrivateCopy) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut PrivateCopy); (&raw mut self.v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for PrivateCopy { - unsafe fn move_assign(&mut self, o: *mut PrivateCopy) -> *mut PrivateCopy { + unsafe fn move_assign(&mut self, o: RvalueRefUnsafe) -> *mut PrivateCopy { + let o = (o.as_ptr() as *mut PrivateCopy); self.v = (*o).v; (*o).v = 0; return &mut (*(self as *mut PrivateCopy)); @@ -138,17 +142,17 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(a, NoCopy(1)); - object_unsafe!(b, NoCopy, Moved(&mut a)); + object_unsafe!(b, NoCopy, RvalueRefUnsafe::bind(&mut a)); assert!(((b.v) == (1)) && ((a.v) == (0))); - assign_unsafe!(a = Moved(b)); + assign_unsafe!(a = RvalueRefUnsafe(b)); assert!(((a.v) == (1)) && ((b.v) == (0))); (unsafe { bump_0((&mut a as *mut NoCopy)) }); assert!(((a.v) == (2))); object_unsafe!(p, PrivateCopy); p.v = 3; - object_unsafe!(q, PrivateCopy, Moved(&mut p)); + object_unsafe!(q, PrivateCopy, RvalueRefUnsafe::bind(&mut p)); assert!(((q.v) == (3)) && ((p.v) == (0))); - assign_unsafe!(p = Moved(q)); + assign_unsafe!(p = RvalueRefUnsafe(q)); assert!(((p.v) == (3)) && ((q.v) == (0))); object_unsafe!(im, Immovable); im.v = 4; @@ -163,20 +167,20 @@ unsafe fn main_0() -> i32 { }, tag: 7, }; - object_unsafe!(d, Container, Moved(&mut c)); + object_unsafe!(d, Container, RvalueRefUnsafe::bind(&mut c)); assert!((((d.inner.v) == (6)) && ((d.tag) == (7))) && ((c.inner.v) == (0))); object_unsafe!(h, VecHolder); - object_unsafe!(h2, VecHolder, Moved(&mut h)); + object_unsafe!(h2, VecHolder, RvalueRefUnsafe::bind(&mut h)); assert!(((h2.items.len()) == (0_usize))); return 0; } impl CopyAssignableUnsafe for PrivateCopy { - unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self { + unsafe fn copy_assign(&mut self, _: LvalueRefUnsafe>) -> *mut Self { unreachable!("PrivateCopy::copy_assign is never defined") } } impl CopyConstructibleUnsafe for PrivateCopy { - unsafe fn copy_constructor(&mut self, _: *const Self) { + unsafe fn copy_constructor(&mut self, _: LvalueRefUnsafe>) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index 129df4dff2..d24050a39a 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -67,7 +67,8 @@ impl MoveOnly { } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(&mut self, x: *mut MoveOnly) { + unsafe fn move_constructor(&mut self, x: RvalueRefUnsafe) { + let x = (x.as_ptr() as *mut MoveOnly); (&raw mut self.data_).write((*x).data_); (*x).data_ = 0; } @@ -117,7 +118,7 @@ unsafe fn main_0() -> i32 { let mut sc: Option = Some(scale_move_only_3); object_unsafe!(n, MoveOnly, |n| (unsafe { let mut _arg0: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _arg0, Moved(&mut m)); + ConstructFromUnsafe::construct_from(&mut _arg0, RvalueRefUnsafe::bind(&mut m)); (sc).unwrap()(n, &mut _arg0) })); assert!(((unsafe { MoveOnly::get(&n,) }) == (40))); diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 28acaf70ac..4d89990e69 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -27,14 +27,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(&mut self, o: *mut Tracked) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); @@ -54,7 +56,7 @@ impl Holder { } impl Holder { pub unsafe fn construct_2(&mut self, x: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut self.t, Moved(x)); + ConstructFromUnsafe::construct_from(&mut self.t, RvalueRefUnsafe::bind(x)); } } #[repr(C)] diff --git a/tests/unit/out/unsafe/forward_decltype.rs b/tests/unit/out/unsafe/forward_decltype.rs index da2ffa87cd..20edcb5335 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -27,14 +27,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(&mut self, o: *mut Tracked) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index bc6566496a..e72c94b191 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -29,14 +29,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(&mut self, o: *mut Tracked) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); @@ -56,7 +58,7 @@ pub unsafe fn chosen_overload_3(_a0: *mut i32) -> Overload { return Overload_kIntRvalueOverload; } pub unsafe fn copy_or_move_into_param_4(this: *mut Tracked, t: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut *this, Moved(t)); + ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(t)); return; } pub fn main() { @@ -76,7 +78,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(b, Tracked(6)); object_unsafe!(moved, Tracked, |moved| (unsafe { let mut _t: Tracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _t, Moved(&mut b)); + ConstructFromUnsafe::construct_from(&mut _t, RvalueRefUnsafe::bind(&mut b)); copy_or_move_into_param_4(moved, &mut _t) })); assert!(((moved.v) == (6))); diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index 85010a2f44..7dd9c333c6 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -29,14 +29,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(&mut self, o: *mut Tracked) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); @@ -92,7 +94,7 @@ pub unsafe fn forward_pack_7( impl Pair { pub unsafe fn construct(&mut self, x: *mut Tracked, y: *mut Tracked) { ConstructFromUnsafe::construct_from(&mut self.a, x); - ConstructFromUnsafe::construct_from(&mut self.b, Moved(y)); + ConstructFromUnsafe::construct_from(&mut self.b, RvalueRefUnsafe::bind(y)); } } #[repr(C)] diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index 0b21b79238..26014506f4 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -148,27 +148,31 @@ impl DefaultConstructibleUnsafe for Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(&mut self, o: *const Counted) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Counted); (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)).prefix_inc(); } } impl MoveConstructibleUnsafe for Counted { - unsafe fn move_constructor(&mut self, o: *mut Counted) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Counted); (&raw mut self.v).write((*o).v); (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); } } impl CopyAssignableUnsafe for Counted { - unsafe fn copy_assign(&mut self, o: *const Counted) -> *mut Counted { + unsafe fn copy_assign(&mut self, o: LvalueRefUnsafe>) -> *mut Counted { + let o = (o.as_ptr() as *const Counted); self.v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_assigns_4)).prefix_inc(); return &mut (*(self as *mut Counted)); } } impl MoveAssignableUnsafe for Counted { - unsafe fn move_assign(&mut self, o: *mut Counted) -> *mut Counted { + unsafe fn move_assign(&mut self, o: RvalueRefUnsafe) -> *mut Counted { + let o = (o.as_ptr() as *mut Counted); self.v = (*o).v; (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_5)).prefix_inc(); @@ -249,7 +253,7 @@ unsafe fn main_0() -> i32 { assert!( ((elems[(1_usize)].hist[(2) as usize]) == (5)) && (((*first).hist[(2) as usize]) == (0)) ); - object_unsafe!(moved, State, Moved(&mut t)); + object_unsafe!(moved, State, RvalueRefUnsafe::bind(&mut t)); assert!( ((moved.grid[(0) as usize][(0) as usize]) == (100)) && ((moved.grid[(1) as usize][(2) as usize]) == (5)) @@ -257,7 +261,7 @@ unsafe fn main_0() -> i32 { assert!((((moved.elems.len()) == (4_usize)) && (t.elems.is_empty())) && (t.rows.is_empty())); assert!(((moved.arr[(1_usize)]) == (7)) && ((t.arr[(1_usize)]) == (7))); let mut assigned: State = ::default(); - assign_unsafe!(assigned = Moved(moved)); + assign_unsafe!(assigned = RvalueRefUnsafe(moved)); assert!( ((assigned.grid[(0) as usize][(0) as usize]) == (100)) && ((assigned.grid[(1) as usize][(1) as usize]) == (4)) @@ -295,7 +299,7 @@ unsafe fn main_0() -> i32 { ); { for __i in 0..3 { - assign_unsafe!(ca[__i] = Moved(cb[__i])); + assign_unsafe!(ca[__i] = RvalueRefUnsafe(cb[__i])); } }; assert!( @@ -319,7 +323,7 @@ unsafe fn main_0() -> i32 { let mut vc: [Vec; 2] = std::array::from_fn::<_, 2, _>(|_| Default::default()); { for __i in 0..2 { - assign_unsafe!(vc[__i] = Moved(vb[__i])); + assign_unsafe!(vc[__i] = RvalueRefUnsafe(vb[__i])); } }; assert!(((vc[(0_usize)].len()) == (1_usize)) && (vb[(0_usize)].is_empty())); diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index 8e632c6980..aea30aa08c 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -105,7 +105,11 @@ impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { } } impl MoveConstructibleUnsafe for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - unsafe fn move_constructor(&mut self, o: *mut Moving__lambda_at_lambda_as_field_cpp_64_12__) { + unsafe fn move_constructor( + &mut self, + o: RvalueRefUnsafe, + ) { + let o = (o.as_ptr() as *mut Moving__lambda_at_lambda_as_field_cpp_64_12__); (&raw mut self.f).write((*o).f.move_from()); (&raw mut self.moves).write((((*o).moves) + (1))); } @@ -230,7 +234,7 @@ unsafe fn main_0() -> i32 { object_unsafe!( m2, Moving__lambda_at_lambda_as_field_cpp_64_12__, - Moved(&mut m) + RvalueRefUnsafe::bind(&mut m) ); assert!(((unsafe { m2.f.call(3,) }) == (6))); assert!(((m2.moves) == (1))); diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index ae9d514bae..095d60f552 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -19,13 +19,15 @@ impl DefaultConstructibleUnsafe for Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(&mut self, o: *const Counted) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Counted); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Counted { - unsafe fn move_constructor(&mut self, o: *mut Counted) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Counted); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); } @@ -49,10 +51,14 @@ impl DefaultConstructibleUnsafe for Dropped { unsafe fn default_constructor(&mut self) {} } impl CopyConstructibleUnsafe for Dropped { - unsafe fn copy_constructor(&mut self, _a0: *const Dropped) {} + unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const Dropped); + } } impl MoveConstructibleUnsafe for Dropped { - unsafe fn move_constructor(&mut self, _a0: *mut Dropped) {} + unsafe fn move_constructor(&mut self, _a0: RvalueRefUnsafe) { + let _a0 = (_a0.as_ptr() as *mut Dropped); + } } impl DestructibleUnsafe for Dropped { unsafe fn destroy(&mut self) { diff --git a/tests/unit/out/unsafe/lambda_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index e722c7be24..09851468bd 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -23,7 +23,7 @@ impl Owner { let mut __v: Owner = ::zero_init(); ConstructFromUnsafe::construct_from( &mut __v, - Moved(&mut (*(self as *mut Owner))), + RvalueRefUnsafe::bind(&mut (*(self as *mut Owner))), ); __v }; @@ -35,7 +35,8 @@ impl Owner { } } impl MoveConstructibleUnsafe for Owner { - unsafe fn move_constructor(&mut self, o: *mut Owner) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Owner); (&raw mut self.p).write((*o).p); (*o).p = std::ptr::null_mut(); } @@ -62,7 +63,7 @@ unsafe fn main_0() -> i32 { { let h: Owner = { let mut __v: Owner = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut o)); + ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut o)); __v }; }, diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 51f47533cd..55da2253c1 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -26,13 +26,15 @@ impl Key { } } impl CopyConstructibleUnsafe for Key { - unsafe fn copy_constructor(&mut self, o: *const Key) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Key); (&raw mut self.k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Key { - unsafe fn move_constructor(&mut self, o: *mut Key) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Key); (&raw mut self.k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index aa77d462f1..53b71be062 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -28,13 +28,15 @@ impl DefaultConstructibleUnsafe for Item { } } impl CopyConstructibleUnsafe for Item { - unsafe fn copy_constructor(&mut self, other: *const Item) { + unsafe fn copy_constructor(&mut self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const Item); (&raw mut self.value).write((*other).value); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)).prefix_inc(); } } impl MoveConstructibleUnsafe for Item { - unsafe fn move_constructor(&mut self, other: *mut Item) { + unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut Item); (&raw mut self.value).write((*other).value); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); (*other).value = -1_i32; @@ -282,7 +284,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_7,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_7)); + ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(__tmp_7)); __v }), }; @@ -316,7 +318,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_9,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_9)); + ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(__tmp_9)); __v }), }; @@ -390,7 +392,7 @@ unsafe fn main_0() -> i32 { { (__tmp_12,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_12)); + ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(__tmp_12)); __v }), } @@ -413,7 +415,7 @@ unsafe fn main_0() -> i32 { { (__tmp_14,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_14)); + ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(__tmp_14)); __v }), } diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 6d058d9580..b81b7d5cd5 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -39,7 +39,8 @@ impl Bag { } } impl CopyConstructibleUnsafe for Bag { - unsafe fn copy_constructor(&mut self, o: *const Bag) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Bag); (&raw mut self.n).write((*o).n); (*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)).prefix_inc(); } diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index ac1f8d6f3c..7cc995e041 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -25,13 +25,15 @@ impl MoveOnly { } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(&mut self, o: *mut MoveOnly) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut MoveOnly); (&raw mut self.v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for MoveOnly { - unsafe fn move_assign(&mut self, o: *mut MoveOnly) -> *mut MoveOnly { + unsafe fn move_assign(&mut self, o: RvalueRefUnsafe) -> *mut MoveOnly { + let o = (o.as_ptr() as *mut MoveOnly); if ((self as *mut MoveOnly) == (o)) { return &mut (*(self as *mut MoveOnly)); } @@ -73,7 +75,7 @@ impl Default for ConstMoveAssign { } pub unsafe fn make_0(this: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut m)); + ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -86,31 +88,31 @@ unsafe fn main_0() -> i32 { object_unsafe!(a, MoveOnly(1)); object_unsafe!(b, MoveOnly(2)); object_unsafe!(c, MoveOnly(3)); - assign_unsafe!(a = Moved(b)); + assign_unsafe!(a = RvalueRefUnsafe(b)); assert!(((a.v) == (2))); assert!(((b.v) == (0))); (unsafe { let mut _o: MoveOnly = ::zero_init(); MoveOnly::construct(&mut _o, 3); - assign_unsafe!(b = Moved(_o)) + assign_unsafe!(b = RvalueRefUnsafe(_o)) }); - assign_unsafe!(c = Moved((*assign_unsafe!(a = Moved(b))))); + assign_unsafe!(c = RvalueRefUnsafe((*assign_unsafe!(a = RvalueRefUnsafe(b))))); assert!((((b.v) == (0)) && ((a.v) == (0))) && ((c.v) == (3))); (unsafe { let mut _o: MoveOnly = ::zero_init(); MoveOnly::construct(&mut _o, 5); - assign_unsafe!(a = Moved(_o)) + assign_unsafe!(a = RvalueRefUnsafe(_o)) }); assert!(((a.v) == (5))); (unsafe { let mut _o: MoveOnly = ::zero_init(); (unsafe { make_0(&mut _o, 6) }); - assign_unsafe!(a = Moved(_o)) + assign_unsafe!(a = RvalueRefUnsafe(_o)) }); assert!(((a.v) == (6))); (unsafe { let _o: *mut MoveOnly = &mut a; - assign_unsafe!(a = Moved(*_o)) + assign_unsafe!(a = RvalueRefUnsafe(*_o)) }); assert!(((a.v) == (6))); let mut vec_: Vec = Vec::new(); @@ -125,7 +127,7 @@ unsafe fn main_0() -> i32 { } }; object_unsafe!(d, MoveOnly(8)); - assign_unsafe!(vec_[(0_usize)] = Moved(d)); + assign_unsafe!(vec_[(0_usize)] = RvalueRefUnsafe(d)); assert!(((vec_[(0_usize)].v) == (8))); assert!(((d.v) == (0))); object_unsafe!(m, ConstMoveAssign); diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index 7df880a284..e160e190c5 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -20,7 +20,8 @@ impl MoveOnly { } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(&mut self, o: *mut MoveOnly) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut MoveOnly); (&raw mut self.v).write((*o).v); (*o).v = 0; } @@ -72,14 +73,16 @@ impl ThrowingMove { } } impl CopyConstructibleUnsafe for ThrowingMove { - unsafe fn copy_constructor(&mut self, o: *const ThrowingMove) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const ThrowingMove); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } } impl MoveConstructibleUnsafe for ThrowingMove { - unsafe fn move_constructor(&mut self, o: *mut ThrowingMove) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut ThrowingMove); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); @@ -104,14 +107,16 @@ impl NoexceptMove { } } impl CopyConstructibleUnsafe for NoexceptMove { - unsafe fn copy_constructor(&mut self, o: *const NoexceptMove) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const NoexceptMove); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((((*o).copies) + (1))); (&raw mut self.moves).write((*o).moves); } } impl MoveConstructibleUnsafe for NoexceptMove { - unsafe fn move_constructor(&mut self, o: *mut NoexceptMove) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut NoexceptMove); (&raw mut self.v).write((*o).v); (&raw mut self.copies).write((*o).copies); (&raw mut self.moves).write((((*o).moves) + (1))); @@ -123,7 +128,7 @@ pub unsafe fn by_value_0(m: *mut MoveOnly) -> i32 { } pub unsafe fn make_1(this: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut m)); + ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -134,13 +139,13 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(a, MoveOnly(1)); - object_unsafe!(b, MoveOnly, Moved(&mut a)); + object_unsafe!(b, MoveOnly, RvalueRefUnsafe::bind(&mut a)); assert!(((b.v) == (1))); assert!(((a.v) == (0))); - object_unsafe!(c, MoveOnly, Moved(&mut b)); + object_unsafe!(c, MoveOnly, RvalueRefUnsafe::bind(&mut b)); assert!(((c.v) == (1))); assert!(((b.v) == (0))); - object_unsafe!(d, MoveOnly, Moved(&mut c)); + object_unsafe!(d, MoveOnly, RvalueRefUnsafe::bind(&mut c)); assert!(((d.v) == (1))); assert!(((c.v) == (0))); object_unsafe!(e, MoveOnly, |e| (unsafe { make_1(e, 5,) })); @@ -155,7 +160,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _m: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _m, Moved(&mut e)); + ConstructFromUnsafe::construct_from(&mut _m, RvalueRefUnsafe::bind(&mut e)); by_value_0(&mut _m) }) == (5)) ); @@ -188,13 +193,13 @@ unsafe fn main_0() -> i32 { assert!(((t1.moves) == (0))); assert!(((t.v) == (1))); object_unsafe!(n, NoexceptMove(2)); - object_unsafe!(n1, NoexceptMove, Moved(&mut n)); + object_unsafe!(n1, NoexceptMove, RvalueRefUnsafe::bind(&mut n)); assert!(((n1.v) == (2))); assert!(((n1.copies) == (0))); assert!(((n1.moves) == (1))); assert!(((n.v) == (0))); object_unsafe!(g, MoveOnly(3)); - object_unsafe!(g1, MoveOnly, Moved(&mut g)); + object_unsafe!(g1, MoveOnly, RvalueRefUnsafe::bind(&mut g)); assert!(((g1.v) == (3))); assert!(((g.v) == (0))); let mut nv: Vec = Vec::new(); diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index f50a3cf2c6..99b8494846 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -27,7 +27,10 @@ impl Chain { return &mut (*(self as *mut Chain)); } pub unsafe fn take(&mut self, this: *mut Chain) { - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut (*(self as *mut Chain)))); + ConstructFromUnsafe::construct_from( + &mut *this, + RvalueRefUnsafe::bind(&mut (*(self as *mut Chain))), + ); return; } pub unsafe fn copy(&self, this: *mut Chain) { @@ -39,12 +42,14 @@ impl Chain { } } impl CopyConstructibleUnsafe for Chain { - unsafe fn copy_constructor(&mut self, o: *const Chain) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Chain); (&raw mut self.v).write((((*o).v) + (100))); } } impl MoveConstructibleUnsafe for Chain { - unsafe fn move_constructor(&mut self, o: *mut Chain) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Chain); (&raw mut self.v).write((((*o).v) + (1))); (*o).v = 0; } @@ -66,7 +71,9 @@ unsafe fn main_0() -> i32 { object_unsafe!( b, Chain, - Moved((unsafe { Chain::add_5(&mut (*(unsafe { Chain::add_5(&mut b0, 1,) })), 1,) })) + RvalueRefUnsafe::bind( + (unsafe { Chain::add_5(&mut (*(unsafe { Chain::add_5(&mut b0, 1,) })), 1,) }) + ) ); assert!(((b.v) == (8)) && ((b0.v) == (0))); object_unsafe!(c, Chain, |c| { @@ -88,7 +95,10 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _c: Chain = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _c, Moved((unsafe { Chain::self_(&mut g) }))); + ConstructFromUnsafe::construct_from( + &mut _c, + RvalueRefUnsafe::bind((unsafe { Chain::self_(&mut g) })), + ); consume_0(&mut _c) }) == (21)) ); diff --git a/tests/unit/out/unsafe/pair.rs b/tests/unit/out/unsafe/pair.rs index 281a52e939..ea56436da7 100644 --- a/tests/unit/out/unsafe/pair.rs +++ b/tests/unit/out/unsafe/pair.rs @@ -67,8 +67,8 @@ unsafe fn main_0() -> i32 { let mut pd: *mut i32 = (&mut d.0 as *mut i32); let mut ps: *mut i32 = (&mut s.0 as *mut i32); { - assign_unsafe!(d.0 = Moved(s.0)); - assign_unsafe!(d.1 = Moved(s.1)); + assign_unsafe!(d.0 = RvalueRefUnsafe(s.0)); + assign_unsafe!(d.1 = RvalueRefUnsafe(s.1)); }; assert!(((*pd) == (3))); (*ps) = 5; @@ -94,8 +94,8 @@ unsafe fn main_0() -> i32 { .1 = 7; assert!(((p.1) == (7)) && ((q.1) == (4))); (*{ - assign_unsafe!(d.0 = Moved(q.0)); - assign_unsafe!(d.1 = Moved(q.1)); + assign_unsafe!(d.0 = RvalueRefUnsafe(q.0)); + assign_unsafe!(d.1 = RvalueRefUnsafe(q.1)); &mut d }) .0 = 8; diff --git a/tests/unit/out/unsafe/rule_of_five.rs b/tests/unit/out/unsafe/rule_of_five.rs index 769b92093f..4b8b928fd6 100644 --- a/tests/unit/out/unsafe/rule_of_five.rs +++ b/tests/unit/out/unsafe/rule_of_five.rs @@ -40,7 +40,8 @@ impl DestructibleUnsafe for Buffer { } } impl CopyConstructibleUnsafe for Buffer { - unsafe fn copy_constructor(&mut self, o: *const Buffer) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Buffer); (&raw mut self.data).write([0_i32; 4]); (&raw mut self.size).write((*o).size); { @@ -57,7 +58,8 @@ impl CopyConstructibleUnsafe for Buffer { } } impl MoveConstructibleUnsafe for Buffer { - unsafe fn move_constructor(&mut self, o: *mut Buffer) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Buffer); (&raw mut self.data).write([0_i32; 4]); (&raw mut self.size).write((*o).size); { @@ -76,7 +78,8 @@ impl MoveConstructibleUnsafe for Buffer { } } impl CopyAssignableUnsafe for Buffer { - unsafe fn copy_assign(&mut self, o: *const Buffer) -> *mut Buffer { + unsafe fn copy_assign(&mut self, o: LvalueRefUnsafe>) -> *mut Buffer { + let o = (o.as_ptr() as *const Buffer); if (((self as *mut Buffer).cast_const()) == (o)) { return &mut (*(self as *mut Buffer)); } @@ -95,7 +98,8 @@ impl CopyAssignableUnsafe for Buffer { } } impl MoveAssignableUnsafe for Buffer { - unsafe fn move_assign(&mut self, o: *mut Buffer) -> *mut Buffer { + unsafe fn move_assign(&mut self, o: RvalueRefUnsafe) -> *mut Buffer { + let o = (o.as_ptr() as *mut Buffer); if ((self as *mut Buffer) == (o)) { return &mut (*(self as *mut Buffer)); } @@ -117,7 +121,7 @@ impl MoveAssignableUnsafe for Buffer { } pub unsafe fn make_3(this: *mut Buffer, mut size: i32) { object_unsafe!(b, Buffer(size)); - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut b)); + ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(&mut b)); return; } pub fn main() { @@ -137,7 +141,7 @@ unsafe fn main_0() -> i32 { ); b.data[(0) as usize] = 100; assert!(((a.data[(0) as usize]) == (0))); - object_unsafe!(c, Buffer, Moved(&mut a)); + object_unsafe!(c, Buffer, RvalueRefUnsafe::bind(&mut a)); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (3)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (1)) @@ -153,14 +157,14 @@ unsafe fn main_0() -> i32 { (((d.size) == (4)) && ((d.data[(0) as usize]) == (100))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (2)) ); - assign_unsafe!(d = Moved(c)); + assign_unsafe!(d = RvalueRefUnsafe(c)); assert!( (((d.data[(0) as usize]) == (0)) && ((c.size) == (0))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (3)) ); (unsafe { let _o: *mut Buffer = &mut d; - assign_unsafe!(d = Moved(*_o)) + assign_unsafe!(d = RvalueRefUnsafe(*_o)) }); assert!( ((d.size) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (3)) diff --git a/tests/unit/out/unsafe/rule_of_three.rs b/tests/unit/out/unsafe/rule_of_three.rs index 2e29537a0a..045528c891 100644 --- a/tests/unit/out/unsafe/rule_of_three.rs +++ b/tests/unit/out/unsafe/rule_of_three.rs @@ -45,7 +45,8 @@ impl DestructibleUnsafe for Buffer { } } impl CopyConstructibleUnsafe for Buffer { - unsafe fn copy_constructor(&mut self, o: *const Buffer) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Buffer); (&raw mut self.data).write([0_i32; 4]); (&raw mut self.size).write((*o).size); { @@ -62,7 +63,8 @@ impl CopyConstructibleUnsafe for Buffer { } } impl CopyAssignableUnsafe for Buffer { - unsafe fn copy_assign(&mut self, o: *const Buffer) -> *mut Buffer { + unsafe fn copy_assign(&mut self, o: LvalueRefUnsafe>) -> *mut Buffer { + let o = (o.as_ptr() as *const Buffer); if (((self as *mut Buffer).cast_const()) == (o)) { return &mut (*(self as *mut Buffer)); } diff --git a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs index 7f50ce20eb..3a8c967e13 100644 --- a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs +++ b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs @@ -29,13 +29,15 @@ impl Elem { } } impl CopyConstructibleUnsafe for Elem { - unsafe fn copy_constructor(&mut self, o: *const Elem) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Elem); (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Elem { - unsafe fn move_constructor(&mut self, o: *mut Elem) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Elem); (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); } diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index bda3ad0366..5283e07f3a 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -54,7 +54,7 @@ pub unsafe fn size_t_in_rules_3() { let mut ar3: [u64; 3] = ar2.clone(); { for __i in 0..3 { - assign_unsafe!(ar3[__i] = Moved(ar[__i])); + assign_unsafe!(ar3[__i] = RvalueRefUnsafe(ar[__i])); } }; assert!(((ar3[1]) == (2_u64))); diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index fda45f4697..6d131b6f6a 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -26,25 +26,29 @@ impl DefaultConstructibleUnsafe for Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(&mut self, o: *mut Tracked) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut self.v).write((*o).v); } } impl CopyAssignableUnsafe for Tracked { - unsafe fn copy_assign(&mut self, o: *const Tracked) -> *mut Tracked { + unsafe fn copy_assign(&mut self, o: LvalueRefUnsafe>) -> *mut Tracked { + let o = (o.as_ptr() as *const Tracked); self.v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*(self as *mut Tracked)); } } impl MoveAssignableUnsafe for Tracked { - unsafe fn move_assign(&mut self, o: *mut Tracked) -> *mut Tracked { + unsafe fn move_assign(&mut self, o: RvalueRefUnsafe) -> *mut Tracked { + let o = (o.as_ptr() as *mut Tracked); self.v = (*o).v; return &mut (*(self as *mut Tracked)); } diff --git a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs index 4609748403..fd47735bab 100644 --- a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs @@ -30,7 +30,8 @@ impl Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(&mut self, other: *const Counted) { + unsafe fn copy_constructor(&mut self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const Counted); (&raw mut self.x).write((((*other).x) * (2))); (&raw mut self.y).write((((*other).y) * (2))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); diff --git a/tests/unit/out/unsafe/structured_binding_element_ctor.rs b/tests/unit/out/unsafe/structured_binding_element_ctor.rs index d314ca6c61..7323d360f6 100644 --- a/tests/unit/out/unsafe/structured_binding_element_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_element_ctor.rs @@ -22,13 +22,15 @@ impl Elem { } } impl CopyConstructibleUnsafe for Elem { - unsafe fn copy_constructor(&mut self, other: *const Elem) { + unsafe fn copy_constructor(&mut self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const Elem); (&raw mut self.v).write((((*other).v) + (100))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Elem { - unsafe fn move_constructor(&mut self, other: *mut Elem) { + unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut Elem); (&raw mut self.v).write((((*other).v) + (1000))); (*other).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); @@ -95,7 +97,7 @@ unsafe fn main_0() -> i32 { assert!(((t.a.v) == (50))); let mut __decomp_5: Two = { let mut __v: Two = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut t)); + ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut t)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == ((base_moves) + (2)))); @@ -118,7 +120,7 @@ unsafe fn main_0() -> i32 { Elem::construct(&mut __tmp_0, 7); { let mut __v: Elem = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut __tmp_0)); + ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut __tmp_0)); __v } }, @@ -127,7 +129,7 @@ unsafe fn main_0() -> i32 { Elem::construct(&mut __tmp_1, 8); { let mut __v: Elem = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut __tmp_1)); + ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut __tmp_1)); __v } }, diff --git a/tests/unit/out/unsafe/structured_binding_move_ctor.rs b/tests/unit/out/unsafe/structured_binding_move_ctor.rs index c7ff58e922..927ca66543 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -21,14 +21,16 @@ impl Movable { } } impl CopyConstructibleUnsafe for Movable { - unsafe fn copy_constructor(&mut self, other: *const Movable) { + unsafe fn copy_constructor(&mut self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const Movable); (&raw mut self.x).write((*other).x); (&raw mut self.y).write((*other).y); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Movable { - unsafe fn move_constructor(&mut self, other: *mut Movable) { + unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut Movable); (&raw mut self.x).write((*other).x); (&raw mut self.y).write((*other).y); (*other).x = 0; @@ -78,7 +80,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(m, Movable(3, 4)); let mut __decomp_2: Movable = { let mut __v: Movable = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut m)); + ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut m)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (1))); diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index 49556c0ee0..2dda18ed12 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -26,25 +26,29 @@ impl DefaultConstructibleUnsafe for Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(&mut self, o: *mut Tracked) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut self.v).write((*o).v); } } impl CopyAssignableUnsafe for Tracked { - unsafe fn copy_assign(&mut self, o: *const Tracked) -> *mut Tracked { + unsafe fn copy_assign(&mut self, o: LvalueRefUnsafe>) -> *mut Tracked { + let o = (o.as_ptr() as *const Tracked); self.v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*(self as *mut Tracked)); } } impl MoveAssignableUnsafe for Tracked { - unsafe fn move_assign(&mut self, o: *mut Tracked) -> *mut Tracked { + unsafe fn move_assign(&mut self, o: RvalueRefUnsafe) -> *mut Tracked { + let o = (o.as_ptr() as *mut Tracked); self.v = (*o).v; return &mut (*(self as *mut Tracked)); } @@ -132,7 +136,8 @@ impl CopyOnly { } } impl CopyConstructibleUnsafe for CopyOnly { - unsafe fn copy_constructor(&mut self, o: *const CopyOnly) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const CopyOnly); (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)).prefix_inc(); } @@ -143,7 +148,8 @@ impl DestructibleUnsafe for CopyOnly { } } impl CopyAssignableUnsafe for CopyOnly { - unsafe fn copy_assign(&mut self, o: *const CopyOnly) -> *mut CopyOnly { + unsafe fn copy_assign(&mut self, o: LvalueRefUnsafe>) -> *mut CopyOnly { + let o = (o.as_ptr() as *const CopyOnly); self.v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)).prefix_inc(); return &mut (*(self as *mut CopyOnly)); @@ -181,27 +187,31 @@ impl Moved { } } impl CopyConstructibleUnsafe for Moved { - unsafe fn copy_constructor(&mut self, o: *const Moved) { + unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Moved); (&raw mut self.v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Moved { - unsafe fn move_constructor(&mut self, o: *mut Moved) { + unsafe fn move_constructor(&mut self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Moved); (&raw mut self.v).write((*o).v); (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); } } impl CopyAssignableUnsafe for Moved { - unsafe fn copy_assign(&mut self, o: *const Moved) -> *mut Moved { + unsafe fn copy_assign(&mut self, o: LvalueRefUnsafe>) -> *mut Moved { + let o = (o.as_ptr() as *const Moved); self.v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*(self as *mut Moved)); } } impl MoveAssignableUnsafe for Moved { - unsafe fn move_assign(&mut self, o: *mut Moved) -> *mut Moved { + unsafe fn move_assign(&mut self, o: RvalueRefUnsafe) -> *mut Moved { + let o = (o.as_ptr() as *mut Moved); self.v = (*o).v; (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)).prefix_inc(); @@ -289,7 +299,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -306,7 +316,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -324,7 +334,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -598,7 +608,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -615,7 +625,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; From 32b3d57ad3bddba442ff76b539736b274f172f03 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 17:49:48 +0000 Subject: [PATCH 02/11] Add value category and cv markers --- libcc2rs-macros/src/assign.rs | 53 +++++++---- libcc2rs-macros/src/constructor.rs | 64 ++++++++++--- libcc2rs-macros/src/lib.rs | 4 +- libcc2rs/src/capture.rs | 12 +-- libcc2rs/src/constructor.rs | 123 ++++++++++++++---------- libcc2rs/src/lib.rs | 4 +- libcc2rs/src/object.rs | 146 +++++++---------------------- libcc2rs/src/swap.rs | 26 +++-- 8 files changed, 216 insertions(+), 216 deletions(-) diff --git a/libcc2rs-macros/src/assign.rs b/libcc2rs-macros/src/assign.rs index 8b5387f5e2..9d833c652c 100644 --- a/libcc2rs-macros/src/assign.rs +++ b/libcc2rs-macros/src/assign.rs @@ -6,11 +6,16 @@ use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::{quote, quote_spanned}; use syn::{Expr, ExprAssign, UnOp, parse_macro_input}; -// The argument of Moved(x), the C++ std::move(x). +// The argument of RvalueRef(x), or of RvalueRefUnsafe(x) in the unsafe model, +// the C++ std::move(x). fn moved(expr: &Expr) -> Option<&Expr> { match expr { Expr::Call(call) if call.args.len() == 1 => match &*call.func { - Expr::Path(path) if path.path.is_ident("Moved") => call.args.first(), + Expr::Path(path) + if path.path.is_ident("RvalueRef") || path.path.is_ident("RvalueRefUnsafe") => + { + call.args.first() + } _ => None, }, _ => None, @@ -34,29 +39,37 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let src_name = quote_spanned!(Span::mixed_site() => __src); // The source is evaluated first, as the right operand of a C++ =. let expanded = if is_unsafe { - let src = match moved(&right) { - Some(object) => quote!(::libcc2rs::Moved(&raw mut #object)), - None => quote!(&raw const #right), + let assign = match moved(&right) { + Some(object) => quote! { + let #src_name = ::libcc2rs::RvalueRefUnsafe::bind(&raw mut #object); + ::libcc2rs::MoveAssignableUnsafe::move_assign(&mut #left, #src_name) + }, + None => quote! { + let #src_name = ::libcc2rs::LvalueRefUnsafe::bind(&raw const #right); + ::libcc2rs::CopyAssignableUnsafe::copy_assign(&mut #left, #src_name) + }, }; - quote! { - unsafe { - let #src_name = #src; - ::libcc2rs::AssignFromUnsafe::assign_from(&mut #left, #src_name) - } - } + quote!(unsafe { #assign }) } else { - let src = match moved(&right) { + let dst = object_ptr(&left); + match moved(&right) { Some(object) => { let ptr = object_ptr(object); - quote!(::libcc2rs::Moved(#ptr)) + quote! { + { + let #src_name = ::libcc2rs::RvalueRef::bind(#ptr); + ::libcc2rs::MoveAssignable::move_assign(&#dst, #src_name) + } + } } - None => object_ptr(&right), - }; - let dst = object_ptr(&left); - quote! { - { - let #src_name = #src; - ::libcc2rs::AssignFrom::assign_from(&#dst, #src_name) + None => { + let ptr = object_ptr(&right); + quote! { + { + let #src_name = ::libcc2rs::LvalueRef::bind(#ptr); + ::libcc2rs::CopyAssignable::copy_assign(&#dst, #src_name) + } + } } } }; diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index 31a3815023..85baa0251a 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -139,19 +139,24 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - }; if is_unsafe { let src_ty = if is_move { - quote!(*mut Self) + quote!(::libcc2rs::RvalueRefUnsafe) } else { - quote!(*const Self) + quote!(::libcc2rs::LvalueRefUnsafe<::libcc2rs::Const>) }; let body = if is_move { - quote!(unsafe { ::libcc2rs::#copy_trait::#copy_method(self, src) }) + quote!(unsafe { + ::libcc2rs::#copy_trait::#copy_method( + self, + ::libcc2rs::LvalueRefUnsafe::bind(src.as_ptr()), + ) + }) } else if is_assign { quote! { - unsafe { *self = (*src).clone() }; + unsafe { *self = (*src.as_const_ptr()).clone() }; self } } else { - quote!(unsafe { ::std::ptr::write(self, (*src).clone()) }) + quote!(unsafe { ::std::ptr::write(self, (*src.as_const_ptr()).clone()) }) }; let ret = if is_assign { quote!(-> *mut Self) @@ -171,8 +176,16 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - } else { quote!() }; + let src_ty = if is_move { + quote!(::libcc2rs::RvalueRef) + } else { + quote!(::libcc2rs::LvalueRef<::libcc2rs::Const>) + }; let body = if is_move { - quote!(::libcc2rs::#copy_trait::#copy_method(this, src)) + quote!(::libcc2rs::#copy_trait::#copy_method( + this, + ::libcc2rs::LvalueRef::bind(src.as_pointer()), + )) } else if is_assign { quote! { this.write(src.with(Self::clone)); @@ -209,7 +222,7 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - }; quote! { impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause { - fn #method(this: &::libcc2rs::Ptr, src: ::libcc2rs::Ptr) #ret { + fn #method(this: &::libcc2rs::Ptr, src: #src_ty) #ret { #body } #copied @@ -356,10 +369,20 @@ fn impl_memberwise( }; let tr = quote!(::libcc2rs::#trait_name); if is_unsafe { - let (src_ty, src_field) = if is_move { - (quote!(*mut Self), quote!(&raw mut)) + let (src_ty, marker, object, src_field) = if is_move { + ( + quote!(::libcc2rs::RvalueRefUnsafe), + quote!(::libcc2rs::RvalueRefUnsafe), + quote!(as_ptr), + quote!(&raw mut), + ) } else { - (quote!(*const Self), quote!(&raw const)) + ( + quote!(::libcc2rs::LvalueRefUnsafe<::libcc2rs::Const>), + quote!(::libcc2rs::LvalueRefUnsafe), + quote!(as_const_ptr), + quote!(&raw const), + ) }; let (ret, tail) = if is_assign { (quote!(-> *mut Self), quote!(self)) @@ -369,12 +392,26 @@ fn impl_memberwise( return quote! { impl #impl_generics #tr for #name #ty_generics #where_clause { unsafe fn #method(&mut self, src: #src_ty) #ret { - #(unsafe { #tr::#method(&mut self.#members, #src_field (*src).#members) };)* + let src = src.#object(); + #(unsafe { + #tr::#method(&mut self.#members, #marker::bind(#src_field (*src).#members)) + };)* #tail } } }; } + let (src_ty, marker) = if is_move { + ( + quote!(::libcc2rs::RvalueRef), + quote!(::libcc2rs::RvalueRef), + ) + } else { + ( + quote!(::libcc2rs::LvalueRef<::libcc2rs::Const>), + quote!(::libcc2rs::LvalueRef), + ) + }; let (ret, tail) = if is_assign { (quote!(-> ::libcc2rs::Ptr), quote!(this.clone())) } else { @@ -382,10 +419,11 @@ fn impl_memberwise( }; quote! { impl #impl_generics #tr for #name #ty_generics #where_clause { - fn #method(this: &::libcc2rs::Ptr, src: ::libcc2rs::Ptr) #ret { + fn #method(this: &::libcc2rs::Ptr, src: #src_ty) #ret { + let src = src.as_pointer(); #(#tr::#method( &::libcc2rs::field_ptr!(this, #members), - ::libcc2rs::field_ptr!(src, #members), + #marker::bind(::libcc2rs::field_ptr!(src, #members)), );)* #tail } diff --git a/libcc2rs-macros/src/lib.rs b/libcc2rs-macros/src/lib.rs index 3b59de2c8b..ef35f8efcd 100644 --- a/libcc2rs-macros/src/lib.rs +++ b/libcc2rs-macros/src/lib.rs @@ -93,9 +93,9 @@ pub fn lambda_unsafe(input: TokenStream) -> TokenStream { } // assign!(a = b); // a = b; -// assign!(*p = Moved(b)); // *p = std::move(b); +// assign!(*p = RvalueRef(b)); // *p = std::move(b); // -// The C++ operator= of a class, picked by its source as AssignFrom does. Both +// The C++ operator= of a class, picked by its source. Both // operands are objects, written as in C++: a variable, or *p for the object // that the pointer p points to (in the unsafe model, any place). The source is // evaluated first. The result is the pointer that operator= returns. diff --git a/libcc2rs/src/capture.rs b/libcc2rs/src/capture.rs index 5e7445edf5..410bab06fe 100644 --- a/libcc2rs/src/capture.rs +++ b/libcc2rs/src/capture.rs @@ -95,7 +95,7 @@ impl CopyLambda>> for &&&Capture<'_, Value>> { let dst: Value> = Rc::new(RefCell::new(FnPtr::zero_init())); CopyConstructible::copy_constructor( &AsPointer::>::as_pointer(&dst), - AsPointer::>::as_pointer(self.0), + crate::LvalueRef::bind(AsPointer::>::as_pointer(self.0)), ); dst } @@ -127,7 +127,7 @@ impl CopyCtor> for &Capture< let dst: Value = Rc::new(RefCell::new(T::zero_init())); T::copy_constructor( &AsPointer::::as_pointer(&dst), - AsPointer::::as_pointer(self.0), + crate::LvalueRef::bind(AsPointer::::as_pointer(self.0)), ); dst } @@ -152,7 +152,7 @@ impl MoveWithCtor> for &&Cap let dst: Value = Rc::new(RefCell::new(T::zero_init())); T::move_constructor( &AsPointer::::as_pointer(&dst), - AsPointer::::as_pointer(self.0), + crate::RvalueRef::bind(AsPointer::::as_pointer(self.0)), ); dst } @@ -227,7 +227,7 @@ impl CopyLambdaUnsafe> for &&&CaptureUnsafe> { unsafe fn copy_capture(&self) -> FnPtr { let mut dst = std::mem::MaybeUninit::>::uninit(); unsafe { - (*dst.as_mut_ptr()).copy_constructor(self.0); + (*dst.as_mut_ptr()).copy_constructor(crate::LvalueRefUnsafe::bind(self.0)); dst.assume_init() } } @@ -251,7 +251,7 @@ impl CopyCtorUnsafe for &CaptureUnsafe { unsafe fn copy_capture(&self) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - (*dst.as_mut_ptr()).copy_constructor(self.0); + (*dst.as_mut_ptr()).copy_constructor(crate::LvalueRefUnsafe::bind(self.0)); dst.assume_init() } } @@ -275,7 +275,7 @@ impl MoveWithCtorUnsafe for &&CaptureUnsafe { unsafe fn move_capture(&self) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - (*dst.as_mut_ptr()).move_constructor(self.0); + (*dst.as_mut_ptr()).move_constructor(crate::RvalueRefUnsafe::bind(self.0)); dst.assume_init() } } diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index 7913dc19b3..e9fd43a27e 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -7,6 +7,7 @@ use crate::capture::{ use crate::fn_ptr::{FnPtr, FnSig}; use crate::initialization::ZeroInitialization; use crate::rc::{AsPointer, Ptr, Value}; +use crate::reference::{Const, LvalueRef, RvalueRef}; use crate::reinterpret::ByteRepr; use crate::void::AnyPtr; @@ -24,8 +25,8 @@ pub trait DefaultConstructible: Sized { } } -pub trait MoveConstructible: Sized { - fn move_constructor(this: &Ptr, src: Ptr); +pub trait MoveConstructible: ByteRepr + Sized { + fn move_constructor(this: &Ptr, src: RvalueRef); // Pushes to the vector that v points to an element that the move // constructor constructs in place from src. A type that moves by Clone, or @@ -38,7 +39,7 @@ pub trait MoveConstructible: Sized { elems.push(Self::zero_init()); elems.len() - 1 }); - Self::move_constructor(&v.decay().offset(i), src); + Self::move_constructor(&v.decay().offset(i), RvalueRef::bind(src)); } } @@ -47,7 +48,7 @@ pub trait TriviallyMoveConstructible: MoveConstructible { } pub trait CopyConstructible: MoveConstructible { - fn copy_constructor(this: &Ptr, src: Ptr); + fn copy_constructor(this: &Ptr, src: LvalueRef>); // A copy of the value that src points to, made by the copy constructor, // which a type with Clone clones. @@ -69,7 +70,7 @@ pub trait CopyConstructible: MoveConstructible { elems.push(Self::zero_init()); elems.len() - 1 }); - Self::copy_constructor(&v.decay().offset(i), src); + Self::copy_constructor(&v.decay().offset(i), LvalueRef::bind(src)); } // A copy of the elements of the vector that src points to, made by the @@ -89,13 +90,13 @@ pub trait TriviallyCopyConstructible: CopyConstructible { } pub trait CopyAssignable: MoveAssignable { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr; + fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr; } pub trait TriviallyCopyAssignable: CopyAssignable {} -pub trait MoveAssignable: Sized { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr; +pub trait MoveAssignable: ByteRepr + Sized { + fn move_assign(this: &Ptr, src: RvalueRef) -> Ptr; } pub trait TriviallyMoveAssignable: MoveAssignable {} @@ -155,16 +156,16 @@ pub trait DefaultConstructibleUnsafe { } } -pub trait MoveConstructibleUnsafe { +pub trait MoveConstructibleUnsafe: Sized { /// # Safety /// `src` must point to a live value. - unsafe fn move_constructor(&mut self, src: *mut Self); + unsafe fn move_constructor(&mut self, src: crate::RvalueRefUnsafe); } pub trait CopyConstructibleUnsafe: MoveConstructibleUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn copy_constructor(&mut self, src: *const Self); + unsafe fn copy_constructor(&mut self, src: crate::LvalueRefUnsafe>); } pub trait TriviallyMoveConstructibleUnsafe: MoveConstructibleUnsafe { @@ -182,15 +183,15 @@ pub trait TriviallyCopyConstructibleUnsafe: CopyConstructibleUnsafe { pub trait CopyAssignableUnsafe: MoveAssignableUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self; + unsafe fn copy_assign(&mut self, src: crate::LvalueRefUnsafe>) -> *mut Self; } pub trait TriviallyCopyAssignableUnsafe: CopyAssignableUnsafe {} -pub trait MoveAssignableUnsafe { +pub trait MoveAssignableUnsafe: Sized { /// # Safety /// `src` must point to a live value. - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self; + unsafe fn move_assign(&mut self, src: crate::RvalueRefUnsafe) -> *mut Self; } pub trait TriviallyMoveAssignableUnsafe: MoveAssignableUnsafe {} @@ -246,7 +247,7 @@ macro_rules! impl_copy_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn copy_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + fn copy_constructor(this: &$crate::Ptr, src: $crate::LvalueRef<$crate::Const>) { this.write(src.with(Self::clone)); } @@ -268,7 +269,7 @@ macro_rules! impl_copy_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn copy_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + fn copy_assign(this: &$crate::Ptr, src: $crate::LvalueRef<$crate::Const>) -> $crate::Ptr { this.write(src.with(Self::clone)); this.clone() } @@ -278,7 +279,8 @@ macro_rules! impl_copy_by_clone { where $ty: Clone, { - unsafe fn copy_constructor(&mut self, src: *const Self) { + unsafe fn copy_constructor(&mut self, src: $crate::LvalueRefUnsafe<$crate::Const>) { + let src = src.as_const_ptr(); unsafe { std::ptr::write(self, (*src).clone()) } } } @@ -287,7 +289,8 @@ macro_rules! impl_copy_by_clone { where $ty: Clone, { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(&mut self, src: $crate::LvalueRefUnsafe<$crate::Const>) -> *mut Self { + let src = src.as_const_ptr(); unsafe { *self = (*src).clone() }; self } @@ -302,7 +305,7 @@ macro_rules! impl_move_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn move_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + fn move_constructor(this: &$crate::Ptr, src: $crate::RvalueRef) { this.write(src.with(Self::clone)); } @@ -316,7 +319,7 @@ macro_rules! impl_move_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn move_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + fn move_assign(this: &$crate::Ptr, src: $crate::RvalueRef) -> $crate::Ptr { this.write(src.with(Self::clone)); this.clone() } @@ -326,7 +329,8 @@ macro_rules! impl_move_by_clone { where $ty: Clone, { - unsafe fn move_constructor(&mut self, src: *mut Self) { + unsafe fn move_constructor(&mut self, src: $crate::RvalueRefUnsafe) { + let src = src.as_ptr(); unsafe { std::ptr::write(self, (*src).clone()) } } } @@ -335,7 +339,8 @@ macro_rules! impl_move_by_clone { where $ty: Clone, { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(&mut self, src: $crate::RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); unsafe { *self = (*src).clone() }; self } @@ -455,7 +460,7 @@ macro_rules! impl_move_by_take { where $ty: Default + $crate::ByteRepr, { - fn move_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + fn move_constructor(this: &$crate::Ptr, src: $crate::RvalueRef) { let value = src.with_mut(std::mem::take); this.with_mut(|dst| *dst = value); } @@ -470,7 +475,7 @@ macro_rules! impl_move_by_take { where $ty: Default + $crate::ByteRepr, { - fn move_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + fn move_assign(this: &$crate::Ptr, src: $crate::RvalueRef) -> $crate::Ptr { let value = src.with_mut(std::mem::take); this.with_mut(|dst| *dst = value); this.clone() @@ -481,7 +486,8 @@ macro_rules! impl_move_by_take { where $ty: Default, { - unsafe fn move_constructor(&mut self, src: *mut Self) { + unsafe fn move_constructor(&mut self, src: $crate::RvalueRefUnsafe) { + let src = src.as_ptr(); unsafe { std::ptr::write(self, std::mem::take(&mut *src)) } } } @@ -490,7 +496,8 @@ macro_rules! impl_move_by_take { where $ty: Default, { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(&mut self, src: $crate::RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); unsafe { *self = std::mem::take(&mut *src) }; self } @@ -749,7 +756,7 @@ impl TriviallyDe } impl MoveConstructible for FnPtr { - fn move_constructor(this: &Ptr, src: Ptr) { + fn move_constructor(this: &Ptr, src: RvalueRef) { let value = src.with(FnPtr::move_from); this.with_mut(|dst| *dst = value); } @@ -762,7 +769,7 @@ impl TriviallyMoveConstructible for FnPtr { } impl CopyConstructible for FnPtr { - fn copy_constructor(this: &Ptr, src: Ptr) { + fn copy_constructor(this: &Ptr, src: LvalueRef>) { let value = src.with(FnPtr::copy_from); this.with_mut(|dst| *dst = value); } @@ -775,7 +782,7 @@ impl TriviallyCopyConstructible for FnPtr { } impl MoveAssignable for FnPtr { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr { + fn move_assign(this: &Ptr, src: RvalueRef) -> Ptr { ::move_constructor(this, src); this.clone() } @@ -784,7 +791,7 @@ impl MoveAssignable for FnPtr { impl TriviallyMoveAssignable for FnPtr {} impl CopyAssignable for FnPtr { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { + fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { ::copy_constructor(this, src); this.clone() } @@ -805,13 +812,15 @@ impl SwappableUnsafe for FnPtr { } impl MoveConstructibleUnsafe for FnPtr { - unsafe fn move_constructor(&mut self, src: *mut Self) { + unsafe fn move_constructor(&mut self, src: crate::RvalueRefUnsafe) { + let src = src.as_ptr(); unsafe { std::ptr::write(self, (*src).move_from()) } } } impl CopyConstructibleUnsafe for FnPtr { - unsafe fn copy_constructor(&mut self, src: *const Self) { + unsafe fn copy_constructor(&mut self, src: crate::LvalueRefUnsafe>) { + let src = src.as_const_ptr(); unsafe { std::ptr::write(self, (*src).copy_from()) } } } @@ -829,14 +838,16 @@ impl TriviallyCopyConstructibleUnsafe for FnPtr { } impl MoveAssignableUnsafe for FnPtr { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(&mut self, src: crate::RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); unsafe { *self = (*src).move_from() }; self } } impl CopyAssignableUnsafe for FnPtr { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(&mut self, src: crate::LvalueRefUnsafe>) -> *mut Self { + let src = src.as_const_ptr(); unsafe { *self = (*src).copy_from() }; self } @@ -873,8 +884,10 @@ fn assign_elems( } impl MoveConstructible for Box<[T]> { - fn move_constructor(this: &Ptr, src: Ptr) { - construct_elems(this, &src, T::move_constructor); + fn move_constructor(this: &Ptr, src: RvalueRef) { + construct_elems(this, &src, |dst, src| { + T::move_constructor(dst, RvalueRef::bind(src)) + }); } } @@ -887,8 +900,10 @@ impl TriviallyMov } impl CopyConstructible for Box<[T]> { - fn copy_constructor(this: &Ptr, src: Ptr) { - construct_elems(this, &src, T::copy_constructor); + fn copy_constructor(this: &Ptr, src: LvalueRef>) { + construct_elems(this, &src, |dst, src| { + T::copy_constructor(dst, LvalueRef::bind(src)) + }); } } @@ -901,16 +916,20 @@ impl TriviallyCop } impl MoveAssignable for Box<[T]> { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr { - assign_elems(this, &src, T::move_assign) + fn move_assign(this: &Ptr, src: RvalueRef) -> Ptr { + assign_elems(this, &src, |dst, src| { + T::move_assign(dst, RvalueRef::bind(src)) + }) } } impl TriviallyMoveAssignable for Box<[T]> {} impl CopyAssignable for Box<[T]> { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { - assign_elems(this, &src, T::copy_assign) + fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { + assign_elems(this, &src, |dst, src| { + T::copy_assign(dst, LvalueRef::bind(src)) + }) } } @@ -936,19 +955,21 @@ impl SwappableUnsafe for [T; N] { } impl MoveConstructibleUnsafe for [T; N] { - unsafe fn move_constructor(&mut self, src: *mut Self) { + unsafe fn move_constructor(&mut self, src: crate::RvalueRefUnsafe) { + let src = src.as_ptr(); let src = src as *mut T; for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.move_constructor(src.add(i)) } + unsafe { elem.move_constructor(crate::RvalueRefUnsafe::bind(src.add(i))) } } } } impl CopyConstructibleUnsafe for [T; N] { - unsafe fn copy_constructor(&mut self, src: *const Self) { + unsafe fn copy_constructor(&mut self, src: crate::LvalueRefUnsafe>) { + let src = src.as_const_ptr(); let src = src as *const T; for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.copy_constructor(src.add(i)) } + unsafe { elem.copy_constructor(crate::LvalueRefUnsafe::bind(src.add(i))) } } } } @@ -972,20 +993,22 @@ impl TriviallyCopyConstruct } impl MoveAssignableUnsafe for [T; N] { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(&mut self, src: crate::RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); let src = src as *mut T; for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.move_assign(src.add(i)) }; + unsafe { elem.move_assign(crate::RvalueRefUnsafe::bind(src.add(i))) }; } self } } impl CopyAssignableUnsafe for [T; N] { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(&mut self, src: crate::LvalueRefUnsafe>) -> *mut Self { + let src = src.as_const_ptr(); let src = src as *const T; for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.copy_assign(src.add(i)) }; + unsafe { elem.copy_assign(crate::LvalueRefUnsafe::bind(src.add(i))) }; } self } diff --git a/libcc2rs/src/lib.rs b/libcc2rs/src/lib.rs index 607b2280fa..3829ab4b51 100644 --- a/libcc2rs/src/lib.rs +++ b/libcc2rs/src/lib.rs @@ -61,6 +61,9 @@ pub use constructor::{ mod cmp; pub use cmp::*; +mod reference; +pub use reference::*; + mod conversion; pub use conversion::{CppFrom, CppFromUnsafe}; @@ -89,7 +92,6 @@ pub mod __capture { } mod object; -pub use object::{AssignFrom, AssignFromUnsafe, ConstructFrom, ConstructFromUnsafe, Moved}; // Used by object! and object_unsafe!. #[doc(hidden)] pub mod __object { diff --git a/libcc2rs/src/object.rs b/libcc2rs/src/object.rs index 37027338a2..a092643e71 100644 --- a/libcc2rs/src/object.rs +++ b/libcc2rs/src/object.rs @@ -7,8 +7,8 @@ // // object!(a, Buffer(4)); // Buffer a(4); // object!(a, Buffer::construct_2(4, 5)); // an overload of many -// object!(b, Buffer, a.as_pointer()); // Buffer b = a; -// object!(c, Buffer, Moved(b.as_pointer())); // Buffer c = std::move(b); +// object!(b, Buffer, LvalueRef::bind(a.as_pointer())); // Buffer b = a; +// object!(c, Buffer, RvalueRef::bind(b.as_pointer())); // Buffer c = std::move(b); // object!(d, Buffer); // Buffer d; // object!(e, Buffer, |e| make(Ptr::clone(e))); // Buffer e = make(); // @@ -16,12 +16,12 @@ // its storage (&Ptr). Assignment (libcc2rs-macros): // // assign!(d = a); // d = a; -// assign!(d = Moved(a)); // d = std::move(a); +// assign!(d = RvalueRef(a)); // d = std::move(a); // assign!(*p = a); // *p = a; // // object_unsafe! and assign_unsafe! are the same in the unsafe model, whose -// object sources are references or raw pointers (`&a`, `Moved(&mut a)`), and -// whose storage is &mut T. +// object sources are LvalueRefUnsafe::bind(&a) and RvalueRefUnsafe::bind(&mut a), +// and whose storage is &mut T. #![allow(private_bounds, clippy::missing_safety_doc)] @@ -31,113 +31,9 @@ use std::rc::Rc; use crate::capture::{ Destructible, DestructibleUnsafe, TriviallyDestructible, TriviallyDestructibleUnsafe, }; -use crate::constructor::{ - CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, - MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, -}; use crate::initialization::ZeroInitialization; use crate::rc::{AsPointer, Ptr, Value}; -// The C++ std::move of a source: construction and assignment from it use the -// move constructor and the move operator=. -pub struct Moved

(pub P); - -// Construction of *self from src, in the refcount model: copy from a Ptr, -// move from a Moved>. -pub trait ConstructFrom { - fn construct_from(&self, src: S); -} - -impl ConstructFrom> for Ptr { - #[inline(always)] - fn construct_from(&self, src: Ptr) { - T::copy_constructor(self, src) - } -} - -impl ConstructFrom>> for Ptr { - #[inline(always)] - fn construct_from(&self, src: Moved>) { - T::move_constructor(self, src.0) - } -} - -// The C++ operator= of *self from src, in the refcount model. -pub trait AssignFrom: Sized { - fn assign_from(&self, src: S) -> Self; -} - -impl AssignFrom> for Ptr { - #[inline(always)] - fn assign_from(&self, src: Ptr) -> Ptr { - T::copy_assign(self, src) - } -} - -impl AssignFrom>> for Ptr { - #[inline(always)] - fn assign_from(&self, src: Moved>) -> Ptr { - T::move_assign(self, src.0) - } -} - -// Construction of self from src, in the unsafe model: copy from a reference or -// a raw pointer, move from a Moved one. -pub trait ConstructFromUnsafe { - /// # Safety - /// `src` must point to a live value. - unsafe fn construct_from(&mut self, src: S); -} - -// The C++ operator= of self from src, in the unsafe model. -pub trait AssignFromUnsafe { - /// # Safety - /// `src` must point to a live value. - unsafe fn assign_from(&mut self, src: S) -> *mut Self; -} - -// The sources of the unsafe model: a reference or a raw pointer copies, and a -// Moved one moves. -macro_rules! unsafe_sources { - ($($src:ty),*) => {$( - impl<'a, T: CopyConstructibleUnsafe> ConstructFromUnsafe<$src> for T { - #[inline(always)] - unsafe fn construct_from(&mut self, src: $src) { - unsafe { T::copy_constructor(self, src) } - } - } - - impl<'a, T: CopyAssignableUnsafe> AssignFromUnsafe<$src> for T { - #[inline(always)] - unsafe fn assign_from(&mut self, src: $src) -> *mut T { - unsafe { T::copy_assign(self, src) } - } - } - )*}; -} - -unsafe_sources!(&'a T, &'a mut T, *const T, *mut T); - -macro_rules! unsafe_moved_sources { - ($($src:ty),*) => {$( - impl<'a, T: MoveConstructibleUnsafe> ConstructFromUnsafe> for T { - #[inline(always)] - unsafe fn construct_from(&mut self, src: Moved<$src>) { - unsafe { T::move_constructor(self, src.0) } - } - } - - impl<'a, T: MoveAssignableUnsafe> AssignFromUnsafe> for T { - #[inline(always)] - unsafe fn assign_from(&mut self, src: Moved<$src>) -> *mut T { - unsafe { T::move_assign(self, src.0) } - } - } - )*}; -} - -unsafe_moved_sources!(&'a mut T, *mut T); - // The pointer to an object of the assign! macro: a variable (Value) or a // reference (Ptr) to it. pub trait ObjectPtr { @@ -255,11 +151,19 @@ macro_rules! object { } $crate::object!(@guard $name); }; - ($name:ident, $ty:ty, $src:expr) => { + ($name:ident, $ty:ty, LvalueRef::bind($src:expr)) => { + let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); + $crate::CopyConstructible::copy_constructor( + &$crate::AsPointer::<$ty>::as_pointer(&$name), + $crate::LvalueRef::bind($src), + ); + $crate::object!(@guard $name); + }; + ($name:ident, $ty:ty, RvalueRef::bind($src:expr)) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); - $crate::ConstructFrom::construct_from( + $crate::MoveConstructible::move_constructor( &$crate::AsPointer::<$ty>::as_pointer(&$name), - $src, + $crate::RvalueRef::bind($src), ); $crate::object!(@guard $name); }; @@ -298,11 +202,25 @@ macro_rules! object_unsafe { } $crate::object_unsafe!(@guard $name); }; - ($name:ident, $ty:ty, $src:expr) => { + ($name:ident, $ty:ty, LvalueRefUnsafe::bind($src:expr)) => { + let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); + #[allow(unused_unsafe)] + unsafe { + $crate::CopyConstructibleUnsafe::copy_constructor( + &mut $name, + $crate::LvalueRefUnsafe::bind::<$ty>($src), + ) + }; + $crate::object_unsafe!(@guard $name); + }; + ($name:ident, $ty:ty, RvalueRefUnsafe::bind($src:expr)) => { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - $crate::ConstructFromUnsafe::construct_from(&mut $name, $src) + $crate::MoveConstructibleUnsafe::move_constructor( + &mut $name, + $crate::RvalueRefUnsafe::bind::<$ty>($src), + ) }; $crate::object_unsafe!(@guard $name); }; diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index d23affb9cc..f7308aaa41 100644 --- a/libcc2rs/src/swap.rs +++ b/libcc2rs/src/swap.rs @@ -50,7 +50,7 @@ pub fn pointer(value: &Value) -> Ptr { pub fn move_constructed(src: &Ptr) -> T { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - T::move_constructor(&pointer(&dst), src.clone()); + T::move_constructor(&pointer(&dst), crate::RvalueRef::bind(src.clone())); Rc::try_unwrap(dst).ok().unwrap().into_inner() } @@ -64,7 +64,7 @@ pub(crate) fn copy_constructed_in_storage, ) -> T { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - T::copy_constructor(&pointer(&dst), src); + T::copy_constructor(&pointer(&dst), crate::LvalueRef::bind(src)); Rc::try_unwrap(dst).ok().unwrap().into_inner() } @@ -73,7 +73,7 @@ pub(crate) fn copy_constructed_in_storage(src: *const T) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - (*dst.as_mut_ptr()).copy_constructor(src); + (*dst.as_mut_ptr()).copy_constructor(crate::LvalueRefUnsafe::bind(src)); dst.assume_init() } } @@ -81,7 +81,7 @@ pub unsafe fn copy_constructed_unsafe(src: *const T) pub unsafe fn move_constructed_unsafe(src: *mut T) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - (*dst.as_mut_ptr()).move_constructor(src); + (*dst.as_mut_ptr()).move_constructor(crate::RvalueRefUnsafe::bind(src)); dst.assume_init() } } @@ -156,9 +156,9 @@ where { let storage: Value = Rc::new(RefCell::new(T::zero_init())); let tmp = AsPointer::::as_pointer(&storage); - T::move_constructor(&tmp, this.clone()); - T::move_assign(this, other.clone()); - T::move_assign(&other, tmp.clone()); + T::move_constructor(&tmp, crate::RvalueRef::bind(this.clone())); + T::move_assign(this, crate::RvalueRef::bind(other.clone())); + T::move_assign(&other, crate::RvalueRef::bind(tmp.clone())); T::destroy(&tmp); } @@ -171,9 +171,15 @@ where let this: *mut T = this; let mut tmp = MaybeUninit::::uninit(); unsafe { - MoveConstructibleUnsafe::move_constructor(&mut *tmp.as_mut_ptr(), this); - MoveAssignableUnsafe::move_assign(&mut *this, other); - MoveAssignableUnsafe::move_assign(&mut *other, tmp.as_mut_ptr()); + MoveConstructibleUnsafe::move_constructor( + &mut *tmp.as_mut_ptr(), + crate::RvalueRefUnsafe::bind(this), + ); + MoveAssignableUnsafe::move_assign(&mut *this, crate::RvalueRefUnsafe::bind(other)); + MoveAssignableUnsafe::move_assign( + &mut *other, + crate::RvalueRefUnsafe::bind(tmp.as_mut_ptr()), + ); DestructibleUnsafe::destroy(&mut *tmp.as_mut_ptr()); } } From ccc03b637cabdcbd3d2f11a3638f1ae9ce6ee6f4 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 17:52:33 +0000 Subject: [PATCH 03/11] Update tests --- .../refcount/out_of_line_methods_cross_tu.rs | 2 +- .../unsafe/out_of_line_methods_cross_tu.rs | 2 +- tests/std/basic/out/refcount/basic.def.odr.rs | 17 +++++++++---- tests/std/basic/out/unsafe/basic.def.odr.rs | 8 +++---- .../out/refcount/class.copy.ctor.rs | 5 +++- .../class.ctor/out/unsafe/class.copy.ctor.rs | 2 +- .../out/refcount/expr.mptr.oper.rs | 5 +++- .../out/unsafe/expr.mptr.oper.rs | 8 ++++--- .../utility/out/refcount/forward-helpers.rs | 10 ++++---- .../utility/out/unsafe/forward-helpers.rs | 17 +++++++++---- tests/unit/out/refcount/copy_assign.rs | 6 ++--- tests/unit/out/refcount/copy_ctor.rs | 24 +++++++++---------- .../unit/out/refcount/copy_move_defaulted.rs | 15 +++++++----- tests/unit/out/refcount/fn_ptr_struct.rs | 2 +- tests/unit/out/refcount/forward_basic.rs | 4 ++-- tests/unit/out/refcount/forward_explicit.rs | 6 ++--- tests/unit/out/refcount/forward_pack.rs | 4 ++-- .../out/refcount/inline_container_fields.rs | 6 ++--- .../out/refcount/lambda_capture_copy_ctor.rs | 17 +++++++++---- .../out/refcount/lambda_move_only_capture.rs | 7 ++++-- tests/unit/out/refcount/map_try_emplace.rs | 18 +++++++++----- tests/unit/out/refcount/move_assign.rs | 2 +- tests/unit/out/refcount/move_ctor.rs | 6 ++--- tests/unit/out/refcount/move_this.rs | 6 ++--- tests/unit/out/refcount/rule_of_five.rs | 4 ++-- tests/unit/out/refcount/rule_of_three.rs | 4 ++-- .../unit/out/refcount/rvalue_rule_arg_move.rs | 2 +- tests/unit/out/refcount/size_t_ssize_t.rs | 3 +-- .../refcount/structured_binding_copy_ctor.rs | 2 +- .../structured_binding_element_ctor.rs | 8 +++---- .../refcount/structured_binding_move_ctor.rs | 2 +- tests/unit/out/unsafe/clone_vs_move.rs | 2 +- tests/unit/out/unsafe/copy_assign.rs | 16 +++++++++---- tests/unit/out/unsafe/copy_ctor.rs | 24 +++++++++---------- tests/unit/out/unsafe/copy_move_defaulted.rs | 14 +++++------ tests/unit/out/unsafe/fn_ptr_struct.rs | 2 +- tests/unit/out/unsafe/forward_basic.rs | 4 ++-- tests/unit/out/unsafe/forward_explicit.rs | 6 ++--- tests/unit/out/unsafe/forward_pack.rs | 4 ++-- .../out/unsafe/lambda_capture_copy_ctor.rs | 17 +++++++++---- .../out/unsafe/lambda_move_only_capture.rs | 4 ++-- tests/unit/out/unsafe/map_try_emplace.rs | 18 +++++++++----- tests/unit/out/unsafe/move_assign.rs | 2 +- tests/unit/out/unsafe/move_ctor.rs | 6 ++--- tests/unit/out/unsafe/move_this.rs | 9 ++++--- tests/unit/out/unsafe/rule_of_five.rs | 4 ++-- tests/unit/out/unsafe/rule_of_three.rs | 4 ++-- .../unsafe/structured_binding_copy_ctor.rs | 2 +- .../unsafe/structured_binding_element_ctor.rs | 14 +++++++---- .../unsafe/structured_binding_move_ctor.rs | 2 +- tests/unit/out/unsafe/vector2.rs | 2 +- 51 files changed, 227 insertions(+), 153 deletions(-) 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 9655a8a0c3..fb39ef405f 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 @@ -85,7 +85,7 @@ fn main_0() -> i32 { object!(m, M(2)); object!(n, M, RvalueRef::bind(m.as_pointer())); assert!(({ (*n.borrow()).v } == 2)); - object!(c, M, n.as_pointer()); + object!(c, M, LvalueRef::bind(n.as_pointer())); assert!(({ (*c.borrow()).v } == 3)); assert!((({ move_m_1(5,) }) == 5)); object!(derived, Derived(3)); 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 359ab857d3..629afc8e5a 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 @@ -83,7 +83,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(m, M(2)); object_unsafe!(n, M, RvalueRefUnsafe::bind(&mut m)); assert!(((n.v) == (2))); - object_unsafe!(c, M, &n); + object_unsafe!(c, M, LvalueRefUnsafe::bind(&n)); assert!(((c.v) == (3))); assert!(((unsafe { move_m_1(5,) }) == (5))); object_unsafe!(derived, Derived(3)); diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 351d7c57df..737101c440 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -293,7 +293,10 @@ pub fn test_14() { let r: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), (r).clone()); + CopyConstructible::copy_constructor( + &__v.as_pointer(), + LvalueRef::bind((r).clone()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -330,12 +333,15 @@ pub fn test_16() { let k: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), k.as_pointer()); + CopyConstructible::copy_constructor( + &__v.as_pointer(), + LvalueRef::bind(k.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || -> i32 { - object!(c, HasConstexprCtor, k.as_pointer()); + object!(c, HasConstexprCtor, LvalueRef::bind(k.as_pointer())); return { (*c.borrow()).m }; } ))); @@ -399,7 +405,10 @@ pub fn test_19() { Rc::new(RefCell::new( ::zero_init(), )); - ConstructFrom::construct_from(&__v.as_pointer(), k.as_pointer()); + CopyConstructible::copy_constructor( + &__v.as_pointer(), + LvalueRef::bind(k.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 9989b758cb..bef0dd041c 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -257,7 +257,7 @@ pub unsafe fn test_14() { { let r: LifetimeTracked = { let mut __v: LifetimeTracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, r); + CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(r)); __v }; }, @@ -294,12 +294,12 @@ pub unsafe fn test_16() { { let k: HasConstexprCtor = { let mut __v: HasConstexprCtor = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &k); + CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(&k)); __v }; }, || -> i32 { - object_unsafe!(c, HasConstexprCtor, &k); + object_unsafe!(c, HasConstexprCtor, LvalueRefUnsafe::bind(&k)); return c.m; } ); @@ -359,7 +359,7 @@ pub unsafe fn test_19() { let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = { let mut __v: p5_2_mutable_subobject_is_odr_used_HasMutableMember = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &k); + CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(&k)); __v }; }, diff --git a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs index 08b9d4ad1e..359828e042 100644 --- a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs @@ -32,7 +32,10 @@ pub fn pass_0( let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - ConstructFrom::construct_from(&__v.as_pointer(), RvalueRef::bind(object.as_pointer())); + MoveConstructible::move_constructor( + &__v.as_pointer(), + RvalueRef::bind(object.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } diff --git a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs index 015e862a50..e989542b7b 100644 --- a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs @@ -31,7 +31,7 @@ pub unsafe fn pass_0( return { let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut object)); + MoveConstructibleUnsafe::move_constructor(&mut __v, RvalueRefUnsafe::bind(&mut object)); __v }; } diff --git a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs index d6aab29f0b..a546a55043 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs @@ -186,7 +186,10 @@ pub fn test_11() { object!( from_lvalue, p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - (holder.as_pointer()).member::(pm) + LvalueRef::bind( + (holder.as_pointer()) + .member::(pm) + ) ); assert!((copyCount_9.with(|rc| *rc.borrow()) == 1)); assert!((moveCount_10.with(|rc| *rc.borrow()) == 0)); diff --git a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs index 7d21f723db..01c434c67a 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs @@ -168,9 +168,11 @@ pub unsafe fn test_11() { object_unsafe!( from_lvalue, p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) - .wrapping_byte_offset(pm) - .cast::()) + LvalueRefUnsafe::bind( + &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) + .wrapping_byte_offset(pm) + .cast::()) + ) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moveCount_10)) == (0))); diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 862671435d..74a10081d1 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -64,11 +64,11 @@ impl Default for p6_forward_like_Holder { } } pub fn take_1(this: Ptr, self_: Ptr) { - ConstructFrom::construct_from(&this, field_ptr!(self_, member)); + CopyConstructible::copy_constructor(&this, LvalueRef::bind(field_ptr!(self_, member))); return; } pub fn take_2(this: Ptr, self_: Ptr) { - ConstructFrom::construct_from(&this, RvalueRef::bind(field_ptr!(self_, member))); + MoveConstructible::move_constructor(&this, RvalueRef::bind(field_ptr!(self_, member))); return; } pub fn test_3() { @@ -169,11 +169,11 @@ impl Default for p10_forward_in_template_A { } } pub fn make_5(this: Ptr, source: Ptr) { - ConstructFrom::construct_from(&this, (source).clone()); + CopyConstructible::copy_constructor(&this, LvalueRef::bind((source).clone())); return; } pub fn make_6(this: Ptr, source: Ptr) { - ConstructFrom::construct_from(&this, RvalueRef::bind((source).clone())); + MoveConstructible::move_constructor(&this, RvalueRef::bind((source).clone())); return; } pub fn test_7() { @@ -257,7 +257,7 @@ pub fn test_8() { object!( copied, p11_move_if_noexcept_ThrowingMove, - copied_from.as_pointer() + LvalueRef::bind(copied_from.as_pointer()) ); assert!(({ (*copied.borrow()).value } == 2) && ({ (*copied_from.borrow()).value } == 2)); } diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index 28e5f3210d..1417fb9766 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -65,11 +65,14 @@ impl Default for p6_forward_like_Holder { } } pub unsafe fn take_1(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - ConstructFromUnsafe::construct_from(&mut *this, &(*self_).member); + CopyConstructibleUnsafe::copy_constructor(&mut *this, LvalueRefUnsafe::bind(&(*self_).member)); return; } pub unsafe fn take_2(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(&mut (*self_).member)); + MoveConstructibleUnsafe::move_constructor( + &mut *this, + RvalueRefUnsafe::bind(&mut (*self_).member), + ); return; } pub unsafe fn test_3() { @@ -178,11 +181,11 @@ impl Default for p10_forward_in_template_A { } } pub unsafe fn make_5(this: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A) { - ConstructFromUnsafe::construct_from(&mut *this, source); + CopyConstructibleUnsafe::copy_constructor(&mut *this, LvalueRefUnsafe::bind(source)); return; } pub unsafe fn make_6(this: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A) { - ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(source)); + MoveConstructibleUnsafe::move_constructor(&mut *this, RvalueRefUnsafe::bind(source)); return; } pub unsafe fn test_7() { @@ -271,7 +274,11 @@ pub unsafe fn test_8() { ); assert!(((moved.value) == (1)) && ((moved_from.value) == (0))); object_unsafe!(copied_from, p11_move_if_noexcept_ThrowingMove(2)); - object_unsafe!(copied, p11_move_if_noexcept_ThrowingMove, &copied_from); + object_unsafe!( + copied, + p11_move_if_noexcept_ThrowingMove, + LvalueRefUnsafe::bind(&copied_from) + ); assert!(((copied.value) == (2)) && ((copied_from.value) == (2))); } pub fn main() { diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index 7443c7774d..d4aa6c5a6c 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -258,14 +258,14 @@ impl CopyConstructible for Swapped { } impl CopyAssignable for Swapped { fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { - object!(__o, Swapped, src.as_pointer()); + object!(__o, Swapped, LvalueRef::bind(src.as_pointer())); SwappedImpl::copy_assign(this, Ptr::clone(&__o.as_pointer())); Ptr::clone(this) } } impl MoveAssignable for Swapped { fn move_assign(this: &Ptr, src: RvalueRef) -> Ptr { - object!(__o, Swapped, src); + object!(__o, Swapped, RvalueRef::bind(src.as_pointer())); SwappedImpl::copy_assign(this, Ptr::clone(&__o.as_pointer())); Ptr::clone(this) } @@ -524,7 +524,7 @@ fn main_0() -> i32 { object!(sw2, Swapped(2)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_o.as_pointer(), sw2.as_pointer()); + CopyConstructible::copy_constructor(&_o.as_pointer(), LvalueRef::bind(sw2.as_pointer())); SwappedImpl::copy_assign(&sw1.as_pointer(), _o.as_pointer()) }); assert!(({ (*sw1.borrow()).v } == 2) && (swap_copies_2.with(|rc| *rc.borrow()) == 1)); diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index c2a048960e..117ba477c5 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -227,7 +227,7 @@ pub fn by_value_2(c: Ptr) -> i32 { } pub fn make_3(this: Ptr, mut v: i32) { object!(c, Counted(v)); - ConstructFrom::construct_from(&this, c.as_pointer()); + CopyConstructible::copy_constructor(&this, LvalueRef::bind(c.as_pointer())); return; } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] @@ -309,9 +309,9 @@ pub fn main() { } fn main_0() -> i32 { object!(a, Counted(1)); - object!(b, Counted, a.as_pointer()); - object!(c, Counted, a.as_pointer()); - object!(d, Counted, a.as_pointer()); + object!(b, Counted, LvalueRef::bind(a.as_pointer())); + object!(c, Counted, LvalueRef::bind(a.as_pointer())); + object!(d, Counted, LvalueRef::bind(a.as_pointer())); assert!((copies_0.with(|rc| *rc.borrow()) == 3)); assert!( (({ (*b.borrow()).v } == 1) && ({ (*c.borrow()).v } == 1)) && ({ (*d.borrow()).v } == 1) @@ -319,7 +319,7 @@ fn main_0() -> i32 { assert!( (({ let _c: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_c.as_pointer(), a.as_pointer()); + CopyConstructible::copy_constructor(&_c.as_pointer(), LvalueRef::bind(a.as_pointer())); by_value_2(_c.as_pointer()) }) == 1) ); @@ -331,7 +331,7 @@ fn main_0() -> i32 { assert!(({ (*f.borrow()).v } == 6)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); object!(g, Counted(7)); - object!(h, Counted, g.as_pointer()); + object!(h, Counted, LvalueRef::bind(g.as_pointer())); assert!(({ (*h.borrow()).v } == 7)); assert!((copies_0.with(|rc| *rc.borrow()) == 6)); let hold: Value = Rc::new(RefCell::new(Holder { @@ -353,7 +353,7 @@ fn main_0() -> i32 { }, ]), })); - object!(hold2, Holder, hold.as_pointer()); + object!(hold2, Holder, LvalueRef::bind(hold.as_pointer())); assert!( (({ (*hold2.borrow()).c.v } == 8) && (array_elem!(hold2.as_pointer(), arr, 0).with(|__s| __s.v) == 9)) @@ -365,7 +365,7 @@ fn main_0() -> i32 { assert!(({ (*vec_.borrow())[0_usize].v } == 1)); assert!((copies_0.with(|rc| *rc.borrow()) == 10)); object!(i1, Ignored(1)); - object!(i2, Ignored, i1.as_pointer()); + object!(i2, Ignored, LvalueRef::bind(i1.as_pointer())); assert!(({ (*i1.borrow()).v } == 1) && ({ (*i2.borrow()).v } == -1_i32)); assert!((copies_0.with(|rc| *rc.borrow()) == 11)); let o: Value = Rc::new(RefCell::new(Owner { @@ -378,7 +378,7 @@ fn main_0() -> i32 { object!(o2, Owner, RvalueRef::bind(o.as_pointer())); assert!(({ (*o2.borrow()).box_.val } == 3)); object!(ol1, OutOfLine(5)); - object!(ol2, OutOfLine, ol1.as_pointer()); + object!(ol2, OutOfLine, LvalueRef::bind(ol1.as_pointer())); assert!(({ (*ol2.borrow()).v } == 105)); assert!((copies_0.with(|rc| *rc.borrow()) == 12)); object!(n, NonConst); @@ -388,16 +388,16 @@ fn main_0() -> i32 { assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); object!(t1, Tracked); - object!(t2, Tracked, t1.as_pointer()); + object!(t2, Tracked, LvalueRef::bind(t1.as_pointer())); assign!(t2 = t1); assert!(({ (*t1.borrow()).copied_from } == 2)); object!(ct, Tracked); - object!(t3, Tracked, ct.as_pointer()); + object!(t3, Tracked, LvalueRef::bind(ct.as_pointer())); ({ touch_1((ct.as_pointer())) }); assert!(({ (*ct.borrow()).copied_from } == 2)); let mut before: i32 = copies_0.with(|rc| *rc.borrow()); object!(der, Derived); - object!(der2, Derived, der.as_pointer()); + object!(der2, Derived, LvalueRef::bind(der.as_pointer())); assert!(({ (*der2.borrow()).c.v } == 20) && (copies_0.with(|rc| *rc.borrow()) == (before + 1))); let mut range: Vec = { let mut __tmp_0 = { vec_.decay().begin() }; diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index ab3f3f9346..27a85e01f5 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -515,7 +515,10 @@ pub struct OutOfLineDefaulted { impl CopyConstructible for OutOfLineDefaulted { fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - ConstructFrom::construct_from(&field_ptr!(this, x), field_ptr!(_a0, x)); + CopyConstructible::copy_constructor( + &field_ptr!(this, x), + LvalueRef::bind(field_ptr!(_a0, x)), + ); field!((*this), v).write(_a0.with(|__s| __s.v)); } } @@ -672,7 +675,7 @@ fn main_0() -> i32 { (({ (*m3.borrow()).v } == 7) && ({ (*m4.borrow()).v } == 7)) && ({ (*m1.borrow()).v } == 0) ); object!(u, UserCopyDefaultMove(8)); - object!(u1, UserCopyDefaultMove, u.as_pointer()); + object!(u1, UserCopyDefaultMove, LvalueRef::bind(u.as_pointer())); object!(u2, UserCopyDefaultMove, RvalueRef::bind(u.as_pointer())); assert!( (({ (*u1.borrow()).v } == 108) && ({ (*u2.borrow()).v } == 8)) @@ -720,7 +723,7 @@ fn main_0() -> i32 { let mut __tmp_2 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( &__v.as_pointer(), RvalueRef::bind(bufs.decay().offset(0_usize)), ); @@ -829,7 +832,7 @@ fn main_0() -> i32 { { object!(d, CtorSeesThis); assert!(({ { (*d.borrow()).self_.clone() } } == { (d.as_pointer()) })); - object!(e, CtorSeesThis, d.as_pointer()); + object!(e, CtorSeesThis, LvalueRef::bind(d.as_pointer())); assert!(({ { (*e.borrow()).self_.clone() } } == { (e.as_pointer()) })); object!(f, CtorSeesThis::construct_1(3)); assert!( @@ -838,7 +841,7 @@ fn main_0() -> i32 { ); object!(h1, HasCtorSeesThis); assert!(({ { (*h1.borrow()).x.self_.clone() } } == { (field_ptr!(h1.as_pointer(), x)) })); - object!(h2, HasCtorSeesThis, h1.as_pointer()); + object!(h2, HasCtorSeesThis, LvalueRef::bind(h1.as_pointer())); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); object!(h3, HasCtorSeesThis, RvalueRef::bind(h1.as_pointer())); assert!(({ { (*h3.borrow()).x.self_.clone() } } == { (field_ptr!(h3.as_pointer(), x)) })); @@ -870,7 +873,7 @@ fn main_0() -> i32 { && ({ { (*o1.borrow()).x.self_.clone() } } == { (field_ptr!(o1.as_pointer(), x)) }) ); (*o1.borrow_mut()).v = 2; - object!(o2, OutOfLineDefaulted, o1.as_pointer()); + object!(o2, OutOfLineDefaulted, LvalueRef::bind(o1.as_pointer())); assert!( ({ (*o2.borrow()).v } == 2) && ({ { (*o2.borrow()).x.self_.clone() } } == { (field_ptr!(o2.as_pointer(), x)) }) diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index da8283dd16..76e2abf598 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -116,7 +116,7 @@ fn main_0() -> i32 { FnPtr::, Ptr)>::new(scale_move_only_3); object!(n, MoveOnly, |n| ({ let _arg0: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_arg0.as_pointer(), RvalueRef::bind(m.as_pointer())); + MoveConstructible::move_constructor(&_arg0.as_pointer(), RvalueRef::bind(m.as_pointer())); sc.call(Ptr::clone(n), _arg0.as_pointer()) })); assert!((({ MoveOnlyImpl::get(&n.as_pointer(),) }) == 40)); diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index 5f113f8680..87b85ec058 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -140,10 +140,10 @@ pub trait HolderImpl { } impl HolderImpl for Ptr { fn construct_1(&self, x: Ptr) { - ConstructFrom::construct_from(&field_ptr!(self, t), (x).clone()); + CopyConstructible::copy_constructor(&field_ptr!(self, t), LvalueRef::bind((x).clone())); } fn construct_2(&self, x: Ptr) { - ConstructFrom::construct_from(&field_ptr!(self, t), RvalueRef::bind((x).clone())); + MoveConstructible::move_constructor(&field_ptr!(self, t), RvalueRef::bind((x).clone())); } } pub trait TrackedImpl { diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index 9567f72d68..c9b44df499 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -54,7 +54,7 @@ pub fn chosen_overload_3(_a0: Ptr) -> Overload { return Overload_kIntRvalueOverload; } pub fn copy_or_move_into_param_4(this: Ptr, t: Ptr) { - ConstructFrom::construct_from(&this, RvalueRef::bind((t).clone())); + MoveConstructible::move_constructor(&this, RvalueRef::bind((t).clone())); return; } pub fn main() { @@ -74,7 +74,7 @@ fn main_0() -> i32 { object!(b, Tracked(6)); object!(moved, Tracked, |moved| ({ let _t: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_t.as_pointer(), RvalueRef::bind(b.as_pointer())); + MoveConstructible::move_constructor(&_t.as_pointer(), RvalueRef::bind(b.as_pointer())); copy_or_move_into_param_4(Ptr::clone(moved), _t.as_pointer()) })); assert!(({ (*moved.borrow()).v } == 6)); @@ -84,7 +84,7 @@ fn main_0() -> i32 { object!(c, Tracked(7)); object!(copied, Tracked, |copied| ({ let _t: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_t.as_pointer(), c.as_pointer()); + CopyConstructible::copy_constructor(&_t.as_pointer(), LvalueRef::bind(c.as_pointer())); copy_or_move_into_param_4(Ptr::clone(copied), _t.as_pointer()) })); assert!(({ (*copied.borrow()).v } == 7)); diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index f2aa10c943..2e8357a76d 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -157,8 +157,8 @@ pub trait PairImpl { } impl PairImpl for Ptr { fn construct(&self, x: Ptr, y: Ptr) { - ConstructFrom::construct_from(&field_ptr!(self, a), (x).clone()); - ConstructFrom::construct_from(&field_ptr!(self, b), RvalueRef::bind((y).clone())); + CopyConstructible::copy_constructor(&field_ptr!(self, a), LvalueRef::bind((x).clone())); + MoveConstructible::move_constructor(&field_ptr!(self, b), RvalueRef::bind((y).clone())); } } pub trait TrackedImpl { diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 3ec91d34ac..1736c00ff5 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -403,8 +403,7 @@ fn main_0() -> i32 { )); let __p: Ptr = __v.decay(); for __i in 0..3 { - __p.offset(__i) - .construct_from(RvalueRef::bind(ca.decay().offset(__i))); + ::move_constructor(&__p.offset(__i), RvalueRef::bind(ca.decay().offset(__i))); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -462,8 +461,7 @@ fn main_0() -> i32 { )); let __p: Ptr> = __v.decay(); for __i in 0..2 { - __p.offset(__i) - .construct_from(RvalueRef::bind(va.decay().offset(__i))); + >::move_constructor(&__p.offset(__i), RvalueRef::bind(va.decay().offset(__i))); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 3cebb30512..49441c12e7 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -79,7 +79,10 @@ fn main_0() -> i32 { { let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), c.as_pointer()); + CopyConstructible::copy_constructor( + &__v.as_pointer(), + LvalueRef::bind(c.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -101,12 +104,15 @@ fn main_0() -> i32 { { let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), c.as_pointer()); + CopyConstructible::copy_constructor( + &__v.as_pointer(), + LvalueRef::bind(c.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, |this: Ptr| { - ConstructFrom::construct_from(&this, c.as_pointer()); + CopyConstructible::copy_constructor(&this, LvalueRef::bind(c.as_pointer())); return; } ) @@ -129,7 +135,10 @@ fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 2, _>(|__i: usize| { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), arr.decay().offset(__i)); + CopyConstructible::copy_constructor( + &__v.as_pointer(), + LvalueRef::bind(arr.decay().offset(__i)), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index df1392fe12..784bb741ca 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -36,7 +36,10 @@ fn main_0() -> i32 { { let h: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), RvalueRef::bind(o.as_pointer())); + MoveConstructible::move_constructor( + &__v.as_pointer(), + RvalueRef::bind(o.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -98,7 +101,7 @@ impl OwnerImpl for Ptr { { let self_: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( &__v.as_pointer(), RvalueRef::bind((*self).clone()), ); diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 3e652fd364..51526799e4 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -382,7 +382,10 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), (__tmp_6).clone()); + CopyConstructible::copy_constructor( + &__v.as_pointer(), + LvalueRef::bind((__tmp_6).clone()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -421,7 +424,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( &__v.as_pointer(), RvalueRef::bind((__tmp_7).clone()), ); @@ -462,7 +465,10 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), (__tmp_8).clone()); + CopyConstructible::copy_constructor( + &__v.as_pointer(), + LvalueRef::bind((__tmp_8).clone()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -502,7 +508,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( &__v.as_pointer(), RvalueRef::bind((__tmp_9).clone()), ); @@ -653,7 +659,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( &__v.as_pointer(), RvalueRef::bind((__tmp_12).clone()), ); @@ -696,7 +702,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( &__v.as_pointer(), RvalueRef::bind((__tmp_14).clone()), ); diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index a79729013f..80cc71bc26 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -65,7 +65,7 @@ impl Default for ConstMoveAssign { } pub fn make_0(this: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(&this, RvalueRef::bind(m.as_pointer())); + MoveConstructible::move_constructor(&this, RvalueRef::bind(m.as_pointer())); return; } pub fn main() { diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index 05c5b401ea..1543ac1a03 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -109,7 +109,7 @@ pub fn by_value_0(m: Ptr) -> i32 { } pub fn make_1(this: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(&this, RvalueRef::bind(m.as_pointer())); + MoveConstructible::move_constructor(&this, RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -139,7 +139,7 @@ fn main_0() -> i32 { assert!( (({ let _m: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_m.as_pointer(), RvalueRef::bind(e.as_pointer())); + MoveConstructible::move_constructor(&_m.as_pointer(), RvalueRef::bind(e.as_pointer())); by_value_0(_m.as_pointer()) }) == 5) ); @@ -166,7 +166,7 @@ fn main_0() -> i32 { assert!(({ (*m1.borrow()).mark } == 1)); assert!(({ (*m2.borrow()).mark } == 10)); object!(t, ThrowingMove(1)); - object!(t1, ThrowingMove, t.as_pointer()); + object!(t1, ThrowingMove, LvalueRef::bind(t.as_pointer())); assert!(({ (*t1.borrow()).v } == 1)); assert!(({ (*t1.borrow()).copies } == 1)); assert!(({ (*t1.borrow()).moves } == 0)); diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index d8eeca8089..96aa283c64 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -67,7 +67,7 @@ fn main_0() -> i32 { assert!( (({ let _c: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( &_c.as_pointer(), RvalueRef::bind(({ ChainImpl::self_(&g.as_pointer()) })), ); @@ -106,11 +106,11 @@ impl ChainImpl for Ptr { return (*self).clone(); } fn take(&self, this: Ptr) { - ConstructFrom::construct_from(&this, RvalueRef::bind((*self).clone())); + MoveConstructible::move_constructor(&this, RvalueRef::bind((*self).clone())); return; } fn copy(&self, this: Ptr) { - ConstructFrom::construct_from(&this, (*self).clone()); + CopyConstructible::copy_constructor(&this, LvalueRef::bind((*self).clone())); return; } fn self_(&self) -> Ptr { diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index 7c3d1dec81..6a173db7d7 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -115,7 +115,7 @@ impl MoveAssignable for Buffer { } pub fn make_3(this: Ptr, mut size: i32) { object!(b, Buffer(size)); - ConstructFrom::construct_from(&this, RvalueRef::bind(b.as_pointer())); + MoveConstructible::move_constructor(&this, RvalueRef::bind(b.as_pointer())); return; } pub fn main() { @@ -125,7 +125,7 @@ pub fn main() { fn main_0() -> i32 { { object!(a, Buffer(4)); - object!(b, Buffer, a.as_pointer()); + object!(b, Buffer, LvalueRef::bind(a.as_pointer())); assert!( ((alive_0.with(|rc| *rc.borrow()) == 2) && (copies_1.with(|rc| *rc.borrow()) == 1)) && (moves_2.with(|rc| *rc.borrow()) == 0) diff --git a/tests/unit/out/refcount/rule_of_three.rs b/tests/unit/out/refcount/rule_of_three.rs index 23dd4dc0d2..20b71421ad 100644 --- a/tests/unit/out/refcount/rule_of_three.rs +++ b/tests/unit/out/refcount/rule_of_three.rs @@ -96,7 +96,7 @@ pub fn main() { fn main_0() -> i32 { { object!(a, Buffer(4)); - object!(b, Buffer, a.as_pointer()); + object!(b, Buffer, LvalueRef::bind(a.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 2) && (copies_1.with(|rc| *rc.borrow()) == 1)); array_elem!(b.as_pointer(), data, 0).write(100); assert!(((array_elem!(a.as_pointer(), data, 0).read()) == 0)); @@ -110,7 +110,7 @@ fn main_0() -> i32 { assert!((copies_1.with(|rc| *rc.borrow()) == 2)); assert!((({ sum_2(a.as_pointer(),) }) == 6)); assert!((({ sum_2(b.as_pointer(),) }) == 106)); - object!(d, Buffer, a.as_pointer()); + object!(d, Buffer, LvalueRef::bind(a.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 4) && (copies_1.with(|rc| *rc.borrow()) == 3)); assert!( ({ (*a.borrow()).size } == 4) && ((array_elem!(a.as_pointer(), data, 3).read()) == 3) diff --git a/tests/unit/out/refcount/rvalue_rule_arg_move.rs b/tests/unit/out/refcount/rvalue_rule_arg_move.rs index 16858720a7..3a948d8ec7 100644 --- a/tests/unit/out/refcount/rvalue_rule_arg_move.rs +++ b/tests/unit/out/refcount/rvalue_rule_arg_move.rs @@ -62,7 +62,7 @@ fn main_0() -> i32 { let mut __tmp_0 = { >::from(v.decay().end()) }; let __a2 = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), RvalueRef::bind(a.as_pointer())); + MoveConstructible::move_constructor(&__v.as_pointer(), RvalueRef::bind(a.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; (*v.borrow_mut()).insert(__tmp_0.index(), __a2); diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 3b6a67899a..feb0a033d3 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -63,8 +63,7 @@ pub fn size_t_in_rules_3() { Rc::new(RefCell::new((0..3).map(|_| ::zero_init()).collect())); let __p: Ptr = __v.decay(); for __i in 0..3 { - __p.offset(__i) - .construct_from(RvalueRef::bind(ar2.decay().offset(__i))); + ::move_constructor(&__p.offset(__i), RvalueRef::bind(ar2.decay().offset(__i))); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); diff --git a/tests/unit/out/refcount/structured_binding_copy_ctor.rs b/tests/unit/out/refcount/structured_binding_copy_ctor.rs index e32d36803e..ecb25ee799 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -49,7 +49,7 @@ fn main_0() -> i32 { object!(s, Counted(1, 2)); let __decomp_2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), s.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), LvalueRef::bind(s.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((copies_0.with(|rc| *rc.borrow()) == 1)); diff --git a/tests/unit/out/refcount/structured_binding_element_ctor.rs b/tests/unit/out/refcount/structured_binding_element_ctor.rs index 3d6eeef3bf..2990228981 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -85,7 +85,7 @@ fn main_0() -> i32 { let mut base_moves: i32 = moves_1.with(|rc| *rc.borrow()); let __decomp_3: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), t.as_pointer()); + CopyConstructible::copy_constructor(&__v.as_pointer(), LvalueRef::bind(t.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((copies_0.with(|rc| *rc.borrow()) == (base_copies + 2))); @@ -99,7 +99,7 @@ fn main_0() -> i32 { assert!(({ (*t.borrow()).a.v } == 50)); let __decomp_5: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), RvalueRef::bind(t.as_pointer())); + MoveConstructible::move_constructor(&__v.as_pointer(), RvalueRef::bind(t.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((moves_1.with(|rc| *rc.borrow()) == (base_moves + 2))); @@ -122,7 +122,7 @@ fn main_0() -> i32 { ElemImpl::construct(&__tmp_0.as_pointer(), 7); { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( &__v.as_pointer(), RvalueRef::bind(__tmp_0.as_pointer()), ); @@ -134,7 +134,7 @@ fn main_0() -> i32 { ElemImpl::construct(&__tmp_1.as_pointer(), 8); { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( &__v.as_pointer(), RvalueRef::bind(__tmp_1.as_pointer()), ); diff --git a/tests/unit/out/refcount/structured_binding_move_ctor.rs b/tests/unit/out/refcount/structured_binding_move_ctor.rs index 7fcf86294c..5c6bf4d9dd 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -75,7 +75,7 @@ fn main_0() -> i32 { object!(m, Movable(3, 4)); let __decomp_2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), RvalueRef::bind(m.as_pointer())); + MoveConstructible::move_constructor(&__v.as_pointer(), RvalueRef::bind(m.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((moves_1.with(|rc| *rc.borrow()) == 1)); diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index ed66325643..b53963d62e 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -310,7 +310,7 @@ unsafe fn main_0() -> i32 { assert!(((b2.w) == (2))); let mut v4: Vec = Vec::new(); { - v4.assign_from(&mut v2); + v4.copy_assign(LvalueRefUnsafe::bind(&mut v2)); }; { let mut i: i32 = 0; diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 3c2c0fe549..ff4235e15c 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -194,7 +194,7 @@ impl CopyAssignableUnsafe for ExplicitOperatorCall { ) -> *mut ExplicitOperatorCall { let o = (o.as_ptr() as *const ExplicitOperatorCall); { - self.w.assign_from(&(*o).w); + self.w.copy_assign(LvalueRefUnsafe::bind(&(*o).w)); }; return &mut (*(self as *mut ExplicitOperatorCall)); } @@ -239,14 +239,22 @@ impl CopyConstructibleUnsafe for Swapped { } impl CopyAssignableUnsafe for Swapped { unsafe fn copy_assign(&mut self, src: LvalueRefUnsafe>) -> *mut Self { - object_unsafe!(__o, Swapped, (src.as_ptr() as *const Swapped)); + object_unsafe!( + __o, + Swapped, + LvalueRefUnsafe::bind((src.as_ptr() as *const Swapped)) + ); Swapped::copy_assign(&mut *self, &mut __o); &mut *self } } impl MoveAssignableUnsafe for Swapped { unsafe fn move_assign(&mut self, src: RvalueRefUnsafe) -> *mut Self { - object_unsafe!(__o, Swapped, src); + object_unsafe!( + __o, + Swapped, + RvalueRefUnsafe::bind((src.as_ptr() as *mut Swapped)) + ); Swapped::copy_assign(&mut *self, &mut __o); &mut *self } @@ -490,7 +498,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(sw2, Swapped(2)); (unsafe { let mut _o: Swapped = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _o, &sw2); + CopyConstructibleUnsafe::copy_constructor(&mut _o, LvalueRefUnsafe::bind(&sw2)); Swapped::copy_assign(&mut sw1, &mut _o) }); assert!( diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 4b7a0e1b9e..0ad94f9767 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -217,7 +217,7 @@ pub unsafe fn by_value_2(c: *mut Counted) -> i32 { } pub unsafe fn make_3(this: *mut Counted, mut v: i32) { object_unsafe!(c, Counted(v)); - ConstructFromUnsafe::construct_from(&mut *this, &c); + CopyConstructibleUnsafe::copy_constructor(&mut *this, LvalueRefUnsafe::bind(&c)); return; } #[repr(C)] @@ -297,15 +297,15 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(a, Counted(1)); - object_unsafe!(b, Counted, &a); - object_unsafe!(c, Counted, &a); - object_unsafe!(d, Counted, &a); + object_unsafe!(b, Counted, LvalueRefUnsafe::bind(&a)); + object_unsafe!(c, Counted, LvalueRefUnsafe::bind(&a)); + object_unsafe!(d, Counted, LvalueRefUnsafe::bind(&a)); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (3))); assert!((((b.v) == (1)) && ((c.v) == (1))) && ((d.v) == (1))); assert!( ((unsafe { let mut _c: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _c, &a); + CopyConstructibleUnsafe::copy_constructor(&mut _c, LvalueRefUnsafe::bind(&a)); by_value_2(&mut _c) }) == (1)) ); @@ -317,7 +317,7 @@ unsafe fn main_0() -> i32 { assert!(((f.v) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5))); object_unsafe!(g, Counted(7)); - object_unsafe!(h, Counted, &g); + object_unsafe!(h, Counted, LvalueRefUnsafe::bind(&g)); assert!(((h.v) == (7))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (6))); let mut hold: Holder = Holder { @@ -339,7 +339,7 @@ unsafe fn main_0() -> i32 { }, ], }; - object_unsafe!(hold2, Holder, &hold); + object_unsafe!(hold2, Holder, LvalueRefUnsafe::bind(&hold)); assert!( (((hold2.c.v) == (8)) && ((hold2.arr[(0) as usize].v) == (9))) && ((hold2.arr[(1) as usize].v) == (10)) @@ -350,7 +350,7 @@ unsafe fn main_0() -> i32 { assert!(((vec_[(0_usize)].v) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (10))); object_unsafe!(i1, Ignored(1)); - object_unsafe!(i2, Ignored, &i1); + object_unsafe!(i2, Ignored, LvalueRefUnsafe::bind(&i1)); assert!(((i1.v) == (1)) && ((i2.v) == (-1_i32))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (11))); let mut o: Owner = Owner { @@ -363,7 +363,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o)); assert!(((o2.box_.val) == (3))); object_unsafe!(ol1, OutOfLine(5)); - object_unsafe!(ol2, OutOfLine, &ol1); + object_unsafe!(ol2, OutOfLine, LvalueRefUnsafe::bind(&ol1)); assert!(((ol2.v) == (105))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (12))); object_unsafe!(n, NonConst); @@ -373,16 +373,16 @@ unsafe fn main_0() -> i32 { assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); object_unsafe!(t1, Tracked); - object_unsafe!(t2, Tracked, &t1); + object_unsafe!(t2, Tracked, LvalueRefUnsafe::bind(&t1)); assign_unsafe!(t2 = t1); assert!(((t1.copied_from) == (2))); object_unsafe!(ct, Tracked); - object_unsafe!(t3, Tracked, &ct); + object_unsafe!(t3, Tracked, LvalueRefUnsafe::bind(&ct)); (unsafe { touch_1((&ct as *const Tracked)) }); assert!(((ct.copied_from) == (2))); let mut before: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)); object_unsafe!(der, Derived); - object_unsafe!(der2, Derived, &der); + object_unsafe!(der2, Derived, LvalueRefUnsafe::bind(&der)); assert!( ((der2.c.v) == (20)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((before) + (1))) diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 0260c44400..099f8a00ff 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -476,7 +476,7 @@ impl OutOfLineDefaulted { impl CopyConstructibleUnsafe for OutOfLineDefaulted { unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const OutOfLineDefaulted); - ConstructFromUnsafe::construct_from(&mut self.x, &(*_a0).x); + CopyConstructibleUnsafe::copy_constructor(&mut self.x, LvalueRefUnsafe::bind(&(*_a0).x)); (&raw mut self.v).write((*_a0).v); } } @@ -536,7 +536,7 @@ impl CopyAssignableUnsafe for OutOfLineAssign { }); self.v = (*_a0).v; { - self.w.assign_from(&(*_a0).w); + self.w.copy_assign(LvalueRefUnsafe::bind(&(*_a0).w)); }; return &mut (*(self as *mut OutOfLineAssign)); } @@ -627,7 +627,7 @@ unsafe fn main_0() -> i32 { assign_unsafe!(m4 = RvalueRefUnsafe(m1)); assert!((((m3.v) == (7)) && ((m4.v) == (7))) && ((m1.v) == (0))); object_unsafe!(u, UserCopyDefaultMove(8)); - object_unsafe!(u1, UserCopyDefaultMove, &u); + object_unsafe!(u1, UserCopyDefaultMove, LvalueRefUnsafe::bind(&u)); object_unsafe!(u2, UserCopyDefaultMove, RvalueRefUnsafe::bind(&mut u)); assert!((((u1.v) == (108)) && ((u2.v) == (8))) && ((u.v) == (8))); object_unsafe!(u3, UserCopyDefaultMove(1)); @@ -657,7 +657,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { { let mut __v: Buffer = ::zero_init(); - ConstructFromUnsafe::construct_from( + MoveConstructibleUnsafe::move_constructor( &mut __v, RvalueRefUnsafe::bind(&mut bufs[(0_usize)]), ); @@ -785,13 +785,13 @@ unsafe fn main_0() -> i32 { { object_unsafe!(d, CtorSeesThis); assert!(((d.self_) == (&mut d as *mut CtorSeesThis))); - object_unsafe!(e, CtorSeesThis, &d); + object_unsafe!(e, CtorSeesThis, LvalueRefUnsafe::bind(&d)); assert!(((e.self_) == (&mut e as *mut CtorSeesThis))); object_unsafe!(f, CtorSeesThis::construct_1(3)); assert!(((f.self_) == (&mut f as *mut CtorSeesThis)) && ((f.id) == (3))); object_unsafe!(h1, HasCtorSeesThis); assert!(((h1.x.self_) == (&mut h1.x as *mut CtorSeesThis))); - object_unsafe!(h2, HasCtorSeesThis, &h1); + object_unsafe!(h2, HasCtorSeesThis, LvalueRefUnsafe::bind(&h1)); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); object_unsafe!(h3, HasCtorSeesThis, RvalueRefUnsafe::bind(&mut h1)); assert!(((h3.x.self_) == (&mut h3.x as *mut CtorSeesThis))); @@ -817,7 +817,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(o1, OutOfLineDefaulted()); assert!(((o1.v) == (1)) && ((o1.x.self_) == (&mut o1.x as *mut CtorSeesThis))); o1.v = 2; - object_unsafe!(o2, OutOfLineDefaulted, &o1); + object_unsafe!(o2, OutOfLineDefaulted, LvalueRefUnsafe::bind(&o1)); assert!(((o2.v) == (2)) && ((o2.x.self_) == (&mut o2.x as *mut CtorSeesThis))); object_unsafe!(a1, OutOfLineAssign); object_unsafe!(a2, OutOfLineAssign); diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index d24050a39a..5cb90689ef 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -118,7 +118,7 @@ unsafe fn main_0() -> i32 { let mut sc: Option = Some(scale_move_only_3); object_unsafe!(n, MoveOnly, |n| (unsafe { let mut _arg0: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _arg0, RvalueRefUnsafe::bind(&mut m)); + MoveConstructibleUnsafe::move_constructor(&mut _arg0, RvalueRefUnsafe::bind(&mut m)); (sc).unwrap()(n, &mut _arg0) })); assert!(((unsafe { MoveOnly::get(&n,) }) == (40))); diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 4d89990e69..b66eee8b5e 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -51,12 +51,12 @@ pub unsafe fn chosen_overload_1(_a0: *mut Tracked) -> Overload { } impl Holder { pub unsafe fn construct_1(&mut self, x: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut self.t, x); + CopyConstructibleUnsafe::copy_constructor(&mut self.t, LvalueRefUnsafe::bind(x)); } } impl Holder { pub unsafe fn construct_2(&mut self, x: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut self.t, RvalueRefUnsafe::bind(x)); + MoveConstructibleUnsafe::move_constructor(&mut self.t, RvalueRefUnsafe::bind(x)); } } #[repr(C)] diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index e72c94b191..e036583283 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -58,7 +58,7 @@ pub unsafe fn chosen_overload_3(_a0: *mut i32) -> Overload { return Overload_kIntRvalueOverload; } pub unsafe fn copy_or_move_into_param_4(this: *mut Tracked, t: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(t)); + MoveConstructibleUnsafe::move_constructor(&mut *this, RvalueRefUnsafe::bind(t)); return; } pub fn main() { @@ -78,7 +78,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(b, Tracked(6)); object_unsafe!(moved, Tracked, |moved| (unsafe { let mut _t: Tracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _t, RvalueRefUnsafe::bind(&mut b)); + MoveConstructibleUnsafe::move_constructor(&mut _t, RvalueRefUnsafe::bind(&mut b)); copy_or_move_into_param_4(moved, &mut _t) })); assert!(((moved.v) == (6))); @@ -88,7 +88,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(c, Tracked(7)); object_unsafe!(copied, Tracked, |copied| (unsafe { let mut _t: Tracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _t, &c); + CopyConstructibleUnsafe::copy_constructor(&mut _t, LvalueRefUnsafe::bind(&c)); copy_or_move_into_param_4(copied, &mut _t) })); assert!(((copied.v) == (7))); diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index 7dd9c333c6..2815e5b724 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -93,8 +93,8 @@ pub unsafe fn forward_pack_7( } impl Pair { pub unsafe fn construct(&mut self, x: *mut Tracked, y: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut self.a, x); - ConstructFromUnsafe::construct_from(&mut self.b, RvalueRefUnsafe::bind(y)); + CopyConstructibleUnsafe::copy_constructor(&mut self.a, LvalueRefUnsafe::bind(x)); + MoveConstructibleUnsafe::move_constructor(&mut self.b, RvalueRefUnsafe::bind(y)); } } #[repr(C)] diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index 095d60f552..cf58fedf4c 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -77,7 +77,7 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &c); + CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(&c)); __v }; }, @@ -99,12 +99,18 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &c); + CopyConstructibleUnsafe::copy_constructor( + &mut __v, + LvalueRefUnsafe::bind(&c), + ); __v }; }, |this: *mut Counted| { - ConstructFromUnsafe::construct_from(&mut *this, &c); + CopyConstructibleUnsafe::copy_constructor( + &mut *this, + LvalueRefUnsafe::bind(&c), + ); return; } ) @@ -124,7 +130,10 @@ unsafe fn main_0() -> i32 { { let arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|__i: usize| { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &arr[(__i)]); + CopyConstructibleUnsafe::copy_constructor( + &mut __v, + LvalueRefUnsafe::bind(&arr[(__i)]), + ); __v }); }, diff --git a/tests/unit/out/unsafe/lambda_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index 09851468bd..6c363fac40 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -21,7 +21,7 @@ impl Owner { { let self_: Owner = { let mut __v: Owner = ::zero_init(); - ConstructFromUnsafe::construct_from( + MoveConstructibleUnsafe::move_constructor( &mut __v, RvalueRefUnsafe::bind(&mut (*(self as *mut Owner))), ); @@ -63,7 +63,7 @@ unsafe fn main_0() -> i32 { { let h: Owner = { let mut __v: Owner = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut o)); + MoveConstructibleUnsafe::move_constructor(&mut __v, RvalueRefUnsafe::bind(&mut o)); __v }; }, diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 53b71be062..beb2e0c347 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -268,7 +268,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_6,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, __tmp_6); + CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(__tmp_6)); __v }), }; @@ -284,7 +284,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_7,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(__tmp_7)); + MoveConstructibleUnsafe::move_constructor(&mut __v, RvalueRefUnsafe::bind(__tmp_7)); __v }), }; @@ -301,7 +301,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_8,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, __tmp_8); + CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(__tmp_8)); __v }), }; @@ -318,7 +318,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_9,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(__tmp_9)); + MoveConstructibleUnsafe::move_constructor(&mut __v, RvalueRefUnsafe::bind(__tmp_9)); __v }), }; @@ -392,7 +392,10 @@ unsafe fn main_0() -> i32 { { (__tmp_12,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(__tmp_12)); + MoveConstructibleUnsafe::move_constructor( + &mut __v, + RvalueRefUnsafe::bind(__tmp_12), + ); __v }), } @@ -415,7 +418,10 @@ unsafe fn main_0() -> i32 { { (__tmp_14,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(__tmp_14)); + MoveConstructibleUnsafe::move_constructor( + &mut __v, + RvalueRefUnsafe::bind(__tmp_14), + ); __v }), } diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index 7cc995e041..5b6108840f 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -75,7 +75,7 @@ impl Default for ConstMoveAssign { } pub unsafe fn make_0(this: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(&mut m)); + MoveConstructibleUnsafe::move_constructor(&mut *this, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index e160e190c5..5ec26c2124 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -128,7 +128,7 @@ pub unsafe fn by_value_0(m: *mut MoveOnly) -> i32 { } pub unsafe fn make_1(this: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(&mut m)); + MoveConstructibleUnsafe::move_constructor(&mut *this, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -160,7 +160,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _m: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _m, RvalueRefUnsafe::bind(&mut e)); + MoveConstructibleUnsafe::move_constructor(&mut _m, RvalueRefUnsafe::bind(&mut e)); by_value_0(&mut _m) }) == (5)) ); @@ -187,7 +187,7 @@ unsafe fn main_0() -> i32 { assert!(((m1.mark) == (1))); assert!(((m2.mark) == (10))); object_unsafe!(t, ThrowingMove(1)); - object_unsafe!(t1, ThrowingMove, &t); + object_unsafe!(t1, ThrowingMove, LvalueRefUnsafe::bind(&t)); assert!(((t1.v) == (1))); assert!(((t1.copies) == (1))); assert!(((t1.moves) == (0))); diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index 99b8494846..e1b84c6eb0 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -27,14 +27,17 @@ impl Chain { return &mut (*(self as *mut Chain)); } pub unsafe fn take(&mut self, this: *mut Chain) { - ConstructFromUnsafe::construct_from( + MoveConstructibleUnsafe::move_constructor( &mut *this, RvalueRefUnsafe::bind(&mut (*(self as *mut Chain))), ); return; } pub unsafe fn copy(&self, this: *mut Chain) { - ConstructFromUnsafe::construct_from(&mut *this, &(*(self as *const Chain))); + CopyConstructibleUnsafe::copy_constructor( + &mut *this, + LvalueRefUnsafe::bind(&(*(self as *const Chain))), + ); return; } pub unsafe fn self_(&mut self) -> *mut Chain { @@ -95,7 +98,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _c: Chain = ::zero_init(); - ConstructFromUnsafe::construct_from( + MoveConstructibleUnsafe::move_constructor( &mut _c, RvalueRefUnsafe::bind((unsafe { Chain::self_(&mut g) })), ); diff --git a/tests/unit/out/unsafe/rule_of_five.rs b/tests/unit/out/unsafe/rule_of_five.rs index 4b8b928fd6..31c8a9c445 100644 --- a/tests/unit/out/unsafe/rule_of_five.rs +++ b/tests/unit/out/unsafe/rule_of_five.rs @@ -121,7 +121,7 @@ impl MoveAssignableUnsafe for Buffer { } pub unsafe fn make_3(this: *mut Buffer, mut size: i32) { object_unsafe!(b, Buffer(size)); - ConstructFromUnsafe::construct_from(&mut *this, RvalueRefUnsafe::bind(&mut b)); + MoveConstructibleUnsafe::move_constructor(&mut *this, RvalueRefUnsafe::bind(&mut b)); return; } pub fn main() { @@ -133,7 +133,7 @@ pub fn main() { unsafe fn main_0() -> i32 { { object_unsafe!(a, Buffer(4)); - object_unsafe!(b, Buffer, &a); + object_unsafe!(b, Buffer, LvalueRefUnsafe::bind(&a)); assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (1))) diff --git a/tests/unit/out/unsafe/rule_of_three.rs b/tests/unit/out/unsafe/rule_of_three.rs index 045528c891..6d1dde3828 100644 --- a/tests/unit/out/unsafe/rule_of_three.rs +++ b/tests/unit/out/unsafe/rule_of_three.rs @@ -104,7 +104,7 @@ pub fn main() { unsafe fn main_0() -> i32 { { object_unsafe!(a, Buffer(4)); - object_unsafe!(b, Buffer, &a); + object_unsafe!(b, Buffer, LvalueRefUnsafe::bind(&a)); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (1)) @@ -125,7 +125,7 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (2))); assert!(((unsafe { sum_2(&a,) }) == (6))); assert!(((unsafe { sum_2(&b,) }) == (106))); - object_unsafe!(d, Buffer, &a); + object_unsafe!(d, Buffer, LvalueRefUnsafe::bind(&a)); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (3)) diff --git a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs index fd47735bab..a902b2fd56 100644 --- a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs @@ -51,7 +51,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(s, Counted(1, 2)); let mut __decomp_2: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &s); + CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(&s)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); diff --git a/tests/unit/out/unsafe/structured_binding_element_ctor.rs b/tests/unit/out/unsafe/structured_binding_element_ctor.rs index 7323d360f6..84a566c7bf 100644 --- a/tests/unit/out/unsafe/structured_binding_element_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_element_ctor.rs @@ -83,7 +83,7 @@ unsafe fn main_0() -> i32 { let mut base_moves: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)); let mut __decomp_3: Two = { let mut __v: Two = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &t); + CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(&t)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((base_copies) + (2)))); @@ -97,7 +97,7 @@ unsafe fn main_0() -> i32 { assert!(((t.a.v) == (50))); let mut __decomp_5: Two = { let mut __v: Two = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut t)); + MoveConstructibleUnsafe::move_constructor(&mut __v, RvalueRefUnsafe::bind(&mut t)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == ((base_moves) + (2)))); @@ -120,7 +120,10 @@ unsafe fn main_0() -> i32 { Elem::construct(&mut __tmp_0, 7); { let mut __v: Elem = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut __tmp_0)); + MoveConstructibleUnsafe::move_constructor( + &mut __v, + RvalueRefUnsafe::bind(&mut __tmp_0), + ); __v } }, @@ -129,7 +132,10 @@ unsafe fn main_0() -> i32 { Elem::construct(&mut __tmp_1, 8); { let mut __v: Elem = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut __tmp_1)); + MoveConstructibleUnsafe::move_constructor( + &mut __v, + RvalueRefUnsafe::bind(&mut __tmp_1), + ); __v } }, diff --git a/tests/unit/out/unsafe/structured_binding_move_ctor.rs b/tests/unit/out/unsafe/structured_binding_move_ctor.rs index 927ca66543..68fb33dce9 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -80,7 +80,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(m, Movable(3, 4)); let mut __decomp_2: Movable = { let mut __v: Movable = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, RvalueRefUnsafe::bind(&mut m)); + MoveConstructibleUnsafe::move_constructor(&mut __v, RvalueRefUnsafe::bind(&mut m)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (1))); diff --git a/tests/unit/out/unsafe/vector2.rs b/tests/unit/out/unsafe/vector2.rs index f678ef14b3..bc2b532f97 100644 --- a/tests/unit/out/unsafe/vector2.rs +++ b/tests/unit/out/unsafe/vector2.rs @@ -34,7 +34,7 @@ pub unsafe fn fn_0(v: *mut Vec, mut v3: Vec) { (v) }))[(0_usize)] = 7; { - v2.assign_from(v); + v2.copy_assign(LvalueRefUnsafe::bind(v)); }; (&mut (*v4))[(1_usize)] = 13; assert!(((x) == (6))); From 9cb3c09d29b0c8d69885d6ff4e1b2b2696c8a8e4 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 17:52:47 +0000 Subject: [PATCH 04/11] Add value category and cv markers --- libcc2rs/src/reference.rs | 425 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 425 insertions(+) create mode 100644 libcc2rs/src/reference.rs diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs new file mode 100644 index 0000000000..40ec9f09be --- /dev/null +++ b/libcc2rs/src/reference.rs @@ -0,0 +1,425 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +use std::fmt; +use std::marker::PhantomData; + +use crate::capture::{ + Destructible, DestructibleUnsafe, TriviallyDestructible, TriviallyDestructibleUnsafe, +}; +use crate::constructor::{ + CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, + MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, Swappable, + SwappableUnsafe, +}; +use crate::rc::Ptr; +use crate::reinterpret::ByteRepr; + +pub struct Const(PhantomData); + +pub struct Volatile(PhantomData); + +pub trait Cv { + type Object; +} + +impl Cv for T { + type Object = T; +} + +impl Cv for Const { + type Object = T::Object; +} + +impl Cv for Volatile { + type Object = T::Object; +} + +macro_rules! reference { + ($name:ident) => { + pub struct $name(Ptr); + + impl $name { + #[inline] + pub fn bind(ptr: Ptr) -> Self { + Self(ptr) + } + + #[inline] + pub fn as_pointer(&self) -> Ptr { + self.0.clone() + } + } + + impl Clone for $name { + #[inline] + fn clone(&self) -> Self { + Self(self.0.clone()) + } + } + + impl fmt::Debug for $name { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } + } + + impl crate::ZeroInitialization for $name { + #[inline] + fn zero_init() -> Self { + Self(Ptr::null()) + } + } + + impl ByteRepr for $name + where + T::Object: ByteRepr, + { + #[inline] + fn byte_size() -> usize { + std::mem::size_of::() + } + fn to_bytes(&self, buf: &mut [u8]) { + self.0.to_bytes(buf) + } + fn from_bytes(buf: &[u8]) -> Self { + Self(Ptr::from_bytes(buf)) + } + } + + impl MoveConstructible for $name + where + T::Object: ByteRepr, + { + fn move_constructor(this: &Ptr, src: RvalueRef) { + this.write(src.as_pointer().with(Self::clone)); + } + } + + impl CopyConstructible for $name + where + T::Object: ByteRepr, + { + fn copy_constructor(this: &Ptr, src: LvalueRef>) { + this.write(src.as_pointer().with(Self::clone)); + } + } + + impl Destructible for $name + where + T::Object: ByteRepr, + { + fn destroy(_this: &Ptr) {} + } + + impl TriviallyDestructible for $name where T::Object: ByteRepr {} + + impl Swappable for $name { + fn swap(this: &Ptr, other: Ptr) { + T::swap(&this.with(|r| r.0.clone()), other.with(|r| r.0.clone())); + } + } + + impl PartialEq for $name { + fn eq(&self, other: &Self) -> bool { + self.0.with(|a| other.0.with(|b| a == b)) + } + } + + impl PartialOrd for $name { + fn partial_cmp(&self, other: &Self) -> Option { + self.0.with(|a| other.0.with(|b| a.partial_cmp(b))) + } + } + }; +} + +reference!(LvalueRef); +reference!(RvalueRef); + +impl CopyAssignable for LvalueRef { + fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { + T::copy_assign( + &this.with(|r| r.0.clone()), + LvalueRef::bind(src.as_pointer().with(|r| r.0.clone())), + ); + this.clone() + } +} + +impl MoveAssignable for LvalueRef { + fn move_assign(this: &Ptr, src: RvalueRef) -> Ptr { + T::copy_assign( + &this.with(|r| r.0.clone()), + LvalueRef::bind(src.as_pointer().with(|r| r.0.clone())), + ); + this.clone() + } +} + +impl CopyAssignable for RvalueRef { + fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { + T::copy_assign( + &this.with(|r| r.0.clone()), + LvalueRef::bind(src.as_pointer().with(|r| r.0.clone())), + ); + this.clone() + } +} + +impl MoveAssignable for RvalueRef { + fn move_assign(this: &Ptr, src: RvalueRef) -> Ptr { + T::move_assign( + &this.with(|r| r.0.clone()), + RvalueRef::bind(src.as_pointer().with(|r| r.0.clone())), + ); + this.clone() + } +} + +macro_rules! reference_unsafe { + ($name:ident) => { + pub struct $name(*mut std::ffi::c_void, PhantomData); + + impl $name { + #[inline] + pub fn bind(ptr: *const U) -> Self { + Self(ptr.cast_mut().cast(), PhantomData) + } + + #[inline] + pub fn as_ptr(&self) -> *mut T { + self.0.cast() + } + } + + impl $name> { + #[inline] + pub fn as_const_ptr(&self) -> *const T { + self.0.cast() + } + } + + impl Clone for $name { + #[inline] + fn clone(&self) -> Self { + *self + } + } + + impl Copy for $name {} + + impl Default for $name { + #[inline] + fn default() -> Self { + Self(std::ptr::null_mut(), PhantomData) + } + } + + impl fmt::Debug for $name { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } + } + + impl MoveConstructibleUnsafe for $name { + unsafe fn move_constructor(&mut self, src: RvalueRefUnsafe) { + let src = src.as_ptr(); + unsafe { std::ptr::write(self, *src) } + } + } + + impl CopyConstructibleUnsafe for $name { + unsafe fn copy_constructor(&mut self, src: LvalueRefUnsafe>) { + let src = src.as_const_ptr(); + unsafe { std::ptr::write(self, *src) } + } + } + + impl DestructibleUnsafe for $name { + unsafe fn destroy(&mut self) {} + } + + impl TriviallyDestructibleUnsafe for $name {} + + impl SwappableUnsafe for $name { + unsafe fn swap(&mut self, other: *mut Self) { + unsafe { + T::swap( + &mut *self.as_ptr().cast::(), + (*other).as_ptr().cast::(), + ) + } + } + } + + impl PartialEq for $name { + fn eq(&self, other: &Self) -> bool { + unsafe { *self.as_ptr().cast::() == *other.as_ptr().cast::() } + } + } + + impl PartialOrd for $name { + fn partial_cmp(&self, other: &Self) -> Option { + unsafe { (*self.as_ptr().cast::()).partial_cmp(&*other.as_ptr().cast::()) } + } + } + + impl PartialEq for $name> { + fn eq(&self, other: &Self) -> bool { + unsafe { *self.as_ptr().cast::() == *other.as_ptr().cast::() } + } + } + + impl PartialOrd for $name> { + fn partial_cmp(&self, other: &Self) -> Option { + unsafe { (*self.as_ptr().cast::()).partial_cmp(&*other.as_ptr().cast::()) } + } + } + }; +} + +reference_unsafe!(LvalueRefUnsafe); +reference_unsafe!(RvalueRefUnsafe); + +impl CopyAssignableUnsafe for LvalueRefUnsafe { + unsafe fn copy_assign(&mut self, src: LvalueRefUnsafe>) -> *mut Self { + let src = src.as_const_ptr(); + unsafe { + T::copy_assign( + &mut *self.as_ptr().cast::(), + LvalueRefUnsafe::bind((*src).as_ptr().cast::()), + ) + }; + self + } +} + +impl MoveAssignableUnsafe for LvalueRefUnsafe { + unsafe fn move_assign(&mut self, src: RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); + unsafe { + T::copy_assign( + &mut *self.as_ptr().cast::(), + LvalueRefUnsafe::bind((*src).as_ptr().cast::()), + ) + }; + self + } +} + +impl CopyAssignableUnsafe for RvalueRefUnsafe { + unsafe fn copy_assign(&mut self, src: LvalueRefUnsafe>) -> *mut Self { + let src = src.as_const_ptr(); + unsafe { + T::copy_assign( + &mut *self.as_ptr().cast::(), + LvalueRefUnsafe::bind((*src).as_ptr().cast::()), + ) + }; + self + } +} + +impl MoveAssignableUnsafe for RvalueRefUnsafe { + unsafe fn move_assign(&mut self, src: RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); + unsafe { + T::move_assign( + &mut *self.as_ptr().cast::(), + RvalueRefUnsafe::bind((*src).as_ptr().cast::()), + ) + }; + self + } +} + +macro_rules! binds { + ($(<$param:ident $(: $bound:path)?> $from:ty => $to:ty),* $(,)?) => {$( + impl<$param $(: $bound)?> From<$from> for $to { + #[inline] + fn from(r: $from) -> Self { + Self(r.0) + } + } + )*}; +} + +macro_rules! binds_unsafe { + ($(<$param:ident> $from:ty => $to:ty),* $(,)?) => {$( + impl<$param> From<$from> for $to { + #[inline] + fn from(r: $from) -> Self { + Self(r.0, PhantomData) + } + } + )*}; +} + +binds!( + LvalueRef => LvalueRef>, + LvalueRef => LvalueRef>, + LvalueRef => LvalueRef>>, + LvalueRef> => LvalueRef>>, + LvalueRef> => LvalueRef>>, + RvalueRef => LvalueRef>, + RvalueRef> => LvalueRef>, + RvalueRef => RvalueRef>, + RvalueRef => RvalueRef>, + RvalueRef => RvalueRef>>, + RvalueRef> => RvalueRef>>, + RvalueRef> => RvalueRef>>, +); + +binds_unsafe!( + LvalueRefUnsafe => LvalueRefUnsafe>, + LvalueRefUnsafe => LvalueRefUnsafe>, + LvalueRefUnsafe => LvalueRefUnsafe>>, + LvalueRefUnsafe> => LvalueRefUnsafe>>, + RvalueRefUnsafe => LvalueRefUnsafe>, + RvalueRefUnsafe> => LvalueRefUnsafe>, + RvalueRefUnsafe => RvalueRefUnsafe>, + RvalueRefUnsafe => RvalueRefUnsafe>, + RvalueRefUnsafe => RvalueRefUnsafe>>, + RvalueRefUnsafe> => RvalueRefUnsafe>>, +); + +pub trait AddLvalueReference { + type Type; +} + +pub trait AddRvalueReference { + type Type; +} + +impl AddLvalueReference for LvalueRef { + type Type = LvalueRef; +} + +impl AddLvalueReference for RvalueRef { + type Type = LvalueRef; +} + +impl AddRvalueReference for LvalueRef { + type Type = LvalueRef; +} + +impl AddRvalueReference for RvalueRef { + type Type = RvalueRef; +} + +impl AddLvalueReference for LvalueRefUnsafe { + type Type = LvalueRefUnsafe; +} + +impl AddLvalueReference for RvalueRefUnsafe { + type Type = LvalueRefUnsafe; +} + +impl AddRvalueReference for LvalueRefUnsafe { + type Type = LvalueRefUnsafe; +} + +impl AddRvalueReference for RvalueRefUnsafe { + type Type = RvalueRefUnsafe; +} From 3ae93bb63ef9400bdc5d8534ed205ea76192b700 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 17:53:24 +0000 Subject: [PATCH 05/11] Update rules --- rules/array/tgt_refcount.rs | 4 ++-- rules/array/tgt_unsafe.rs | 2 +- rules/deque/tgt_unsafe.rs | 2 +- rules/map/shim.rs | 35 ++++++++++++++++++++++------------- rules/map/tgt_unsafe.rs | 2 +- rules/pair/src_cxx20.cpp | 5 +++++ rules/pair/tgt_refcount.rs | 6 +++--- rules/pair/tgt_unsafe.rs | 8 ++++++-- rules/unique_ptr/shim.rs | 16 +++++++++------- rules/vector/shim.rs | 35 +++++++++++++++++++++++------------ rules/vector/tgt_unsafe.rs | 2 +- 11 files changed, 74 insertions(+), 43 deletions(-) diff --git a/rules/array/tgt_refcount.rs b/rules/array/tgt_refcount.rs index c1e3e02b7c..3fea197871 100644 --- a/rules/array/tgt_refcount.rs +++ b/rules/array/tgt_refcount.rs @@ -36,7 +36,7 @@ fn f4( Rc::new(RefCell::new((0..T2).map(|_| T1::zero_init()).collect())); let __p: Ptr = __v.decay(); for __i in 0..T2 { - __p.offset(__i).construct_from(Moved(a0.offset(__i))); + T1::move_constructor(&__p.offset(__i), RvalueRef::bind(a0.offset(__i))); } Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -46,7 +46,7 @@ fn f5( a1: Ptr, ) -> Ptr> { for __i in 0..T2 { - assign!(*a0.decay().offset(__i) = Moved(*a1.offset(__i))); + assign!(*a0.decay().offset(__i) = RvalueRef(*a1.offset(__i))); } a0 } diff --git a/rules/array/tgt_unsafe.rs b/rules/array/tgt_unsafe.rs index 0c26310026..75deb1b919 100644 --- a/rules/array/tgt_unsafe.rs +++ b/rules/array/tgt_unsafe.rs @@ -48,7 +48,7 @@ unsafe fn f5<'a, T1: MoveAssignableUnsafe, const T2: usize>( a1: &mut [T1; T2], ) -> &'a mut [T1; T2] { for __i in 0..T2 { - assign_unsafe!(a0[__i] = Moved(a1[__i])); + assign_unsafe!(a0[__i] = RvalueRefUnsafe(a1[__i])); } a0 } diff --git a/rules/deque/tgt_unsafe.rs b/rules/deque/tgt_unsafe.rs index d2b5a47390..dbd65100c2 100644 --- a/rules/deque/tgt_unsafe.rs +++ b/rules/deque/tgt_unsafe.rs @@ -59,7 +59,7 @@ unsafe fn f9(a0: &mut Vec) -> Vec { } unsafe fn f10<'a, T1: CopyConstructibleUnsafe>(a0: &'a mut Vec, a1: *const Vec) -> &'a mut Vec { - a0.assign_from(a1); + a0.copy_assign(LvalueRefUnsafe::bind(a1)); a0 } diff --git a/rules/map/shim.rs b/rules/map/shim.rs index 94de6738cf..858bdf06f5 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -8,9 +8,9 @@ use std::ops::Bound; use std::rc::{Rc, Weak}; use crate::{ - AsPointer, BidirectionalIterator, ByteRepr, CopyAssignable, CopyAssignableUnsafe, - CopyConstructible, CopyConstructibleUnsafe, CppIterator, CppLess, Ptr, - UnsafeBidirectionalIterator, UnsafeCppIterator, Value, ZeroInitialization, + AsPointer, BidirectionalIterator, ByteRepr, Const, CopyAssignable, CopyAssignableUnsafe, + CopyConstructible, CopyConstructibleUnsafe, CppIterator, CppLess, LvalueRef, LvalueRefUnsafe, + Ptr, UnsafeBidirectionalIterator, UnsafeCppIterator, Value, ZeroInitialization, copy_constructed, copy_constructed_unsafe, cpp_cmp, }; @@ -115,8 +115,8 @@ where K: CppLess + CopyConstructible + ZeroInitialization + 'static, V: CopyConstructible + ZeroInitialization + 'static, { - fn copy_constructor(this: &Ptr, src: Ptr) { - this.write(Self::copied(src)); + fn copy_constructor(this: &Ptr, src: LvalueRef>) { + this.write(Self::copied(src.as_pointer())); } fn copied(src: Ptr) -> Self { @@ -147,8 +147,8 @@ where K: CppLess + CopyConstructible + ZeroInitialization + 'static, V: CopyConstructible + ZeroInitialization + 'static, { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { - let map = Self::copied(src); + fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { + let map = Self::copied(src.as_pointer()); this.write(map); this.clone() } @@ -273,7 +273,6 @@ impl Map> { next.borrow_mut().prev = Rc::downgrade(&prev); next } - } // The functions that modify a map take a pointer to it, and borrow it after @@ -315,7 +314,10 @@ impl Map> { ) -> (BidirectionalIterator>, bool) { map.with_mut(|map| match map.search(key) { Ok(node) => (BidirectionalIterator::Map(node), false), - Err(prev) => (BidirectionalIterator::Map(map.link_after(prev, entry())), true), + Err(prev) => ( + BidirectionalIterator::Map(map.link_after(prev, entry())), + true, + ), }) } @@ -466,7 +468,8 @@ impl UnsafeMap CopyConstructibleUnsafe for UnsafeMap { - unsafe fn copy_constructor(&mut self, src: *const Self) { + unsafe fn copy_constructor(&mut self, src: LvalueRefUnsafe>) { + let src = src.as_const_ptr(); unsafe { std::ptr::write(self, (*src).copied()) } } } @@ -474,7 +477,8 @@ impl CopyConstruct impl CopyAssignableUnsafe for UnsafeMap { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(&mut self, src: LvalueRefUnsafe>) -> *mut Self { + let src = src.as_const_ptr(); unsafe { *self = (*src).copied() }; self } @@ -607,7 +611,10 @@ impl UnsafeMap { pub fn emplace(&mut self, entry: (K, V)) -> (UnsafeBidirectionalIterator<(K, V)>, bool) { match self.search(&entry.0) { Ok(node) => (UnsafeBidirectionalIterator::Map(node), false), - Err(prev) => (UnsafeBidirectionalIterator::Map(self.link_after(prev, entry)), true), + Err(prev) => ( + UnsafeBidirectionalIterator::Map(self.link_after(prev, entry)), + true, + ), } } @@ -627,7 +634,9 @@ impl UnsafeMap { pub fn get(&self, key: &K) -> Option<*mut (K, V)> { self.nodes.get(&UnsafeMapKey(key)).map(|node| { - UnsafeMapNode::value(&**node as *const UnsafeMapNode<(K, V)> as *mut UnsafeMapNode<(K, V)>) + UnsafeMapNode::value( + &**node as *const UnsafeMapNode<(K, V)> as *mut UnsafeMapNode<(K, V)>, + ) }) } diff --git a/rules/map/tgt_unsafe.rs b/rules/map/tgt_unsafe.rs index e9de45d444..290b81b2d3 100644 --- a/rules/map/tgt_unsafe.rs +++ b/rules/map/tgt_unsafe.rs @@ -81,7 +81,7 @@ unsafe fn f25<'a, T1, T2>(a0: &'a mut UnsafeMap, a1: &mut UnsafeMa } unsafe fn f26<'a, T1: Ord + CopyConstructibleUnsafe, T2: CopyConstructibleUnsafe>(a0: &'a mut UnsafeMap, a1: *const UnsafeMap) -> &'a mut UnsafeMap { - a0.assign_from(a1); + a0.copy_assign(LvalueRefUnsafe::bind(a1)); a0 } diff --git a/rules/pair/src_cxx20.cpp b/rules/pair/src_cxx20.cpp index ddd18d87ae..dafe7b0291 100644 --- a/rules/pair/src_cxx20.cpp +++ b/rules/pair/src_cxx20.cpp @@ -27,3 +27,8 @@ template bool f32(const std::pair &a0, const std::pair &a1) { return a0 >= a1; } + +template +bool f33(const std::pair &a0, const std::pair &a1) { + return a0 == a1; +} diff --git a/rules/pair/tgt_refcount.rs b/rules/pair/tgt_refcount.rs index 50219d6641..7e87e8efbc 100644 --- a/rules/pair/tgt_refcount.rs +++ b/rules/pair/tgt_refcount.rs @@ -49,12 +49,12 @@ fn f13( a0 } -fn f14<'a, T1: MoveAssignable, T2: MoveAssignable>( +fn f14<'a, T1: MoveAssignable + ByteRepr, T2: MoveAssignable + ByteRepr>( a0: &'a mut (Value, Value), a1: &mut (Value, Value), ) -> &'a mut (Value, Value) { - assign!(a0.0 = Moved(a1.0)); - assign!(a0.1 = Moved(a1.1)); + assign!(a0.0 = RvalueRef(a1.0)); + assign!(a0.1 = RvalueRef(a1.1)); a0 } diff --git a/rules/pair/tgt_unsafe.rs b/rules/pair/tgt_unsafe.rs index e3fa54ce19..d34b6cc659 100644 --- a/rules/pair/tgt_unsafe.rs +++ b/rules/pair/tgt_unsafe.rs @@ -39,8 +39,8 @@ unsafe fn f13<'a, T1: CopyAssignableUnsafe, T2: CopyAssignableUnsafe>(a0: &'a mu } unsafe fn f14<'a, T1: MoveAssignableUnsafe, T2: MoveAssignableUnsafe>(a0: &'a mut (T1, T2), a1: &mut (T1, T2)) -> &'a mut (T1, T2) { - assign_unsafe!(a0.0 = Moved(a1.0)); - assign_unsafe!(a0.1 = Moved(a1.1)); + assign_unsafe!(a0.0 = RvalueRefUnsafe(a1.0)); + assign_unsafe!(a0.1 = RvalueRefUnsafe(a1.1)); a0 } @@ -117,3 +117,7 @@ fn f31(a0: (T1, T2), a1: (T1, T2)) -> bool { fn f32(a0: (T1, T2), a1: (T1, T2)) -> bool { a0 >= a1 } + +fn f33(a0: (T1, T2), a1: (T1, T2)) -> bool { + a0 == a1 +} diff --git a/rules/unique_ptr/shim.rs b/rules/unique_ptr/shim.rs index 264aad2598..8c5ec80cd9 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -3,7 +3,7 @@ use crate::{ ByteRepr, MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, - Ptr, Swappable, SwappableUnsafe, Value, + Ptr, RvalueRef, RvalueRefUnsafe, Swappable, SwappableUnsafe, Value, }; pub trait CppArray {} @@ -12,8 +12,8 @@ impl MoveConstructible for Option> where Self: ByteRepr, { - fn move_constructor(this: &Ptr, src: Ptr) { - let value = src.with_mut(Option::take); + fn move_constructor(this: &Ptr, src: RvalueRef) { + let value = src.as_pointer().with_mut(Option::take); this.with_mut(|dst| *dst = value); } } @@ -22,21 +22,23 @@ impl MoveAssignable for Option> where Self: ByteRepr, { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr { - let value = src.with_mut(Option::take); + fn move_assign(this: &Ptr, src: RvalueRef) -> Ptr { + let value = src.as_pointer().with_mut(Option::take); this.with_mut(|dst| *dst = value); this.clone() } } impl MoveConstructibleUnsafe for Option> { - unsafe fn move_constructor(&mut self, src: *mut Self) { + unsafe fn move_constructor(&mut self, src: RvalueRefUnsafe) { + let src = src.as_ptr(); unsafe { std::ptr::write(self, (*src).take()) } } } impl MoveAssignableUnsafe for Option> { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(&mut self, src: RvalueRefUnsafe) -> *mut Self { + let src = src.as_ptr(); unsafe { *self = (*src).take() }; self } diff --git a/rules/vector/shim.rs b/rules/vector/shim.rs index 5dd36017b1..dc9e3a5299 100644 --- a/rules/vector/shim.rs +++ b/rules/vector/shim.rs @@ -2,9 +2,9 @@ // Distributed under the MIT license that can be found in the LICENSE file. use crate::{ - ArgRepr, ByteRepr, ConstructFromUnsafe, CopyAssignable, CopyAssignableUnsafe, - CopyConstructible, CopyConstructibleUnsafe, FnPtrArg, MoveConstructibleUnsafe, Moved, Ptr, - ZeroInitialization, copy_constructed_unsafe, record_from_repr, + ArgRepr, ByteRepr, Const, CopyAssignable, CopyAssignableUnsafe, CopyConstructible, + CopyConstructibleUnsafe, FnPtrArg, LvalueRef, LvalueRefUnsafe, MoveConstructibleUnsafe, Ptr, + RvalueRefUnsafe, ZeroInitialization, copy_constructed_unsafe, record_from_repr, }; impl ByteRepr for Vec {} @@ -23,8 +23,8 @@ crate::constructor::impl_move_by_take!( Vec); // A vector is copied by copying its elements, each with its copy constructor. impl CopyConstructible for Vec { - fn copy_constructor(this: &Ptr, src: Ptr) { - this.write(T::copied_elems(&src)); + fn copy_constructor(this: &Ptr, src: LvalueRef>) { + this.write(T::copied_elems(&src.as_pointer())); } fn copied(src: Ptr) -> Self { @@ -33,8 +33,8 @@ impl CopyConstructible for } impl CopyAssignable for Vec { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { - this.write(T::copied_elems(&src)); + fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { + this.write(T::copied_elems(&src.as_pointer())); this.clone() } } @@ -84,7 +84,7 @@ impl PushConstructedUnsafe for Vec { { unsafe { push_constructed(self, src.cast_mut(), |dst, src| { - dst.construct_from(src.cast_const()) + dst.copy_constructor(LvalueRefUnsafe::bind(src)) }) } } @@ -93,22 +93,33 @@ impl PushConstructedUnsafe for Vec { where T: MoveConstructibleUnsafe, { - unsafe { push_constructed(self, src, |dst, src| dst.construct_from(Moved(src))) } + unsafe { + push_constructed(self, src, |dst, src| { + dst.move_constructor(RvalueRefUnsafe::bind(src)) + }) + } } } unsafe fn copied_elems_unsafe(src: *const Vec) -> Vec { - unsafe { (*src).iter().map(|elem| copy_constructed_unsafe(elem)).collect() } + unsafe { + (*src) + .iter() + .map(|elem| copy_constructed_unsafe(elem)) + .collect() + } } impl CopyConstructibleUnsafe for Vec { - unsafe fn copy_constructor(&mut self, src: *const Self) { + unsafe fn copy_constructor(&mut self, src: LvalueRefUnsafe>) { + let src = src.as_const_ptr(); unsafe { std::ptr::write(self, copied_elems_unsafe(src)) } } } impl CopyAssignableUnsafe for Vec { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(&mut self, src: LvalueRefUnsafe>) -> *mut Self { + let src = src.as_const_ptr(); unsafe { *self = copied_elems_unsafe(src) }; self } diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index 99f8530687..53f5e75ec8 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -222,7 +222,7 @@ fn f104(a0: Vec) -> UnsafeRandomAccessIterator { } unsafe fn f105<'a, T1: CopyConstructibleUnsafe>(a0: &'a mut Vec, a1: *const Vec) -> &'a mut Vec { - a0.assign_from(a1); + a0.copy_assign(LvalueRefUnsafe::bind(a1)); a0 } From d7a3cec5bfb7a297d2405d0eecab4f861560abad Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 17:55:18 +0000 Subject: [PATCH 06/11] Use explicit as_pointer for refrences --- libcc2rs-macros/src/constructor.rs | 4 ++-- libcc2rs/src/constructor.rs | 26 ++++++++++++++------------ libcc2rs/src/reference.rs | 1 + rules/array/tgt_refcount.rs | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index 85baa0251a..d260b7b30a 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -188,11 +188,11 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - )) } else if is_assign { quote! { - this.write(src.with(Self::clone)); + this.write(src.as_pointer().with(Self::clone)); this.clone() } } else { - quote!(this.write(src.with(Self::clone));) + quote!(this.write(src.as_pointer().with(Self::clone));) }; // The copy of a type with Clone is a clone, and its move is its copy. let copied = match (is_move, is_assign) { diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index e9fd43a27e..3b914f77fd 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -248,7 +248,7 @@ macro_rules! impl_copy_by_clone { $ty: Clone + $crate::ByteRepr, { fn copy_constructor(this: &$crate::Ptr, src: $crate::LvalueRef<$crate::Const>) { - this.write(src.with(Self::clone)); + this.write(src.as_pointer().with(Self::clone)); } fn copied(src: $crate::Ptr) -> Self { @@ -270,7 +270,7 @@ macro_rules! impl_copy_by_clone { $ty: Clone + $crate::ByteRepr, { fn copy_assign(this: &$crate::Ptr, src: $crate::LvalueRef<$crate::Const>) -> $crate::Ptr { - this.write(src.with(Self::clone)); + this.write(src.as_pointer().with(Self::clone)); this.clone() } } @@ -306,7 +306,7 @@ macro_rules! impl_move_by_clone { $ty: Clone + $crate::ByteRepr, { fn move_constructor(this: &$crate::Ptr, src: $crate::RvalueRef) { - this.write(src.with(Self::clone)); + this.write(src.as_pointer().with(Self::clone)); } fn push_moved(v: &$crate::Ptr>, src: $crate::Ptr) { @@ -320,7 +320,7 @@ macro_rules! impl_move_by_clone { $ty: Clone + $crate::ByteRepr, { fn move_assign(this: &$crate::Ptr, src: $crate::RvalueRef) -> $crate::Ptr { - this.write(src.with(Self::clone)); + this.write(src.as_pointer().with(Self::clone)); this.clone() } } @@ -461,7 +461,7 @@ macro_rules! impl_move_by_take { $ty: Default + $crate::ByteRepr, { fn move_constructor(this: &$crate::Ptr, src: $crate::RvalueRef) { - let value = src.with_mut(std::mem::take); + let value = src.as_pointer().with_mut(std::mem::take); this.with_mut(|dst| *dst = value); } @@ -476,7 +476,7 @@ macro_rules! impl_move_by_take { $ty: Default + $crate::ByteRepr, { fn move_assign(this: &$crate::Ptr, src: $crate::RvalueRef) -> $crate::Ptr { - let value = src.with_mut(std::mem::take); + let value = src.as_pointer().with_mut(std::mem::take); this.with_mut(|dst| *dst = value); this.clone() } @@ -663,6 +663,8 @@ impl_trivial_copy_move!( impl_trivial_copy_move!( Ptr, *mut T, *const T); +// TODO: copy and move a pair memberwise, with the copy and move members of +// A and B, and then remove Clone from LvalueRef and RvalueRef. impl_copy_by_clone!( (A, B)); impl_move_by_clone!( (A, B)); @@ -757,7 +759,7 @@ impl TriviallyDe impl MoveConstructible for FnPtr { fn move_constructor(this: &Ptr, src: RvalueRef) { - let value = src.with(FnPtr::move_from); + let value = src.as_pointer().with(FnPtr::move_from); this.with_mut(|dst| *dst = value); } } @@ -770,7 +772,7 @@ impl TriviallyMoveConstructible for FnPtr { impl CopyConstructible for FnPtr { fn copy_constructor(this: &Ptr, src: LvalueRef>) { - let value = src.with(FnPtr::copy_from); + let value = src.as_pointer().with(FnPtr::copy_from); this.with_mut(|dst| *dst = value); } } @@ -885,7 +887,7 @@ fn assign_elems( impl MoveConstructible for Box<[T]> { fn move_constructor(this: &Ptr, src: RvalueRef) { - construct_elems(this, &src, |dst, src| { + construct_elems(this, &src.as_pointer(), |dst, src| { T::move_constructor(dst, RvalueRef::bind(src)) }); } @@ -901,7 +903,7 @@ impl TriviallyMov impl CopyConstructible for Box<[T]> { fn copy_constructor(this: &Ptr, src: LvalueRef>) { - construct_elems(this, &src, |dst, src| { + construct_elems(this, &src.as_pointer(), |dst, src| { T::copy_constructor(dst, LvalueRef::bind(src)) }); } @@ -917,7 +919,7 @@ impl TriviallyCop impl MoveAssignable for Box<[T]> { fn move_assign(this: &Ptr, src: RvalueRef) -> Ptr { - assign_elems(this, &src, |dst, src| { + assign_elems(this, &src.as_pointer(), |dst, src| { T::move_assign(dst, RvalueRef::bind(src)) }) } @@ -927,7 +929,7 @@ impl TriviallyMoveAssignable for Box<[T]> impl CopyAssignable for Box<[T]> { fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { - assign_elems(this, &src, |dst, src| { + assign_elems(this, &src.as_pointer(), |dst, src| { T::copy_assign(dst, LvalueRef::bind(src)) }) } diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs index 40ec9f09be..f6163cb8c5 100644 --- a/libcc2rs/src/reference.rs +++ b/libcc2rs/src/reference.rs @@ -51,6 +51,7 @@ macro_rules! reference { } } + // TODO: remove, with the copy of a pair by Clone (constructor.rs). impl Clone for $name { #[inline] fn clone(&self) -> Self { diff --git a/rules/array/tgt_refcount.rs b/rules/array/tgt_refcount.rs index 3fea197871..c38a8b1dbe 100644 --- a/rules/array/tgt_refcount.rs +++ b/rules/array/tgt_refcount.rs @@ -36,7 +36,7 @@ fn f4( Rc::new(RefCell::new((0..T2).map(|_| T1::zero_init()).collect())); let __p: Ptr = __v.decay(); for __i in 0..T2 { - T1::move_constructor(&__p.offset(__i), RvalueRef::bind(a0.offset(__i))); + MoveConstructible::move_constructor(&__p.offset(__i), RvalueRef::bind(a0.offset(__i))); } Rc::try_unwrap(__v).ok().unwrap().into_inner() } From 2db5e3349e307ea55de11cfa8dc462d30c7d11b8 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 17:56:19 +0000 Subject: [PATCH 07/11] Add refrence support in converter --- cpp2rust/converter/converter.cpp | 117 +++++++++++++++--- cpp2rust/converter/converter.h | 17 ++- cpp2rust/converter/converter_lib.cpp | 10 ++ cpp2rust/converter/converter_lib.h | 30 +++-- .../converter/models/converter_refcount.cpp | 26 +++- .../converter/models/converter_refcount.h | 9 ++ cpp2rust/converter/rules/registry.cpp | 39 ++++++ cpp2rust/converter/rules/registry.h | 6 + cpp2rust/converter/translation_rule.cpp | 2 +- 9 files changed, 222 insertions(+), 34 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 83a2225e74..8b075e209e 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -170,6 +170,9 @@ std::string Converter::GetTemplateArgumentAsString(const clang::TemplateArgument &arg) { switch (arg.getKind()) { case clang::TemplateArgument::Type: + if (IsReferenceToObject(arg.getAsType())) { + return GetReferenceMarkerAsString(arg.getAsType()); + } return GetUnboxedTypeAsString(arg.getAsType()); case clang::TemplateArgument::Integral: if (!arg.getIntegralType()->isBooleanType()) { @@ -1073,10 +1076,16 @@ void Converter::AddAssignmentTraits(const clang::CXXRecordDecl *decl) { StrCat(GetAssignmentTraitSignature(*trait)); PushBrace fn_brace(*this); // An argument by value is constructed from the source. - std::string arg = "src"; + clang::QualType source_type = ctx_.getCanonicalTagType(decl); + if (trait == &kCopyAssignable) { + source_type.addConst(); + } + auto arg = GetReferredObjectPointer( + "src", ctx_.getLValueReferenceType(source_type)); if (!param_type->isReferenceType()) { - StrCat(std::format("{}(__o, {}, {});", GetObjectMacro(), record_name, - trait == &kMoveAssignable ? "Moved(src)" : "src")); + StrCat(std::format("{}(__o, {}, {}::bind({}));", GetObjectMacro(), + record_name, + GetReferenceMarker(trait == &kMoveAssignable), arg)); arg = GetReturnSlotArg(GetPlacementReceiver("__o")); } StrCat(std::format("{}::{}({}, {});", GetUFCSName(method), @@ -1087,9 +1096,15 @@ void Converter::AddAssignmentTraits(const clang::CXXRecordDecl *decl) { std::string Converter::GetAssignmentTraitSignature(const RecordTrait &trait) const { - return std::format("unsafe fn {}(&mut self, src: {} Self) -> *mut Self", - trait.method, - &trait == &kMoveAssignable ? "*mut" : "*const"); + return std::format("unsafe fn {}(&mut self, src: {}) -> *mut Self", + trait.method, GetCopyOrMoveSourceType(trait)); +} + +std::string Converter::GetCopyOrMoveSourceType(const RecordTrait &trait) const { + if (&trait == &kMoveConstructible || &trait == &kMoveAssignable) { + return std::format("{}", GetReferenceMarker(true)); + } + return std::format("{}>", GetReferenceMarker(false)); } void Converter::ConvertTemplateInstantiatedCtors(clang::CXXRecordDecl *decl) { @@ -2627,14 +2642,14 @@ void Converter::EmitArgList(const CallInfo &info) { StrCat(GetReturnSlotArg(in_place_.receiver), token::kComma); } - // The move operator= is picked by a Moved source. + // The move operator= is picked by an rvalue reference source. auto *method = clang::dyn_cast_or_null( info.expr->getDirectCallee()); bool moved = method && GetRecordTrait(method) == &kMoveAssignable; for (unsigned i = 0; i < info.args.size(); i++) { const auto &ca = info.args[i]; if (moved) { - StrCat("Moved"); + StrCat(GetReferenceMarker(true), "::bind"); } PushParen moved_paren(*this, moved); switch (ca.kind) { @@ -2783,7 +2798,7 @@ void Converter::ConvertAssignCall(clang::CallExpr *expr, })); } if (GetRecordTrait(method) == &kMoveAssignable) { - src = std::format("Moved({})", src); + src = std::format("{}({})", GetReferenceMarker(true), src); } std::string dst; if (auto *member = clang::dyn_cast(expr)) { @@ -4311,6 +4326,12 @@ void Converter::SetUFCSReceiver(clang::Expr *base, bool is_arrow, void Converter::ConvertMemberExpr(clang::MemberExpr *expr) { if (auto mapped = GetMappedAsString(expr); !mapped.empty()) { + if (auto type = expr->getMemberDecl()->getType(); + IsReferenceToObject(type)) { + mapped = + std::format("({}.as_ptr() as {})", mapped, + ToString(ctx_.getPointerType(type->getPointeeType()))); + } if (RuleRegistry::ReturnsPointer(ctx_, expr) && !isAddrOf() && !Mapper::IsRefExpr(ctx_, expr)) { PushParen paren(*this); @@ -4779,8 +4800,9 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) { auto *trait = GetRecordTrait(ctor); bool from_source = trait == &kCopyConstructible || trait == &kMoveConstructible; - if (trait == &kMoveConstructible) { - args = std::format("Moved({})", args); + if (from_source) { + args = std::format("{}::bind({})", + GetReferenceMarker(trait == &kMoveConstructible), args); } if (in_place && in_place_.object_tail && hoist_temps.empty() && full_expression_temporaries_->empty()) { @@ -4798,10 +4820,7 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) { return; } auto path = - from_source - ? std::format("{}::{}", GetCopyOrMoveTraitName(kConstructFrom), - kConstructFrom.method) - : std::format("{}::{}", GetConstructorPath(ctor), GetCtorName(ctor)); + std::format("{}::{}", GetConstructorPath(ctor), GetCtorName(ctor)); StrCat(std::format("{}({}{}{})", path, in_place ? in_place_.receiver : GetPlacementReceiver(), args.empty() ? "" : ", ", args)); @@ -5674,9 +5693,28 @@ void Converter::ConvertFunctionParameters(clang::FunctionDecl *decl) { if (UsesReturnSlot(decl->getReturnType())) { StrCat(GetReturnSlotParam(decl->getReturnType())); } + if (auto *source = GetCopyOrMoveSource(decl)) { + StrCat(GetNamedDeclAsString(source), token::kColon, + GetReferenceMarkerAsString(source->getType()), token::kComma); + return; + } ConvertParamList(DefinitionParameters(decl), decl->isVariadic()); } +void Converter::EmitFunctionPreamble(clang::FunctionDecl *decl) { + if (auto *source = GetCopyOrMoveSource(decl)) { + auto name = GetNamedDeclAsString(source); + StrCat(std::format("let {} = {};", name, + GetReferredObjectPointer(name, source->getType()))); + } +} + +std::string Converter::GetReferredObjectPointer(std::string_view reference, + clang::QualType type) { + return std::format("({}.as_ptr() as {})", reference, + ToString(ctx_.getPointerType(type->getPointeeType()))); +} + void Converter::ConvertParamList(llvm::ArrayRef params, bool is_variadic) { ScopedValue in_formals(in_function_formals_, true); @@ -6943,9 +6981,24 @@ std::string Converter::GetMappedAsString(clang::Expr *expr, clang::Expr **args, if (!effects.empty()) { result = std::format("{{ {} {} }}", effects, result); } + if (auto referred = RuleRegistry::GetReferenceReturnedByReference(expr); + !referred.isNull() && IsReferenceToObject(referred) && + tgt_ir->return_type.is_pointer()) { + result = CollapseReference(result, referred, place); + } return result; } +std::string Converter::CollapseReference(std::string_view result, + clang::QualType referred, + bool is_place) { + auto type = ToString(ctx_.getPointerType(referred->getPointeeType())); + if (is_place) { + return std::format("(*(({}).as_ptr() as {}))", result, type); + } + return std::format("((*({})).as_ptr() as {})", result, type); +} + bool Converter::UsedOnce(const TranslationRule::ExprRule &rule, unsigned n) { unsigned uses = 0; TranslationRule::AnyFragment(rule.body, [&](const auto &frag) { @@ -7008,6 +7061,33 @@ std::vector Converter::ArgsToEvaluateFirst( return first; } +bool Converter::IsReferenceToObject(clang::QualType type) const { + if (!type->isReferenceType()) { + return false; + } + auto pointee = type->getPointeeType(); + auto *record = pointee->getAsCXXRecordDecl(); + return !pointee->isFunctionType() && !pointee->isArrayType() && + !(record && IsAbstractUserClass(record)); +} + +std::string Converter::GetReferenceMarkerAsString(clang::QualType type) { + auto pointee = type->getPointeeType(); + auto object = GetUnboxedTypeAsString(pointee.getUnqualifiedType()); + if (pointee.isVolatileQualified()) { + object = std::format("Volatile<{}>", object); + } + if (pointee.isConstQualified()) { + object = std::format("Const<{}>", object); + } + return std::format("{}<{}>", + GetReferenceMarker(type->isRValueReferenceType()), object); +} + +const char *Converter::GetReferenceMarker(bool is_rvalue) const { + return is_rvalue ? "RvalueRefUnsafe" : "LvalueRefUnsafe"; +} + bool Converter::ReturnsPointerToArg(clang::Expr *) { return false; } std::string Converter::ConvertPointerToArg(clang::Expr *, std::string_view) { @@ -7071,6 +7151,13 @@ std::string Converter::ConvertIRFragment( value = std::format("({})", value); } borrows_ |= outer_borrows; + if (auto bound = + RuleRegistry::GetReferenceBoundToParam(ctx_, expr, arg_idx); + !bound.isNull() && IsReferenceToObject(bound)) { + value = std::format("{}::bind({})", + GetReferenceMarker(bound->isRValueReferenceType()), + value); + } result += value; } else if (std::get_if(&frag)) { assert(expr && "variadic arguments outside an expression rule"); diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index d80b182d0b..8ac96e4bfb 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -101,6 +101,16 @@ class Converter : public clang::RecursiveASTVisitor { std::string GetTemplateArgumentAsString(const clang::TemplateArgument &arg); + bool IsReferenceToObject(clang::QualType type) const; + + std::string GetReferenceMarkerAsString(clang::QualType type); + + virtual const char *GetReferenceMarker(bool is_rvalue) const; + + virtual std::string CollapseReference(std::string_view result, + clang::QualType referred, + bool is_place); + bool VisitRecoveryExpr(clang::RecoveryExpr *expr); bool VisitExprWithCleanups(clang::ExprWithCleanups *expr); bool VisitMaterializeTemporaryExpr(clang::MaterializeTemporaryExpr *expr); @@ -142,7 +152,10 @@ class Converter : public clang::RecursiveASTVisitor { virtual bool VisitFunctionDecl(clang::FunctionDecl *decl); - virtual void EmitFunctionPreamble(clang::FunctionDecl *) {} + virtual void EmitFunctionPreamble(clang::FunctionDecl *decl); + + virtual std::string GetReferredObjectPointer(std::string_view reference, + clang::QualType type); virtual void ConvertFunctionBody(clang::FunctionDecl *decl); @@ -999,6 +1012,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual std::string GetAssignmentTraitSignature(const RecordTrait &trait) const; + std::string GetCopyOrMoveSourceType(const RecordTrait &trait) const; + virtual void AddDefaultTraitForUnion(const clang::RecordDecl *decl); clang::CXXConstructExpr * diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 8e93241570..8c33d2445b 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -695,6 +695,16 @@ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { return is_copy ? &kCopyAssignable : &kMoveAssignable; } +const clang::ParmVarDecl *GetCopyOrMoveSource(const clang::FunctionDecl *decl) { + auto *method = clang::dyn_cast(decl); + auto *trait = method ? GetRecordTrait(method) : nullptr; + if (trait != &kCopyConstructible && trait != &kMoveConstructible && + trait != &kCopyAssignable && trait != &kMoveAssignable) { + return nullptr; + } + return DefinitionParameters(decl)[0]; +} + bool IsDerivedCopyOrMove(const clang::CXXMethodDecl *method) { if (auto *ctor = clang::dyn_cast(method); ctor && ctor->isDefaultConstructor()) { diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 923520f3e3..1d9b14b083 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -125,34 +125,36 @@ inline constexpr RecordTrait kDefaultConstructible{ "&mut *self"}}; inline constexpr RecordTrait kCopyConstructible{ "copy_constructor", - {"CopyConstructible", "fn copy_constructor(this: &Ptr, _: Ptr)", + {"CopyConstructible", + "fn copy_constructor(this: &Ptr, _: LvalueRef>)", "this"}, {"CopyConstructibleUnsafe", - "unsafe fn copy_constructor(&mut self, _: *const Self)", "&mut *self"}}; + "unsafe fn copy_constructor(&mut self, _: LvalueRefUnsafe>)", + "&mut *self"}}; inline constexpr RecordTrait kMoveConstructible{ "move_constructor", - {"MoveConstructible", "fn move_constructor(this: &Ptr, _: Ptr)", - "this"}, + {"MoveConstructible", + "fn move_constructor(this: &Ptr, _: RvalueRef)", "this"}, {"MoveConstructibleUnsafe", - "unsafe fn move_constructor(&mut self, _: *mut Self)", "&mut *self"}}; + "unsafe fn move_constructor(&mut self, _: RvalueRefUnsafe)", + "&mut *self"}}; inline constexpr RecordTrait kCopyAssignable{ "copy_assign", {"CopyAssignable", - "fn copy_assign(this: &Ptr, _: Ptr) -> Ptr", "this"}, + "fn copy_assign(this: &Ptr, _: LvalueRef>) -> Ptr", + "this"}, {"CopyAssignableUnsafe", - "unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self", + "unsafe fn copy_assign(&mut self, _: LvalueRefUnsafe>) -> " + "*mut Self", "&mut *self"}}; inline constexpr RecordTrait kMoveAssignable{ "move_assign", {"MoveAssignable", - "fn move_assign(this: &Ptr, _: Ptr) -> Ptr", "this"}, + "fn move_assign(this: &Ptr, _: RvalueRef) -> Ptr", + "this"}, {"MoveAssignableUnsafe", - "unsafe fn move_assign(&mut self, _: *mut Self) -> *mut Self", + "unsafe fn move_assign(&mut self, _: RvalueRefUnsafe) -> *mut Self", "&mut *self"}}; -// The construction from a source, which picks the copy or the move -// constructor from the type of the source. -inline constexpr RecordTrait kConstructFrom{ - "construct_from", {"ConstructFrom"}, {"ConstructFromUnsafe"}}; inline constexpr RecordTrait kSwappable{ "swap", {"Swappable", "fn swap(this: &Ptr, _: Ptr)", "this"}, @@ -178,6 +180,8 @@ inline constexpr RecordTrait kMemberwise{ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method); +const clang::ParmVarDecl *GetCopyOrMoveSource(const clang::FunctionDecl *decl); + // Whether method is a C++ defaulted copy or move member that is translated as // a memberwise derive of its trait, rather than from its body. bool IsDerivedCopyOrMove(const clang::CXXMethodDecl *method); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 3f1c01d821..a96e66017c 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -325,6 +325,15 @@ bool ConverterRefCount::VisitReferenceType(clang::ReferenceType *type) { return false; } +const char *ConverterRefCount::GetReferenceMarker(bool is_rvalue) const { + return is_rvalue ? "RvalueRef" : "LvalueRef"; +} + +std::string ConverterRefCount::CollapseReference(std::string_view result, + clang::QualType, bool) { + return std::format("{}.with(|__r| __r.as_pointer())", result); +} + std::string ConverterRefCount::ConvertFunctionPointerType( const clang::FunctionProtoType *proto) { PushConversionKind push(*this, ConversionKind::Unboxed); @@ -653,7 +662,7 @@ ConverterRefCount::GetComparisonArg(const clang::ParmVarDecl *param, if (IsTriviallyCopyable(decl)) { return std::format("{}.read()", value); } - return std::format("{{ {} {}::{}({}, {}.clone()); {} }}", + return std::format("{{ {} {}::{}({}, LvalueRef::bind({}.clone())); {} }}", CreatePlacementStorage(GetRecordName(decl)), GetCopyOrMoveTraitName(kCopyConstructible), kCopyConstructible.method, GetPlacementReceiver(), value, @@ -873,7 +882,14 @@ bool ConverterRefCount::VisitFieldDecl(clang::FieldDecl *decl) { return Converter::VisitFieldDecl(decl); } +std::string +ConverterRefCount::GetReferredObjectPointer(std::string_view reference, + clang::QualType) { + return std::format("{}.as_pointer()", reference); +} + void ConverterRefCount::EmitFunctionPreamble(clang::FunctionDecl *decl) { + Converter::EmitFunctionPreamble(decl); PushConversionKind push(*this, ConversionKind::FullRefCount); if (decl->isVariadic()) { StrCat("let __args: Value> = " @@ -1817,7 +1833,9 @@ bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) { if (known) { str = GetMappedAsString(expr); if (member->getType()->isReferenceType()) { - str = std::format("{}.borrow().clone()", str); + str = std::format("{}.borrow().{}()", str, + IsReferenceToObject(member->getType()) ? "as_pointer" + : "clone"); borrows_ = true; } } else if (clang::isa(member)) { @@ -3775,8 +3793,8 @@ std::string ConverterRefCount::ConvertObjectOperand(clang::Expr *expr, std::string ConverterRefCount::GetAssignmentTraitSignature(const RecordTrait &trait) const { - return std::format("fn {}(this: &Ptr, src: Ptr) -> Ptr", - trait.method); + return std::format("fn {}(this: &Ptr, src: {}) -> Ptr", + trait.method, GetCopyOrMoveSourceType(trait)); } const char *ConverterRefCount::GetConstructorSelf() const { diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 1d9fb0d900..4c5069b1de 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -31,6 +31,12 @@ class ConverterRefCount final : public Converter { bool VisitReferenceType(clang::ReferenceType *type) override; + const char *GetReferenceMarker(bool is_rvalue) const override; + + std::string CollapseReference(std::string_view result, + clang::QualType referred, + bool is_place) override; + bool VisitPointerType(clang::PointerType *type) override; std::string @@ -138,6 +144,9 @@ class ConverterRefCount final : public Converter { void EmitFunctionPreamble(clang::FunctionDecl *decl) override; + std::string GetReferredObjectPointer(std::string_view reference, + clang::QualType type) override; + bool VisitVarDecl(clang::VarDecl *decl) override; bool LazyStaticInit() const override { return false; } std::string ForceGlobalInit(const clang::VarDecl *decl) override; diff --git a/cpp2rust/converter/rules/registry.cpp b/cpp2rust/converter/rules/registry.cpp index 82dc77c55f..583961c19c 100644 --- a/cpp2rust/converter/rules/registry.cpp +++ b/cpp2rust/converter/rules/registry.cpp @@ -620,6 +620,31 @@ bool ReturnsReference(const clang::Expr *expr) { ->isReferenceType(); } +clang::QualType GetReferenceReturnedByReference(const clang::Expr *expr) { + if (ExprHasUserDefinedDecl(expr)) { + return {}; + } + auto match = findExpr(expr); + if (!match.rule_decl) { + return {}; + } + auto *function = match.rule_decl->decl->getAsFunction(); + if (!function || !function->getReturnType()->isReferenceType()) { + return {}; + } + auto pointee = function->getReturnType()->getPointeeType(); + auto *tmpl = function->getDescribedFunctionTemplate(); + if (!tmpl || !pointee->isDependentType()) { + return {}; + } + clang::MultiLevelTemplateArgumentList args(tmpl, match.args, /*Final=*/false); + clang::Sema::InstantiatingTemplate inst( + *sema_, expr->getBeginLoc(), const_cast(function)); + auto type = sema_->SubstType(pointee, args, expr->getBeginLoc(), + clang::DeclarationName()); + return !type.isNull() && type->isReferenceType() ? type : clang::QualType(); +} + static bool BindsGenericToReference(const TranslationRule::TypeInfo ¶m, const Matcher::Bindings &bindings) { auto n = param.generic; @@ -628,6 +653,20 @@ static bool BindsGenericToReference(const TranslationRule::TypeInfo ¶m, bindings[n - 1].getAsType()->isReferenceType(); } +clang::QualType GetReferenceBoundToParam(clang::ASTContext &ctx, + const clang::Expr *expr, + unsigned index) { + auto [rule, bindings] = Search(ctx, expr); + assert(rule && "expression must have a translation rule"); + if (index >= rule->params.size()) { + return {}; + } + auto ¶m = rule->params[index]; + return BindsGenericToReference(param, bindings) + ? bindings[param.generic - 1].getAsType() + : clang::QualType(); +} + bool ParamIsPointer(clang::ASTContext &ctx, const clang::Expr *expr, unsigned index) { auto [rule, bindings] = Search(ctx, expr); diff --git a/cpp2rust/converter/rules/registry.h b/cpp2rust/converter/rules/registry.h index adf78602c7..c035aa8da7 100644 --- a/cpp2rust/converter/rules/registry.h +++ b/cpp2rust/converter/rules/registry.h @@ -54,6 +54,8 @@ bool HasExprRule(const clang::FunctionDecl *decl); bool IsLibcPassthrough(clang::ASTContext &ctx, const clang::Expr *expr); bool ReturnsPointer(clang::ASTContext &ctx, const clang::Expr *expr); bool ReturnsReference(const clang::Expr *expr); + +clang::QualType GetReferenceReturnedByReference(const clang::Expr *expr); // The argument of expr, a call, that its rule returns a reference to, or to an // element of, which element is then set to. clang::Expr *GetReferencedArg(clang::ASTContext &ctx, const clang::Expr *expr, @@ -61,6 +63,10 @@ clang::Expr *GetReferencedArg(clang::ASTContext &ctx, const clang::Expr *expr, // The argument of expr, a call, that its rule returns a reference to, after // computing something else, e.g., the receiver of std::string::append. clang::Expr *GetReturnedArg(clang::ASTContext &ctx, const clang::Expr *expr); +clang::QualType GetReferenceBoundToParam(clang::ASTContext &ctx, + const clang::Expr *expr, + unsigned index); + bool ParamIsPointer(clang::ASTContext &ctx, const clang::Expr *expr, unsigned index); diff --git a/cpp2rust/converter/translation_rule.cpp b/cpp2rust/converter/translation_rule.cpp index 7ba5431a2a..5235253ff9 100644 --- a/cpp2rust/converter/translation_rule.cpp +++ b/cpp2rust/converter/translation_rule.cpp @@ -433,7 +433,7 @@ bool ExprRule::takesAddress(clang::ASTContext &ctx, const clang::Expr *expr, if (i >= params.size()) { return usesInit(); } - if (!params[i].is_pointer()) { + if (!RuleRegistry::ParamIsPointer(ctx, expr, i)) { return false; } if (arg->getType()->isPointerType()) { From 96d3e289ee8f83f105c1be42c053d13d93a84005 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 18:12:28 +0000 Subject: [PATCH 08/11] Add tests for reference collapsing and reference binding --- libcc2rs-macros/Cargo.toml | 1 + libcc2rs-macros/tests/ui/reference_binding.rs | 48 +++++ .../tests/ui/reference_binding.stderr | 165 ++++++++++++++++++ libcc2rs/src/reference.rs | 109 ++++++++++++ 4 files changed, 323 insertions(+) create mode 100644 libcc2rs-macros/tests/ui/reference_binding.rs create mode 100644 libcc2rs-macros/tests/ui/reference_binding.stderr diff --git a/libcc2rs-macros/Cargo.toml b/libcc2rs-macros/Cargo.toml index 25ed02f400..dc55c02ecf 100644 --- a/libcc2rs-macros/Cargo.toml +++ b/libcc2rs-macros/Cargo.toml @@ -12,6 +12,7 @@ quote = "1" syn = { version = "2", features = ["full", "visit-mut", "extra-traits"] } [dev-dependencies] +libcc2rs = { path = "../libcc2rs" } # trybuild 1.0.123 passes --diagnostic-width to rustc, which cargo also passes # when it knows the width of the terminal, and rustc rejects it twice. trybuild = ">=1, <1.0.123" diff --git a/libcc2rs-macros/tests/ui/reference_binding.rs b/libcc2rs-macros/tests/ui/reference_binding.rs new file mode 100644 index 0000000000..2e7ca362f7 --- /dev/null +++ b/libcc2rs-macros/tests/ui/reference_binding.rs @@ -0,0 +1,48 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +use libcc2rs::{Const, LvalueRef, LvalueRefUnsafe, RvalueRef, RvalueRefUnsafe, Volatile}; + +fn lvalue_reference_drops_const(r: LvalueRef>) -> LvalueRef { + r.into() +} + +fn lvalue_reference_drops_volatile(r: LvalueRef>) -> LvalueRef { + r.into() +} + +fn lvalue_reference_drops_one_of_two(r: LvalueRef>>) -> LvalueRef> { + r.into() +} + +fn rvalue_reference_drops_const(r: RvalueRef>) -> RvalueRef { + r.into() +} + +fn rvalue_reference_binds_to_lvalue(r: LvalueRef) -> RvalueRef { + r.into() +} + +fn lvalue_reference_binds_to_rvalue(r: RvalueRef) -> LvalueRef { + r.into() +} + +fn volatile_lvalue_reference_binds_to_rvalue( + r: RvalueRef, +) -> LvalueRef>> { + r.into() +} + +fn unsafe_lvalue_reference_drops_const(r: LvalueRefUnsafe>) -> LvalueRefUnsafe { + r.into() +} + +fn unsafe_rvalue_reference_binds_to_lvalue(r: LvalueRefUnsafe) -> RvalueRefUnsafe { + r.into() +} + +fn unsafe_lvalue_reference_binds_to_rvalue(r: RvalueRefUnsafe) -> LvalueRefUnsafe { + r.into() +} + +fn main() {} diff --git a/libcc2rs-macros/tests/ui/reference_binding.stderr b/libcc2rs-macros/tests/ui/reference_binding.stderr new file mode 100644 index 0000000000..2199d97ce9 --- /dev/null +++ b/libcc2rs-macros/tests/ui/reference_binding.stderr @@ -0,0 +1,165 @@ +error[E0277]: the trait bound `LvalueRef: From>>` is not satisfied + --> tests/ui/reference_binding.rs:7:7 + | +7 | r.into() + | ^^^^ the trait `From>>` is not implemented for `LvalueRef` + | + = help: the following other types implement trait `From`: + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>>` + `LvalueRef>>` implements `From>` + `LvalueRef>>` implements `From>>` + `LvalueRef>>` implements `From>>` + = note: required for `LvalueRef>` to implement `Into>` + +error[E0277]: the trait bound `LvalueRef: From>>` is not satisfied + --> tests/ui/reference_binding.rs:11:7 + | +11 | r.into() + | ^^^^ the trait `From>>` is not implemented for `LvalueRef` + | + = help: the following other types implement trait `From`: + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>>` + `LvalueRef>>` implements `From>` + `LvalueRef>>` implements `From>>` + `LvalueRef>>` implements `From>>` + = note: required for `LvalueRef>` to implement `Into>` + +error[E0277]: the trait bound `LvalueRef>: From>>>` is not satisfied + --> tests/ui/reference_binding.rs:15:7 + | +15 | r.into() + | ^^^^ the trait `From>>>` is not implemented for `LvalueRef>` + | + = help: the following other types implement trait `From`: + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>>` + `LvalueRef>>` implements `From>` + `LvalueRef>>` implements `From>>` + `LvalueRef>>` implements `From>>` + = note: required for `LvalueRef>>` to implement `Into>>` + +error[E0277]: the trait bound `RvalueRef: From>>` is not satisfied + --> tests/ui/reference_binding.rs:19:7 + | +19 | r.into() + | ^^^^ the trait `From>>` is not implemented for `RvalueRef` + | + = help: the following other types implement trait `From`: + `RvalueRef>` implements `From>` + `RvalueRef>` implements `From>` + `RvalueRef>>` implements `From>` + `RvalueRef>>` implements `From>>` + `RvalueRef>>` implements `From>>` + = note: required for `RvalueRef>` to implement `Into>` + +error[E0277]: the trait bound `RvalueRef: From>` is not satisfied + --> tests/ui/reference_binding.rs:23:7 + | +23 | r.into() + | ^^^^ the trait `From>` is not implemented for `RvalueRef` + | + = help: the following other types implement trait `From`: + `RvalueRef>` implements `From>` + `RvalueRef>` implements `From>` + `RvalueRef>>` implements `From>` + `RvalueRef>>` implements `From>>` + `RvalueRef>>` implements `From>>` + = note: required for `LvalueRef` to implement `Into>` + +error[E0277]: the trait bound `LvalueRef: From>` is not satisfied + --> tests/ui/reference_binding.rs:27:7 + | +27 | r.into() + | ^^^^ the trait `From>` is not implemented for `LvalueRef` + | + = help: the following other types implement trait `From`: + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>>` + `LvalueRef>>` implements `From>` + `LvalueRef>>` implements `From>>` + `LvalueRef>>` implements `From>>` + = note: required for `RvalueRef` to implement `Into>` + +error[E0277]: the trait bound `LvalueRef>>: From>` is not satisfied + --> tests/ui/reference_binding.rs:33:7 + | +33 | r.into() + | ^^^^ the trait `From>` is not implemented for `LvalueRef>>` + | + = help: the following other types implement trait `From`: + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>` + `LvalueRef>` implements `From>>` + `LvalueRef>>` implements `From>` + `LvalueRef>>` implements `From>>` + `LvalueRef>>` implements `From>>` + = note: required for `RvalueRef` to implement `Into>>>` + +error[E0277]: the trait bound `LvalueRefUnsafe: From>>` is not satisfied + --> tests/ui/reference_binding.rs:37:7 + | +37 | r.into() + | ^^^^ the trait `From>>` is not implemented for `LvalueRefUnsafe` + | + = help: the following other types implement trait `From`: + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>>` + `LvalueRefUnsafe>>` implements `From>` + `LvalueRefUnsafe>>` implements `From>>` + = note: required for `LvalueRefUnsafe>` to implement `Into>` + +error[E0277]: the trait bound `RvalueRefUnsafe: From>` is not satisfied + --> tests/ui/reference_binding.rs:41:7 + | +41 | r.into() + | ^^^^ the trait `From>` is not implemented for `RvalueRefUnsafe` + | +help: the following other types implement trait `From` + --> $LIBCC2RS/src/reference.rs + | + | impl<$param> From<$from> for $to { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `RvalueRefUnsafe>` implements `From>` + | `RvalueRefUnsafe>` implements `From>` + | `RvalueRefUnsafe>>` implements `From>` + | `RvalueRefUnsafe>>` implements `From>>` +... + | / binds_unsafe!( + | | LvalueRefUnsafe => LvalueRefUnsafe>, + | | LvalueRefUnsafe => LvalueRefUnsafe>, + | | LvalueRefUnsafe => LvalueRefUnsafe>>, +... | + | | RvalueRefUnsafe> => RvalueRefUnsafe>>, + | | ); + | |_- in this macro invocation + = note: required for `LvalueRefUnsafe` to implement `Into>` + = note: this error originates in the macro `binds_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `LvalueRefUnsafe: From>` is not satisfied + --> tests/ui/reference_binding.rs:45:7 + | +45 | r.into() + | ^^^^ the trait `From>` is not implemented for `LvalueRefUnsafe` + | + = help: the following other types implement trait `From`: + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>` + `LvalueRefUnsafe>` implements `From>>` + `LvalueRefUnsafe>>` implements `From>` + `LvalueRefUnsafe>>` implements `From>>` + = note: required for `RvalueRefUnsafe` to implement `Into>` diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs index f6163cb8c5..42deec5c8c 100644 --- a/libcc2rs/src/reference.rs +++ b/libcc2rs/src/reference.rs @@ -424,3 +424,112 @@ impl AddRvalueReference for LvalueRefUnsafe { impl AddRvalueReference for RvalueRefUnsafe { type Type = RvalueRefUnsafe; } + +#[cfg(test)] +mod tests { + use std::cell::RefCell; + use std::rc::Rc; + + use super::*; + use crate::rc::{AsPointer, Value}; + + fn object(value: i32) -> Value { + Rc::new(RefCell::new(value)) + } + + #[test] + fn lvalue_reference_binds_as_more_cv_qualified() { + let x = object(1); + let r = LvalueRef::::bind(x.as_pointer()); + let to_const: LvalueRef> = r.clone().into(); + let to_volatile: LvalueRef> = r.clone().into(); + let to_const_volatile: LvalueRef>> = r.clone().into(); + let from_const: LvalueRef>> = to_const.clone().into(); + let from_volatile: LvalueRef>> = to_volatile.clone().into(); + r.as_pointer().write(5); + for bound in [ + to_const.as_pointer(), + to_volatile.as_pointer(), + to_const_volatile.as_pointer(), + from_const.as_pointer(), + from_volatile.as_pointer(), + ] { + assert!(bound == x.as_pointer()); + assert_eq!(bound.with(|v| *v), 5); + } + } + + #[test] + fn rvalue_binds_to_const_lvalue_reference() { + let x = object(1); + let r = RvalueRef::::bind(x.as_pointer()); + let to_const: LvalueRef> = r.clone().into(); + let from_const: LvalueRef> = RvalueRef::>::from(r.clone()).into(); + assert!(to_const.as_pointer() == x.as_pointer()); + assert!(from_const.as_pointer() == x.as_pointer()); + } + + #[test] + fn rvalue_reference_binds_as_more_cv_qualified() { + let x = object(1); + let r = RvalueRef::::bind(x.as_pointer()); + let to_const: RvalueRef> = r.clone().into(); + let to_volatile: RvalueRef> = r.clone().into(); + let to_const_volatile: RvalueRef>> = r.clone().into(); + let from_const: RvalueRef>> = to_const.clone().into(); + let from_volatile: RvalueRef>> = to_volatile.clone().into(); + for bound in [ + to_const.as_pointer(), + to_volatile.as_pointer(), + to_const_volatile.as_pointer(), + from_const.as_pointer(), + from_volatile.as_pointer(), + ] { + assert!(bound == x.as_pointer()); + } + } + + #[test] + fn unsafe_references_bind_as_more_cv_qualified() { + let mut x = 1; + let address = &raw mut x; + let r = LvalueRefUnsafe::::bind(address.cast_const()); + let to_const: LvalueRefUnsafe> = r.into(); + let to_const_volatile: LvalueRefUnsafe>> = to_const.into(); + let moved = RvalueRefUnsafe::::bind(address.cast_const()); + let rvalue_to_const: LvalueRefUnsafe> = moved.into(); + unsafe { *r.as_ptr() = 5 }; + assert_eq!(to_const.as_const_ptr(), address.cast_const()); + assert_eq!(to_const_volatile.as_ptr().cast::(), address); + assert_eq!(rvalue_to_const.as_const_ptr(), address.cast_const()); + assert_eq!(unsafe { *to_const.as_const_ptr() }, 5); + } + + #[test] + fn reference_collapsing() { + let x = object(1); + let _: as AddLvalueReference>::Type = + LvalueRef::::bind(x.as_pointer()); + let _: as AddLvalueReference>::Type = + LvalueRef::::bind(x.as_pointer()); + let _: as AddRvalueReference>::Type = + LvalueRef::::bind(x.as_pointer()); + let _: as AddRvalueReference>::Type = + RvalueRef::::bind(x.as_pointer()); + let _: > as AddRvalueReference>::Type = + LvalueRef::>::bind(x.as_pointer()); + } + + #[test] + fn unsafe_reference_collapsing() { + let x = 1; + let _: as AddLvalueReference>::Type = + LvalueRefUnsafe::::bind(&raw const x); + let _: as AddLvalueReference>::Type = + LvalueRefUnsafe::::bind(&raw const x); + let _: as AddRvalueReference>::Type = + LvalueRefUnsafe::::bind(&raw const x); + let _: as AddRvalueReference>::Type = + RvalueRefUnsafe::::bind(&raw const x); + } +} From 7f42416caa1304a3609e45de8441a3c754aaaf3e Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 18:16:38 +0000 Subject: [PATCH 09/11] Update tests --- tests/unit/out/refcount/inline_container_fields.rs | 10 ++++++++-- tests/unit/out/refcount/size_t_ssize_t.rs | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 1736c00ff5..54b17067dd 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -403,7 +403,10 @@ fn main_0() -> i32 { )); let __p: Ptr = __v.decay(); for __i in 0..3 { - ::move_constructor(&__p.offset(__i), RvalueRef::bind(ca.decay().offset(__i))); + MoveConstructible::move_constructor( + &__p.offset(__i), + RvalueRef::bind(ca.decay().offset(__i)), + ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -461,7 +464,10 @@ fn main_0() -> i32 { )); let __p: Ptr> = __v.decay(); for __i in 0..2 { - >::move_constructor(&__p.offset(__i), RvalueRef::bind(va.decay().offset(__i))); + MoveConstructible::move_constructor( + &__p.offset(__i), + RvalueRef::bind(va.decay().offset(__i)), + ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index feb0a033d3..42bee8d2fc 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -63,7 +63,10 @@ pub fn size_t_in_rules_3() { Rc::new(RefCell::new((0..3).map(|_| ::zero_init()).collect())); let __p: Ptr = __v.decay(); for __i in 0..3 { - ::move_constructor(&__p.offset(__i), RvalueRef::bind(ar2.decay().offset(__i))); + MoveConstructible::move_constructor( + &__p.offset(__i), + RvalueRef::bind(ar2.decay().offset(__i)), + ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); From 33973ebe659915b726a9def68818356c9691d597 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 19:27:44 +0000 Subject: [PATCH 10/11] Update tests --- libcc2rs/src/constructor.rs | 15 +- libcc2rs/src/reference.rs | 7 +- .../refcount/out_of_line_methods_cross_tu.rs | 102 ++++----- .../unsafe/out_of_line_methods_cross_tu.rs | 44 ++-- .../out/refcount/p14-class-in-two-files.rs | 49 ++--- .../out/unsafe/p14-class-in-two-files.rs | 36 +-- .../p15-class-template-static-member.rs | 41 ++-- .../p15-class-template-static-member.rs | 30 ++- .../out/refcount/p15-function-template.rs | 49 ++--- .../out/unsafe/p15-function-template.rs | 28 +-- .../out/refcount/p15-inline-function.rs | 41 ++-- .../out/unsafe/p15-inline-function.rs | 26 ++- .../out/refcount/p15-inline-variable.rs | 41 ++-- .../out/unsafe/p15-inline-variable.rs | 30 ++- .../p16-default-argument-lambda-in-class.rs | 86 ++++---- .../p16-default-argument-lambda-in-class.rs | 38 ++-- .../refcount/p16-lambda-in-inline-function.rs | 39 ++-- .../unsafe/p16-lambda-in-inline-function.rs | 24 +- .../out/refcount/basic.scope.block.rs | 62 ++---- .../out/unsafe/basic.scope.block.rs | 40 ++-- tests/std/basic/out/refcount/basic.def.odr.rs | 208 ++++++++---------- tests/std/basic/out/unsafe/basic.def.odr.rs | 125 +++++------ .../out/refcount/class.copy.ctor.rs | 22 +- .../class.ctor/out/unsafe/class.copy.ctor.rs | 8 +- .../out/refcount/expr.mptr.oper.rs | 4 +- .../out/unsafe/expr.mptr.oper.rs | 4 +- .../stmt.select/out/refcount/stmt.if.rs | 31 ++- .../stmt.select/out/refcount/stmt.switch.rs | 52 ++--- .../stmt.select/out/unsafe/stmt.if.rs | 18 +- .../stmt.select/out/unsafe/stmt.switch.rs | 28 +-- .../utility/out/refcount/forward-helpers.rs | 149 ++++++------- .../utilities/utility/out/refcount/forward.rs | 17 +- .../utility/out/unsafe/forward-helpers.rs | 99 +++++---- .../utilities/utility/out/unsafe/forward.rs | 8 +- tests/unit/out/refcount/copy_assign.rs | 39 ++-- tests/unit/out/refcount/copy_ctor.rs | 50 +++-- .../unit/out/refcount/copy_move_defaulted.rs | 108 +++++---- tests/unit/out/refcount/copy_move_deleted.rs | 28 ++- tests/unit/out/refcount/fn_ptr_struct.rs | 5 +- tests/unit/out/refcount/forward_basic.rs | 10 +- tests/unit/out/refcount/forward_decltype.rs | 6 +- tests/unit/out/refcount/forward_explicit.rs | 12 +- tests/unit/out/refcount/forward_pack.rs | 10 +- .../out/refcount/inline_container_fields.rs | 32 ++- tests/unit/out/refcount/lambda_as_field.rs | 8 +- .../out/refcount/lambda_capture_copy_ctor.rs | 34 ++- .../out/refcount/lambda_move_only_capture.rs | 13 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 6 +- tests/unit/out/refcount/map_try_emplace.rs | 32 ++- tests/unit/out/refcount/max.rs | 3 +- tests/unit/out/refcount/move_assign.rs | 22 +- tests/unit/out/refcount/move_ctor.rs | 31 +-- tests/unit/out/refcount/move_this.rs | 16 +- tests/unit/out/refcount/rule_of_five.rs | 22 +- tests/unit/out/refcount/rule_of_three.rs | 10 +- .../unit/out/refcount/rvalue_rule_arg_move.rs | 8 +- tests/unit/out/refcount/size_t_ssize_t.rs | 8 +- tests/unit/out/refcount/sort_no_copy.rs | 12 +- .../refcount/structured_binding_copy_ctor.rs | 5 +- .../structured_binding_element_ctor.rs | 20 +- .../refcount/structured_binding_move_ctor.rs | 8 +- tests/unit/out/refcount/swap_map_no_copy.rs | 40 ++-- tests/unit/out/unsafe/clone_vs_move.rs | 2 +- tests/unit/out/unsafe/copy_assign.rs | 49 +++-- tests/unit/out/unsafe/copy_ctor.rs | 50 +++-- tests/unit/out/unsafe/copy_move_defaulted.rs | 117 ++++++---- tests/unit/out/unsafe/copy_move_deleted.rs | 28 ++- tests/unit/out/unsafe/fn_ptr_struct.rs | 5 +- tests/unit/out/unsafe/forward_basic.rs | 10 +- tests/unit/out/unsafe/forward_decltype.rs | 6 +- tests/unit/out/unsafe/forward_explicit.rs | 12 +- tests/unit/out/unsafe/forward_pack.rs | 10 +- .../out/unsafe/inline_container_fields.rs | 20 +- tests/unit/out/unsafe/lambda_as_field.rs | 5 +- .../out/unsafe/lambda_capture_copy_ctor.rs | 31 ++- .../out/unsafe/lambda_move_only_capture.rs | 13 +- tests/unit/out/unsafe/map_key_copy_ctor.rs | 6 +- tests/unit/out/unsafe/map_try_emplace.rs | 89 +++++--- tests/unit/out/unsafe/max.rs | 3 +- tests/unit/out/unsafe/move_assign.rs | 22 +- tests/unit/out/unsafe/move_ctor.rs | 31 +-- tests/unit/out/unsafe/move_this.rs | 18 +- tests/unit/out/unsafe/rule_of_five.rs | 22 +- tests/unit/out/unsafe/rule_of_three.rs | 10 +- tests/unit/out/unsafe/rvalue_rule_arg_move.rs | 6 +- tests/unit/out/unsafe/sort_no_copy.rs | 12 +- .../unsafe/structured_binding_copy_ctor.rs | 5 +- .../unsafe/structured_binding_element_ctor.rs | 20 +- .../unsafe/structured_binding_move_ctor.rs | 8 +- tests/unit/out/unsafe/swap_map_no_copy.rs | 40 ++-- tests/unit/out/unsafe/vector2.rs | 2 +- 91 files changed, 1537 insertions(+), 1314 deletions(-) diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index c155c5bf6f..a087433a91 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -183,7 +183,10 @@ pub trait TriviallyCopyConstructibleUnsafe: CopyConstructibleUnsafe { pub trait CopyAssignableUnsafe: MoveAssignableUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn copy_assign(this: *mut Self, src: crate::LvalueRefUnsafe>) -> *mut Self; + unsafe fn copy_assign( + this: *mut Self, + src: crate::LvalueRefUnsafe>, + ) -> *mut Self; } pub trait TriviallyCopyAssignableUnsafe: CopyAssignableUnsafe {} @@ -849,7 +852,10 @@ impl MoveAssignableUnsafe for FnPtr { } impl CopyAssignableUnsafe for FnPtr { - unsafe fn copy_assign(this: *mut Self, src: crate::LvalueRefUnsafe>) -> *mut Self { + unsafe fn copy_assign( + this: *mut Self, + src: crate::LvalueRefUnsafe>, + ) -> *mut Self { let src = src.as_const_ptr(); unsafe { *this = (*src).copy_from() }; this @@ -1011,7 +1017,10 @@ impl MoveAssignableUnsafe for [T; N] { } impl CopyAssignableUnsafe for [T; N] { - unsafe fn copy_assign(this: *mut Self, src: crate::LvalueRefUnsafe>) -> *mut Self { + unsafe fn copy_assign( + this: *mut Self, + src: crate::LvalueRefUnsafe>, + ) -> *mut Self { let src = src.as_const_ptr(); let src = src as *const T; let dst = this as *mut T; diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs index 146a7cace6..cce1d74a88 100644 --- a/libcc2rs/src/reference.rs +++ b/libcc2rs/src/reference.rs @@ -245,12 +245,7 @@ macro_rules! reference_unsafe { impl SwappableUnsafe for $name { unsafe fn swap(this: *mut Self, other: *mut Self) { - unsafe { - T::swap( - (*this).as_ptr().cast::(), - (*other).as_ptr().cast::(), - ) - } + unsafe { T::swap((*this).as_ptr().cast::(), (*other).as_ptr().cast::()) } } } 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 fb39ef405f..00e752b7cf 100644 --- a/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs +++ b/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs @@ -24,12 +24,18 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.v); + } +} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default)] #[byte_size(4)] pub struct M { #[offset(0)] pub v: i32, } +impl M {} pub trait Base { fn apply(&mut self, x: i32) -> i32; } @@ -50,6 +56,7 @@ pub struct Derived { #[offset(8)] pub factor: i32, } +impl Derived {} #[derive( Copy, Clone, @@ -78,10 +85,10 @@ pub fn main() { } fn main_0() -> i32 { object!(s, S(1)); - assert!((({ SImpl::get(&s.as_pointer(),) }) == 1)); - ({ SImpl::set(&s.as_pointer(), 4) }); - assert!((({ SImpl::get(&s.as_pointer(),) }) == 4)); - assert!((({ SImpl::add(&s.as_pointer(), 2,) }) == 6)); + assert!((({ S::get(s.as_pointer(),) }) == 1)); + ({ S::set(s.as_pointer(), 4) }); + assert!((({ S::get(s.as_pointer(),) }) == 4)); + assert!((({ S::add(s.as_pointer(), 2,) }) == 6)); object!(m, M(2)); object!(n, M, RvalueRef::bind(m.as_pointer())); assert!(({ (*n.borrow()).v } == 2)); @@ -99,21 +106,49 @@ fn main_0() -> i32 { assert!((({ pair_diff_0((pair.as_pointer()),) }) == 4)); return 0; } +impl S { + pub fn construct(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } +} +impl M { + pub fn construct(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } +} impl MoveConstructible for M { - fn move_constructor(this: &Ptr, _a0: RvalueRef) { + fn move_constructor(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); - field!((*this), v).write({ (*_a0.upgrade().deref()).v }); + field!(this, v).write({ (*_a0.upgrade().deref()).v }); } } impl CopyConstructible for M { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); - field!((*this), v).write((o.with(|__s| __s.v) + 1)); + field!(this, v).write((o.with(|__s| __s.v) + 1)); + } +} +impl Derived { + pub fn construct(this: Ptr, mut factor: i32) { + field!(this, factor).write(factor); } } impl S {} impl Destructible for S { - fn destroy(this: &Ptr) {} + fn destroy(this: Ptr) {} +} +impl S { + pub fn set(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } +} +impl S { + pub fn add(this: Ptr, mut x: i32) -> i32 { + { + field!(this, v).with_mut(|__v| *__v = *__v + x) + }; + return this.with(|__s| __s.v); + } } impl M {} pub fn move_m_1(mut x: i32) -> i32 { @@ -130,53 +165,4 @@ impl Base for Derived { return ({ self.factor } * x); } } -pub trait DerivedImpl { - fn construct(&self, mut factor: i32) { - unimplemented!() - } -} -impl DerivedImpl for Ptr { - fn construct(&self, mut factor: i32) { - field!((*self), factor).write(factor); - } -} -pub trait MImpl { - fn construct(&self, mut x: i32) { - unimplemented!() - } -} -impl MImpl for Ptr { - fn construct(&self, mut x: i32) { - field!((*self), v).write(x); - } -} -pub trait SImpl { - fn construct(&self, mut x: i32) { - unimplemented!() - } - fn get(&self) -> i32; - fn set(&self, mut x: i32) { - unimplemented!() - } - fn add(&self, mut x: i32) -> i32 { - unimplemented!() - } -} -impl SImpl for Ptr { - fn get(&self) -> i32 { - return (*self).with(|__s| __s.v); - } - fn construct(&self, mut x: i32) { - field!((*self), v).write(x); - } - fn set(&self, mut x: i32) { - field!((*self), v).write(x); - } - fn add(&self, mut x: i32) -> i32 { - { - field!((*self), v).with_mut(|__v| *__v = *__v + x) - }; - return (*self).with(|__s| __s.v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs b/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs index 629afc8e5a..059056900a 100644 --- a/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs +++ b/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs @@ -22,8 +22,8 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn get(&self) -> i32 { - return self.v; + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).v; } } #[repr(C)] @@ -76,10 +76,10 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(s, S(1)); - assert!(((unsafe { S::get(&s,) }) == (1))); - (unsafe { S::set(&mut s, 4) }); - assert!(((unsafe { S::get(&s,) }) == (4))); - assert!(((unsafe { S::add(&mut s, 2,) }) == (6))); + assert!(((unsafe { S::get(&raw const s,) }) == (1))); + (unsafe { S::set(&raw mut s, 4) }); + assert!(((unsafe { S::get(&raw const s,) }) == (4))); + assert!(((unsafe { S::add(&raw mut s, 2,) }) == (6))); object_unsafe!(m, M(2)); object_unsafe!(n, M, RvalueRefUnsafe::bind(&mut m)); assert!(((n.v) == (2))); @@ -98,45 +98,45 @@ unsafe fn main_0() -> i32 { return 0; } impl S { - pub unsafe fn construct(&mut self, mut x: i32) { - (&raw mut self.v).write(x); + pub unsafe fn construct(this: *mut Self, mut x: i32) { + (&raw mut (*this).v).write(x); } } impl M { - pub unsafe fn construct(&mut self, mut x: i32) { - (&raw mut self.v).write(x); + pub unsafe fn construct(this: *mut Self, mut x: i32) { + (&raw mut (*this).v).write(x); } } impl MoveConstructibleUnsafe for M { - unsafe fn move_constructor(&mut self, _a0: RvalueRefUnsafe) { + unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { let _a0 = (_a0.as_ptr() as *mut M); - (&raw mut self.v).write((*_a0).v); + (&raw mut (*this).v).write((*_a0).v); } } impl CopyConstructibleUnsafe for M { - unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const M); - (&raw mut self.v).write((((*o).v) + (1))); + (&raw mut (*this).v).write((((*o).v) + (1))); } } impl Derived { - pub unsafe fn construct(&mut self, mut factor: i32) { - (&raw mut self.factor).write(factor); + pub unsafe fn construct(this: *mut Self, mut factor: i32) { + (&raw mut (*this).factor).write(factor); } } impl S {} impl DestructibleUnsafe for S { - unsafe fn destroy(&mut self) {} + unsafe fn destroy(this: *mut Self) {} } impl S { - pub unsafe fn set(&mut self, mut x: i32) { - self.v = x; + pub unsafe fn set(this: *mut Self, mut x: i32) { + (*this).v = x; } } impl S { - pub unsafe fn add(&mut self, mut x: i32) -> i32 { - self.v += x; - return self.v; + pub unsafe fn add(this: *mut Self, mut x: i32) -> i32 { + (*this).v += x; + return (*this).v; } } impl M {} diff --git a/tests/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 8f39664a18..efa08bb605 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs @@ -53,22 +53,28 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - field!((*this), uses).write(0); + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -91,15 +97,15 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } thread_local!( pub static check_4: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 2 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_4.with(Value::clone).as_pointer()) + Destructible::destroy(check_4.with(Value::clone).as_pointer()) }); __static }; @@ -108,11 +114,11 @@ thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&shared_5.with(Value::clone).as_pointer()) + Destructible::destroy(shared_5.with(Value::clone).as_pointer()) }); __static }; @@ -140,11 +146,11 @@ thread_local!( static local_6: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&local_6.with(Value::clone).as_pointer()) + Destructible::destroy(local_6.with(Value::clone).as_pointer()) }); __static }; @@ -154,8 +160,8 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); - ({ LifetimeTrackedImpl::use_(&({ HasInlineMembers::instance() })) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(({ HasInlineMembers::instance() })) }); ({ b_use_7() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); assert!(({ (*shared_5.with(Value::clone).borrow()).uses } == 2)); @@ -166,8 +172,8 @@ fn main_0() -> i32 { return 0; } pub fn b_use_7() { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); - ({ LifetimeTrackedImpl::use_(&({ HasInlineMembers::instance() })) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(({ HasInlineMembers::instance() })) }); } pub fn b_shared_address_8() -> Ptr { return (shared_5.with(|v| v.as_pointer())); @@ -175,17 +181,6 @@ pub fn b_shared_address_8() -> Ptr { pub fn b_instance_address_9() -> Ptr { return ({ HasInlineMembers::instance() }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index d0ae84b6bf..9d5edbf4fc 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs @@ -36,26 +36,26 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); - (&raw mut self.uses).write(0); + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -75,8 +75,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub static mut check_4: std::cell::LazyCell = @@ -94,7 +96,7 @@ pub static mut shared_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -124,7 +126,7 @@ static mut local_6: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -140,8 +142,10 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); - (unsafe { LifetimeTracked::use_(&(*(unsafe { HasInlineMembers::instance() }))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { HasInlineMembers::instance() }))) }); (unsafe { b_use_7() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)).uses) == (2))); @@ -156,8 +160,10 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_7() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); - (unsafe { LifetimeTracked::use_(&(*(unsafe { HasInlineMembers::instance() }))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { HasInlineMembers::instance() }))) }); } pub unsafe fn b_shared_address_8() -> *mut LifetimeTracked { return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index 240f936fac..f5e3f4f2bc 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs @@ -53,22 +53,28 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - field!((*this), uses).write(0); + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -76,11 +82,11 @@ thread_local!( pub static member_4: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&member_4.with(Value::clone).as_pointer()) + Destructible::destroy(member_4.with(Value::clone).as_pointer()) }); __static }; @@ -103,11 +109,11 @@ thread_local!( pub static member_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&member_5.with(Value::clone).as_pointer()) + Destructible::destroy(member_5.with(Value::clone).as_pointer()) }); __static }; @@ -131,7 +137,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&member_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(member_4.with(|v| v.as_pointer())) }); ({ b_use_int_6() }); ({ b_use_long_7() }); assert!(({ (*member_4.with(Value::clone).borrow()).uses } == 2)); @@ -142,25 +148,14 @@ fn main_0() -> i32 { return 0; } pub fn b_use_int_6() { - ({ LifetimeTrackedImpl::use_(&member_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(member_4.with(|v| v.as_pointer())) }); } pub fn b_use_long_7() { - ({ LifetimeTrackedImpl::use_(&member_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(member_5.with(|v| v.as_pointer())) }); } pub fn b_int_address_8() -> Ptr { return (member_4.with(|v| v.as_pointer())); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index 49bb41ee04..71eb9129c1 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs @@ -36,26 +36,26 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); - (&raw mut self.uses).write(0); + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -64,7 +64,7 @@ pub static mut member_4: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -90,7 +90,7 @@ pub static mut member_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -118,7 +118,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) + }); (unsafe { b_use_int_6() }); (unsafe { b_use_long_7() }); assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut member_4)).uses) == (2))); @@ -133,10 +135,14 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_int_6() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) + }); } pub unsafe fn b_use_long_7() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_5))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut member_5))) + }); } pub unsafe fn b_int_address_8() -> *mut LifetimeTracked { return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4)) diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index 2d248f9a0b..42f9c61e41 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs @@ -53,22 +53,28 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - field!((*this), uses).write(0); + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -91,8 +97,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } pub fn count_4() -> i32 { @@ -108,11 +114,11 @@ thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_5.with(Value::clone).as_pointer()) + Destructible::destroy(t_5.with(Value::clone).as_pointer()) }); __static }; @@ -124,11 +130,11 @@ thread_local!( static t_8: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_8.with(Value::clone).as_pointer()) + Destructible::destroy(t_8.with(Value::clone).as_pointer()) }); __static }; @@ -140,11 +146,11 @@ thread_local!( static t_11: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_11.with(Value::clone).as_pointer()) + Destructible::destroy(t_11.with(Value::clone).as_pointer()) }); __static }; @@ -156,7 +162,7 @@ thread_local!( pub static check_13: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 4 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_13.with(Value::clone).as_pointer()) + Destructible::destroy(check_13.with(Value::clone).as_pointer()) }); __static }; @@ -200,11 +206,11 @@ thread_local!( static t_19: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_19.with(Value::clone).as_pointer()) + Destructible::destroy(t_19.with(Value::clone).as_pointer()) }); __static }; @@ -235,17 +241,6 @@ pub fn b_count_local_15() -> i32 { )] #[byte_size(1)] pub struct S_21 {} -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index 4c6ad661cf..e40f13ae30 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -36,26 +36,26 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); - (&raw mut self.uses).write(0); + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -75,8 +75,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub unsafe fn count_4() -> i32 { @@ -92,7 +94,7 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -106,7 +108,7 @@ static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -120,7 +122,7 @@ static mut t_11: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -179,7 +181,7 @@ static mut t_19: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs index e714671e8a..318037e78f 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs @@ -53,22 +53,28 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - field!((*this), uses).write(0); + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -91,8 +97,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } pub fn instance_4() -> Ptr { @@ -102,11 +108,11 @@ thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_5.with(Value::clone).as_pointer()) + Destructible::destroy(t_5.with(Value::clone).as_pointer()) }); __static }; @@ -115,7 +121,7 @@ thread_local!( pub static check_6: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_6.with(Value::clone).as_pointer()) + Destructible::destroy(check_6.with(Value::clone).as_pointer()) }); __static }; @@ -126,7 +132,7 @@ pub fn main() { } fn main_0() -> i32 { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); - ({ LifetimeTrackedImpl::use_(&({ instance_4() })) }); + ({ LifetimeTracked::use_(({ instance_4() })) }); ({ b_use_7() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); @@ -137,22 +143,11 @@ fn main_0() -> i32 { return 0; } pub fn b_use_7() { - ({ LifetimeTrackedImpl::use_(&({ instance_4() })) }); + ({ LifetimeTracked::use_(({ instance_4() })) }); } pub fn b_address_8() -> Ptr { return ({ instance_4() }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs index 8de81f2055..afc2b03b66 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs @@ -36,26 +36,26 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); - (&raw mut self.uses).write(0); + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -75,8 +75,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub unsafe fn instance_4() -> *mut LifetimeTracked { @@ -86,7 +88,7 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -113,7 +115,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); - (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_4() }))) }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { instance_4() }))) }); (unsafe { b_use_7() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); @@ -124,7 +126,7 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_7() { - (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_4() }))) }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { instance_4() }))) }); } pub unsafe fn b_address_8() -> *mut LifetimeTracked { return (unsafe { instance_4() }); diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index 08640764f2..cfbfc17551 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs @@ -53,22 +53,28 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - field!((*this), uses).write(0); + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -91,15 +97,15 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } thread_local!( pub static check_4: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_4.with(Value::clone).as_pointer()) + Destructible::destroy(check_4.with(Value::clone).as_pointer()) }); __static }; @@ -108,11 +114,11 @@ thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&shared_5.with(Value::clone).as_pointer()) + Destructible::destroy(shared_5.with(Value::clone).as_pointer()) }); __static }; @@ -122,7 +128,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); ({ b_use_6() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); @@ -132,22 +138,11 @@ fn main_0() -> i32 { return 0; } pub fn b_use_6() { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); } pub fn b_address_7() -> Ptr { return (shared_5.with(|v| v.as_pointer())); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index 100cb9920b..890dc010a4 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs @@ -36,26 +36,26 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); - (&raw mut self.uses).write(0); + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -75,8 +75,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub static mut check_4: std::cell::LazyCell = @@ -94,7 +96,7 @@ pub static mut shared_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -110,7 +112,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); (unsafe { b_use_6() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); @@ -124,7 +128,9 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_6() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); } pub unsafe fn b_address_7() -> *mut LifetimeTracked { return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index d2660015b3..0b2af40577 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs @@ -53,22 +53,28 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - field!((*this), uses).write(0); + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -91,8 +97,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } #[derive( @@ -109,15 +115,32 @@ impl Destructible for AssertsDtorCountAtExit { )] #[byte_size(1)] pub struct X {} +impl X { + pub fn h(this: Ptr, mut cond: bool, mut p: FnPtr) { + if cond { + ({ + X::h( + this.clone(), + false, + FnPtr::::new(|| { + ({ LifetimeTracked::use_(local_4.with(|v| v.as_pointer())) }); + }), + ) + }); + } else { + ({ p.call() }); + } + } +} thread_local!( static local_4: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&local_4.with(Value::clone).as_pointer()) + Destructible::destroy(local_4.with(Value::clone).as_pointer()) }); __static }; @@ -126,7 +149,7 @@ thread_local!( pub static check_5: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_5.with(Value::clone).as_pointer()) + Destructible::destroy(check_5.with(Value::clone).as_pointer()) }); __static }; @@ -139,11 +162,11 @@ fn main_0() -> i32 { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); let x: Value = Rc::new(RefCell::new(::default())); ({ - XImpl::h( - &x.as_pointer(), + X::h( + x.as_pointer(), true, FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(local_4.with(|v| v.as_pointer())) }); }), ) }); @@ -157,46 +180,15 @@ fn main_0() -> i32 { pub fn b_call_6() { let x: Value = Rc::new(RefCell::new(::default())); ({ - XImpl::h( - &x.as_pointer(), + X::h( + x.as_pointer(), true, FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(local_4.with(|v| v.as_pointer())) }); }), ) }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait XImpl { - fn h(&self, cond: bool, p: FnPtr); -} -impl XImpl for Ptr { - fn h(&self, mut cond: bool, mut p: FnPtr) { - if cond { - ({ - XImpl::h( - self, - false, - FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_4.with(|v| v.as_pointer())) }); - }), - ) - }); - } else { - ({ p.call() }); - } - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs index 2d66db0898..f0ccef5c69 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs @@ -36,26 +36,26 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); - (&raw mut self.uses).write(0); + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -75,8 +75,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } #[repr(C)] @@ -92,16 +94,18 @@ impl DestructibleUnsafe for AssertsDtorCountAtExit { )] pub struct X {} impl X { - pub unsafe fn h(&mut self, mut cond: bool, mut p: Option) { + pub unsafe fn h(this: *mut Self, mut cond: bool, mut p: Option) { if cond { (unsafe { X::h( - self, + this, false, Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), + &raw const (*std::cell::LazyCell::force_mut( + &mut *&raw mut local_4, + )), ) }); }), @@ -116,7 +120,7 @@ static mut local_4: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -146,12 +150,12 @@ unsafe fn main_0() -> i32 { let mut x: X = ::default(); (unsafe { X::h( - &mut x, + &raw mut x, true, Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), ) }); }), @@ -168,12 +172,12 @@ pub unsafe fn b_call_6() { let mut x: X = ::default(); (unsafe { X::h( - &mut x, + &raw mut x, true, Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), ) }); }), diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index 4558b47766..1881620397 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs @@ -53,22 +53,28 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - field!((*this), uses).write(0); + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -91,8 +97,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } pub fn f_4(mut cond: bool, mut p: FnPtr) { @@ -101,7 +107,7 @@ pub fn f_4(mut cond: bool, mut p: FnPtr) { f_4( false, FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(local_5.with(|v| v.as_pointer())) }); }), ) }); @@ -113,11 +119,11 @@ thread_local!( static local_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&local_5.with(Value::clone).as_pointer()) + Destructible::destroy(local_5.with(Value::clone).as_pointer()) }); __static }; @@ -126,7 +132,7 @@ thread_local!( pub static check_6: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_6.with(Value::clone).as_pointer()) + Destructible::destroy(check_6.with(Value::clone).as_pointer()) }); __static }; @@ -148,17 +154,6 @@ fn main_0() -> i32 { pub fn b_call_7() { ({ f_4(true, FnPtr::::null()) }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index 9d037055d2..93cd43ae0b 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs @@ -36,26 +36,26 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); - (&raw mut self.uses).write(0); + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -75,8 +75,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub unsafe fn f_4(mut cond: bool, mut p: Option) { @@ -87,7 +89,7 @@ pub unsafe fn f_4(mut cond: bool, mut p: Option) { Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_5)), + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut local_5)), ) }); }), @@ -101,7 +103,7 @@ static mut local_5: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs index 02d1469f89..302b248269 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs @@ -53,22 +53,28 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - field!((*this), uses).write(0); + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -99,8 +105,13 @@ pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] pub value: i32, } +impl p1_1_condition_variable_visible_in_else_ConvertsToBool { + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.value) != 0); + } +} impl Destructible for p1_1_condition_variable_visible_in_else_ConvertsToBool { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -110,12 +121,10 @@ pub fn test_7() { RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }), ); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if ({ - p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(condition.as_pointer()) }) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); } else { @@ -132,12 +141,10 @@ pub fn test_7() { RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }), ); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if ({ - p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(condition.as_pointer()) }) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); assert!(({ (*condition.borrow()).value } == 6)); @@ -194,7 +201,7 @@ pub fn test_9() { } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 6)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 5)); - ({ LifetimeTrackedImpl::use_(&scoped.as_pointer()) }); + ({ LifetimeTracked::use_(scoped.as_pointer()) }); assert!(({ (*scoped.borrow()).uses } == 1)); } pub fn test_10() { @@ -223,13 +230,13 @@ pub fn test_11() { { object!(tracked, LifetimeTracked); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); - ({ LifetimeTrackedImpl::use_(&tracked.as_pointer()) }); + ({ LifetimeTracked::use_(tracked.as_pointer()) }); assert!(({ (*tracked.borrow()).uses } == 1)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); } assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); assert!(({ (*tracked.borrow()).uses } == 0)); - ({ LifetimeTrackedImpl::use_(&tracked.as_pointer()) }); + ({ LifetimeTracked::use_(tracked.as_pointer()) }); assert!(({ (*tracked.borrow()).uses } == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); } @@ -307,27 +314,6 @@ fn main_0() -> i32 { ({ test_16() }); return 0; } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl { - fn to_bool(&self) -> bool; -} -impl p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl - for Ptr -{ - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.value) != 0); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs index 6164087fa1..5d170897e2 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs @@ -36,26 +36,26 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); - (&raw mut self.uses).write(0); + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -80,12 +80,12 @@ pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { pub value: i32, } impl p1_1_condition_variable_visible_in_else_ConvertsToBool { - pub unsafe fn to_bool(&self) -> bool { - return ((self.value) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).value) != (0)); } } impl DestructibleUnsafe for p1_1_condition_variable_visible_in_else_ConvertsToBool { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); } } @@ -94,10 +94,11 @@ pub unsafe fn test_7() { let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); - if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) - { + if (unsafe { + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&raw const condition) + }) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); } else { (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); @@ -112,10 +113,11 @@ pub unsafe fn test_7() { let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); - if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) - { + if (unsafe { + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&raw const condition) + }) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); assert!(((condition.value) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)) == (1))); @@ -171,7 +173,7 @@ pub unsafe fn test_9() { } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (5))); - (unsafe { LifetimeTracked::use_(&scoped) }); + (unsafe { LifetimeTracked::use_(&raw const scoped) }); assert!(((scoped.uses) == (1))); } pub unsafe fn test_10() { @@ -196,13 +198,13 @@ pub unsafe fn test_11() { { object_unsafe!(tracked, LifetimeTracked); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); - (unsafe { LifetimeTracked::use_(&tracked) }); + (unsafe { LifetimeTracked::use_(&raw const tracked) }); assert!(((tracked.uses) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); assert!(((tracked.uses) == (0))); - (unsafe { LifetimeTracked::use_(&tracked) }); + (unsafe { LifetimeTracked::use_(&raw const tracked) }); assert!(((tracked.uses) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); } diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 737101c440..5d0468bac2 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -33,11 +33,14 @@ impl HasConstexprCtor { pub fn reset() { copyCount_0.with(|rc| *rc.borrow_mut() = 0); } + pub fn construct(this: Ptr, mut v: i32) { + field!(this, m).write(v); + } } impl CopyConstructible for HasConstexprCtor { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); - field!((*this), m).write(o.with(|__s| __s.m)); + field!(this, m).write(o.with(|__s| __s.m)); (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -88,22 +91,28 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - field!((*this), uses).write(0); + field!(this, uses).write(0); (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -113,13 +122,13 @@ pub fn test_5() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 3); + HasConstexprCtor::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 4); + HasConstexprCtor::construct(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]; @@ -130,13 +139,13 @@ pub fn test_5() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 3); + HasConstexprCtor::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 4); + HasConstexprCtor::construct(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ][(1) as usize] @@ -157,7 +166,7 @@ pub fn test_6() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 5); + HasConstexprCtor::construct(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } .m @@ -180,14 +189,14 @@ pub fn test_7() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 7); + HasConstexprCtor::construct(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } else { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 9); + HasConstexprCtor::construct(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }) @@ -216,7 +225,7 @@ pub fn test_9() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 5); + HasConstexprCtor::construct(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -263,11 +272,11 @@ thread_local!( pub static global_12: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&global_12.with(Value::clone).as_pointer()) + Destructible::destroy(global_12.with(Value::clone).as_pointer()) }); __static }; @@ -276,7 +285,7 @@ pub fn test_13() { ({ LifetimeTracked::reset() }); let r: Ptr = global_12.with(|v| v.as_pointer()); let f: Value> = Rc::new(RefCell::new(FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&global_12.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(global_12.with(|v| v.as_pointer())) }); }))); assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); ({ (*f.borrow()).call() }); @@ -293,19 +302,16 @@ pub fn test_14() { let r: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( - &__v.as_pointer(), - LvalueRef::bind((r).clone()), - ); + CopyConstructible::copy_constructor(__v.as_pointer(), LvalueRef::bind((r).clone())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || { - ({ LifetimeTrackedImpl::use_(&r.as_pointer()) }); + ({ LifetimeTracked::use_(r.as_pointer()) }); } ))); let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); ({ (*f.borrow()).call() }); assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); @@ -334,7 +340,7 @@ pub fn test_16() { let __v: Value = Rc::new(RefCell::new(::zero_init())); CopyConstructible::copy_constructor( - &__v.as_pointer(), + __v.as_pointer(), LvalueRef::bind(k.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -384,14 +390,20 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { #[offset(4)] pub scratch: i32, } +impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, value).write(v); + field!(this, scratch).write(0); + } +} impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember { fn copy_constructor( - this: &Ptr, + this: Ptr, o: LvalueRef>, ) { let o = o.as_pointer(); - field!((*this), value).write(o.with(|__s| __s.value)); - field!((*this), scratch).write(o.with(|__s| __s.scratch)); + field!(this, value).write(o.with(|__s| __s.value)); + field!(this, scratch).write(o.with(|__s| __s.scratch)); (*copies_18.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -406,7 +418,7 @@ pub fn test_19() { ::zero_init(), )); CopyConstructible::copy_constructor( - &__v.as_pointer(), + __v.as_pointer(), LvalueRef::bind(k.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -434,9 +446,9 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { pub b: LifetimeTracked, } impl DefaultConstructible for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, a)); - DefaultConstructible::default_constructor(&field_ptr!(this, b)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, a)); + DefaultConstructible::default_constructor(field_ptr!(this, b)); } } pub fn test_20() { @@ -446,19 +458,19 @@ pub fn test_20() { a: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, b: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, }, )); let _dtor_p = - std::mem::DropGuard::new(p.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(p.clone(), |__p| Destructible::destroy(__p.as_pointer())); let __decomp_21: Ptr = p.as_pointer(); let f: Value usize>> = Rc::new(RefCell::new(FnPtr:: usize>::new(|| -> usize { @@ -482,17 +494,31 @@ pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(4)] pub n: i32, } +impl p7_member_access_captures_this_HasMemberUsedInLambda { + pub fn makeLambda(this: Ptr) -> FnPtr i32> { + return lambda!( + { + let this_: Value> = + Rc::new(RefCell::new((this).clone())); + }, + || -> i32 { + ({ LifetimeTracked::use_({ field_ptr!((*this_.borrow()), x) }) }); + return (*this_.borrow()).with(|__s| __s.n); + } + ); + } +} impl DefaultConstructible for p7_member_access_captures_this_HasMemberUsedInLambda { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, x)); - field!((*this), n).write(1); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, x)); + field!(this, n).write(1); } } pub fn test_22() { ({ LifetimeTracked::reset() }); object!(c, p7_member_access_captures_this_HasMemberUsedInLambda); let f: Value i32>> = Rc::new(RefCell::new( - ({ p7_member_access_captures_this_HasMemberUsedInLambdaImpl::makeLambda(&c.as_pointer()) }), + ({ p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(c.as_pointer()) }), )); assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); assert!(({ (({ (*f.borrow()).call() }) == 1) })); @@ -511,9 +537,18 @@ pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, } +impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + pub fn sizer(this: Ptr) -> FnPtr usize> { + return FnPtr:: usize>::new(|| -> usize { + { + return 4usize; + } + }); + } +} impl DefaultConstructible for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, x)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, x)); } } pub fn test_23() { @@ -523,9 +558,7 @@ pub fn test_23() { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda ); let f: Value usize>> = Rc::new(RefCell::new( - ({ - p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl::sizer(&c.as_pointer()) - }), + ({ p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(c.as_pointer()) }), )); assert!(({ (({ (*f.borrow()).call() }) == 4usize) })); assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); @@ -569,7 +602,7 @@ thread_local!( #[byte_size(1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl DefaultConstructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { (*t_ctors_27.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -577,7 +610,7 @@ pub fn test_28() { let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + DefaultConstructible::default_constructor(__p.clone()); __p }; assert!(!((p).is_null())); @@ -604,8 +637,8 @@ pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } impl DefaultConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(3); + fn default_constructor(this: Ptr) { + field!(this, value).write(3); (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -616,7 +649,7 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -648,7 +681,7 @@ thread_local!( #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl DefaultConstructible for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -660,7 +693,7 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { Rc::new(RefCell::new( ::zero_init(), )); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -685,8 +718,8 @@ pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } impl DefaultConstructible for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, m)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, m)); } } pub fn test_33() { @@ -832,89 +865,26 @@ impl p4_1_pure_virtual_without_definition_HasPureVirtual } } impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { unreachable!( "p9_destructor_not_potentially_invoked_HasUndefinedDestructor::destroy is never defined" ) } } impl CopyConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn copy_constructor(this: &Ptr, _: LvalueRef>) { + fn copy_constructor(this: Ptr, _: LvalueRef>) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } impl CopyAssignable for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn copy_assign(this: &Ptr, _: LvalueRef>) -> Ptr { + fn copy_assign(this: Ptr, _: LvalueRef>) -> Ptr { unreachable!( "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" ) } } -pub trait HasConstexprCtorImpl { - fn construct(&self, v: i32); -} -impl HasConstexprCtorImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), m).write(v); - } -} -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl { - fn construct(&self, v: i32); -} -impl p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl - for Ptr -{ - fn construct(&self, mut v: i32) { - field!((*self), value).write(v); - field!((*self), scratch).write(0); - } -} -pub trait p7_member_access_captures_this_HasMemberUsedInLambdaImpl { - fn makeLambda(&self) -> FnPtr i32>; -} -impl p7_member_access_captures_this_HasMemberUsedInLambdaImpl - for Ptr -{ - fn makeLambda(&self) -> FnPtr i32> { - return lambda!( - { - let this_: Value> = - Rc::new(RefCell::new((*self).clone())); - }, - || -> i32 { - ({ LifetimeTrackedImpl::use_(&field_ptr!((*this_.borrow()), x)) }); - return (*this_.borrow()).with(|__s| __s.n); - } - ); - } -} -pub trait p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl { - fn sizer(&self) -> FnPtr usize>; -} -impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl - for Ptr -{ - fn sizer(&self) -> FnPtr usize> { - return FnPtr:: usize>::new(|| -> usize { - { - return 4usize; - } - }); - } -} pub fn __cpp2rust_init_globals() { let _ = copyCount_0.with(|_| ()); let _ = ctorCount_1.with(|_| ()); diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index bef0dd041c..cb4fb7231f 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -28,14 +28,14 @@ impl HasConstexprCtor { pub unsafe fn reset() { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) = 0; } - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.m).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).m).write(v); } } impl CopyConstructibleUnsafe for HasConstexprCtor { - unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const HasConstexprCtor); - (&raw mut self.m).write((*o).m); + (&raw mut (*this).m).write((*o).m); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); } } @@ -69,26 +69,26 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); - (&raw mut self.uses).write(0); + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)).prefix_inc(); } } @@ -97,12 +97,12 @@ pub unsafe fn test_5() { let arr: [HasConstexprCtor; 2] = [ { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 3); + HasConstexprCtor::construct(&raw mut __v, 3); __v }, { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 4); + HasConstexprCtor::construct(&raw mut __v, 4); __v }, ]; @@ -111,12 +111,12 @@ pub unsafe fn test_5() { return [ { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 3); + HasConstexprCtor::construct(&raw mut __v, 3); __v }, { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 4); + HasConstexprCtor::construct(&raw mut __v, 4); __v }, ][(1) as usize] @@ -134,7 +134,7 @@ pub unsafe fn test_6() { unsafe { return { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 5); + HasConstexprCtor::construct(&raw mut __v, 5); __v } .m; @@ -153,13 +153,13 @@ pub unsafe fn test_7() { return (if b { { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 7); + HasConstexprCtor::construct(&raw mut __v, 7); __v } } else { { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 9); + HasConstexprCtor::construct(&raw mut __v, 9); __v } }) @@ -181,7 +181,7 @@ pub unsafe fn test_9() { (*std::cell::LazyCell::force_mut(&mut *&raw mut left_8)).prefix_inc(); { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 5); + HasConstexprCtor::construct(&raw mut __v, 5); __v } } @@ -224,7 +224,7 @@ pub static mut global_12: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -240,7 +240,9 @@ pub unsafe fn test_13() { let r: *mut LifetimeTracked = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_12)); let mut f: FnPtr = FnPtr::::new(|| unsafe { (unsafe { - LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut global_12))) + LifetimeTracked::use_( + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut global_12)), + ) }); }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); @@ -257,16 +259,16 @@ pub unsafe fn test_14() { { let r: LifetimeTracked = { let mut __v: LifetimeTracked = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(r)); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(r)); __v }; }, || { - (unsafe { LifetimeTracked::use_(&r) }); + (unsafe { LifetimeTracked::use_(&raw const r) }); } ); let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (1))); (unsafe { f.call() }); @@ -294,7 +296,7 @@ pub unsafe fn test_16() { { let k: HasConstexprCtor = { let mut __v: HasConstexprCtor = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(&k)); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&k)); __v }; }, @@ -336,19 +338,19 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { pub scratch: i32, } impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.value).write(v); - (&raw mut self.scratch).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); + (&raw mut (*this).scratch).write(0); } } impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMember { unsafe fn copy_constructor( - &mut self, + this: *mut Self, o: LvalueRefUnsafe>, ) { let o = (o.as_ptr() as *const p5_2_mutable_subobject_is_odr_used_HasMutableMember); - (&raw mut self.value).write((*o).value); - (&raw mut self.scratch).write((*o).scratch); + (&raw mut (*this).value).write((*o).value); + (&raw mut (*this).scratch).write((*o).scratch); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)).prefix_inc(); } } @@ -359,7 +361,7 @@ pub unsafe fn test_19() { let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = { let mut __v: p5_2_mutable_subobject_is_odr_used_HasMutableMember = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(&k)); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&k)); __v }; }, @@ -383,9 +385,9 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { pub b: LifetimeTracked, } impl DefaultConstructibleUnsafe for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.a); - DefaultConstructibleUnsafe::default_constructor(&mut self.b); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).a); + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).b); } } pub unsafe fn test_20() { @@ -394,17 +396,17 @@ pub unsafe fn test_20() { p6_unevaluated_binding_needs_no_capture_HasTwoMembers { a: { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }, b: { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }, }; let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let __decomp_21: *mut p6_unevaluated_binding_needs_no_capture_HasTwoMembers = &mut p; let mut f: FnPtr usize> = FnPtr:: usize>::new(|| -> usize { @@ -428,30 +430,29 @@ pub struct p7_member_access_captures_this_HasMemberUsedInLambda { pub n: i32, } impl p7_member_access_captures_this_HasMemberUsedInLambda { - pub unsafe fn makeLambda(&mut self) -> FnPtr i32> { + pub unsafe fn makeLambda(this: *mut Self) -> FnPtr i32> { return lambda_unsafe!( { - let this_: *mut p7_member_access_captures_this_HasMemberUsedInLambda = - (self as *mut p7_member_access_captures_this_HasMemberUsedInLambda); + let this_: *mut p7_member_access_captures_this_HasMemberUsedInLambda = this; }, || -> i32 { - (unsafe { LifetimeTracked::use_(&(*this_).x) }); + (unsafe { LifetimeTracked::use_(&raw const (*this_).x) }); return (*this_).n; } ); } } impl DefaultConstructibleUnsafe for p7_member_access_captures_this_HasMemberUsedInLambda { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.x); - (&raw mut self.n).write(1); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + (&raw mut (*this).n).write(1); } } pub unsafe fn test_22() { (unsafe { LifetimeTracked::reset() }); object_unsafe!(c, p7_member_access_captures_this_HasMemberUsedInLambda); let mut f: FnPtr i32> = - (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&mut c) }); + (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&raw mut c) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); assert!(((unsafe { f.call() }) == (1))); assert!(((c.x.uses) == (1))); @@ -470,7 +471,7 @@ pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { pub x: LifetimeTracked, } impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - pub unsafe fn sizer(&mut self) -> FnPtr usize> { + pub unsafe fn sizer(this: *mut Self) -> FnPtr usize> { return FnPtr:: usize>::new(|| -> usize { unsafe { return ::std::mem::size_of::(); @@ -479,8 +480,8 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } } impl DefaultConstructibleUnsafe for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.x); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); } } pub unsafe fn test_23() { @@ -490,7 +491,7 @@ pub unsafe fn test_23() { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda ); let mut f: FnPtr usize> = - (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&mut c) }); + (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&raw mut c) }); assert!(((unsafe { f.call() }) == (::std::mem::size_of::()))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) == (0))); @@ -530,7 +531,7 @@ pub static mut t_ctors_27: std::cell::LazyCell = std::cell::LazyCell::new(| #[memberwise(copy_assign)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl DefaultConstructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)).prefix_inc(); } } @@ -539,7 +540,7 @@ pub unsafe fn test_28() { let __p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = Box::leak( Box::new(::zero_init()), ); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + DefaultConstructibleUnsafe::default_constructor(__p); __p }; assert!(!((p).is_null())); @@ -562,8 +563,8 @@ pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } impl DefaultConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(3); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(3); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)).prefix_inc(); } } @@ -573,7 +574,7 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { { let mut __v: p9_unused_copy_constructor_HasUndefinedCopyCtor = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -601,7 +602,7 @@ pub static mut m_ctors_32: std::cell::LazyCell = std::cell::LazyCell::new(| )] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl DefaultConstructibleUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)).prefix_inc(); } } @@ -611,7 +612,7 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { { let mut __v: p9_unused_implicit_assignment_HasUndefinedCopyAssignment = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -634,8 +635,8 @@ pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { impl DefaultConstructibleUnsafe for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.m); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).m); } } pub unsafe fn test_33() { @@ -768,21 +769,21 @@ unsafe impl p4_1_pure_virtual_without_definition_HasPureVirtual } } impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { unreachable!( "p9_destructor_not_potentially_invoked_HasUndefinedDestructor::destroy is never defined" ) } } impl CopyConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn copy_constructor(&mut self, _: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _: LvalueRefUnsafe>) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } impl CopyAssignableUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn copy_assign(&mut self, _: LvalueRefUnsafe>) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, _: LvalueRefUnsafe>) -> *mut Self { unreachable!( "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" ) diff --git a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs index 359828e042..206493ac95 100644 --- a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs @@ -23,6 +23,11 @@ pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { #[offset(0)] pub value: i32, } +impl p11_defaulted_move_constructor_is_trivial_MoveOnly { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} pub fn pass_0( object: p11_defaulted_move_constructor_is_trivial_MoveOnly, ) -> p11_defaulted_move_constructor_is_trivial_MoveOnly { @@ -32,10 +37,7 @@ pub fn pass_0( let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - MoveConstructible::move_constructor( - &__v.as_pointer(), - RvalueRef::bind(object.as_pointer()), - ); + MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(object.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -45,7 +47,7 @@ pub fn test_1() { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl::construct(&__v.as_pointer(), 7); + p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }); @@ -77,14 +79,4 @@ fn main_0() -> i32 { ({ test_3() }); return 0; } -pub trait p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl { - fn construct(&self, value: i32); -} -impl p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl - for Ptr -{ - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs index e989542b7b..5a52ddae70 100644 --- a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs @@ -21,8 +21,8 @@ pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { pub value: i32, } impl p11_defaulted_move_constructor_is_trivial_MoveOnly { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } pub unsafe fn pass_0( @@ -31,7 +31,7 @@ pub unsafe fn pass_0( return { let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&mut __v, RvalueRefUnsafe::bind(&mut object)); + MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(&mut object)); __v }; } @@ -40,7 +40,7 @@ pub unsafe fn test_1() { pass_0({ let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = ::zero_init(); - p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(&mut __v, 7); + p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(&raw mut __v, 7); __v }) }); diff --git a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs index a546a55043..a1888f1daf 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs @@ -144,7 +144,7 @@ thread_local!( pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { fn copy_constructor( - this: &Ptr, + this: Ptr, _a0: LvalueRef>, ) { let _a0 = _a0.as_pointer(); @@ -153,7 +153,7 @@ impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMov } impl MoveConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { fn move_constructor( - this: &Ptr, + this: Ptr, _a0: RvalueRef, ) { let _a0 = _a0.as_pointer(); diff --git a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs index 01c434c67a..1811b24dc4 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs @@ -131,7 +131,7 @@ pub static mut moveCount_10: std::cell::LazyCell = std::cell::LazyCell::new pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} impl CopyConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { unsafe fn copy_constructor( - &mut self, + this: *mut Self, _a0: LvalueRefUnsafe>, ) { let _a0 = (_a0.as_ptr() as *const p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves); @@ -140,7 +140,7 @@ impl CopyConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopies } impl MoveConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { unsafe fn move_constructor( - &mut self, + this: *mut Self, _a0: RvalueRefUnsafe, ) { let _a0 = (_a0.as_ptr() as *mut p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves); diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs index 4f3a4b286f..f25fdafd12 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs @@ -53,22 +53,28 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - field!((*this), uses).write(0); + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -88,7 +94,7 @@ pub fn test_6() { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); } else { (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); - ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + ({ LifetimeTracked::use_(guard.as_pointer()) }); assert!(({ (*guard.borrow()).uses } == 1)); assert!((choice == 0)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); @@ -102,7 +108,7 @@ pub fn test_6() { let mut choice: i32 = 4; if (choice != 0) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); - ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + ({ LifetimeTracked::use_(guard.as_pointer()) }); assert!(({ (*guard.borrow()).uses } == 1)); assert!((choice == 4)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); @@ -192,17 +198,6 @@ fn main_0() -> i32 { ({ test_12() }); return 0; } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index 33d1a938e8..44809583da 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs @@ -53,22 +53,28 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - field!((*this), uses).write(0); + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -101,8 +107,13 @@ pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { #[offset(0)] pub value: i32, } +impl p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.value); + } +} impl Destructible for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -113,13 +124,13 @@ pub fn test_7() { p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }, )); let _dtor_selector = std::mem::DropGuard::new(selector.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); 'switch: { match { ({ - p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl::to_i32( - &selector.as_pointer(), + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + selector.as_pointer(), ) }) } { @@ -156,7 +167,7 @@ pub fn test_10() { match { selector } { __v if __v == 2 => { (*matching_case_runs_8.with(Value::clone).borrow_mut()).prefix_inc(); - ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + ({ LifetimeTracked::use_(guard.as_pointer()) }); assert!(({ (*guard.borrow()).uses } == 1)); assert!((selector == 2)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); @@ -221,27 +232,6 @@ fn main_0() -> i32 { ({ test_10() }); return 0; } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl { - fn to_i32(&self) -> i32; -} -impl p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl - for Ptr -{ - fn to_i32(&self) -> i32 { - return (*self).with(|__s| __s.value); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs index 067131a2c9..d01b906459 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs @@ -36,26 +36,26 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); - (&raw mut self.uses).write(0); + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -73,7 +73,7 @@ pub unsafe fn test_6() { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); } else { (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); - (unsafe { LifetimeTracked::use_(&guard) }); + (unsafe { LifetimeTracked::use_(&raw const guard) }); assert!(((guard.uses) == (1))); assert!(((choice) == (0))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); @@ -87,7 +87,7 @@ pub unsafe fn test_6() { let mut choice: i32 = 4; if (choice != 0) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); - (unsafe { LifetimeTracked::use_(&guard) }); + (unsafe { LifetimeTracked::use_(&raw const guard) }); assert!(((guard.uses) == (1))); assert!(((choice) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs index e26693b527..c1521c990e 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs @@ -36,26 +36,26 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: LvalueRefUnsafe>) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); - (&raw mut self.uses).write(0); + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -82,12 +82,12 @@ pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { pub value: i32, } impl p2_condition_variable_lives_for_whole_statement_ConvertsToInt { - pub unsafe fn to_i32(&self) -> i32 { - return self.value; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).value; } } impl DestructibleUnsafe for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); } } @@ -96,12 +96,14 @@ pub unsafe fn test_7() { let mut selector: p2_condition_variable_lives_for_whole_statement_ConvertsToInt = p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }; let _dtor_selector = std::mem::DropGuard::new(&raw mut selector, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); 'switch: { match { (unsafe { - p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32(&selector) + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const selector, + ) }) } { __v if __v == 2 => { @@ -138,7 +140,7 @@ pub unsafe fn test_10() { __v if __v == 2 => { (*std::cell::LazyCell::force_mut(&mut *&raw mut matching_case_runs_8)) .prefix_inc(); - (unsafe { LifetimeTracked::use_(&guard) }); + (unsafe { LifetimeTracked::use_(&raw const guard) }); assert!(((guard.uses) == (1))); assert!(((selector) == (2))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 74a10081d1..ddf90123e1 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -23,16 +23,21 @@ pub struct p6_forward_like_Movable { #[offset(0)] pub value: i32, } +impl p6_forward_like_Movable { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl CopyConstructible for p6_forward_like_Movable { - fn copy_constructor(this: &Ptr, other: LvalueRef>) { + fn copy_constructor(this: Ptr, other: LvalueRef>) { let other = other.as_pointer(); - field!((*this), value).write(other.with(|__s| __s.value)); + field!(this, value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p6_forward_like_Movable { - fn move_constructor(this: &Ptr, other: RvalueRef) { + fn move_constructor(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); - field!((*this), value).write(other.with(|__s| __s.value)); + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -45,8 +50,8 @@ pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } impl DefaultConstructible for p6_forward_like_Holder { - fn default_constructor(this: &Ptr) { - p6_forward_like_MovableImpl::construct(&field_ptr!(this, member), 1); + fn default_constructor(this: Ptr) { + p6_forward_like_Movable::construct(field_ptr!(this, member), 1); } } impl Default for p6_forward_like_Holder { @@ -56,29 +61,35 @@ impl Default for p6_forward_like_Holder { member: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - p6_forward_like_MovableImpl::construct(&__v.as_pointer(), 1); + p6_forward_like_Movable::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, } } } } -pub fn take_1(this: Ptr, self_: Ptr) { - CopyConstructible::copy_constructor(&this, LvalueRef::bind(field_ptr!(self_, member))); +pub fn take_1(__return: Ptr, self_: Ptr) { + CopyConstructible::copy_constructor( + __return.clone(), + LvalueRef::bind(field_ptr!(self_, member)), + ); return; } -pub fn take_2(this: Ptr, self_: Ptr) { - MoveConstructible::move_constructor(&this, RvalueRef::bind(field_ptr!(self_, member))); +pub fn take_2(__return: Ptr, self_: Ptr) { + MoveConstructible::move_constructor( + __return.clone(), + RvalueRef::bind(field_ptr!(self_, member)), + ); return; } pub fn test_3() { object!(holder, p6_forward_like_Holder); object!(copied, p6_forward_like_Movable, |copied| ({ - take_1(Ptr::clone(copied), holder.as_pointer()) + take_1(Ptr::clone(&copied.clone()), holder.as_pointer()) })); assert!(({ (*copied.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 1)); object!(moved, p6_forward_like_Movable, |moved| ({ - take_2(Ptr::clone(moved), holder.as_pointer()) + take_2(Ptr::clone(&moved.clone()), holder.as_pointer()) })); assert!(({ (*moved.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 0)); } @@ -91,10 +102,15 @@ pub struct p9_move_Movable { #[offset(0)] pub value: i32, } +impl p9_move_Movable { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl MoveConstructible for p9_move_Movable { - fn move_constructor(this: &Ptr, other: RvalueRef) { + fn move_constructor(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); - field!((*this), value).write(other.with(|__s| __s.value)); + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -146,20 +162,27 @@ pub struct p10_forward_in_template_A { #[offset(8)] pub moves: i32, } +impl p10_forward_in_template_A { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for p10_forward_in_template_A { - fn copy_constructor(this: &Ptr, other: LvalueRef>) { + fn copy_constructor(this: Ptr, other: LvalueRef>) { let other = other.as_pointer(); - field!((*this), value).write(other.with(|__s| __s.value)); - field!((*this), copies).write((other.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(0); + field!(this, value).write(other.with(|__s| __s.value)); + field!(this, copies).write((other.with(|__s| __s.copies) + 1)); + field!(this, moves).write(0); } } impl MoveConstructible for p10_forward_in_template_A { - fn move_constructor(this: &Ptr, other: RvalueRef) { + fn move_constructor(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); - field!((*this), value).write(other.with(|__s| __s.value)); - field!((*this), copies).write(0); - field!((*this), moves).write((other.with(|__s| __s.moves) + 1)); + field!(this, value).write(other.with(|__s| __s.value)); + field!(this, copies).write(0); + field!(this, moves).write((other.with(|__s| __s.moves) + 1)); field!(other, value).write(0); } } @@ -168,18 +191,18 @@ impl Default for p10_forward_in_template_A { { ::zero_init() } } } -pub fn make_5(this: Ptr, source: Ptr) { - CopyConstructible::copy_constructor(&this, LvalueRef::bind((source).clone())); +pub fn make_5(__return: Ptr, source: Ptr) { + CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind((source).clone())); return; } -pub fn make_6(this: Ptr, source: Ptr) { - MoveConstructible::move_constructor(&this, RvalueRef::bind((source).clone())); +pub fn make_6(__return: Ptr, source: Ptr) { + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((source).clone())); return; } pub fn test_7() { object!(a, p10_forward_in_template_A(1)); object!(copied, p10_forward_in_template_A, |copied| ({ - make_5(Ptr::clone(copied), a.as_pointer()) + make_5(Ptr::clone(&copied.clone()), a.as_pointer()) })); assert!( (({ (*copied.borrow()).value } == 1) && ({ (*copied.borrow()).copies } == 1)) @@ -187,7 +210,7 @@ pub fn test_7() { ); assert!(({ (*a.borrow()).value } == 1)); object!(moved, p10_forward_in_template_A, |moved| ({ - make_6(Ptr::clone(moved), a.as_pointer()) + make_6(Ptr::clone(&moved.clone()), a.as_pointer()) })); assert!( (({ (*moved.borrow()).value } == 1) && ({ (*moved.borrow()).copies } == 0)) @@ -204,19 +227,24 @@ pub struct p11_move_if_noexcept_NoexceptMove { #[offset(0)] pub value: i32, } +impl p11_move_if_noexcept_NoexceptMove { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl CopyConstructible for p11_move_if_noexcept_NoexceptMove { fn copy_constructor( - this: &Ptr, + this: Ptr, other: LvalueRef>, ) { let other = other.as_pointer(); - field!((*this), value).write(other.with(|__s| __s.value)); + field!(this, value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p11_move_if_noexcept_NoexceptMove { - fn move_constructor(this: &Ptr, other: RvalueRef) { + fn move_constructor(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); - field!((*this), value).write(other.with(|__s| __s.value)); + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -229,19 +257,24 @@ pub struct p11_move_if_noexcept_ThrowingMove { #[offset(0)] pub value: i32, } +impl p11_move_if_noexcept_ThrowingMove { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl CopyConstructible for p11_move_if_noexcept_ThrowingMove { fn copy_constructor( - this: &Ptr, + this: Ptr, other: LvalueRef>, ) { let other = other.as_pointer(); - field!((*this), value).write(other.with(|__s| __s.value)); + field!(this, value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p11_move_if_noexcept_ThrowingMove { - fn move_constructor(this: &Ptr, other: RvalueRef) { + fn move_constructor(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); - field!((*this), value).write(other.with(|__s| __s.value)); + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -273,46 +306,4 @@ fn main_0() -> i32 { ({ test_8() }); return 0; } -pub trait p10_forward_in_template_AImpl { - fn construct(&self, value: i32); -} -impl p10_forward_in_template_AImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} -pub trait p11_move_if_noexcept_NoexceptMoveImpl { - fn construct(&self, value: i32); -} -impl p11_move_if_noexcept_NoexceptMoveImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} -pub trait p11_move_if_noexcept_ThrowingMoveImpl { - fn construct(&self, value: i32); -} -impl p11_move_if_noexcept_ThrowingMoveImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} -pub trait p6_forward_like_MovableImpl { - fn construct(&self, value: i32); -} -impl p6_forward_like_MovableImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} -pub trait p9_move_MovableImpl { - fn construct(&self, value: i32); -} -impl p9_move_MovableImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index ef7d280d26..60ce4b7846 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -66,10 +66,15 @@ pub struct p10_move_constructor_A { #[offset(0)] pub value: i32, } +impl p10_move_constructor_A { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl MoveConstructible for p10_move_constructor_A { - fn move_constructor(this: &Ptr, other: RvalueRef) { + fn move_constructor(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); - field!((*this), value).write(other.with(|__s| __s.value)); + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -98,12 +103,4 @@ fn main_0() -> i32 { ({ test_2() }); return 0; } -pub trait p10_move_constructor_AImpl { - fn construct(&self, value: i32); -} -impl p10_move_constructor_AImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index 1417fb9766..8b4e364fcf 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -23,20 +23,23 @@ pub struct p6_forward_like_Movable { pub value: i32, } impl p6_forward_like_Movable { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl CopyConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn copy_constructor(&mut self, other: LvalueRefUnsafe>) { + unsafe fn copy_constructor( + this: *mut Self, + other: LvalueRefUnsafe>, + ) { let other = (other.as_ptr() as *const p6_forward_like_Movable); - (&raw mut self.value).write((*other).value); + (&raw mut (*this).value).write((*other).value); } } impl MoveConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { + unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p6_forward_like_Movable); - (&raw mut self.value).write((*other).value); + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } @@ -47,8 +50,8 @@ pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } impl DefaultConstructibleUnsafe for p6_forward_like_Holder { - unsafe fn default_constructor(&mut self) { - p6_forward_like_Movable::construct(&mut self.member, 1); + unsafe fn default_constructor(this: *mut Self) { + p6_forward_like_Movable::construct(&raw mut (*this).member, 1); } } impl Default for p6_forward_like_Holder { @@ -57,20 +60,20 @@ impl Default for p6_forward_like_Holder { p6_forward_like_Holder { member: { let mut __v: p6_forward_like_Movable = ::zero_init(); - p6_forward_like_Movable::construct(&mut __v, 1); + p6_forward_like_Movable::construct(&raw mut __v, 1); __v }, } } } } -pub unsafe fn take_1(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - CopyConstructibleUnsafe::copy_constructor(&mut *this, LvalueRefUnsafe::bind(&(*self_).member)); +pub unsafe fn take_1(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { + CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(&(*self_).member)); return; } -pub unsafe fn take_2(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { +pub unsafe fn take_2(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { MoveConstructibleUnsafe::move_constructor( - &mut *this, + __return, RvalueRefUnsafe::bind(&mut (*self_).member), ); return; @@ -95,14 +98,14 @@ pub struct p9_move_Movable { pub value: i32, } impl p9_move_Movable { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl MoveConstructibleUnsafe for p9_move_Movable { - unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { + unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p9_move_Movable); - (&raw mut self.value).write((*other).value); + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } @@ -149,29 +152,29 @@ pub struct p10_forward_in_template_A { pub moves: i32, } impl p10_forward_in_template_A { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for p10_forward_in_template_A { unsafe fn copy_constructor( - &mut self, + this: *mut Self, other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p10_forward_in_template_A); - (&raw mut self.value).write((*other).value); - (&raw mut self.copies).write((((*other).copies) + (1))); - (&raw mut self.moves).write(0); + (&raw mut (*this).value).write((*other).value); + (&raw mut (*this).copies).write((((*other).copies) + (1))); + (&raw mut (*this).moves).write(0); } } impl MoveConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { + unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p10_forward_in_template_A); - (&raw mut self.value).write((*other).value); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write((((*other).moves) + (1))); + (&raw mut (*this).value).write((*other).value); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write((((*other).moves) + (1))); (*other).value = 0; } } @@ -180,12 +183,18 @@ impl Default for p10_forward_in_template_A { unsafe { ::zero_init() } } } -pub unsafe fn make_5(this: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A) { - CopyConstructibleUnsafe::copy_constructor(&mut *this, LvalueRefUnsafe::bind(source)); +pub unsafe fn make_5( + __return: *mut p10_forward_in_template_A, + source: *mut p10_forward_in_template_A, +) { + CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(source)); return; } -pub unsafe fn make_6(this: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A) { - MoveConstructibleUnsafe::move_constructor(&mut *this, RvalueRefUnsafe::bind(source)); +pub unsafe fn make_6( + __return: *mut p10_forward_in_template_A, + source: *mut p10_forward_in_template_A, +) { + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(source)); return; } pub unsafe fn test_7() { @@ -210,26 +219,26 @@ pub struct p11_move_if_noexcept_NoexceptMove { pub value: i32, } impl p11_move_if_noexcept_NoexceptMove { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl CopyConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { unsafe fn copy_constructor( - &mut self, + this: *mut Self, other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p11_move_if_noexcept_NoexceptMove); - (&raw mut self.value).write((*other).value); + (&raw mut (*this).value).write((*other).value); } } impl MoveConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { unsafe fn move_constructor( - &mut self, + this: *mut Self, other: RvalueRefUnsafe, ) { let other = (other.as_ptr() as *mut p11_move_if_noexcept_NoexceptMove); - (&raw mut self.value).write((*other).value); + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } @@ -242,26 +251,26 @@ pub struct p11_move_if_noexcept_ThrowingMove { pub value: i32, } impl p11_move_if_noexcept_ThrowingMove { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl CopyConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { unsafe fn copy_constructor( - &mut self, + this: *mut Self, other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p11_move_if_noexcept_ThrowingMove); - (&raw mut self.value).write((*other).value); + (&raw mut (*this).value).write((*other).value); } } impl MoveConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { unsafe fn move_constructor( - &mut self, + this: *mut Self, other: RvalueRefUnsafe, ) { let other = (other.as_ptr() as *mut p11_move_if_noexcept_ThrowingMove); - (&raw mut self.value).write((*other).value); + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index e777c2b07f..41b6475507 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -56,14 +56,14 @@ pub struct p10_move_constructor_A { pub value: i32, } impl p10_move_constructor_A { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl MoveConstructibleUnsafe for p10_move_constructor_A { - unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { + unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p10_move_constructor_A); - (&raw mut self.value).write((*other).value); + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index a117175a55..dfbec42db3 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -34,13 +34,15 @@ impl Partial { } } impl CopyConstructible for Partial { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, keep).write(o.with(|__s| __s.keep)); } } impl CopyAssignable for Partial { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); if (this == (o)) { return (this).clone(); } @@ -107,7 +109,8 @@ impl DefaultConstructible for RefQualified { } } impl CopyAssignable for RefQualified { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 1)); return (this).clone(); } @@ -178,7 +181,8 @@ impl CopyCounted { } } impl CopyConstructible for CopyCounted { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -228,7 +232,11 @@ pub struct ExplicitOperatorCall { pub w: Vec, } impl CopyAssignable for ExplicitOperatorCall { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign( + this: Ptr, + o: LvalueRef>, + ) -> Ptr { + let o = o.as_pointer(); match (field_ref!(o, w).as_pointer(),) { (__tmp_0,) => field!(this, w).with_mut(|__b0| { (*__b0) = copy_constructed(__tmp_0); @@ -274,21 +282,22 @@ impl Swapped { } } impl CopyConstructible for Swapped { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*swap_copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyAssignable for Swapped { - fn copy_assign(this: Ptr, src: Ptr) -> Ptr { - object!(__o, Swapped, src); + fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { + object!(__o, Swapped, LvalueRef::bind(src.as_pointer())); Swapped::copy_assign(this.clone(), Ptr::clone(&__o.as_pointer())); Ptr::clone(&this.clone()) } } impl MoveAssignable for Swapped { - fn move_assign(this: Ptr, src: Ptr) -> Ptr { - object!(__o, Swapped, Moved(src)); + fn move_assign(this: Ptr, src: RvalueRef) -> Ptr { + object!(__o, Swapped, RvalueRef::bind(src.as_pointer())); Swapped::copy_assign(this.clone(), Ptr::clone(&__o.as_pointer())); Ptr::clone(&this.clone()) } @@ -339,14 +348,14 @@ impl DefaultConstructible for VoidAssign { } } impl CopyAssignable for VoidAssign { - fn copy_assign(this: Ptr, src: Ptr) -> Ptr { - VoidAssign::copy_assign(this.clone(), src); + fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { + VoidAssign::copy_assign(this.clone(), src.as_pointer()); Ptr::clone(&this.clone()) } } impl MoveAssignable for VoidAssign { - fn move_assign(this: Ptr, src: Ptr) -> Ptr { - VoidAssign::copy_assign(this.clone(), src); + fn move_assign(this: Ptr, src: RvalueRef) -> Ptr { + VoidAssign::copy_assign(this.clone(), src.as_pointer()); Ptr::clone(&this.clone()) } } @@ -552,7 +561,7 @@ fn main_0() -> i32 { object!(sw2, Swapped(2)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_o.as_pointer(), sw2.as_pointer()); + CopyConstructible::copy_constructor(_o.as_pointer(), LvalueRef::bind(sw2.as_pointer())); Swapped::copy_assign(sw1.as_pointer(), _o.as_pointer()) }); assert!(({ (*sw1.borrow()).v } == 2) && (swap_copies_2.with(|rc| *rc.borrow()) == 1)); diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 1c838005ce..fcf3f332d0 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -35,7 +35,8 @@ impl Counted { } } impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -99,7 +100,8 @@ impl Ignored { } } impl CopyConstructible for Ignored { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, v).write(-1_i32); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -153,7 +155,8 @@ impl Box_int_ { } } impl CopyConstructible for Box_int_ { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, val).write(o.with(|__s| __s.val)); } } @@ -193,7 +196,8 @@ impl OutOfLine { } } impl CopyConstructible for OutOfLine { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -219,7 +223,8 @@ impl DefaultConstructible for Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, copied_from).write(0); field!(o, copied_from).with_mut(|__v| { __v.prefix_inc(); @@ -227,7 +232,8 @@ impl CopyConstructible for Tracked { } } impl CopyAssignable for Tracked { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(o, copied_from).with_mut(|__v| { __v.prefix_inc(); }); @@ -249,7 +255,7 @@ pub fn by_value_2(c: Ptr) -> i32 { } pub fn make_3(__return: Ptr, mut v: i32) { object!(c, Counted(v)); - ConstructFrom::construct_from(__return.clone(), c.as_pointer()); + CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind(c.as_pointer())); return; } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] @@ -265,12 +271,14 @@ impl DefaultConstructible for SelfPtr { } } impl CopyConstructible for SelfPtr { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); } } impl MoveConstructible for SelfPtr { - fn move_constructor(this: Ptr, _a0: Ptr) { + fn move_constructor(this: Ptr, _a0: RvalueRef) { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); } } @@ -329,9 +337,9 @@ pub fn main() { } fn main_0() -> i32 { object!(a, Counted(1)); - object!(b, Counted, a.as_pointer()); - object!(c, Counted, a.as_pointer()); - object!(d, Counted, a.as_pointer()); + object!(b, Counted, LvalueRef::bind(a.as_pointer())); + object!(c, Counted, LvalueRef::bind(a.as_pointer())); + object!(d, Counted, LvalueRef::bind(a.as_pointer())); assert!((copies_0.with(|rc| *rc.borrow()) == 3)); assert!( (({ (*b.borrow()).v } == 1) && ({ (*c.borrow()).v } == 1)) && ({ (*d.borrow()).v } == 1) @@ -339,7 +347,7 @@ fn main_0() -> i32 { assert!( (({ let _c: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_c.as_pointer(), a.as_pointer()); + CopyConstructible::copy_constructor(_c.as_pointer(), LvalueRef::bind(a.as_pointer())); by_value_2(_c.as_pointer()) }) == 1) ); @@ -351,7 +359,7 @@ fn main_0() -> i32 { assert!(({ (*f.borrow()).v } == 6)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); object!(g, Counted(7)); - object!(h, Counted, g.as_pointer()); + object!(h, Counted, LvalueRef::bind(g.as_pointer())); assert!(({ (*h.borrow()).v } == 7)); assert!((copies_0.with(|rc| *rc.borrow()) == 6)); let hold: Value = Rc::new(RefCell::new(Holder { @@ -373,7 +381,7 @@ fn main_0() -> i32 { }, ]), })); - object!(hold2, Holder, hold.as_pointer()); + object!(hold2, Holder, LvalueRef::bind(hold.as_pointer())); assert!( (({ (*hold2.borrow()).c.v } == 8) && (array_elem!(hold2.as_pointer(), arr, 0).with(|__s| __s.v) == 9)) @@ -385,7 +393,7 @@ fn main_0() -> i32 { assert!(({ (*vec_.borrow())[0_usize].v } == 1)); assert!((copies_0.with(|rc| *rc.borrow()) == 10)); object!(i1, Ignored(1)); - object!(i2, Ignored, i1.as_pointer()); + object!(i2, Ignored, LvalueRef::bind(i1.as_pointer())); assert!(({ (*i1.borrow()).v } == 1) && ({ (*i2.borrow()).v } == -1_i32)); assert!((copies_0.with(|rc| *rc.borrow()) == 11)); let o: Value = Rc::new(RefCell::new(Owner { @@ -395,10 +403,10 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); - object!(o2, Owner, Moved(o.as_pointer())); + object!(o2, Owner, RvalueRef::bind(o.as_pointer())); assert!(({ (*o2.borrow()).box_.val } == 3)); object!(ol1, OutOfLine(5)); - object!(ol2, OutOfLine, ol1.as_pointer()); + object!(ol2, OutOfLine, LvalueRef::bind(ol1.as_pointer())); assert!(({ (*ol2.borrow()).v } == 105)); assert!((copies_0.with(|rc| *rc.borrow()) == 12)); object!(n, NonConst); @@ -408,16 +416,16 @@ fn main_0() -> i32 { assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); object!(t1, Tracked); - object!(t2, Tracked, t1.as_pointer()); + object!(t2, Tracked, LvalueRef::bind(t1.as_pointer())); assign!(t2 = t1); assert!(({ (*t1.borrow()).copied_from } == 2)); object!(ct, Tracked); - object!(t3, Tracked, ct.as_pointer()); + object!(t3, Tracked, LvalueRef::bind(ct.as_pointer())); ({ touch_1((ct.as_pointer())) }); assert!(({ (*ct.borrow()).copied_from } == 2)); let mut before: i32 = copies_0.with(|rc| *rc.borrow()); object!(der, Derived); - object!(der2, Derived, der.as_pointer()); + object!(der2, Derived, LvalueRef::bind(der.as_pointer())); assert!(({ (*der2.borrow()).c.v } == 20) && (copies_0.with(|rc| *rc.borrow()) == (before + 1))); let mut range: Vec = { let mut __tmp_0 = { vec_.decay().begin() }; diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index 136f8b34ce..129850f27f 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -122,13 +122,15 @@ impl DefaultCopyUserMove { } } impl MoveConstructible for DefaultCopyUserMove { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for DefaultCopyUserMove { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); return (this).clone(); @@ -158,12 +160,17 @@ impl UserCopyDefaultMove { } } impl CopyConstructible for UserCopyDefaultMove { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); } } impl CopyAssignable for UserCopyDefaultMove { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign( + this: Ptr, + o: LvalueRef>, + ) -> Ptr { + let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); return (this).clone(); } @@ -325,13 +332,15 @@ pub struct SeesThis { pub self_: Ptr, } impl CopyAssignable for SeesThis { - fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _a0: LvalueRef>) -> Ptr { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); return (this).clone(); } } impl MoveAssignable for SeesThis { - fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn move_assign(this: Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); return (this).clone(); } @@ -382,13 +391,15 @@ impl DefaultConstructible for Counted_int_ { } } impl MoveConstructible for Counted_int_ { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); } } impl MoveAssignable for Counted_int_ { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); return (this).clone(); @@ -441,24 +452,28 @@ impl DefaultConstructible for CtorSeesThis { } } impl CopyConstructible for CtorSeesThis { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); field!(this, id).write(0); } } impl MoveConstructible for CtorSeesThis { - fn move_constructor(this: Ptr, _a0: Ptr) { + fn move_constructor(this: Ptr, _a0: RvalueRef) { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); field!(this, id).write(0); } } impl CopyAssignable for CtorSeesThis { - fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _a0: LvalueRef>) -> Ptr { + let _a0 = _a0.as_pointer(); return (this).clone(); } } impl MoveAssignable for CtorSeesThis { - fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn move_assign(this: Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); return (this).clone(); } } @@ -548,8 +563,12 @@ impl OutOfLineDefaulted { } } impl CopyConstructible for OutOfLineDefaulted { - fn copy_constructor(this: Ptr, _a0: Ptr) { - ConstructFrom::construct_from(field_ptr!(this, x), field_ptr!(_a0, x)); + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); + CopyConstructible::copy_constructor( + field_ptr!(this, x), + LvalueRef::bind(field_ptr!(_a0, x)), + ); field!(this, v).write(_a0.with(|__s| __s.v)); } } @@ -604,7 +623,11 @@ impl Default for OutOfLineAssign { } } impl CopyAssignable for OutOfLineAssign { - fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn copy_assign( + this: Ptr, + _a0: LvalueRef>, + ) -> Ptr { + let _a0 = _a0.as_pointer(); assign!(*field_ptr!(this, s) = *field_ptr!(_a0, s)); field!(this, v).write(_a0.with(|__s| __s.v)); match (field_ref!(_a0, w).as_pointer(),) { @@ -616,8 +639,9 @@ impl CopyAssignable for OutOfLineAssign { } } impl MoveAssignable for OutOfLineAssign { - fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { - assign!(*field_ptr!(this, s) = Moved(*field_ptr!(_a0, s))); + fn move_assign(this: Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); + assign!(*field_ptr!(this, s) = RvalueRef(*field_ptr!(_a0, s))); field!(this, v).write({ (*_a0.upgrade().deref()).v }); field!(this, w).with_mut(|__b0| { (*__b0) = field!(_a0, w).with_mut(std::mem::take); @@ -648,7 +672,7 @@ fn main_0() -> i32 { object!(e, Explicit(2)); object!(f, Explicit(3)); assign!(e = b); - assign!(f = Moved(c)); + assign!(f = RvalueRef(c)); assert!( ({ same_0(e.as_pointer(), b.as_pointer(),) }) && ({ same_0(f.as_pointer(), c.as_pointer(),) }) @@ -689,20 +713,20 @@ fn main_0() -> i32 { assert!(({ (*vec_.borrow())[0_usize].v } == 1) && ({ (*vec_.borrow())[1_usize].v } == 9)); object!(m, DefaultCopyUserMove(7)); let m1: Value = Rc::new(RefCell::new((*m.borrow()))); - object!(m2, DefaultCopyUserMove, Moved(m.as_pointer())); + object!(m2, DefaultCopyUserMove, RvalueRef::bind(m.as_pointer())); assert!( (({ (*m1.borrow()).v } == 7) && ({ (*m2.borrow()).v } == 7)) && ({ (*m.borrow()).v } == 0) ); object!(m3, DefaultCopyUserMove(1)); object!(m4, DefaultCopyUserMove(1)); assign!(m3 = m1); - assign!(m4 = Moved(m1)); + assign!(m4 = RvalueRef(m1)); assert!( (({ (*m3.borrow()).v } == 7) && ({ (*m4.borrow()).v } == 7)) && ({ (*m1.borrow()).v } == 0) ); object!(u, UserCopyDefaultMove(8)); - object!(u1, UserCopyDefaultMove, u.as_pointer()); - object!(u2, UserCopyDefaultMove, Moved(u.as_pointer())); + object!(u1, UserCopyDefaultMove, LvalueRef::bind(u.as_pointer())); + object!(u2, UserCopyDefaultMove, RvalueRef::bind(u.as_pointer())); assert!( (({ (*u1.borrow()).v } == 108) && ({ (*u2.borrow()).v } == 8)) && ({ (*u.borrow()).v } == 8) @@ -710,10 +734,10 @@ fn main_0() -> i32 { object!(u3, UserCopyDefaultMove(1)); object!(u4, UserCopyDefaultMove(1)); assign!(u3 = u2); - assign!(u4 = Moved(u2)); + assign!(u4 = RvalueRef(u2)); assert!(({ (*u3.borrow()).v } == 108) && ({ (*u4.borrow()).v } == 8)); object!(p, Buffer(3)); - object!(q, Buffer, Moved(p.as_pointer())); + object!(q, Buffer, RvalueRef::bind(p.as_pointer())); assert!( ({ ((({ (*q.borrow()).n } == 3) && ((*q.borrow()).data.len() == 3_usize)) @@ -722,7 +746,7 @@ fn main_0() -> i32 { }) ); object!(r, Buffer(1)); - assign!(r = Moved(q)); + assign!(r = RvalueRef(q)); assert!( ({ ((({ (*r.borrow()).n } == 3) && ((*r.borrow()).data.len() == 3_usize)) @@ -749,9 +773,9 @@ fn main_0() -> i32 { let mut __tmp_2 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( __v.as_pointer(), - Moved(bufs.decay().offset(0_usize)), + RvalueRef::bind(bufs.decay().offset(0_usize)), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -780,7 +804,7 @@ fn main_0() -> i32 { let _p: Ptr<_> = Ptr::alloc(7); field_ptr!(o1.as_pointer(), p).write(_p.to_owned_opt()) }; - object!(o2, Owner, Moved(o1.as_pointer())); + object!(o2, Owner, RvalueRef::bind(o1.as_pointer())); assert!( ({ ((({ (*o2.borrow()).n } == 5) && ((*o2.borrow()).data.len() == 1_usize)) @@ -795,7 +819,7 @@ fn main_0() -> i32 { }) ); object!(o3, Owner); - assign!(o3 = Moved(o2)); + assign!(o3 = RvalueRef(o2)); assert!( ((({ (*o3.borrow()).n } == 5) && ((vec_elem!(o3.as_pointer(), data, 0_usize).read()) == 5)) @@ -812,11 +836,11 @@ fn main_0() -> i32 { data: Vec::from([1, 2]), })); let mut c2: Copyable = (*c1.borrow()).clone(); - object!(c3, Copyable, Moved(c1.as_pointer())); + object!(c3, Copyable, RvalueRef::bind(c1.as_pointer())); assert!(({ (c2.data.len() == 2_usize) && ((*c3.borrow()).data.len() == 2_usize) })); assert!(({ (*c1.borrow()).data.is_empty() })); object!(c4, Copyable); - assign!(c4 = Moved(c3)); + assign!(c4 = RvalueRef(c3)); assert!( ({ ((vec_elem!(c4.as_pointer(), data, 1_usize).read()) == 2) @@ -828,14 +852,14 @@ fn main_0() -> i32 { let _p: Ptr<_> = Ptr::alloc(9); field_ptr!(h1.as_pointer(), p).write(_p.to_owned_opt()) }; - object!(h2, Holder, Moved(h1.as_pointer())); + object!(h2, Holder, RvalueRef::bind(h1.as_pointer())); assert!( ((({ (*h2.borrow()).inner.x } == 4) && ({ (*h2.borrow()).e.v } == 4)) && (({ (*h2.borrow()).p.clone() }.as_pointer().read()) == 9)) && (({ (*h1.borrow()).p.clone() }.as_pointer()).is_null()) ); object!(h3, Holder(1)); - assign!(h3 = Moved(h2)); + assign!(h3 = RvalueRef(h2)); assert!( ((({ (*h3.borrow()).inner.x } == 4) && ((array_elem!(field_ptr!(h3.as_pointer(), e), arr, 1).read()) == 5)) @@ -845,20 +869,20 @@ fn main_0() -> i32 { object!(t1, HasSeesThis); object!(t2, HasSeesThis); object!(t3, HasSeesThis); - assign!(t2 = Moved(t1)); + assign!(t2 = RvalueRef(t1)); assert!(({ { (*t2.borrow()).s.self_.clone() } } == { (field_ptr!(t2.as_pointer(), s)) })); assign!(t3 = t2); assert!(({ { (*t3.borrow()).s.self_.clone() } } == { (field_ptr!(t3.as_pointer(), s)) })); object!(k1, HasCounted); - object!(k2, HasCounted, Moved(k1.as_pointer())); + object!(k2, HasCounted, RvalueRef::bind(k1.as_pointer())); assert!(({ (*k2.borrow()).c.moves } == 1)); object!(k3, HasCounted); - assign!(k3 = Moved(k2)); + assign!(k3 = RvalueRef(k2)); assert!(({ (*k3.borrow()).c.moves } == 2)); { object!(d, CtorSeesThis); assert!(({ { (*d.borrow()).self_.clone() } } == { (d.as_pointer()) })); - object!(e, CtorSeesThis, d.as_pointer()); + object!(e, CtorSeesThis, LvalueRef::bind(d.as_pointer())); assert!(({ { (*e.borrow()).self_.clone() } } == { (e.as_pointer()) })); object!(f, CtorSeesThis::construct_1(3)); assert!( @@ -867,11 +891,11 @@ fn main_0() -> i32 { ); object!(h1, HasCtorSeesThis); assert!(({ { (*h1.borrow()).x.self_.clone() } } == { (field_ptr!(h1.as_pointer(), x)) })); - object!(h2, HasCtorSeesThis, h1.as_pointer()); + object!(h2, HasCtorSeesThis, LvalueRef::bind(h1.as_pointer())); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); - object!(h3, HasCtorSeesThis, Moved(h1.as_pointer())); + object!(h3, HasCtorSeesThis, RvalueRef::bind(h1.as_pointer())); assert!(({ { (*h3.borrow()).x.self_.clone() } } == { (field_ptr!(h3.as_pointer(), x)) })); - assign!(h2 = Moved(h3)); + assign!(h2 = RvalueRef(h3)); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); assign!(h2 = h1); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); @@ -899,7 +923,7 @@ fn main_0() -> i32 { && ({ { (*o1.borrow()).x.self_.clone() } } == { (field_ptr!(o1.as_pointer(), x)) }) ); (*o1.borrow_mut()).v = 2; - object!(o2, OutOfLineDefaulted, o1.as_pointer()); + object!(o2, OutOfLineDefaulted, LvalueRef::bind(o1.as_pointer())); assert!( ({ (*o2.borrow()).v } == 2) && ({ { (*o2.borrow()).x.self_.clone() } } == { (field_ptr!(o2.as_pointer(), x)) }) @@ -923,7 +947,7 @@ fn main_0() -> i32 { }) ); assert!(({ { (*a2.borrow()).s.self_.clone() } } == { (field_ptr!(a2.as_pointer(), s)) })); - assign!(a3 = Moved(a2)); + assign!(a3 = RvalueRef(a2)); assert!( ({ (({ (*a3.borrow()).v } == 3) && ((*a3.borrow()).w.len() == 1_usize)) diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index 65c9b482e9..81abcb51e9 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -28,13 +28,15 @@ impl NoCopy { } } impl MoveConstructible for NoCopy { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for NoCopy { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); return (this).clone(); @@ -52,13 +54,15 @@ impl DefaultConstructible for PrivateCopy { } } impl MoveConstructible for PrivateCopy { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for PrivateCopy { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); return (this).clone(); @@ -143,17 +147,17 @@ pub fn main() { } fn main_0() -> i32 { object!(a, NoCopy(1)); - object!(b, NoCopy, Moved(a.as_pointer())); + object!(b, NoCopy, RvalueRef::bind(a.as_pointer())); assert!(({ (*b.borrow()).v } == 1) && ({ (*a.borrow()).v } == 0)); - assign!(a = Moved(b)); + assign!(a = RvalueRef(b)); assert!(({ (*a.borrow()).v } == 1) && ({ (*b.borrow()).v } == 0)); ({ bump_0((a.as_pointer())) }); assert!(({ (*a.borrow()).v } == 2)); object!(p, PrivateCopy); (*p.borrow_mut()).v = 3; - object!(q, PrivateCopy, Moved(p.as_pointer())); + object!(q, PrivateCopy, RvalueRef::bind(p.as_pointer())); assert!(({ (*q.borrow()).v } == 3) && ({ (*p.borrow()).v } == 0)); - assign!(p = Moved(q)); + assign!(p = RvalueRef(q)); assert!(({ (*p.borrow()).v } == 3) && ({ (*q.borrow()).v } == 0)); object!(im, Immovable); (*im.borrow_mut()).v = 4; @@ -168,23 +172,23 @@ fn main_0() -> i32 { }, tag: 7, })); - object!(d, Container, Moved(c.as_pointer())); + object!(d, Container, RvalueRef::bind(c.as_pointer())); assert!( (({ (*d.borrow()).inner.v } == 6) && ({ (*d.borrow()).tag } == 7)) && ({ (*c.borrow()).inner.v } == 0) ); object!(h, VecHolder); - object!(h2, VecHolder, Moved(h.as_pointer())); + object!(h2, VecHolder, RvalueRef::bind(h.as_pointer())); assert!(({ ((*h2.borrow()).items.len() == 0_usize) })); return 0; } impl CopyAssignable for PrivateCopy { - fn copy_assign(this: Ptr, _: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _: LvalueRef>) -> Ptr { unreachable!("PrivateCopy::copy_assign is never defined") } } impl CopyConstructible for PrivateCopy { - fn copy_constructor(this: Ptr, _: Ptr) { + fn copy_constructor(this: Ptr, _: LvalueRef>) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index 38d211ae47..6c6ee7cbbc 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -74,7 +74,8 @@ impl MoveOnly { } } impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, x: Ptr) { + fn move_constructor(this: Ptr, x: RvalueRef) { + let x = x.as_pointer(); field!(this, data_).write(x.with(|__s| __s.data_)); field!(x, data_).write(0); } @@ -123,7 +124,7 @@ fn main_0() -> i32 { FnPtr::, Ptr)>::new(scale_move_only_3); object!(n, MoveOnly, |n| ({ let _arg0: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_arg0.as_pointer(), Moved(m.as_pointer())); + MoveConstructible::move_constructor(_arg0.as_pointer(), RvalueRef::bind(m.as_pointer())); sc.call(Ptr::clone(&n.clone()), _arg0.as_pointer()) })); assert!((({ MoveOnly::get(n.as_pointer(),) }) == 40)); diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index 2830c24e3f..c12b3aa9e3 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -30,14 +30,16 @@ impl Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write((o.with(|__s| __s.copies) + 1)); field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -52,12 +54,12 @@ pub fn chosen_overload_1(_a0: Ptr) -> Overload { } impl Holder { pub fn construct_1(this: Ptr, x: Ptr) { - ConstructFrom::construct_from(field_ptr!(this, t), (x).clone()); + CopyConstructible::copy_constructor(field_ptr!(this, t), LvalueRef::bind((x).clone())); } } impl Holder { pub fn construct_2(this: Ptr, x: Ptr) { - ConstructFrom::construct_from(field_ptr!(this, t), Moved((x).clone())); + MoveConstructible::move_constructor(field_ptr!(this, t), RvalueRef::bind((x).clone())); } } #[derive( diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index 9b665040ef..152965ba21 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -30,14 +30,16 @@ impl Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write((o.with(|__s| __s.copies) + 1)); field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index 8c178d0bd4..d448573954 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -32,14 +32,16 @@ impl Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write((o.with(|__s| __s.copies) + 1)); field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -59,7 +61,7 @@ pub fn chosen_overload_3(_a0: Ptr) -> Overload { return Overload_kIntRvalueOverload; } pub fn copy_or_move_into_param_4(__return: Ptr, t: Ptr) { - ConstructFrom::construct_from(__return.clone(), Moved((t).clone())); + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((t).clone())); return; } pub fn main() { @@ -79,7 +81,7 @@ fn main_0() -> i32 { object!(b, Tracked(6)); object!(moved, Tracked, |moved| ({ let _t: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_t.as_pointer(), Moved(b.as_pointer())); + MoveConstructible::move_constructor(_t.as_pointer(), RvalueRef::bind(b.as_pointer())); copy_or_move_into_param_4(Ptr::clone(&moved.clone()), _t.as_pointer()) })); assert!(({ (*moved.borrow()).v } == 6)); @@ -89,7 +91,7 @@ fn main_0() -> i32 { object!(c, Tracked(7)); object!(copied, Tracked, |copied| ({ let _t: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_t.as_pointer(), c.as_pointer()); + CopyConstructible::copy_constructor(_t.as_pointer(), LvalueRef::bind(c.as_pointer())); copy_or_move_into_param_4(Ptr::clone(&copied.clone()), _t.as_pointer()) })); assert!(({ (*copied.borrow()).v } == 7)); diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index 69e43be7ae..1322d87ae1 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -32,14 +32,16 @@ impl Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write((o.with(|__s| __s.copies) + 1)); field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -96,8 +98,8 @@ pub fn forward_pack_7( } impl Pair { pub fn construct(this: Ptr, x: Ptr, y: Ptr) { - ConstructFrom::construct_from(field_ptr!(this, a), (x).clone()); - ConstructFrom::construct_from(field_ptr!(this, b), Moved((y).clone())); + CopyConstructible::copy_constructor(field_ptr!(this, a), LvalueRef::bind((x).clone())); + MoveConstructible::move_constructor(field_ptr!(this, b), RvalueRef::bind((y).clone())); } } #[derive( diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index dffd012142..65956063ca 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -194,27 +194,31 @@ impl DefaultConstructible for Counted { } } impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Counted { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyAssignable for Counted { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copy_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); return (this).clone(); } } impl MoveAssignable for Counted { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*move_assigns_5.with(Value::clone).borrow_mut()).prefix_inc(); @@ -344,7 +348,7 @@ fn main_0() -> i32 { ((array_elem!(elems.decay().offset(1_usize), hist, 2).read()) == 5) && ((array_elem!(first, hist, 2).read()) == 0) ); - object!(moved, State, Moved(t.as_pointer())); + object!(moved, State, RvalueRef::bind(t.as_pointer())); assert!( ({ ((*moved.borrow()).grid[(0) as usize][(0) as usize] == 100) @@ -362,7 +366,7 @@ fn main_0() -> i32 { && ((elem!(field_ref!(t.as_pointer(), arr).decay(), 1_usize).read()) == 7) ); let assigned: Value = Rc::new(RefCell::new(::default())); - assign!(assigned = Moved(moved)); + assign!(assigned = RvalueRef(moved)); assert!( ({ ((*assigned.borrow()).grid[(0) as usize][(0) as usize] == 100) @@ -399,8 +403,10 @@ fn main_0() -> i32 { )); let __p: Ptr = __v.decay(); for __i in 0..3 { - __p.offset(__i) - .construct_from(Moved(ca.decay().offset(__i))); + MoveConstructible::move_constructor( + __p.offset(__i), + RvalueRef::bind(ca.decay().offset(__i)), + ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -433,7 +439,7 @@ fn main_0() -> i32 { ); { for __i in 0..3 { - assign!(*ca.as_pointer().decay().offset(__i) = Moved(*cb.decay().offset(__i))); + assign!(*ca.as_pointer().decay().offset(__i) = RvalueRef(*cb.decay().offset(__i))); } ca.as_pointer() }; @@ -458,8 +464,10 @@ fn main_0() -> i32 { )); let __p: Ptr> = __v.decay(); for __i in 0..2 { - __p.offset(__i) - .construct_from(Moved(va.decay().offset(__i))); + MoveConstructible::move_constructor( + __p.offset(__i), + RvalueRef::bind(va.decay().offset(__i)), + ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -474,7 +482,7 @@ fn main_0() -> i32 { ))); { for __i in 0..2 { - assign!(*vc.as_pointer().decay().offset(__i) = Moved(*vb.decay().offset(__i))); + assign!(*vc.as_pointer().decay().offset(__i) = RvalueRef(*vb.decay().offset(__i))); } vc.as_pointer() }; diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index faf000ed8c..f4c2bb7b5c 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -125,7 +125,11 @@ impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { } } impl MoveConstructible for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor( + this: Ptr, + o: RvalueRef, + ) { + let o = o.as_pointer(); field!(this, f).write((*o.upgrade().deref()).f.move_from()); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); } @@ -259,7 +263,7 @@ fn main_0() -> i32 { object!( m2, Moving__lambda_at_lambda_as_field_cpp_64_12__, - Moved(m.as_pointer()) + RvalueRef::bind(m.as_pointer()) ); assert!(({ (({ (*m2.borrow()).f.call(3,) }) == 6) })); assert!(({ (*m2.borrow()).moves } == 1)); diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 225a2866f9..9afa88dffb 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -21,13 +21,15 @@ impl DefaultConstructible for Counted { } } impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, copies).write((o.with(|__s| __s.copies) + 1)); field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Counted { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, copies).write(o.with(|__s| __s.copies)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); } @@ -53,10 +55,14 @@ impl DefaultConstructible for Dropped { fn default_constructor(this: Ptr) {} } impl CopyConstructible for Dropped { - fn copy_constructor(this: Ptr, _a0: Ptr) {} + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); + } } impl MoveConstructible for Dropped { - fn move_constructor(this: Ptr, _a0: Ptr) {} + fn move_constructor(this: Ptr, _a0: RvalueRef) { + let _a0 = _a0.as_pointer(); + } } impl Destructible for Dropped { fn destroy(this: Ptr) { @@ -73,7 +79,10 @@ fn main_0() -> i32 { { let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), c.as_pointer()); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind(c.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -95,12 +104,18 @@ fn main_0() -> i32 { { let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), c.as_pointer()); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind(c.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, |__return: Ptr| { - ConstructFrom::construct_from(__return.clone(), c.as_pointer()); + CopyConstructible::copy_constructor( + __return.clone(), + LvalueRef::bind(c.as_pointer()), + ); return; } ) @@ -123,7 +138,10 @@ fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 2, _>(|__i: usize| { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), arr.decay().offset(__i)); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind(arr.decay().offset(__i)), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index 12c53fdf5d..1585f4b343 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -23,7 +23,10 @@ impl Owner { { let self_: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved((this).clone())); + MoveConstructible::move_constructor( + __v.as_pointer(), + RvalueRef::bind((this).clone()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -34,7 +37,8 @@ impl Owner { } } impl MoveConstructible for Owner { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, p).write(o.with(|__s| __s.p.clone())); field!(o, p).write(Ptr::::null()); } @@ -54,7 +58,10 @@ fn main_0() -> i32 { { let h: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(o.as_pointer())); + MoveConstructible::move_constructor( + __v.as_pointer(), + RvalueRef::bind(o.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 23a1742f03..2c23b92b11 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -33,13 +33,15 @@ impl Key { } } impl CopyConstructible for Key { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, k).write(o.with(|__s| __s.k)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Key { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, k).write(o.with(|__s| __s.k)); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index bd21add8dd..0061279e7f 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -37,13 +37,15 @@ impl DefaultConstructible for Item { } } impl CopyConstructible for Item { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor(this: Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Item { - fn move_constructor(this: Ptr, other: Ptr) { + fn move_constructor(this: Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); field!(other, value).write(-1_i32); @@ -397,7 +399,10 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), (__tmp_6).clone()); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind((__tmp_6).clone()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -436,9 +441,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( __v.as_pointer(), - Moved((__tmp_7).clone()), + RvalueRef::bind((__tmp_7).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -477,7 +482,10 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), (__tmp_8).clone()); + CopyConstructible::copy_constructor( + __v.as_pointer(), + LvalueRef::bind((__tmp_8).clone()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -517,9 +525,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( __v.as_pointer(), - Moved((__tmp_9).clone()), + RvalueRef::bind((__tmp_9).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -668,9 +676,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( __v.as_pointer(), - Moved((__tmp_12).clone()), + RvalueRef::bind((__tmp_12).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -711,9 +719,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( __v.as_pointer(), - Moved((__tmp_14).clone()), + RvalueRef::bind((__tmp_14).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index fdd9e50724..5eb4df545a 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -46,7 +46,8 @@ impl Bag { } } impl CopyConstructible for Bag { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, n).write(o.with(|__s| __s.n)); (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); } diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 5664557646..56a09bd1b9 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -28,13 +28,15 @@ impl MoveOnly { } } impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for MoveOnly { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); if (this == (o)) { return (this).clone(); } @@ -78,7 +80,7 @@ impl Default for ConstMoveAssign { } pub fn make_0(__return: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(__return.clone(), Moved(m.as_pointer())); + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -89,31 +91,31 @@ fn main_0() -> i32 { object!(a, MoveOnly(1)); object!(b, MoveOnly(2)); object!(c, MoveOnly(3)); - assign!(a = Moved(b)); + assign!(a = RvalueRef(b)); assert!(({ (*a.borrow()).v } == 2)); assert!(({ (*b.borrow()).v } == 0)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); MoveOnly::construct(_o.as_pointer(), 3); - assign!(b = Moved(_o)) + assign!(b = RvalueRef(_o)) }); - assign!(c = Moved(*assign!(a = Moved(b)))); + assign!(c = RvalueRef(*assign!(a = RvalueRef(b)))); assert!( (({ (*b.borrow()).v } == 0) && ({ (*a.borrow()).v } == 0)) && ({ (*c.borrow()).v } == 3) ); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); MoveOnly::construct(_o.as_pointer(), 5); - assign!(a = Moved(_o)) + assign!(a = RvalueRef(_o)) }); assert!(({ (*a.borrow()).v } == 5)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); ({ make_0(Ptr::clone(&_o.as_pointer()), 6) }); - assign!(a = Moved(_o)) + assign!(a = RvalueRef(_o)) }); assert!(({ (*a.borrow()).v } == 6)); - assign!(a = Moved(a)); + assign!(a = RvalueRef(a)); assert!(({ (*a.borrow()).v } == 6)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { @@ -127,7 +129,7 @@ fn main_0() -> i32 { } }; object!(d, MoveOnly(8)); - assign!(*vec_.decay().offset(0_usize) = Moved(d)); + assign!(*vec_.decay().offset(0_usize) = RvalueRef(d)); assert!(({ (*vec_.borrow())[0_usize].v } == 8)); assert!(({ (*d.borrow()).v } == 0)); object!(m, ConstMoveAssign); diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index 97c764b6c1..f87768df30 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -21,7 +21,8 @@ impl MoveOnly { } } impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } @@ -77,14 +78,16 @@ impl ThrowingMove { } } impl CopyConstructible for ThrowingMove { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write((o.with(|__s| __s.copies) + 1)); field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for ThrowingMove { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -112,14 +115,16 @@ impl NoexceptMove { } } impl CopyConstructible for NoexceptMove { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write((o.with(|__s| __s.copies) + 1)); field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for NoexceptMove { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, copies).write(o.with(|__s| __s.copies)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); @@ -131,7 +136,7 @@ pub fn by_value_0(m: Ptr) -> i32 { } pub fn make_1(__return: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(__return.clone(), Moved(m.as_pointer())); + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -140,13 +145,13 @@ pub fn main() { } fn main_0() -> i32 { object!(a, MoveOnly(1)); - object!(b, MoveOnly, Moved(a.as_pointer())); + object!(b, MoveOnly, RvalueRef::bind(a.as_pointer())); assert!(({ (*b.borrow()).v } == 1)); assert!(({ (*a.borrow()).v } == 0)); - object!(c, MoveOnly, Moved(b.as_pointer())); + object!(c, MoveOnly, RvalueRef::bind(b.as_pointer())); assert!(({ (*c.borrow()).v } == 1)); assert!(({ (*b.borrow()).v } == 0)); - object!(d, MoveOnly, Moved(c.as_pointer())); + object!(d, MoveOnly, RvalueRef::bind(c.as_pointer())); assert!(({ (*d.borrow()).v } == 1)); assert!(({ (*c.borrow()).v } == 0)); object!(e, MoveOnly, |e| ({ make_1(Ptr::clone(&e.clone()), 5,) })); @@ -161,7 +166,7 @@ fn main_0() -> i32 { assert!( (({ let _m: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(_m.as_pointer(), Moved(e.as_pointer())); + MoveConstructible::move_constructor(_m.as_pointer(), RvalueRef::bind(e.as_pointer())); by_value_0(_m.as_pointer()) }) == 5) ); @@ -188,19 +193,19 @@ fn main_0() -> i32 { assert!(({ (*m1.borrow()).mark } == 1)); assert!(({ (*m2.borrow()).mark } == 10)); object!(t, ThrowingMove(1)); - object!(t1, ThrowingMove, t.as_pointer()); + object!(t1, ThrowingMove, LvalueRef::bind(t.as_pointer())); assert!(({ (*t1.borrow()).v } == 1)); assert!(({ (*t1.borrow()).copies } == 1)); assert!(({ (*t1.borrow()).moves } == 0)); assert!(({ (*t.borrow()).v } == 1)); object!(n, NoexceptMove(2)); - object!(n1, NoexceptMove, Moved(n.as_pointer())); + object!(n1, NoexceptMove, RvalueRef::bind(n.as_pointer())); assert!(({ (*n1.borrow()).v } == 2)); assert!(({ (*n1.borrow()).copies } == 0)); assert!(({ (*n1.borrow()).moves } == 1)); assert!(({ (*n.borrow()).v } == 0)); object!(g, MoveOnly(3)); - object!(g1, MoveOnly, Moved(g.as_pointer())); + object!(g1, MoveOnly, RvalueRef::bind(g.as_pointer())); assert!(({ (*g1.borrow()).v } == 3)); assert!(({ (*g.borrow()).v } == 0)); let nv: Value> = Rc::new(RefCell::new(Vec::new())); diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index de74dd8d5d..8af642151c 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -32,11 +32,11 @@ impl Chain { return (this).clone(); } pub fn take(this: Ptr, __return: Ptr) { - ConstructFrom::construct_from(__return.clone(), Moved((this).clone())); + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((this).clone())); return; } pub fn copy(this: Ptr, __return: Ptr) { - ConstructFrom::construct_from(__return.clone(), (this).clone()); + CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind((this).clone())); return; } pub fn self_(this: Ptr) -> Ptr { @@ -44,12 +44,14 @@ impl Chain { } } impl CopyConstructible for Chain { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); } } impl MoveConstructible for Chain { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 1)); field!(o, v).write(0); } @@ -69,7 +71,7 @@ fn main_0() -> i32 { object!( b, Chain, - Moved(({ Chain::add_5(({ Chain::add_5(b0.as_pointer(), 1,) }), 1,) })) + RvalueRef::bind(({ Chain::add_5(({ Chain::add_5(b0.as_pointer(), 1,) }), 1,) })) ); assert!(({ (*b.borrow()).v } == 8) && ({ (*b0.borrow()).v } == 0)); object!(c, Chain, |c| { @@ -93,9 +95,9 @@ fn main_0() -> i32 { assert!( (({ let _c: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( _c.as_pointer(), - Moved(({ Chain::self_(g.as_pointer()) })), + RvalueRef::bind(({ Chain::self_(g.as_pointer()) })), ); consume_0(_c.as_pointer()) }) == 21) diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index b497cf9c2c..06aa981bdb 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -50,7 +50,8 @@ impl Destructible for Buffer { } } impl CopyConstructible for Buffer { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, data).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(o.with(|__s| __s.size)); { @@ -67,7 +68,8 @@ impl CopyConstructible for Buffer { } } impl MoveConstructible for Buffer { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, data).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(o.with(|__s| __s.size)); { @@ -86,7 +88,8 @@ impl MoveConstructible for Buffer { } } impl CopyAssignable for Buffer { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); if (this == (o)) { return (this).clone(); } @@ -105,7 +108,8 @@ impl CopyAssignable for Buffer { } } impl MoveAssignable for Buffer { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); if (this == (o)) { return (this).clone(); } @@ -127,7 +131,7 @@ impl MoveAssignable for Buffer { } pub fn make_3(__return: Ptr, mut size: i32) { object!(b, Buffer(size)); - ConstructFrom::construct_from(__return.clone(), Moved(b.as_pointer())); + MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind(b.as_pointer())); return; } pub fn main() { @@ -137,14 +141,14 @@ pub fn main() { fn main_0() -> i32 { { object!(a, Buffer(4)); - object!(b, Buffer, a.as_pointer()); + object!(b, Buffer, LvalueRef::bind(a.as_pointer())); assert!( ((alive_0.with(|rc| *rc.borrow()) == 2) && (copies_1.with(|rc| *rc.borrow()) == 1)) && (moves_2.with(|rc| *rc.borrow()) == 0) ); array_elem!(b.as_pointer(), data, 0).write(100); assert!(((array_elem!(a.as_pointer(), data, 0).read()) == 0)); - object!(c, Buffer, Moved(a.as_pointer())); + object!(c, Buffer, RvalueRef::bind(a.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 3) && (moves_2.with(|rc| *rc.borrow()) == 1)); assert!( ({ (*a.borrow()).size } == 0) @@ -161,12 +165,12 @@ fn main_0() -> i32 { && ((array_elem!(d.as_pointer(), data, 0).read()) == 100)) && (copies_1.with(|rc| *rc.borrow()) == 2) ); - assign!(d = Moved(c)); + assign!(d = RvalueRef(c)); assert!( (((array_elem!(d.as_pointer(), data, 0).read()) == 0) && ({ (*c.borrow()).size } == 0)) && (moves_2.with(|rc| *rc.borrow()) == 3) ); - assign!(d = Moved(d)); + assign!(d = RvalueRef(d)); assert!(({ (*d.borrow()).size } == 4) && (moves_2.with(|rc| *rc.borrow()) == 3)); } assert!((alive_0.with(|rc| *rc.borrow()) == 0)); diff --git a/tests/unit/out/refcount/rule_of_three.rs b/tests/unit/out/refcount/rule_of_three.rs index 7a72047e63..cefeb4ff1a 100644 --- a/tests/unit/out/refcount/rule_of_three.rs +++ b/tests/unit/out/refcount/rule_of_three.rs @@ -55,7 +55,8 @@ impl Destructible for Buffer { } } impl CopyConstructible for Buffer { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, data).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(o.with(|__s| __s.size)); { @@ -72,7 +73,8 @@ impl CopyConstructible for Buffer { } } impl CopyAssignable for Buffer { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); if (this == (o)) { return (this).clone(); } @@ -110,7 +112,7 @@ pub fn main() { fn main_0() -> i32 { { object!(a, Buffer(4)); - object!(b, Buffer, a.as_pointer()); + object!(b, Buffer, LvalueRef::bind(a.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 2) && (copies_1.with(|rc| *rc.borrow()) == 1)); array_elem!(b.as_pointer(), data, 0).write(100); assert!(((array_elem!(a.as_pointer(), data, 0).read()) == 0)); @@ -124,7 +126,7 @@ fn main_0() -> i32 { assert!((copies_1.with(|rc| *rc.borrow()) == 2)); assert!((({ sum_2(a.as_pointer(),) }) == 6)); assert!((({ sum_2(b.as_pointer(),) }) == 106)); - object!(d, Buffer, a.as_pointer()); + object!(d, Buffer, LvalueRef::bind(a.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 4) && (copies_1.with(|rc| *rc.borrow()) == 3)); assert!( ({ (*a.borrow()).size } == 4) && ((array_elem!(a.as_pointer(), data, 3).read()) == 3) diff --git a/tests/unit/out/refcount/rvalue_rule_arg_move.rs b/tests/unit/out/refcount/rvalue_rule_arg_move.rs index 1ee22ca2c7..d4933d171e 100644 --- a/tests/unit/out/refcount/rvalue_rule_arg_move.rs +++ b/tests/unit/out/refcount/rvalue_rule_arg_move.rs @@ -36,13 +36,15 @@ impl Elem { } } impl CopyConstructible for Elem { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Elem { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -65,7 +67,7 @@ fn main_0() -> i32 { let mut __tmp_0 = { >::from(v.decay().end()) }; let __a2 = { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(a.as_pointer())); + MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(a.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; (*v.borrow_mut()).insert(__tmp_0.index(), __a2); diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 28168bbd87..de93e952b1 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -63,14 +63,16 @@ pub fn size_t_in_rules_3() { Rc::new(RefCell::new((0..3).map(|_| ::zero_init()).collect())); let __p: Ptr = __v.decay(); for __i in 0..3 { - __p.offset(__i) - .construct_from(Moved(ar2.decay().offset(__i))); + MoveConstructible::move_constructor( + __p.offset(__i), + RvalueRef::bind(ar2.decay().offset(__i)), + ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); { for __i in 0..3 { - assign!(*ar3.as_pointer().decay().offset(__i) = Moved(*ar.decay().offset(__i))); + assign!(*ar3.as_pointer().decay().offset(__i) = RvalueRef(*ar.decay().offset(__i))); } ar3.as_pointer() }; diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index 27aee2afb1..3e017a0df4 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -27,25 +27,29 @@ impl DefaultConstructible for Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Tracked { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); } } impl CopyAssignable for Tracked { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); return (this).clone(); } } impl MoveAssignable for Tracked { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); return (this).clone(); } diff --git a/tests/unit/out/refcount/structured_binding_copy_ctor.rs b/tests/unit/out/refcount/structured_binding_copy_ctor.rs index 3a0162e107..1e9c93ba33 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -36,7 +36,8 @@ impl Counted { } } impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor(this: Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!(this, x).write((other.with(|__s| __s.x) * 2)); field!(this, y).write((other.with(|__s| __s.y) * 2)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); @@ -54,7 +55,7 @@ fn main_0() -> i32 { object!(s, Counted(1, 2)); let __decomp_2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), s.as_pointer()); + CopyConstructible::copy_constructor(__v.as_pointer(), LvalueRef::bind(s.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((copies_0.with(|rc| *rc.borrow()) == 1)); diff --git a/tests/unit/out/refcount/structured_binding_element_ctor.rs b/tests/unit/out/refcount/structured_binding_element_ctor.rs index 405c4024d0..e73c88804f 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -27,13 +27,15 @@ impl Elem { } } impl CopyConstructible for Elem { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor(this: Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!(this, v).write((other.with(|__s| __s.v) + 100)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Elem { - fn move_constructor(this: Ptr, other: Ptr) { + fn move_constructor(this: Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!(this, v).write((other.with(|__s| __s.v) + 1000)); field!(other, v).write(-1_i32); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); @@ -88,7 +90,7 @@ fn main_0() -> i32 { let mut base_moves: i32 = moves_1.with(|rc| *rc.borrow()); let __decomp_3: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), t.as_pointer()); + CopyConstructible::copy_constructor(__v.as_pointer(), LvalueRef::bind(t.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((copies_0.with(|rc| *rc.borrow()) == (base_copies + 2))); @@ -102,7 +104,7 @@ fn main_0() -> i32 { assert!(({ (*t.borrow()).a.v } == 50)); let __decomp_5: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(t.as_pointer())); + MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(t.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((moves_1.with(|rc| *rc.borrow()) == (base_moves + 2))); @@ -125,7 +127,10 @@ fn main_0() -> i32 { Elem::construct(__tmp_0.as_pointer(), 7); { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(__tmp_0.as_pointer())); + MoveConstructible::move_constructor( + __v.as_pointer(), + RvalueRef::bind(__tmp_0.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } })), @@ -134,7 +139,10 @@ fn main_0() -> i32 { Elem::construct(__tmp_1.as_pointer(), 8); { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(__tmp_1.as_pointer())); + MoveConstructible::move_constructor( + __v.as_pointer(), + RvalueRef::bind(__tmp_1.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } })), diff --git a/tests/unit/out/refcount/structured_binding_move_ctor.rs b/tests/unit/out/refcount/structured_binding_move_ctor.rs index 58ccc2b8df..5fe6efe7c3 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -27,14 +27,16 @@ impl Movable { } } impl CopyConstructible for Movable { - fn copy_constructor(this: Ptr, other: Ptr) { + fn copy_constructor(this: Ptr, other: LvalueRef>) { + let other = other.as_pointer(); field!(this, x).write(other.with(|__s| __s.x)); field!(this, y).write(other.with(|__s| __s.y)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Movable { - fn move_constructor(this: Ptr, other: Ptr) { + fn move_constructor(this: Ptr, other: RvalueRef) { + let other = other.as_pointer(); field!(this, x).write(other.with(|__s| __s.x)); field!(this, y).write(other.with(|__s| __s.y)); field!(other, x).write(0); @@ -88,7 +90,7 @@ fn main_0() -> i32 { object!(m, Movable(3, 4)); let __decomp_2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), Moved(m.as_pointer())); + MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(m.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((moves_1.with(|rc| *rc.borrow()) == 1)); diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 782246a0d9..e3c2df9ae8 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -27,25 +27,29 @@ impl DefaultConstructible for Tracked { } } impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Tracked { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); } } impl CopyAssignable for Tracked { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); return (this).clone(); } } impl MoveAssignable for Tracked { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); return (this).clone(); } @@ -150,7 +154,8 @@ impl CopyOnly { } } impl CopyConstructible for CopyOnly { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copy_only_copies_1.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -161,7 +166,8 @@ impl Destructible for CopyOnly { } } impl CopyAssignable for CopyOnly { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copy_only_copies_1.with(Value::clone).borrow_mut()).prefix_inc(); return (this).clone(); @@ -206,27 +212,31 @@ impl Moved { } } impl CopyConstructible for Moved { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Moved { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyAssignable for Moved { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); return (this).clone(); } } impl MoveAssignable for Moved { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*move_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -310,7 +320,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); ({ @@ -327,7 +337,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); let m2: Value, Value)>> = Rc::new(RefCell::new(Map::new())); @@ -345,7 +355,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); @@ -647,7 +657,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); ({ @@ -664,7 +674,7 @@ fn main_0() -> i32 { ) }) } - } = Moved(_o) + } = RvalueRef(_o) ) }); Swappable::swap(maps.decay().offset(0), maps.decay().offset(1)); diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index 11379eabf7..919d9683c7 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -310,7 +310,7 @@ unsafe fn main_0() -> i32 { assert!(((b2.w) == (2))); let mut v4: Vec = Vec::new(); { - AssignFromUnsafe::assign_from(&raw mut v4, &mut v2); + CopyAssignableUnsafe::copy_assign(&raw mut v4, LvalueRefUnsafe::bind(&mut v2)); }; { let mut i: i32 = 0; diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index f4702998d3..9864b73db1 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -28,13 +28,15 @@ impl Partial { } } impl CopyConstructibleUnsafe for Partial { - unsafe fn copy_constructor(this: *mut Self, o: *const Partial) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Partial); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).keep).write((*o).keep); } } impl CopyAssignableUnsafe for Partial { - unsafe fn copy_assign(this: *mut Self, o: *const Partial) -> *mut Partial { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Partial { + let o = (o.as_ptr() as *const Partial); if (((this).cast_const()) == (o)) { return &mut (*this); } @@ -102,7 +104,11 @@ impl DefaultConstructibleUnsafe for RefQualified { } } impl CopyAssignableUnsafe for RefQualified { - unsafe fn copy_assign(this: *mut Self, o: *const RefQualified) -> *mut RefQualified { + unsafe fn copy_assign( + this: *mut Self, + o: LvalueRefUnsafe>, + ) -> *mut RefQualified { + let o = (o.as_ptr() as *const RefQualified); (*this).mark = (((*o).mark) + (1)); return &mut (*this); } @@ -156,7 +162,8 @@ impl CopyCounted { } } impl CopyConstructibleUnsafe for CopyCounted { - unsafe fn copy_constructor(this: *mut Self, o: *const CopyCounted) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const CopyCounted); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); } @@ -192,10 +199,11 @@ pub struct ExplicitOperatorCall { impl CopyAssignableUnsafe for ExplicitOperatorCall { unsafe fn copy_assign( this: *mut Self, - o: *const ExplicitOperatorCall, + o: LvalueRefUnsafe>, ) -> *mut ExplicitOperatorCall { + let o = (o.as_ptr() as *const ExplicitOperatorCall); { - AssignFromUnsafe::assign_from(&raw mut (*this).w, &(*o).w); + CopyAssignableUnsafe::copy_assign(&raw mut (*this).w, LvalueRefUnsafe::bind(&(*o).w)); }; return &mut (*this); } @@ -232,21 +240,30 @@ impl Swapped { } } impl CopyConstructibleUnsafe for Swapped { - unsafe fn copy_constructor(this: *mut Self, o: *const Swapped) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Swapped); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut swap_copies_2)).prefix_inc(); } } impl CopyAssignableUnsafe for Swapped { - unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { - object_unsafe!(__o, Swapped, src); + unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { + object_unsafe!( + __o, + Swapped, + LvalueRefUnsafe::bind((src.as_ptr() as *const Swapped)) + ); Swapped::copy_assign(this, &raw mut __o); this } } impl MoveAssignableUnsafe for Swapped { - unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { - object_unsafe!(__o, Swapped, Moved(src)); + unsafe fn move_assign(this: *mut Self, src: RvalueRefUnsafe) -> *mut Self { + object_unsafe!( + __o, + Swapped, + RvalueRefUnsafe::bind((src.as_ptr() as *mut Swapped)) + ); Swapped::copy_assign(this, &raw mut __o); this } @@ -290,14 +307,14 @@ impl DefaultConstructibleUnsafe for VoidAssign { } } impl CopyAssignableUnsafe for VoidAssign { - unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { - VoidAssign::copy_assign(this, src); + unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { + VoidAssign::copy_assign(this, (src.as_ptr() as *const VoidAssign)); this } } impl MoveAssignableUnsafe for VoidAssign { - unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { - VoidAssign::copy_assign(this, src); + unsafe fn move_assign(this: *mut Self, src: RvalueRefUnsafe) -> *mut Self { + VoidAssign::copy_assign(this, (src.as_ptr() as *mut VoidAssign)); this } } @@ -490,7 +507,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(sw2, Swapped(2)); (unsafe { let mut _o: Swapped = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut _o, &sw2); + CopyConstructibleUnsafe::copy_constructor(&raw mut _o, LvalueRefUnsafe::bind(&sw2)); Swapped::copy_assign(&raw mut sw1, &mut _o) }); assert!( diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 0c83840e9f..ba09cb3c4d 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -30,7 +30,8 @@ impl Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: *const Counted) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Counted); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } @@ -90,7 +91,8 @@ impl Ignored { } } impl CopyConstructibleUnsafe for Ignored { - unsafe fn copy_constructor(this: *mut Self, _a0: *const Ignored) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const Ignored); (&raw mut (*this).v).write(-1_i32); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } @@ -129,7 +131,8 @@ impl Box_int_ { } } impl CopyConstructibleUnsafe for Box_int_ { - unsafe fn copy_constructor(this: *mut Self, o: *const Box_int_) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Box_int_); (&raw mut (*this).val).write((*o).val); } } @@ -164,7 +167,8 @@ impl OutOfLine { } } impl CopyConstructibleUnsafe for OutOfLine { - unsafe fn copy_constructor(this: *mut Self, o: *const OutOfLine) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const OutOfLine); (&raw mut (*this).v).write((((*o).v) + (100))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } @@ -187,13 +191,15 @@ impl DefaultConstructibleUnsafe for Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).copied_from).write(0); (*(&raw const (*o).copied_from).cast_mut()).prefix_inc(); } } impl CopyAssignableUnsafe for Tracked { - unsafe fn copy_assign(this: *mut Self, o: *const Tracked) -> *mut Tracked { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Tracked { + let o = (o.as_ptr() as *const Tracked); (*(&raw const (*o).copied_from).cast_mut()).prefix_inc(); return &mut (*this); } @@ -211,7 +217,7 @@ pub unsafe fn by_value_2(c: *mut Counted) -> i32 { } pub unsafe fn make_3(__return: *mut Counted, mut v: i32) { object_unsafe!(c, Counted(v)); - ConstructFromUnsafe::construct_from(__return, &c); + CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(&c)); return; } #[repr(C)] @@ -225,12 +231,14 @@ impl DefaultConstructibleUnsafe for SelfPtr { } } impl CopyConstructibleUnsafe for SelfPtr { - unsafe fn copy_constructor(this: *mut Self, _a0: *const SelfPtr) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const SelfPtr); (&raw mut (*this).self_).write(this); } } impl MoveConstructibleUnsafe for SelfPtr { - unsafe fn move_constructor(this: *mut Self, _a0: *mut SelfPtr) { + unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { + let _a0 = (_a0.as_ptr() as *mut SelfPtr); (&raw mut (*this).self_).write(this); } } @@ -289,15 +297,15 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(a, Counted(1)); - object_unsafe!(b, Counted, &a); - object_unsafe!(c, Counted, &a); - object_unsafe!(d, Counted, &a); + object_unsafe!(b, Counted, LvalueRefUnsafe::bind(&a)); + object_unsafe!(c, Counted, LvalueRefUnsafe::bind(&a)); + object_unsafe!(d, Counted, LvalueRefUnsafe::bind(&a)); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (3))); assert!((((b.v) == (1)) && ((c.v) == (1))) && ((d.v) == (1))); assert!( ((unsafe { let mut _c: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut _c, &a); + CopyConstructibleUnsafe::copy_constructor(&raw mut _c, LvalueRefUnsafe::bind(&a)); by_value_2(&mut _c) }) == (1)) ); @@ -309,7 +317,7 @@ unsafe fn main_0() -> i32 { assert!(((f.v) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5))); object_unsafe!(g, Counted(7)); - object_unsafe!(h, Counted, &g); + object_unsafe!(h, Counted, LvalueRefUnsafe::bind(&g)); assert!(((h.v) == (7))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (6))); let mut hold: Holder = Holder { @@ -331,7 +339,7 @@ unsafe fn main_0() -> i32 { }, ], }; - object_unsafe!(hold2, Holder, &hold); + object_unsafe!(hold2, Holder, LvalueRefUnsafe::bind(&hold)); assert!( (((hold2.c.v) == (8)) && ((hold2.arr[(0) as usize].v) == (9))) && ((hold2.arr[(1) as usize].v) == (10)) @@ -342,7 +350,7 @@ unsafe fn main_0() -> i32 { assert!(((vec_[(0_usize)].v) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (10))); object_unsafe!(i1, Ignored(1)); - object_unsafe!(i2, Ignored, &i1); + object_unsafe!(i2, Ignored, LvalueRefUnsafe::bind(&i1)); assert!(((i1.v) == (1)) && ((i2.v) == (-1_i32))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (11))); let mut o: Owner = Owner { @@ -352,10 +360,10 @@ unsafe fn main_0() -> i32 { __v }, }; - object_unsafe!(o2, Owner, Moved(&mut o)); + object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o)); assert!(((o2.box_.val) == (3))); object_unsafe!(ol1, OutOfLine(5)); - object_unsafe!(ol2, OutOfLine, &ol1); + object_unsafe!(ol2, OutOfLine, LvalueRefUnsafe::bind(&ol1)); assert!(((ol2.v) == (105))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (12))); object_unsafe!(n, NonConst); @@ -365,16 +373,16 @@ unsafe fn main_0() -> i32 { assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); object_unsafe!(t1, Tracked); - object_unsafe!(t2, Tracked, &t1); + object_unsafe!(t2, Tracked, LvalueRefUnsafe::bind(&t1)); assign_unsafe!(t2 = t1); assert!(((t1.copied_from) == (2))); object_unsafe!(ct, Tracked); - object_unsafe!(t3, Tracked, &ct); + object_unsafe!(t3, Tracked, LvalueRefUnsafe::bind(&ct)); (unsafe { touch_1((&ct as *const Tracked)) }); assert!(((ct.copied_from) == (2))); let mut before: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)); object_unsafe!(der, Derived); - object_unsafe!(der2, Derived, &der); + object_unsafe!(der2, Derived, LvalueRefUnsafe::bind(&der)); assert!( ((der2.c.v) == (20)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((before) + (1))) diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 234e910395..e120566636 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -91,7 +91,8 @@ impl DefaultCopyUserMove { } } impl MoveConstructibleUnsafe for DefaultCopyUserMove { - unsafe fn move_constructor(this: *mut Self, o: *mut DefaultCopyUserMove) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut DefaultCopyUserMove); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } @@ -99,8 +100,9 @@ impl MoveConstructibleUnsafe for DefaultCopyUserMove { impl MoveAssignableUnsafe for DefaultCopyUserMove { unsafe fn move_assign( this: *mut Self, - o: *mut DefaultCopyUserMove, + o: RvalueRefUnsafe, ) -> *mut DefaultCopyUserMove { + let o = (o.as_ptr() as *mut DefaultCopyUserMove); (*this).v = (*o).v; (*o).v = 0; return &mut (*this); @@ -127,15 +129,17 @@ impl UserCopyDefaultMove { } } impl CopyConstructibleUnsafe for UserCopyDefaultMove { - unsafe fn copy_constructor(this: *mut Self, o: *const UserCopyDefaultMove) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const UserCopyDefaultMove); (&raw mut (*this).v).write((((*o).v) + (100))); } } impl CopyAssignableUnsafe for UserCopyDefaultMove { unsafe fn copy_assign( this: *mut Self, - o: *const UserCopyDefaultMove, + o: LvalueRefUnsafe>, ) -> *mut UserCopyDefaultMove { + let o = (o.as_ptr() as *const UserCopyDefaultMove); (*this).v = (((*o).v) + (100)); return &mut (*this); } @@ -249,13 +253,15 @@ pub struct SeesThis { pub self_: *mut SeesThis, } impl CopyAssignableUnsafe for SeesThis { - unsafe fn copy_assign(this: *mut Self, _a0: *const SeesThis) -> *mut SeesThis { + unsafe fn copy_assign(this: *mut Self, _a0: LvalueRefUnsafe>) -> *mut SeesThis { + let _a0 = (_a0.as_ptr() as *const SeesThis); (*this).self_ = this; return &mut (*this); } } impl MoveAssignableUnsafe for SeesThis { - unsafe fn move_assign(this: *mut Self, _a0: *mut SeesThis) -> *mut SeesThis { + unsafe fn move_assign(this: *mut Self, _a0: RvalueRefUnsafe) -> *mut SeesThis { + let _a0 = (_a0.as_ptr() as *mut SeesThis); (*this).self_ = this; return &mut (*this); } @@ -300,13 +306,15 @@ impl DefaultConstructibleUnsafe for Counted_int_ { } } impl MoveConstructibleUnsafe for Counted_int_ { - unsafe fn move_constructor(this: *mut Self, o: *mut Counted_int_) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Counted_int_); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).moves).write((((*o).moves) + (1))); } } impl MoveAssignableUnsafe for Counted_int_ { - unsafe fn move_assign(this: *mut Self, o: *mut Counted_int_) -> *mut Counted_int_ { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Counted_int_ { + let o = (o.as_ptr() as *mut Counted_int_); (*this).v = (*o).v; (*this).moves = (((*o).moves) + (1)); return &mut (*this); @@ -359,24 +367,34 @@ impl DefaultConstructibleUnsafe for CtorSeesThis { } } impl CopyConstructibleUnsafe for CtorSeesThis { - unsafe fn copy_constructor(this: *mut Self, _a0: *const CtorSeesThis) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const CtorSeesThis); (&raw mut (*this).self_).write(this); (&raw mut (*this).id).write(0); } } impl MoveConstructibleUnsafe for CtorSeesThis { - unsafe fn move_constructor(this: *mut Self, _a0: *mut CtorSeesThis) { + unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { + let _a0 = (_a0.as_ptr() as *mut CtorSeesThis); (&raw mut (*this).self_).write(this); (&raw mut (*this).id).write(0); } } impl CopyAssignableUnsafe for CtorSeesThis { - unsafe fn copy_assign(this: *mut Self, _a0: *const CtorSeesThis) -> *mut CtorSeesThis { + unsafe fn copy_assign( + this: *mut Self, + _a0: LvalueRefUnsafe>, + ) -> *mut CtorSeesThis { + let _a0 = (_a0.as_ptr() as *const CtorSeesThis); return &mut (*this); } } impl MoveAssignableUnsafe for CtorSeesThis { - unsafe fn move_assign(this: *mut Self, _a0: *mut CtorSeesThis) -> *mut CtorSeesThis { + unsafe fn move_assign( + this: *mut Self, + _a0: RvalueRefUnsafe, + ) -> *mut CtorSeesThis { + let _a0 = (_a0.as_ptr() as *mut CtorSeesThis); return &mut (*this); } } @@ -459,8 +477,12 @@ impl OutOfLineDefaulted { } } impl CopyConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn copy_constructor(this: *mut Self, _a0: *const OutOfLineDefaulted) { - ConstructFromUnsafe::construct_from(&raw mut (*this).x, &(*_a0).x); + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const OutOfLineDefaulted); + CopyConstructibleUnsafe::copy_constructor( + &raw mut (*this).x, + LvalueRefUnsafe::bind(&(*_a0).x), + ); (&raw mut (*this).v).write((*_a0).v); } } @@ -509,23 +531,31 @@ impl Default for OutOfLineAssign { } } impl CopyAssignableUnsafe for OutOfLineAssign { - unsafe fn copy_assign(this: *mut Self, _a0: *const OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn copy_assign( + this: *mut Self, + _a0: LvalueRefUnsafe>, + ) -> *mut OutOfLineAssign { + let _a0 = (_a0.as_ptr() as *const OutOfLineAssign); (unsafe { let _arg0: *const SeesThis = &(*_a0).s; assign_unsafe!((*this).s = *_arg0) }); (*this).v = (*_a0).v; { - AssignFromUnsafe::assign_from(&raw mut (*this).w, &(*_a0).w); + CopyAssignableUnsafe::copy_assign(&raw mut (*this).w, LvalueRefUnsafe::bind(&(*_a0).w)); }; return &mut (*this); } } impl MoveAssignableUnsafe for OutOfLineAssign { - unsafe fn move_assign(this: *mut Self, _a0: *mut OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn move_assign( + this: *mut Self, + _a0: RvalueRefUnsafe, + ) -> *mut OutOfLineAssign { + let _a0 = (_a0.as_ptr() as *mut OutOfLineAssign); (unsafe { let _arg0: *mut SeesThis = &mut (*_a0).s; - assign_unsafe!((*this).s = Moved(*_arg0)) + assign_unsafe!((*this).s = RvalueRefUnsafe(*_arg0)) }); (*this).v = (*_a0).v; { @@ -561,7 +591,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(e, Explicit(2)); object_unsafe!(f, Explicit(3)); assign_unsafe!(e = b); - assign_unsafe!(f = Moved(c)); + assign_unsafe!(f = RvalueRefUnsafe(c)); assert!((unsafe { same_0(&e, &b,) }) && (unsafe { same_0(&f, &c,) })); object_unsafe!(g, Explicit(4)); assign_unsafe!(g = (*assign_unsafe!(e = f))); @@ -595,30 +625,30 @@ unsafe fn main_0() -> i32 { assert!(((vec_[(0_usize)].v) == (1)) && ((vec_[(1_usize)].v) == (9))); object_unsafe!(m, DefaultCopyUserMove(7)); let mut m1: DefaultCopyUserMove = m; - object_unsafe!(m2, DefaultCopyUserMove, Moved(&mut m)); + object_unsafe!(m2, DefaultCopyUserMove, RvalueRefUnsafe::bind(&mut m)); assert!((((m1.v) == (7)) && ((m2.v) == (7))) && ((m.v) == (0))); object_unsafe!(m3, DefaultCopyUserMove(1)); object_unsafe!(m4, DefaultCopyUserMove(1)); assign_unsafe!(m3 = m1); - assign_unsafe!(m4 = Moved(m1)); + assign_unsafe!(m4 = RvalueRefUnsafe(m1)); assert!((((m3.v) == (7)) && ((m4.v) == (7))) && ((m1.v) == (0))); object_unsafe!(u, UserCopyDefaultMove(8)); - object_unsafe!(u1, UserCopyDefaultMove, &u); - object_unsafe!(u2, UserCopyDefaultMove, Moved(&mut u)); + object_unsafe!(u1, UserCopyDefaultMove, LvalueRefUnsafe::bind(&u)); + object_unsafe!(u2, UserCopyDefaultMove, RvalueRefUnsafe::bind(&mut u)); assert!((((u1.v) == (108)) && ((u2.v) == (8))) && ((u.v) == (8))); object_unsafe!(u3, UserCopyDefaultMove(1)); object_unsafe!(u4, UserCopyDefaultMove(1)); assign_unsafe!(u3 = u2); - assign_unsafe!(u4 = Moved(u2)); + assign_unsafe!(u4 = RvalueRefUnsafe(u2)); assert!(((u3.v) == (108)) && ((u4.v) == (8))); object_unsafe!(p, Buffer(3)); - object_unsafe!(q, Buffer, Moved(&mut p)); + object_unsafe!(q, Buffer, RvalueRefUnsafe::bind(&mut p)); assert!( ((((q.n) == (3)) && ((q.data.len()) == (3_usize))) && ((q.data[(2_usize)]) == (3))) && (p.data.is_empty()) ); object_unsafe!(r, Buffer(1)); - assign_unsafe!(r = Moved(q)); + assign_unsafe!(r = RvalueRefUnsafe(q)); assert!( ((((r.n) == (3)) && ((r.data.len()) == (3_usize))) && ((r.arr[(1) as usize]) == (4))) && (q.data.is_empty()) @@ -633,7 +663,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { { let mut __v: Buffer = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut bufs[(0_usize)])); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut bufs[(0_usize)]), + ); __v } }; @@ -659,7 +692,7 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(_a0)) } }; - object_unsafe!(o2, Owner, Moved(&mut o1)); + object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o1)); assert!( ((((o2.n) == (5)) && ((o2.data.len()) == (1_usize))) && ((o2.arr[(1) as usize]) == (6))) && ((*o2 @@ -677,7 +710,7 @@ unsafe fn main_0() -> i32 { .is_null()) ); object_unsafe!(o3, Owner); - assign_unsafe!(o3 = Moved(o2)); + assign_unsafe!(o3 = RvalueRefUnsafe(o2)); assert!( ((((o3.n) == (5)) && ((o3.data[(0_usize)]) == (5))) && ((o3.arr[(0) as usize]) == (5))) && ((*o3 @@ -698,11 +731,11 @@ unsafe fn main_0() -> i32 { data: Vec::from([1, 2]), }; let mut c2: Copyable = c1.clone(); - object_unsafe!(c3, Copyable, Moved(&mut c1)); + object_unsafe!(c3, Copyable, RvalueRefUnsafe::bind(&mut c1)); assert!(((c2.data.len()) == (2_usize)) && ((c3.data.len()) == (2_usize))); assert!(c1.data.is_empty()); object_unsafe!(c4, Copyable); - assign_unsafe!(c4 = Moved(c3)); + assign_unsafe!(c4 = RvalueRefUnsafe(c3)); assert!(((c4.data[(1_usize)]) == (2)) && (c3.data.is_empty())); object_unsafe!(h1, Holder(4)); { @@ -713,7 +746,7 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(_a0)) } }; - object_unsafe!(h2, Holder, Moved(&mut h1)); + object_unsafe!(h2, Holder, RvalueRefUnsafe::bind(&mut h1)); assert!( ((((h2.inner.x) == (4)) && ((h2.e.v) == (4))) && ((*h2 @@ -728,7 +761,7 @@ unsafe fn main_0() -> i32 { .is_null()) ); object_unsafe!(h3, Holder(1)); - assign_unsafe!(h3 = Moved(h2)); + assign_unsafe!(h3 = RvalueRefUnsafe(h2)); assert!( ((((h3.inner.x) == (4)) && ((h3.e.arr[(1) as usize]) == (5))) && ((*h3 @@ -745,30 +778,30 @@ unsafe fn main_0() -> i32 { object_unsafe!(t1, HasSeesThis); object_unsafe!(t2, HasSeesThis); object_unsafe!(t3, HasSeesThis); - assign_unsafe!(t2 = Moved(t1)); + assign_unsafe!(t2 = RvalueRefUnsafe(t1)); assert!(((t2.s.self_) == (&mut t2.s as *mut SeesThis))); assign_unsafe!(t3 = t2); assert!(((t3.s.self_) == (&mut t3.s as *mut SeesThis))); object_unsafe!(k1, HasCounted); - object_unsafe!(k2, HasCounted, Moved(&mut k1)); + object_unsafe!(k2, HasCounted, RvalueRefUnsafe::bind(&mut k1)); assert!(((k2.c.moves) == (1))); object_unsafe!(k3, HasCounted); - assign_unsafe!(k3 = Moved(k2)); + assign_unsafe!(k3 = RvalueRefUnsafe(k2)); assert!(((k3.c.moves) == (2))); { object_unsafe!(d, CtorSeesThis); assert!(((d.self_) == (&mut d as *mut CtorSeesThis))); - object_unsafe!(e, CtorSeesThis, &d); + object_unsafe!(e, CtorSeesThis, LvalueRefUnsafe::bind(&d)); assert!(((e.self_) == (&mut e as *mut CtorSeesThis))); object_unsafe!(f, CtorSeesThis::construct_1(3)); assert!(((f.self_) == (&mut f as *mut CtorSeesThis)) && ((f.id) == (3))); object_unsafe!(h1, HasCtorSeesThis); assert!(((h1.x.self_) == (&mut h1.x as *mut CtorSeesThis))); - object_unsafe!(h2, HasCtorSeesThis, &h1); + object_unsafe!(h2, HasCtorSeesThis, LvalueRefUnsafe::bind(&h1)); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); - object_unsafe!(h3, HasCtorSeesThis, Moved(&mut h1)); + object_unsafe!(h3, HasCtorSeesThis, RvalueRefUnsafe::bind(&mut h1)); assert!(((h3.x.self_) == (&mut h3.x as *mut CtorSeesThis))); - assign_unsafe!(h2 = Moved(h3)); + assign_unsafe!(h2 = RvalueRefUnsafe(h3)); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); assign_unsafe!(h2 = h1); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); @@ -790,7 +823,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(o1, OutOfLineDefaulted()); assert!(((o1.v) == (1)) && ((o1.x.self_) == (&mut o1.x as *mut CtorSeesThis))); o1.v = 2; - object_unsafe!(o2, OutOfLineDefaulted, &o1); + object_unsafe!(o2, OutOfLineDefaulted, LvalueRefUnsafe::bind(&o1)); assert!(((o2.v) == (2)) && ((o2.x.self_) == (&mut o2.x as *mut CtorSeesThis))); object_unsafe!(a1, OutOfLineAssign); object_unsafe!(a2, OutOfLineAssign); @@ -803,7 +836,7 @@ unsafe fn main_0() -> i32 { assign_unsafe!(a2 = a1); assert!((((a2.v) == (3)) && ((a2.w.len()) == (1_usize))) && ((a1.w.len()) == (1_usize))); assert!(((a2.s.self_) == (&mut a2.s as *mut SeesThis))); - assign_unsafe!(a3 = Moved(a2)); + assign_unsafe!(a3 = RvalueRefUnsafe(a2)); assert!( (((a3.v) == (3)) && ((a3.w.len()) == (1_usize))) && ((a3.s.self_) == (&mut a3.s as *mut SeesThis)) diff --git a/tests/unit/out/unsafe/copy_move_deleted.rs b/tests/unit/out/unsafe/copy_move_deleted.rs index d2aebc4c55..be888a3cd0 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.rs @@ -25,13 +25,15 @@ impl NoCopy { } } impl MoveConstructibleUnsafe for NoCopy { - unsafe fn move_constructor(this: *mut Self, o: *mut NoCopy) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut NoCopy); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for NoCopy { - unsafe fn move_assign(this: *mut Self, o: *mut NoCopy) -> *mut NoCopy { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut NoCopy { + let o = (o.as_ptr() as *mut NoCopy); (*this).v = (*o).v; (*o).v = 0; return &mut (*this); @@ -48,13 +50,15 @@ impl DefaultConstructibleUnsafe for PrivateCopy { } } impl MoveConstructibleUnsafe for PrivateCopy { - unsafe fn move_constructor(this: *mut Self, o: *mut PrivateCopy) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut PrivateCopy); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for PrivateCopy { - unsafe fn move_assign(this: *mut Self, o: *mut PrivateCopy) -> *mut PrivateCopy { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut PrivateCopy { + let o = (o.as_ptr() as *mut PrivateCopy); (*this).v = (*o).v; (*o).v = 0; return &mut (*this); @@ -138,17 +142,17 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(a, NoCopy(1)); - object_unsafe!(b, NoCopy, Moved(&mut a)); + object_unsafe!(b, NoCopy, RvalueRefUnsafe::bind(&mut a)); assert!(((b.v) == (1)) && ((a.v) == (0))); - assign_unsafe!(a = Moved(b)); + assign_unsafe!(a = RvalueRefUnsafe(b)); assert!(((a.v) == (1)) && ((b.v) == (0))); (unsafe { bump_0((&mut a as *mut NoCopy)) }); assert!(((a.v) == (2))); object_unsafe!(p, PrivateCopy); p.v = 3; - object_unsafe!(q, PrivateCopy, Moved(&mut p)); + object_unsafe!(q, PrivateCopy, RvalueRefUnsafe::bind(&mut p)); assert!(((q.v) == (3)) && ((p.v) == (0))); - assign_unsafe!(p = Moved(q)); + assign_unsafe!(p = RvalueRefUnsafe(q)); assert!(((p.v) == (3)) && ((q.v) == (0))); object_unsafe!(im, Immovable); im.v = 4; @@ -163,20 +167,20 @@ unsafe fn main_0() -> i32 { }, tag: 7, }; - object_unsafe!(d, Container, Moved(&mut c)); + object_unsafe!(d, Container, RvalueRefUnsafe::bind(&mut c)); assert!((((d.inner.v) == (6)) && ((d.tag) == (7))) && ((c.inner.v) == (0))); object_unsafe!(h, VecHolder); - object_unsafe!(h2, VecHolder, Moved(&mut h)); + object_unsafe!(h2, VecHolder, RvalueRefUnsafe::bind(&mut h)); assert!(((h2.items.len()) == (0_usize))); return 0; } impl CopyAssignableUnsafe for PrivateCopy { - unsafe fn copy_assign(this: *mut Self, _: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, _: LvalueRefUnsafe>) -> *mut Self { unreachable!("PrivateCopy::copy_assign is never defined") } } impl CopyConstructibleUnsafe for PrivateCopy { - unsafe fn copy_constructor(this: *mut Self, _: *const Self) { + unsafe fn copy_constructor(this: *mut Self, _: LvalueRefUnsafe>) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index 02770b369d..dfedc383e9 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -67,7 +67,8 @@ impl MoveOnly { } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, x: *mut MoveOnly) { + unsafe fn move_constructor(this: *mut Self, x: RvalueRefUnsafe) { + let x = (x.as_ptr() as *mut MoveOnly); (&raw mut (*this).data_).write((*x).data_); (*x).data_ = 0; } @@ -120,7 +121,7 @@ unsafe fn main_0() -> i32 { let mut sc: Option = Some(scale_move_only_3); object_unsafe!(n, MoveOnly, |n| (unsafe { let mut _arg0: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut _arg0, Moved(&mut m)); + MoveConstructibleUnsafe::move_constructor(&raw mut _arg0, RvalueRefUnsafe::bind(&mut m)); (sc).unwrap()(n, &mut _arg0) })); assert!(((unsafe { MoveOnly::get(&raw const n,) }) == (40))); diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 36855b01cc..a6c2edcaf1 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -27,14 +27,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -49,12 +51,12 @@ pub unsafe fn chosen_overload_1(_a0: *mut Tracked) -> Overload { } impl Holder { pub unsafe fn construct_1(this: *mut Self, x: *mut Tracked) { - ConstructFromUnsafe::construct_from(&raw mut (*this).t, x); + CopyConstructibleUnsafe::copy_constructor(&raw mut (*this).t, LvalueRefUnsafe::bind(x)); } } impl Holder { pub unsafe fn construct_2(this: *mut Self, x: *mut Tracked) { - ConstructFromUnsafe::construct_from(&raw mut (*this).t, Moved(x)); + MoveConstructibleUnsafe::move_constructor(&raw mut (*this).t, RvalueRefUnsafe::bind(x)); } } #[repr(C)] diff --git a/tests/unit/out/unsafe/forward_decltype.rs b/tests/unit/out/unsafe/forward_decltype.rs index 719d60dd5d..6c78d55ef1 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -27,14 +27,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); (&raw mut (*this).moves).write((((*o).moves) + (1))); diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index d787f5307c..e5f675c7ce 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -29,14 +29,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -56,7 +58,7 @@ pub unsafe fn chosen_overload_3(_a0: *mut i32) -> Overload { return Overload_kIntRvalueOverload; } pub unsafe fn copy_or_move_into_param_4(__return: *mut Tracked, t: *mut Tracked) { - ConstructFromUnsafe::construct_from(__return, Moved(t)); + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(t)); return; } pub fn main() { @@ -76,7 +78,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(b, Tracked(6)); object_unsafe!(moved, Tracked, |moved| (unsafe { let mut _t: Tracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut _t, Moved(&mut b)); + MoveConstructibleUnsafe::move_constructor(&raw mut _t, RvalueRefUnsafe::bind(&mut b)); copy_or_move_into_param_4(moved, &mut _t) })); assert!(((moved.v) == (6))); @@ -86,7 +88,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(c, Tracked(7)); object_unsafe!(copied, Tracked, |copied| (unsafe { let mut _t: Tracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut _t, &c); + CopyConstructibleUnsafe::copy_constructor(&raw mut _t, LvalueRefUnsafe::bind(&c)); copy_or_move_into_param_4(copied, &mut _t) })); assert!(((copied.v) == (7))); diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index f848da77e0..5b7c949f79 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -29,14 +29,16 @@ impl Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -91,8 +93,8 @@ pub unsafe fn forward_pack_7( } impl Pair { pub unsafe fn construct(this: *mut Self, x: *mut Tracked, y: *mut Tracked) { - ConstructFromUnsafe::construct_from(&raw mut (*this).a, x); - ConstructFromUnsafe::construct_from(&raw mut (*this).b, Moved(y)); + CopyConstructibleUnsafe::copy_constructor(&raw mut (*this).a, LvalueRefUnsafe::bind(x)); + MoveConstructibleUnsafe::move_constructor(&raw mut (*this).b, RvalueRefUnsafe::bind(y)); } } #[repr(C)] diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index 47a07f2ea9..ff19c40209 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -148,27 +148,31 @@ impl DefaultConstructibleUnsafe for Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: *const Counted) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Counted); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)).prefix_inc(); } } impl MoveConstructibleUnsafe for Counted { - unsafe fn move_constructor(this: *mut Self, o: *mut Counted) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Counted); (&raw mut (*this).v).write((*o).v); (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); } } impl CopyAssignableUnsafe for Counted { - unsafe fn copy_assign(this: *mut Self, o: *const Counted) -> *mut Counted { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Counted { + let o = (o.as_ptr() as *const Counted); (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_assigns_4)).prefix_inc(); return &mut (*this); } } impl MoveAssignableUnsafe for Counted { - unsafe fn move_assign(this: *mut Self, o: *mut Counted) -> *mut Counted { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Counted { + let o = (o.as_ptr() as *mut Counted); (*this).v = (*o).v; (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_5)).prefix_inc(); @@ -249,7 +253,7 @@ unsafe fn main_0() -> i32 { assert!( ((elems[(1_usize)].hist[(2) as usize]) == (5)) && (((*first).hist[(2) as usize]) == (0)) ); - object_unsafe!(moved, State, Moved(&mut t)); + object_unsafe!(moved, State, RvalueRefUnsafe::bind(&mut t)); assert!( ((moved.grid[(0) as usize][(0) as usize]) == (100)) && ((moved.grid[(1) as usize][(2) as usize]) == (5)) @@ -257,7 +261,7 @@ unsafe fn main_0() -> i32 { assert!((((moved.elems.len()) == (4_usize)) && (t.elems.is_empty())) && (t.rows.is_empty())); assert!(((moved.arr[(1_usize)]) == (7)) && ((t.arr[(1_usize)]) == (7))); let mut assigned: State = ::default(); - assign_unsafe!(assigned = Moved(moved)); + assign_unsafe!(assigned = RvalueRefUnsafe(moved)); assert!( ((assigned.grid[(0) as usize][(0) as usize]) == (100)) && ((assigned.grid[(1) as usize][(1) as usize]) == (4)) @@ -295,7 +299,7 @@ unsafe fn main_0() -> i32 { ); { for __i in 0..3 { - assign_unsafe!(ca[__i] = Moved(cb[__i])); + assign_unsafe!(ca[__i] = RvalueRefUnsafe(cb[__i])); } }; assert!( @@ -319,7 +323,7 @@ unsafe fn main_0() -> i32 { let mut vc: [Vec; 2] = std::array::from_fn::<_, 2, _>(|_| Default::default()); { for __i in 0..2 { - assign_unsafe!(vc[__i] = Moved(vb[__i])); + assign_unsafe!(vc[__i] = RvalueRefUnsafe(vb[__i])); } }; assert!(((vc[(0_usize)].len()) == (1_usize)) && (vb[(0_usize)].is_empty())); diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index 9427def813..509d44bfd8 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -107,8 +107,9 @@ impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { impl MoveConstructibleUnsafe for Moving__lambda_at_lambda_as_field_cpp_64_12__ { unsafe fn move_constructor( this: *mut Self, - o: *mut Moving__lambda_at_lambda_as_field_cpp_64_12__, + o: RvalueRefUnsafe, ) { + let o = (o.as_ptr() as *mut Moving__lambda_at_lambda_as_field_cpp_64_12__); (&raw mut (*this).f).write((*o).f.move_from()); (&raw mut (*this).moves).write((((*o).moves) + (1))); } @@ -239,7 +240,7 @@ unsafe fn main_0() -> i32 { object_unsafe!( m2, Moving__lambda_at_lambda_as_field_cpp_64_12__, - Moved(&mut m) + RvalueRefUnsafe::bind(&mut m) ); assert!(((unsafe { m2.f.call(3,) }) == (6))); assert!(((m2.moves) == (1))); diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index 9fdb98268b..122501d962 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -19,13 +19,15 @@ impl DefaultConstructibleUnsafe for Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: *const Counted) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Counted); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Counted { - unsafe fn move_constructor(this: *mut Self, o: *mut Counted) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Counted); (&raw mut (*this).copies).write((*o).copies); (&raw mut (*this).moves).write((((*o).moves) + (1))); } @@ -49,10 +51,14 @@ impl DefaultConstructibleUnsafe for Dropped { unsafe fn default_constructor(this: *mut Self) {} } impl CopyConstructibleUnsafe for Dropped { - unsafe fn copy_constructor(this: *mut Self, _a0: *const Dropped) {} + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const Dropped); + } } impl MoveConstructibleUnsafe for Dropped { - unsafe fn move_constructor(this: *mut Self, _a0: *mut Dropped) {} + unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { + let _a0 = (_a0.as_ptr() as *mut Dropped); + } } impl DestructibleUnsafe for Dropped { unsafe fn destroy(this: *mut Self) { @@ -71,7 +77,7 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &c); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&c)); __v }; }, @@ -93,12 +99,18 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &c); + CopyConstructibleUnsafe::copy_constructor( + &raw mut __v, + LvalueRefUnsafe::bind(&c), + ); __v }; }, |__return: *mut Counted| { - ConstructFromUnsafe::construct_from(__return, &c); + CopyConstructibleUnsafe::copy_constructor( + __return, + LvalueRefUnsafe::bind(&c), + ); return; } ) @@ -118,7 +130,10 @@ unsafe fn main_0() -> i32 { { let arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|__i: usize| { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &arr[(__i)]); + CopyConstructibleUnsafe::copy_constructor( + &raw mut __v, + LvalueRefUnsafe::bind(&arr[(__i)]), + ); __v }); }, diff --git a/tests/unit/out/unsafe/lambda_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index 1c66791fba..465e9ffbb8 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -21,7 +21,10 @@ impl Owner { { let self_: Owner = { let mut __v: Owner = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut (*this))); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut (*this)), + ); __v }; }, @@ -32,7 +35,8 @@ impl Owner { } } impl MoveConstructibleUnsafe for Owner { - unsafe fn move_constructor(this: *mut Self, o: *mut Owner) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Owner); (&raw mut (*this).p).write((*o).p); (*o).p = std::ptr::null_mut(); } @@ -59,7 +63,10 @@ unsafe fn main_0() -> i32 { { let h: Owner = { let mut __v: Owner = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut o)); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut o), + ); __v }; }, diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 3db77d5c8f..3c6b03cd11 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -26,13 +26,15 @@ impl Key { } } impl CopyConstructibleUnsafe for Key { - unsafe fn copy_constructor(this: *mut Self, o: *const Key) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Key); (&raw mut (*this).k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Key { - unsafe fn move_constructor(this: *mut Self, o: *mut Key) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Key); (&raw mut (*this).k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 50b537fdfa..740a9100de 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -28,13 +28,15 @@ impl DefaultConstructibleUnsafe for Item { } } impl CopyConstructibleUnsafe for Item { - unsafe fn copy_constructor(this: *mut Self, other: *const Item) { + unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const Item); (&raw mut (*this).value).write((*other).value); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)).prefix_inc(); } } impl MoveConstructibleUnsafe for Item { - unsafe fn move_constructor(this: *mut Self, other: *mut Item) { + unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut Item); (&raw mut (*this).value).write((*other).value); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); (*other).value = -1_i32; @@ -262,14 +264,16 @@ unsafe fn main_0() -> i32 { }; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) }; - let mut hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = - match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_6,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, __tmp_6); - __v - }), - }; + let mut hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { + argument_4(&mut source) + }) as *mut Item),) + { + (__tmp_6,) => items.try_emplace(key, || { + let mut __v: Item = ::zero_init(); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(__tmp_6)); + __v + }), + }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) @@ -278,14 +282,17 @@ unsafe fn main_0() -> i32 { as i32)) != 0; ok = ((ok as i32) & (((!(hit.1)) && (((*hit.0.iter_deref()).1.value) == (10))) as i32)) != 0; - let mut move_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = - match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_7,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_7)); - __v - }), - }; + let mut move_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { + argument_4(&mut source) + }) + as *mut Item),) + { + (__tmp_7,) => items.try_emplace(key, || { + let mut __v: Item = ::zero_init(); + MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(__tmp_7)); + __v + }), + }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) @@ -295,14 +302,16 @@ unsafe fn main_0() -> i32 { != 0; ok = ((ok as i32) & (((!(move_hit.1)) && ((source.value) == (20))) as i32)) != 0; key.prefix_inc(); - let mut copied: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = - match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_8,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, __tmp_8); - __v - }), - }; + let mut copied: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { + argument_4(&mut source) + }) as *mut Item),) + { + (__tmp_8,) => items.try_emplace(key, || { + let mut __v: Item = ::zero_init(); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(__tmp_8)); + __v + }), + }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (3)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) @@ -312,14 +321,16 @@ unsafe fn main_0() -> i32 { != 0; ok = ((ok as i32) & (((copied.1) && (((*copied.0.iter_deref()).1.value) == (20))) as i32)) != 0; key.prefix_inc(); - let mut moved: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = - match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_9,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_9)); - __v - }), - }; + let mut moved: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { + argument_4(&mut source) + }) as *mut Item),) + { + (__tmp_9,) => items.try_emplace(key, || { + let mut __v: Item = ::zero_init(); + MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(__tmp_9)); + __v + }), + }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) @@ -390,7 +401,10 @@ unsafe fn main_0() -> i32 { { (__tmp_12,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_12)); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(__tmp_12), + ); __v }), } @@ -413,7 +427,10 @@ unsafe fn main_0() -> i32 { { (__tmp_14,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_14)); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(__tmp_14), + ); __v }), } diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 2418d926f2..de8fccadef 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -39,7 +39,8 @@ impl Bag { } } impl CopyConstructibleUnsafe for Bag { - unsafe fn copy_constructor(this: *mut Self, o: *const Bag) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Bag); (&raw mut (*this).n).write((*o).n); (*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)).prefix_inc(); } diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index d8a0ea3fa0..dd069c5785 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -25,13 +25,15 @@ impl MoveOnly { } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, o: *mut MoveOnly) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut MoveOnly); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for MoveOnly { - unsafe fn move_assign(this: *mut Self, o: *mut MoveOnly) -> *mut MoveOnly { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut MoveOnly { + let o = (o.as_ptr() as *mut MoveOnly); if ((this) == (o)) { return &mut (*this); } @@ -79,7 +81,7 @@ impl Default for ConstMoveAssign { } pub unsafe fn make_0(__return: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(__return, Moved(&mut m)); + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -92,31 +94,31 @@ unsafe fn main_0() -> i32 { object_unsafe!(a, MoveOnly(1)); object_unsafe!(b, MoveOnly(2)); object_unsafe!(c, MoveOnly(3)); - assign_unsafe!(a = Moved(b)); + assign_unsafe!(a = RvalueRefUnsafe(b)); assert!(((a.v) == (2))); assert!(((b.v) == (0))); (unsafe { let mut _o: MoveOnly = ::zero_init(); MoveOnly::construct(&raw mut _o, 3); - assign_unsafe!(b = Moved(_o)) + assign_unsafe!(b = RvalueRefUnsafe(_o)) }); - assign_unsafe!(c = Moved((*assign_unsafe!(a = Moved(b))))); + assign_unsafe!(c = RvalueRefUnsafe((*assign_unsafe!(a = RvalueRefUnsafe(b))))); assert!((((b.v) == (0)) && ((a.v) == (0))) && ((c.v) == (3))); (unsafe { let mut _o: MoveOnly = ::zero_init(); MoveOnly::construct(&raw mut _o, 5); - assign_unsafe!(a = Moved(_o)) + assign_unsafe!(a = RvalueRefUnsafe(_o)) }); assert!(((a.v) == (5))); (unsafe { let mut _o: MoveOnly = ::zero_init(); (unsafe { make_0(&raw mut _o, 6) }); - assign_unsafe!(a = Moved(_o)) + assign_unsafe!(a = RvalueRefUnsafe(_o)) }); assert!(((a.v) == (6))); (unsafe { let _o: *mut MoveOnly = &mut a; - assign_unsafe!(a = Moved(*_o)) + assign_unsafe!(a = RvalueRefUnsafe(*_o)) }); assert!(((a.v) == (6))); let mut vec_: Vec = Vec::new(); @@ -131,7 +133,7 @@ unsafe fn main_0() -> i32 { } }; object_unsafe!(d, MoveOnly(8)); - assign_unsafe!(vec_[(0_usize)] = Moved(d)); + assign_unsafe!(vec_[(0_usize)] = RvalueRefUnsafe(d)); assert!(((vec_[(0_usize)].v) == (8))); assert!(((d.v) == (0))); object_unsafe!(m, ConstMoveAssign); diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index 314099031b..19b86d5dfd 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -20,7 +20,8 @@ impl MoveOnly { } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, o: *mut MoveOnly) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut MoveOnly); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } @@ -72,14 +73,16 @@ impl ThrowingMove { } } impl CopyConstructibleUnsafe for ThrowingMove { - unsafe fn copy_constructor(this: *mut Self, o: *const ThrowingMove) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const ThrowingMove); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for ThrowingMove { - unsafe fn move_constructor(this: *mut Self, o: *mut ThrowingMove) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut ThrowingMove); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -104,14 +107,16 @@ impl NoexceptMove { } } impl CopyConstructibleUnsafe for NoexceptMove { - unsafe fn copy_constructor(this: *mut Self, o: *const NoexceptMove) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const NoexceptMove); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((((*o).copies) + (1))); (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for NoexceptMove { - unsafe fn move_constructor(this: *mut Self, o: *mut NoexceptMove) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut NoexceptMove); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).copies).write((*o).copies); (&raw mut (*this).moves).write((((*o).moves) + (1))); @@ -123,7 +128,7 @@ pub unsafe fn by_value_0(m: *mut MoveOnly) -> i32 { } pub unsafe fn make_1(__return: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(__return, Moved(&mut m)); + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -134,13 +139,13 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(a, MoveOnly(1)); - object_unsafe!(b, MoveOnly, Moved(&mut a)); + object_unsafe!(b, MoveOnly, RvalueRefUnsafe::bind(&mut a)); assert!(((b.v) == (1))); assert!(((a.v) == (0))); - object_unsafe!(c, MoveOnly, Moved(&mut b)); + object_unsafe!(c, MoveOnly, RvalueRefUnsafe::bind(&mut b)); assert!(((c.v) == (1))); assert!(((b.v) == (0))); - object_unsafe!(d, MoveOnly, Moved(&mut c)); + object_unsafe!(d, MoveOnly, RvalueRefUnsafe::bind(&mut c)); assert!(((d.v) == (1))); assert!(((c.v) == (0))); object_unsafe!(e, MoveOnly, |e| (unsafe { make_1(e, 5,) })); @@ -155,7 +160,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _m: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut _m, Moved(&mut e)); + MoveConstructibleUnsafe::move_constructor(&raw mut _m, RvalueRefUnsafe::bind(&mut e)); by_value_0(&mut _m) }) == (5)) ); @@ -182,19 +187,19 @@ unsafe fn main_0() -> i32 { assert!(((m1.mark) == (1))); assert!(((m2.mark) == (10))); object_unsafe!(t, ThrowingMove(1)); - object_unsafe!(t1, ThrowingMove, &t); + object_unsafe!(t1, ThrowingMove, LvalueRefUnsafe::bind(&t)); assert!(((t1.v) == (1))); assert!(((t1.copies) == (1))); assert!(((t1.moves) == (0))); assert!(((t.v) == (1))); object_unsafe!(n, NoexceptMove(2)); - object_unsafe!(n1, NoexceptMove, Moved(&mut n)); + object_unsafe!(n1, NoexceptMove, RvalueRefUnsafe::bind(&mut n)); assert!(((n1.v) == (2))); assert!(((n1.copies) == (0))); assert!(((n1.moves) == (1))); assert!(((n.v) == (0))); object_unsafe!(g, MoveOnly(3)); - object_unsafe!(g1, MoveOnly, Moved(&mut g)); + object_unsafe!(g1, MoveOnly, RvalueRefUnsafe::bind(&mut g)); assert!(((g1.v) == (3))); assert!(((g.v) == (0))); let mut nv: Vec = Vec::new(); diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index 65caaec186..ef8486e171 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -27,11 +27,11 @@ impl Chain { return &mut (*this); } pub unsafe fn take(this: *mut Self, __return: *mut Chain) { - ConstructFromUnsafe::construct_from(__return, Moved(&mut (*this))); + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut (*this))); return; } pub unsafe fn copy(this: *const Self, __return: *mut Chain) { - ConstructFromUnsafe::construct_from(__return, &(*this)); + CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(&(*this))); return; } pub unsafe fn self_(this: *mut Self) -> *mut Chain { @@ -39,12 +39,14 @@ impl Chain { } } impl CopyConstructibleUnsafe for Chain { - unsafe fn copy_constructor(this: *mut Self, o: *const Chain) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Chain); (&raw mut (*this).v).write((((*o).v) + (100))); } } impl MoveConstructibleUnsafe for Chain { - unsafe fn move_constructor(this: *mut Self, o: *mut Chain) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Chain); (&raw mut (*this).v).write((((*o).v) + (1))); (*o).v = 0; } @@ -66,7 +68,9 @@ unsafe fn main_0() -> i32 { object_unsafe!( b, Chain, - Moved((unsafe { Chain::add_5(&mut (*(unsafe { Chain::add_5(&raw mut b0, 1,) })), 1,) })) + RvalueRefUnsafe::bind( + (unsafe { Chain::add_5(&mut (*(unsafe { Chain::add_5(&raw mut b0, 1,) })), 1,) }) + ) ); assert!(((b.v) == (8)) && ((b0.v) == (0))); object_unsafe!(c, Chain, |c| { @@ -88,9 +92,9 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _c: Chain = ::zero_init(); - ConstructFromUnsafe::construct_from( + MoveConstructibleUnsafe::move_constructor( &raw mut _c, - Moved((unsafe { Chain::self_(&raw mut g) })), + RvalueRefUnsafe::bind((unsafe { Chain::self_(&raw mut g) })), ); consume_0(&mut _c) }) == (21)) diff --git a/tests/unit/out/unsafe/rule_of_five.rs b/tests/unit/out/unsafe/rule_of_five.rs index 118d336ff1..22858790f7 100644 --- a/tests/unit/out/unsafe/rule_of_five.rs +++ b/tests/unit/out/unsafe/rule_of_five.rs @@ -40,7 +40,8 @@ impl DestructibleUnsafe for Buffer { } } impl CopyConstructibleUnsafe for Buffer { - unsafe fn copy_constructor(this: *mut Self, o: *const Buffer) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Buffer); (&raw mut (*this).data).write([0_i32; 4]); (&raw mut (*this).size).write((*o).size); { @@ -57,7 +58,8 @@ impl CopyConstructibleUnsafe for Buffer { } } impl MoveConstructibleUnsafe for Buffer { - unsafe fn move_constructor(this: *mut Self, o: *mut Buffer) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Buffer); (&raw mut (*this).data).write([0_i32; 4]); (&raw mut (*this).size).write((*o).size); { @@ -76,7 +78,8 @@ impl MoveConstructibleUnsafe for Buffer { } } impl CopyAssignableUnsafe for Buffer { - unsafe fn copy_assign(this: *mut Self, o: *const Buffer) -> *mut Buffer { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Buffer { + let o = (o.as_ptr() as *const Buffer); if (((this).cast_const()) == (o)) { return &mut (*this); } @@ -95,7 +98,8 @@ impl CopyAssignableUnsafe for Buffer { } } impl MoveAssignableUnsafe for Buffer { - unsafe fn move_assign(this: *mut Self, o: *mut Buffer) -> *mut Buffer { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Buffer { + let o = (o.as_ptr() as *mut Buffer); if ((this) == (o)) { return &mut (*this); } @@ -117,7 +121,7 @@ impl MoveAssignableUnsafe for Buffer { } pub unsafe fn make_3(__return: *mut Buffer, mut size: i32) { object_unsafe!(b, Buffer(size)); - ConstructFromUnsafe::construct_from(__return, Moved(&mut b)); + MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut b)); return; } pub fn main() { @@ -129,7 +133,7 @@ pub fn main() { unsafe fn main_0() -> i32 { { object_unsafe!(a, Buffer(4)); - object_unsafe!(b, Buffer, &a); + object_unsafe!(b, Buffer, LvalueRefUnsafe::bind(&a)); assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (1))) @@ -137,7 +141,7 @@ unsafe fn main_0() -> i32 { ); b.data[(0) as usize] = 100; assert!(((a.data[(0) as usize]) == (0))); - object_unsafe!(c, Buffer, Moved(&mut a)); + object_unsafe!(c, Buffer, RvalueRefUnsafe::bind(&mut a)); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (3)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (1)) @@ -153,14 +157,14 @@ unsafe fn main_0() -> i32 { (((d.size) == (4)) && ((d.data[(0) as usize]) == (100))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (2)) ); - assign_unsafe!(d = Moved(c)); + assign_unsafe!(d = RvalueRefUnsafe(c)); assert!( (((d.data[(0) as usize]) == (0)) && ((c.size) == (0))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (3)) ); (unsafe { let _o: *mut Buffer = &mut d; - assign_unsafe!(d = Moved(*_o)) + assign_unsafe!(d = RvalueRefUnsafe(*_o)) }); assert!( ((d.size) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (3)) diff --git a/tests/unit/out/unsafe/rule_of_three.rs b/tests/unit/out/unsafe/rule_of_three.rs index b616469915..2f80927abb 100644 --- a/tests/unit/out/unsafe/rule_of_three.rs +++ b/tests/unit/out/unsafe/rule_of_three.rs @@ -45,7 +45,8 @@ impl DestructibleUnsafe for Buffer { } } impl CopyConstructibleUnsafe for Buffer { - unsafe fn copy_constructor(this: *mut Self, o: *const Buffer) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Buffer); (&raw mut (*this).data).write([0_i32; 4]); (&raw mut (*this).size).write((*o).size); { @@ -62,7 +63,8 @@ impl CopyConstructibleUnsafe for Buffer { } } impl CopyAssignableUnsafe for Buffer { - unsafe fn copy_assign(this: *mut Self, o: *const Buffer) -> *mut Buffer { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Buffer { + let o = (o.as_ptr() as *const Buffer); if (((this).cast_const()) == (o)) { return &mut (*this); } @@ -102,7 +104,7 @@ pub fn main() { unsafe fn main_0() -> i32 { { object_unsafe!(a, Buffer(4)); - object_unsafe!(b, Buffer, &a); + object_unsafe!(b, Buffer, LvalueRefUnsafe::bind(&a)); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (1)) @@ -123,7 +125,7 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (2))); assert!(((unsafe { sum_2(&a,) }) == (6))); assert!(((unsafe { sum_2(&b,) }) == (106))); - object_unsafe!(d, Buffer, &a); + object_unsafe!(d, Buffer, LvalueRefUnsafe::bind(&a)); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (3)) diff --git a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs index eadfe793de..26d09160bc 100644 --- a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs +++ b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs @@ -29,13 +29,15 @@ impl Elem { } } impl CopyConstructibleUnsafe for Elem { - unsafe fn copy_constructor(this: *mut Self, o: *const Elem) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Elem); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Elem { - unsafe fn move_constructor(this: *mut Self, o: *mut Elem) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Elem); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); } diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index 3ec644d0cc..3ade8dfdc2 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -26,25 +26,29 @@ impl DefaultConstructibleUnsafe for Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); } } impl CopyAssignableUnsafe for Tracked { - unsafe fn copy_assign(this: *mut Self, o: *const Tracked) -> *mut Tracked { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Tracked { + let o = (o.as_ptr() as *const Tracked); (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*this); } } impl MoveAssignableUnsafe for Tracked { - unsafe fn move_assign(this: *mut Self, o: *mut Tracked) -> *mut Tracked { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Tracked { + let o = (o.as_ptr() as *mut Tracked); (*this).v = (*o).v; return &mut (*this); } diff --git a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs index 68b884c264..e56c7afd7e 100644 --- a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs @@ -30,7 +30,8 @@ impl Counted { } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, other: *const Counted) { + unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const Counted); (&raw mut (*this).x).write((((*other).x) * (2))); (&raw mut (*this).y).write((((*other).y) * (2))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); @@ -50,7 +51,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(s, Counted(1, 2)); let mut __decomp_2: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &s); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&s)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); diff --git a/tests/unit/out/unsafe/structured_binding_element_ctor.rs b/tests/unit/out/unsafe/structured_binding_element_ctor.rs index 6340174390..5a8348d585 100644 --- a/tests/unit/out/unsafe/structured_binding_element_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_element_ctor.rs @@ -22,13 +22,15 @@ impl Elem { } } impl CopyConstructibleUnsafe for Elem { - unsafe fn copy_constructor(this: *mut Self, other: *const Elem) { + unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const Elem); (&raw mut (*this).v).write((((*other).v) + (100))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Elem { - unsafe fn move_constructor(this: *mut Self, other: *mut Elem) { + unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut Elem); (&raw mut (*this).v).write((((*other).v) + (1000))); (*other).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); @@ -81,7 +83,7 @@ unsafe fn main_0() -> i32 { let mut base_moves: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)); let mut __decomp_3: Two = { let mut __v: Two = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, &t); + CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&t)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((base_copies) + (2)))); @@ -95,7 +97,7 @@ unsafe fn main_0() -> i32 { assert!(((t.a.v) == (50))); let mut __decomp_5: Two = { let mut __v: Two = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut t)); + MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(&mut t)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == ((base_moves) + (2)))); @@ -118,7 +120,10 @@ unsafe fn main_0() -> i32 { Elem::construct(&raw mut __tmp_0, 7); { let mut __v: Elem = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut __tmp_0)); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut __tmp_0), + ); __v } }, @@ -127,7 +132,10 @@ unsafe fn main_0() -> i32 { Elem::construct(&raw mut __tmp_1, 8); { let mut __v: Elem = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut __tmp_1)); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut __tmp_1), + ); __v } }, diff --git a/tests/unit/out/unsafe/structured_binding_move_ctor.rs b/tests/unit/out/unsafe/structured_binding_move_ctor.rs index 97dd30545a..1d18fde0d8 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -21,14 +21,16 @@ impl Movable { } } impl CopyConstructibleUnsafe for Movable { - unsafe fn copy_constructor(this: *mut Self, other: *const Movable) { + unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + let other = (other.as_ptr() as *const Movable); (&raw mut (*this).x).write((*other).x); (&raw mut (*this).y).write((*other).y); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Movable { - unsafe fn move_constructor(this: *mut Self, other: *mut Movable) { + unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + let other = (other.as_ptr() as *mut Movable); (&raw mut (*this).x).write((*other).x); (&raw mut (*this).y).write((*other).y); (*other).x = 0; @@ -78,7 +80,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(m, Movable(3, 4)); let mut __decomp_2: Movable = { let mut __v: Movable = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut m)); + MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(&mut m)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (1))); diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index 492d0473ee..d802de8c86 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -26,25 +26,29 @@ impl DefaultConstructibleUnsafe for Tracked { } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Tracked); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); } } impl CopyAssignableUnsafe for Tracked { - unsafe fn copy_assign(this: *mut Self, o: *const Tracked) -> *mut Tracked { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Tracked { + let o = (o.as_ptr() as *const Tracked); (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*this); } } impl MoveAssignableUnsafe for Tracked { - unsafe fn move_assign(this: *mut Self, o: *mut Tracked) -> *mut Tracked { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Tracked { + let o = (o.as_ptr() as *mut Tracked); (*this).v = (*o).v; return &mut (*this); } @@ -132,7 +136,8 @@ impl CopyOnly { } } impl CopyConstructibleUnsafe for CopyOnly { - unsafe fn copy_constructor(this: *mut Self, o: *const CopyOnly) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const CopyOnly); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)).prefix_inc(); } @@ -143,7 +148,8 @@ impl DestructibleUnsafe for CopyOnly { } } impl CopyAssignableUnsafe for CopyOnly { - unsafe fn copy_assign(this: *mut Self, o: *const CopyOnly) -> *mut CopyOnly { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut CopyOnly { + let o = (o.as_ptr() as *const CopyOnly); (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)).prefix_inc(); return &mut (*this); @@ -181,27 +187,31 @@ impl Moved { } } impl CopyConstructibleUnsafe for Moved { - unsafe fn copy_constructor(this: *mut Self, o: *const Moved) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Moved); (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Moved { - unsafe fn move_constructor(this: *mut Self, o: *mut Moved) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Moved); (&raw mut (*this).v).write((*o).v); (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); } } impl CopyAssignableUnsafe for Moved { - unsafe fn copy_assign(this: *mut Self, o: *const Moved) -> *mut Moved { + unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Moved { + let o = (o.as_ptr() as *const Moved); (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); return &mut (*this); } } impl MoveAssignableUnsafe for Moved { - unsafe fn move_assign(this: *mut Self, o: *mut Moved) -> *mut Moved { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Moved { + let o = (o.as_ptr() as *mut Moved); (*this).v = (*o).v; (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)).prefix_inc(); @@ -289,7 +299,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -306,7 +316,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -324,7 +334,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -598,7 +608,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; @@ -615,7 +625,7 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || ::default(), )) - }) = Moved(_o) + }) = RvalueRefUnsafe(_o) ) }) }; diff --git a/tests/unit/out/unsafe/vector2.rs b/tests/unit/out/unsafe/vector2.rs index 69dde434ba..723493103b 100644 --- a/tests/unit/out/unsafe/vector2.rs +++ b/tests/unit/out/unsafe/vector2.rs @@ -34,7 +34,7 @@ pub unsafe fn fn_0(v: *mut Vec, mut v3: Vec) { (v) }))[(0_usize)] = 7; { - AssignFromUnsafe::assign_from(&raw mut v2, v); + CopyAssignableUnsafe::copy_assign(&raw mut v2, LvalueRefUnsafe::bind(v)); }; (&mut (*v4))[(1_usize)] = 13; assert!(((x) == (6))); From bb9ab2e9cd6a7c98cf8bdcac342b73bb69cb9d4e Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 19:43:35 +0000 Subject: [PATCH 11/11] Update tests --- .../unit/out/refcount/copy_move_defaulted.rs | 108 +++++++++------- tests/unit/out/refcount/size_t_ssize_t.rs | 8 +- tests/unit/out/unsafe/copy_move_defaulted.rs | 117 +++++++++++------- tests/unit/out/unsafe/size_t_ssize_t.rs | 2 +- 4 files changed, 147 insertions(+), 88 deletions(-) diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index 8b1aef8ecd..5c66db8525 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -122,13 +122,15 @@ impl DefaultCopyUserMove { } } impl MoveConstructible for DefaultCopyUserMove { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for DefaultCopyUserMove { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); return (this).clone(); @@ -158,12 +160,17 @@ impl UserCopyDefaultMove { } } impl CopyConstructible for UserCopyDefaultMove { - fn copy_constructor(this: Ptr, o: Ptr) { + fn copy_constructor(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); } } impl CopyAssignable for UserCopyDefaultMove { - fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + fn copy_assign( + this: Ptr, + o: LvalueRef>, + ) -> Ptr { + let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); return (this).clone(); } @@ -325,13 +332,15 @@ pub struct SeesThis { pub self_: Ptr, } impl CopyAssignable for SeesThis { - fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _a0: LvalueRef>) -> Ptr { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); return (this).clone(); } } impl MoveAssignable for SeesThis { - fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn move_assign(this: Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); return (this).clone(); } @@ -382,13 +391,15 @@ impl DefaultConstructible for Counted_int_ { } } impl MoveConstructible for Counted_int_ { - fn move_constructor(this: Ptr, o: Ptr) { + fn move_constructor(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); } } impl MoveAssignable for Counted_int_ { - fn move_assign(this: Ptr, o: Ptr) -> Ptr { + fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(this, moves).write((o.with(|__s| __s.moves) + 1)); return (this).clone(); @@ -441,24 +452,28 @@ impl DefaultConstructible for CtorSeesThis { } } impl CopyConstructible for CtorSeesThis { - fn copy_constructor(this: Ptr, _a0: Ptr) { + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); field!(this, id).write(0); } } impl MoveConstructible for CtorSeesThis { - fn move_constructor(this: Ptr, _a0: Ptr) { + fn move_constructor(this: Ptr, _a0: RvalueRef) { + let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); field!(this, id).write(0); } } impl CopyAssignable for CtorSeesThis { - fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _a0: LvalueRef>) -> Ptr { + let _a0 = _a0.as_pointer(); return (this).clone(); } } impl MoveAssignable for CtorSeesThis { - fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn move_assign(this: Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); return (this).clone(); } } @@ -548,8 +563,12 @@ impl OutOfLineDefaulted { } } impl CopyConstructible for OutOfLineDefaulted { - fn copy_constructor(this: Ptr, _a0: Ptr) { - ConstructFrom::construct_from(field_ptr!(this, x), field_ptr!(_a0, x)); + fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + let _a0 = _a0.as_pointer(); + CopyConstructible::copy_constructor( + field_ptr!(this, x), + LvalueRef::bind(field_ptr!(_a0, x)), + ); field!(this, v).write(_a0.with(|__s| __s.v)); } } @@ -604,7 +623,11 @@ impl Default for OutOfLineAssign { } } impl CopyAssignable for OutOfLineAssign { - fn copy_assign(this: Ptr, _a0: Ptr) -> Ptr { + fn copy_assign( + this: Ptr, + _a0: LvalueRef>, + ) -> Ptr { + let _a0 = _a0.as_pointer(); assign!(*field_ptr!(this, s) = *field_ptr!(_a0, s)); field!(this, v).write(_a0.with(|__s| __s.v)); match (field_ref!(_a0, w).as_pointer(),) { @@ -616,8 +639,9 @@ impl CopyAssignable for OutOfLineAssign { } } impl MoveAssignable for OutOfLineAssign { - fn move_assign(this: Ptr, _a0: Ptr) -> Ptr { - assign!(*field_ptr!(this, s) = Moved(*field_ptr!(_a0, s))); + fn move_assign(this: Ptr, _a0: RvalueRef) -> Ptr { + let _a0 = _a0.as_pointer(); + assign!(*field_ptr!(this, s) = RvalueRef(*field_ptr!(_a0, s))); field!(this, v).write({ (*_a0.upgrade().deref()).v }); field!(this, w).with_mut(|__b0| { (*__b0) = field!(_a0, w).with_mut(std::mem::take); @@ -648,7 +672,7 @@ fn main_0() -> i32 { object!(e, Explicit(2)); object!(f, Explicit(3)); assign!(e = b); - assign!(f = Moved(c)); + assign!(f = RvalueRef(c)); assert!( ({ same_0(e.as_pointer(), b.as_pointer(),) }) && ({ same_0(f.as_pointer(), c.as_pointer(),) }) @@ -689,20 +713,20 @@ fn main_0() -> i32 { assert!(({ (*vec_.borrow())[0_usize].v } == 1) && ({ (*vec_.borrow())[1_usize].v } == 9)); object!(m, DefaultCopyUserMove(7)); let m1: Value = Rc::new(RefCell::new((*m.borrow()))); - object!(m2, DefaultCopyUserMove, Moved(m.as_pointer())); + object!(m2, DefaultCopyUserMove, RvalueRef::bind(m.as_pointer())); assert!( (({ (*m1.borrow()).v } == 7) && ({ (*m2.borrow()).v } == 7)) && ({ (*m.borrow()).v } == 0) ); object!(m3, DefaultCopyUserMove(1)); object!(m4, DefaultCopyUserMove(1)); assign!(m3 = m1); - assign!(m4 = Moved(m1)); + assign!(m4 = RvalueRef(m1)); assert!( (({ (*m3.borrow()).v } == 7) && ({ (*m4.borrow()).v } == 7)) && ({ (*m1.borrow()).v } == 0) ); object!(u, UserCopyDefaultMove(8)); - object!(u1, UserCopyDefaultMove, u.as_pointer()); - object!(u2, UserCopyDefaultMove, Moved(u.as_pointer())); + object!(u1, UserCopyDefaultMove, LvalueRef::bind(u.as_pointer())); + object!(u2, UserCopyDefaultMove, RvalueRef::bind(u.as_pointer())); assert!( (({ (*u1.borrow()).v } == 108) && ({ (*u2.borrow()).v } == 8)) && ({ (*u.borrow()).v } == 8) @@ -710,10 +734,10 @@ fn main_0() -> i32 { object!(u3, UserCopyDefaultMove(1)); object!(u4, UserCopyDefaultMove(1)); assign!(u3 = u2); - assign!(u4 = Moved(u2)); + assign!(u4 = RvalueRef(u2)); assert!(({ (*u3.borrow()).v } == 108) && ({ (*u4.borrow()).v } == 8)); object!(p, Buffer(3)); - object!(q, Buffer, Moved(p.as_pointer())); + object!(q, Buffer, RvalueRef::bind(p.as_pointer())); assert!( ({ ((({ (*q.borrow()).n } == 3) && ((*q.borrow()).data.len() == 3_usize)) @@ -722,7 +746,7 @@ fn main_0() -> i32 { }) ); object!(r, Buffer(1)); - assign!(r = Moved(q)); + assign!(r = RvalueRef(q)); assert!( ({ ((({ (*r.borrow()).n } == 3) && ((*r.borrow()).data.len() == 3_usize)) @@ -749,9 +773,9 @@ fn main_0() -> i32 { let mut __tmp_2 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from( + MoveConstructible::move_constructor( __v.as_pointer(), - Moved(bufs.decay().offset(0_usize)), + RvalueRef::bind(bufs.decay().offset(0_usize)), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -777,7 +801,7 @@ fn main_0() -> i32 { array_elem!(o1.as_pointer(), arr, 0).write(5); array_elem!(o1.as_pointer(), arr, 1).write(6); field_ptr!(o1.as_pointer(), p).write(Ptr::alloc(7).to_owned_opt()); - object!(o2, Owner, Moved(o1.as_pointer())); + object!(o2, Owner, RvalueRef::bind(o1.as_pointer())); assert!( ({ ((({ (*o2.borrow()).n } == 5) && ((*o2.borrow()).data.len() == 1_usize)) @@ -792,7 +816,7 @@ fn main_0() -> i32 { }) ); object!(o3, Owner); - assign!(o3 = Moved(o2)); + assign!(o3 = RvalueRef(o2)); assert!( ((({ (*o3.borrow()).n } == 5) && ((vec_elem!(o3.as_pointer(), data, 0_usize).read()) == 5)) @@ -809,11 +833,11 @@ fn main_0() -> i32 { data: Vec::from([1, 2]), })); let mut c2: Copyable = (*c1.borrow()).clone(); - object!(c3, Copyable, Moved(c1.as_pointer())); + object!(c3, Copyable, RvalueRef::bind(c1.as_pointer())); assert!(({ (c2.data.len() == 2_usize) && ((*c3.borrow()).data.len() == 2_usize) })); assert!(({ (*c1.borrow()).data.is_empty() })); object!(c4, Copyable); - assign!(c4 = Moved(c3)); + assign!(c4 = RvalueRef(c3)); assert!( ({ ((vec_elem!(c4.as_pointer(), data, 1_usize).read()) == 2) @@ -822,14 +846,14 @@ fn main_0() -> i32 { ); object!(h1, Holder(4)); field_ptr!(h1.as_pointer(), p).write(Ptr::alloc(9).to_owned_opt()); - object!(h2, Holder, Moved(h1.as_pointer())); + object!(h2, Holder, RvalueRef::bind(h1.as_pointer())); assert!( ((({ (*h2.borrow()).inner.x } == 4) && ({ (*h2.borrow()).e.v } == 4)) && (({ (*h2.borrow()).p.clone() }.as_pointer().read()) == 9)) && (({ (*h1.borrow()).p.clone() }.as_pointer()).is_null()) ); object!(h3, Holder(1)); - assign!(h3 = Moved(h2)); + assign!(h3 = RvalueRef(h2)); assert!( ((({ (*h3.borrow()).inner.x } == 4) && ((array_elem!(field_ptr!(h3.as_pointer(), e), arr, 1).read()) == 5)) @@ -839,20 +863,20 @@ fn main_0() -> i32 { object!(t1, HasSeesThis); object!(t2, HasSeesThis); object!(t3, HasSeesThis); - assign!(t2 = Moved(t1)); + assign!(t2 = RvalueRef(t1)); assert!(({ { (*t2.borrow()).s.self_.clone() } } == { (field_ptr!(t2.as_pointer(), s)) })); assign!(t3 = t2); assert!(({ { (*t3.borrow()).s.self_.clone() } } == { (field_ptr!(t3.as_pointer(), s)) })); object!(k1, HasCounted); - object!(k2, HasCounted, Moved(k1.as_pointer())); + object!(k2, HasCounted, RvalueRef::bind(k1.as_pointer())); assert!(({ (*k2.borrow()).c.moves } == 1)); object!(k3, HasCounted); - assign!(k3 = Moved(k2)); + assign!(k3 = RvalueRef(k2)); assert!(({ (*k3.borrow()).c.moves } == 2)); { object!(d, CtorSeesThis); assert!(({ { (*d.borrow()).self_.clone() } } == { (d.as_pointer()) })); - object!(e, CtorSeesThis, d.as_pointer()); + object!(e, CtorSeesThis, LvalueRef::bind(d.as_pointer())); assert!(({ { (*e.borrow()).self_.clone() } } == { (e.as_pointer()) })); object!(f, CtorSeesThis::construct_1(3)); assert!( @@ -861,11 +885,11 @@ fn main_0() -> i32 { ); object!(h1, HasCtorSeesThis); assert!(({ { (*h1.borrow()).x.self_.clone() } } == { (field_ptr!(h1.as_pointer(), x)) })); - object!(h2, HasCtorSeesThis, h1.as_pointer()); + object!(h2, HasCtorSeesThis, LvalueRef::bind(h1.as_pointer())); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); - object!(h3, HasCtorSeesThis, Moved(h1.as_pointer())); + object!(h3, HasCtorSeesThis, RvalueRef::bind(h1.as_pointer())); assert!(({ { (*h3.borrow()).x.self_.clone() } } == { (field_ptr!(h3.as_pointer(), x)) })); - assign!(h2 = Moved(h3)); + assign!(h2 = RvalueRef(h3)); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); assign!(h2 = h1); assert!(({ { (*h2.borrow()).x.self_.clone() } } == { (field_ptr!(h2.as_pointer(), x)) })); @@ -893,7 +917,7 @@ fn main_0() -> i32 { && ({ { (*o1.borrow()).x.self_.clone() } } == { (field_ptr!(o1.as_pointer(), x)) }) ); (*o1.borrow_mut()).v = 2; - object!(o2, OutOfLineDefaulted, o1.as_pointer()); + object!(o2, OutOfLineDefaulted, LvalueRef::bind(o1.as_pointer())); assert!( ({ (*o2.borrow()).v } == 2) && ({ { (*o2.borrow()).x.self_.clone() } } == { (field_ptr!(o2.as_pointer(), x)) }) @@ -917,7 +941,7 @@ fn main_0() -> i32 { }) ); assert!(({ { (*a2.borrow()).s.self_.clone() } } == { (field_ptr!(a2.as_pointer(), s)) })); - assign!(a3 = Moved(a2)); + assign!(a3 = RvalueRef(a2)); assert!( ({ (({ (*a3.borrow()).v } == 3) && ((*a3.borrow()).w.len() == 1_usize)) diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 350bcdccec..be6b1f2537 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -63,14 +63,16 @@ pub fn size_t_in_rules_3() { Rc::new(RefCell::new((0..3).map(|_| ::zero_init()).collect())); let __p: Ptr = __v.decay(); for __i in 0..3 { - __p.offset(__i) - .construct_from(Moved(ar2.decay().offset(__i))); + MoveConstructible::move_constructor( + __p.offset(__i), + RvalueRef::bind(ar2.decay().offset(__i)), + ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); { for __i in 0..3 { - assign!(*ar3.as_pointer().decay().offset(__i) = Moved(*ar.decay().offset(__i))); + assign!(*ar3.as_pointer().decay().offset(__i) = RvalueRef(*ar.decay().offset(__i))); } ar3.as_pointer() }; diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index ece42c2a54..7dabf54a1b 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -91,7 +91,8 @@ impl DefaultCopyUserMove { } } impl MoveConstructibleUnsafe for DefaultCopyUserMove { - unsafe fn move_constructor(this: *mut Self, o: *mut DefaultCopyUserMove) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut DefaultCopyUserMove); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } @@ -99,8 +100,9 @@ impl MoveConstructibleUnsafe for DefaultCopyUserMove { impl MoveAssignableUnsafe for DefaultCopyUserMove { unsafe fn move_assign( this: *mut Self, - o: *mut DefaultCopyUserMove, + o: RvalueRefUnsafe, ) -> *mut DefaultCopyUserMove { + let o = (o.as_ptr() as *mut DefaultCopyUserMove); (*this).v = (*o).v; (*o).v = 0; return &mut (*this); @@ -127,15 +129,17 @@ impl UserCopyDefaultMove { } } impl CopyConstructibleUnsafe for UserCopyDefaultMove { - unsafe fn copy_constructor(this: *mut Self, o: *const UserCopyDefaultMove) { + unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const UserCopyDefaultMove); (&raw mut (*this).v).write((((*o).v) + (100))); } } impl CopyAssignableUnsafe for UserCopyDefaultMove { unsafe fn copy_assign( this: *mut Self, - o: *const UserCopyDefaultMove, + o: LvalueRefUnsafe>, ) -> *mut UserCopyDefaultMove { + let o = (o.as_ptr() as *const UserCopyDefaultMove); (*this).v = (((*o).v) + (100)); return &mut (*this); } @@ -249,13 +253,15 @@ pub struct SeesThis { pub self_: *mut SeesThis, } impl CopyAssignableUnsafe for SeesThis { - unsafe fn copy_assign(this: *mut Self, _a0: *const SeesThis) -> *mut SeesThis { + unsafe fn copy_assign(this: *mut Self, _a0: LvalueRefUnsafe>) -> *mut SeesThis { + let _a0 = (_a0.as_ptr() as *const SeesThis); (*this).self_ = this; return &mut (*this); } } impl MoveAssignableUnsafe for SeesThis { - unsafe fn move_assign(this: *mut Self, _a0: *mut SeesThis) -> *mut SeesThis { + unsafe fn move_assign(this: *mut Self, _a0: RvalueRefUnsafe) -> *mut SeesThis { + let _a0 = (_a0.as_ptr() as *mut SeesThis); (*this).self_ = this; return &mut (*this); } @@ -300,13 +306,15 @@ impl DefaultConstructibleUnsafe for Counted_int_ { } } impl MoveConstructibleUnsafe for Counted_int_ { - unsafe fn move_constructor(this: *mut Self, o: *mut Counted_int_) { + unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Counted_int_); (&raw mut (*this).v).write((*o).v); (&raw mut (*this).moves).write((((*o).moves) + (1))); } } impl MoveAssignableUnsafe for Counted_int_ { - unsafe fn move_assign(this: *mut Self, o: *mut Counted_int_) -> *mut Counted_int_ { + unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Counted_int_ { + let o = (o.as_ptr() as *mut Counted_int_); (*this).v = (*o).v; (*this).moves = (((*o).moves) + (1)); return &mut (*this); @@ -359,24 +367,34 @@ impl DefaultConstructibleUnsafe for CtorSeesThis { } } impl CopyConstructibleUnsafe for CtorSeesThis { - unsafe fn copy_constructor(this: *mut Self, _a0: *const CtorSeesThis) { + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const CtorSeesThis); (&raw mut (*this).self_).write(this); (&raw mut (*this).id).write(0); } } impl MoveConstructibleUnsafe for CtorSeesThis { - unsafe fn move_constructor(this: *mut Self, _a0: *mut CtorSeesThis) { + unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { + let _a0 = (_a0.as_ptr() as *mut CtorSeesThis); (&raw mut (*this).self_).write(this); (&raw mut (*this).id).write(0); } } impl CopyAssignableUnsafe for CtorSeesThis { - unsafe fn copy_assign(this: *mut Self, _a0: *const CtorSeesThis) -> *mut CtorSeesThis { + unsafe fn copy_assign( + this: *mut Self, + _a0: LvalueRefUnsafe>, + ) -> *mut CtorSeesThis { + let _a0 = (_a0.as_ptr() as *const CtorSeesThis); return &mut (*this); } } impl MoveAssignableUnsafe for CtorSeesThis { - unsafe fn move_assign(this: *mut Self, _a0: *mut CtorSeesThis) -> *mut CtorSeesThis { + unsafe fn move_assign( + this: *mut Self, + _a0: RvalueRefUnsafe, + ) -> *mut CtorSeesThis { + let _a0 = (_a0.as_ptr() as *mut CtorSeesThis); return &mut (*this); } } @@ -459,8 +477,12 @@ impl OutOfLineDefaulted { } } impl CopyConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn copy_constructor(this: *mut Self, _a0: *const OutOfLineDefaulted) { - ConstructFromUnsafe::construct_from(&raw mut (*this).x, &(*_a0).x); + unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + let _a0 = (_a0.as_ptr() as *const OutOfLineDefaulted); + CopyConstructibleUnsafe::copy_constructor( + &raw mut (*this).x, + LvalueRefUnsafe::bind(&(*_a0).x), + ); (&raw mut (*this).v).write((*_a0).v); } } @@ -509,23 +531,31 @@ impl Default for OutOfLineAssign { } } impl CopyAssignableUnsafe for OutOfLineAssign { - unsafe fn copy_assign(this: *mut Self, _a0: *const OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn copy_assign( + this: *mut Self, + _a0: LvalueRefUnsafe>, + ) -> *mut OutOfLineAssign { + let _a0 = (_a0.as_ptr() as *const OutOfLineAssign); (unsafe { let _arg0: *const SeesThis = &(*_a0).s; assign_unsafe!((*this).s = *_arg0) }); (*this).v = (*_a0).v; { - AssignFromUnsafe::assign_from(&raw mut (*this).w, &(*_a0).w); + CopyAssignableUnsafe::copy_assign(&raw mut (*this).w, LvalueRefUnsafe::bind(&(*_a0).w)); }; return &mut (*this); } } impl MoveAssignableUnsafe for OutOfLineAssign { - unsafe fn move_assign(this: *mut Self, _a0: *mut OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn move_assign( + this: *mut Self, + _a0: RvalueRefUnsafe, + ) -> *mut OutOfLineAssign { + let _a0 = (_a0.as_ptr() as *mut OutOfLineAssign); (unsafe { let _arg0: *mut SeesThis = &mut (*_a0).s; - assign_unsafe!((*this).s = Moved(*_arg0)) + assign_unsafe!((*this).s = RvalueRefUnsafe(*_arg0)) }); (*this).v = (*_a0).v; { @@ -561,7 +591,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(e, Explicit(2)); object_unsafe!(f, Explicit(3)); assign_unsafe!(e = b); - assign_unsafe!(f = Moved(c)); + assign_unsafe!(f = RvalueRefUnsafe(c)); assert!((unsafe { same_0(&e, &b,) }) && (unsafe { same_0(&f, &c,) })); object_unsafe!(g, Explicit(4)); assign_unsafe!(g = (*assign_unsafe!(e = f))); @@ -595,30 +625,30 @@ unsafe fn main_0() -> i32 { assert!(((vec_[(0_usize)].v) == (1)) && ((vec_[(1_usize)].v) == (9))); object_unsafe!(m, DefaultCopyUserMove(7)); let mut m1: DefaultCopyUserMove = m; - object_unsafe!(m2, DefaultCopyUserMove, Moved(&mut m)); + object_unsafe!(m2, DefaultCopyUserMove, RvalueRefUnsafe::bind(&mut m)); assert!((((m1.v) == (7)) && ((m2.v) == (7))) && ((m.v) == (0))); object_unsafe!(m3, DefaultCopyUserMove(1)); object_unsafe!(m4, DefaultCopyUserMove(1)); assign_unsafe!(m3 = m1); - assign_unsafe!(m4 = Moved(m1)); + assign_unsafe!(m4 = RvalueRefUnsafe(m1)); assert!((((m3.v) == (7)) && ((m4.v) == (7))) && ((m1.v) == (0))); object_unsafe!(u, UserCopyDefaultMove(8)); - object_unsafe!(u1, UserCopyDefaultMove, &u); - object_unsafe!(u2, UserCopyDefaultMove, Moved(&mut u)); + object_unsafe!(u1, UserCopyDefaultMove, LvalueRefUnsafe::bind(&u)); + object_unsafe!(u2, UserCopyDefaultMove, RvalueRefUnsafe::bind(&mut u)); assert!((((u1.v) == (108)) && ((u2.v) == (8))) && ((u.v) == (8))); object_unsafe!(u3, UserCopyDefaultMove(1)); object_unsafe!(u4, UserCopyDefaultMove(1)); assign_unsafe!(u3 = u2); - assign_unsafe!(u4 = Moved(u2)); + assign_unsafe!(u4 = RvalueRefUnsafe(u2)); assert!(((u3.v) == (108)) && ((u4.v) == (8))); object_unsafe!(p, Buffer(3)); - object_unsafe!(q, Buffer, Moved(&mut p)); + object_unsafe!(q, Buffer, RvalueRefUnsafe::bind(&mut p)); assert!( ((((q.n) == (3)) && ((q.data.len()) == (3_usize))) && ((q.data[(2_usize)]) == (3))) && (p.data.is_empty()) ); object_unsafe!(r, Buffer(1)); - assign_unsafe!(r = Moved(q)); + assign_unsafe!(r = RvalueRefUnsafe(q)); assert!( ((((r.n) == (3)) && ((r.data.len()) == (3_usize))) && ((r.arr[(1) as usize]) == (4))) && (q.data.is_empty()) @@ -633,7 +663,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { { let mut __v: Buffer = ::zero_init(); - ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut bufs[(0_usize)])); + MoveConstructibleUnsafe::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut bufs[(0_usize)]), + ); __v } }; @@ -659,7 +692,7 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(__tmp_3)) } }; - object_unsafe!(o2, Owner, Moved(&mut o1)); + object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o1)); assert!( ((((o2.n) == (5)) && ((o2.data.len()) == (1_usize))) && ((o2.arr[(1) as usize]) == (6))) && ((*o2 @@ -677,7 +710,7 @@ unsafe fn main_0() -> i32 { .is_null()) ); object_unsafe!(o3, Owner); - assign_unsafe!(o3 = Moved(o2)); + assign_unsafe!(o3 = RvalueRefUnsafe(o2)); assert!( ((((o3.n) == (5)) && ((o3.data[(0_usize)]) == (5))) && ((o3.arr[(0) as usize]) == (5))) && ((*o3 @@ -698,11 +731,11 @@ unsafe fn main_0() -> i32 { data: Vec::from([1, 2]), }; let mut c2: Copyable = c1.clone(); - object_unsafe!(c3, Copyable, Moved(&mut c1)); + object_unsafe!(c3, Copyable, RvalueRefUnsafe::bind(&mut c1)); assert!(((c2.data.len()) == (2_usize)) && ((c3.data.len()) == (2_usize))); assert!(c1.data.is_empty()); object_unsafe!(c4, Copyable); - assign_unsafe!(c4 = Moved(c3)); + assign_unsafe!(c4 = RvalueRefUnsafe(c3)); assert!(((c4.data[(1_usize)]) == (2)) && (c3.data.is_empty())); object_unsafe!(h1, Holder(4)); { @@ -713,7 +746,7 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(__tmp_4)) } }; - object_unsafe!(h2, Holder, Moved(&mut h1)); + object_unsafe!(h2, Holder, RvalueRefUnsafe::bind(&mut h1)); assert!( ((((h2.inner.x) == (4)) && ((h2.e.v) == (4))) && ((*h2 @@ -728,7 +761,7 @@ unsafe fn main_0() -> i32 { .is_null()) ); object_unsafe!(h3, Holder(1)); - assign_unsafe!(h3 = Moved(h2)); + assign_unsafe!(h3 = RvalueRefUnsafe(h2)); assert!( ((((h3.inner.x) == (4)) && ((h3.e.arr[(1) as usize]) == (5))) && ((*h3 @@ -745,30 +778,30 @@ unsafe fn main_0() -> i32 { object_unsafe!(t1, HasSeesThis); object_unsafe!(t2, HasSeesThis); object_unsafe!(t3, HasSeesThis); - assign_unsafe!(t2 = Moved(t1)); + assign_unsafe!(t2 = RvalueRefUnsafe(t1)); assert!(((t2.s.self_) == (&mut t2.s as *mut SeesThis))); assign_unsafe!(t3 = t2); assert!(((t3.s.self_) == (&mut t3.s as *mut SeesThis))); object_unsafe!(k1, HasCounted); - object_unsafe!(k2, HasCounted, Moved(&mut k1)); + object_unsafe!(k2, HasCounted, RvalueRefUnsafe::bind(&mut k1)); assert!(((k2.c.moves) == (1))); object_unsafe!(k3, HasCounted); - assign_unsafe!(k3 = Moved(k2)); + assign_unsafe!(k3 = RvalueRefUnsafe(k2)); assert!(((k3.c.moves) == (2))); { object_unsafe!(d, CtorSeesThis); assert!(((d.self_) == (&mut d as *mut CtorSeesThis))); - object_unsafe!(e, CtorSeesThis, &d); + object_unsafe!(e, CtorSeesThis, LvalueRefUnsafe::bind(&d)); assert!(((e.self_) == (&mut e as *mut CtorSeesThis))); object_unsafe!(f, CtorSeesThis::construct_1(3)); assert!(((f.self_) == (&mut f as *mut CtorSeesThis)) && ((f.id) == (3))); object_unsafe!(h1, HasCtorSeesThis); assert!(((h1.x.self_) == (&mut h1.x as *mut CtorSeesThis))); - object_unsafe!(h2, HasCtorSeesThis, &h1); + object_unsafe!(h2, HasCtorSeesThis, LvalueRefUnsafe::bind(&h1)); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); - object_unsafe!(h3, HasCtorSeesThis, Moved(&mut h1)); + object_unsafe!(h3, HasCtorSeesThis, RvalueRefUnsafe::bind(&mut h1)); assert!(((h3.x.self_) == (&mut h3.x as *mut CtorSeesThis))); - assign_unsafe!(h2 = Moved(h3)); + assign_unsafe!(h2 = RvalueRefUnsafe(h3)); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); assign_unsafe!(h2 = h1); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); @@ -790,7 +823,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(o1, OutOfLineDefaulted()); assert!(((o1.v) == (1)) && ((o1.x.self_) == (&mut o1.x as *mut CtorSeesThis))); o1.v = 2; - object_unsafe!(o2, OutOfLineDefaulted, &o1); + object_unsafe!(o2, OutOfLineDefaulted, LvalueRefUnsafe::bind(&o1)); assert!(((o2.v) == (2)) && ((o2.x.self_) == (&mut o2.x as *mut CtorSeesThis))); object_unsafe!(a1, OutOfLineAssign); object_unsafe!(a2, OutOfLineAssign); @@ -803,7 +836,7 @@ unsafe fn main_0() -> i32 { assign_unsafe!(a2 = a1); assert!((((a2.v) == (3)) && ((a2.w.len()) == (1_usize))) && ((a1.w.len()) == (1_usize))); assert!(((a2.s.self_) == (&mut a2.s as *mut SeesThis))); - assign_unsafe!(a3 = Moved(a2)); + assign_unsafe!(a3 = RvalueRefUnsafe(a2)); assert!( (((a3.v) == (3)) && ((a3.w.len()) == (1_usize))) && ((a3.s.self_) == (&mut a3.s as *mut SeesThis)) diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 35638f5401..0b1b446c68 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -54,7 +54,7 @@ pub unsafe fn size_t_in_rules_3() { let mut ar3: [u64; 3] = ar2.clone(); { for __i in 0..3 { - assign_unsafe!(ar3[__i] = Moved(ar[__i])); + assign_unsafe!(ar3[__i] = RvalueRefUnsafe(ar[__i])); } }; assert!(((ar3[1]) == (2_u64)));